From 3cfd3f5beb6200eed20b8a2d4e7c3147278b98c5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 26 Sep 2021 23:34:15 +0200 Subject: [PATCH] Update Punishment system Simplify Punishment code overhead --- src/de/steamwar/bungeecore/BungeeCore.java | 8 + .../bungeecore/bot/commands/BanCommand.java | 6 +- .../bungeecore/bot/commands/MuteCommand.java | 7 +- .../bungeecore/bot/commands/UnbanCommand.java | 5 +- .../bot/listeners/IngameChatListener.java | 3 +- .../bungeecore/commands/BanCommand.java | 85 ----------- .../bungeecore/commands/MsgCommand.java | 5 +- .../bungeecore/commands/MuteCommand.java | 57 -------- .../commands/PunishmentCommand.java | 108 ++++++++++++++ .../bungeecore/commands/RCommand.java | 5 +- .../bungeecore/commands/UnbanCommand.java | 54 ------- .../bungeecore/listeners/BanListener.java | 6 +- .../bungeecore/listeners/ChatListener.java | 10 +- .../bungeecore/listeners/mods/Utils.java | 5 +- .../steamwar/bungeecore/sql/Punishment.java | 46 +++--- .../steamwar/bungeecore/sql/SteamwarUser.java | 138 ++++++++---------- .../steamwar/messages/BungeeCore.properties | 46 ++++-- 17 files changed, 261 insertions(+), 333 deletions(-) delete mode 100644 src/de/steamwar/bungeecore/commands/BanCommand.java delete mode 100644 src/de/steamwar/bungeecore/commands/MuteCommand.java create mode 100644 src/de/steamwar/bungeecore/commands/PunishmentCommand.java delete mode 100644 src/de/steamwar/bungeecore/commands/UnbanCommand.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 0b71cb53..2a725a67 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -20,6 +20,9 @@ package de.steamwar.bungeecore; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; +import de.steamwar.bungeecore.bot.commands.BanCommand; +import de.steamwar.bungeecore.bot.commands.MuteCommand; +import de.steamwar.bungeecore.bot.commands.UnbanCommand; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import de.steamwar.bungeecore.commands.*; import de.steamwar.bungeecore.comms.SpigotReceiver; @@ -28,6 +31,7 @@ import de.steamwar.bungeecore.listeners.mods.Forge; import de.steamwar.bungeecore.listeners.mods.LabyMod; import de.steamwar.bungeecore.listeners.mods.ModLoaderBlocker; import de.steamwar.bungeecore.listeners.mods.WorldDownloader; +import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.Statement; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.Team; @@ -130,6 +134,10 @@ public class BungeeCore extends Plugin { new StatCommand(); new VerifyCommand(); + // Punishment Commands: + new PunishmentCommand("ban", Punishment.PunishmentType.Ban); + new PunishmentCommand("mute", Punishment.PunishmentType.Mute); + if(!EVENT_MODE){ new BauCommand(); new WebregisterCommand(); diff --git a/src/de/steamwar/bungeecore/bot/commands/BanCommand.java b/src/de/steamwar/bungeecore/bot/commands/BanCommand.java index e55b97e6..5e06cb67 100644 --- a/src/de/steamwar/bungeecore/bot/commands/BanCommand.java +++ b/src/de/steamwar/bungeecore/bot/commands/BanCommand.java @@ -20,6 +20,8 @@ package de.steamwar.bungeecore.bot.commands; import de.steamwar.bungeecore.Message; +import de.steamwar.bungeecore.commands.PunishmentCommand; +import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; @@ -49,7 +51,7 @@ public class BanCommand extends BasicDiscordCommand { return; } - Timestamp time = de.steamwar.bungeecore.commands.BanCommand.parseTime(null, event.getOption("time").getAsString()); + Timestamp time = PunishmentCommand.parseTime(null, event.getOption("time").getAsString()); if (time == null) { event.reply("Angegebene Zeit invalide").setEphemeral(true).queue(); return; @@ -58,7 +60,7 @@ public class BanCommand extends BasicDiscordCommand { String msg = event.getOption("reason").getAsString(); boolean isPerma = event.getOption("time").getAsString().equals("perma"); - target.ban(time, msg, sender.getId(), isPerma); + target.punish(Punishment.PunishmentType.Ban, time, msg, sender.getId(), isPerma); Message.team("BAN_TEAM_BANNED", new Message("PREFIX"), target.getUserName(), sender.getUserName(), new Message((isPerma ? "BAN_PERMA" : "BAN_UNTIL"), time), msg); event.reply("Erfolgreich " + target.getUserName() + (isPerma ? " permanent" : " bis " + time) + " gebannt").setEphemeral(true).queue(); } diff --git a/src/de/steamwar/bungeecore/bot/commands/MuteCommand.java b/src/de/steamwar/bungeecore/bot/commands/MuteCommand.java index 1c0bc96b..7847316a 100644 --- a/src/de/steamwar/bungeecore/bot/commands/MuteCommand.java +++ b/src/de/steamwar/bungeecore/bot/commands/MuteCommand.java @@ -20,7 +20,8 @@ package de.steamwar.bungeecore.bot.commands; import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.commands.BanCommand; +import de.steamwar.bungeecore.commands.PunishmentCommand; +import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; @@ -50,7 +51,7 @@ public class MuteCommand extends BasicDiscordCommand { return; } - Timestamp time = BanCommand.parseTime(null, event.getOption("time").getAsString()); + Timestamp time = PunishmentCommand.parseTime(null, event.getOption("time").getAsString()); if (time == null) { event.reply("Angegebene Zeit invalide").setEphemeral(true).complete(); return; @@ -59,7 +60,7 @@ public class MuteCommand extends BasicDiscordCommand { String msg = event.getOption("reason").getAsString(); boolean isPerma = event.getOption("time").getAsString().equals("perma"); - target.mute(time, msg, sender.getId(), isPerma); + target.punish(Punishment.PunishmentType.Mute, time, msg, sender.getId(), isPerma); Message.team("MUTE_TEAM_MUTED", new Message("PREFIX"), target.getUserName(), sender.getUserName(), new Message((isPerma ? "BAN_PERMA" : "BAN_UNTIL"), time), msg); event.reply("Erfolgreich " + target.getUserName() + (isPerma ? " permanent" : " bis " + time) + " gemutet").setEphemeral(true).queue(); } diff --git a/src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java b/src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java index 925423f6..f8d6185d 100644 --- a/src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java +++ b/src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java @@ -19,6 +19,7 @@ package de.steamwar.bungeecore.bot.commands; +import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; @@ -47,12 +48,12 @@ public class UnbanCommand extends BasicDiscordCommand { return; } - if (!target.isBanned()) { + if (!target.isPunished(Punishment.PunishmentType.Ban)) { event.reply("Angegebener User ist nicht gebannt").setEphemeral(true).queue(); return; } - target.ban(Timestamp.from(new Date().toInstant()), "Unban", sender.getId(), false); + target.punish(Punishment.PunishmentType.Ban, Timestamp.from(new Date().toInstant()), "Unban", sender.getId(), false); event.reply("Erfolgreich " + target.getUserName() + " entbannt").setEphemeral(true).queue(); } } diff --git a/src/de/steamwar/bungeecore/bot/listeners/IngameChatListener.java b/src/de/steamwar/bungeecore/bot/listeners/IngameChatListener.java index 7163985b..e7b709d9 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/IngameChatListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/IngameChatListener.java @@ -22,6 +22,7 @@ package de.steamwar.bungeecore.bot.listeners; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import de.steamwar.bungeecore.listeners.ChatListener; +import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.UserGroup; import net.dv8tion.jda.api.MessageBuilder; @@ -50,7 +51,7 @@ public class IngameChatListener extends BasicDiscordListener { event.getMessage().delete().queue(); return; } - if (steamwarUser.isMuted() || steamwarUser.isBanned()) { + if (steamwarUser.isPunished(Punishment.PunishmentType.Mute) || steamwarUser.isPunished(Punishment.PunishmentType.Ban)) { event.getMessage().delete().queue(); return; } diff --git a/src/de/steamwar/bungeecore/commands/BanCommand.java b/src/de/steamwar/bungeecore/commands/BanCommand.java deleted file mode 100644 index 1b3f38d3..00000000 --- a/src/de/steamwar/bungeecore/commands/BanCommand.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - 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.commands; - -import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.sql.SteamwarUser; -import net.md_5.bungee.api.CommandSender; - -import java.sql.Timestamp; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.time.Instant; -import java.util.Date; - -public class BanCommand extends BasicCommand { - - public BanCommand() { - super("ban", "bungeecore.ban"); - } - - @Override - public void execute(CommandSender sender, String[] args) { - if(args.length < 3){ - Message.send("USAGE_BAN", sender); - return; - } - - SteamwarUser target = unsafeUser(sender, args[0]); - if(target == null) - return; - - Timestamp banTime = parseTime(sender, args[1]); - if(banTime == null) - return; - - StringBuilder banReason = new StringBuilder(); - 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(), isPerma); - 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){ - if(arg.equalsIgnoreCase("perma")) { - return Timestamp.from(Instant.ofEpochSecond(946674800)); - }else{ - SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy_HH:mm"); - try{ - Date parsedDate = dateFormat.parse(arg); - return new java.sql.Timestamp(parsedDate.getTime()); - }catch(ParseException e){ - dateFormat = new SimpleDateFormat("dd.MM.yyyy"); - try{ - Date parsedDate = dateFormat.parse(arg.split("_")[0]); - return new java.sql.Timestamp(parsedDate.getTime()); - }catch(ParseException exception){ - if (sender != null) { - Message.send("INVALID_TIME", sender); - } - return null; - } - } - } - } -} diff --git a/src/de/steamwar/bungeecore/commands/MsgCommand.java b/src/de/steamwar/bungeecore/commands/MsgCommand.java index 8ec0d386..13dbb272 100644 --- a/src/de/steamwar/bungeecore/commands/MsgCommand.java +++ b/src/de/steamwar/bungeecore/commands/MsgCommand.java @@ -22,6 +22,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.sql.IgnoreSystem; +import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; @@ -48,8 +49,8 @@ public class MsgCommand extends BasicCommand { } SteamwarUser user = SteamwarUser.get(player); - if(user.isMuted()){ - sender.sendMessage(user.muteMessage(player)); + if (user.isPunished(Punishment.PunishmentType.Mute)) { + sender.sendMessage(user.punishmentMessage(Punishment.PunishmentType.Mute, player)); return; } diff --git a/src/de/steamwar/bungeecore/commands/MuteCommand.java b/src/de/steamwar/bungeecore/commands/MuteCommand.java deleted file mode 100644 index 9ecfde18..00000000 --- a/src/de/steamwar/bungeecore/commands/MuteCommand.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - 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.commands; - -import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.sql.SteamwarUser; -import net.md_5.bungee.api.CommandSender; - -import java.sql.Timestamp; - -public class MuteCommand extends BasicCommand { - - public MuteCommand() { - super("mute", "bungeecore.ban"); - } - - @Override - public void execute(CommandSender sender, String[] args) { - if(args.length < 3){ - Message.send("USAGE_MUTE", sender); - return; - } - - SteamwarUser target = unsafeUser(sender, args[0]); - if(target == null) - return; - - Timestamp muteTime = BanCommand.parseTime(sender, args[1]); - if(muteTime == null) - return; - - StringBuilder muteReason = new StringBuilder(); - for (int i = 2; i < args.length; i++){ - muteReason.append(args[i]).append(" "); - } - String msg = muteReason.toString(); - target.mute(muteTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma")); - 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/PunishmentCommand.java b/src/de/steamwar/bungeecore/commands/PunishmentCommand.java new file mode 100644 index 00000000..6f425c1a --- /dev/null +++ b/src/de/steamwar/bungeecore/commands/PunishmentCommand.java @@ -0,0 +1,108 @@ +/* + * 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.commands; + +import de.steamwar.bungeecore.Message; +import de.steamwar.bungeecore.sql.Punishment; +import de.steamwar.bungeecore.sql.SteamwarUser; +import net.md_5.bungee.api.CommandSender; + +import java.sql.Timestamp; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.Instant; +import java.util.Date; + +public class PunishmentCommand { + + public PunishmentCommand(String command, Punishment.PunishmentType punishmentType) { + new BasicCommand(command, "bungeecore.ban") { + @Override + public void execute(CommandSender sender, String[] args) { + if (args.length < 3) { + Message.send("PUNISHMENT_USAGE", sender, command); + return; + } + + SteamwarUser target = unsafeUser(sender, args[0]); + if (target == null) + return; + + Timestamp banTime = parseTime(sender, args[1]); + if (banTime == null) + return; + + StringBuilder reason = new StringBuilder(); + for (int i = 2; i < args.length; i++) { + reason.append(args[i]).append(" "); + } + boolean isPerma = args[1].equalsIgnoreCase("perma"); + String msg = reason.toString(); + target.punish(punishmentType, banTime, msg, SteamwarUser.get(sender.getName()).getId(), isPerma); + Message.team(punishmentType.getTeamMessage(), new Message("PREFIX"), target.getUserName(), sender.getName(), new Message((isPerma ? "PUNISHMENT_PERMA" : "PUNISHMENT_UNTIL"), banTime), msg); + } + }; + String antiCommand = "un" + command; + new BasicCommand(antiCommand, "bungeecore.ban") { + @Override + public void execute(CommandSender sender, String[] args) { + if (args.length < 1) { + Message.send("UNPUNISHMENT_USAGE", sender, antiCommand); + return; + } + + SteamwarUser target = existingUser(sender, args[0]); + if (target == null) + return; + + if (!target.isPunished(punishmentType)) { + Message.send(punishmentType.getUsageNotPunished(), sender); + return; + } + + Message.send(punishmentType.getUnpunishmentMessage(), sender, target.getUserName()); + target.punish(punishmentType, Timestamp.from(new Date().toInstant()), antiCommand, SteamwarUser.get(sender.getName()).getId(), false); + } + }; + } + + public static Timestamp parseTime(CommandSender sender, String arg) { + if (arg.equalsIgnoreCase("perma")) { + return Timestamp.from(Instant.ofEpochSecond(946674800)); + } else { + SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy_HH:mm"); + try { + Date parsedDate = dateFormat.parse(arg); + return new java.sql.Timestamp(parsedDate.getTime()); + } catch (ParseException e) { + dateFormat = new SimpleDateFormat("dd.MM.yyyy"); + try { + Date parsedDate = dateFormat.parse(arg.split("_")[0]); + return new java.sql.Timestamp(parsedDate.getTime()); + } catch (ParseException exception) { + if (sender != null) { + Message.send("INVALID_TIME", sender); + } + return null; + } + } + } + } +} diff --git a/src/de/steamwar/bungeecore/commands/RCommand.java b/src/de/steamwar/bungeecore/commands/RCommand.java index fef00317..7a208db1 100644 --- a/src/de/steamwar/bungeecore/commands/RCommand.java +++ b/src/de/steamwar/bungeecore/commands/RCommand.java @@ -22,6 +22,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.sql.IgnoreSystem; +import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -44,8 +45,8 @@ public class RCommand extends BasicCommand { } SteamwarUser user = SteamwarUser.get(player); - if(user.isMuted()){ - sender.sendMessage(user.muteMessage(player)); + if (user.isPunished(Punishment.PunishmentType.Mute)) { + sender.sendMessage(user.punishmentMessage(Punishment.PunishmentType.Mute, player)); return; } diff --git a/src/de/steamwar/bungeecore/commands/UnbanCommand.java b/src/de/steamwar/bungeecore/commands/UnbanCommand.java deleted file mode 100644 index 176029ab..00000000 --- a/src/de/steamwar/bungeecore/commands/UnbanCommand.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - 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.commands; - -import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.sql.SteamwarUser; -import net.md_5.bungee.api.CommandSender; - -import java.sql.Timestamp; -import java.util.Date; - -public class UnbanCommand extends BasicCommand { - - public UnbanCommand() { - super("unban", "bungeecore.ban"); - } - - @Override - public void execute(CommandSender sender, String[] args) { - if(args.length < 1){ - Message.send("UNBAN_USAGE", sender); - return; - } - - SteamwarUser target = existingUser(sender, args[0]); - if(target == null) - return; - - if(!target.isBanned()) { - Message.send("UNBAN_NOT_BANNED", sender); - return; - } - - Message.send("UNBAN_UNBANNED", sender, target.getUserName()); - target.ban(Timestamp.from(new Date().toInstant()), "Unban", SteamwarUser.get(sender.getName()).getId(), false); - } -} diff --git a/src/de/steamwar/bungeecore/listeners/BanListener.java b/src/de/steamwar/bungeecore/listeners/BanListener.java index 2daabdef..195cc19a 100644 --- a/src/de/steamwar/bungeecore/listeners/BanListener.java +++ b/src/de/steamwar/bungeecore/listeners/BanListener.java @@ -41,10 +41,10 @@ public class BanListener extends BasicListener { @EventHandler public void onLogin(LoginEvent event) { SteamwarUser user = SteamwarUser.getOrCreate(event.getConnection()); - if(user.isBanned()) { + if (user.isPunished(Punishment.PunishmentType.Ban)) { user.updateBanIP(event.getConnection().getAddress().getAddress().getHostAddress()); event.setCancelled(true); - event.setCancelReason(user.banMessage(ProxyServer.getInstance().getPlayer(event.getConnection().getUniqueId()))); + event.setCancelReason(user.punishmentMessage(Punishment.PunishmentType.Ban, ProxyServer.getInstance().getPlayer(event.getConnection().getUniqueId()))); return; } @@ -55,7 +55,7 @@ public class BanListener extends BasicListener { boolean perma = false; for(BannedUserIPs banned : ips) { SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID()); - if(bannedUser.isBanned()) { + if (bannedUser.isPunished(Punishment.PunishmentType.Ban)) { Punishment ban = bannedUser.getPunishment(Punishment.PunishmentType.Ban); if(ban.isPerma()) { perma = true; diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index e0e4472b..a371a2ed 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -21,9 +21,9 @@ package de.steamwar.bungeecore.listeners; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; -import de.steamwar.bungeecore.bot.listeners.IngameChatListener; import de.steamwar.bungeecore.commands.TpCommand; import de.steamwar.bungeecore.comms.packets.PingPacket; +import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.Team; import de.steamwar.bungeecore.sql.UserGroup; @@ -145,8 +145,8 @@ public class ChatListener extends BasicListener { } SteamwarUser user = SteamwarUser.get(sender); - if(user.isMuted()){ - sender.sendMessage(user.muteMessage(sender)); + if (user.isPunished(Punishment.PunishmentType.Mute)) { + sender.sendMessage(user.punishmentMessage(Punishment.PunishmentType.Mute, sender)); e.setCancelled(true); return; } @@ -224,8 +224,8 @@ public class ChatListener extends BasicListener { } SteamwarUser user = SteamwarUser.get(sender); - if(user.isMuted()){ - sender.sendMessage(user.muteMessage(sender)); + if (user.isPunished(Punishment.PunishmentType.Mute)) { + sender.sendMessage(user.punishmentMessage(Punishment.PunishmentType.Mute, sender)); e.setCancelled(true); return; } diff --git a/src/de/steamwar/bungeecore/listeners/mods/Utils.java b/src/de/steamwar/bungeecore/listeners/mods/Utils.java index e6907c5c..9ed160af 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Utils.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Utils.java @@ -23,6 +23,7 @@ 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.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -75,7 +76,7 @@ class Utils { if(max == ModType.YELLOW) 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)), Message.parse("MOD_RED_SING", player, mods.get(0).getModName()), 0, false); + user.punish(Punishment.PunishmentType.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{ @@ -85,7 +86,7 @@ class Utils { if(max == ModType.YELLOW) player.disconnect(BungeeCore.stringToText(Message.parse("MOD_YELLOW_PLUR", player, sb.toString()))); else{ - user.ban(Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), Message.parse("MOD_RED_PLUR", player, sb.toString()), 0, false); + user.punish(Punishment.PunishmentType.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/bungeecore/sql/Punishment.java b/src/de/steamwar/bungeecore/sql/Punishment.java index 914e6b85..0bd09624 100644 --- a/src/de/steamwar/bungeecore/sql/Punishment.java +++ b/src/de/steamwar/bungeecore/sql/Punishment.java @@ -19,9 +19,8 @@ package de.steamwar.bungeecore.sql; -import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.Message; -import net.md_5.bungee.api.connection.ProxiedPlayer; +import lombok.AllArgsConstructor; +import lombok.Getter; import java.sql.ResultSet; import java.sql.SQLException; @@ -39,7 +38,7 @@ public class Punishment { public static Punishment getPunishmentOfPlayer(int user, PunishmentType type) { return getPunishment.select(rs -> { - if(rs.next()) + if (rs.next()) return new Punishment(rs); return null; }, user, type.name()); @@ -116,35 +115,34 @@ public class Punishment { return perma; } - public void updateEndTime(int from, String newreason, Timestamp newUpdate, boolean perma) { - if(newreason.equals(reason) && newUpdate.equals(endTime) && this.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(), - getBantime(endTime, this.perma), - getBantime(newUpdate, perma), - newreason); - - update.update(newUpdate, newReason, perma, id); - this.reason = newReason; - this.perma = perma; - this.endTime = newUpdate; - } - public String getBantime(Timestamp endTime, boolean perma) { - if(perma) + if (perma) { return "permanent"; - else + } else { return endTime.toLocalDateTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm")); + } } public boolean isCurrent() { return isPerma() || getEndTime().after(new Date()); } + @AllArgsConstructor + @Getter public enum PunishmentType { - Ban, - Mute; + Ban("BAN_TEAM_BANNED", "BANNED_MESSAGE_PERMA", "BANNED_MESSAGE_UNTIL", "UNBAN_NOT_BANNED", "UNBAN_UNBANNED"), + Mute( "MUTE_TEAM_MUTED", "MUTED_MESSAGE_PERMA", "MUTED_MESSAGE_UNTIL", "UNMUTE_NOT_MUTED", "UNMUTE_UNMUTED"), + AntiSchemAdd("ANTISCHEMADD_TEAM_ANTISCHEMADD", "ANTISCHEMADD_MESSAGE_PERMA", "ANTISCHEMADD_MESSAGE_UNTIL", "UNANTISCHEMADD_NOT_ANTISCHEMADD", "UNANTISCHEMADD_UNANTISCHEMADDED"), + AntiSchemAdded("ANTISCHEMADDED_TEAM_ANTISCHEMADDED", "ANTISCHEMADDED_MESSAGE_PERMA", "ANTISCHEMADDED_MESSAGE_UNTIL", "UNANTISCHEMADDED_NOT_ANTISCHEMADDED", "UNANTISCHEMADDED_UNANTISCHEMADDED"), + // AntiSchemDownload("UNANTISCHEMDOWNLOAD_NOT_ANTISCHEMDOWNLOADED"), + // AntiSchemUpload("UNANTISCHEMUPLOAD_NOT_ANTISCHEMUPLOADED"), + // AntiBauJoin("UNANTIBAUJOIN_NOT_ANTIBAUJOINED"); + ; + + private String teamMessage; + private String playerMessagePerma; + private String playerMessageUntil; + private String usageNotPunished; + private String unpunishmentMessage; } } diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index 67c35960..f83d76cf 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -97,25 +97,27 @@ public class SteamwarUser { usersById.put(id, this); usersByName.put(userName.toLowerCase(), this); usersByUUID.put(uuid, this); - if(discordId != null) + if (discordId != null) { usersByDiscord.put(discordId, this); + } punishments = Punishment.getPunishmentsOfPlayer(id); } - public static SteamwarUser getOrCreate(PendingConnection connection){ + public static SteamwarUser getOrCreate(PendingConnection connection) { SteamwarUser user = SteamwarUser.get(connection.getUniqueId()); - if(user != null){ + if (user != null) { String userName = connection.getName(); - if(!user.userName.equals(userName)){ + if (!user.userName.equals(userName)) { updateName.update(userName, user.id); WebregisterCommand.changeUsername(user.userName, userName); user.userName = userName; } - }else{ + } else { user = SteamwarUser.createUserInDatabase(connection.getUniqueId(), connection.getName()); - if(user == null) + if (user == null) { throw new SecurityException("user == null"); + } ConnectionListener.newPlayer(user.uuid); } @@ -124,7 +126,7 @@ public class SteamwarUser { return user; } - public static SteamwarUser getOrCreateOfflinePlayer(String name){ + public static SteamwarUser getOrCreateOfflinePlayer(String name) { SteamwarUser user = SteamwarUser.get(name); if (user != null) { return user; @@ -143,34 +145,37 @@ public class SteamwarUser { return get(uuid); } - public static SteamwarUser get(String userName){ + public static SteamwarUser get(String userName) { userName = userName.toLowerCase(); - if(usersByName.containsKey(userName)) + if (usersByName.containsKey(userName)) { return usersByName.get(userName); + } return byName.select(rs -> { - if(rs.next()) + if (rs.next()) return new SteamwarUser(rs); return null; }, userName); } - public static SteamwarUser get(UUID uuid){ - if(usersByUUID.containsKey(uuid)) + public static SteamwarUser get(UUID uuid) { + if (usersByUUID.containsKey(uuid)) { return usersByUUID.get(uuid); + } return byUUID.select(rs -> { - if(rs.next()) + if (rs.next()) return new SteamwarUser(rs); return null; }, uuid.toString()); } - public static SteamwarUser get(ProxiedPlayer player){ + public static SteamwarUser get(ProxiedPlayer player) { return get(player.getUniqueId()); } - public static SteamwarUser get(int id){ - if(usersById.containsKey(id)) + public static SteamwarUser get(int id) { + if (usersById.containsKey(id)) { return usersById.get(id); + } return byID.select(rs -> { rs.next(); return new SteamwarUser(rs); @@ -178,16 +183,16 @@ public class SteamwarUser { } public static SteamwarUser get(Long discordId) { - if(usersByDiscord.containsKey(discordId.toString())) + if (usersByDiscord.containsKey(discordId.toString())) return usersByDiscord.get(discordId.toString()); return byDiscord.select(rs -> { - if(rs.next()) + if (rs.next()) return new SteamwarUser(rs); return null; }, discordId); } - public static void clearCache(){ + public static void clearCache() { usersById.clear(); usersByName.clear(); usersByUUID.clear(); @@ -205,7 +210,7 @@ public class SteamwarUser { } } - public void setTeam(int team){ + public void setTeam(int team) { this.team = team; updateTeam.update(team, id); setLeader(false); @@ -227,7 +232,7 @@ public class SteamwarUser { return userGroup; } - public int getTeam(){ + public int getTeam() { return team; } @@ -243,89 +248,64 @@ public class SteamwarUser { usersByDiscord.remove(this.discordId); this.discordId = discordId; updateDiscord.update(discordId, id); - if(discordId != null) { + if (discordId != null) { usersByDiscord.put(discordId, this); } } - public boolean isBanned() { - if(!punishments.containsKey(Punishment.PunishmentType.Ban)) + public boolean isPunished(Punishment.PunishmentType punishment) { + if (!punishments.containsKey(punishment)) { return false; - if(!punishments.get(Punishment.PunishmentType.Ban).isCurrent()) { - deleteIPs.update(id); - punishments.remove(Punishment.PunishmentType.Ban); + } + if (!punishments.get(punishment).isCurrent()) { + if (punishment == Punishment.PunishmentType.Ban) { + deleteIPs.update(id); + } + punishments.remove(punishment); return false; } return true; } - public boolean isMuted(){ - if(!punishments.containsKey(Punishment.PunishmentType.Mute)) - return false; - if(!punishments.get(Punishment.PunishmentType.Mute).isCurrent()) { - punishments.remove(Punishment.PunishmentType.Mute); - return false; - } - return true; - } + public void punish(Punishment.PunishmentType punishment, Timestamp time, String banReason, int from, boolean perma) { + punishments.remove(punishment); + punishments.put(punishment, Punishment.createPunishment(id, from, punishment, banReason, time, perma)); - public TextComponent banMessage(ProxiedPlayer player){ - Punishment punishment = punishments.get(Punishment.PunishmentType.Ban); - if (punishment.isPerma()) { - return BungeeCore.stringToText(Message.parsePrefixed("BANNED_MESSAGE_PERMA", player, punishment.getReason())); - } else { - return BungeeCore.stringToText(Message.parsePrefixed("BANNED_MESSAGE_UNTIL", player, punishment.getEndTime().toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", player))), - punishment.getReason())); - } - } - - public TextComponent muteMessage(ProxiedPlayer player){ - Punishment punishment = punishments.get(Punishment.PunishmentType.Mute); - if (punishment.isPerma()) { - return BungeeCore.stringToText(Message.parsePrefixed("MUTED_MESSAGE_PERMA", player, punishment.getReason())); - } else { - return BungeeCore.stringToText(Message.parsePrefixed("MUTED_MESSAGE_UNTIL", player, punishment.getEndTime().toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", player))), punishment.getReason())); - } - } - - public void updateBanIP(String ip){ - BannedUserIPs.banIP(this, ip); - } - - public void ban(Timestamp time, String banReason, int from, boolean perma){ - if(isBanned()) { - punishments.get(Punishment.PunishmentType.Ban).updateEndTime(from, banReason, time, perma); + if (punishment != Punishment.PunishmentType.Ban) { return; } - 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){ + if (player != null) { updateBanIP(player.getAddress().getAddress().getHostAddress()); - player.disconnect(banMessage(player)); - for (BannedUserIPs banned: - BannedUserIPs.get(player.getAddress().getAddress().getHostAddress())) { + player.disconnect(punishmentMessage(punishment, 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, banReason, from, perma); + if (isPunished(punishment) && banned.getTimestamp().before(time)) { + bannedUser.punish(punishment, time, banReason, from, perma); + } } - }else + } else { updateBanIP(""); + } } - public void mute(Timestamp time, String muteReason, int from, boolean perma){ - if(isMuted()) { - punishments.get(Punishment.PunishmentType.Mute).updateEndTime(from, muteReason, time, perma); - return; + public TextComponent punishmentMessage(Punishment.PunishmentType punishment, ProxiedPlayer player) { + Punishment currentPunishment = punishments.get(punishment); + if (currentPunishment.isPerma()) { + return BungeeCore.stringToText(Message.parsePrefixed(punishment.getPlayerMessagePerma(), player, currentPunishment.getReason())); + } else { + return BungeeCore.stringToText(Message.parsePrefixed(punishment.getPlayerMessageUntil(), player, currentPunishment.getEndTime().toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", player))), currentPunishment.getReason())); } - punishments.remove(Punishment.PunishmentType.Mute); - punishments.put(Punishment.PunishmentType.Mute, Punishment.createPunishment(id, from, Punishment.PunishmentType.Mute, muteReason, time, perma)); + } + + public void updateBanIP(String ip) { + BannedUserIPs.banIP(this, ip); } public double getOnlinetime() { return getPlaytime.select(rs -> { - if(rs.next()) + if (rs.next()) return rs.getBigDecimal("Playtime").doubleValue(); return 0.0; }, id); @@ -333,7 +313,7 @@ public class SteamwarUser { public Timestamp getFirstjoin() { return getFirstjoin.select(rs -> { - if(rs.next()) + if (rs.next()) return rs.getTimestamp("FirstJoin"); return null; }, id); diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 5d32af1e..76322382 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -95,8 +95,6 @@ HELP_BAU_TESTARENA_HOVER=§eTestarena starten #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] #ModListener @@ -110,21 +108,50 @@ ALERT=§f{0} STAT_SERVER=§7Server §e{0}§8: §7Load §e{1} §7Serveranzahl §e{2} #Ban&Mute-Command -BAN_TEAM_BANNED={0} §c{1} wurde von {2} {3} gebannt. §f§lGrund: §f{4} +PUNISHMENT_USAGE=§8/§7{0} §8[§eSpieler§8] [§edd§8.§emm§8.§eyyyy §7oder §edd§8.§emm§8.§eyyyy§8_§ehh§8:§emm §7oder §eperma§8] [§eGrund§8] +UNPUNISHMENT_USAGE=§8/§7{0} §8[§eSpieler§8] + +PUNISHMENT_UNTIL=bis zum {0} +PUNISHMENT_PERMA=permanent + +BAN_TEAM_BANNED={0} §c{1} wurde von {2} {3} gebannt. §f§lGrund§r: §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} +UNBAN_NOT_BANNED=§cDer Spieler ist nicht gebannt. +UNBAN_UNBANNED=Du hast {0} entbannt. + +MUTE_TEAM_MUTED={0} §c{1} wurde von {2} {3} gemuted. §f§lGrund§r: §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_UNTIL=bis zum {0} +UNMUTE_NOT_MUTED=§cDer Spieler ist nicht gemutet. +UNMUTE_UNMUTED=Du hast {0} entmutet. + +ANTISCHEMADD_TEAM_ANTISCHEMADD={0} §c{1} wurde von {2} {3} schem adden ausgeschlossen. §f§lGrund§r: §f{4} +ANTISCHEMADD_MESSAGE_PERMA=§cDu bist permanent vom schem adden ausgeschlossen. §f§lGrund§r: §f{4} +ANTISCHEMADD_MESSAGE_UNTIL=§cDu bist bis zum {0} vom schem adden ausgeschlossen. §f§lGrund§r: §f{4} +UNANTISCHEMADD_NOT_ANTISCHEMADD=§cDer Spieler ist nicht vom schem adden ausgeschlossen. +UNANTISCHEMADD_UNANTISCHEMADDED=Du hast {0} das schem adden zurückgegeben. + +ANTISCHEMADDED_TEAM_ANTISCHEMADDED={0} §c{1} wurde von {2} {3} schem add ausgeschlossen. §f§lGrund§r: §f{4} +ANTISCHEMADDED_MESSAGE_PERMA=§cDu bist permanent vom schem add ausgeschlossen. §f§lGrund§r: §f{4} +ANTISCHEMADDED_MESSAGE_UNTIL=§cDu bist bis zum {0} vom schem add ausgeschlossen. §f§lGrund§r: §f{4} +UNANTISCHEMADDED_NOT_ANTISCHEMADDED=§cDer Spieler ist nicht vom schem add ausgeschlossen. +UNANTISCHEMADDED_UNANTISCHEMADDED=Du hast {0} das schem add zurückgegeben. + +UNANTISCHEMDOWNLOAD_NOT_ANTISCHEMDOWNLOADED=§cDer Spieler ist nicht ausgeschlossen Schematics runterzuladen. + +UNANTISCHEMUPLOAD_NOT_ANTISCHEMUPLOADED=§cDer Spieler ist nicht ausgeschlossen Schematics hochzuladen. + +UNANTIBAUJOIN_NOT_ANTIBAUJOINED=§cDer Spieler ist nicht vom joinen von Baus ausgeschlossen. + 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 +#BugCommand BUG_MESSAGE=§7Dein Bugreport wurde gespeichert. +#IgnoreCommand IGNORE_YOURSELF=§cWie willst du dich selber ignorieren? IGNORE_ALREADY=§cDu ignorierst diesen Spieler bereits. IGNORE_MESSAGE=§7Du ignorierst nun §e{0}§8. @@ -423,11 +450,6 @@ TP_USAGE=§8/§7tp §8[§eSpieler§8] TP_USAGE_EVENT=§8/§7tp §8[§eSpieler §7oder §eTeam§8] TP_NOT_FOUND=§cKonnte das angegebene Ziel nicht finden. -#UnbanCommand -UNBAN_USAGE=§8/§7unban §8[§eSpieler§8] -UNBAN_NOT_BANNED=§cDer Spieler ist nicht gebannt. -UNBAN_UNBANNED=Du hast {0} entbannt. - #UnignoreCommand UNIGNORE_USAGE=§8/§7unignore §8[§eSpieler§8] UNIGNORE_NOT_PLAYER=§cDiesen Spieler gibt es nicht!