Changes several commands to use Adventure

This commit is contained in:
Video 2023-03-26 16:28:12 -06:00
parent 77d65e80f8
commit e4782a3542
4 changed files with 23 additions and 8 deletions

View File

@ -1,7 +1,8 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank; 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.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -21,12 +22,15 @@ public class Command_consolesay extends FreedomCommand
return false; return false;
} }
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)
{
String message = StringUtils.join(args, " "); String message = StringUtils.join(args, " ");
FUtil.bcastMsg(String.format("§7[CONSOLE] §c%s §8» §f%s", sender.getName(), StringUtils.join(args, " ")));
if (plugin.dc != null) {
plugin.dc.messageChatChannel("[CONSOLE] " + sender.getName() + " \u00BB " + ChatColor.stripColor(message), true); plugin.dc.messageChatChannel("[CONSOLE] " + sender.getName() + " \u00BB " + ChatColor.stripColor(message), true);
} }
return true; return true;

View File

@ -3,11 +3,16 @@ package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.freeze.FreezeData; import me.totalfreedom.totalfreedommod.freeze.FreezeData;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil; 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.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.time.Duration;
@CommandPermissions(rank = Rank.ADMIN, source = SourceType.BOTH) @CommandPermissions(rank = Rank.ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Freeze/Unfreeze a specified player, or all non-admins on the server.", usage = "/<command> [target | purge]", aliases = "fr") @CommandParameters(description = "Freeze/Unfreeze a specified player, or all non-admins on the server.", usage = "/<command> [target | purge]", aliases = "fr")
public class Command_freeze extends FreedomCommand public class Command_freeze extends FreedomCommand
@ -33,7 +38,9 @@ public class Command_freeze extends FreedomCommand
{ {
if (!isAdmin(player)) 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); 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)) 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(); plugin.fm.purge();

View File

@ -17,7 +17,7 @@ public class Command_rawsay extends FreedomCommand
{ {
if (args.length > 0) if (args.length > 0)
{ {
FUtil.bcastMsg(FUtil.colorize(StringUtils.join(args, " "))); server.broadcast(FUtil.LEGACY_AMPERSAND.deserialize(StringUtils.join(args, " ")));
} }
return true; return true;

View File

@ -3,6 +3,7 @@ package me.totalfreedom.totalfreedommod.util;
import com.earth2me.essentials.utils.DateUtil; import com.earth2me.essentials.utils.DateUtil;
import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.WordUtils; import org.apache.commons.lang.WordUtils;
import org.bukkit.*; import org.bukkit.*;
@ -71,6 +72,7 @@ public class FUtil
"Taahh", "Taahh",
"G6_", "G6_",
"ayunami2000"); "ayunami2000");
public static final LegacyComponentSerializer LEGACY_AMPERSAND = LegacyComponentSerializer.legacyAmpersand();
public static final Map<String, ChatColor> CHAT_COLOR_NAMES = new HashMap<>(); public static final Map<String, ChatColor> CHAT_COLOR_NAMES = new HashMap<>();
public static final List<ChatColor> CHAT_COLOR_POOL = Arrays.asList( public static final List<ChatColor> CHAT_COLOR_POOL = Arrays.asList(
ChatColor.DARK_RED, ChatColor.DARK_RED,