From e4782a35428ed24ec460b47de5bf572eb59deba5 Mon Sep 17 00:00:00 2001 From: Video Date: Sun, 26 Mar 2023 16:28:12 -0600 Subject: [PATCH] Changes several commands to use Adventure --- .../command/Command_consolesay.java | 14 +++++++++----- .../totalfreedommod/command/Command_freeze.java | 13 +++++++++++-- .../totalfreedommod/command/Command_rawsay.java | 2 +- .../totalfreedom/totalfreedommod/util/FUtil.java | 2 ++ 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_consolesay.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_consolesay.java index 986acdfb..de4664dc 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_consolesay.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_consolesay.java @@ -1,7 +1,8 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.rank.Rank; -import me.totalfreedom.totalfreedommod.util.FUtil; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -21,12 +22,15 @@ public class Command_consolesay extends FreedomCommand return false; } - String message = StringUtils.join(args, " "); - FUtil.bcastMsg(String.format("§7[CONSOLE] §c%s §8» §f%s", sender.getName(), StringUtils.join(args, " "))); + server.broadcast(Component.text("[CONSOLE] ", NamedTextColor.GRAY) + .append(Component.text(sender.getName(), NamedTextColor.RED)) + .append(Component.text("» ", NamedTextColor.DARK_GRAY)) + .append(Component.text(StringUtils.join(args, " "), NamedTextColor.WHITE))); - if (plugin.dc != null) { + if (plugin.dc != null) + { + String message = StringUtils.join(args, " "); plugin.dc.messageChatChannel("[CONSOLE] " + sender.getName() + " \u00BB " + ChatColor.stripColor(message), true); - } return true; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_freeze.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_freeze.java index 6f0597d9..8f4b83f7 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_freeze.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_freeze.java @@ -3,11 +3,16 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.freeze.FreezeData; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.title.Title; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.time.Duration; + @CommandPermissions(rank = Rank.ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Freeze/Unfreeze a specified player, or all non-admins on the server.", usage = "/ [target | purge]", aliases = "fr") public class Command_freeze extends FreedomCommand @@ -33,7 +38,9 @@ public class Command_freeze extends FreedomCommand { if (!isAdmin(player)) { - player.sendTitle(ChatColor.RED + "You've been globally frozen.", ChatColor.YELLOW + "Please be patient and you will be unfrozen shortly.", 20, 100, 60); + player.showTitle(Title.title(Component.text("You have been frozen.", NamedTextColor.RED), + Component.text("Please be patient and you will be unfrozen shortly.", NamedTextColor.YELLOW), + Title.Times.of(Duration.ofSeconds(1), Duration.ofSeconds(5), Duration.ofSeconds(3)))); msg(player, "You have been globally frozen due to an OP breaking the rules, please wait and you will be unfrozen soon.", ChatColor.RED); } } @@ -48,7 +55,9 @@ public class Command_freeze extends FreedomCommand { if (!isAdmin(player)) { - player.sendTitle(ChatColor.GREEN + "You've been unfrozen.", ChatColor.YELLOW + "You may now move again.", 20, 100, 60); + player.showTitle(Title.title(Component.text("You have been unfrozen.", NamedTextColor.GREEN), + Component.text("You may now move again.", NamedTextColor.YELLOW), + Title.Times.of(Duration.ofSeconds(1), Duration.ofSeconds(5), Duration.ofSeconds(3)))); } } plugin.fm.purge(); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rawsay.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rawsay.java index 3a3df6c8..a95a1d7c 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rawsay.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rawsay.java @@ -17,7 +17,7 @@ public class Command_rawsay extends FreedomCommand { if (args.length > 0) { - FUtil.bcastMsg(FUtil.colorize(StringUtils.join(args, " "))); + server.broadcast(FUtil.LEGACY_AMPERSAND.deserialize(StringUtils.join(args, " "))); } return true; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java index 512c69ea..c9f9e3e6 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java @@ -3,6 +3,7 @@ package me.totalfreedom.totalfreedommod.util; import com.earth2me.essentials.utils.DateUtil; import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.WordUtils; import org.bukkit.*; @@ -71,6 +72,7 @@ public class FUtil "Taahh", "G6_", "ayunami2000"); + public static final LegacyComponentSerializer LEGACY_AMPERSAND = LegacyComponentSerializer.legacyAmpersand(); public static final Map CHAT_COLOR_NAMES = new HashMap<>(); public static final List CHAT_COLOR_POOL = Arrays.asList( ChatColor.DARK_RED,