From fec517f5a1c606a7c3ef1d1b494f7ffa144c761e Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 30 Dec 2020 13:28:09 +0100 Subject: [PATCH] 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.