1
0
mirror of https://github.com/lucko/LuckPerms.git synced 2025-09-09 05:40:47 +02:00

Update to text 3

This commit is contained in:
Luck
2019-05-07 00:23:40 +01:00
parent d762a0aaa6
commit f49446011a
44 changed files with 233 additions and 102 deletions

View File

@@ -56,9 +56,9 @@ subprojects {
}
repositories {
//mavenLocal()
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url 'https://repo.lucko.me/' }
mavenLocal()
}
}

View File

@@ -11,7 +11,7 @@ dependencies {
compile project(':common')
compileOnly 'org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT'
compileOnly'net.kyori:text-adapter-bukkit:1.0.2'
compileOnly 'net.kyori:text-adapter-bukkit:3.0.1'
compileOnly 'me.lucko:commodore:1.3'
compileOnly('net.milkbowl.vault:VaultAPI:1.6') {
exclude(module: 'bukkit')

View File

@@ -73,7 +73,6 @@ import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.ServicePriority;
import java.io.File;
import java.util.EnumSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
@@ -123,7 +122,8 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
@Override
protected Set<Dependency> getGlobalDependencies() {
EnumSet<Dependency> dependencies = EnumSet.of(Dependency.TEXT, Dependency.TEXT_ADAPTER_BUKKIT, Dependency.CAFFEINE, Dependency.OKIO, Dependency.OKHTTP, Dependency.EVENT);
Set<Dependency> dependencies = super.getGlobalDependencies();
dependencies.add(Dependency.TEXT_ADAPTER_BUKKIT);
if (isBrigadierSupported()) {
dependencies.add(Dependency.COMMODORE);
}

View File

@@ -6,7 +6,7 @@ dependencies {
compile project(':common')
compileOnly 'net.md-5:bungeecord-api:1.13-SNAPSHOT'
compileOnly 'net.kyori:text-adapter-bungeecord:1.0.2'
compileOnly 'net.kyori:text-adapter-bungeecord:3.0.1'
compileOnly 'com.imaginarycode.minecraft:RedisBungee:0.4'
// migration plugins

View File

@@ -58,7 +58,6 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.EnumSet;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@@ -94,7 +93,9 @@ public class LPBungeePlugin extends AbstractLuckPermsPlugin {
@Override
protected Set<Dependency> getGlobalDependencies() {
return EnumSet.of(Dependency.TEXT, Dependency.TEXT_ADAPTER_BUNGEECORD, Dependency.CAFFEINE, Dependency.OKIO, Dependency.OKHTTP, Dependency.EVENT);
Set<Dependency> dependencies = super.getGlobalDependencies();
dependencies.add(Dependency.TEXT_ADAPTER_BUNGEECORD);
return dependencies;
}
@Override

View File

@@ -2,9 +2,14 @@ dependencies {
compile project(':luckperms-api')
compile 'org.checkerframework:checker-qual:2.5.5'
compile('net.kyori:text:1.11-1.6.5') {
compile('net.kyori:text-api:3.0.0') {
exclude(module: 'checker-qual')
exclude(module: 'guava')
}
compile('net.kyori:text-serializer-legacy:3.0.0') {
exclude(module: 'text-api')
}
compile('net.kyori:text-serializer-gson:3.0.0') {
exclude(module: 'text-api')
exclude(module: 'gson')
}
compile('net.kyori:event-api:3.0.0') {

View File

@@ -279,7 +279,7 @@ public class CommandManager {
TextComponent component = TextUtils.fromLegacy("&3> &a" + String.format(c.getUsage(), label), AMPERSAND_CHAR)
.toBuilder().applyDeep(comp -> {
comp.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline(
comp.hoverEvent(HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(
"&bCommand: &2" + c.getName(),
"&bDescription: &2" + c.getDescription(),
"&bUsage: &2" + String.format(c.getUsage(), label),
@@ -287,7 +287,7 @@ public class CommandManager {
" ",
"&7Click to auto-complete."
), AMPERSAND_CHAR)));
comp.clickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, String.format(c.getUsage(), label)));
comp.clickEvent(ClickEvent.suggestCommand(String.format(c.getUsage(), label)));
}).build();
sender.sendMessage(component);
});

View File

@@ -31,7 +31,6 @@ import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.sender.Sender;
import java.util.Collection;
import java.util.List;

View File

@@ -86,7 +86,7 @@ public class MetaAddChatMeta extends SharedSubCommand {
DataMutateResult result = holder.setPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).withExtraContext(context).build());
if (result.asBoolean()) {
TextComponent.Builder builder = Message.ADD_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
'¥'
));

View File

@@ -94,7 +94,7 @@ public class MetaAddTempChatMeta extends SharedSubCommand {
duration = ret.getMergedNode().getExpiryUnixTime();
TextComponent.Builder builder = Message.ADD_TEMP_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
'¥'
));

View File

@@ -47,7 +47,7 @@ import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.BuildableComponent;
import net.kyori.text.ComponentBuilder;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
@@ -152,7 +152,7 @@ public class MetaInfo extends SharedSubCommand {
}
}
private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(ChatMetaType type, PermissionHolder holder, String label, LocalizedNode node) {
private static Consumer<ComponentBuilder<?, ?>> makeFancy(ChatMetaType type, PermissionHolder holder, String label, LocalizedNode node) {
if (!node.getLocation().equals(holder.getObjectName())) {
// inherited.
Group group = holder.getPlugin().getGroupManager().getIfLoaded(node.getLocation());
@@ -161,14 +161,14 @@ public class MetaInfo extends SharedSubCommand {
}
}
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline(
HoverEvent hoverEvent = HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(
"¥3> ¥a" + type.getEntry(node).getKey() + " ¥7- ¥r" + type.getEntry(node).getValue(),
" ",
"¥7Click to remove this " + type.name().toLowerCase() + " from " + holder.getFormattedDisplayName()
), '¥'));
String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType() == HolderType.GROUP ? holder.getObjectName() : holder.getFormattedDisplayName(), holder.getType(), false, !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty());
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
ClickEvent clickEvent = ClickEvent.suggestCommand(command);
return component -> {
component.hoverEvent(hoverEvent);
@@ -176,7 +176,7 @@ public class MetaInfo extends SharedSubCommand {
};
}
private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(PermissionHolder holder, String label, LocalizedNode node) {
private static Consumer<ComponentBuilder<?, ?>> makeFancy(PermissionHolder holder, String label, LocalizedNode node) {
if (!node.getLocation().equals(holder.getObjectName())) {
// inherited.
Group group = holder.getPlugin().getGroupManager().getIfLoaded(node.getLocation());
@@ -185,14 +185,14 @@ public class MetaInfo extends SharedSubCommand {
}
}
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline(
HoverEvent hoverEvent = HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(
"¥3> ¥r" + node.getMeta().getKey() + " ¥7- ¥r" + node.getMeta().getValue(),
" ",
"¥7Click to remove this meta pair from " + holder.getFormattedDisplayName()
), '¥'));
String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType() == HolderType.GROUP ? holder.getObjectName() : holder.getFormattedDisplayName(), holder.getType(), false, !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty());
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
ClickEvent clickEvent = ClickEvent.suggestCommand(command);
return component -> {
component.hoverEvent(hoverEvent);

View File

@@ -105,7 +105,7 @@ public class MetaRemoveChatMeta extends SharedSubCommand {
if (result.asBoolean()) {
TextComponent.Builder builder = Message.REMOVE_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
'¥'
));

View File

@@ -105,7 +105,7 @@ public class MetaRemoveTempChatMeta extends SharedSubCommand {
if (result.asBoolean()) {
TextComponent.Builder builder = Message.REMOVE_TEMP_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
'¥'
));

View File

@@ -87,7 +87,7 @@ public class MetaSet extends SharedSubCommand {
holder.setPermission(n);
TextComponent.Builder builder = Message.SET_META_SUCCESS.asComponent(plugin.getLocaleManager(), key, value, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
TextUtils.joinNewline("¥3Raw key: ¥r" + key, "¥3Raw value: ¥r" + value),
'¥'
));

View File

@@ -122,7 +122,7 @@ public class MetaSetChatMeta extends SharedSubCommand {
DataMutateResult result = holder.setPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).withExtraContext(context).build());
if (result.asBoolean()) {
TextComponent.Builder builder = Message.ADD_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
'¥'
));

View File

@@ -92,7 +92,7 @@ public class MetaSetTemp extends SharedSubCommand {
duration = holder.setPermission(n, modifier).getMergedNode().getExpiryUnixTime();
TextComponent.Builder builder = Message.SET_META_TEMP_SUCCESS.asComponent(plugin.getLocaleManager(), key, value, holder.getFormattedDisplayName(), DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
TextUtils.joinNewline("¥3Raw key: ¥r" + key, "¥3Raw value: ¥r" + value),
'¥'
));

View File

@@ -134,7 +134,7 @@ public class MetaSetTempChatMeta extends SharedSubCommand {
duration = ret.getMergedNode().getExpiryUnixTime();
TextComponent.Builder builder = Message.ADD_TEMP_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
'¥'
));

View File

@@ -81,8 +81,8 @@ public class HolderEditor<T extends PermissionHolder> extends SubCommand<T> {
Message.EDITOR_URL.send(sender);
Component message = TextComponent.builder(url).color(TextColor.AQUA)
.clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url))
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the editor.").color(TextColor.GRAY)))
.clickEvent(ClickEvent.openUrl(url))
.hoverEvent(HoverEvent.showText(TextComponent.of("Click to open the editor.").color(TextColor.GRAY)))
.build();
sender.sendMessage(message);

View File

@@ -50,7 +50,7 @@ import me.lucko.luckperms.common.util.Iterators;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.BuildableComponent;
import net.kyori.text.ComponentBuilder;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
@@ -135,15 +135,15 @@ public class ParentInfo extends SharedSubCommand {
return NodeWithContextComparator.reverse().compare(o1, o2);
};
private static Consumer<BuildableComponent.Builder<? ,?>> makeFancy(PermissionHolder holder, String label, Node node) {
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline(
private static Consumer<ComponentBuilder<? ,?>> makeFancy(PermissionHolder holder, String label, Node node) {
HoverEvent hoverEvent = HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(
"&3> &f" + node.getGroupName(),
" ",
"&7Click to remove this parent from " + holder.getFormattedDisplayName()
), CommandManager.AMPERSAND_CHAR));
String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType() == HolderType.GROUP ? holder.getObjectName() : holder.getFormattedDisplayName(), holder.getType(), false, !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty());
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
ClickEvent clickEvent = ClickEvent.suggestCommand(command);
return component -> {
component.hoverEvent(hoverEvent);

View File

@@ -50,7 +50,7 @@ import me.lucko.luckperms.common.util.Iterators;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.BuildableComponent;
import net.kyori.text.ComponentBuilder;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
@@ -137,15 +137,15 @@ public class PermissionInfo extends SharedSubCommand {
return NodeWithContextComparator.reverse().compare(o1, o2);
};
private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(PermissionHolder holder, String label, Node node) {
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline(
private static Consumer<ComponentBuilder<?, ?>> makeFancy(PermissionHolder holder, String label, Node node) {
HoverEvent hoverEvent = HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(
"¥3> " + (node.getValue() ? "¥a" : "¥c") + node.getPermission(),
" ",
"¥7Click to remove this node from " + holder.getFormattedDisplayName()
), '¥'));
String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType() == HolderType.GROUP ? holder.getObjectName() : holder.getFormattedDisplayName(), holder.getType(), false, !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty());
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
ClickEvent clickEvent = ClickEvent.suggestCommand(command);
return component -> {
component.hoverEvent(hoverEvent);

View File

@@ -54,7 +54,7 @@ import me.lucko.luckperms.common.util.Iterators;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.BuildableComponent;
import net.kyori.text.ComponentBuilder;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
@@ -159,15 +159,15 @@ public class GroupListMembers extends SubCommand<Group> {
return " &8(&7expires in " + DurationFormatter.LONG.formatDateDiff(node.getExpiryUnixTime()) + "&8)";
}
private static Consumer<BuildableComponent.Builder<? ,?>> makeFancy(String holderName, HolderType holderType, String label, HeldPermission<?> perm, LuckPermsPlugin plugin) {
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline(
private static Consumer<ComponentBuilder<? ,?>> makeFancy(String holderName, HolderType holderType, String label, HeldPermission<?> perm, LuckPermsPlugin plugin) {
HoverEvent hoverEvent = HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(
"&3> &b" + perm.asNode().getGroupName(),
" ",
"&7Click to remove this parent from " + holderName
), CommandManager.AMPERSAND_CHAR));
String command = "/" + label + " " + NodeFactory.nodeAsCommand(perm.asNode(), holderName, holderType, false, !plugin.getConfiguration().getContextsFile().getDefaultContexts().isEmpty());
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
ClickEvent clickEvent = ClickEvent.suggestCommand(command);
return component -> {
component.hoverEvent(hoverEvent);

View File

@@ -85,8 +85,8 @@ public class ListGroups extends SingleCommand {
}
component = component.toBuilder().applyDeep(c -> {
c.clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + label + " group " + group.getName() + " info"));
c.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to view more info about " + group.getName() + ".").color(TextColor.GRAY)));
c.clickEvent(ClickEvent.runCommand("/" + label + " group " + group.getName() + " info"));
c.hoverEvent(HoverEvent.showText(TextComponent.of("Click to view more info about " + group.getName() + ".").color(TextColor.GRAY)));
}).build();
sender.sendMessage(component);

View File

@@ -95,8 +95,8 @@ public class DebugCommand extends SingleCommand {
Message.DEBUG_URL.send(sender);
Component message = TextComponent.builder(pasteUrl).color(TextColor.AQUA)
.clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, pasteUrl))
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the debugging data.").color(TextColor.GRAY)))
.clickEvent(ClickEvent.openUrl(pasteUrl))
.hoverEvent(HoverEvent.showText(TextComponent.of("Click to open the debugging data.").color(TextColor.GRAY)))
.build();
sender.sendMessage(message);

View File

@@ -118,8 +118,8 @@ public class EditorCommand extends SingleCommand {
Message.EDITOR_URL.send(sender);
Component message = TextComponent.builder(url).color(TextColor.AQUA)
.clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url))
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the editor.").color(TextColor.GRAY)))
.clickEvent(ClickEvent.openUrl(url))
.hoverEvent(HoverEvent.showText(TextComponent.of("Click to open the editor.").color(TextColor.GRAY)))
.build();
sender.sendMessage(message);

View File

@@ -55,7 +55,7 @@ import me.lucko.luckperms.common.util.Iterators;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.BuildableComponent;
import net.kyori.text.ComponentBuilder;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
@@ -169,15 +169,15 @@ public class SearchCommand extends SingleCommand {
return " &8(&7expires in " + DurationFormatter.LONG.formatDateDiff(node.getExpiryUnixTime()) + "&8)";
}
private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(String holderName, HolderType holderType, String label, HeldPermission<?> perm, LuckPermsPlugin plugin) {
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline(
private static Consumer<ComponentBuilder<?, ?>> makeFancy(String holderName, HolderType holderType, String label, HeldPermission<?> perm, LuckPermsPlugin plugin) {
HoverEvent hoverEvent = HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(
"&3> " + (perm.asNode().getValue() ? "&a" : "&c") + perm.asNode().getPermission(),
" ",
"&7Click to remove this node from " + holderName
), CommandManager.AMPERSAND_CHAR));
String command = "/" + label + " " + NodeFactory.nodeAsCommand(perm.asNode(), holderName, holderType, false, !plugin.getConfiguration().getContextsFile().getDefaultContexts().isEmpty());
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
ClickEvent clickEvent = ClickEvent.suggestCommand(command);
return component -> {
component.hoverEvent(hoverEvent);

View File

@@ -97,8 +97,8 @@ public class TreeCommand extends SingleCommand {
Message.TREE_URL.send(sender);
Component message = TextComponent.builder(url).color(TextColor.AQUA)
.clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url))
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the tree view.").color(TextColor.GRAY)))
.clickEvent(ClickEvent.openUrl(url))
.hoverEvent(HoverEvent.showText(TextComponent.of("Click to open the tree view.").color(TextColor.GRAY)))
.build();
sender.sendMessage(message);

View File

@@ -118,8 +118,8 @@ public class VerboseCommand extends SingleCommand {
Message.VERBOSE_RESULTS_URL.send(sender);
Component message = TextComponent.builder(url).color(TextColor.AQUA)
.clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url))
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the results page.").color(TextColor.GRAY)))
.clickEvent(ClickEvent.openUrl(url))
.hoverEvent(HoverEvent.showText(TextComponent.of("Click to open the results page.").color(TextColor.GRAY)))
.build();
sender.sendMessage(message);

View File

@@ -64,23 +64,44 @@ public enum Dependency {
TEXT(
"net{}kyori",
"text",
"1.11-1.6.5",
"I5D0U+Gsd5G3XO+W+4ZyO7Fyc8g7lt/up8oNpetq1W8=",
"text-api",
"3.0.0",
"/d7o/eZkZx/naJE+pMg1KqIzL8TWxWjA4yxjv8/10Cg=",
Relocation.of("text", "net{}kyori{}text")
),
TEXT_SERIALIZER_GSON(
"net{}kyori",
"text-serializer-gson",
"3.0.0",
"zc1ePBBRCjSoNQiNqsBL+6TYRmaUPyEZtj1LhCtViv0=",
Relocation.of("text", "net{}kyori{}text")
),
TEXT_SERIALIZER_LEGACY(
"net{}kyori",
"text-serializer-legacy",
"3.0.0",
"Zns1sKvALAt3Sn0Px+vENv1XQ9y80E1cSzzDN46C9rQ=",
Relocation.of("text", "net{}kyori{}text")
),
TEXT_ADAPTER_BUKKIT(
"net{}kyori",
"text-adapter-bukkit",
"1.0.2",
"jZx0BgSlfyeamadYiE52wlJbQOwSyB4fffPoE526hOk=",
"3.0.1",
"y/3ObS+Gwguy1/e1/bJRCbaWoMigFju6VypliQKFa5M=",
Relocation.of("text", "net{}kyori{}text")
),
TEXT_ADAPTER_BUNGEECORD(
"net{}kyori",
"text-adapter-bungeecord",
"1.0.2",
"hj7z8v8AceARfwTPzLzJwZdTqqERN9fPJPhZQAqD1Rc=",
"3.0.1",
"Q+cj+8MGgaAVOAjekG4oaE1TOijsezbbEXB41NP1mEA=",
Relocation.of("text", "net{}kyori{}text")
),
TEXT_ADAPTER_SPONGEAPI(
"net{}kyori",
"text-adapter-spongeapi",
"3.0.1",
"Yedf+fTvFwjdZ74EoQ8TTrmDvT0hszCu1RoRs5hweWc=",
Relocation.of("text", "net{}kyori{}text")
),
EVENT(

View File

@@ -175,7 +175,6 @@ public class DependencyManager {
RelocationHandler relocationHandler = getRelocationHandler();
// attempt to remap the jar.
this.plugin.getLogger().info("Attempting to apply relocations to " + input.getFileName().toString() + "...");
relocationHandler.remap(input, output, relocations);
remappedJars.add(new Source(source.dependency, output));
@@ -255,8 +254,6 @@ public class DependencyManager {
"Actual: " + Base64.getEncoder().encodeToString(hash));
}
this.plugin.getLogger().info("Successfully downloaded '" + fileName + "' with matching checksum: " + Base64.getEncoder().encodeToString(hash));
// if the checksum matches, save the content to disk
Files.write(file, bytes);
success = true;

View File

@@ -94,11 +94,6 @@ public class DependencyRegistry {
relocations.add(Relocation.of("gson", "com{}google{}gson"));
}
// don't relocate text when running on Velocity
if (dependency == Dependency.TEXT && type == PlatformType.VELOCITY) {
relocations.remove(Relocation.of("text", "net{}kyori{}text"));
}
// relocate yaml within configurate when running velocity
if (dependency == Dependency.CONFIGURATE_YAML && type == PlatformType.VELOCITY) {
relocations.add(Relocation.of("yaml", "org{}yaml{}snakeyaml"));

View File

@@ -26,7 +26,6 @@
package me.lucko.luckperms.common.model.manager.user;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.Streams;
import me.lucko.luckperms.api.LocalizedNode;
import me.lucko.luckperms.api.Node;

View File

@@ -56,6 +56,7 @@ import me.lucko.luckperms.common.verbose.VerboseHandler;
import me.lucko.luckperms.common.web.Bytebin;
import java.io.IOException;
import java.util.EnumSet;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@@ -220,8 +221,19 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin {
getLogger().info("Goodbye!");
}
protected Set<Dependency> getGlobalDependencies() {
return EnumSet.of(
Dependency.TEXT,
Dependency.TEXT_SERIALIZER_GSON,
Dependency.TEXT_SERIALIZER_LEGACY,
Dependency.CAFFEINE,
Dependency.OKIO,
Dependency.OKHTTP,
Dependency.EVENT
);
}
protected abstract void setupSenderFactory();
protected abstract Set<Dependency> getGlobalDependencies();
protected abstract ConfigurationAdapter provideConfigurationAdapter();
protected abstract void registerPlatformListeners();
protected abstract MessagingFactory<?> provideMessagingFactory();

View File

@@ -27,7 +27,7 @@ package me.lucko.luckperms.common.util;
import net.kyori.text.Component;
import net.kyori.text.TextComponent;
import net.kyori.text.serializer.ComponentSerializers;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import java.util.Arrays;
import java.util.stream.Collectors;
@@ -46,19 +46,19 @@ public final class TextUtils {
}
public static TextComponent fromLegacy(String input, char character) {
return ComponentSerializers.LEGACY.deserialize(input, character);
return LegacyComponentSerializer.INSTANCE.deserialize(input, character);
}
public static TextComponent fromLegacy(String input) {
return ComponentSerializers.LEGACY.deserialize(input);
return LegacyComponentSerializer.INSTANCE.deserialize(input);
}
public static String toLegacy(Component component, char character) {
return ComponentSerializers.LEGACY.serialize(component, character);
return LegacyComponentSerializer.INSTANCE.serialize(component, character);
}
public static String toLegacy(Component component) {
return ComponentSerializers.LEGACY.serialize(component);
return LegacyComponentSerializer.INSTANCE.serialize(component);
}
public static String rewritePlaceholders(String input) {

View File

@@ -221,7 +221,7 @@ public class VerboseListener {
}
// send the message
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline(hover.stream()), CommandManager.AMPERSAND_CHAR));
HoverEvent hoverEvent = HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(hover.stream()), CommandManager.AMPERSAND_CHAR));
TextComponent text = textComponent.toBuilder().applyDeep(comp -> comp.hoverEvent(hoverEvent)).build();
this.notifiedSender.sendMessage(text);
}

View File

@@ -34,7 +34,6 @@ import me.lucko.luckperms.common.calculator.CalculatorFactory;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter;
import me.lucko.luckperms.common.dependencies.Dependency;
import me.lucko.luckperms.common.event.AbstractEventBus;
import me.lucko.luckperms.common.messaging.MessagingFactory;
import me.lucko.luckperms.common.model.User;
@@ -70,10 +69,8 @@ import cn.nukkit.plugin.service.ServicePriority;
import cn.nukkit.utils.Config;
import java.io.File;
import java.util.EnumSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
@@ -108,11 +105,6 @@ public class LPNukkitPlugin extends AbstractLuckPermsPlugin {
this.senderFactory = new NukkitSenderFactory(this);
}
@Override
protected Set<Dependency> getGlobalDependencies() {
return EnumSet.of(Dependency.TEXT, Dependency.CAFFEINE, Dependency.OKIO, Dependency.OKHTTP, Dependency.EVENT);
}
@Override
protected ConfigurationAdapter provideConfigurationAdapter() {
return new NukkitConfigAdapter(this, resolveConfig());

View File

@@ -24,6 +24,7 @@
*/
package me.lucko.luckperms.nukkit.inject.dummy;
import cn.nukkit.Server;
import cn.nukkit.command.Command;
import cn.nukkit.command.CommandSender;

View File

@@ -25,6 +25,7 @@ dependencies {
exclude(module: 'configurate-gson')
exclude(module: 'configurate-yaml')
}
compileOnly 'net.kyori:text-adapter-spongeapi:3.0.1'
}
blossom {

View File

@@ -72,7 +72,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
@@ -113,8 +112,12 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin {
@Override
protected Set<Dependency> getGlobalDependencies() {
return EnumSet.of(Dependency.TEXT, Dependency.CAFFEINE, Dependency.OKIO, Dependency.OKHTTP, Dependency.EVENT,
Dependency.CONFIGURATE_CORE, Dependency.CONFIGURATE_HOCON, Dependency.HOCON_CONFIG);
Set<Dependency> dependencies = super.getGlobalDependencies();
dependencies.add(Dependency.TEXT_ADAPTER_SPONGEAPI);
dependencies.add(Dependency.CONFIGURATE_CORE);
dependencies.add(Dependency.CONFIGURATE_HOCON);
dependencies.add(Dependency.HOCON_CONFIG);
return dependencies;
}
@Override

View File

@@ -32,7 +32,7 @@ import me.lucko.luckperms.common.sender.SenderFactory;
import me.lucko.luckperms.sponge.service.CompatibilityUtil;
import net.kyori.text.Component;
import net.kyori.text.serializer.ComponentSerializers;
import net.kyori.text.adapter.spongeapi.TextAdapter;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.entity.living.player.Player;
@@ -69,7 +69,7 @@ public class SpongeSenderFactory extends SenderFactory<CommandSource> {
@Override
protected void sendMessage(CommandSource source, Component message) {
source.sendMessage(TextSerializers.JSON.deserialize(ComponentSerializers.JSON.serialize(message)));
TextAdapter.sendComponent(source, message);
}
@Override

View File

@@ -10,8 +10,12 @@ repositories {
dependencies {
compile project(':common')
compileOnly 'com.velocitypowered:velocity-api:1.0-SNAPSHOT'
annotationProcessor 'com.velocitypowered:velocity-api:1.0-SNAPSHOT'
compileOnly('com.velocitypowered:velocity-api:1.0-SNAPSHOT') {
exclude(module: 'text')
}
annotationProcessor('com.velocitypowered:velocity-api:1.0-SNAPSHOT') {
exclude(module: 'text')
}
}
blossom {
@@ -26,7 +30,7 @@ shadowJar {
include(dependency('me.lucko.luckperms:.*'))
}
// relocate 'net.kyori.text', 'me.lucko.luckperms.lib.text' (included in velocity!)
relocate 'net.kyori.text', 'me.lucko.luckperms.lib.text'
relocate 'net.kyori.event', 'me.lucko.luckperms.lib.eventbus'
relocate 'com.github.benmanes.caffeine', 'me.lucko.luckperms.lib.caffeine'
relocate 'okio', 'me.lucko.luckperms.lib.okio'

View File

@@ -58,7 +58,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.EnumSet;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@@ -94,8 +93,11 @@ public class LPVelocityPlugin extends AbstractLuckPermsPlugin {
@Override
protected Set<Dependency> getGlobalDependencies() {
return EnumSet.of(Dependency.CAFFEINE, Dependency.OKIO, Dependency.OKHTTP, Dependency.EVENT,
Dependency.CONFIGURATE_CORE, Dependency.CONFIGURATE_YAML, Dependency.SNAKEYAML);
Set<Dependency> dependencies = super.getGlobalDependencies();
dependencies.add(Dependency.CONFIGURATE_CORE);
dependencies.add(Dependency.CONFIGURATE_YAML);
dependencies.add(Dependency.SNAKEYAML);
return dependencies;
}
@Override

View File

@@ -0,0 +1,99 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.velocity;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.event.ResultedEvent;
import net.kyori.text.Component;
import net.kyori.text.serializer.gson.GsonComponentSerializer;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* Utility for handling text components on Velocity.
*
* <p>Velocity bundles an old, incompatible version of the text library used by LuckPerms.
* The package remains the same - so we have to use this reflection hack to convert our
* relocated Component object to one Velocity will accept.</p>
*/
public class VelocityComponentUtils {
private static final String KYORI_TEXT_PACKAGE_NO_RELOCATION = "net#kyori#text#".replace("#", ".");
private static final Class<?> COMPONENT_CLASS;
private static final Method DESERIALIZE_METHOD;
private static final Object SERIALIZER;
private static final Method SEND_MESSAGE_METHOD;
private static final Method COMPONENT_RESULT_DENIED_CONSTRUCTOR;
static {
try {
COMPONENT_CLASS = kyoriClass("Component");
Class<?> componentSerializerClass = kyoriClass("serializer.ComponentSerializer");
Class<?> componentSerializersClass = kyoriClass("serializer.ComponentSerializers");
DESERIALIZE_METHOD = componentSerializerClass.getMethod("deserialize", Object.class);
Field jsonSerializerField = componentSerializersClass.getField("JSON");
SERIALIZER = jsonSerializerField.get(null);
SEND_MESSAGE_METHOD = CommandSource.class.getMethod("sendMessage", COMPONENT_CLASS);
COMPONENT_RESULT_DENIED_CONSTRUCTOR = ResultedEvent.ComponentResult.class.getMethod("denied", COMPONENT_CLASS);
} catch (Exception e) {
throw new ExceptionInInitializerError(e);
}
}
private static Class<?> kyoriClass(String name) throws ClassNotFoundException {
return Class.forName(KYORI_TEXT_PACKAGE_NO_RELOCATION + name);
}
private static Object convertComponent(Component component) {
String json = GsonComponentSerializer.INSTANCE.serialize(component);
try {
return DESERIALIZE_METHOD.invoke(SERIALIZER, json);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
public static void sendMessage(CommandSource source, Component message) {
try {
SEND_MESSAGE_METHOD.invoke(source, convertComponent(message));
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
public static ResultedEvent.ComponentResult createDeniedResult(Component component) {
try {
return (ResultedEvent.ComponentResult) COMPONENT_RESULT_DENIED_CONSTRUCTOR.invoke(null, convertComponent(component));
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
}

View File

@@ -67,7 +67,7 @@ public class VelocitySenderFactory extends SenderFactory<CommandSource> {
@Override
protected void sendMessage(CommandSource source, Component message) {
source.sendMessage(message);
VelocityComponentUtils.sendMessage(source, message);
}
@Override

View File

@@ -26,7 +26,6 @@
package me.lucko.luckperms.velocity.listeners;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.ResultedEvent;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.DisconnectEvent;
import com.velocitypowered.api.event.connection.LoginEvent;
@@ -38,6 +37,7 @@ import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener;
import me.lucko.luckperms.velocity.LPVelocityPlugin;
import me.lucko.luckperms.velocity.VelocityComponentUtils;
import me.lucko.luckperms.velocity.service.PlayerPermissionProvider;
import java.util.Collections;
@@ -105,7 +105,7 @@ public class VelocityConnectionListener extends AbstractConnectionListener {
@Subscribe(order = PostOrder.FIRST)
public void onPlayerLogin(LoginEvent e) {
if (this.deniedLogin.remove(e.getPlayer().getUniqueId())) {
e.setResult(ResultedEvent.ComponentResult.denied(Message.LOADING_DATABASE_ERROR.asComponent(this.plugin.getLocaleManager())));
e.setResult(VelocityComponentUtils.createDeniedResult(Message.LOADING_DATABASE_ERROR.asComponent(this.plugin.getLocaleManager())));
}
}
@@ -133,7 +133,7 @@ public class VelocityConnectionListener extends AbstractConnectionListener {
if (this.plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) {
// disconnect the user
e.setResult(ResultedEvent.ComponentResult.denied(Message.LOADING_STATE_ERROR.asComponent(this.plugin.getLocaleManager())));
e.setResult(VelocityComponentUtils.createDeniedResult(Message.LOADING_STATE_ERROR.asComponent(this.plugin.getLocaleManager())));
} else {
// just send a message
this.plugin.getBootstrap().getScheduler().asyncLater(() -> {
@@ -141,7 +141,7 @@ public class VelocityConnectionListener extends AbstractConnectionListener {
return;
}
player.sendMessage(Message.LOADING_STATE_ERROR.asComponent(this.plugin.getLocaleManager()));
this.plugin.getSenderFactory().wrap(player).sendMessage(Message.LOADING_STATE_ERROR.asComponent(this.plugin.getLocaleManager()));
}, 1, TimeUnit.SECONDS);
}
}