Revert bad text refactoring, bump version to 3.0.2

This commit is contained in:
Luck 2019-10-15 13:58:20 +01:00
parent 4b0574710e
commit 916e3dbb0b
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
25 changed files with 186 additions and 71 deletions

View File

@ -29,10 +29,10 @@ import me.lucko.luckperms.bukkit.compat.CraftBukkitUtil;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.sender.SenderFactory;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.Component;
import net.kyori.text.adapter.bukkit.TextAdapter;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.node.Tristate;
import org.bukkit.command.CommandSender;
@ -82,7 +82,7 @@ public class BukkitSenderFactory extends SenderFactory<CommandSender> {
TextAdapter.sendComponent(sender, message);
} else {
// Fallback to legacy format
sendMessage(sender, LegacyComponentSerializer.INSTANCE.serialize(message));
sendMessage(sender, TextUtils.toLegacy(message));
}
}

View File

@ -29,10 +29,10 @@ import me.lucko.luckperms.bungee.event.TristateCheckEvent;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.sender.SenderFactory;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.Component;
import net.kyori.text.adapter.bungeecord.TextAdapter;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.node.Tristate;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -62,7 +62,7 @@ public class BungeeSenderFactory extends SenderFactory<CommandSender> {
@Override
protected void sendMessage(CommandSender sender, String s) {
sendMessage(sender, LegacyComponentSerializer.INSTANCE.deserialize(s));
sendMessage(sender, TextUtils.fromLegacy(s));
}
@Override

View File

@ -2,13 +2,13 @@ dependencies {
compile project(':api')
compile 'org.checkerframework:checker-qual:2.5.5'
compile('net.kyori:text-api:3.0.0') {
compile('net.kyori:text-api:3.0.2') {
exclude(module: 'checker-qual')
}
compile('net.kyori:text-serializer-legacy:3.0.0') {
compile('net.kyori:text-serializer-legacy:3.0.2') {
exclude(module: 'text-api')
}
compile('net.kyori:text-serializer-gson:3.0.0') {
compile('net.kyori:text-serializer-gson:3.0.2') {
exclude(module: 'text-api')
exclude(module: 'gson')
}

View File

@ -61,11 +61,11 @@ import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.query.QueryOptions;
import java.util.ArrayList;
@ -276,9 +276,16 @@ public class CommandManager {
.forEach(c -> {
String permission = c.getPermission().map(CommandPermission::getPermission).orElse("None");
TextComponent component = LegacyComponentSerializer.INSTANCE.deserialize("&3> &a" + String.format(c.getUsage(), label), AMPERSAND_CHAR)
TextComponent component = TextUtils.fromLegacy("&3> &a" + String.format(c.getUsage(), label), AMPERSAND_CHAR)
.toBuilder().applyDeep(comp -> {
comp.hoverEvent(HoverEvent.showText(LegacyComponentSerializer.INSTANCE.deserialize(String.join("\n", "&bCommand: &2" + c.getName(), "&bDescription: &2" + c.getDescription(), "&bUsage: &2" + String.format(c.getUsage(), label), "&bPermission: &2" + permission, " ", "&7Click to auto-complete."), AMPERSAND_CHAR)));
comp.hoverEvent(HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(
"&bCommand: &2" + c.getName(),
"&bDescription: &2" + c.getDescription(),
"&bUsage: &2" + String.format(c.getUsage(), label),
"&bPermission: &2" + permission,
" ",
"&7Click to auto-complete."
), AMPERSAND_CHAR)));
comp.clickEvent(ClickEvent.suggestCommand(String.format(c.getUsage(), label)));
}).build();
sender.sendMessage(component);

View File

@ -45,10 +45,10 @@ import me.lucko.luckperms.common.node.types.Suffix;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
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.TextComponent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.context.MutableContextSet;
import net.luckperms.api.model.DataMutateResult;
import net.luckperms.api.model.DataType;
@ -90,7 +90,10 @@ public class MetaAddChatMeta extends SharedSubCommand {
DataMutateResult result = holder.setNode(DataType.NORMAL, ((this.type == ChatMetaType.PREFIX ? Prefix.builder(priority, meta) : Suffix.builder(priority, meta))).withContext(context).build(), true);
if (result.wasSuccessful()) {
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 = HoverEvent.showText(LegacyComponentSerializer.INSTANCE.deserialize("¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta, '¥'));
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
'¥'
));
builder.applyDeep(c -> c.hoverEvent(event));
sender.sendMessage(builder.build());

View File

@ -47,10 +47,10 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.TextComponent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.context.MutableContextSet;
import net.luckperms.api.model.DataType;
import net.luckperms.api.model.TemporaryDataMutateResult;
@ -99,7 +99,10 @@ public class MetaAddTempChatMeta extends SharedSubCommand {
duration = ret.getMergedNode().getExpiry().getEpochSecond();
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 = HoverEvent.showText(LegacyComponentSerializer.INSTANCE.deserialize("¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta, '¥'));
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
'¥'
));
builder.applyDeep(c -> c.hoverEvent(event));
sender.sendMessage(builder.build());

View File

@ -43,12 +43,12 @@ import me.lucko.luckperms.common.node.factory.NodeCommandFactory;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
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.ComponentBuilder;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.NodeType;
import net.luckperms.api.node.metadata.types.InheritanceOriginMetadata;
@ -171,7 +171,11 @@ public class MetaInfo extends SharedSubCommand {
}
}
HoverEvent hoverEvent = HoverEvent.showText(LegacyComponentSerializer.INSTANCE.deserialize(String.join("\n", "¥3> ¥a" + node.getPriority() + " ¥7- ¥r" + node.getMetaValue(), " ", "¥7Click to remove this " + node.getMetaType().name().toLowerCase() + " from " + holder.getFormattedDisplayName()), '¥'));
HoverEvent hoverEvent = HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(
"¥3> ¥a" + node.getPriority() + " ¥7- ¥r" + node.getMetaValue(),
" ",
"¥7Click to remove this " + node.getMetaType().name().toLowerCase() + " from " + holder.getFormattedDisplayName()
), '¥'));
String id = holder.getType() == HolderType.GROUP ? holder.getObjectName() : holder.getFormattedDisplayName();
boolean explicitGlobalContext = !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty();
@ -194,7 +198,11 @@ public class MetaInfo extends SharedSubCommand {
}
}
HoverEvent hoverEvent = HoverEvent.showText(LegacyComponentSerializer.INSTANCE.deserialize(String.join("\n", "¥3> ¥r" + node.getMetaKey() + " ¥7- ¥r" + node.getMetaValue(), " ", "¥7Click to remove this meta pair from " + holder.getFormattedDisplayName()), '¥'));
HoverEvent hoverEvent = HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(
"¥3> ¥r" + node.getMetaKey() + " ¥7- ¥r" + node.getMetaValue(),
" ",
"¥7Click to remove this meta pair from " + holder.getFormattedDisplayName()
), '¥'));
String id = holder.getType() == HolderType.GROUP ? holder.getObjectName() : holder.getFormattedDisplayName();
boolean explicitGlobalContext = !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty();

View File

@ -45,10 +45,10 @@ import me.lucko.luckperms.common.node.types.Suffix;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
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.TextComponent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.context.ImmutableContextSet;
import net.luckperms.api.model.DataMutateResult;
import net.luckperms.api.model.DataType;
@ -107,7 +107,10 @@ public class MetaRemoveChatMeta extends SharedSubCommand {
if (result.wasSuccessful()) {
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 = HoverEvent.showText(LegacyComponentSerializer.INSTANCE.deserialize("¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta, '¥'));
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
'¥'
));
builder.applyDeep(c -> c.hoverEvent(event));
sender.sendMessage(builder.build());

View File

@ -45,10 +45,10 @@ import me.lucko.luckperms.common.node.types.Suffix;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
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.TextComponent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.context.ImmutableContextSet;
import net.luckperms.api.model.DataMutateResult;
import net.luckperms.api.model.DataType;
@ -107,7 +107,10 @@ public class MetaRemoveTempChatMeta extends SharedSubCommand {
if (result.wasSuccessful()) {
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 = HoverEvent.showText(LegacyComponentSerializer.INSTANCE.deserialize("¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta, '¥'));
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
'¥'
));
builder.applyDeep(c -> c.hoverEvent(event));
sender.sendMessage(builder.build());

View File

@ -44,10 +44,10 @@ import me.lucko.luckperms.common.node.types.Meta;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
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.TextComponent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.context.MutableContextSet;
import net.luckperms.api.model.DataType;
import net.luckperms.api.node.Node;
@ -90,7 +90,10 @@ public class MetaSet extends SharedSubCommand {
holder.setNode(DataType.NORMAL, node, true);
TextComponent.Builder builder = Message.SET_META_SUCCESS.asComponent(plugin.getLocaleManager(), key, value, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = HoverEvent.showText(LegacyComponentSerializer.INSTANCE.deserialize(String.join("\n", "¥3Raw key: ¥r" + key, "¥3Raw value: ¥r" + value), '¥'));
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
TextUtils.joinNewline("¥3Raw key: ¥r" + key, "¥3Raw value: ¥r" + value),
'¥'
));
builder.applyDeep(c -> c.hoverEvent(event));
sender.sendMessage(builder.build());

View File

@ -47,10 +47,10 @@ import me.lucko.luckperms.common.node.types.Suffix;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
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.TextComponent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.context.MutableContextSet;
import net.luckperms.api.model.DataMutateResult;
import net.luckperms.api.model.DataType;
@ -126,7 +126,10 @@ public class MetaSetChatMeta extends SharedSubCommand {
DataMutateResult result = holder.setNode(DataType.NORMAL, ((this.type == ChatMetaType.PREFIX ? Prefix.builder(priority, meta) : Suffix.builder(priority, meta))).withContext(context).build(), true);
if (result.wasSuccessful()) {
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 = HoverEvent.showText(LegacyComponentSerializer.INSTANCE.deserialize("¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta, '¥'));
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
'¥'
));
builder.applyDeep(c -> c.hoverEvent(event));
sender.sendMessage(builder.build());

View File

@ -46,10 +46,10 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.TextComponent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.context.MutableContextSet;
import net.luckperms.api.model.DataType;
import net.luckperms.api.model.TemporaryMergeBehaviour;
@ -95,7 +95,10 @@ public class MetaSetTemp extends SharedSubCommand {
duration = holder.setNode(DataType.NORMAL, node, modifier).getMergedNode().getExpiry().getEpochSecond();
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 = HoverEvent.showText(LegacyComponentSerializer.INSTANCE.deserialize(String.join("\n", "¥3Raw key: ¥r" + key, "¥3Raw value: ¥r" + value), '¥'));
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
TextUtils.joinNewline("¥3Raw key: ¥r" + key, "¥3Raw value: ¥r" + value),
'¥'
));
builder.applyDeep(c -> c.hoverEvent(event));
sender.sendMessage(builder.build());

View File

@ -49,10 +49,10 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.TextComponent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.context.MutableContextSet;
import net.luckperms.api.model.DataType;
import net.luckperms.api.model.TemporaryDataMutateResult;
@ -139,7 +139,10 @@ public class MetaSetTempChatMeta extends SharedSubCommand {
duration = ret.getMergedNode().getExpiry().getEpochSecond();
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 = HoverEvent.showText(LegacyComponentSerializer.INSTANCE.deserialize("¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta, '¥'));
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
'¥'
));
builder.applyDeep(c -> c.hoverEvent(event));
sender.sendMessage(builder.build());

View File

@ -46,12 +46,12 @@ import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
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.ComponentBuilder;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.node.types.InheritanceNode;
import net.luckperms.api.query.QueryOptions;
@ -119,7 +119,7 @@ public class ParentInfo extends SharedSubCommand {
s += "\n&2 expires in " + DurationFormatter.LONG.formatDateDiff(node.getExpiry().getEpochSecond());
}
TextComponent message = LegacyComponentSerializer.INSTANCE.deserialize(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(holder, label, node)).build();
TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(holder, label, node)).build();
sender.sendMessage(message);
}
@ -137,7 +137,11 @@ public class ParentInfo extends SharedSubCommand {
};
private static Consumer<ComponentBuilder<? ,?>> makeFancy(PermissionHolder holder, String label, InheritanceNode node) {
HoverEvent hoverEvent = HoverEvent.showText(LegacyComponentSerializer.INSTANCE.deserialize(String.join("\n", "&3> &f" + node.getGroupName(), " ", "&7Click to remove this parent from " + holder.getFormattedDisplayName()), CommandManager.AMPERSAND_CHAR));
HoverEvent hoverEvent = HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(
"&3> &f" + node.getGroupName(),
" ",
"&7Click to remove this parent from " + holder.getFormattedDisplayName()
), CommandManager.AMPERSAND_CHAR));
String id = holder.getType() == HolderType.GROUP ? holder.getObjectName() : holder.getFormattedDisplayName();
boolean explicitGlobalContext = !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty();

View File

@ -46,12 +46,12 @@ import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
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.ComponentBuilder;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.NodeType;
@ -119,7 +119,7 @@ public class PermissionInfo extends SharedSubCommand {
s += "\n&2- expires in " + DurationFormatter.LONG.formatDateDiff(node.getExpiry().getEpochSecond());
}
TextComponent message = LegacyComponentSerializer.INSTANCE.deserialize(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(holder, label, node)).build();
TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(holder, label, node)).build();
sender.sendMessage(message);
}
@ -137,8 +137,11 @@ public class PermissionInfo extends SharedSubCommand {
};
private static Consumer<ComponentBuilder<?, ?>> makeFancy(PermissionHolder holder, String label, Node node) {
String[] strings = new String[]{"¥3> " + (node.getValue() ? "¥a" : "¥c") + node.getKey(), " ", "¥7Click to remove this node from " + holder.getFormattedDisplayName()};
HoverEvent hoverEvent = HoverEvent.showText(LegacyComponentSerializer.INSTANCE.deserialize(String.join("\n", strings), '¥'));
HoverEvent hoverEvent = HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(
"¥3> " + (node.getValue() ? "¥a" : "¥c") + node.getKey(),
" ",
"¥7Click to remove this node from " + holder.getFormattedDisplayName()
), '¥'));
String id = holder.getType() == HolderType.GROUP ? holder.getObjectName() : holder.getFormattedDisplayName();
boolean explicitGlobalContext = !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty();

View File

@ -51,12 +51,12 @@ import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
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.ComponentBuilder;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.node.HeldNode;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.types.InheritanceNode;
@ -148,7 +148,7 @@ public class GroupListMembers extends SubCommand<Group> {
for (Map.Entry<String, HeldNode<T>> ent : mappedContent) {
String s = "&3> &b" + ent.getKey() + " " + getNodeExpiryString(ent.getValue().getNode()) + MessageUtils.getAppendableNodeContextString(sender.getPlugin().getLocaleManager(), ent.getValue().getNode());
TextComponent message = LegacyComponentSerializer.INSTANCE.deserialize(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue(), sender.getPlugin())).build();
TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue(), sender.getPlugin())).build();
sender.sendMessage(message);
}
}
@ -162,7 +162,11 @@ public class GroupListMembers extends SubCommand<Group> {
}
private static Consumer<ComponentBuilder<? ,?>> makeFancy(String holderName, HolderType holderType, String label, HeldNode<?> perm, LuckPermsPlugin plugin) {
HoverEvent hoverEvent = HoverEvent.showText(LegacyComponentSerializer.INSTANCE.deserialize(String.join("\n", "&3> &b" + ((InheritanceNode) perm.getNode()).getGroupName(), " ", "&7Click to remove this parent from " + holderName), CommandManager.AMPERSAND_CHAR));
HoverEvent hoverEvent = HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(
"&3> &b" + ((InheritanceNode) perm.getNode()).getGroupName(),
" ",
"&7Click to remove this parent from " + holderName
), CommandManager.AMPERSAND_CHAR));
boolean explicitGlobalContext = !plugin.getConfiguration().getContextsFile().getDefaultContexts().isEmpty();
String command = "/" + label + " " + NodeCommandFactory.generateCommand(perm.getNode(), holderName, holderType, false, explicitGlobalContext);

View File

@ -51,12 +51,12 @@ import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
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.ComponentBuilder;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.node.HeldNode;
import net.luckperms.api.node.Node;
@ -156,7 +156,7 @@ public class SearchCommand extends SingleCommand {
}
String s = "&3> &b" + ent.getKey() + permission + "&7 - " + (ent.getValue().getNode().getValue() ? "&a" : "&c") + ent.getValue().getNode().getValue() + getNodeExpiryString(ent.getValue().getNode()) + MessageUtils.getAppendableNodeContextString(sender.getPlugin().getLocaleManager(), ent.getValue().getNode());
TextComponent message = LegacyComponentSerializer.INSTANCE.deserialize(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue(), sender.getPlugin())).build();
TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue(), sender.getPlugin())).build();
sender.sendMessage(message);
}
}
@ -170,8 +170,11 @@ public class SearchCommand extends SingleCommand {
}
private static Consumer<ComponentBuilder<?, ?>> makeFancy(String holderName, HolderType holderType, String label, HeldNode<?> perm, LuckPermsPlugin plugin) {
String[] strings = new String[]{"&3> " + (perm.getNode().getValue() ? "&a" : "&c") + perm.getNode().getKey(), " ", "&7Click to remove this node from " + holderName};
HoverEvent hoverEvent = HoverEvent.showText(LegacyComponentSerializer.INSTANCE.deserialize(String.join("\n", strings), CommandManager.AMPERSAND_CHAR));
HoverEvent hoverEvent = HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(
"&3> " + (perm.getNode().getValue() ? "&a" : "&c") + perm.getNode().getKey(),
" ",
"&7Click to remove this node from " + holderName
), CommandManager.AMPERSAND_CHAR));
boolean explicitGlobalContext = !plugin.getConfiguration().getContextsFile().getDefaultContexts().isEmpty();
String command = "/" + label + " " + NodeCommandFactory.generateCommand(perm.getNode(), holderName, holderType, false, explicitGlobalContext);

View File

@ -65,22 +65,22 @@ public enum Dependency {
TEXT(
"net{}kyori",
"text-api",
"3.0.0",
"/d7o/eZkZx/naJE+pMg1KqIzL8TWxWjA4yxjv8/10Cg=",
"3.0.2",
"seZnPElZhfba3XO8/LLUWQHE35kqVM02HpswEVcJqz0=",
Relocation.of("text", "net{}kyori{}text")
),
TEXT_SERIALIZER_GSON(
"net{}kyori",
"text-serializer-gson",
"3.0.0",
"zc1ePBBRCjSoNQiNqsBL+6TYRmaUPyEZtj1LhCtViv0=",
"3.0.2",
"8gJFpnqSHp762TWXn3x5ICLiKg2KgEwEA1FFyOtJ92Y=",
Relocation.of("text", "net{}kyori{}text")
),
TEXT_SERIALIZER_LEGACY(
"net{}kyori",
"text-serializer-legacy",
"3.0.0",
"Zns1sKvALAt3Sn0Px+vENv1XQ9y80E1cSzzDN46C9rQ=",
"3.0.2",
"ks8pZV6ZUHWtwD93Xynyg0KaAMs8CLa61Zb8CaLPsdM=",
Relocation.of("text", "net{}kyori{}text")
),
TEXT_ADAPTER_BUKKIT(

View File

@ -28,9 +28,9 @@ package me.lucko.luckperms.common.locale.message;
import me.lucko.luckperms.common.command.CommandManager;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.TextComponent;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -482,18 +482,10 @@ public enum Message {
Message(String message, boolean showPrefix) {
// rewrite hardcoded placeholders according to their position
this.message = rewritePlaceholders(message);
this.message = TextUtils.rewritePlaceholders(message);
this.showPrefix = showPrefix;
}
private static String rewritePlaceholders(String input) {
int i = 0;
while (input.contains("{}")) {
input = input.replaceFirst("\\{\\}", "{" + i++ + "}");
}
return input;
}
public String getMessage() {
return this.message;
}
@ -525,7 +517,7 @@ public enum Message {
}
public TextComponent asComponent(@Nullable LocaleManager localeManager, Object... objects) {
return LegacyComponentSerializer.INSTANCE.deserialize(format(localeManager, objects), CommandManager.AMPERSAND_CHAR);
return TextUtils.fromLegacy(format(localeManager, objects), CommandManager.AMPERSAND_CHAR);
}
public void send(Sender sender, Object... objects) {

View File

@ -28,9 +28,9 @@ package me.lucko.luckperms.common.sender;
import com.google.common.base.Splitter;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.Component;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.node.Tristate;
import java.lang.ref.WeakReference;
@ -93,7 +93,7 @@ public final class AbstractSender<T> implements Sender {
@Override
public void sendMessage(Component message) {
if (isConsole()) {
sendMessage(LegacyComponentSerializer.INSTANCE.serialize(message));
sendMessage(TextUtils.toLegacy(message));
return;
}

View File

@ -26,9 +26,9 @@
package me.lucko.luckperms.common.sender;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.Component;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.node.Tristate;
import java.util.UUID;
@ -58,7 +58,7 @@ public abstract class DummySender implements Sender {
@Override
public void sendMessage(Component message) {
consumeMessage(LegacyComponentSerializer.INSTANCE.serialize(message));
consumeMessage(TextUtils.toLegacy(message));
}
@Override

View File

@ -0,0 +1,71 @@
/*
* 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.common.util;
import net.kyori.text.Component;
import net.kyori.text.TextComponent;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public final class TextUtils {
private TextUtils() {}
public static String joinNewline(String... strings) {
return joinNewline(Arrays.stream(strings));
}
public static String joinNewline(Stream<String> strings) {
return strings.collect(Collectors.joining("\n"));
}
public static TextComponent fromLegacy(String input, char character) {
return LegacyComponentSerializer.legacy().deserialize(input, character);
}
public static TextComponent fromLegacy(String input) {
return LegacyComponentSerializer.legacy().deserialize(input);
}
public static String toLegacy(Component component, char character) {
return LegacyComponentSerializer.legacy().serialize(component, character);
}
public static String toLegacy(Component component) {
return LegacyComponentSerializer.legacy().serialize(component);
}
public static String rewritePlaceholders(String input) {
int i = 0;
while (input.contains("{}")) {
input = input.replaceFirst("\\{\\}", "{" + i++ + "}");
}
return input;
}
}

View File

@ -34,6 +34,7 @@ import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.StackTracePrinter;
import me.lucko.luckperms.common.util.TextUtils;
import me.lucko.luckperms.common.util.gson.GsonProvider;
import me.lucko.luckperms.common.util.gson.JArray;
import me.lucko.luckperms.common.util.gson.JObject;
@ -45,7 +46,6 @@ import me.lucko.luckperms.common.web.BytebinClient;
import net.kyori.text.TextComponent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.node.Tristate;
import net.luckperms.api.query.QueryMode;
@ -60,7 +60,6 @@ import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.zip.GZIPOutputStream;
/**
@ -233,7 +232,7 @@ public class VerboseListener {
}
// send the message
HoverEvent hoverEvent = HoverEvent.showText(LegacyComponentSerializer.INSTANCE.deserialize(hover.stream().collect(Collectors.joining("\n")), 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

@ -28,9 +28,9 @@ package me.lucko.luckperms.nukkit;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.sender.SenderFactory;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.Component;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.node.Tristate;
import cn.nukkit.Player;
@ -75,7 +75,7 @@ public class NukkitSenderFactory extends SenderFactory<CommandSender> {
@Override
protected void sendMessage(CommandSender sender, Component message) {
// Fallback to legacy format
sendMessage(sender, LegacyComponentSerializer.INSTANCE.serialize(message));
sendMessage(sender, TextUtils.toLegacy(message));
}
@Override

View File

@ -31,10 +31,10 @@ import com.velocitypowered.api.proxy.Player;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.sender.SenderFactory;
import me.lucko.luckperms.common.util.TextUtils;
import me.lucko.luckperms.velocity.service.CompatibilityUtil;
import net.kyori.text.Component;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.node.Tristate;
import java.util.UUID;
@ -62,7 +62,7 @@ public class VelocitySenderFactory extends SenderFactory<CommandSource> {
@Override
protected void sendMessage(CommandSource source, String s) {
sendMessage(source, LegacyComponentSerializer.INSTANCE.deserialize(s));
sendMessage(source, TextUtils.fromLegacy(s));
}
@Override