From f97411ce0908a0fba6aec6bf6f2d95a3f9cbdf0d Mon Sep 17 00:00:00 2001 From: Taah Date: Thu, 24 Aug 2023 22:36:14 -0700 Subject: [PATCH] Cache whether the server is on a proxy or not Fix kick where ban message was displayed instead of kick message --- .../src/main/java/dev/plex/command/impl/BanCMD.java | 12 ++++++------ .../src/main/java/dev/plex/command/impl/KickCMD.java | 11 +++++------ .../main/java/dev/plex/punishment/Punishment.java | 5 +++++ server/src/main/java/dev/plex/util/BungeeUtil.java | 3 ++- server/src/main/resources/messages.yml | 3 +++ 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/server/src/main/java/dev/plex/command/impl/BanCMD.java b/server/src/main/java/dev/plex/command/impl/BanCMD.java index 075a5c1..15d9be7 100644 --- a/server/src/main/java/dev/plex/command/impl/BanCMD.java +++ b/server/src/main/java/dev/plex/command/impl/BanCMD.java @@ -39,14 +39,14 @@ public class BanCMD extends PlexCommand return usage(); } - UUID targetUUID = WebUtils.getFromName(args[0]); + final PlexPlayer plexPlayer = DataUtils.getPlayer(args[0]); - if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID)) + if (plexPlayer == null) { throw new PlayerNotFoundException(); } - PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID); - Player player = Bukkit.getPlayer(targetUUID); + + Player player = Bukkit.getPlayer(plexPlayer.getUuid()); if (plugin.getSystem().equalsIgnoreCase("ranks")) { @@ -64,7 +64,7 @@ public class BanCMD extends PlexCommand } } - plugin.getPunishmentManager().isAsyncBanned(targetUUID).whenComplete((aBoolean, throwable) -> + plugin.getPunishmentManager().isAsyncBanned(plexPlayer.getUuid()).whenComplete((aBoolean, throwable) -> { if (aBoolean) { @@ -72,7 +72,7 @@ public class BanCMD extends PlexCommand return; } String reason; - Punishment punishment = new Punishment(targetUUID, getUUID(sender)); + Punishment punishment = new Punishment(plexPlayer.getUuid(), getUUID(sender)); punishment.setType(PunishmentType.BAN); if (args.length > 1) { diff --git a/server/src/main/java/dev/plex/command/impl/KickCMD.java b/server/src/main/java/dev/plex/command/impl/KickCMD.java index ef6218d..76b8076 100644 --- a/server/src/main/java/dev/plex/command/impl/KickCMD.java +++ b/server/src/main/java/dev/plex/command/impl/KickCMD.java @@ -38,21 +38,20 @@ public class KickCMD extends PlexCommand return usage(); } - UUID targetUUID = WebUtils.getFromName(args[0]); + PlexPlayer plexPlayer = DataUtils.getPlayer(args[0]); String reason = "No reason provided"; - if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID)) + if (plexPlayer == null) { throw new PlayerNotFoundException(); } - PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID); - Player player = Bukkit.getPlayer(targetUUID); + Player player = Bukkit.getPlayer(plexPlayer.getUuid()); if (player == null) { throw new PlayerNotFoundException(); } - Punishment punishment = new Punishment(targetUUID, getUUID(sender)); + Punishment punishment = new Punishment(plexPlayer.getUuid(), getUUID(sender)); punishment.setType(PunishmentType.KICK); if (args.length > 1) { @@ -67,7 +66,7 @@ public class KickCMD extends PlexCommand punishment.setIp(player.getAddress().getAddress().getHostAddress().trim()); plugin.getPunishmentManager().punish(plexPlayer, punishment); PlexUtils.broadcast(messageComponent("kickedPlayer", sender.getName(), plexPlayer.getName())); - BungeeUtil.kickPlayer(player, Punishment.generateBanMessage(punishment)); + BungeeUtil.kickPlayer(player, Punishment.generateKickMessage(punishment)); return null; } } \ No newline at end of file diff --git a/server/src/main/java/dev/plex/punishment/Punishment.java b/server/src/main/java/dev/plex/punishment/Punishment.java index c58ff82..346d9d5 100644 --- a/server/src/main/java/dev/plex/punishment/Punishment.java +++ b/server/src/main/java/dev/plex/punishment/Punishment.java @@ -49,6 +49,11 @@ public class Punishment return PlexUtils.messageComponent("banMessage", banUrl, punishment.getReason(), TimeUtils.useTimezone(punishment.getEndDate()), punishment.getPunisher() == null ? "CONSOLE" : MojangUtils.getInfo(punishment.getPunisher().toString()).getUsername()); } + public static Component generateKickMessage(Punishment punishment) + { + return PlexUtils.messageComponent("kickMessage", punishment.getReason(), punishment.getPunisher() == null ? "CONSOLE" : MojangUtils.getInfo(punishment.getPunisher().toString()).getUsername()); + } + public static Component generateIndefBanMessageWithReason(String type, String reason) { return PlexUtils.messageComponent("indefBanMessageReason", type, banUrl, reason); diff --git a/server/src/main/java/dev/plex/util/BungeeUtil.java b/server/src/main/java/dev/plex/util/BungeeUtil.java index 93552a7..adb75a0 100644 --- a/server/src/main/java/dev/plex/util/BungeeUtil.java +++ b/server/src/main/java/dev/plex/util/BungeeUtil.java @@ -10,6 +10,7 @@ import org.bukkit.entity.Player; public class BungeeUtil { + public static final boolean PROXIED_SERVER = isBungeeCord() || isVelocity(); public static boolean isBungeeCord() { return Bukkit.spigot().getSpigotConfig().getBoolean("settings.bungeecord"); @@ -23,7 +24,7 @@ public class BungeeUtil @SuppressWarnings("UnstableApiUsage") public static void kickPlayer(Player player, Component message) { - if (isBungeeCord() || isVelocity()) + if (PROXIED_SERVER) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("KickPlayer"); diff --git a/server/src/main/resources/messages.yml b/server/src/main/resources/messages.yml index 311e67e..e481f57 100644 --- a/server/src/main/resources/messages.yml +++ b/server/src/main/resources/messages.yml @@ -14,6 +14,9 @@ # 2 - Expiry # 3 - Punisher banMessage: "You have been banned! You may appeal at {0}.\nReason: {1}\nEnd date: {2}\nBanned by: {3}" +# 0 - Reason +# 1 - Punisher +kickMessage: "You have been kicked! \nReason: {0}\nKicked by: {1}" # 0 - The type of indefinite ban # 1 - Appeal URL indefBanMessage: "Your {0} is indefinitely banned! You may appeal at {1}."