Replace fanciful with KyoriPowered/text

This commit is contained in:
Luck 2017-06-11 14:46:56 +01:00
parent 3df1ae8ded
commit a9e751b4b8
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
23 changed files with 212 additions and 190 deletions

View File

@ -47,8 +47,8 @@
<shadedPattern>me.lucko.luckperms.lib.gson</shadedPattern> <shadedPattern>me.lucko.luckperms.lib.gson</shadedPattern>
</relocation> </relocation>
<relocation> <relocation>
<pattern>io.github.mkremins.fanciful</pattern> <pattern>net.kyori.text</pattern>
<shadedPattern>me.lucko.luckperms.lib.fanciful</shadedPattern> <shadedPattern>me.lucko.luckperms.lib.text</shadedPattern>
</relocation> </relocation>
</relocations> </relocations>
</configuration> </configuration>

View File

@ -46,8 +46,8 @@
<createDependencyReducedPom>false</createDependencyReducedPom> <createDependencyReducedPom>false</createDependencyReducedPom>
<relocations> <relocations>
<relocation> <relocation>
<pattern>io.github.mkremins.fanciful</pattern> <pattern>net.kyori.text</pattern>
<shadedPattern>me.lucko.luckperms.lib.fanciful</shadedPattern> <shadedPattern>me.lucko.luckperms.lib.text</shadedPattern>
</relocation> </relocation>
</relocations> </relocations>
</configuration> </configuration>

View File

@ -30,11 +30,11 @@ import me.lucko.luckperms.common.commands.sender.SenderFactory;
import me.lucko.luckperms.common.constants.Constants; import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import net.kyori.text.Component;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import io.github.mkremins.fanciful.FancyMessage;
import java.util.UUID; import java.util.UUID;
public class BukkitSenderFactory extends SenderFactory<CommandSender> { public class BukkitSenderFactory extends SenderFactory<CommandSender> {
@ -67,7 +67,7 @@ public class BukkitSenderFactory extends SenderFactory<CommandSender> {
} }
@Override @Override
protected void sendMessage(CommandSender sender, FancyMessage message) { protected void sendMessage(CommandSender sender, Component message) {
messageHandler.sendJsonMessage(sender, message); messageHandler.sendJsonMessage(sender, message);
} }

View File

@ -25,11 +25,14 @@
package me.lucko.luckperms.bukkit.compat; package me.lucko.luckperms.bukkit.compat;
import me.lucko.luckperms.common.constants.Constants;
import net.kyori.text.Component;
import net.kyori.text.serializer.ComponentSerializer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import io.github.mkremins.fanciful.FancyMessage;
public class MessageHandler { public class MessageHandler {
private final BukkitJsonMessageHandler bukkitHandler; private final BukkitJsonMessageHandler bukkitHandler;
private final SpigotJsonMessageHandler spigotHandler; private final SpigotJsonMessageHandler spigotHandler;
@ -39,10 +42,10 @@ public class MessageHandler {
spigotHandler = isSpigot() ? new SpigotJsonMessageHandler() : null; spigotHandler = isSpigot() ? new SpigotJsonMessageHandler() : null;
} }
public void sendJsonMessage(CommandSender sender, FancyMessage message) { public void sendJsonMessage(CommandSender sender, Component message) {
if (ReflectionUtil.isChatCompatible() && sender instanceof Player) { if (ReflectionUtil.isChatCompatible() && sender instanceof Player) {
Player player = (Player) sender; Player player = (Player) sender;
String json = message.exportToJson(); String json = ComponentSerializer.serialize(message);
// Try Bukkit. // Try Bukkit.
if (bukkitHandler.sendJsonMessage(player, json)) { if (bukkitHandler.sendJsonMessage(player, json)) {
@ -56,7 +59,7 @@ public class MessageHandler {
} }
// Fallback to Bukkit // Fallback to Bukkit
sender.sendMessage(message.toOldMessageFormat()); sender.sendMessage(ComponentSerializer.toLegacy(message, Constants.COLOR_CHAR));
} }
private static boolean isSpigot() { private static boolean isSpigot() {

View File

@ -46,8 +46,8 @@
<createDependencyReducedPom>false</createDependencyReducedPom> <createDependencyReducedPom>false</createDependencyReducedPom>
<relocations> <relocations>
<relocation> <relocation>
<pattern>io.github.mkremins.fanciful</pattern> <pattern>net.kyori.text</pattern>
<shadedPattern>me.lucko.luckperms.lib.fanciful</shadedPattern> <shadedPattern>me.lucko.luckperms.lib.text</shadedPattern>
</relocation> </relocation>
</relocations> </relocations>
</configuration> </configuration>

View File

@ -29,12 +29,11 @@ import me.lucko.luckperms.common.commands.sender.SenderFactory;
import me.lucko.luckperms.common.constants.Constants; import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import net.kyori.text.Component;
import net.kyori.text.serializer.ComponentSerializer;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.chat.ComponentSerializer;
import io.github.mkremins.fanciful.FancyMessage;
import java.util.UUID; import java.util.UUID;
@ -65,11 +64,11 @@ public class BungeeSenderFactory extends SenderFactory<CommandSender> {
} }
@Override @Override
protected void sendMessage(CommandSender sender, FancyMessage message) { protected void sendMessage(CommandSender sender, Component message) {
try { try {
sender.sendMessage(ComponentSerializer.parse(message.exportToJson())); sender.sendMessage(net.md_5.bungee.chat.ComponentSerializer.parse(ComponentSerializer.serialize(message)));
} catch (Exception e) { } catch (Exception e) {
sendMessage(sender, message.toOldMessageFormat()); sendMessage(sender, ComponentSerializer.toLegacy(message, Constants.COLOR_CHAR));
} }
} }

View File

@ -35,11 +35,11 @@
<version>${project.version}</version> <version>${project.version}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- fanciful --> <!-- text -->
<dependency> <dependency>
<groupId>io.github.mkremins</groupId> <groupId>net.kyori</groupId>
<artifactId>fanciful</artifactId> <artifactId>text</artifactId>
<version>1.2.5</version> <version>1.12-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!-- HikariCP --> <!-- HikariCP -->

View File

@ -56,12 +56,16 @@ import me.lucko.luckperms.common.commands.impl.user.UserMainCommand;
import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.commands.utils.ArgumentUtils; import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.commands.utils.Util;
import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.TextUtils;
import io.github.mkremins.fanciful.ChatColor; import net.kyori.text.Component;
import io.github.mkremins.fanciful.FancyMessage; import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.serializer.ComponentSerializer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -127,7 +131,7 @@ public class CommandManager {
return executor.submit(() -> { return executor.submit(() -> {
try { try {
return execute(sender, label, args); return execute(sender, label, args);
} catch (Exception e) { } catch (Throwable e) {
plugin.getLog().severe("Exception whilst executing command: " + args.toString()); plugin.getLog().severe("Exception whilst executing command: " + args.toString());
e.printStackTrace(); e.printStackTrace();
return null; return null;
@ -179,7 +183,7 @@ public class CommandManager {
result = main.execute(plugin, sender, null, arguments, label); result = main.execute(plugin, sender, null, arguments, label);
} catch (CommandException e) { } catch (CommandException e) {
result = handleException(e, sender, label, main); result = handleException(e, sender, label, main);
} catch (Exception e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
result = CommandResult.FAILURE; result = CommandResult.FAILURE;
} }
@ -247,23 +251,22 @@ public class CommandManager {
.forEach(c -> { .forEach(c -> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
String permission = (String) c.getPermission().map(p -> ((Permission) p).getExample()).orElse("None"); String permission = (String) c.getPermission().map(p -> ((Permission) p).getExample()).orElse("None");
FancyMessage msg = new FancyMessage("> ").color(c('3')).then().text(String.format(c.getUsage(), label)).color(c('a'))
.formattedTooltip( Component component = ComponentSerializer.parseFromLegacy("&3> &a" + String.format(c.getUsage(), label), Constants.FORMAT_CHAR)
new FancyMessage("Command: ").color(c('b')).then().text(c.getName()).color(c('2')), .applyRecursively(comp -> {
new FancyMessage("Description: ").color(c('b')).then().text(c.getDescription()).color(c('2')), comp.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, ComponentSerializer.parseFromLegacy(TextUtils.joinNewline(
new FancyMessage("Usage: ").color(c('b')).then().text(String.format(c.getUsage(), label)).color(c('2')), "&bCommand: &2" + c.getName(),
new FancyMessage("Permission: ").color(c('b')).then().text(permission).color(c('2')), "&bDescription: &2" + c.getDescription(),
new FancyMessage(" "), "&bUsage: &2" + String.format(c.getUsage(), label),
new FancyMessage("Click to auto-complete.").color(c('7')) "&bPermission: &2" + permission,
) " ",
.suggest(String.format(c.getUsage(), label)); "&7Click to auto-complete."
sender.sendMessage(msg); ), Constants.FORMAT_CHAR)));
comp.clickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, String.format(c.getUsage(), label)));
});
sender.sendMessage(component);
}); });
} }
private static ChatColor c(char c) {
return ChatColor.getByChar(c);
}
public static CommandResult handleException(CommandException e, Sender sender, String label, Command command) { public static CommandResult handleException(CommandException e, Sender sender, String label, Command command) {
if (e instanceof ArgumentUtils.ArgumentException) { if (e instanceof ArgumentUtils.ArgumentException) {

View File

@ -46,8 +46,10 @@ import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.common.utils.Predicates;
import io.github.mkremins.fanciful.ChatColor; import net.kyori.text.Component;
import io.github.mkremins.fanciful.FancyMessage; import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -90,7 +92,12 @@ public class HolderEditor<T extends PermissionHolder> extends SubCommand<T> {
String url = plugin.getConfiguration().get(ConfigKeys.WEB_EDITOR_URL_PATTERN) + id; String url = plugin.getConfiguration().get(ConfigKeys.WEB_EDITOR_URL_PATTERN) + id;
Message.EDITOR_URL.send(sender); Message.EDITOR_URL.send(sender);
sender.sendMessage(new FancyMessage(url).color(ChatColor.getByChar('b')).link(url));
Component message = new TextComponent(url).color('b')
.clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url))
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent("Click to open the editor.").color('7')));
sender.sendMessage(message);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} }

View File

@ -45,14 +45,19 @@ import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.DateUtil; import me.lucko.luckperms.common.utils.DateUtil;
import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.common.utils.TextUtils;
import io.github.mkremins.fanciful.ChatColor; import net.kyori.text.Component;
import io.github.mkremins.fanciful.FancyMessage; import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.serializer.ComponentSerializer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.function.Consumer;
public class PermissionInfo extends SharedSubCommand { public class PermissionInfo extends SharedSubCommand {
public PermissionInfo() { public PermissionInfo() {
@ -86,7 +91,7 @@ public class PermissionInfo extends SharedSubCommand {
} else { } else {
int page = ArgumentUtils.handleIntOrElse(0, args, 1); int page = ArgumentUtils.handleIntOrElse(0, args, 1);
Map.Entry<FancyMessage, String> ent = permNodesToMessage(filter, holder.mergePermissionsToSortedSet(), holder, label, page); Map.Entry<Component, String> ent = permNodesToMessage(filter, holder.mergePermissionsToSortedSet(), holder, label, page);
if (ent.getValue() != null) { if (ent.getValue() != null) {
Message.LISTNODES_WITH_PAGE.send(sender, holder.getFriendlyName(), ent.getValue()); Message.LISTNODES_WITH_PAGE.send(sender, holder.getFriendlyName(), ent.getValue());
sender.sendMessage(ent.getKey()); sender.sendMessage(ent.getKey());
@ -100,7 +105,7 @@ public class PermissionInfo extends SharedSubCommand {
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} }
private static Map.Entry<FancyMessage, String> permNodesToMessage(String filter, SortedSet<LocalizedNode> nodes, PermissionHolder holder, String label, int pageNumber) { private static Map.Entry<Component, String> permNodesToMessage(String filter, SortedSet<LocalizedNode> nodes, PermissionHolder holder, String label, int pageNumber) {
List<Node> l = new ArrayList<>(); List<Node> l = new ArrayList<>();
for (Node node : nodes) { for (Node node : nodes) {
if (filter != null && !node.getPermission().startsWith(filter)) { if (filter != null && !node.getPermission().startsWith(filter)) {
@ -114,7 +119,7 @@ public class PermissionInfo extends SharedSubCommand {
} }
if (l.isEmpty()) { if (l.isEmpty()) {
return Maps.immutableEntry(new FancyMessage("None").color(ChatColor.getByChar('3')), null); return Maps.immutableEntry(new TextComponent("None").color('3'), null);
} }
int index = pageNumber - 1; int index = pageNumber - 1;
@ -127,7 +132,7 @@ public class PermissionInfo extends SharedSubCommand {
List<Node> page = pages.get(index); List<Node> page = pages.get(index);
FancyMessage message = new FancyMessage(""); TextComponent message = new TextComponent("");
String title = "&7(showing page &f" + pageNumber + "&7 of &f" + pages.size() + "&7 - &f" + nodes.size() + "&7 entries"; String title = "&7(showing page &f" + pageNumber + "&7 of &f" + pages.size() + "&7 - &f" + nodes.size() + "&7 entries";
if (filter != null) { if (filter != null) {
title += " - filtered by &f\"" + filter + "\"&7)"; title += " - filtered by &f\"" + filter + "\"&7)";
@ -136,24 +141,19 @@ public class PermissionInfo extends SharedSubCommand {
} }
for (Node node : page) { for (Node node : page) {
message.then("> ").color(ChatColor.getByChar('3')).apply(m -> makeFancy(m, holder, label, node)) String s = "&3> " + (node.getValue() ? "&a" : "&c") + node.getPermission() + Util.getAppendableNodeContextString(node) + "\n";
.then(Util.color(node.getPermission())).color(node.getValue() ? ChatColor.getByChar('a') : ChatColor.getByChar('c')).apply(m -> makeFancy(m, holder, label, node)) message.append(ComponentSerializer.parseFromLegacy(s, Constants.FORMAT_CHAR).applyRecursively(makeFancy(holder, label, node)));
.apply(node, Util::appendNodeContextDescription)
.then("\n");
} }
return Maps.immutableEntry(message, title); return Maps.immutableEntry(message, title);
} }
private static void makeFancy(FancyMessage message, PermissionHolder holder, String label, Node node) { private static Consumer<Component> makeFancy(PermissionHolder holder, String label, Node node) {
message.formattedTooltip( HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, ComponentSerializer.parseFromLegacy(TextUtils.joinNewline(
new FancyMessage("> ") "&3> " + (node.getValue() ? "&a" : "&c") + node.getPermission(),
.color(ChatColor.getByChar('3')) " ",
.then(node.getPermission()) "&7Click to remove this node from " + holder.getFriendlyName()
.color(node.getValue() ? ChatColor.getByChar('a') : ChatColor.getByChar('c')), ), Constants.FORMAT_CHAR));
new FancyMessage(" "),
new FancyMessage("Click to remove this node from " + holder.getFriendlyName()).color(ChatColor.getByChar('7'))
);
boolean group = !(holder instanceof User); boolean group = !(holder instanceof User);
String command = NodeFactory.nodeAsCommand(node, group ? holder.getObjectName() : holder.getFriendlyName(), group) String command = NodeFactory.nodeAsCommand(node, group ? holder.getObjectName() : holder.getFriendlyName(), group)
@ -163,7 +163,10 @@ public class PermissionInfo extends SharedSubCommand {
.replace(" true", "") .replace(" true", "")
.replace(" false", ""); .replace(" false", "");
message.suggest(command); return component -> {
component.hoverEvent(hoverEvent);
component.clickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command));
};
} }
private static String permNodesToString(String filter, SortedSet<LocalizedNode> nodes) { private static String permNodesToString(String filter, SortedSet<LocalizedNode> nodes) {

View File

@ -36,6 +36,7 @@ import me.lucko.luckperms.common.commands.abstraction.SubCommand;
import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.commands.utils.ArgumentUtils; import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.commands.utils.Util;
import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.NodeFactory; import me.lucko.luckperms.common.core.NodeFactory;
@ -43,9 +44,13 @@ import me.lucko.luckperms.common.core.model.Group;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.DateUtil; import me.lucko.luckperms.common.utils.DateUtil;
import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.common.utils.TextUtils;
import io.github.mkremins.fanciful.ChatColor; import net.kyori.text.Component;
import io.github.mkremins.fanciful.FancyMessage; import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.serializer.ComponentSerializer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
@ -53,6 +58,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -90,8 +96,8 @@ public class GroupListMembers extends SubCommand<Group> {
return s; return s;
}); });
Map.Entry<FancyMessage, String> msgUsers = searchUserResultToMessage(matchedUsers, lookupFunc, label, page); Map.Entry<Component, String> msgUsers = searchUserResultToMessage(matchedUsers, lookupFunc, label, page);
Map.Entry<FancyMessage, String> msgGroups = searchGroupResultToMessage(matchedGroups, label, page); Map.Entry<Component, String> msgGroups = searchGroupResultToMessage(matchedGroups, label, page);
if (msgUsers.getValue() != null) { if (msgUsers.getValue() != null) {
Message.SEARCH_SHOWING_USERS_WITH_PAGE.send(sender, msgUsers.getValue()); Message.SEARCH_SHOWING_USERS_WITH_PAGE.send(sender, msgUsers.getValue());
@ -112,9 +118,9 @@ public class GroupListMembers extends SubCommand<Group> {
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} }
private static Map.Entry<FancyMessage, String> searchUserResultToMessage(List<HeldPermission<UUID>> results, Function<UUID, String> uuidLookup, String label, int pageNumber) { private static Map.Entry<Component, String> searchUserResultToMessage(List<HeldPermission<UUID>> results, Function<UUID, String> uuidLookup, String label, int pageNumber) {
if (results.isEmpty()) { if (results.isEmpty()) {
return Maps.immutableEntry(new FancyMessage("None").color(ChatColor.getByChar('3')), null); return Maps.immutableEntry(new TextComponent("None").color('3'), null);
} }
List<HeldPermission<UUID>> sorted = new ArrayList<>(results); List<HeldPermission<UUID>> sorted = new ArrayList<>(results);
@ -133,23 +139,20 @@ public class GroupListMembers extends SubCommand<Group> {
.map(hp -> Maps.immutableEntry(uuidLookup.apply(hp.getHolder()), hp)) .map(hp -> Maps.immutableEntry(uuidLookup.apply(hp.getHolder()), hp))
.collect(Collectors.toList()); .collect(Collectors.toList());
FancyMessage message = new FancyMessage(""); TextComponent message = new TextComponent("");
String title = "&7(page &f" + pageNumber + "&7 of &f" + pages.size() + "&7 - &f" + sorted.size() + "&7 entries)"; String title = "&7(page &f" + pageNumber + "&7 of &f" + pages.size() + "&7 - &f" + sorted.size() + "&7 entries)";
for (Map.Entry<String, HeldPermission<UUID>> ent : uuidMappedPage) { for (Map.Entry<String, HeldPermission<UUID>> ent : uuidMappedPage) {
message.then("> ").color(ChatColor.getByChar('3')).apply(m -> makeFancy(m, ent.getKey(), false, label, ent.getValue())) String s = "&3> &b" + ent.getKey() + " " + getNodeExpiryString(ent.getValue().asNode()) + Util.getAppendableNodeContextString(ent.getValue().asNode()) + "\n";
.then(ent.getKey() + " ").color(ChatColor.getByChar('b')).apply(m -> makeFancy(m, ent.getKey(), false, label, ent.getValue())) message.append(ComponentSerializer.parseFromLegacy(s, Constants.FORMAT_CHAR).applyRecursively(makeFancy(ent.getKey(), false, label, ent.getValue())));
.apply(ent.getValue().asNode(), GroupListMembers::appendNodeExpiry)
.apply(ent.getValue().asNode(), Util::appendNodeContextDescription)
.then("\n");
} }
return Maps.immutableEntry(message, title); return Maps.immutableEntry(message, title);
} }
private static Map.Entry<FancyMessage, String> searchGroupResultToMessage(List<HeldPermission<String>> results, String label, int pageNumber) { private static Map.Entry<Component, String> searchGroupResultToMessage(List<HeldPermission<String>> results, String label, int pageNumber) {
if (results.isEmpty()) { if (results.isEmpty()) {
return Maps.immutableEntry(new FancyMessage("None").color(ChatColor.getByChar('3')), null); return Maps.immutableEntry(new TextComponent("None").color('3'), null);
} }
List<HeldPermission<String>> sorted = new ArrayList<>(results); List<HeldPermission<String>> sorted = new ArrayList<>(results);
@ -165,49 +168,42 @@ public class GroupListMembers extends SubCommand<Group> {
List<HeldPermission<String>> page = pages.get(index); List<HeldPermission<String>> page = pages.get(index);
FancyMessage message = new FancyMessage(""); TextComponent message = new TextComponent("");
String title = "&7(page &f" + pageNumber + "&7 of &f" + pages.size() + "&7 - &f" + sorted.size() + "&7 entries)"; String title = "&7(page &f" + pageNumber + "&7 of &f" + pages.size() + "&7 - &f" + sorted.size() + "&7 entries)";
for (HeldPermission<String> ent : page) { for (HeldPermission<String> ent : page) {
message.then("> ").color(ChatColor.getByChar('3')).apply(m -> makeFancy(m, ent.getHolder(), true, label, ent)) String s = "&3> &b" + ent.getHolder() + " " + getNodeExpiryString(ent.asNode()) + Util.getAppendableNodeContextString(ent.asNode()) + "\n";
.then(ent.getHolder() + " ").color(ChatColor.getByChar('b')).apply(m -> makeFancy(m, ent.getHolder(), true, label, ent)) message.append(ComponentSerializer.parseFromLegacy(s, Constants.FORMAT_CHAR).applyRecursively(makeFancy(ent.getHolder(), true, label, ent)));
.apply(ent.asNode(), GroupListMembers::appendNodeExpiry)
.apply(ent.asNode(), Util::appendNodeContextDescription)
.then("\n");
} }
return Maps.immutableEntry(message, title); return Maps.immutableEntry(message, title);
} }
private static void appendNodeExpiry(FancyMessage message, Node node) { private static String getNodeExpiryString(Node node) {
if (!node.isTemporary()) { if (!node.isTemporary()) {
return; return "";
} }
message.then(" (").color(ChatColor.getByChar('8')) return " &8(&7expires in " + DateUtil.formatDateDiff(node.getExpiryUnixTime()) + "&8)";
.then("expires in " + DateUtil.formatDateDiff(node.getExpiryUnixTime())).color(ChatColor.getByChar('7'))
.then(")").color(ChatColor.getByChar('8'));
} }
private static void makeFancy(FancyMessage message, String holderName, boolean group, String label, HeldPermission<?> perm) { private static Consumer<Component> makeFancy(String holderName, boolean group, String label, HeldPermission<?> perm) {
Node node = perm.asNode(); HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, ComponentSerializer.parseFromLegacy(TextUtils.joinNewline(
"&3> " + (perm.asNode().getValue() ? "&a" : "&c") + perm.asNode().getGroupName(),
" ",
"&7Click to remove this parent from " + holderName
), Constants.FORMAT_CHAR));
message = message.formattedTooltip( String command = NodeFactory.nodeAsCommand(perm.asNode(), holderName, group)
new FancyMessage("> ")
.color(ChatColor.getByChar('3'))
.then(node.getPermission())
.color(node.getValue() ? ChatColor.getByChar('a') : ChatColor.getByChar('c')),
new FancyMessage(" "),
new FancyMessage("Click to remove this parent from " + holderName).color(ChatColor.getByChar('7'))
);
String command = NodeFactory.nodeAsCommand(node, holderName, group)
.replace("/luckperms", "/" + label) .replace("/luckperms", "/" + label)
.replace("permission set", "permission unset") .replace("permission set", "permission unset")
.replace("parent add", "parent remove") .replace("parent add", "parent remove")
.replace(" true", "") .replace(" true", "")
.replace(" false", ""); .replace(" false", "");
message.suggest(command); return component -> {
component.hoverEvent(hoverEvent);
component.clickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command));
};
} }
} }

View File

@ -37,15 +37,20 @@ import me.lucko.luckperms.common.commands.abstraction.SubCommand;
import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.commands.utils.ArgumentUtils; import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.commands.utils.Util;
import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.NodeFactory; import me.lucko.luckperms.common.core.NodeFactory;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.DateUtil; import me.lucko.luckperms.common.utils.DateUtil;
import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.common.utils.TextUtils;
import io.github.mkremins.fanciful.ChatColor; import net.kyori.text.Component;
import io.github.mkremins.fanciful.FancyMessage; import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.serializer.ComponentSerializer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
@ -53,6 +58,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -91,8 +97,8 @@ public class SearchCommand extends SingleCommand {
return s; return s;
}); });
Map.Entry<FancyMessage, String> msgUsers = searchUserResultToMessage(matchedUsers, lookupFunc, label, page); Map.Entry<Component, String> msgUsers = searchUserResultToMessage(matchedUsers, lookupFunc, label, page);
Map.Entry<FancyMessage, String> msgGroups = searchGroupResultToMessage(matchedGroups, label, page); Map.Entry<Component, String> msgGroups = searchGroupResultToMessage(matchedGroups, label, page);
if (msgUsers.getValue() != null) { if (msgUsers.getValue() != null) {
Message.SEARCH_SHOWING_USERS_WITH_PAGE.send(sender, msgUsers.getValue()); Message.SEARCH_SHOWING_USERS_WITH_PAGE.send(sender, msgUsers.getValue());
@ -118,9 +124,9 @@ public class SearchCommand extends SingleCommand {
return SubCommand.getPermissionTabComplete(args, plugin.getPermissionVault()); return SubCommand.getPermissionTabComplete(args, plugin.getPermissionVault());
} }
private static Map.Entry<FancyMessage, String> searchUserResultToMessage(List<HeldPermission<UUID>> results, Function<UUID, String> uuidLookup, String label, int pageNumber) { private static Map.Entry<Component, String> searchUserResultToMessage(List<HeldPermission<UUID>> results, Function<UUID, String> uuidLookup, String label, int pageNumber) {
if (results.isEmpty()) { if (results.isEmpty()) {
return Maps.immutableEntry(new FancyMessage("None").color(ChatColor.getByChar('3')), null); return Maps.immutableEntry(new TextComponent("None").color('3'), null);
} }
List<HeldPermission<UUID>> sorted = new ArrayList<>(results); List<HeldPermission<UUID>> sorted = new ArrayList<>(results);
@ -139,25 +145,20 @@ public class SearchCommand extends SingleCommand {
.map(hp -> Maps.immutableEntry(uuidLookup.apply(hp.getHolder()), hp)) .map(hp -> Maps.immutableEntry(uuidLookup.apply(hp.getHolder()), hp))
.collect(Collectors.toList()); .collect(Collectors.toList());
FancyMessage message = new FancyMessage(""); TextComponent message = new TextComponent("");
String title = "&7(page &f" + pageNumber + "&7 of &f" + pages.size() + "&7 - &f" + sorted.size() + "&7 entries)"; String title = "&7(page &f" + pageNumber + "&7 of &f" + pages.size() + "&7 - &f" + sorted.size() + "&7 entries)";
for (Map.Entry<String, HeldPermission<UUID>> ent : uuidMappedPage) { for (Map.Entry<String, HeldPermission<UUID>> ent : uuidMappedPage) {
message.then("> ").color(ChatColor.getByChar('3')).apply(m -> makeFancy(m, ent.getKey(), false, label, ent.getValue())) String s = "&3> &b" + ent.getKey() + " &7- " + (ent.getValue().getValue() ? "&a" : "&c") + ent.getValue().getValue() + getNodeExpiryString(ent.getValue().asNode()) + Util.getAppendableNodeContextString(ent.getValue().asNode()) + "\n";
.then(ent.getKey()).color(ChatColor.getByChar('b')).apply(m -> makeFancy(m, ent.getKey(), false, label, ent.getValue())) message.append(ComponentSerializer.parseFromLegacy(s, Constants.FORMAT_CHAR).applyRecursively(makeFancy(ent.getKey(), false, label, ent.getValue())));
.then(" - ").color(ChatColor.getByChar('7')).apply(m -> makeFancy(m, ent.getKey(), false, label, ent.getValue()))
.then("" + ent.getValue().getValue()).color(ent.getValue().getValue() ? ChatColor.getByChar('a') : ChatColor.getByChar('c')).apply(m -> makeFancy(m, ent.getKey(), false, label, ent.getValue()))
.apply(ent.getValue().asNode(), SearchCommand::appendNodeExpiry)
.apply(ent.getValue().asNode(), Util::appendNodeContextDescription)
.then("\n");
} }
return Maps.immutableEntry(message, title); return Maps.immutableEntry(message, title);
} }
private static Map.Entry<FancyMessage, String> searchGroupResultToMessage(List<HeldPermission<String>> results, String label, int pageNumber) { private static Map.Entry<Component, String> searchGroupResultToMessage(List<HeldPermission<String>> results, String label, int pageNumber) {
if (results.isEmpty()) { if (results.isEmpty()) {
return Maps.immutableEntry(new FancyMessage("None").color(ChatColor.getByChar('3')), null); return Maps.immutableEntry(new TextComponent("None").color('3'), null);
} }
List<HeldPermission<String>> sorted = new ArrayList<>(results); List<HeldPermission<String>> sorted = new ArrayList<>(results);
@ -173,51 +174,42 @@ public class SearchCommand extends SingleCommand {
List<HeldPermission<String>> page = pages.get(index); List<HeldPermission<String>> page = pages.get(index);
FancyMessage message = new FancyMessage(""); TextComponent message = new TextComponent("");
String title = "&7(page &f" + pageNumber + "&7 of &f" + pages.size() + "&7 - &f" + sorted.size() + "&7 entries)"; String title = "&7(page &f" + pageNumber + "&7 of &f" + pages.size() + "&7 - &f" + sorted.size() + "&7 entries)";
for (HeldPermission<String> ent : page) { for (HeldPermission<String> ent : page) {
message.then("> ").color(ChatColor.getByChar('3')).apply(m -> makeFancy(m, ent.getHolder(), true, label, ent)) String s = "&3> &b" + ent.getHolder() + " &7- " + (ent.getValue() ? "&a" : "&c") + ent.getValue() + getNodeExpiryString(ent.asNode()) + Util.getAppendableNodeContextString(ent.asNode()) + "\n";
.then(ent.getHolder()).color(ChatColor.getByChar('b')).apply(m -> makeFancy(m, ent.getHolder(), true, label, ent)) message.append(ComponentSerializer.parseFromLegacy(s, Constants.FORMAT_CHAR).applyRecursively(makeFancy(ent.getHolder(), true, label, ent)));
.then(" - ").color(ChatColor.getByChar('7')).apply(m -> makeFancy(m, ent.getHolder(), true, label, ent))
.then("" + ent.getValue()).color(ent.getValue() ? ChatColor.getByChar('a') : ChatColor.getByChar('c')).apply(m -> makeFancy(m, ent.getHolder(), true, label, ent))
.apply(ent.asNode(), SearchCommand::appendNodeExpiry)
.apply(ent.asNode(), Util::appendNodeContextDescription)
.then("\n");
} }
return Maps.immutableEntry(message, title); return Maps.immutableEntry(message, title);
} }
private static void appendNodeExpiry(FancyMessage message, Node node) { private static String getNodeExpiryString(Node node) {
if (!node.isTemporary()) { if (!node.isTemporary()) {
return; return "";
} }
message.then(" (").color(ChatColor.getByChar('8')) return " &8(&7expires in " + DateUtil.formatDateDiff(node.getExpiryUnixTime()) + "&8)";
.then("expires in " + DateUtil.formatDateDiff(node.getExpiryUnixTime())).color(ChatColor.getByChar('7'))
.then(")").color(ChatColor.getByChar('8'));
} }
private static void makeFancy(FancyMessage message, String holderName, boolean group, String label, HeldPermission<?> perm) { private static Consumer<Component> makeFancy(String holderName, boolean group, String label, HeldPermission<?> perm) {
Node node = perm.asNode(); HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, ComponentSerializer.parseFromLegacy(TextUtils.joinNewline(
"&3> " + (perm.asNode().getValue() ? "&a" : "&c") + perm.asNode().getPermission(),
" ",
"&7Click to remove this node from " + holderName
), Constants.FORMAT_CHAR));
message = message.formattedTooltip( String command = NodeFactory.nodeAsCommand(perm.asNode(), holderName, group)
new FancyMessage("> ")
.color(ChatColor.getByChar('3'))
.then(node.getPermission())
.color(node.getValue() ? ChatColor.getByChar('a') : ChatColor.getByChar('c')),
new FancyMessage(" "),
new FancyMessage("Click to remove this node from " + holderName).color(ChatColor.getByChar('7'))
);
String command = NodeFactory.nodeAsCommand(node, holderName, group)
.replace("/luckperms", "/" + label) .replace("/luckperms", "/" + label)
.replace("permission set", "permission unset") .replace("permission set", "permission unset")
.replace("parent add", "parent remove") .replace("parent add", "parent remove")
.replace(" true", "") .replace(" true", "")
.replace(" false", ""); .replace(" false", "");
message.suggest(command); return component -> {
component.hoverEvent(hoverEvent);
component.clickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command));
};
} }
} }

View File

@ -41,8 +41,10 @@ import me.lucko.luckperms.common.treeview.TreeView;
import me.lucko.luckperms.common.treeview.TreeViewBuilder; import me.lucko.luckperms.common.treeview.TreeViewBuilder;
import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.common.utils.Predicates;
import io.github.mkremins.fanciful.ChatColor; import net.kyori.text.Component;
import io.github.mkremins.fanciful.FancyMessage; import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -105,7 +107,12 @@ public class TreeCommand extends SingleCommand {
} }
Message.TREE_URL.send(sender); Message.TREE_URL.send(sender);
sender.sendMessage(new FancyMessage(url).color(ChatColor.getByChar('b')).link(url));
Component message = new TextComponent(url).color('b')
.clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url))
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent("Click to open the tree view.").color('7')));
sender.sendMessage(message);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} }
@ -124,7 +131,12 @@ public class TreeCommand extends SingleCommand {
} }
Message.TREE_URL.send(sender); Message.TREE_URL.send(sender);
sender.sendMessage(new FancyMessage(url).color(ChatColor.getByChar('b')).link(url));
Component message = new TextComponent(url).color('b')
.clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url))
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent("Click to open the tree view.").color('7')));
sender.sendMessage(message);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} }
} }

View File

@ -37,8 +37,10 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.common.verbose.VerboseListener; import me.lucko.luckperms.common.verbose.VerboseListener;
import io.github.mkremins.fanciful.ChatColor; import net.kyori.text.Component;
import io.github.mkremins.fanciful.FancyMessage; import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -114,7 +116,12 @@ public class VerboseCommand extends SingleCommand {
} }
Message.VERBOSE_RECORDING_URL.send(sender); Message.VERBOSE_RECORDING_URL.send(sender);
sender.sendMessage(new FancyMessage(url).color(ChatColor.getByChar('b')).link(url));
Component message = new TextComponent(url).color('b')
.clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url))
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent("Click to open the results page.").color('7')));
sender.sendMessage(message);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} }
} else { } else {

View File

@ -34,7 +34,8 @@ import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import io.github.mkremins.fanciful.FancyMessage; import net.kyori.text.Component;
import net.kyori.text.serializer.ComponentSerializer;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.UUID; import java.util.UUID;
@ -81,9 +82,9 @@ public final class AbstractSender<T> implements Sender {
} }
@Override @Override
public void sendMessage(FancyMessage message) { public void sendMessage(Component message) {
if (isConsole()) { if (isConsole()) {
sendMessage(message.toOldMessageFormat()); sendMessage(ComponentSerializer.toLegacy(message, Constants.COLOR_CHAR));
return; return;
} }

View File

@ -29,7 +29,7 @@ import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import io.github.mkremins.fanciful.FancyMessage; import net.kyori.text.Component;
import java.util.UUID; import java.util.UUID;
@ -71,7 +71,7 @@ public interface Sender {
* *
* @param message the message to send. * @param message the message to send.
*/ */
void sendMessage(FancyMessage message); void sendMessage(Component message);
/** /**
* Check if the Sender has a permission. * Check if the Sender has a permission.

View File

@ -29,7 +29,7 @@ import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import io.github.mkremins.fanciful.FancyMessage; import net.kyori.text.Component;
import java.util.UUID; import java.util.UUID;
@ -48,7 +48,7 @@ public abstract class SenderFactory<T> {
protected abstract void sendMessage(T t, String s); protected abstract void sendMessage(T t, String s);
protected abstract void sendMessage(T t, FancyMessage message); protected abstract void sendMessage(T t, Component message);
protected abstract boolean hasPermission(T t, String node); protected abstract boolean hasPermission(T t, String node);

View File

@ -27,16 +27,12 @@ package me.lucko.luckperms.common.commands.utils;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import com.google.common.collect.Maps;
import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Message;
import io.github.mkremins.fanciful.FancyMessage;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
@ -238,18 +234,6 @@ public class Util {
return sb.toString(); return sb.toString();
} }
public static void appendNodeContextDescription(FancyMessage message, Node node) {
if (node.isServerSpecific()) {
message.then(" ").apply(Maps.immutableEntry("server", node.getServer().get()), Util::appendContext);
}
if (node.isWorldSpecific()) {
message.then(" ").apply(Maps.immutableEntry("world", node.getWorld().get()), Util::appendContext);
}
for (Map.Entry<String, String> c : node.getContexts().toSet()) {
message.then(" ").apply(c, Util::appendContext);
}
}
/** /**
* Converts a context pair to a formatted string, surrounded by ( ) brackets. * Converts a context pair to a formatted string, surrounded by ( ) brackets.
* *
@ -261,10 +245,6 @@ public class Util {
return Message.CONTEXT_PAIR.asString(null, key, value); return Message.CONTEXT_PAIR.asString(null, key, value);
} }
public static void appendContext(FancyMessage message, Map.Entry<String, String> ent) {
message.addAll(FancyMessage.fromLegacyText(contextToString(ent.getKey(), ent.getValue())));
}
public static String contextSetToString(ContextSet set) { public static String contextSetToString(ContextSet set) {
if (set.isEmpty()) { if (set.isEmpty()) {
return Message.CONTEXT_PAIR__GLOBAL_INLINE.asString(null); return Message.CONTEXT_PAIR__GLOBAL_INLINE.asString(null);

View File

@ -37,5 +37,7 @@ public class Constants {
public static final UUID IMPORT_UUID = UUID.fromString("11111111-1111-1111-1111-111111111111"); public static final UUID IMPORT_UUID = UUID.fromString("11111111-1111-1111-1111-111111111111");
public static final String IMPORT_NAME = "Import"; public static final String IMPORT_NAME = "Import";
public static final String LOG_FORMAT = "&8(&e%s&8) [&a%s&8] (&b%s&8) &7--> &f%s"; public static final String LOG_FORMAT = "&8(&e%s&8) [&a%s&8] (&b%s&8) &7--> &f%s";
public static final char COLOR_CHAR = '\u00A7';
public static final char FORMAT_CHAR = '&';
} }

View File

@ -42,7 +42,8 @@ import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.DateUtil; import me.lucko.luckperms.common.utils.DateUtil;
import io.github.mkremins.fanciful.FancyMessage; import net.kyori.text.Component;
import net.kyori.text.serializer.ComponentSerializer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -203,8 +204,8 @@ public class Importer implements Runnable {
} }
@Override @Override
public void sendMessage(FancyMessage message) { public void sendMessage(Component message) {
logMessage(message.toOldMessageFormat()); logMessage(ComponentSerializer.toLegacy(message, Constants.COLOR_CHAR));
} }
@Override @Override

View File

@ -0,0 +1,15 @@
package me.lucko.luckperms.common.utils;
import lombok.experimental.UtilityClass;
import java.util.Arrays;
import java.util.stream.Collectors;
@UtilityClass
public class TextUtils {
public String joinNewline(String... strings) {
return Arrays.stream(strings).collect(Collectors.joining("\n"));
}
}

View File

@ -46,8 +46,8 @@
<createDependencyReducedPom>false</createDependencyReducedPom> <createDependencyReducedPom>false</createDependencyReducedPom>
<relocations> <relocations>
<relocation> <relocation>
<pattern>io.github.mkremins.fanciful</pattern> <pattern>net.kyori.text</pattern>
<shadedPattern>me.lucko.luckperms.lib.fanciful</shadedPattern> <shadedPattern>me.lucko.luckperms.lib.text</shadedPattern>
</relocation> </relocation>
</relocations> </relocations>
</configuration> </configuration>

View File

@ -29,12 +29,13 @@ import me.lucko.luckperms.common.commands.sender.SenderFactory;
import me.lucko.luckperms.common.constants.Constants; import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import net.kyori.text.Component;
import net.kyori.text.serializer.ComponentSerializer;
import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.text.serializer.TextSerializers; import org.spongepowered.api.text.serializer.TextSerializers;
import io.github.mkremins.fanciful.FancyMessage;
import java.util.UUID; import java.util.UUID;
public class SpongeSenderFactory extends SenderFactory<CommandSource> { public class SpongeSenderFactory extends SenderFactory<CommandSource> {
@ -65,11 +66,11 @@ public class SpongeSenderFactory extends SenderFactory<CommandSource> {
} }
@Override @Override
protected void sendMessage(CommandSource source, FancyMessage message) { protected void sendMessage(CommandSource source, Component message) {
try { try {
source.sendMessage(TextSerializers.JSON.deserialize(message.exportToJson())); source.sendMessage(TextSerializers.JSON.deserialize(ComponentSerializer.serialize(message)));
} catch (Exception e) { } catch (Exception e) {
sendMessage(source, message.toOldMessageFormat()); sendMessage(source, ComponentSerializer.toLegacy(message, Constants.COLOR_CHAR));
} }
} }