From bb9627b74c62845ea16ddc9b7e436cd5297be3aa Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 27 Sep 2021 09:29:51 +0200 Subject: [PATCH] Add punishment implementations --- src/de/steamwar/bungeecore/BungeeCore.java | 8 ++++-- src/de/steamwar/bungeecore/Node.java | 3 +++ .../bot/config/SteamwarDiscordBotConfig.java | 2 ++ .../bungeecore/commands/BauCommand.java | 10 ++++++- .../bungeecore/commands/ChallengeCommand.java | 8 ++++++ .../bungeecore/commands/DevCommand.java | 9 +++++++ .../bungeecore/commands/FightCommand.java | 8 ++++++ .../bungeecore/commands/HistoricCommand.java | 9 +++++++ .../bungeecore/commands/MsgCommand.java | 3 +-- .../commands/PunishmentCommand.java | 3 +++ .../bungeecore/commands/RCommand.java | 3 +-- .../bungeecore/commands/RankedCommand.java | 14 ++++++++-- .../bungeecore/listeners/ChatListener.java | 6 ++--- .../listeners/ConnectionListener.java | 26 ++++++++++++++++--- .../steamwar/bungeecore/sql/Punishment.java | 1 - .../steamwar/bungeecore/sql/SteamwarUser.java | 8 ++++++ 16 files changed, 103 insertions(+), 18 deletions(-) diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index ae333dbb..23660f81 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -162,7 +162,9 @@ public class BungeeCore extends Plugin { Team.clearCache(); }, 1, 1, TimeUnit.HOURS); - new SteamwarDiscordBot(); + if (SteamwarDiscordBotConfig.loaded) { + new SteamwarDiscordBot(); + } } @Override @@ -275,7 +277,9 @@ public class BungeeCore extends Plugin { ); ArenaMode.init(config.getSection("games")); - SteamwarDiscordBotConfig.loadConfig(config.getSection("discord")); + if (config.getSection("discord") != null) { + SteamwarDiscordBotConfig.loadConfig(config.getSection("discord")); + } final Configuration servers = config.getSection("servers"); for(final String serverName : servers.getKeys()){ diff --git a/src/de/steamwar/bungeecore/Node.java b/src/de/steamwar/bungeecore/Node.java index ea0a2eda..c5bed1e9 100644 --- a/src/de/steamwar/bungeecore/Node.java +++ b/src/de/steamwar/bungeecore/Node.java @@ -194,6 +194,9 @@ public abstract class Node { } catch (IOException e) { BungeeCore.get().getLogger().log(Level.SEVERE, "Could not read cores of" + remote, e); c = 1; + } catch (NumberFormatException e) { + BungeeCore.get().getLogger().log(Level.SEVERE, "Could not read cores of" + remote, e); + c = 1; } cores = c; BungeeCore.get().getLogger().log(Level.INFO, "Adding node " + remote + " with " + cores + " cores."); diff --git a/src/de/steamwar/bungeecore/bot/config/SteamwarDiscordBotConfig.java b/src/de/steamwar/bungeecore/bot/config/SteamwarDiscordBotConfig.java index f69a3ac1..34c65e88 100644 --- a/src/de/steamwar/bungeecore/bot/config/SteamwarDiscordBotConfig.java +++ b/src/de/steamwar/bungeecore/bot/config/SteamwarDiscordBotConfig.java @@ -29,6 +29,7 @@ import java.util.Map; public class SteamwarDiscordBotConfig { + public static boolean loaded = false; public static String TOKEN; public static String GUILD; public static String ANNOUNCEMENTS_CHANNEL; @@ -110,5 +111,6 @@ public class SteamwarDiscordBotConfig { for (String type : ranksSections.getKeys()) { RANKS.put(UserGroup.getUsergroup(type), ranksSections.getString(type)); } + loaded = true; } } diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 2965f08a..ae8282c4 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -24,6 +24,7 @@ import de.steamwar.bungeecore.comms.packets.BaumemberUpdatePacket; import de.steamwar.bungeecore.inventory.SWInventory; import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.bungeecore.sql.BauweltMember; +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; @@ -38,8 +39,15 @@ public class BauCommand extends BasicCommand { @Override public void execute(CommandSender sender, String[] args) { - if(!(sender instanceof ProxiedPlayer)) + if(!(sender instanceof ProxiedPlayer)) { return; + } + + ProxiedPlayer proxiedPlayer = (ProxiedPlayer) sender; + SteamwarUser steamwarUser = SteamwarUser.get(proxiedPlayer); + if (steamwarUser.isPunishedWithMessage(proxiedPlayer, Punishment.PunishmentType.AntiBauJoin)) { + return; + } ProxiedPlayer p = (ProxiedPlayer) sender; diff --git a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java index 3d4150d3..03a8a3d3 100644 --- a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java +++ b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java @@ -22,6 +22,8 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.listeners.mods.ModLoaderBlocker; 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; import net.md_5.bungee.api.chat.ClickEvent; @@ -39,6 +41,12 @@ public class ChallengeCommand extends BasicCommand { @Override public void execute(CommandSender sender, String[] args) { + ProxiedPlayer proxiedPlayer = (ProxiedPlayer) sender; + SteamwarUser steamwarUser = SteamwarUser.get(proxiedPlayer); + if (steamwarUser.isPunishedWithMessage(proxiedPlayer, Punishment.PunishmentType.AntiFightJoin)) { + return; + } + if(args.length < 1){ Message.send("CHALLENGE_USAGE", sender); return; diff --git a/src/de/steamwar/bungeecore/commands/DevCommand.java b/src/de/steamwar/bungeecore/commands/DevCommand.java index dcc4b7fd..6fafeee7 100644 --- a/src/de/steamwar/bungeecore/commands/DevCommand.java +++ b/src/de/steamwar/bungeecore/commands/DevCommand.java @@ -20,6 +20,8 @@ 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 net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; @@ -45,6 +47,13 @@ public class DevCommand extends BasicCommand { if (!(sender instanceof ProxiedPlayer)) { return; } + + ProxiedPlayer proxiedPlayer = (ProxiedPlayer) sender; + SteamwarUser steamwarUser = SteamwarUser.get(proxiedPlayer); + if (steamwarUser.isPunishedWithMessage(proxiedPlayer, Punishment.PunishmentType.AntiBauJoin)) { + return; + } + String[] devServer = DevServerDir.list(); if (devServer == null || devServer.length == 0) { Message.send("DEV_NO_SERVER", sender); diff --git a/src/de/steamwar/bungeecore/commands/FightCommand.java b/src/de/steamwar/bungeecore/commands/FightCommand.java index 984bc06b..878e5afc 100644 --- a/src/de/steamwar/bungeecore/commands/FightCommand.java +++ b/src/de/steamwar/bungeecore/commands/FightCommand.java @@ -21,6 +21,8 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.listeners.mods.ModLoaderBlocker; +import de.steamwar.bungeecore.sql.Punishment; +import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.chat.ClickEvent; @@ -163,6 +165,12 @@ public class FightCommand extends BasicCommand { @Override public void execute(CommandSender sender, String[] args) { + ProxiedPlayer proxiedPlayer = (ProxiedPlayer) sender; + SteamwarUser steamwarUser = SteamwarUser.get(proxiedPlayer); + if (steamwarUser.isPunishedWithMessage(proxiedPlayer, Punishment.PunishmentType.AntiFightJoin)) { + return; + } + createArena(sender, "/fight ", args, 0, false, (player, mode, map) -> { Subserver arena = SubserverSystem.startArena(mode, map, 0, 0, 0, null, null, player.getUniqueId(), null, false); arena.sendPlayer(player); diff --git a/src/de/steamwar/bungeecore/commands/HistoricCommand.java b/src/de/steamwar/bungeecore/commands/HistoricCommand.java index ebf93123..f7275902 100644 --- a/src/de/steamwar/bungeecore/commands/HistoricCommand.java +++ b/src/de/steamwar/bungeecore/commands/HistoricCommand.java @@ -20,8 +20,11 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; +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.chat.ClickEvent; +import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.LinkedList; @@ -32,6 +35,12 @@ public class HistoricCommand extends BasicCommand { @Override public void execute(CommandSender sender, String[] args) { + ProxiedPlayer proxiedPlayer = (ProxiedPlayer) sender; + SteamwarUser steamwarUser = SteamwarUser.get(proxiedPlayer); + if (steamwarUser.isPunishedWithMessage(proxiedPlayer, Punishment.PunishmentType.AntiFightJoin)) { + return; + } + FightCommand.createArena(sender, "/historic ", args, 0, true, (player, mode, map) -> { Subserver arena = SubserverSystem.startArena(mode, map, 0, 0, 0, null, null, player.getUniqueId(), null, false); arena.sendPlayer(player); diff --git a/src/de/steamwar/bungeecore/commands/MsgCommand.java b/src/de/steamwar/bungeecore/commands/MsgCommand.java index 13dbb272..67f7013c 100644 --- a/src/de/steamwar/bungeecore/commands/MsgCommand.java +++ b/src/de/steamwar/bungeecore/commands/MsgCommand.java @@ -49,8 +49,7 @@ public class MsgCommand extends BasicCommand { } SteamwarUser user = SteamwarUser.get(player); - if (user.isPunished(Punishment.PunishmentType.Mute)) { - sender.sendMessage(user.punishmentMessage(Punishment.PunishmentType.Mute, player)); + if (user.isPunishedWithMessage(player, Punishment.PunishmentType.Mute)) { return; } diff --git a/src/de/steamwar/bungeecore/commands/PunishmentCommand.java b/src/de/steamwar/bungeecore/commands/PunishmentCommand.java index 6f425c1a..ce66981d 100644 --- a/src/de/steamwar/bungeecore/commands/PunishmentCommand.java +++ b/src/de/steamwar/bungeecore/commands/PunishmentCommand.java @@ -22,6 +22,7 @@ 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.BungeeCord; import net.md_5.bungee.api.CommandSender; import java.sql.Timestamp; @@ -29,10 +30,12 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.Instant; import java.util.Date; +import java.util.logging.Level; public class PunishmentCommand { public PunishmentCommand(String command, Punishment.PunishmentType punishmentType) { + BungeeCord.getInstance().getLogger().log(Level.INFO, "CMD: " + command + " " + punishmentType); new BasicCommand(command, "bungeecore.ban") { @Override public void execute(CommandSender sender, String[] args) { diff --git a/src/de/steamwar/bungeecore/commands/RCommand.java b/src/de/steamwar/bungeecore/commands/RCommand.java index 7a208db1..c9d70dd2 100644 --- a/src/de/steamwar/bungeecore/commands/RCommand.java +++ b/src/de/steamwar/bungeecore/commands/RCommand.java @@ -45,8 +45,7 @@ public class RCommand extends BasicCommand { } SteamwarUser user = SteamwarUser.get(player); - if (user.isPunished(Punishment.PunishmentType.Mute)) { - sender.sendMessage(user.punishmentMessage(Punishment.PunishmentType.Mute, player)); + if (user.isPunishedWithMessage(player, Punishment.PunishmentType.Mute)) { return; } diff --git a/src/de/steamwar/bungeecore/commands/RankedCommand.java b/src/de/steamwar/bungeecore/commands/RankedCommand.java index 1a978b55..3fb70cf8 100644 --- a/src/de/steamwar/bungeecore/commands/RankedCommand.java +++ b/src/de/steamwar/bungeecore/commands/RankedCommand.java @@ -21,6 +21,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.sql.Elo; +import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; @@ -49,11 +50,20 @@ public class RankedCommand extends BasicCommand { @Override public void execute(CommandSender sender, String[] args) { + if(!(sender instanceof ProxiedPlayer)) { + return; + } + + ProxiedPlayer proxiedPlayer = (ProxiedPlayer) sender; + SteamwarUser steamwarUser = SteamwarUser.get(proxiedPlayer); + if (steamwarUser.isPunishedWithMessage(proxiedPlayer, Punishment.PunishmentType.AntiFightJoin)) { + return; + } + if(args.length < 1){ getModes(sender, "/ranked "); return; - }else if(!(sender instanceof ProxiedPlayer)) - return; + } ArenaMode mode = FightCommand.getMode(sender, args[0]); if(mode == null) diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index a371a2ed..c50c782e 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -145,8 +145,7 @@ public class ChatListener extends BasicListener { } SteamwarUser user = SteamwarUser.get(sender); - if (user.isPunished(Punishment.PunishmentType.Mute)) { - sender.sendMessage(user.punishmentMessage(Punishment.PunishmentType.Mute, sender)); + if (user.isPunishedWithMessage(sender, Punishment.PunishmentType.Mute)) { e.setCancelled(true); return; } @@ -224,8 +223,7 @@ public class ChatListener extends BasicListener { } SteamwarUser user = SteamwarUser.get(sender); - if (user.isPunished(Punishment.PunishmentType.Mute)) { - sender.sendMessage(user.punishmentMessage(Punishment.PunishmentType.Mute, sender)); + if (user.isPunishedWithMessage(sender, Punishment.PunishmentType.Mute)) { e.setCancelled(true); return; } diff --git a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java index 9506ea2d..53a11ddb 100644 --- a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java +++ b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java @@ -27,6 +27,7 @@ import de.steamwar.bungeecore.bot.util.DiscordRanks; import de.steamwar.bungeecore.commands.ChallengeCommand; import de.steamwar.bungeecore.commands.CheckCommand; import de.steamwar.bungeecore.commands.MsgCommand; +import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.UserGroup; import net.md_5.bungee.api.AbstractReconnectHandler; @@ -34,10 +35,7 @@ import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.event.PlayerDisconnectEvent; -import net.md_5.bungee.api.event.PostLoginEvent; -import net.md_5.bungee.api.event.ServerDisconnectEvent; -import net.md_5.bungee.api.event.ServerKickEvent; +import net.md_5.bungee.api.event.*; import net.md_5.bungee.event.EventHandler; import java.util.*; @@ -144,4 +142,24 @@ public class ConnectionListener extends BasicListener { if(players.isEmpty() || (players.size() == 1 && players.contains(player))) ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), subserver::waitForTermination); } + + @EventHandler + public void onServerConnect(ServerConnectEvent e) { + ServerInfo server = e.getTarget(); + Subserver subserver = Subserver.getSubserver(server); + if (subserver == null) { + return; + } + SteamwarUser steamwarUser = SteamwarUser.get(e.getPlayer()); + + if (subserver.getType() == Servertype.BAUSERVER) { + if (steamwarUser.isPunishedWithMessage(e.getPlayer(), Punishment.PunishmentType.AntiBauJoin)) { + e.setCancelled(true); + } + } else { + if (steamwarUser.isPunishedWithMessage(e.getPlayer(), Punishment.PunishmentType.AntiFightJoin)) { + e.setCancelled(true); + } + } + } } diff --git a/src/de/steamwar/bungeecore/sql/Punishment.java b/src/de/steamwar/bungeecore/sql/Punishment.java index 0352bbb1..c6ca242f 100644 --- a/src/de/steamwar/bungeecore/sql/Punishment.java +++ b/src/de/steamwar/bungeecore/sql/Punishment.java @@ -34,7 +34,6 @@ public class Punishment { private static final Statement getPunishments = new Statement("SELECT * FROM Punishments WHERE PunishmentId IN (SELECT MAX(PunishmentId) FROM Punishments WHERE UserId = ? GROUP BY Type)"); private static final Statement getAllPunishments = new Statement("SELECT * FROM Punishments WHERE UserId = ? ORDER BY `PunishmentId` DESC"); private static final Statement insert = new Statement("INSERT INTO Punishments (UserId, Punisher, Type, Reason, EndTime, Perma) VALUES (?, ?, ?, ?, ?, ?)"); - private static final Statement update = new Statement("UPDATE Punishments SET EndTime = ?, Reason = ?, Perma = ? WHERE PunishmentId = ?"); public static Punishment getPunishmentOfPlayer(int user, PunishmentType type) { return getPunishment.select(rs -> { diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index f83d76cf..bc66108f 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -267,6 +267,14 @@ public class SteamwarUser { return true; } + public boolean isPunishedWithMessage(ProxiedPlayer player, Punishment.PunishmentType punishment) { + if (!isPunished(punishment)) { + return false; + } + player.sendMessage(punishmentMessage(punishment, player)); + 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));