diff --git a/src/main/java/dev/xdpxi/xdlib/api/plugin/chatUtils.java b/src/main/java/dev/xdpxi/xdlib/api/plugin/chatUtils.java index e1c1b42..ab05472 100644 --- a/src/main/java/dev/xdpxi/xdlib/api/plugin/chatUtils.java +++ b/src/main/java/dev/xdpxi/xdlib/api/plugin/chatUtils.java @@ -2,6 +2,7 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import net.kyori.adventure.text.Component; public class chatUtils { public static void sendMessageToAll(String message) { @@ -9,7 +10,6 @@ public static void sendMessageToAll(String message) { player.sendMessage(message); } } - public static void sendMessageToOps(String message) { for (Player player : Bukkit.getOnlinePlayers()) { if (player.isOp()) { @@ -17,4 +17,17 @@ public static void sendMessageToOps(String message) { } } } + public static void sendMessageToAll(Component message) { + for (Player player : Bukkit.getOnlinePlayers()) { + player.sendMessage(message); + } + } + + public static void sendMessageToOps(Component message) { + for (Player player : Bukkit.getOnlinePlayers()) { + if (player.isOp()) { + player.sendMessage(message); + } + } + } } \ No newline at end of file diff --git a/src/main/java/dev/xdpxi/xdlib/plugin/joinLeaveListener.java b/src/main/java/dev/xdpxi/xdlib/plugin/joinLeaveListener.java index 6887b67..7ed1b80 100644 --- a/src/main/java/dev/xdpxi/xdlib/plugin/joinLeaveListener.java +++ b/src/main/java/dev/xdpxi/xdlib/plugin/joinLeaveListener.java @@ -1,11 +1,13 @@ package dev.xdpxi.xdlib.plugin; -import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextDecoration; public class joinLeaveListener implements Listener { private final xdlib plugin; @@ -16,18 +18,29 @@ public joinLeaveListener(xdlib plugin) { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { - event.setJoinMessage(ChatColor.GREEN + ">>> " + ChatColor.WHITE + event.getPlayer().getName()); + event.joinMessage(Component.text(">>> " + event.getPlayer().getName()) + .color(NamedTextColor.WHITE) + .decoration(TextDecoration.BOLD, false)); Player player = event.getPlayer(); if (player.isOp()) { if (updateChecker.isUpdate()) { - player.sendMessage(ChatColor.RED + "[" + ChatColor.GOLD + "XDLib" + ChatColor.RED + "]" + ChatColor.DARK_GRAY + " - " + ChatColor.YELLOW + "An update is available!"); + player.sendMessage(Component.text() + .append(Component.text("[", NamedTextColor.RED)) + .append(Component.text("XDLib", NamedTextColor.GOLD)) + .append(Component.text("]", NamedTextColor.RED)) + .append(Component.text(" - ", NamedTextColor.DARK_GRAY)) + .append(Component.text("An update is available!", NamedTextColor.YELLOW)) + .build()); } } } @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - event.setQuitMessage(ChatColor.RED + "<<< " + ChatColor.WHITE + event.getPlayer().getName()); + event.quitMessage(Component.text() + .append(Component.text("<<< ", NamedTextColor.RED)) + .append(Component.text(event.getPlayer().getName(), NamedTextColor.WHITE)) + .build()); } } \ No newline at end of file diff --git a/src/main/java/dev/xdpxi/xdlib/plugin/tpaCommand.java b/src/main/java/dev/xdpxi/xdlib/plugin/tpaCommand.java index c675c30..a0cfde3 100644 --- a/src/main/java/dev/xdpxi/xdlib/plugin/tpaCommand.java +++ b/src/main/java/dev/xdpxi/xdlib/plugin/tpaCommand.java @@ -3,7 +3,6 @@ import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -12,6 +11,9 @@ import java.util.HashMap; import java.util.UUID; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + public class tpaCommand implements CommandExecutor { private final HashMap teleportRequests = new HashMap<>(); @@ -48,51 +50,53 @@ public boolean onCommand(CommandSender sender, Command command, String label, St private void handleAccept(Player player) { UUID requesterUUID = teleportRequests.remove(player.getUniqueId()); if (requesterUUID == null) { - player.sendMessage(ChatColor.RED + "No teleport request found."); + player.sendMessage(Component.text("No teleport request found.", NamedTextColor.RED)); return; } Player requester = Bukkit.getPlayer(requesterUUID); if (requester == null) { - player.sendMessage(ChatColor.RED + "Player not found."); + player.sendMessage(Component.text("Player not found.", NamedTextColor.RED)); return; } requester.teleport(player.getLocation()); - player.sendMessage(ChatColor.GOLD + "Teleporting..."); - requester.sendMessage(ChatColor.GOLD + "Teleport request " + ChatColor.GREEN + "accepted" + ChatColor.GOLD + " by " + ChatColor.GREEN + player.getName() + ChatColor.GOLD + "."); + player.sendMessage(Component.text("Teleporting...", NamedTextColor.GOLD)); + requester.sendMessage(Component.text("Teleport request accepted by " + player.getName(), NamedTextColor.GOLD)); } private void handleDecline(Player player) { UUID requesterUUID = teleportRequests.remove(player.getUniqueId()); if (requesterUUID == null) { - player.sendMessage(ChatColor.RED + "No teleport request found."); + player.sendMessage(Component.text("No teleport request found.", NamedTextColor.RED)); return; } Player requester = Bukkit.getPlayer(requesterUUID); if (requester == null) { - player.sendMessage(ChatColor.RED + "Player not found."); + player.sendMessage(Component.text("Player not found.", NamedTextColor.RED)); return; } - player.sendMessage(ChatColor.GOLD + "Teleport request " + ChatColor.RED + "declined" + ChatColor.GOLD + "."); - requester.sendMessage(ChatColor.GOLD + "Teleport request" + ChatColor.RED + " declined" + ChatColor.GOLD + " by " + ChatColor.GREEN + player.getName()); + player.sendMessage(Component.text("Teleport request declined.", NamedTextColor.GOLD)); + requester.sendMessage(Component.text("Teleport request declined by " + player.getName(), NamedTextColor.GOLD)); } private void handleTpaRequest(Player player, String targetName) { Player target = Bukkit.getPlayer(targetName); if (target == null) { - player.sendMessage(ChatColor.RED + "Player not found."); + player.sendMessage(Component.text("Player not found.", NamedTextColor.RED)); return; } teleportRequests.put(target.getUniqueId(), player.getUniqueId()); - TextComponent message = new TextComponent(ChatColor.GREEN + player.getName() + ChatColor.GOLD + " has requested to teleport to you. \n"); - TextComponent accept = new TextComponent(ChatColor.GREEN + "[Accept]"); + TextComponent message = new TextComponent(player.getName() + " has requested to teleport to you. \n"); + TextComponent accept = new TextComponent("[Accept]"); + accept.setColor(net.md_5.bungee.api.ChatColor.GREEN); accept.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tpa accept")); - TextComponent decline = new TextComponent(ChatColor.RED + "[Decline]"); + TextComponent decline = new TextComponent("[Decline]"); + decline.setColor(net.md_5.bungee.api.ChatColor.RED); decline.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tpa decline")); message.addExtra(accept); @@ -100,6 +104,6 @@ private void handleTpaRequest(Player player, String targetName) { message.addExtra(decline); target.spigot().sendMessage(message); - player.sendMessage(ChatColor.GOLD + "Teleport request sent to " + ChatColor.GREEN + target.getName() + ChatColor.GOLD + "."); + player.sendMessage(Component.text("Teleport request sent to " + target.getName(), NamedTextColor.GOLD)); } } \ No newline at end of file diff --git a/src/main/java/dev/xdpxi/xdlib/plugin/updateChecker.java b/src/main/java/dev/xdpxi/xdlib/plugin/updateChecker.java index 18b656f..9a77cd8 100644 --- a/src/main/java/dev/xdpxi/xdlib/plugin/updateChecker.java +++ b/src/main/java/dev/xdpxi/xdlib/plugin/updateChecker.java @@ -1,7 +1,6 @@ package dev.xdpxi.xdlib.plugin; import dev.xdpxi.xdlib.api.plugin.chatUtils; -import org.bukkit.ChatColor; import org.json.JSONArray; import org.json.JSONObject; @@ -10,6 +9,9 @@ import java.net.HttpURLConnection; import java.net.URI; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.Component; + public class updateChecker { private final xdlib plugin; private static boolean update = false; @@ -39,12 +41,12 @@ public void checkForUpdate() { String latestVersion = parseLatestVersion(response.toString()); latestVersion = textParser(latestVersion); - String currentVersion = plugin.getDescription().getVersion(); + String currentVersion = plugin.getPluginMeta().getVersion(); currentVersion = textParser(currentVersion); if (isVersionLower(currentVersion, latestVersion)) { plugin.getLogger().info("[XDLib] - An update is available!"); - chatUtils.sendMessageToOps(ChatColor.GOLD + "[XDLib] - An update is available!"); + chatUtils.sendMessageToOps(Component.text("[XDLib] - An update is available!", NamedTextColor.GOLD)); update = true; } else { plugin.getLogger().info("[XDLib] - No update available!"); diff --git a/src/main/java/dev/xdpxi/xdlib/plugin/welcomeListener.java b/src/main/java/dev/xdpxi/xdlib/plugin/welcomeListener.java index 25a7438..f46ebf3 100644 --- a/src/main/java/dev/xdpxi/xdlib/plugin/welcomeListener.java +++ b/src/main/java/dev/xdpxi/xdlib/plugin/welcomeListener.java @@ -1,9 +1,10 @@ package dev.xdpxi.xdlib.plugin; -import org.bukkit.ChatColor; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; public class welcomeListener implements Listener { private final xdlib plugin; @@ -15,7 +16,10 @@ public welcomeListener(xdlib plugin) { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { if (!event.getPlayer().hasPlayedBefore() && plugin.getConfig().getBoolean("welcomeMessage")) { - event.getPlayer().sendMessage(ChatColor.GOLD + "Welcome " + ChatColor.GREEN + event.getPlayer().getName() + ChatColor.GOLD + " to the server!"); + event.getPlayer().sendMessage(Component.text("Welcome ") + .color(NamedTextColor.GOLD) + .append(Component.text(event.getPlayer().getName()).color(NamedTextColor.GREEN)) + .append(Component.text(" to the server!").color(NamedTextColor.GOLD))); } } } \ No newline at end of file diff --git a/src/main/java/dev/xdpxi/xdlib/plugin/xdlib.java b/src/main/java/dev/xdpxi/xdlib/plugin/xdlib.java index f21a41b..2faefb5 100644 --- a/src/main/java/dev/xdpxi/xdlib/plugin/xdlib.java +++ b/src/main/java/dev/xdpxi/xdlib/plugin/xdlib.java @@ -9,7 +9,7 @@ import java.util.HashMap; import java.util.UUID; -public final class xdlib extends JavaPlugin implements CommandExecutor { +public final class xdlib extends JavaPlugin { private final HashMap teleportRequests = new HashMap<>(); private welcomeListener WelcomeListener; private chatListener ChatListener; @@ -82,50 +82,4 @@ private void setConfig() { public void onDisable() { getLogger().info("[XDLib] - Disabled!"); } - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (command.getName().equalsIgnoreCase("xdlib")) { - if (args.length > 0) { - if (args[0].equalsIgnoreCase("reload")) { - if (sender.hasPermission("xdlib.reload")) { - reloadConfig(); - setConfig(); - sender.sendMessage("[XDLib] - Config reloaded!"); - } else { - sender.sendMessage("[XDLib] - You do not have permission to execute this command."); - } - } else if (args[0].equalsIgnoreCase("help")) { - sender.sendMessage("Available commands:\n/xdlib - Displays the configured message\n/xdlib reload - Reloads the plugin configuration\n/xdlib help - Shows this help message"); - } else { - sender.sendMessage("[XDLib] - Use '/xdlib help' for a list of commands."); - } - } else { - String message = getConfig().getString("message"); - sender.sendMessage(message); - } - return true; - } - return false; - } - - private void unregisterCommand(String commandName) { - try { - Field commandMapField = getServer().getClass().getDeclaredField("commandMap"); - commandMapField.setAccessible(true); - CommandMap commandMap = (CommandMap) commandMapField.get(getServer()); - - PluginCommand command = getCommand(commandName); - if (command != null) { - command.unregister(commandMap); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - private boolean isCommandAvailable(String commandName) { - PluginCommand command = getServer().getPluginCommand(commandName); - return command != null; - } } \ No newline at end of file