From 986b53fbf82bf6940d31a1c26aecd85179a304e9 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 14 Nov 2020 23:23:49 +0100 Subject: [PATCH 01/30] Reworked Ban and Mute --- src/de/steamwar/bungeecore/BungeeCore.java | 2 +- .../bungeecore/commands/BanCommand.java | 5 +- .../bungeecore/commands/MuteCommand.java | 3 +- .../bungeecore/commands/UnbanCommand.java | 3 +- .../bungeecore/commands/WhoisCommand.java | 10 +- .../bungeecore/listeners/BanListener.java | 9 ++ .../bungeecore/listeners/mods/Utils.java | 4 +- .../bungeecore/sql/BannedUserIPs.java | 4 + .../steamwar/bungeecore/sql/Punishment.java | 141 ++++++++++++++++++ .../steamwar/bungeecore/sql/SteamwarUser.java | 65 +++----- 10 files changed, 189 insertions(+), 57 deletions(-) create mode 100644 src/de/steamwar/bungeecore/sql/Punishment.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index a6a9cca..ce64862 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -54,7 +54,7 @@ public class BungeeCore extends Plugin { public static final String SERVER_TEAMCHAT_PREFIX = "§8STC §e"; public static final String TEAMCHAT_PREFIX = "§8TC §e"; - public static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("dd.MM.yyyy"); + public static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("HH:mm dd.MM.yyyy"); public static String CHAT_PREFIX; public static String WORLD_FOLDER; diff --git a/src/de/steamwar/bungeecore/commands/BanCommand.java b/src/de/steamwar/bungeecore/commands/BanCommand.java index 9ac7ff8..c2d637d 100644 --- a/src/de/steamwar/bungeecore/commands/BanCommand.java +++ b/src/de/steamwar/bungeecore/commands/BanCommand.java @@ -22,6 +22,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.connection.ProxiedPlayer; import java.sql.Timestamp; import java.text.ParseException; @@ -56,12 +57,12 @@ public class BanCommand extends BasicCommand { } String msg = banReason.toString(); BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "Du hast " + target.getUserName() + " gebannt. Grund: §c" + msg); - target.ban(banTime, msg); + target.ban(banTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma")); } public static Timestamp parseTime(CommandSender sender, String arg){ if(arg.equalsIgnoreCase("perma")) { - return Timestamp.from(Instant.ofEpochSecond(946674800)); + return Timestamp.from(Instant.ofEpochSecond(946684800)); }else{ SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy_HH:mm"); try{ diff --git a/src/de/steamwar/bungeecore/commands/MuteCommand.java b/src/de/steamwar/bungeecore/commands/MuteCommand.java index dc0d681..cf35b9d 100644 --- a/src/de/steamwar/bungeecore/commands/MuteCommand.java +++ b/src/de/steamwar/bungeecore/commands/MuteCommand.java @@ -24,6 +24,7 @@ import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.CommandSender; import java.sql.Timestamp; +import java.time.Instant; public class MuteCommand extends BasicCommand { @@ -52,6 +53,6 @@ public class MuteCommand extends BasicCommand { } String msg = muteReason.toString(); BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "Du hast " + target.getUserName() + " gemuted. Grund: §c" + msg); - target.mute(muteTime, msg); + target.mute(muteTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma")); } } diff --git a/src/de/steamwar/bungeecore/commands/UnbanCommand.java b/src/de/steamwar/bungeecore/commands/UnbanCommand.java index 080a8d6..c21561a 100644 --- a/src/de/steamwar/bungeecore/commands/UnbanCommand.java +++ b/src/de/steamwar/bungeecore/commands/UnbanCommand.java @@ -22,6 +22,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.connection.ProxiedPlayer; import java.sql.Timestamp; import java.util.Date; @@ -44,6 +45,6 @@ public class UnbanCommand extends BasicCommand { return; BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "Du hast " + target.getUserName() + " entbannt."); - target.ban(Timestamp.from(new Date().toInstant()), ""); + target.ban(Timestamp.from(new Date().toInstant()), "Unban", SteamwarUser.get(sender.getName()).getId(), false); } } diff --git a/src/de/steamwar/bungeecore/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/commands/WhoisCommand.java index 5bd83d6..cc66c1a 100644 --- a/src/de/steamwar/bungeecore/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/commands/WhoisCommand.java @@ -20,6 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.Team; import net.md_5.bungee.api.CommandSender; @@ -70,11 +71,10 @@ public class WhoisCommand extends BasicCommand { Team team = Team.get(user.getTeam()); BungeeCore.send(player, "§7Team§8: §e" + team.getTeamName()); - if(user.isBanned()){ - player.sendMessage(user.banMessage()); - } - if(user.isMuted()){ - player.sendMessage(user.muteMessage()); + BungeeCore.send(player, "§7Bestrafungen: "); + for (Punishment punishment : Punishment.getAllPunishmentsByPlayer(user.getId())) { + BungeeCore.send(player, "§7" + SteamwarUser.get(punishment.getPunisher()).getUserName() + "§8» §f§l" + punishment.getType().name() + ": §e" + + punishment.getStartTime().toLocalDateTime().format(BungeeCore.DATE_FORMAT) + " - " + (punishment.isPerma()?"Perma":punishment.getEndTime().toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " §c" + punishment.getReason()); } } } diff --git a/src/de/steamwar/bungeecore/listeners/BanListener.java b/src/de/steamwar/bungeecore/listeners/BanListener.java index c9aadb7..bc56de3 100644 --- a/src/de/steamwar/bungeecore/listeners/BanListener.java +++ b/src/de/steamwar/bungeecore/listeners/BanListener.java @@ -47,6 +47,15 @@ public class BanListener extends BasicListener { List ips = BannedUserIPs.get(event.getConnection().getAddress().getAddress().getHostAddress()); if(!ips.isEmpty()){ + if(ips.stream().anyMatch(bannedUserIPs -> bannedUserIPs.getUserID() == user.getId())) { + ips.forEach(bannedUserIPs -> { + if(bannedUserIPs.getUserID() == user.getId()) + bannedUserIPs.remove(); + }); + ips.removeIf(bannedUserIPs -> bannedUserIPs.getUserID() == user.getId()); + if(ips.isEmpty()) + return; + } StringBuilder potentialBan = new StringBuilder(); potentialBan.append(BungeeCore.CHAT_PREFIX); potentialBan.append("§cMögliche Bannumgehung durch §r"); diff --git a/src/de/steamwar/bungeecore/listeners/mods/Utils.java b/src/de/steamwar/bungeecore/listeners/mods/Utils.java index 7f6d16f..1ca83e3 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Utils.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Utils.java @@ -74,7 +74,7 @@ class Utils { if(max == ModType.YELLOW) player.disconnect(BungeeCore.stringToText("§7Deaktiviere den Mod §e" + mods.get(0).getModName() + "§7, um weiter auf §eSteam§8War §7spielen zu können.")); else{ - user.ban(Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), "Versuchte Benutzung des Mods " + mods.get(0).getModName()); + user.ban(Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), "Versuchte Benutzung des Mods " + mods.get(0).getModName(), 0, false); BungeeCore.log(Level.SEVERE, user.getUserName() + " " + user.getId() + " wurde automatisch wegen des Mods " + mods.get(0).getModName() + " gebannt."); } }else{ @@ -84,7 +84,7 @@ class Utils { if(max == ModType.YELLOW) player.disconnect(BungeeCore.stringToText("§7Deaktiviere die Mods\n§e" + sb.toString() + "§7um weiter auf §eSteam§8War §7spielen zu können.")); else{ - user.ban(Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), "Versuchte Benutzung der Mods\n" + sb.toString()); + user.ban(Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), "Versuchte Benutzung der Mods\n" + sb.toString(), 0, false); BungeeCore.log(Level.SEVERE, user.getUserName() + " " + user.getId() + " wurde automatisch wegen der Mods " + sb.toString() + " gebannt."); } } diff --git a/src/de/steamwar/bungeecore/sql/BannedUserIPs.java b/src/de/steamwar/bungeecore/sql/BannedUserIPs.java index 6b371cc..243e5f3 100644 --- a/src/de/steamwar/bungeecore/sql/BannedUserIPs.java +++ b/src/de/steamwar/bungeecore/sql/BannedUserIPs.java @@ -78,4 +78,8 @@ public class BannedUserIPs { public java.sql.Timestamp getTimestamp() { return timestamp; } + + public void remove() { + SQL.update("DELETE FROM BannedUserIPs WHERE UserID = ?", userID); + } } diff --git a/src/de/steamwar/bungeecore/sql/Punishment.java b/src/de/steamwar/bungeecore/sql/Punishment.java new file mode 100644 index 0000000..ec787a7 --- /dev/null +++ b/src/de/steamwar/bungeecore/sql/Punishment.java @@ -0,0 +1,141 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.bungeecore.sql; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Timestamp; +import java.util.*; +import java.util.stream.Collectors; + +public class Punishment { + + public static Punishment getPunishmentByPlayer(int user, PunishmentType type) { + ResultSet set = SQL.select("SELECT * FROM `Punishments` WHERE `PunishmentId` IN (SELECT MAX(`PunishmentId`) FROM Punishments WHERE UserId = ? AND Type = ?)", user, type.toDb()); + try { + if(!set.next()) + return null; + return new Punishment(set); + } catch (SQLException throwable) { + throwable.printStackTrace(); + throw new SecurityException("Could not Load Punishments", throwable); + } + } + + public static Map getPunishmentsByPlayer(int user) { + ResultSet set = SQL.select("SELECT * FROM `Punishments` WHERE `PunishmentId` IN (SELECT MAX(`PunishmentId`) FROM Punishments WHERE UserId = ? GROUP BY Type)", user); + try { + Map punishmentMap = new HashMap<>(); + while (set.next()) { + Punishment punishment = new Punishment(set); + punishmentMap.put(punishment.getType(), punishment); + } + return punishmentMap; + } catch (SQLException throwable) { + throwable.printStackTrace(); + throw new SecurityException("Could not Load Punishments", throwable); + } + } + + public static Set getAllPunishmentsByPlayer(int user) { + ResultSet set = SQL.select("SELECT * FROM Punishments WHERE UserId = ? ORDER BY `PunishmentId` DESC", user); + try { + Set punishments = new HashSet<>(); + while (set.next()) { + punishments.add(new Punishment(set)); + } + return punishments; + } catch (SQLException throwable) { + throwable.printStackTrace(); + throw new SecurityException("Could not Load all Punishments", throwable); + } + } + + public static Punishment createPunishment(int user, int executor, PunishmentType type, String reason, Timestamp endTime, Boolean perma) { + SQL.update("INSERT INTO Punishments (UserId, Punisher, Type, Reason, EndTime, Perma) VALUES (?, ?, ?, ?, ?, ?)", + user, executor, type.toDb(), reason, endTime, perma); + return getPunishmentByPlayer(user, type); + } + + private final Timestamp startTime; + private final Timestamp endTime; + private final PunishmentType type; + private final int user; + private final String reason; + private final int id; + private final int punisher; + private final boolean perma; + + private Punishment(ResultSet set) throws SQLException { + id = set.getInt("PunishmentId"); + user = set.getInt("UserId"); + reason = set.getString("Reason"); + type = PunishmentType.getTypeFromDB(set.getString("Type")); + startTime = set.getTimestamp("StartTime"); + endTime = set.getTimestamp("EndTime"); + punisher = set.getInt("Punisher"); + perma = set.getBoolean("Perma"); + } + + public Timestamp getStartTime() { + return startTime; + } + + public Timestamp getEndTime() { + return endTime; + } + + public PunishmentType getType() { + return type; + } + + public int getUser() { + return user; + } + + public String getReason() { + return reason; + } + + public int getId() { + return id; + } + + public int getPunisher() { + return punisher; + } + + public boolean isPerma() { + return perma; + } + + public enum PunishmentType { + Ban, + Mute; + + public String toDb() { + return name().toLowerCase(); + } + + public static PunishmentType getTypeFromDB(String str) { + return Arrays.stream(values()).filter(punishmentType -> punishmentType.name().equalsIgnoreCase(str)).collect(Collectors.toList()).get(0); + } + } +} diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index 61625ea..82ace6b 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -32,7 +32,6 @@ import java.net.UnknownHostException; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; -import java.time.Instant; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -43,16 +42,12 @@ public class SteamwarUser { private final UUID uuid; private String userName; private UserGroup userGroup; - private Timestamp banTime; - private String banReason; private int team; - private Timestamp muteTime; - private String muteReason; + private Map punishments; private static final Map usersByName = new HashMap<>(); private static final Map usersByUUID = new HashMap<>(); private static final Map usersById = new HashMap<>(); - private static final Timestamp PERMA_BAN = Timestamp.from(Instant.ofEpochSecond(946684800)); private static final InetAddress LIXFEL_DE; static { @@ -69,14 +64,11 @@ public class SteamwarUser { uuid = UUID.fromString(rs.getString("UUID")); userName = rs.getString("UserName"); userGroup = UserGroup.getUsergroup(rs.getString("UserGroup")); - banTime = rs.getTimestamp("BanTime"); - banReason = rs.getString("BanReason"); team = rs.getInt("Team"); - muteTime = rs.getTimestamp("MuteTime"); - muteReason = rs.getString("MuteReason"); usersById.put(id, this); usersByName.put(userName.toLowerCase(), this); usersByUUID.put(uuid, this); + punishments = Punishment.getPunishmentsByPlayer(id); } public static SteamwarUser getOrCreate(PendingConnection connection){ @@ -157,47 +149,32 @@ public class SteamwarUser { } public boolean isBanned() { - if (banTime == null) { - return false; - } else if (banTime.after(new Date()) || banTime.before(PERMA_BAN)) { - return true; - } else { - SQL.update("UPDATE UserData SET BanTime = NULL, BanReason = '' WHERE id = ?", id); - SQL.update("DELETE FROM BannedUserIPs WHERE UserID = ?", id); - banTime = null; - banReason = ""; - return false; - } + return punishments.containsKey(Punishment.PunishmentType.Ban) && + (punishments.get(Punishment.PunishmentType.Ban).getEndTime().after(new Date()) || punishments.get(Punishment.PunishmentType.Ban).isPerma()); } public boolean isMuted(){ - if(muteTime == null){ - return false; - }else if(muteTime.after(new Date()) || muteTime.before(PERMA_BAN)){ - return true; - }else{ - SQL.update("UPDATE UserData SET MuteTime = NULL, MuteReason = '' WHERE id = ?", id); - muteTime = null; - muteReason = ""; - return false; - } + return punishments.containsKey(Punishment.PunishmentType.Mute) && + (punishments.get(Punishment.PunishmentType.Mute).getEndTime().after(new Date()) || punishments.get(Punishment.PunishmentType.Mute).isPerma()); } public TextComponent banMessage(){ - if (banTime.before(PERMA_BAN)) { - return BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + "§cDu bist permanent gebannt. §r§lGrund§r: §c" + banReason); + Punishment punishment = punishments.get(Punishment.PunishmentType.Ban); + if (punishment.isPerma()) { + return BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + "§cDu bist permanent gebannt. §r§lGrund§r: §c" + punishment.getReason()); } else { return BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + " Du bist bis zum " + - banTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT) + " gebannt. §r§lGrund§r: §c" + banReason); + punishment.getEndTime().toLocalDateTime().format(BungeeCore.DATE_FORMAT) + " gebannt. §r§lGrund§r: §c" + punishment.getReason()); } } public TextComponent muteMessage(){ - if (muteTime.before(PERMA_BAN)) { - return BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + "§cDu bist permanent gemuted. §r§lGrund§r: §c" + muteReason); + Punishment punishment = punishments.get(Punishment.PunishmentType.Mute); + if (punishment.isPerma()) { + return BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + "§cDu bist permanent gemuted. §r§lGrund§r: §c" + punishment.getReason()); } else { return BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + " Du bist bis zum " + - muteTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT) + " gemuted. §r§lGrund§r: §c" + muteReason); + punishment.getEndTime().toLocalDateTime().format(BungeeCore.DATE_FORMAT) + " gemuted. §r§lGrund§r: §c" + punishment.getReason()); } } @@ -205,10 +182,9 @@ public class SteamwarUser { BannedUserIPs.banIP(this, ip); } - public void ban(Timestamp time, String banReason){ - SQL.update("UPDATE UserData SET BanTime = ?, BanReason = ? WHERE id = ?", time, banReason, id); - banTime = time; - this.banReason = banReason; + public void ban(Timestamp time, String banReason, int from, boolean perma){ + punishments.remove(Punishment.PunishmentType.Ban); + punishments.put(Punishment.PunishmentType.Ban, Punishment.createPunishment(id, from, Punishment.PunishmentType.Ban, banReason, time, perma)); ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid); if(player != null){ @@ -218,10 +194,9 @@ public class SteamwarUser { updateBanIP(""); } - public void mute(Timestamp time, String muteReason){ - SQL.update("UPDATE UserData SET MuteTime = ?, MuteReason = ? WHERE id = ?", time, muteReason, id); - muteTime = time; - this.muteReason = muteReason; + public void mute(Timestamp time, String muteReason, int from, boolean perma){ + punishments.remove(Punishment.PunishmentType.Mute); + punishments.put(Punishment.PunishmentType.Mute, Punishment.createPunishment(id, from, Punishment.PunishmentType.Mute, muteReason, time, perma)); } private static SteamwarUser dbInit(ResultSet rs){ From 2c026a1d21938940bb091e72854d7e02b3e9f251 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 14 Nov 2020 23:25:39 +0100 Subject: [PATCH 02/30] Imports... --- src/de/steamwar/bungeecore/commands/BanCommand.java | 3 +-- src/de/steamwar/bungeecore/commands/MuteCommand.java | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/BanCommand.java b/src/de/steamwar/bungeecore/commands/BanCommand.java index c2d637d..8939ebc 100644 --- a/src/de/steamwar/bungeecore/commands/BanCommand.java +++ b/src/de/steamwar/bungeecore/commands/BanCommand.java @@ -22,7 +22,6 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.connection.ProxiedPlayer; import java.sql.Timestamp; import java.text.ParseException; @@ -62,7 +61,7 @@ public class BanCommand extends BasicCommand { public static Timestamp parseTime(CommandSender sender, String arg){ if(arg.equalsIgnoreCase("perma")) { - return Timestamp.from(Instant.ofEpochSecond(946684800)); + return Timestamp.from(Instant.ofEpochSecond(946674800)); }else{ SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy_HH:mm"); try{ diff --git a/src/de/steamwar/bungeecore/commands/MuteCommand.java b/src/de/steamwar/bungeecore/commands/MuteCommand.java index cf35b9d..6a681f4 100644 --- a/src/de/steamwar/bungeecore/commands/MuteCommand.java +++ b/src/de/steamwar/bungeecore/commands/MuteCommand.java @@ -24,7 +24,6 @@ import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.CommandSender; import java.sql.Timestamp; -import java.time.Instant; public class MuteCommand extends BasicCommand { From f20be78c5953c3e7e3738496463a37c6a313e948 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 14 Nov 2020 23:31:11 +0100 Subject: [PATCH 03/30] Announce Bans and Mutes --- src/de/steamwar/bungeecore/commands/BanCommand.java | 1 + src/de/steamwar/bungeecore/commands/MuteCommand.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/de/steamwar/bungeecore/commands/BanCommand.java b/src/de/steamwar/bungeecore/commands/BanCommand.java index 8939ebc..eef825b 100644 --- a/src/de/steamwar/bungeecore/commands/BanCommand.java +++ b/src/de/steamwar/bungeecore/commands/BanCommand.java @@ -56,6 +56,7 @@ public class BanCommand extends BasicCommand { } String msg = banReason.toString(); BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "Du hast " + target.getUserName() + " gebannt. Grund: §c" + msg); + ServerTeamchatCommand.sendToTeam(BungeeCore.CHAT_PREFIX + "§c" + target.getUserName() + " wurde von " + sender.getName() + " " + (args[1].equalsIgnoreCase("perma")?"Permanent":"bis zum " + banTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " gebannt. §f§lGrund: §f" + banReason); target.ban(banTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma")); } diff --git a/src/de/steamwar/bungeecore/commands/MuteCommand.java b/src/de/steamwar/bungeecore/commands/MuteCommand.java index 6a681f4..7e9b1ea 100644 --- a/src/de/steamwar/bungeecore/commands/MuteCommand.java +++ b/src/de/steamwar/bungeecore/commands/MuteCommand.java @@ -51,6 +51,7 @@ public class MuteCommand extends BasicCommand { muteReason.append(args[i]).append(" "); } String msg = muteReason.toString(); + ServerTeamchatCommand.sendToTeam(BungeeCore.CHAT_PREFIX + "§c" + target.getUserName() + " wurde von " + sender.getName() + " " + (args[1].equalsIgnoreCase("perma")?"Permanent":"bis zum " + muteTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " gemuted. §f§lGrund: §f" + muteReason); BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "Du hast " + target.getUserName() + " gemuted. Grund: §c" + msg); target.mute(muteTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma")); } From 6607b736ee0278de6bd233715ed8913ff42adc66 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 15 Nov 2020 11:02:23 +0100 Subject: [PATCH 04/30] Fixing... --- .../bungeecore/commands/BanCommand.java | 3 +- .../bungeecore/commands/MuteCommand.java | 3 +- .../bungeecore/commands/WhoisCommand.java | 4 +- .../steamwar/bungeecore/sql/Punishment.java | 48 ++++++------------- .../steamwar/bungeecore/sql/SteamwarUser.java | 16 +++++-- 5 files changed, 30 insertions(+), 44 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/BanCommand.java b/src/de/steamwar/bungeecore/commands/BanCommand.java index eef825b..ff4516b 100644 --- a/src/de/steamwar/bungeecore/commands/BanCommand.java +++ b/src/de/steamwar/bungeecore/commands/BanCommand.java @@ -55,9 +55,8 @@ public class BanCommand extends BasicCommand { banReason.append(args[i]).append(" "); } String msg = banReason.toString(); - BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "Du hast " + target.getUserName() + " gebannt. Grund: §c" + msg); - ServerTeamchatCommand.sendToTeam(BungeeCore.CHAT_PREFIX + "§c" + target.getUserName() + " wurde von " + sender.getName() + " " + (args[1].equalsIgnoreCase("perma")?"Permanent":"bis zum " + banTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " gebannt. §f§lGrund: §f" + banReason); target.ban(banTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma")); + ServerTeamchatCommand.sendToTeam(BungeeCore.CHAT_PREFIX + "§c" + target.getUserName() + " wurde von " + sender.getName() + " " + (args[1].equalsIgnoreCase("perma")?"Permanent":"bis zum " + banTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " gebannt. §f§lGrund: §f" + banReason); } 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 7e9b1ea..edd429a 100644 --- a/src/de/steamwar/bungeecore/commands/MuteCommand.java +++ b/src/de/steamwar/bungeecore/commands/MuteCommand.java @@ -51,8 +51,7 @@ public class MuteCommand extends BasicCommand { muteReason.append(args[i]).append(" "); } String msg = muteReason.toString(); - ServerTeamchatCommand.sendToTeam(BungeeCore.CHAT_PREFIX + "§c" + target.getUserName() + " wurde von " + sender.getName() + " " + (args[1].equalsIgnoreCase("perma")?"Permanent":"bis zum " + muteTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " gemuted. §f§lGrund: §f" + muteReason); - BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "Du hast " + target.getUserName() + " gemuted. Grund: §c" + msg); target.mute(muteTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma")); + ServerTeamchatCommand.sendToTeam(BungeeCore.CHAT_PREFIX + "§c" + target.getUserName() + " wurde von " + sender.getName() + " " + (args[1].equalsIgnoreCase("perma")?"Permanent":"bis zum " + muteTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " gemuted. §f§lGrund: §f" + muteReason); } } diff --git a/src/de/steamwar/bungeecore/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/commands/WhoisCommand.java index cc66c1a..d2e2f4b 100644 --- a/src/de/steamwar/bungeecore/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/commands/WhoisCommand.java @@ -71,8 +71,8 @@ public class WhoisCommand extends BasicCommand { Team team = Team.get(user.getTeam()); BungeeCore.send(player, "§7Team§8: §e" + team.getTeamName()); - BungeeCore.send(player, "§7Bestrafungen: "); - for (Punishment punishment : Punishment.getAllPunishmentsByPlayer(user.getId())) { + BungeeCore.send(player, "§7Strafen: "); + for (Punishment punishment : Punishment.getAllPunishmentsOfPlayer(user.getId())) { BungeeCore.send(player, "§7" + SteamwarUser.get(punishment.getPunisher()).getUserName() + "§8» §f§l" + punishment.getType().name() + ": §e" + punishment.getStartTime().toLocalDateTime().format(BungeeCore.DATE_FORMAT) + " - " + (punishment.isPerma()?"Perma":punishment.getEndTime().toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " §c" + punishment.getReason()); } diff --git a/src/de/steamwar/bungeecore/sql/Punishment.java b/src/de/steamwar/bungeecore/sql/Punishment.java index ec787a7..87d50dd 100644 --- a/src/de/steamwar/bungeecore/sql/Punishment.java +++ b/src/de/steamwar/bungeecore/sql/Punishment.java @@ -23,24 +23,22 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; import java.util.*; -import java.util.stream.Collectors; public class Punishment { - public static Punishment getPunishmentByPlayer(int user, PunishmentType type) { - ResultSet set = SQL.select("SELECT * FROM `Punishments` WHERE `PunishmentId` IN (SELECT MAX(`PunishmentId`) FROM Punishments WHERE UserId = ? AND Type = ?)", user, type.toDb()); + public static Punishment getPunishmentOfPlayer(int user, PunishmentType type) { + ResultSet set = SQL.select("SELECT * FROM `Punishments` WHERE EndTime < NOW() AND UserId = ? AND Type = ? ORDER BY PunishmentId DESC LIMIT 1", user, type.name()); try { if(!set.next()) return null; return new Punishment(set); - } catch (SQLException throwable) { - throwable.printStackTrace(); - throw new SecurityException("Could not Load Punishments", throwable); + } catch (SQLException e) { + throw new SecurityException("Could not Load Punishments", e); } } - public static Map getPunishmentsByPlayer(int user) { - ResultSet set = SQL.select("SELECT * FROM `Punishments` WHERE `PunishmentId` IN (SELECT MAX(`PunishmentId`) FROM Punishments WHERE UserId = ? GROUP BY Type)", user); + public static Map getPunishmentsOfPlayer(int user) { + ResultSet set = SQL.select("SELECT * FROM Punishments WHERE PunishmentId IN (SELECT MAX(PunishmentId) FROM Punishments WHERE UserId = ? GROUP BY Type)", user); try { Map punishmentMap = new HashMap<>(); while (set.next()) { @@ -48,30 +46,28 @@ public class Punishment { punishmentMap.put(punishment.getType(), punishment); } return punishmentMap; - } catch (SQLException throwable) { - throwable.printStackTrace(); - throw new SecurityException("Could not Load Punishments", throwable); + } catch (SQLException e) { + throw new SecurityException("Could not Load Punishments", e); } } - public static Set getAllPunishmentsByPlayer(int user) { + public static List getAllPunishmentsOfPlayer(int user) { ResultSet set = SQL.select("SELECT * FROM Punishments WHERE UserId = ? ORDER BY `PunishmentId` DESC", user); try { - Set punishments = new HashSet<>(); + List punishments = new ArrayList<>(); while (set.next()) { punishments.add(new Punishment(set)); } return punishments; - } catch (SQLException throwable) { - throwable.printStackTrace(); - throw new SecurityException("Could not Load all Punishments", throwable); + } catch (SQLException e) { + throw new SecurityException("Could not Load all Punishments", e); } } public static Punishment createPunishment(int user, int executor, PunishmentType type, String reason, Timestamp endTime, Boolean perma) { SQL.update("INSERT INTO Punishments (UserId, Punisher, Type, Reason, EndTime, Perma) VALUES (?, ?, ?, ?, ?, ?)", - user, executor, type.toDb(), reason, endTime, perma); - return getPunishmentByPlayer(user, type); + user, executor, type.name(), reason, endTime, perma); + return getPunishmentOfPlayer(user, type); } private final Timestamp startTime; @@ -79,15 +75,13 @@ public class Punishment { private final PunishmentType type; private final int user; private final String reason; - private final int id; private final int punisher; private final boolean perma; private Punishment(ResultSet set) throws SQLException { - id = set.getInt("PunishmentId"); user = set.getInt("UserId"); reason = set.getString("Reason"); - type = PunishmentType.getTypeFromDB(set.getString("Type")); + type = PunishmentType.valueOf(set.getString("Type")); startTime = set.getTimestamp("StartTime"); endTime = set.getTimestamp("EndTime"); punisher = set.getInt("Punisher"); @@ -114,10 +108,6 @@ public class Punishment { return reason; } - public int getId() { - return id; - } - public int getPunisher() { return punisher; } @@ -129,13 +119,5 @@ public class Punishment { public enum PunishmentType { Ban, Mute; - - public String toDb() { - return name().toLowerCase(); - } - - public static PunishmentType getTypeFromDB(String str) { - return Arrays.stream(values()).filter(punishmentType -> punishmentType.name().equalsIgnoreCase(str)).collect(Collectors.toList()).get(0); - } } } diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index 82ace6b..d092b9e 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -68,7 +68,7 @@ public class SteamwarUser { usersById.put(id, this); usersByName.put(userName.toLowerCase(), this); usersByUUID.put(uuid, this); - punishments = Punishment.getPunishmentsByPlayer(id); + punishments = Punishment.getPunishmentsOfPlayer(id); } public static SteamwarUser getOrCreate(PendingConnection connection){ @@ -149,13 +149,19 @@ public class SteamwarUser { } public boolean isBanned() { - return punishments.containsKey(Punishment.PunishmentType.Ban) && - (punishments.get(Punishment.PunishmentType.Ban).getEndTime().after(new Date()) || punishments.get(Punishment.PunishmentType.Ban).isPerma()); + if(!punishments.containsKey(Punishment.PunishmentType.Ban)) + return false; + return isCurrent(punishments.get(Punishment.PunishmentType.Ban)); } public boolean isMuted(){ - return punishments.containsKey(Punishment.PunishmentType.Mute) && - (punishments.get(Punishment.PunishmentType.Mute).getEndTime().after(new Date()) || punishments.get(Punishment.PunishmentType.Mute).isPerma()); + 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()); } public TextComponent banMessage(){ From 4dd593243e8181bd230ea2c1b37d43d51563cce1 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 15 Nov 2020 12:23:44 +0100 Subject: [PATCH 05/30] Fixing Recursive SQL Select --- .../steamwar/bungeecore/sql/Punishment.java | 59 ++++++++++++++----- .../steamwar/bungeecore/sql/SteamwarUser.java | 8 +++ 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/src/de/steamwar/bungeecore/sql/Punishment.java b/src/de/steamwar/bungeecore/sql/Punishment.java index 87d50dd..f6f1c2c 100644 --- a/src/de/steamwar/bungeecore/sql/Punishment.java +++ b/src/de/steamwar/bungeecore/sql/Punishment.java @@ -19,6 +19,8 @@ package de.steamwar.bungeecore.sql; +import de.steamwar.bungeecore.BungeeCore; + import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; @@ -27,7 +29,7 @@ import java.util.*; public class Punishment { public static Punishment getPunishmentOfPlayer(int user, PunishmentType type) { - ResultSet set = SQL.select("SELECT * FROM `Punishments` WHERE EndTime < NOW() AND UserId = ? AND Type = ? ORDER BY PunishmentId DESC LIMIT 1", user, type.name()); + ResultSet set = SQL.select("SELECT * FROM Punishments WHERE UserId = ? AND Type = ? ORDER BY PunishmentId DESC LIMIT 1", user, type.name()); try { if(!set.next()) return null; @@ -38,17 +40,14 @@ public class Punishment { } public static Map getPunishmentsOfPlayer(int user) { - ResultSet set = SQL.select("SELECT * FROM Punishments WHERE PunishmentId IN (SELECT MAX(PunishmentId) FROM Punishments WHERE UserId = ? GROUP BY Type)", user); - try { - Map punishmentMap = new HashMap<>(); - while (set.next()) { - Punishment punishment = new Punishment(set); - punishmentMap.put(punishment.getType(), punishment); - } - return punishmentMap; - } catch (SQLException e) { - throw new SecurityException("Could not Load Punishments", e); + Map punishmentMap = new HashMap<>(); + for (PunishmentType type : PunishmentType.values()) { + Punishment punishment = getPunishmentOfPlayer(user, type); + if(punishment == null) + continue; + punishmentMap.put(type, punishment); } + return punishmentMap; } public static List getAllPunishmentsOfPlayer(int user) { @@ -71,12 +70,13 @@ public class Punishment { } private final Timestamp startTime; - private final Timestamp endTime; + private Timestamp endTime; private final PunishmentType type; private final int user; - private final String reason; + private final int id; + private String reason; private final int punisher; - private final boolean perma; + private boolean perma; private Punishment(ResultSet set) throws SQLException { user = set.getInt("UserId"); @@ -86,6 +86,7 @@ public class Punishment { endTime = set.getTimestamp("EndTime"); punisher = set.getInt("Punisher"); perma = set.getBoolean("Perma"); + id = set.getInt("PunishmentId"); } public Timestamp getStartTime() { @@ -116,6 +117,36 @@ public class Punishment { return perma; } + public void updateEndTime(int from, String reason, Timestamp newUpdate, boolean perma) { + StringBuilder newReason = new StringBuilder(reason); + if(newUpdate.before(endTime)) + newReason.append(" verkürtz vom ") + .append(getBantime()) + .append(" von ") + .append(SteamwarUser.get(from).getUserName()) + .append(" Grund: ") + .append(reason); + else + newReason.append(" verlängert vom ") + .append(getBantime()) + .append(" von ") + .append(SteamwarUser.get(from).getUserName()) + .append(" Grund: ") + .append(reason); + + SQL.update("UPDATE Punishments SET EndTime = ?, Reason = ?, Perma = ? WHERE PunishmentId = ?", newUpdate, newReason.toString(), perma, id); + this.reason = newReason.toString(); + this.perma = perma; + this.endTime = newUpdate; + } + + public String getBantime() { + if(perma) + return "Permanent"; + else + return endTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT); + } + public enum PunishmentType { Ban, Mute; diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index d092b9e..b1e723f 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -189,6 +189,10 @@ public class SteamwarUser { } public void ban(Timestamp time, String banReason, int from, boolean perma){ + if(isBanned()) { + punishments.get(Punishment.PunishmentType.Ban).updateEndTime(from, banReason, time, perma); + return; + } punishments.remove(Punishment.PunishmentType.Ban); punishments.put(Punishment.PunishmentType.Ban, Punishment.createPunishment(id, from, Punishment.PunishmentType.Ban, banReason, time, perma)); @@ -201,6 +205,10 @@ public class SteamwarUser { } public void mute(Timestamp time, String muteReason, int from, boolean perma){ + if(isMuted()) { + punishments.get(Punishment.PunishmentType.Ban).updateEndTime(from, muteReason, time, perma); + return; + } punishments.remove(Punishment.PunishmentType.Mute); punishments.put(Punishment.PunishmentType.Mute, Punishment.createPunishment(id, from, Punishment.PunishmentType.Mute, muteReason, time, perma)); } From 5ee2d1030876feffa6a67b2f466dfeafc51f96f3 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 15 Nov 2020 13:04:31 +0100 Subject: [PATCH 06/30] Fixing BannedUserIp Delete --- src/de/steamwar/bungeecore/listeners/BanListener.java | 9 --------- src/de/steamwar/bungeecore/sql/SteamwarUser.java | 6 +++++- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/BanListener.java b/src/de/steamwar/bungeecore/listeners/BanListener.java index bc56de3..c9aadb7 100644 --- a/src/de/steamwar/bungeecore/listeners/BanListener.java +++ b/src/de/steamwar/bungeecore/listeners/BanListener.java @@ -47,15 +47,6 @@ public class BanListener extends BasicListener { List ips = BannedUserIPs.get(event.getConnection().getAddress().getAddress().getHostAddress()); if(!ips.isEmpty()){ - if(ips.stream().anyMatch(bannedUserIPs -> bannedUserIPs.getUserID() == user.getId())) { - ips.forEach(bannedUserIPs -> { - if(bannedUserIPs.getUserID() == user.getId()) - bannedUserIPs.remove(); - }); - ips.removeIf(bannedUserIPs -> bannedUserIPs.getUserID() == user.getId()); - if(ips.isEmpty()) - return; - } StringBuilder potentialBan = new StringBuilder(); potentialBan.append(BungeeCore.CHAT_PREFIX); potentialBan.append("§cMögliche Bannumgehung durch §r"); diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index b1e723f..8fc30fe 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -151,7 +151,11 @@ public class SteamwarUser { public boolean isBanned() { if(!punishments.containsKey(Punishment.PunishmentType.Ban)) return false; - return isCurrent(punishments.get(Punishment.PunishmentType.Ban)); + if(!isCurrent(punishments.get(Punishment.PunishmentType.Ban))) { + SQL.update("DELETE FROM BannedUserIPs WHERE UserID = ?", id); + return false; + } + return true; } public boolean isMuted(){ From aa73889ffe4dbb50c9d2222ef9c62fe908035660 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 15 Nov 2020 13:04:53 +0100 Subject: [PATCH 07/30] Fixing BannedUserIp Delete --- src/de/steamwar/bungeecore/sql/BannedUserIPs.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/de/steamwar/bungeecore/sql/BannedUserIPs.java b/src/de/steamwar/bungeecore/sql/BannedUserIPs.java index 243e5f3..6b371cc 100644 --- a/src/de/steamwar/bungeecore/sql/BannedUserIPs.java +++ b/src/de/steamwar/bungeecore/sql/BannedUserIPs.java @@ -78,8 +78,4 @@ public class BannedUserIPs { public java.sql.Timestamp getTimestamp() { return timestamp; } - - public void remove() { - SQL.update("DELETE FROM BannedUserIPs WHERE UserID = ?", userID); - } } From cfb12dfb75ac6adb38752e7e4a1c4910a20e538c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 15 Nov 2020 20:45:34 +0100 Subject: [PATCH 08/30] Fixing Ban extended --- src/de/steamwar/bungeecore/sql/Punishment.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/de/steamwar/bungeecore/sql/Punishment.java b/src/de/steamwar/bungeecore/sql/Punishment.java index f6f1c2c..31e3934 100644 --- a/src/de/steamwar/bungeecore/sql/Punishment.java +++ b/src/de/steamwar/bungeecore/sql/Punishment.java @@ -117,22 +117,22 @@ public class Punishment { return perma; } - public void updateEndTime(int from, String reason, Timestamp newUpdate, boolean perma) { - StringBuilder newReason = new StringBuilder(reason); - if(newUpdate.before(endTime)) - newReason.append(" verkürtz vom ") + public void updateEndTime(int from, String newreason, Timestamp newUpdate, boolean perma) { + StringBuilder newReason = new StringBuilder(this.reason); + if(newUpdate.before(endTime) || this.perma) + newReason.append("verkürtz vo" + (this.perma?"n":"m") + " ") .append(getBantime()) .append(" von ") .append(SteamwarUser.get(from).getUserName()) .append(" Grund: ") - .append(reason); + .append(newreason); else - newReason.append(" verlängert vom ") + newReason.append("verlängert vo" + (this.perma?"n":"m") + " ") .append(getBantime()) .append(" von ") .append(SteamwarUser.get(from).getUserName()) .append(" Grund: ") - .append(reason); + .append(newreason); SQL.update("UPDATE Punishments SET EndTime = ?, Reason = ?, Perma = ? WHERE PunishmentId = ?", newUpdate, newReason.toString(), perma, id); this.reason = newReason.toString(); From 4137ebb61bf19a96addfdfb133f340042c4e4b8c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 16 Nov 2020 15:47:28 +0100 Subject: [PATCH 09/30] Fixing... --- .../bungeecore/commands/BanCommand.java | 2 +- .../bungeecore/commands/MuteCommand.java | 2 +- .../steamwar/bungeecore/sql/Punishment.java | 24 +++++++------------ 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/BanCommand.java b/src/de/steamwar/bungeecore/commands/BanCommand.java index ff4516b..0e6e55b 100644 --- a/src/de/steamwar/bungeecore/commands/BanCommand.java +++ b/src/de/steamwar/bungeecore/commands/BanCommand.java @@ -56,7 +56,7 @@ public class BanCommand extends BasicCommand { } String msg = banReason.toString(); target.ban(banTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma")); - ServerTeamchatCommand.sendToTeam(BungeeCore.CHAT_PREFIX + "§c" + target.getUserName() + " wurde von " + sender.getName() + " " + (args[1].equalsIgnoreCase("perma")?"Permanent":"bis zum " + banTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " gebannt. §f§lGrund: §f" + banReason); + ServerTeamchatCommand.sendToTeam(BungeeCore.CHAT_PREFIX + target.getUserGroup().getColorCode() + target.getUserName() + "§c wurde von " + SteamwarUser.get(sender.getName()).getUserGroup().getColorCode() + sender.getName() + " §c" + (args[1].equalsIgnoreCase("perma")?"Permanent":"bis zum " + banTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " gebannt. §f§lGrund: §f" + banReason); } 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 edd429a..7590d22 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")); - ServerTeamchatCommand.sendToTeam(BungeeCore.CHAT_PREFIX + "§c" + target.getUserName() + " wurde von " + sender.getName() + " " + (args[1].equalsIgnoreCase("perma")?"Permanent":"bis zum " + muteTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " gemuted. §f§lGrund: §f" + muteReason); + ServerTeamchatCommand.sendToTeam(BungeeCore.CHAT_PREFIX + target.getUserGroup().getColorCode() + target.getUserName() + "§c wurde von " + SteamwarUser.get(sender.getName()).getUserGroup().getColorCode() + sender.getName() + " §c" + (args[1].equalsIgnoreCase("perma")?"Permanent":"bis zum " + muteTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " gemuted. §f§lGrund: §f" + muteReason); } } diff --git a/src/de/steamwar/bungeecore/sql/Punishment.java b/src/de/steamwar/bungeecore/sql/Punishment.java index 31e3934..abd3bee 100644 --- a/src/de/steamwar/bungeecore/sql/Punishment.java +++ b/src/de/steamwar/bungeecore/sql/Punishment.java @@ -119,20 +119,14 @@ public class Punishment { public void updateEndTime(int from, String newreason, Timestamp newUpdate, boolean perma) { StringBuilder newReason = new StringBuilder(this.reason); - if(newUpdate.before(endTime) || this.perma) - newReason.append("verkürtz vo" + (this.perma?"n":"m") + " ") - .append(getBantime()) - .append(" von ") - .append(SteamwarUser.get(from).getUserName()) - .append(" Grund: ") - .append(newreason); - else - newReason.append("verlängert vo" + (this.perma?"n":"m") + " ") - .append(getBantime()) - .append(" von ") - .append(SteamwarUser.get(from).getUserName()) - .append(" Grund: ") - .append(newreason); + newReason.append("verändert von ") + .append(SteamwarUser.get(from).getUserName()) + .append(" von ") + .append(getBantime(endTime, this.perma)) + .append(" auf ") + .append(getBantime(newUpdate, perma)) + .append(" wegen ") + .append(newreason); SQL.update("UPDATE Punishments SET EndTime = ?, Reason = ?, Perma = ? WHERE PunishmentId = ?", newUpdate, newReason.toString(), perma, id); this.reason = newReason.toString(); @@ -140,7 +134,7 @@ public class Punishment { this.endTime = newUpdate; } - public String getBantime() { + public String getBantime(Timestamp endTime, boolean perma) { if(perma) return "Permanent"; else From 3cb5eac639114d2a2ce197364638db8dd5126745 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 18 Nov 2020 14:03:52 +0100 Subject: [PATCH 10/30] Fixing Everything --- src/de/steamwar/bungeecore/BungeeCore.java | 2 +- src/de/steamwar/bungeecore/commands/BanCommand.java | 2 +- src/de/steamwar/bungeecore/commands/MuteCommand.java | 2 +- src/de/steamwar/bungeecore/sql/Punishment.java | 2 +- src/de/steamwar/bungeecore/sql/SteamwarUser.java | 3 ++- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index ce64862..843ba1b 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -54,7 +54,7 @@ public class BungeeCore extends Plugin { public static final String SERVER_TEAMCHAT_PREFIX = "§8STC §e"; public static final String TEAMCHAT_PREFIX = "§8TC §e"; - public static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("HH:mm dd.MM.yyyy"); + public static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm"); public static String CHAT_PREFIX; public static String WORLD_FOLDER; diff --git a/src/de/steamwar/bungeecore/commands/BanCommand.java b/src/de/steamwar/bungeecore/commands/BanCommand.java index 0e6e55b..159e07e 100644 --- a/src/de/steamwar/bungeecore/commands/BanCommand.java +++ b/src/de/steamwar/bungeecore/commands/BanCommand.java @@ -56,7 +56,7 @@ public class BanCommand extends BasicCommand { } String msg = banReason.toString(); target.ban(banTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma")); - ServerTeamchatCommand.sendToTeam(BungeeCore.CHAT_PREFIX + target.getUserGroup().getColorCode() + target.getUserName() + "§c wurde von " + SteamwarUser.get(sender.getName()).getUserGroup().getColorCode() + sender.getName() + " §c" + (args[1].equalsIgnoreCase("perma")?"Permanent":"bis zum " + banTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " gebannt. §f§lGrund: §f" + banReason); + ServerTeamchatCommand.sendToTeam(BungeeCore.CHAT_PREFIX + "§c" + target.getUserName() + " wurde von " + sender.getName() + " §c" + (args[1].equalsIgnoreCase("perma")?"Permanent":"bis zum " + banTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " gebannt. §f§lGrund: §f" + banReason); } 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 7590d22..ac53d05 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")); - ServerTeamchatCommand.sendToTeam(BungeeCore.CHAT_PREFIX + target.getUserGroup().getColorCode() + target.getUserName() + "§c wurde von " + SteamwarUser.get(sender.getName()).getUserGroup().getColorCode() + sender.getName() + " §c" + (args[1].equalsIgnoreCase("perma")?"Permanent":"bis zum " + muteTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " gemuted. §f§lGrund: §f" + muteReason); + ServerTeamchatCommand.sendToTeam(BungeeCore.CHAT_PREFIX + "§c" + target.getUserName() + " wurde von " + sender.getName() + " §c" + (args[1].equalsIgnoreCase("perma")?"Permanent":"bis zum " + muteTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " gemuted. §f§lGrund: §f" + muteReason); } } diff --git a/src/de/steamwar/bungeecore/sql/Punishment.java b/src/de/steamwar/bungeecore/sql/Punishment.java index abd3bee..72e5c0a 100644 --- a/src/de/steamwar/bungeecore/sql/Punishment.java +++ b/src/de/steamwar/bungeecore/sql/Punishment.java @@ -63,7 +63,7 @@ public class Punishment { } } - public static Punishment createPunishment(int user, int executor, PunishmentType type, String reason, Timestamp endTime, Boolean perma) { + public static Punishment createPunishment(int user, int executor, PunishmentType type, String reason, Timestamp endTime, boolean perma) { SQL.update("INSERT INTO Punishments (UserId, Punisher, Type, Reason, EndTime, Perma) VALUES (?, ?, ?, ?, ?, ?)", user, executor, type.name(), reason, endTime, perma); return getPunishmentOfPlayer(user, type); diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index 8fc30fe..0916686 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -153,6 +153,7 @@ public class SteamwarUser { return false; if(!isCurrent(punishments.get(Punishment.PunishmentType.Ban))) { SQL.update("DELETE FROM BannedUserIPs WHERE UserID = ?", id); + punishments.remove(Punishment.PunishmentType.Ban); return false; } return true; @@ -210,7 +211,7 @@ public class SteamwarUser { public void mute(Timestamp time, String muteReason, int from, boolean perma){ if(isMuted()) { - punishments.get(Punishment.PunishmentType.Ban).updateEndTime(from, muteReason, time, perma); + punishments.get(Punishment.PunishmentType.Mute).updateEndTime(from, muteReason, time, perma); return; } punishments.remove(Punishment.PunishmentType.Mute); From 63ce857c4589fbbc50ed280783bd441521ed4029 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 18 Nov 2020 14:23:46 +0100 Subject: [PATCH 11/30] Add MoreMultilingualTransfer --- src/de/steamwar/bungeecore/commands/BanCommand.java | 6 ++++-- src/de/steamwar/messages/BungeeCore.properties | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/BanCommand.java b/src/de/steamwar/bungeecore/commands/BanCommand.java index 330960a..f770ee8 100644 --- a/src/de/steamwar/bungeecore/commands/BanCommand.java +++ b/src/de/steamwar/bungeecore/commands/BanCommand.java @@ -19,6 +19,7 @@ package de.steamwar.bungeecore.commands; +import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.CommandSender; @@ -38,7 +39,7 @@ public class BanCommand extends BasicCommand { @Override public void execute(CommandSender sender, String[] args) { if(args.length < 3){ - BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "/ban [Spieler] [dd.mm.yyyy oder dd.mm.yyyy_hh:mm oder perma] [Grund]"); + Message.send("USAGE_BAN", sender); return; } @@ -56,7 +57,8 @@ public class BanCommand extends BasicCommand { } String msg = banReason.toString(); target.ban(banTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma")); - ServerTeamchatCommand.sendToTeam(BungeeCore.CHAT_PREFIX + "§c" + target.getUserName() + " wurde von " + sender.getName() + " §c" + (args[1].equalsIgnoreCase("perma")?"Permanent":"bis zum " + banTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " gebannt. §f§lGrund: §f" + banReason); + Message.team("BAN_TEAM_BANNED", target.getUserName(), sender.getName(), + (args[1].equalsIgnoreCase("perma")?Message.parse("BAN_PERMA", sender):Message.parse("BAN_UNTIL", sender) + banTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)), msg); } public static Timestamp parseTime(CommandSender sender, String arg){ diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 64916c9..32b2ac1 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -66,8 +66,10 @@ USAGE_IGNORE=§8/§7ignore §8[§eSpieler§8] #Various commands ALERT=§f{0} -BAN_YOU_BANNED=§7Du hast §e{0} §7gebannt§8. §7Grund§8: §c{1} +BAN_TEAM_BANNED=§c {0} wurde von {1} {2} gebannt. §f§lGrund: §f{3} BAN_INVALID_TIME=§cUngültige Zeitangabe. +BAN_PERMA=Permanent +BAN_UNTIL=bis zum BUG_SAVED=§7Dein Bugreport wurde gespeichert. From 293b037ffd901c01ab3aadb0a1fbed67402abbf5 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 19 Nov 2020 17:13:02 +0100 Subject: [PATCH 12/30] Update Message --- src/de/steamwar/bungeecore/commands/MuteCommand.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/commands/MuteCommand.java b/src/de/steamwar/bungeecore/commands/MuteCommand.java index ac53d05..dc43bae 100644 --- a/src/de/steamwar/bungeecore/commands/MuteCommand.java +++ b/src/de/steamwar/bungeecore/commands/MuteCommand.java @@ -20,6 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.CommandSender; @@ -52,6 +53,7 @@ public class MuteCommand extends BasicCommand { } String msg = muteReason.toString(); target.mute(muteTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma")); - ServerTeamchatCommand.sendToTeam(BungeeCore.CHAT_PREFIX + "§c" + target.getUserName() + " wurde von " + sender.getName() + " §c" + (args[1].equalsIgnoreCase("perma")?"Permanent":"bis zum " + muteTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " gemuted. §f§lGrund: §f" + muteReason); + Message.team("BAN_TEAM_BANNED", target.getUserName(), sender.getName(), + (args[1].equalsIgnoreCase("perma")?Message.parse("BAN_PERMA", sender):Message.parse("BAN_UNTIL", sender) + muteTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)), msg); } } From 2d9f686ba80767a1f8383364c1d5e7c72bbaa504 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 19 Nov 2020 17:14:56 +0100 Subject: [PATCH 13/30] Update Message Mute --- src/de/steamwar/bungeecore/commands/MuteCommand.java | 4 ++-- src/de/steamwar/messages/BungeeCore.properties | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/MuteCommand.java b/src/de/steamwar/bungeecore/commands/MuteCommand.java index dc43bae..4cbda7b 100644 --- a/src/de/steamwar/bungeecore/commands/MuteCommand.java +++ b/src/de/steamwar/bungeecore/commands/MuteCommand.java @@ -35,7 +35,7 @@ public class MuteCommand extends BasicCommand { @Override public void execute(CommandSender sender, String[] args) { if(args.length < 3){ - BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "/mute [Spieler] [dd.mm.yyyy oder dd.mm.yyyy_hh:mm oder perma] [Grund]"); + Message.send("USAGE_MUTE", sender); return; } @@ -53,7 +53,7 @@ public class MuteCommand extends BasicCommand { } String msg = muteReason.toString(); target.mute(muteTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma")); - Message.team("BAN_TEAM_BANNED", target.getUserName(), sender.getName(), + Message.team("MUTE_TEAM_MUTED", target.getUserName(), sender.getName(), (args[1].equalsIgnoreCase("perma")?Message.parse("BAN_PERMA", sender):Message.parse("BAN_UNTIL", sender) + muteTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)), msg); } } diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 32b2ac1..8f2a672 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -61,12 +61,14 @@ HELP_BAU_BAU_HOVER=§eNützliche Zusatzfunktionen #Usage description of various commands USAGE_ALERT=§8/§7alert §8[§eNachricht§8] USAGE_BAN=§8/§7ban §8[§eSpieler§8] [§edd§8.§emm§8.§eyyyy §7oder §edd§8.§emm§8.§eyyyy§8_§ehh§8:§emm §7oder §eperma§8] [§eGrund§8] +USAGE_MUTE=§8/§7mute §8[§eSpieler§8] [§edd§8.§emm§8.§eyyyy §7oder §edd§8.§emm§8.§eyyyy§8_§ehh§8:§emm §7oder §eperma§8] [§eGrund§8] USAGE_IGNORE=§8/§7ignore §8[§eSpieler§8] #Various commands ALERT=§f{0} BAN_TEAM_BANNED=§c {0} wurde von {1} {2} gebannt. §f§lGrund: §f{3} +MUTE_TEAM_MUTED=§c {0} wurde von {1} {2} gemuted. §f§lGrund: §f{3} BAN_INVALID_TIME=§cUngültige Zeitangabe. BAN_PERMA=Permanent BAN_UNTIL=bis zum From 01f40b9440f58a410dc63b91cb3cf04fe57b90ff Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 23 Nov 2020 18:26:04 +0100 Subject: [PATCH 14/30] Changing Messages --- src/de/steamwar/bungeecore/sql/Punishment.java | 3 ++- src/de/steamwar/bungeecore/sql/SteamwarUser.java | 16 ++++++++++------ src/de/steamwar/messages/BungeeCore.properties | 5 +++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/de/steamwar/bungeecore/sql/Punishment.java b/src/de/steamwar/bungeecore/sql/Punishment.java index 72e5c0a..e39f854 100644 --- a/src/de/steamwar/bungeecore/sql/Punishment.java +++ b/src/de/steamwar/bungeecore/sql/Punishment.java @@ -20,6 +20,7 @@ package de.steamwar.bungeecore.sql; import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.Message; import java.sql.ResultSet; import java.sql.SQLException; @@ -136,7 +137,7 @@ public class Punishment { public String getBantime(Timestamp endTime, boolean perma) { if(perma) - return "Permanent"; + return Message.parse("BAN_PERMA", SteamwarUser.get(user).getPlayer()); else return endTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT); } diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index 0916686..62dc67c 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -20,6 +20,7 @@ package de.steamwar.bungeecore.sql; import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.commands.WebregisterCommand; import de.steamwar.bungeecore.listeners.ConnectionListener; import net.md_5.bungee.api.ProxyServer; @@ -148,6 +149,10 @@ public class SteamwarUser { return team; } + public ProxiedPlayer getPlayer() { + return BungeeCore.get().getProxy().getPlayer(uuid); + } + public boolean isBanned() { if(!punishments.containsKey(Punishment.PunishmentType.Ban)) return false; @@ -172,20 +177,19 @@ public class SteamwarUser { public TextComponent banMessage(){ Punishment punishment = punishments.get(Punishment.PunishmentType.Ban); if (punishment.isPerma()) { - return BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + "§cDu bist permanent gebannt. §r§lGrund§r: §c" + punishment.getReason()); + return BungeeCore.stringToText(Message.parsePrefixed("BANNED_MESSAGE_PERMA", getPlayer(), punishment.getReason())); } else { - return BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + " Du bist bis zum " + - punishment.getEndTime().toLocalDateTime().format(BungeeCore.DATE_FORMAT) + " gebannt. §r§lGrund§r: §c" + punishment.getReason()); + return BungeeCore.stringToText(Message.parsePrefixed("BANNED_MESSAGE_UNTIL", getPlayer(), punishment.getEndTime().toLocalDateTime().format(BungeeCore.DATE_FORMAT), + punishment.getReason())); } } public TextComponent muteMessage(){ Punishment punishment = punishments.get(Punishment.PunishmentType.Mute); if (punishment.isPerma()) { - return BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + "§cDu bist permanent gemuted. §r§lGrund§r: §c" + punishment.getReason()); + return BungeeCore.stringToText(Message.parsePrefixed("MUTED_MESSAGE_PERMA", getPlayer(), punishment.getReason())); } else { - return BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + " Du bist bis zum " + - punishment.getEndTime().toLocalDateTime().format(BungeeCore.DATE_FORMAT) + " gemuted. §r§lGrund§r: §c" + punishment.getReason()); + return BungeeCore.stringToText(Message.parsePrefixed("MUTED_MESSAGE_UNTIL",getPlayer(), punishment.getEndTime().toLocalDateTime().format(BungeeCore.DATE_FORMAT), punishment.getReason())); } } diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 8f2a672..8d08c2c 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -68,7 +68,12 @@ USAGE_IGNORE=§8/§7ignore §8[§eSpieler§8] ALERT=§f{0} BAN_TEAM_BANNED=§c {0} wurde von {1} {2} gebannt. §f§lGrund: §f{3} +BANNED_MESSAGE_PERMA=§cDu bist permanent gebannt. §r§lGrund§r: §c{0} +BANNED_MESSAGE_UNTIL=Du bist bis zum {0} gebannt. §r§lGrund§r: §c{1} MUTE_TEAM_MUTED=§c {0} wurde von {1} {2} gemuted. §f§lGrund: §f{3} +MUTED_MESSAGE_PERMA=§cDu bist permanent gemuted. §r§lGrund§r: §c{0} +MUTED_MESSAGE_UNTIL=Du bist bis zum {0} gemuted. §r§lGrund§r: §c{1} +BAN_CHANGED={0} verändert von {1} von BAN_INVALID_TIME=§cUngültige Zeitangabe. BAN_PERMA=Permanent BAN_UNTIL=bis zum From 06d18866b64575a40510f5de38b53aba7966b62d Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 24 Nov 2020 16:38:47 +0100 Subject: [PATCH 15/30] Add Multilang --- src/de/steamwar/bungeecore/sql/Punishment.java | 13 ++++--------- src/de/steamwar/messages/BungeeCore.properties | 2 +- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/de/steamwar/bungeecore/sql/Punishment.java b/src/de/steamwar/bungeecore/sql/Punishment.java index e39f854..321fb87 100644 --- a/src/de/steamwar/bungeecore/sql/Punishment.java +++ b/src/de/steamwar/bungeecore/sql/Punishment.java @@ -119,15 +119,10 @@ public class Punishment { } public void updateEndTime(int from, String newreason, Timestamp newUpdate, boolean perma) { - StringBuilder newReason = new StringBuilder(this.reason); - newReason.append("verändert von ") - .append(SteamwarUser.get(from).getUserName()) - .append(" von ") - .append(getBantime(endTime, this.perma)) - .append(" auf ") - .append(getBantime(newUpdate, perma)) - .append(" wegen ") - .append(newreason); + String newReason = Message.parse("BAN_CHANGED", SteamwarUser.get(from).getPlayer(), SteamwarUser.get(from).getUserName(), + getBantime(endTime, this.perma), + getBantime(newUpdate, perma), + newreason); SQL.update("UPDATE Punishments SET EndTime = ?, Reason = ?, Perma = ? WHERE PunishmentId = ?", newUpdate, newReason.toString(), perma, id); this.reason = newReason.toString(); diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 8d08c2c..63f47ac 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -73,7 +73,7 @@ BANNED_MESSAGE_UNTIL=Du bist bis zum {0} gebannt. §r§lGrund§r: §c{1} MUTE_TEAM_MUTED=§c {0} wurde von {1} {2} gemuted. §f§lGrund: §f{3} MUTED_MESSAGE_PERMA=§cDu bist permanent gemuted. §r§lGrund§r: §c{0} MUTED_MESSAGE_UNTIL=Du bist bis zum {0} gemuted. §r§lGrund§r: §c{1} -BAN_CHANGED={0} verändert von {1} von +BAN_CHANGED={0} verändert von {1} von {2} auf {3} wegen {4} BAN_INVALID_TIME=§cUngültige Zeitangabe. BAN_PERMA=Permanent BAN_UNTIL=bis zum From fec517f5a1c606a7c3ef1d1b494f7ffa144c761e Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 30 Dec 2020 13:28:09 +0100 Subject: [PATCH 16/30] WIP --- src/de/steamwar/bungeecore/BungeeCore.java | 1 - src/de/steamwar/bungeecore/Message.java | 14 +++++++++---- .../bungeecore/commands/BanCommand.java | 4 ++-- .../bungeecore/commands/MsgCommand.java | 2 +- .../bungeecore/commands/MuteCommand.java | 6 +++--- .../bungeecore/commands/RCommand.java | 2 +- .../bungeecore/listeners/BanListener.java | 2 +- .../bungeecore/listeners/ChatListener.java | 4 ++-- .../steamwar/bungeecore/sql/Punishment.java | 16 ++++++++------ .../steamwar/bungeecore/sql/SteamwarUser.java | 21 ++++++++----------- .../steamwar/messages/BungeeCore.properties | 1 + 11 files changed, 40 insertions(+), 33 deletions(-) diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 971f0ab..82ff320 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -55,7 +55,6 @@ public class BungeeCore extends Plugin { public static final String SERVER_TEAMCHAT_PREFIX = "§8STC §e"; public static final String TEAMCHAT_PREFIX = "§8TC §e"; - public static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm"); public static String CHAT_PREFIX; public static String WORLD_FOLDER; diff --git a/src/de/steamwar/bungeecore/Message.java b/src/de/steamwar/bungeecore/Message.java index 1e5e0c0..2d2fbb2 100644 --- a/src/de/steamwar/bungeecore/Message.java +++ b/src/de/steamwar/bungeecore/Message.java @@ -31,6 +31,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import java.text.MessageFormat; import java.util.Locale; import java.util.ResourceBundle; +import java.util.function.Function; public class Message { private Message(){} @@ -119,14 +120,19 @@ public class Message { } } - public static void team(String message, Object... params){ + public static void team(String message, Function... params){ team(message, ChatMessageType.SYSTEM, params); } - public static void team(String message, ChatMessageType type, Object... params){ + public static void team(String message, ChatMessageType type, Function... params){ for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()){ - if(player.getGroups().contains(ConnectionListener.TEAM_GROUP)) - sendPrefixless(message, player, type, params); + if(player.getGroups().contains(ConnectionListener.TEAM_GROUP)) { + Object[] objects = new Object[params.length]; + for (int i = 0; i < params.length; i++) { + objects[i] = params[i].apply(player); + } + sendPrefixless(message, player, type, objects); + } } } } \ No newline at end of file diff --git a/src/de/steamwar/bungeecore/commands/BanCommand.java b/src/de/steamwar/bungeecore/commands/BanCommand.java index bccd5d9..52b2638 100644 --- a/src/de/steamwar/bungeecore/commands/BanCommand.java +++ b/src/de/steamwar/bungeecore/commands/BanCommand.java @@ -19,7 +19,6 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.CommandSender; @@ -28,6 +27,7 @@ import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.Instant; +import java.time.format.DateTimeFormatter; import java.util.Date; public class BanCommand extends BasicCommand { @@ -58,7 +58,7 @@ public class BanCommand extends BasicCommand { String msg = banReason.toString(); target.ban(banTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma")); Message.team("BAN_TEAM_BANNED", target.getUserName(), sender.getName(), - (args[1].equalsIgnoreCase("perma")?Message.parse("BAN_PERMA", sender):Message.parse("BAN_UNTIL", sender) + banTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)), msg); + (args[1].equalsIgnoreCase("perma")?Message.parse("BAN_PERMA", sender):Message.parse("BAN_UNTIL", sender) + banTime.toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", sender)))), msg); } public static Timestamp parseTime(CommandSender sender, String arg){ diff --git a/src/de/steamwar/bungeecore/commands/MsgCommand.java b/src/de/steamwar/bungeecore/commands/MsgCommand.java index 5d5baba..c013386 100644 --- a/src/de/steamwar/bungeecore/commands/MsgCommand.java +++ b/src/de/steamwar/bungeecore/commands/MsgCommand.java @@ -48,7 +48,7 @@ public class MsgCommand extends BasicCommand { SteamwarUser user = SteamwarUser.get(player); if(user.isMuted()){ - sender.sendMessage(user.muteMessage()); + sender.sendMessage(user.muteMessage(player)); return; } diff --git a/src/de/steamwar/bungeecore/commands/MuteCommand.java b/src/de/steamwar/bungeecore/commands/MuteCommand.java index 4cbda7b..043428e 100644 --- a/src/de/steamwar/bungeecore/commands/MuteCommand.java +++ b/src/de/steamwar/bungeecore/commands/MuteCommand.java @@ -19,12 +19,12 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.CommandSender; import java.sql.Timestamp; +import java.time.format.DateTimeFormatter; public class MuteCommand extends BasicCommand { @@ -53,7 +53,7 @@ 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(), - (args[1].equalsIgnoreCase("perma")?Message.parse("BAN_PERMA", sender):Message.parse("BAN_UNTIL", sender) + muteTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)), msg); + Message.team("MUTE_TEAM_MUTED", player -> target.getUserName(), player -> sender.getName(), + player -> (args[1].equalsIgnoreCase("perma")?Message.parse("BAN_PERMA", player):Message.parse("BAN_UNTIL", player) + muteTime.toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", player)))), player -> msg); } } diff --git a/src/de/steamwar/bungeecore/commands/RCommand.java b/src/de/steamwar/bungeecore/commands/RCommand.java index 566dbcf..8a1dd03 100644 --- a/src/de/steamwar/bungeecore/commands/RCommand.java +++ b/src/de/steamwar/bungeecore/commands/RCommand.java @@ -44,7 +44,7 @@ public class RCommand extends BasicCommand { SteamwarUser user = SteamwarUser.get(player); if(user.isMuted()){ - sender.sendMessage(user.muteMessage()); + sender.sendMessage(user.muteMessage(player)); return; } diff --git a/src/de/steamwar/bungeecore/listeners/BanListener.java b/src/de/steamwar/bungeecore/listeners/BanListener.java index 9c8b85c..2d27685 100644 --- a/src/de/steamwar/bungeecore/listeners/BanListener.java +++ b/src/de/steamwar/bungeecore/listeners/BanListener.java @@ -44,7 +44,7 @@ public class BanListener extends BasicListener { if(user.isBanned()) { user.updateBanIP(event.getConnection().getAddress().getAddress().getHostAddress()); event.setCancelled(true); - event.setCancelReason(user.banMessage()); + event.setCancelReason(user.banMessage((ProxiedPlayer) event.getConnection())); return; } diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index 0ee6265..c08c389 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -137,7 +137,7 @@ public class ChatListener extends BasicListener { SteamwarUser user = SteamwarUser.get(sender); if(user.isMuted()){ - sender.sendMessage(user.muteMessage()); + sender.sendMessage(user.muteMessage(sender)); e.setCancelled(true); return; } @@ -200,7 +200,7 @@ public class ChatListener extends BasicListener { SteamwarUser user = SteamwarUser.get(sender); if(user.isMuted()){ - sender.sendMessage(user.muteMessage()); + sender.sendMessage(user.muteMessage(sender)); e.setCancelled(true); return; } diff --git a/src/de/steamwar/bungeecore/sql/Punishment.java b/src/de/steamwar/bungeecore/sql/Punishment.java index 321fb87..295a330 100644 --- a/src/de/steamwar/bungeecore/sql/Punishment.java +++ b/src/de/steamwar/bungeecore/sql/Punishment.java @@ -21,10 +21,12 @@ package de.steamwar.bungeecore.sql; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; +import net.md_5.bungee.api.connection.ProxiedPlayer; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; +import java.time.format.DateTimeFormatter; import java.util.*; public class Punishment { @@ -119,22 +121,24 @@ public class Punishment { } public void updateEndTime(int from, String newreason, Timestamp newUpdate, boolean perma) { - String newReason = Message.parse("BAN_CHANGED", SteamwarUser.get(from).getPlayer(), SteamwarUser.get(from).getUserName(), + ProxiedPlayer player = BungeeCore.get().getProxy().getPlayer(SteamwarUser.get(from).getUuid()); + String newReason = Message.parse("BAN_CHANGED", player, SteamwarUser.get(from).getUserName(), getBantime(endTime, this.perma), getBantime(newUpdate, perma), newreason); + //TODO Add User - SQL.update("UPDATE Punishments SET EndTime = ?, Reason = ?, Perma = ? WHERE PunishmentId = ?", newUpdate, newReason.toString(), perma, id); - this.reason = newReason.toString(); + SQL.update("UPDATE Punishments SET EndTime = ?, Reason = ?, Perma = ? WHERE PunishmentId = ?", newUpdate, newReason, perma, id); + this.reason = newReason; this.perma = perma; this.endTime = newUpdate; } - public String getBantime(Timestamp endTime, boolean perma) { + public String getBantime(Timestamp endTime, boolean perma, ProxiedPlayer player) { if(perma) - return Message.parse("BAN_PERMA", SteamwarUser.get(user).getPlayer()); + return Message.parse("BAN_PERMA", player); else - return endTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT); + return endTime.toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", player))); } public enum PunishmentType { diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index b1dc309..b681b24 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -33,6 +33,7 @@ import java.net.UnknownHostException; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; +import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -149,10 +150,6 @@ public class SteamwarUser { return team; } - public ProxiedPlayer getPlayer() { - return BungeeCore.get().getProxy().getPlayer(uuid); - } - public boolean isBanned() { if(!punishments.containsKey(Punishment.PunishmentType.Ban)) return false; @@ -174,22 +171,22 @@ public class SteamwarUser { return punishment.isPerma() || punishment.getEndTime().after(new Date()); } - public TextComponent banMessage(){ + public TextComponent banMessage(ProxiedPlayer player){ Punishment punishment = punishments.get(Punishment.PunishmentType.Ban); if (punishment.isPerma()) { - return BungeeCore.stringToText(Message.parsePrefixed("BANNED_MESSAGE_PERMA", getPlayer(), punishment.getReason())); + return BungeeCore.stringToText(Message.parsePrefixed("BANNED_MESSAGE_PERMA", player, punishment.getReason())); } else { - return BungeeCore.stringToText(Message.parsePrefixed("BANNED_MESSAGE_UNTIL", getPlayer(), punishment.getEndTime().toLocalDateTime().format(BungeeCore.DATE_FORMAT), + return BungeeCore.stringToText(Message.parsePrefixed("BANNED_MESSAGE_UNTIL", player, punishment.getEndTime().toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", player))), punishment.getReason())); } } - public TextComponent muteMessage(){ + public TextComponent muteMessage(ProxiedPlayer player){ Punishment punishment = punishments.get(Punishment.PunishmentType.Mute); if (punishment.isPerma()) { - return BungeeCore.stringToText(Message.parsePrefixed("MUTED_MESSAGE_PERMA", getPlayer(), punishment.getReason())); + return BungeeCore.stringToText(Message.parsePrefixed("MUTED_MESSAGE_PERMA", player, punishment.getReason())); } else { - return BungeeCore.stringToText(Message.parsePrefixed("MUTED_MESSAGE_UNTIL",getPlayer(), punishment.getEndTime().toLocalDateTime().format(BungeeCore.DATE_FORMAT), punishment.getReason())); + return BungeeCore.stringToText(Message.parsePrefixed("MUTED_MESSAGE_UNTIL", player, punishment.getEndTime().toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", player))), punishment.getReason())); } } @@ -208,12 +205,12 @@ public class SteamwarUser { ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid); if(player != null){ updateBanIP(player.getAddress().getAddress().getHostAddress()); - player.disconnect(banMessage()); + player.disconnect(banMessage(player)); for (BannedUserIPs banned: BannedUserIPs.get(player.getAddress().getAddress().getHostAddress())) { SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID()); if(bannedUser.isBanned() && banned.getTimestamp().before(time)) - bannedUser.ban(time, bannedUser.banReason); + bannedUser.ban(time, banReason, from, perma); } }else updateBanIP(""); diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index f1e3015..883a77c 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -1,5 +1,6 @@ PREFIX=§eSteam§8War» SPACER= +TIMEFORMAT=dd.MM.yyyy HH:mm UNKNOWN_COMMAND=§cUnbekannter Befehl. UNKNOWN_PLAYER=§cDiesen Spieler gibt es nicht. From e76c79c8d8820f2b47337237b6aeffd287d3d79d Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 15 Jan 2021 19:29:44 +0100 Subject: [PATCH 17/30] Add Some Refactoring and enabling Doublelayer Messages --- src/de/steamwar/bungeecore/Message.java | 57 +++++++++++++------ .../bungeecore/commands/BanCommand.java | 4 +- .../bungeecore/commands/MuteCommand.java | 4 +- .../bungeecore/commands/WhoisCommand.java | 4 +- .../bungeecore/listeners/BanListener.java | 2 +- .../steamwar/bungeecore/sql/Punishment.java | 6 +- .../steamwar/messages/BungeeCore.properties | 4 +- 7 files changed, 50 insertions(+), 31 deletions(-) diff --git a/src/de/steamwar/bungeecore/Message.java b/src/de/steamwar/bungeecore/Message.java index 2d2fbb2..f3f0b26 100644 --- a/src/de/steamwar/bungeecore/Message.java +++ b/src/de/steamwar/bungeecore/Message.java @@ -28,27 +28,36 @@ import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; +import java.text.ChoiceFormat; import java.text.MessageFormat; import java.util.Locale; import java.util.ResourceBundle; -import java.util.function.Function; public class Message { private Message(){} - public static TextComponent parseToComponent(String message, boolean prefixed, CommandSender sender, Object... params){ - return new TextComponent(TextComponent.fromLegacyText(parse(message, prefixed, sender, params))); + public static TextComponent parseToComponent(String message, boolean prefixed, CommandSender sender, int[] useFormatter, Object... params){ + return new TextComponent(TextComponent.fromLegacyText(parse(message, prefixed, sender, useFormatter, params))); + } + + public static String parsePrefixed(String message, CommandSender sender, int[] useFormatter, Object... params){ + return parse(message, true, sender, useFormatter, params); } public static String parsePrefixed(String message, CommandSender sender, Object... params){ - return parse(message, true, sender, params); + return parse(message, true, sender, new int[0], params); + } + + + public static String parse(String message, CommandSender sender, int[] useFormatter, Object... params){ + return parse(message, false, sender, useFormatter, params); } public static String parse(String message, CommandSender sender, Object... params){ - return parse(message, false, sender, params); + return parse(message, false, sender, new int[0], params); } - private static String parse(String message, boolean prefixed, CommandSender sender,Object... params){ + private static String parse(String message, boolean prefixed, CommandSender sender, int[] useFormatter, Object... params){ Locale locale; if(sender instanceof ProxiedPlayer) locale = ((ProxiedPlayer)sender).getLocale(); @@ -61,7 +70,11 @@ public class Message { pattern = resourceBundle.getObject("PREFIX") + " "; pattern += (String)resourceBundle.getObject(message); - return new MessageFormat(pattern, locale).format(params); + MessageFormat format = new MessageFormat(pattern, locale); + for (int i : useFormatter) { + params[i] = new MessageFormat((String) resourceBundle.getObject((String) params[i]), locale).format(params); + } + return format.format(params); } public static void send(String message, CommandSender sender, Object... params){ @@ -80,6 +93,10 @@ public class Message { send(message, false, sender, type, null, null, params); } + public static void sendPrefixless(String message, CommandSender sender, ChatMessageType type, int[] useFormatter, Object... params) { + send(message, false, sender, type, null, null, useFormatter, params); + } + public static void send(String message, CommandSender sender, String onHover, ClickEvent onClick, Object... params){ send(message, true, sender, ChatMessageType.SYSTEM, onHover, onClick, params); } @@ -88,10 +105,10 @@ public class Message { send(message, false, sender, ChatMessageType.SYSTEM, onHover, onClick, params); } - public static void send(String message, boolean prefixed, CommandSender sender, ChatMessageType type, String onHover, ClickEvent onClick, Object... params){ + public static void send(String message, boolean prefixed, CommandSender sender, ChatMessageType type, String onHover, ClickEvent onClick, int[] useFormatter, Object... params){ if(type == ChatMessageType.CHAT && sender instanceof ProxiedPlayer && ((ProxiedPlayer)sender).getChatMode() != ProxiedPlayer.ChatMode.SHOWN) return; - TextComponent msg = parseToComponent(message, prefixed, sender, params); + TextComponent msg = parseToComponent(message, prefixed, sender, useFormatter, params); if(onHover != null) msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(onHover))); if(onClick != null) @@ -102,9 +119,13 @@ public class Message { sender.sendMessage(msg); } + public static void send(String message, boolean prefixed, CommandSender sender, ChatMessageType type, String onHover, ClickEvent onClick, Object... params){ + send(message, prefixed, sender, type, onHover, onClick, new int[0], params); + } + public static void broadcast(String message, String onHover, ClickEvent onClick, Object... params){ for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) - send(message, player, parse(onHover, false, player), onClick, params); + send(message, player, parse(onHover, false, player, new int[0]), onClick, params); } public static void broadcast(String message, Object... params){ @@ -120,18 +141,18 @@ public class Message { } } - public static void team(String message, Function... params){ - team(message, ChatMessageType.SYSTEM, params); + public static void team(String message, Object... params){ + team(message, ChatMessageType.SYSTEM, new int[0], params); } - public static void team(String message, ChatMessageType type, Function... params){ + public static void team(String message, int[] useChoice, Object... params){ + team(message, ChatMessageType.SYSTEM, useChoice, params); + } + + public static void team(String message, ChatMessageType type, int[] useFormatter, Object... params){ for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()){ if(player.getGroups().contains(ConnectionListener.TEAM_GROUP)) { - Object[] objects = new Object[params.length]; - for (int i = 0; i < params.length; i++) { - objects[i] = params[i].apply(player); - } - sendPrefixless(message, player, type, objects); + sendPrefixless(message, player, type, useFormatter, params); } } } diff --git a/src/de/steamwar/bungeecore/commands/BanCommand.java b/src/de/steamwar/bungeecore/commands/BanCommand.java index 52b2638..8e6830f 100644 --- a/src/de/steamwar/bungeecore/commands/BanCommand.java +++ b/src/de/steamwar/bungeecore/commands/BanCommand.java @@ -27,7 +27,6 @@ import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.Instant; -import java.time.format.DateTimeFormatter; import java.util.Date; public class BanCommand extends BasicCommand { @@ -57,8 +56,7 @@ public class BanCommand extends BasicCommand { } String msg = banReason.toString(); target.ban(banTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma")); - Message.team("BAN_TEAM_BANNED", target.getUserName(), sender.getName(), - (args[1].equalsIgnoreCase("perma")?Message.parse("BAN_PERMA", sender):Message.parse("BAN_UNTIL", sender) + banTime.toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", sender)))), msg); + Message.team("BAN_TEAM_BANNED", new int[]{2}, target.getUserName(), sender.getName(), (args[1].equalsIgnoreCase("perma")?"BAN_PERMA":"BAN_UNTIL"), msg, banTime); } 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 043428e..e8661b9 100644 --- a/src/de/steamwar/bungeecore/commands/MuteCommand.java +++ b/src/de/steamwar/bungeecore/commands/MuteCommand.java @@ -24,7 +24,6 @@ import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.CommandSender; import java.sql.Timestamp; -import java.time.format.DateTimeFormatter; public class MuteCommand extends BasicCommand { @@ -53,7 +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", player -> target.getUserName(), player -> sender.getName(), - player -> (args[1].equalsIgnoreCase("perma")?Message.parse("BAN_PERMA", player):Message.parse("BAN_UNTIL", player) + muteTime.toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", player)))), player -> msg); + Message.team("MUTE_TEAM_MUTED", target.getUserName(), new int[]{2}, sender.getName(), (args[1].equalsIgnoreCase("perma")?"BAN_PERMA":"BAN_UNTIL"), msg, muteTime); } } diff --git a/src/de/steamwar/bungeecore/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/commands/WhoisCommand.java index d2e2f4b..4b1d562 100644 --- a/src/de/steamwar/bungeecore/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/commands/WhoisCommand.java @@ -20,6 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.Team; @@ -28,6 +29,7 @@ import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.text.DecimalFormat; +import java.time.format.DateTimeFormatter; public class WhoisCommand extends BasicCommand { public WhoisCommand(){ @@ -74,7 +76,7 @@ public class WhoisCommand extends BasicCommand { BungeeCore.send(player, "§7Strafen: "); for (Punishment punishment : Punishment.getAllPunishmentsOfPlayer(user.getId())) { BungeeCore.send(player, "§7" + SteamwarUser.get(punishment.getPunisher()).getUserName() + "§8» §f§l" + punishment.getType().name() + ": §e" - + punishment.getStartTime().toLocalDateTime().format(BungeeCore.DATE_FORMAT) + " - " + (punishment.isPerma()?"Perma":punishment.getEndTime().toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " §c" + punishment.getReason()); + + punishment.getStartTime().toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", player))) + " - " + (punishment.isPerma()?"Perma":punishment.getEndTime().toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", player)))) + " §c" + punishment.getReason()); } } } diff --git a/src/de/steamwar/bungeecore/listeners/BanListener.java b/src/de/steamwar/bungeecore/listeners/BanListener.java index 2d27685..a4fbbec 100644 --- a/src/de/steamwar/bungeecore/listeners/BanListener.java +++ b/src/de/steamwar/bungeecore/listeners/BanListener.java @@ -70,7 +70,7 @@ public class BanListener extends BasicListener { for(BannedUserIPs banned : ips) { SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID()); potentialBan.append(Message.parse("BAN_AVOIDING_LIST", target, bannedUser.getUserName(), - banned.getTimestamp().toLocalDateTime().format(BungeeCore.DATE_FORMAT))); + banned.getTimestamp().toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", target))))); } TextComponent msg = new TextComponent(potentialBan.toString()); diff --git a/src/de/steamwar/bungeecore/sql/Punishment.java b/src/de/steamwar/bungeecore/sql/Punishment.java index 295a330..ada287d 100644 --- a/src/de/steamwar/bungeecore/sql/Punishment.java +++ b/src/de/steamwar/bungeecore/sql/Punishment.java @@ -134,11 +134,11 @@ public class Punishment { this.endTime = newUpdate; } - public String getBantime(Timestamp endTime, boolean perma, ProxiedPlayer player) { + public String getBantime(Timestamp endTime, boolean perma) { if(perma) - return Message.parse("BAN_PERMA", player); + return "Permanent"; else - return endTime.toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", player))); + return endTime.toLocalDateTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm")); } public enum PunishmentType { diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 883a77c..35f5a15 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -96,7 +96,7 @@ USAGE_IGNORE=§8/§7ignore §8[§eSpieler§8] #Various commands ALERT=§f{0} -BAN_TEAM_BANNED=§c {0} wurde von {1} {2} gebannt. §f§lGrund: §f{3} +BAN_TEAM_BANNED=§c{0} wurde von {1} {2} gebannt. §f§lGrund: §f{3} BANNED_MESSAGE_PERMA=§cDu bist permanent gebannt. §r§lGrund§r: §c{0} BANNED_MESSAGE_UNTIL=Du bist bis zum {0} gebannt. §r§lGrund§r: §c{1} MUTE_TEAM_MUTED=§c {0} wurde von {1} {2} gemuted. §f§lGrund: §f{3} @@ -105,7 +105,7 @@ MUTED_MESSAGE_UNTIL=Du bist bis zum {0} gemuted. §r§lGrund§r: §c{1} BAN_CHANGED={0} verändert von {1} von {2} auf {3} wegen {4} BAN_INVALID_TIME=§cUngültige Zeitangabe. BAN_PERMA=Permanent -BAN_UNTIL=bis zum +BAN_UNTIL=bis zum {4} BAN_AVOIDING_ALERT=§cMögliche Bannumgehung durch §r{0}§c: §c BAN_AVOIDING_LIST={0} §e{1} §c BAN_AVOIDING_BAN_HOVER=§cBanne Spieler wegen Bannumgehung From e0222982cbfe40832d5176d35a15b2afa9ab89d0 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 16 Jan 2021 13:38:47 +0100 Subject: [PATCH 18/30] Fixing some Things --- src/de/steamwar/bungeecore/Message.java | 50 +++++++++++-------- .../bungeecore/commands/BanCommand.java | 5 +- .../bungeecore/commands/MuteCommand.java | 2 +- .../bungeecore/commands/WhoisCommand.java | 18 +++---- .../steamwar/bungeecore/sql/Punishment.java | 9 +--- .../steamwar/bungeecore/sql/SteamwarUser.java | 18 ++++++- .../steamwar/messages/BungeeCore.properties | 24 ++++++--- 7 files changed, 78 insertions(+), 48 deletions(-) diff --git a/src/de/steamwar/bungeecore/Message.java b/src/de/steamwar/bungeecore/Message.java index 6845085..705bae3 100644 --- a/src/de/steamwar/bungeecore/Message.java +++ b/src/de/steamwar/bungeecore/Message.java @@ -28,36 +28,26 @@ import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; -import java.text.ChoiceFormat; import java.text.MessageFormat; import java.util.Locale; import java.util.ResourceBundle; public class Message { - private Message(){} - public static TextComponent parseToComponent(String message, boolean prefixed, CommandSender sender, int[] useFormatter, Object... params){ - return new TextComponent(TextComponent.fromLegacyText(parse(message, prefixed, sender, useFormatter, params))); - } - - public static String parsePrefixed(String message, CommandSender sender, int[] useFormatter, Object... params){ - return parse(message, true, sender, useFormatter, params); + public static TextComponent parseToComponent(String message, boolean prefixed, CommandSender sender, Object... params){ + return new TextComponent(TextComponent.fromLegacyText(parse(message, prefixed, sender, params))); } public static String parsePrefixed(String message, CommandSender sender, Object... params){ - return parse(message, true, sender, new int[0], params); + return parse(message, true, sender, params); } - public static String parse(String message, CommandSender sender, int[] useFormatter, Object... params){ - return parse(message, false, sender, useFormatter, params); - } - public static String parse(String message, CommandSender sender, Object... params){ - return parse(message, false, sender, new int[0], params); + return parse(message, false, sender, params); } - private static String parse(String message, boolean prefixed, CommandSender sender, int[] useFormatter, Object... params){ + private static String parse(String message, boolean prefixed, CommandSender sender, Object... params){ Locale locale = null; if(sender instanceof ProxiedPlayer) locale = ((ProxiedPlayer)sender).getLocale(); @@ -71,8 +61,11 @@ public class Message { pattern += (String)resourceBundle.getObject(message); MessageFormat format = new MessageFormat(pattern, locale); - for (int i : useFormatter) { - params[i] = new MessageFormat((String) resourceBundle.getObject((String) params[i]), locale).format(params); + for (int i = 0; i < params.length; i++) { + if(params[i] instanceof Message) { + Message msg = (Message) params[i]; + params[i] = parse(msg.getMessage(), sender, msg.getParams()); + } } return format.format(params); } @@ -105,10 +98,10 @@ public class Message { send(message, false, sender, ChatMessageType.SYSTEM, onHover, onClick, params); } - public static void send(String message, boolean prefixed, CommandSender sender, ChatMessageType type, String onHover, ClickEvent onClick, int[] useFormatter, Object... params){ + public static void send(String message, boolean prefixed, CommandSender sender, ChatMessageType type, String onHover, ClickEvent onClick, Object... params){ if(type == ChatMessageType.CHAT && sender instanceof ProxiedPlayer && ((ProxiedPlayer)sender).getChatMode() != ProxiedPlayer.ChatMode.SHOWN) return; - TextComponent msg = parseToComponent(message, prefixed, sender, useFormatter, params); + TextComponent msg = parseToComponent(message, prefixed, sender, params); if(onHover != null) msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(onHover))); if(onClick != null) @@ -143,8 +136,25 @@ public class Message { public static void team(String message, ChatMessageType type, Object... params){ for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()){ - if(player.getGroups().contains(ConnectionListener.TEAM_GROUP)) + if(player.getGroups().contains(ConnectionListener.TEAM_GROUP)) { sendPrefixless(message, player, type, params); + } } } + + private final String message; + private final Object[] params; + + public Message(String message, Object... params) { + this.message = message; + this.params = params; + } + + public String getMessage() { + return message; + } + + public Object[] getParams() { + return params; + } } \ No newline at end of file diff --git a/src/de/steamwar/bungeecore/commands/BanCommand.java b/src/de/steamwar/bungeecore/commands/BanCommand.java index 8e6830f..e977fef 100644 --- a/src/de/steamwar/bungeecore/commands/BanCommand.java +++ b/src/de/steamwar/bungeecore/commands/BanCommand.java @@ -54,9 +54,10 @@ public class BanCommand extends BasicCommand { for (int i = 2; i < args.length; i++){ banReason.append(args[i]).append(" "); } + boolean isPerma = args[1].equalsIgnoreCase("perma"); String msg = banReason.toString(); - target.ban(banTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma")); - Message.team("BAN_TEAM_BANNED", new int[]{2}, target.getUserName(), sender.getName(), (args[1].equalsIgnoreCase("perma")?"BAN_PERMA":"BAN_UNTIL"), msg, banTime); + 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); } 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 e8661b9..0ab8d29 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(), new int[]{2}, sender.getName(), (args[1].equalsIgnoreCase("perma")?"BAN_PERMA":"BAN_UNTIL"), msg, muteTime); + Message.team("MUTE_TEAM_MUTED", 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 4b1d562..567574e 100644 --- a/src/de/steamwar/bungeecore/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/commands/WhoisCommand.java @@ -29,7 +29,6 @@ import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.text.DecimalFormat; -import java.time.format.DateTimeFormatter; public class WhoisCommand extends BasicCommand { public WhoisCommand(){ @@ -64,19 +63,18 @@ public class WhoisCommand extends BasicCommand { } private static void sendUserinfo(ProxiedPlayer player, SteamwarUser user) { - BungeeCore.send(player, "§7Username§8: §e" + user.getUserName()); - BungeeCore.send(player, "§7UUID§8: §e" + user.getUuid().toString(), "", new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, user.getUuid().toString())); - BungeeCore.send(player, "§7ID§8: §e" + user.getId()); - BungeeCore.send(player, "§7Beigetreten am§8: §e" + user.getFirstjoin().toString()); - BungeeCore.send(player, "§7Online Time§8: §e" + new DecimalFormat("###.##").format(user.getOnlinetime() / (double) 3600) + "h"); + Message.send("WHOIS_USERNAME", player, user.getUserName()); + Message.send("WHOIS_UUID", player, Message.parse("WHOIS_UUID_HOVER", player), new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, user.getUuid().toString()), user.getUuid().toString()); + Message.send("WHOIS_ID", player, user.getId()); + Message.send("WHOIS_JOINED_FIRST", player, user.getFirstjoin().toString()); + Message.send("WHOIS_HOURS_PLAYED", player, new DecimalFormat("###.##").format(user.getOnlinetime() / (double) 3600)); Team team = Team.get(user.getTeam()); - BungeeCore.send(player, "§7Team§8: §e" + team.getTeamName()); + Message.send("WHOIS_TEAM", player, team.getTeamColor(), team.getTeamKuerzel(), team.getTeamName()); - BungeeCore.send(player, "§7Strafen: "); + Message.send("WHOIS_PUNISHMENTS", player); for (Punishment punishment : Punishment.getAllPunishmentsOfPlayer(user.getId())) { - BungeeCore.send(player, "§7" + SteamwarUser.get(punishment.getPunisher()).getUserName() + "§8» §f§l" + punishment.getType().name() + ": §e" - + punishment.getStartTime().toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", player))) + " - " + (punishment.isPerma()?"Perma":punishment.getEndTime().toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", player)))) + " §c" + punishment.getReason()); + Message.send("WHOIS_PUNISHMENT", player, SteamwarUser.get(punishment.getPunisher()).getUserName(), punishment.getType().name(), punishment.getBantime(punishment.getStartTime(), false), punishment.getBantime(punishment.getEndTime(), punishment.isPerma()), punishment.getReason()); } } } diff --git a/src/de/steamwar/bungeecore/sql/Punishment.java b/src/de/steamwar/bungeecore/sql/Punishment.java index ada287d..964961d 100644 --- a/src/de/steamwar/bungeecore/sql/Punishment.java +++ b/src/de/steamwar/bungeecore/sql/Punishment.java @@ -44,12 +44,8 @@ public class Punishment { public static Map getPunishmentsOfPlayer(int user) { Map punishmentMap = new HashMap<>(); - for (PunishmentType type : PunishmentType.values()) { - Punishment punishment = getPunishmentOfPlayer(user, type); - if(punishment == null) - continue; - punishmentMap.put(type, punishment); - } + punishmentMap.put(PunishmentType.Ban, getPunishmentOfPlayer(user, PunishmentType.Ban)); + punishmentMap.put(PunishmentType.Mute, getPunishmentOfPlayer(user, PunishmentType.Mute)); return punishmentMap; } @@ -126,7 +122,6 @@ public class Punishment { getBantime(endTime, this.perma), getBantime(newUpdate, perma), newreason); - //TODO Add User SQL.update("UPDATE Punishments SET EndTime = ?, Reason = ?, Perma = ? WHERE PunishmentId = ?", newUpdate, newReason, perma, id); this.reason = newReason; diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index b681b24..08ec23b 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -33,6 +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; @@ -70,7 +71,7 @@ public class SteamwarUser { usersById.put(id, this); usersByName.put(userName.toLowerCase(), this); usersByUUID.put(uuid, this); - punishments = Punishment.getPunishmentsOfPlayer(id); + punishments = null; } public static SteamwarUser getOrCreate(PendingConnection connection){ @@ -150,7 +151,14 @@ 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))) { @@ -162,6 +170,7 @@ public class SteamwarUser { } public boolean isMuted(){ + loadPunishments(); if(!punishments.containsKey(Punishment.PunishmentType.Mute)) return false; return isCurrent(punishments.get(Punishment.PunishmentType.Mute)); @@ -172,6 +181,7 @@ public class SteamwarUser { } 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())); @@ -182,6 +192,7 @@ 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())); @@ -195,6 +206,7 @@ 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; @@ -217,6 +229,7 @@ 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; @@ -249,7 +262,8 @@ public class SteamwarUser { public Timestamp getFirstjoin() { ResultSet set = SQL.select("SELECT MIN(StartTime) AS FirstJoin FROM Session WHERE UserID = ?", id); try { - set.next(); + if(!set.next()) + return Timestamp.from(Instant.MIN); return set.getTimestamp("FirstJoin"); } catch (SQLException throwables) { throw new SecurityException("Could not load First Join"); diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 77412b9..5c06f67 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -100,16 +100,17 @@ USAGE_IGNORE=§8/§7ignore §8[§eSpieler§8] #Various commands ALERT=§f{0} +#Ban&Mute-Command BAN_TEAM_BANNED=§c{0} wurde von {1} {2} gebannt. §f§lGrund: §f{3} BANNED_MESSAGE_PERMA=§cDu bist permanent gebannt. §r§lGrund§r: §c{0} -BANNED_MESSAGE_UNTIL=Du bist bis zum {0} gebannt. §r§lGrund§r: §c{1} -MUTE_TEAM_MUTED=§c {0} wurde von {1} {2} gemuted. §f§lGrund: §f{3} +BANNED_MESSAGE_UNTIL=§cDu bist bis zum {0} gebannt. §r§lGrund§r: §c{1} +MUTE_TEAM_MUTED=§c{0} wurde von {1} {2} gemuted. §f§lGrund: §f{3} MUTED_MESSAGE_PERMA=§cDu bist permanent gemuted. §r§lGrund§r: §c{0} -MUTED_MESSAGE_UNTIL=Du bist bis zum {0} gemuted. §r§lGrund§r: §c{1} -BAN_CHANGED={0} verändert von {1} von {2} auf {3} wegen {4} +MUTED_MESSAGE_UNTIL=§cDu bist bis zum {0} gemuted. §r§lGrund§r: §c{1} +BAN_CHANGED=§c{0} verändert von {1} von {2} auf {3} wegen {4} BAN_INVALID_TIME=§cUngültige Zeitangabe. BAN_PERMA=Permanent -BAN_UNTIL=bis zum {4} +BAN_UNTIL=bis zum {0} BAN_AVOIDING_ALERT=§cMögliche Bannumgehung durch §r{0}§c: §c BAN_AVOIDING_LIST={0} §e{1} §c BAN_AVOIDING_BAN_HOVER=§cBanne Spieler wegen Bannumgehung @@ -157,4 +158,15 @@ CHECK_RANK_HOVER=§aMit diesem Rang freigeben CHECK_ACCEPTED=§aDein §e{0} {1} §ewurde freigegeben§8! CHECK_ACCEPTED_TEAM=§7Die Schematic §e{0} §7von §e{1} §7ist nun freigegeben! 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! \ No newline at end of file +CHECK_DECLINED_TEAM=§7Die Schematic §e{0} §7von §e{1} §awurde aufgrund von §e{2} §7abgelehnt! + +#WhoisCommand +WHOIS_USERNAME=§7Username§8: §e{0} +WHOIS_UUID=§7UUID§8: §e{0} +WHOIS_UUID_HOVER=§eUUID Kopieren +WHOIS_ID=§7ID§8: §e{0} +WHOIS_JOINED_FIRST=§7Beigetreten am§8: §e{0} +WHOIS_HOURS_PLAYED=§7Online Time§8: §e{0}h +WHOIS_TEAM=§7Team§8: §e[§{0}{1}§e] {2} +WHOIS_PUNISHMENTS=§7Strafen: +WHOIS_PUNISHMENT=§7{0}§8» §f§l{1}: §e{2} - {3} §f{4} \ No newline at end of file From 0d643d618af0231312c9c34c66a1296a3ecb5157 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 16 Jan 2021 13:50:34 +0100 Subject: [PATCH 19/30] Add ML to Mod Autoban --- src/de/steamwar/bungeecore/listeners/mods/Utils.java | 9 +++++---- src/de/steamwar/messages/BungeeCore.properties | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/mods/Utils.java b/src/de/steamwar/bungeecore/listeners/mods/Utils.java index 1ca83e3..e6907c5 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Utils.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Utils.java @@ -20,6 +20,7 @@ package de.steamwar.bungeecore.listeners.mods; import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.sql.Mod; import de.steamwar.bungeecore.sql.Mod.ModType; import de.steamwar.bungeecore.sql.SteamwarUser; @@ -72,9 +73,9 @@ class Utils { if(mods.size() == 1){ if(max == ModType.YELLOW) - player.disconnect(BungeeCore.stringToText("§7Deaktiviere den Mod §e" + mods.get(0).getModName() + "§7, um weiter auf §eSteam§8War §7spielen zu können.")); + player.disconnect(BungeeCore.stringToText(Message.parse("MOD_YELLOW_SING", player, mods.get(0).getModName()))); else{ - user.ban(Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), "Versuchte Benutzung des Mods " + mods.get(0).getModName(), 0, false); + user.ban(Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), Message.parse("MOD_RED_SING", player, mods.get(0).getModName()), 0, false); BungeeCore.log(Level.SEVERE, user.getUserName() + " " + user.getId() + " wurde automatisch wegen des Mods " + mods.get(0).getModName() + " gebannt."); } }else{ @@ -82,9 +83,9 @@ class Utils { mods.forEach(mod -> sb.append(mod.getModName()).append('\n')); if(max == ModType.YELLOW) - player.disconnect(BungeeCore.stringToText("§7Deaktiviere die Mods\n§e" + sb.toString() + "§7um weiter auf §eSteam§8War §7spielen zu können.")); + player.disconnect(BungeeCore.stringToText(Message.parse("MOD_YELLOW_PLUR", player, sb.toString()))); else{ - user.ban(Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), "Versuchte Benutzung der Mods\n" + sb.toString(), 0, false); + user.ban(Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), Message.parse("MOD_RED_PLUR", player, sb.toString()), 0, false); BungeeCore.log(Level.SEVERE, user.getUserName() + " " + user.getId() + " wurde automatisch wegen der Mods " + sb.toString() + " gebannt."); } } diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 5c06f67..8487703 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -97,6 +97,12 @@ USAGE_BAN=§8/§7ban §8[§eSpieler§8] [§edd§8.§emm§8.§eyyyy §7oder §edd USAGE_MUTE=§8/§7mute §8[§eSpieler§8] [§edd§8.§emm§8.§eyyyy §7oder §edd§8.§emm§8.§eyyyy§8_§ehh§8:§emm §7oder §eperma§8] [§eGrund§8] USAGE_IGNORE=§8/§7ignore §8[§eSpieler§8] +#ModListener +MOD_RED_SING=Versuchte Benutzung des Mods {0} +MOD_RED_PLUR=Versuchte Benutzung der Mods\n{0} +MOD_YELLOW_SING=§7Deaktiviere den Mod §e{0}§7, um weiter auf §eSteam§8War §7spielen zu können. +MOD_YELLOW_PLUR=§7Deaktiviere die Mods\n§e{0}\n§7um weiter auf §eSteam§8War §7spielen zu können. + #Various commands ALERT=§f{0} From f99b10ade201d51ccd7185edf3a526d15731bd34 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 16 Jan 2021 16:41:34 +0100 Subject: [PATCH 20/30] Fix NPE --- src/de/steamwar/bungeecore/listeners/BanListener.java | 1 - src/de/steamwar/bungeecore/sql/Punishment.java | 10 ++++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/BanListener.java b/src/de/steamwar/bungeecore/listeners/BanListener.java index a4fbbec..c62a17d 100644 --- a/src/de/steamwar/bungeecore/listeners/BanListener.java +++ b/src/de/steamwar/bungeecore/listeners/BanListener.java @@ -19,7 +19,6 @@ package de.steamwar.bungeecore.listeners; -import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.sql.BannedUserIPs; import de.steamwar.bungeecore.sql.SteamwarUser; diff --git a/src/de/steamwar/bungeecore/sql/Punishment.java b/src/de/steamwar/bungeecore/sql/Punishment.java index 964961d..0e47e05 100644 --- a/src/de/steamwar/bungeecore/sql/Punishment.java +++ b/src/de/steamwar/bungeecore/sql/Punishment.java @@ -43,10 +43,12 @@ public class Punishment { } public static Map getPunishmentsOfPlayer(int user) { - Map punishmentMap = new HashMap<>(); - punishmentMap.put(PunishmentType.Ban, getPunishmentOfPlayer(user, PunishmentType.Ban)); - punishmentMap.put(PunishmentType.Mute, getPunishmentOfPlayer(user, PunishmentType.Mute)); - return punishmentMap; + 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; } public static List getAllPunishmentsOfPlayer(int user) { From 9970266d90a854cda7f8867ea8c4095dab2e4e92 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 16 Jan 2021 18:36:19 +0100 Subject: [PATCH 21/30] Fix Ban Changed --- src/de/steamwar/bungeecore/sql/Punishment.java | 3 ++- src/de/steamwar/messages/BungeeCore.properties | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/bungeecore/sql/Punishment.java b/src/de/steamwar/bungeecore/sql/Punishment.java index 0e47e05..2e14a2a 100644 --- a/src/de/steamwar/bungeecore/sql/Punishment.java +++ b/src/de/steamwar/bungeecore/sql/Punishment.java @@ -120,7 +120,8 @@ public class Punishment { public void updateEndTime(int from, String newreason, Timestamp newUpdate, boolean perma) { ProxiedPlayer player = BungeeCore.get().getProxy().getPlayer(SteamwarUser.get(from).getUuid()); - String newReason = Message.parse("BAN_CHANGED", player, SteamwarUser.get(from).getUserName(), + String newReason = Message.parse("BAN_CHANGED", player, reason, + SteamwarUser.get(from).getUserName(), getBantime(endTime, this.perma), getBantime(newUpdate, perma), newreason); diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 8487703..f61d1ea 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -121,8 +121,6 @@ BAN_AVOIDING_ALERT=§cMögliche Bannumgehung durch §r{0}§c: §c BAN_AVOIDING_LIST={0} §e{1} §c BAN_AVOIDING_BAN_HOVER=§cBanne Spieler wegen Bannumgehung -MUTE_MESSAGE_YOU=§7Du hast §e{0} §7gemutet§8. §7Grund§8: §c{1} - BUG_MESSAGE=§7Dein Bugreport wurde gespeichert. IGNORE_YOURSELF=§cWie willst du dich selber ignorieren? From 898a948512d6803a23f7b0d25079977fcf25b321 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 16 Jan 2021 19:47:21 +0100 Subject: [PATCH 22/30] Fixing Whois --- .../bungeecore/commands/WhoisCommand.java | 23 ++++++++++++++----- .../steamwar/bungeecore/sql/SteamwarUser.java | 10 ++++---- .../steamwar/messages/BungeeCore.properties | 14 ++++++----- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/commands/WhoisCommand.java index 567574e..a183f00 100644 --- a/src/de/steamwar/bungeecore/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/commands/WhoisCommand.java @@ -19,7 +19,6 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; @@ -28,7 +27,10 @@ import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; +import java.sql.Timestamp; import java.text.DecimalFormat; +import java.time.Instant; +import java.util.List; public class WhoisCommand extends BasicCommand { public WhoisCommand(){ @@ -42,7 +44,7 @@ public class WhoisCommand extends BasicCommand { ProxiedPlayer player = (ProxiedPlayer) sender; if(args.length == 0){ - BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§c/whois [Spieler/ID]"); + Message.send("WHOIS_SYNTAX", player); return; } @@ -55,7 +57,7 @@ public class WhoisCommand extends BasicCommand { } if(user == null) { - BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spieler!"); + Message.send("UNKNOWN_PLAYER", player); return; } @@ -66,14 +68,23 @@ public class WhoisCommand extends BasicCommand { Message.send("WHOIS_USERNAME", player, user.getUserName()); Message.send("WHOIS_UUID", player, Message.parse("WHOIS_UUID_HOVER", player), new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, user.getUuid().toString()), user.getUuid().toString()); Message.send("WHOIS_ID", player, user.getId()); - Message.send("WHOIS_JOINED_FIRST", player, user.getFirstjoin().toString()); + Timestamp firstJoin = user.getFirstjoin(); + if(firstJoin == null) + Message.send("WHOIS_JOINED_FIRST", player, "0000-00-00 00:00:00"); + else + Message.send("WHOIS_JOINED_FIRST", player, firstJoin.toString()); Message.send("WHOIS_HOURS_PLAYED", player, new DecimalFormat("###.##").format(user.getOnlinetime() / (double) 3600)); Team team = Team.get(user.getTeam()); - Message.send("WHOIS_TEAM", player, team.getTeamColor(), team.getTeamKuerzel(), team.getTeamName()); + Message.send("WHOIS_TEAM", player, Message.parse("WHOIS_TEAM_HOVER", player, team.getTeamName()), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team info " + team.getTeamKuerzel()), team.getTeamColor(), team.getTeamKuerzel(), team.getTeamName()); Message.send("WHOIS_PUNISHMENTS", player); - for (Punishment punishment : Punishment.getAllPunishmentsOfPlayer(user.getId())) { + List punishmentList = Punishment.getAllPunishmentsOfPlayer(user.getId()); + if(punishmentList.isEmpty()) { + Message.send("WHOIS_NO_PUNISHMENT", player); + return; + } + for (Punishment punishment : punishmentList) { Message.send("WHOIS_PUNISHMENT", player, SteamwarUser.get(punishment.getPunisher()).getUserName(), punishment.getType().name(), punishment.getBantime(punishment.getStartTime(), false), punishment.getBantime(punishment.getEndTime(), punishment.isPerma()), punishment.getReason()); } } diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index 08ec23b..3f926a6 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -251,19 +251,21 @@ public class SteamwarUser { public double getOnlinetime() { ResultSet set = SQL.select("SELECT SUM(UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime)) as Playtime FROM Session WHERE UserID = ?", id); try { - set.next(); + if(!set.next()) + return 0; return set.getBigDecimal("Playtime").doubleValue(); } catch (SQLException throwables) { - throwables.printStackTrace(); + throw new SecurityException("Could not load Online Time", throwables); + } catch (NullPointerException e) { //When no Sessions are recorded + return 0; } - return 0; } public Timestamp getFirstjoin() { ResultSet set = SQL.select("SELECT MIN(StartTime) AS FirstJoin FROM Session WHERE UserID = ?", id); try { if(!set.next()) - return Timestamp.from(Instant.MIN); + return null; return set.getTimestamp("FirstJoin"); } catch (SQLException throwables) { throw new SecurityException("Could not load First Join"); diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index f61d1ea..9b9df0d 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -99,7 +99,7 @@ USAGE_IGNORE=§8/§7ignore §8[§eSpieler§8] #ModListener MOD_RED_SING=Versuchte Benutzung des Mods {0} -MOD_RED_PLUR=Versuchte Benutzung der Mods\n{0} +MOD_RED_PLUR=Versuchte Benutzung der Mods:\n{0} MOD_YELLOW_SING=§7Deaktiviere den Mod §e{0}§7, um weiter auf §eSteam§8War §7spielen zu können. MOD_YELLOW_PLUR=§7Deaktiviere die Mods\n§e{0}\n§7um weiter auf §eSteam§8War §7spielen zu können. @@ -107,14 +107,13 @@ MOD_YELLOW_PLUR=§7Deaktiviere die Mods\n§e{0}\n§7um weiter auf §eSteam§8War ALERT=§f{0} #Ban&Mute-Command -BAN_TEAM_BANNED=§c{0} wurde von {1} {2} gebannt. §f§lGrund: §f{3} +BAN_TEAM_BANNED=§8[§4☣§8]» §c{0} wurde von {1} {2} gebannt. §f§lGrund: §f{3} 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=§c{0} wurde von {1} {2} gemuted. §f§lGrund: §f{3} +MUTE_TEAM_MUTED=§8[§4☣§8]» §c{0} wurde von {1} {2} gemuted. §f§lGrund: §f{3} 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=§c{0} verändert von {1} von {2} auf {3} wegen {4} -BAN_INVALID_TIME=§cUngültige Zeitangabe. +BAN_CHANGED={0}verändert von {1} von {2} auf {3} wegen {4} BAN_PERMA=Permanent BAN_UNTIL=bis zum {0} BAN_AVOIDING_ALERT=§cMögliche Bannumgehung durch §r{0}§c: §c @@ -165,6 +164,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 +WHIS_SYNTAX=§c/whois [Spieler/ID] WHOIS_USERNAME=§7Username§8: §e{0} WHOIS_UUID=§7UUID§8: §e{0} WHOIS_UUID_HOVER=§eUUID Kopieren @@ -172,5 +172,7 @@ WHOIS_ID=§7ID§8: §e{0} WHOIS_JOINED_FIRST=§7Beigetreten am§8: §e{0} WHOIS_HOURS_PLAYED=§7Online Time§8: §e{0}h WHOIS_TEAM=§7Team§8: §e[§{0}{1}§e] {2} +WHOIS_TEAM_HOVER=§e{0} anzeigen WHOIS_PUNISHMENTS=§7Strafen: -WHOIS_PUNISHMENT=§7{0}§8» §f§l{1}: §e{2} - {3} §f{4} \ No newline at end of file +WHOIS_PUNISHMENT=§7{0}§8» §f§l{1}: §e{2} - {3} §f{4} +WHOIS_NO_PUNISHMENT=§8[§a✓§8] §7Der Spieler hat noch nichts getan. \ No newline at end of file From 4a5ccc0bbf4f5acd30a58b5a9a32f8dae3cc9b29 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 18 Jan 2021 03:17:13 +0100 Subject: [PATCH 23/30] Remove Unused Method --- src/de/steamwar/bungeecore/Message.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/de/steamwar/bungeecore/Message.java b/src/de/steamwar/bungeecore/Message.java index 705bae3..88f2b7f 100644 --- a/src/de/steamwar/bungeecore/Message.java +++ b/src/de/steamwar/bungeecore/Message.java @@ -86,10 +86,6 @@ public class Message { send(message, false, sender, type, null, null, params); } - public static void sendPrefixless(String message, CommandSender sender, ChatMessageType type, int[] useFormatter, Object... params) { - send(message, false, sender, type, null, null, useFormatter, params); - } - public static void send(String message, CommandSender sender, String onHover, ClickEvent onClick, Object... params){ send(message, true, sender, ChatMessageType.SYSTEM, onHover, onClick, params); } From 45e97702ca7596899c40d545303eb2c1da1caa43 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 18 Jan 2021 03:18:19 +0100 Subject: [PATCH 24/30] Fix Message Name --- src/de/steamwar/messages/BungeeCore.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 9b9df0d..0b8b830 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -164,7 +164,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 -WHIS_SYNTAX=§c/whois [Spieler/ID] +WHOIS_SYNTAX=§c/whois [Spieler/ID] WHOIS_USERNAME=§7Username§8: §e{0} WHOIS_UUID=§7UUID§8: §e{0} WHOIS_UUID_HOVER=§eUUID Kopieren From cac7b662087acd7860bca3bfae5b53b1350ebb0b Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 18 Jan 2021 03:18:36 +0100 Subject: [PATCH 25/30] Remove Unused Import --- src/de/steamwar/bungeecore/commands/WhoisCommand.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/commands/WhoisCommand.java index a183f00..c774ac1 100644 --- a/src/de/steamwar/bungeecore/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/commands/WhoisCommand.java @@ -29,7 +29,6 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import java.sql.Timestamp; import java.text.DecimalFormat; -import java.time.Instant; import java.util.List; public class WhoisCommand extends BasicCommand { From bef39c7cc2a4fd1038acaa88ba568014497fb308 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 22 Jan 2021 10:41:57 +0100 Subject: [PATCH 26/30] 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 e977fef..293b3f1 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 0ab8d29..ea77888 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 c774ac1..f30e8fe 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 c62a17d..80f666e 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 2e14a2a..09a5fd1 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 3f926a6..4c5b562 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 0b8b830..5f6c5a6 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 From 7f802c7a8a057757b732ff65dbe620ee76cca28f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 22 Jan 2021 11:02:40 +0100 Subject: [PATCH 27/30] Minor Changes --- src/de/steamwar/bungeecore/commands/WhoisCommand.java | 2 +- src/de/steamwar/messages/BungeeCore.properties | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/commands/WhoisCommand.java index f30e8fe..5bcb2b6 100644 --- a/src/de/steamwar/bungeecore/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/commands/WhoisCommand.java @@ -84,7 +84,7 @@ public class WhoisCommand extends BasicCommand { return; } for (Punishment punishment : punishmentList) { - Message.send("WHOIS_PUNISHMENT", player, SteamwarUser.get(punishment.getPunisher()).getUserName(), punishment.getType().name(), punishment.getBantime(punishment.getStartTime(), false), punishment.getBantime(punishment.getEndTime(), punishment.isPerma()), punishment.getReason()); + Message.sendPrefixless("WHOIS_PUNISHMENT", player, SteamwarUser.get(punishment.getPunisher()).getUserName(), punishment.getType().name(), punishment.getBantime(punishment.getStartTime(), false), punishment.getBantime(punishment.getEndTime(), punishment.isPerma()), punishment.getReason()); } } } diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 5f6c5a6..c5b0e66 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -105,10 +105,10 @@ MOD_YELLOW_PLUR=§7Deaktiviere die Mods\n§e{0}\n§7um weiter auf §eSteam§8War ALERT=§f{0} #Ban&Mute-Command -BAN_TEAM_BANNED={0}§c{1} wurde von {2} {3} gebannt. §f§lGrund: §f{4} +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={0}§c{1} wurde von {2} {3} gemuted. §f§lGrund: §f{4} +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} @@ -173,4 +173,4 @@ WHOIS_TEAM=§7Team§8: §e[§{0}{1}§e] {2} WHOIS_TEAM_HOVER=§e{0} anzeigen WHOIS_PUNISHMENTS=§7Strafen: WHOIS_PUNISHMENT=§7{0}§8» §f§l{1}: §e{2} - {3} §f{4} -WHOIS_NO_PUNISHMENT=§8[§a✓§8] §7Der Spieler hat noch nichts getan. \ No newline at end of file +WHOIS_NO_PUNISHMENT=§a✓ §7Der Spieler hat noch nichts getan. \ No newline at end of file From d2db4af4ebcf7823f3c01c76a63cf564abb47bc4 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 22 Jan 2021 16:31:21 +0100 Subject: [PATCH 28/30] Remove Empty Line --- src/de/steamwar/bungeecore/Message.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/Message.java b/src/de/steamwar/bungeecore/Message.java index 88f2b7f..9439207 100644 --- a/src/de/steamwar/bungeecore/Message.java +++ b/src/de/steamwar/bungeecore/Message.java @@ -42,7 +42,6 @@ public class Message { return parse(message, true, sender, params); } - public static String parse(String message, CommandSender sender, Object... params){ return parse(message, false, sender, params); } From df5b40020a1d635a252652645951e7330f744d8d Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 22 Jan 2021 16:42:15 +0100 Subject: [PATCH 29/30] Fixing Typo --- src/de/steamwar/bungeecore/sql/Punishment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/sql/Punishment.java b/src/de/steamwar/bungeecore/sql/Punishment.java index 09a5fd1..40a2f4e 100644 --- a/src/de/steamwar/bungeecore/sql/Punishment.java +++ b/src/de/steamwar/bungeecore/sql/Punishment.java @@ -139,7 +139,7 @@ public class Punishment { public String getBantime(Timestamp endTime, boolean perma) { if(perma) - return "Permanent"; + return "permanent"; else return endTime.toLocalDateTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm")); } From 42adba4adc6bb3a2f140c2defdd6fd67f75e176e Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 28 Jan 2021 20:14:05 +0100 Subject: [PATCH 30/30] Add Check if user is Banned in Unban Command --- src/de/steamwar/bungeecore/commands/UnbanCommand.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/commands/UnbanCommand.java b/src/de/steamwar/bungeecore/commands/UnbanCommand.java index c21561a..8b17a27 100644 --- a/src/de/steamwar/bungeecore/commands/UnbanCommand.java +++ b/src/de/steamwar/bungeecore/commands/UnbanCommand.java @@ -22,7 +22,6 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.connection.ProxiedPlayer; import java.sql.Timestamp; import java.util.Date; @@ -44,6 +43,11 @@ public class UnbanCommand extends BasicCommand { if(target == null) return; + if(!target.isBanned()) { + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "Der Spieler ist nicht gebannt."); + return; + } + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "Du hast " + target.getUserName() + " entbannt."); target.ban(Timestamp.from(new Date().toInstant()), "Unban", SteamwarUser.get(sender.getName()).getId(), false); }