From bef39c7cc2a4fd1038acaa88ba568014497fb308 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 22 Jan 2021 10:41:57 +0100 Subject: [PATCH] Fixing... --- .../bungeecore/commands/BanCommand.java | 2 +- .../bungeecore/commands/MuteCommand.java | 2 +- .../bungeecore/commands/WhoisCommand.java | 2 +- .../bungeecore/listeners/BanListener.java | 2 +- .../steamwar/bungeecore/sql/Punishment.java | 21 ++++++++++---- .../steamwar/bungeecore/sql/SteamwarUser.java | 28 +++++-------------- .../steamwar/messages/BungeeCore.properties | 10 +++---- 7 files changed, 30 insertions(+), 37 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/BanCommand.java b/src/de/steamwar/bungeecore/commands/BanCommand.java index e977fefe..293b3f1c 100644 --- a/src/de/steamwar/bungeecore/commands/BanCommand.java +++ b/src/de/steamwar/bungeecore/commands/BanCommand.java @@ -57,7 +57,7 @@ public class BanCommand extends BasicCommand { boolean isPerma = args[1].equalsIgnoreCase("perma"); String msg = banReason.toString(); target.ban(banTime, msg, SteamwarUser.get(sender.getName()).getId(), isPerma); - Message.team("BAN_TEAM_BANNED", target.getUserName(), sender.getName(), new Message((isPerma?"BAN_PERMA":"BAN_UNTIL"), banTime), msg); + Message.team("BAN_TEAM_BANNED", new Message("PREFIX"), target.getUserName(), sender.getName(), new Message((isPerma?"BAN_PERMA":"BAN_UNTIL"), banTime), msg); } public static Timestamp parseTime(CommandSender sender, String arg){ diff --git a/src/de/steamwar/bungeecore/commands/MuteCommand.java b/src/de/steamwar/bungeecore/commands/MuteCommand.java index 0ab8d29f..ea778885 100644 --- a/src/de/steamwar/bungeecore/commands/MuteCommand.java +++ b/src/de/steamwar/bungeecore/commands/MuteCommand.java @@ -52,6 +52,6 @@ public class MuteCommand extends BasicCommand { } String msg = muteReason.toString(); target.mute(muteTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma")); - Message.team("MUTE_TEAM_MUTED", target.getUserName(), sender.getName(), new Message((args[1].equalsIgnoreCase("perma")?"BAN_PERMA":"BAN_UNTIL"), muteTime), msg); + Message.team("MUTE_TEAM_MUTED", new Message("PREFIX"), target.getUserName(), sender.getName(), new Message((args[1].equalsIgnoreCase("perma")?"BAN_PERMA":"BAN_UNTIL"), muteTime), msg); } } diff --git a/src/de/steamwar/bungeecore/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/commands/WhoisCommand.java index c774ac1f..f30e8fed 100644 --- a/src/de/steamwar/bungeecore/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/commands/WhoisCommand.java @@ -43,7 +43,7 @@ public class WhoisCommand extends BasicCommand { ProxiedPlayer player = (ProxiedPlayer) sender; if(args.length == 0){ - Message.send("WHOIS_SYNTAX", player); + Message.send("WHOIS_USAGE", player); return; } diff --git a/src/de/steamwar/bungeecore/listeners/BanListener.java b/src/de/steamwar/bungeecore/listeners/BanListener.java index c62a17d0..80f666eb 100644 --- a/src/de/steamwar/bungeecore/listeners/BanListener.java +++ b/src/de/steamwar/bungeecore/listeners/BanListener.java @@ -43,7 +43,7 @@ public class BanListener extends BasicListener { if(user.isBanned()) { user.updateBanIP(event.getConnection().getAddress().getAddress().getHostAddress()); event.setCancelled(true); - event.setCancelReason(user.banMessage((ProxiedPlayer) event.getConnection())); + event.setCancelReason(user.banMessage(ProxyServer.getInstance().getPlayer(event.getConnection().getUniqueId()))); return; } diff --git a/src/de/steamwar/bungeecore/sql/Punishment.java b/src/de/steamwar/bungeecore/sql/Punishment.java index 2e14a2a9..09a5fd12 100644 --- a/src/de/steamwar/bungeecore/sql/Punishment.java +++ b/src/de/steamwar/bungeecore/sql/Punishment.java @@ -43,12 +43,15 @@ public class Punishment { } public static Map getPunishmentsOfPlayer(int user) { - Map punishments = new HashMap<>(); - Punishment banPunishment = getPunishmentOfPlayer(user, PunishmentType.Ban); - if(banPunishment != null) punishments.put(PunishmentType.Ban, banPunishment); - Punishment mutePunishment = getPunishmentOfPlayer(user, PunishmentType.Mute); - if(mutePunishment != null) punishments.put(PunishmentType.Mute, mutePunishment); - return punishments; + ResultSet set = SQL.select("SELECT * FROM Punishments WHERE PunishmentId IN (SELECT MAX(PunishmentId) WHERE UserId = ? GROUP BY Type)", user); + try { + Map punishments = new HashMap<>(); + while (set.next()) + punishments.put(PunishmentType.valueOf(set.getString("Type")), new Punishment(set)); + return punishments; + } catch (SQLException e) { + throw new SecurityException("Could not Load Punishments", e); + } } public static List getAllPunishmentsOfPlayer(int user) { @@ -119,6 +122,8 @@ public class Punishment { } public void updateEndTime(int from, String newreason, Timestamp newUpdate, boolean perma) { + if(newreason.equals(reason) && newUpdate.equals(endTime) && perma == perma) + return; ProxiedPlayer player = BungeeCore.get().getProxy().getPlayer(SteamwarUser.get(from).getUuid()); String newReason = Message.parse("BAN_CHANGED", player, reason, SteamwarUser.get(from).getUserName(), @@ -139,6 +144,10 @@ public class Punishment { return endTime.toLocalDateTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm")); } + public boolean isCurrent() { + return isPerma() || getEndTime().after(new Date()); + } + public enum PunishmentType { Ban, Mute; diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index 3f926a66..4c5b562a 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -33,9 +33,7 @@ import java.net.UnknownHostException; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; -import java.time.Instant; import java.time.format.DateTimeFormatter; -import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -71,7 +69,7 @@ public class SteamwarUser { usersById.put(id, this); usersByName.put(userName.toLowerCase(), this); usersByUUID.put(uuid, this); - punishments = null; + punishments = Punishment.getPunishmentsOfPlayer(id); } public static SteamwarUser getOrCreate(PendingConnection connection){ @@ -151,17 +149,10 @@ public class SteamwarUser { return team; } - private void loadPunishments() { - if(punishments == null) { - punishments = Punishment.getPunishmentsOfPlayer(id); - } - } - public boolean isBanned() { - loadPunishments(); if(!punishments.containsKey(Punishment.PunishmentType.Ban)) return false; - if(!isCurrent(punishments.get(Punishment.PunishmentType.Ban))) { + if(!punishments.get(Punishment.PunishmentType.Ban).isCurrent()) { SQL.update("DELETE FROM BannedUserIPs WHERE UserID = ?", id); punishments.remove(Punishment.PunishmentType.Ban); return false; @@ -170,18 +161,16 @@ public class SteamwarUser { } public boolean isMuted(){ - loadPunishments(); if(!punishments.containsKey(Punishment.PunishmentType.Mute)) return false; - return isCurrent(punishments.get(Punishment.PunishmentType.Mute)); - } - - private boolean isCurrent(Punishment punishment) { - return punishment.isPerma() || punishment.getEndTime().after(new Date()); + if(!punishments.get(Punishment.PunishmentType.Mute).isCurrent()) { + punishments.remove(Punishment.PunishmentType.Mute); + return false; + } + return true; } public TextComponent banMessage(ProxiedPlayer player){ - loadPunishments(); Punishment punishment = punishments.get(Punishment.PunishmentType.Ban); if (punishment.isPerma()) { return BungeeCore.stringToText(Message.parsePrefixed("BANNED_MESSAGE_PERMA", player, punishment.getReason())); @@ -192,7 +181,6 @@ public class SteamwarUser { } public TextComponent muteMessage(ProxiedPlayer player){ - loadPunishments(); Punishment punishment = punishments.get(Punishment.PunishmentType.Mute); if (punishment.isPerma()) { return BungeeCore.stringToText(Message.parsePrefixed("MUTED_MESSAGE_PERMA", player, punishment.getReason())); @@ -206,7 +194,6 @@ public class SteamwarUser { } public void ban(Timestamp time, String banReason, int from, boolean perma){ - loadPunishments(); if(isBanned()) { punishments.get(Punishment.PunishmentType.Ban).updateEndTime(from, banReason, time, perma); return; @@ -229,7 +216,6 @@ public class SteamwarUser { } public void mute(Timestamp time, String muteReason, int from, boolean perma){ - loadPunishments(); if(isMuted()) { punishments.get(Punishment.PunishmentType.Mute).updateEndTime(from, muteReason, time, perma); return; diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 0b8b8309..5f6c5a6b 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -88,8 +88,6 @@ HELP_BAU_DELETE=§8/§ebau delete §8- §7Setzt deine Bauwelt zurück HELP_BAU_DELETE_HOVER=§eBauwelt zurücksetzen HELP_BAU_TESTARENA=§8/§ebau testarena §8- §7Starte eine Testarena HELP_BAU_TESTARENA_HOVER=§eTestarena starten -HELP_BAU_BAU=§8/§ehelp bau §8- §7Hilfe zu nützlichen Werkzeugen -HELP_BAU_BAU_HOVER=§eNützliche Zusatzfunktionen #Usage description of various commands USAGE_ALERT=§8/§7alert §8[§eNachricht§8] @@ -107,14 +105,14 @@ MOD_YELLOW_PLUR=§7Deaktiviere die Mods\n§e{0}\n§7um weiter auf §eSteam§8War ALERT=§f{0} #Ban&Mute-Command -BAN_TEAM_BANNED=§8[§4☣§8]» §c{0} wurde von {1} {2} gebannt. §f§lGrund: §f{3} +BAN_TEAM_BANNED={0}§c{1} wurde von {2} {3} gebannt. §f§lGrund: §f{4} BANNED_MESSAGE_PERMA=§cDu bist permanent gebannt. §r§lGrund§r: §c{0} BANNED_MESSAGE_UNTIL=§cDu bist bis zum {0} gebannt. §r§lGrund§r: §c{1} -MUTE_TEAM_MUTED=§8[§4☣§8]» §c{0} wurde von {1} {2} gemuted. §f§lGrund: §f{3} +MUTE_TEAM_MUTED={0}§c{1} wurde von {2} {3} gemuted. §f§lGrund: §f{4} MUTED_MESSAGE_PERMA=§cDu bist permanent gemuted. §r§lGrund§r: §c{0} MUTED_MESSAGE_UNTIL=§cDu bist bis zum {0} gemuted. §r§lGrund§r: §c{1} BAN_CHANGED={0}verändert von {1} von {2} auf {3} wegen {4} -BAN_PERMA=Permanent +BAN_PERMA=permanent BAN_UNTIL=bis zum {0} BAN_AVOIDING_ALERT=§cMögliche Bannumgehung durch §r{0}§c: §c BAN_AVOIDING_LIST={0} §e{1} §c @@ -164,7 +162,7 @@ CHECK_DECLINED=§cDein §e{0} {1} §cwurde abgelehnt§8: §c{2} CHECK_DECLINED_TEAM=§7Die Schematic §e{0} §7von §e{1} §awurde aufgrund von §e{2} §7abgelehnt! #WhoisCommand -WHOIS_SYNTAX=§c/whois [Spieler/ID] +WHOIS_USAGE=§c/whois [Spieler/ID] WHOIS_USERNAME=§7Username§8: §e{0} WHOIS_UUID=§7UUID§8: §e{0} WHOIS_UUID_HOVER=§eUUID Kopieren