From f13bd8a5d569a87b913930d6d2e8877d53b1f310 Mon Sep 17 00:00:00 2001 From: Taah Date: Thu, 24 Feb 2022 23:50:11 -0800 Subject: [PATCH] - Fix banning bug + make plex name color config option work --- src/main/java/dev/plex/cache/PlayerCache.java | 4 ++++ .../java/dev/plex/command/impl/AdminworldCMD.java | 1 + src/main/java/dev/plex/command/impl/BanCMD.java | 1 + .../java/dev/plex/command/impl/FlatlandsCMD.java | 1 + .../java/dev/plex/command/impl/LocalSpawnCMD.java | 1 + .../plex/command/impl/MasterbuilderworldCMD.java | 1 + src/main/java/dev/plex/command/impl/TagCMD.java | 1 + src/main/java/dev/plex/command/impl/UnbanCMD.java | 3 ++- src/main/java/dev/plex/command/impl/WorldCMD.java | 1 + .../java/dev/plex/listener/impl/ChatListener.java | 2 +- .../java/dev/plex/listener/impl/PlayerListener.java | 11 +---------- .../java/dev/plex/punishment/PunishmentManager.java | 13 +++---------- src/main/java/dev/plex/util/PlexUtils.java | 4 ++-- 13 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/main/java/dev/plex/cache/PlayerCache.java b/src/main/java/dev/plex/cache/PlayerCache.java index b2fafdd..742876e 100644 --- a/src/main/java/dev/plex/cache/PlayerCache.java +++ b/src/main/java/dev/plex/cache/PlayerCache.java @@ -34,6 +34,10 @@ public class PlayerCache public static PunishedPlayer getPunishedPlayer(UUID uuid) { + if (!getPunishedPlayerMap().containsKey(uuid)) + { + getPunishedPlayerMap().put(uuid, new PunishedPlayer(uuid)); + } return getPunishedPlayerMap().get(uuid); } diff --git a/src/main/java/dev/plex/command/impl/AdminworldCMD.java b/src/main/java/dev/plex/command/impl/AdminworldCMD.java index df1d004..96cb2ac 100644 --- a/src/main/java/dev/plex/command/impl/AdminworldCMD.java +++ b/src/main/java/dev/plex/command/impl/AdminworldCMD.java @@ -20,6 +20,7 @@ public class AdminworldCMD extends PlexCommand @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) { + assert playerSender != null; // TODO: Add adminworld settings if (args.length == 0) { diff --git a/src/main/java/dev/plex/command/impl/BanCMD.java b/src/main/java/dev/plex/command/impl/BanCMD.java index 9b217b2..2ce06c6 100644 --- a/src/main/java/dev/plex/command/impl/BanCMD.java +++ b/src/main/java/dev/plex/command/impl/BanCMD.java @@ -53,6 +53,7 @@ public class BanCMD extends PlexCommand { if (!isConsole(sender)) { + assert playerSender != null; PlexPlayer plexPlayer1 = getPlexPlayer(playerSender); if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString())) { diff --git a/src/main/java/dev/plex/command/impl/FlatlandsCMD.java b/src/main/java/dev/plex/command/impl/FlatlandsCMD.java index e80a734..433051e 100644 --- a/src/main/java/dev/plex/command/impl/FlatlandsCMD.java +++ b/src/main/java/dev/plex/command/impl/FlatlandsCMD.java @@ -21,6 +21,7 @@ public class FlatlandsCMD extends PlexCommand @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) { + assert playerSender != null; if (args.length == 0) { Location loc = new Location(Bukkit.getWorld("flatlands"), 0, 50, 0); diff --git a/src/main/java/dev/plex/command/impl/LocalSpawnCMD.java b/src/main/java/dev/plex/command/impl/LocalSpawnCMD.java index e805f99..67a973e 100644 --- a/src/main/java/dev/plex/command/impl/LocalSpawnCMD.java +++ b/src/main/java/dev/plex/command/impl/LocalSpawnCMD.java @@ -18,6 +18,7 @@ public class LocalSpawnCMD extends PlexCommand @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) { + assert playerSender != null; playerSender.teleportAsync(playerSender.getWorld().getSpawnLocation()); return messageComponent("teleportedToWorldSpawn"); } diff --git a/src/main/java/dev/plex/command/impl/MasterbuilderworldCMD.java b/src/main/java/dev/plex/command/impl/MasterbuilderworldCMD.java index ce6d3cd..cb8b4c2 100644 --- a/src/main/java/dev/plex/command/impl/MasterbuilderworldCMD.java +++ b/src/main/java/dev/plex/command/impl/MasterbuilderworldCMD.java @@ -21,6 +21,7 @@ public class MasterbuilderworldCMD extends PlexCommand @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) { + assert playerSender != null; // TODO: Add masterbuilderworld settings if (args.length == 0) { diff --git a/src/main/java/dev/plex/command/impl/TagCMD.java b/src/main/java/dev/plex/command/impl/TagCMD.java index 200a01e..133bb02 100644 --- a/src/main/java/dev/plex/command/impl/TagCMD.java +++ b/src/main/java/dev/plex/command/impl/TagCMD.java @@ -38,6 +38,7 @@ public class TagCMD extends PlexCommand { return messageComponent("noPermissionConsole"); } + assert playerSender != null; PlexPlayer player = DataUtils.getPlayer(playerSender.getUniqueId()); if (args.length < 2) { diff --git a/src/main/java/dev/plex/command/impl/UnbanCMD.java b/src/main/java/dev/plex/command/impl/UnbanCMD.java index dba93de..ccd5b37 100644 --- a/src/main/java/dev/plex/command/impl/UnbanCMD.java +++ b/src/main/java/dev/plex/command/impl/UnbanCMD.java @@ -17,6 +17,7 @@ import net.kyori.adventure.text.Component; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @CommandParameters(name = "unban", usage = "/ ", description = "Unbans a player, offline or online") @CommandPermissions(level = Rank.ADMIN, permission = "plex.ban", source = RequiredCommandSource.ANY) @@ -24,7 +25,7 @@ import org.jetbrains.annotations.NotNull; public class UnbanCMD extends PlexCommand { @Override - public Component execute(@NotNull CommandSender sender, @NotNull Player playerSender, String[] args) + public Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) { if (args.length == 0) { diff --git a/src/main/java/dev/plex/command/impl/WorldCMD.java b/src/main/java/dev/plex/command/impl/WorldCMD.java index 82f1c37..3bc613e 100644 --- a/src/main/java/dev/plex/command/impl/WorldCMD.java +++ b/src/main/java/dev/plex/command/impl/WorldCMD.java @@ -24,6 +24,7 @@ public class WorldCMD extends PlexCommand @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) { + assert playerSender != null; if (args.length != 1) { return usage(); diff --git a/src/main/java/dev/plex/listener/impl/ChatListener.java b/src/main/java/dev/plex/listener/impl/ChatListener.java index 94a2944..1fd3b61 100644 --- a/src/main/java/dev/plex/listener/impl/ChatListener.java +++ b/src/main/java/dev/plex/listener/impl/ChatListener.java @@ -73,7 +73,7 @@ public class ChatListener extends PlexListener { return Component.empty().append(LegacyComponentSerializer.legacyAmpersand().deserialize(prefix)) .append(Component.space()) - .append(sourceDisplayName) + .append(LegacyComponentSerializer.legacyAmpersand().deserialize("&" + plugin.config.getString("chat.name-color") + LegacyComponentSerializer.legacyAmpersand().serialize(sourceDisplayName))) .append(Component.space()) .append(Component.text("ยป").color(NamedTextColor.GRAY)) .append(Component.space()) diff --git a/src/main/java/dev/plex/listener/impl/PlayerListener.java b/src/main/java/dev/plex/listener/impl/PlayerListener.java index b7c8be3..cbde48c 100644 --- a/src/main/java/dev/plex/listener/impl/PlayerListener.java +++ b/src/main/java/dev/plex/listener/impl/PlayerListener.java @@ -57,17 +57,8 @@ public class PlayerListener extends PlexListener plexPlayer = DataUtils.getPlayer(player.getUniqueId()); } - PunishedPlayer punishedPlayer; + PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId()); PlayerCache.getPlexPlayerMap().put(player.getUniqueId(), plexPlayer); //put them into the cache - if (!PlayerCache.getPunishedPlayerMap().containsKey(player.getUniqueId())) - { - punishedPlayer = new PunishedPlayer(player.getUniqueId()); - PlayerCache.getPunishedPlayerMap().put(player.getUniqueId(), punishedPlayer); - } - else - { - punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId()); - } punishedPlayer.convertPunishments(); assert plexPlayer != null; diff --git a/src/main/java/dev/plex/punishment/PunishmentManager.java b/src/main/java/dev/plex/punishment/PunishmentManager.java index 6e82a61..b111f74 100644 --- a/src/main/java/dev/plex/punishment/PunishmentManager.java +++ b/src/main/java/dev/plex/punishment/PunishmentManager.java @@ -95,7 +95,7 @@ public class PunishmentManager extends PlexBase public boolean isBanned(UUID uuid) { - return PlayerCache.getPunishedPlayerMap().containsKey(uuid) && PlayerCache.getPunishedPlayer(uuid).getPunishments().stream().anyMatch(punishment -> punishment.getType() == PunishmentType.BAN && punishment.isActive()); + return PlayerCache.getPunishedPlayer(uuid).getPunishments().stream().anyMatch(punishment -> punishment.getType() == PunishmentType.BAN && punishment.isActive()); } public boolean isBanned(PunishedPlayer player) @@ -160,15 +160,8 @@ public class PunishmentManager extends PlexBase jedis.set(uuid.toString(), object.toString()); } - PunishedPlayer player; - if (PlayerCache.getPunishedPlayerMap().containsKey(uuid)) - { - player = PlayerCache.getPunishedPlayer(uuid); - } - else - { - player = new PunishedPlayer(uuid); - } + PunishedPlayer player = PlayerCache.getPunishedPlayer(uuid); + File file = player.getPunishmentsFile(); if (isNotEmpty(file)) { diff --git a/src/main/java/dev/plex/util/PlexUtils.java b/src/main/java/dev/plex/util/PlexUtils.java index a4202b4..7efd5c9 100644 --- a/src/main/java/dev/plex/util/PlexUtils.java +++ b/src/main/java/dev/plex/util/PlexUtils.java @@ -41,8 +41,8 @@ public class PlexUtils extends PlexBase public static Map CHAT_COLOR_NAMES; public static List CHAT_COLOR_POOL; public static List DEVELOPERS = - Arrays.asList("78408086-1991-4c33-a571-d8fa325465b2", // Telesphoreo - "f5cd54c4-3a24-4213-9a56-c06c49594dff" // Taahh + Arrays.asList("78408086-1991-4c33-a571-d8fa325465b2" // Telesphoreo +// "f5cd54c4-3a24-4213-9a56-c06c49594dff" // Taahh ); private static final Random RANDOM;