From d8d1ee78323b3f4a0886250cc48564bcff0740bc Mon Sep 17 00:00:00 2001 From: AlexTheCoder Date: Fri, 21 Jul 2017 22:31:23 -0400 Subject: [PATCH] Fix anticheat banning in clans --- .../src/mineplex/core/antihack/AntiHack.java | 38 ++++++++++--------- .../antihack/logging/AnticheatDatabase.java | 3 +- .../antihack/logging/AnticheatMetadata.java | 2 +- .../logging/builtin/PartyInfoMetadata.java | 9 ++++- .../logging/builtin/PlayerInfoMetadata.java | 2 +- .../builtin/ViolationInfoMetadata.java | 2 +- .../core/punish/clans/ClansBanRepository.java | 27 +++++++------ 7 files changed, 44 insertions(+), 39 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/antihack/AntiHack.java b/Plugins/Mineplex.Core/src/mineplex/core/antihack/AntiHack.java index 159290bf3..c991e8c75 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/antihack/AntiHack.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/antihack/AntiHack.java @@ -1,6 +1,5 @@ package mineplex.core.antihack; -import javax.xml.bind.DatatypeConverter; import java.util.Collections; import java.util.HashSet; import java.util.Map; @@ -10,11 +9,7 @@ import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; -import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; +import javax.xml.bind.DatatypeConverter; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -77,6 +72,7 @@ import mineplex.core.common.Rank; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTime; import mineplex.core.preferences.Preference; import mineplex.core.preferences.PreferencesManager; import mineplex.core.punish.Category; @@ -85,6 +81,11 @@ import mineplex.core.punish.PunishClient; import mineplex.core.punish.Punishment; import mineplex.core.punish.PunishmentResponse; import mineplex.serverdata.commands.ServerCommandManager; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; @ReflectivelyCreateMiniPlugin public class AntiHack extends MiniPlugin @@ -238,7 +239,7 @@ public class AntiHack extends MiniPlugin { _punish.getClansPunish().loadClient(coreClient.getUniqueId(), client -> { - _punish.getClansPunish().ban(client, null, AntiHack.NAME, 90 * 24 * 60 * 60 * 1000, finalMessage, null, ban -> {}); + _punish.getClansPunish().ban(client, null, AntiHack.NAME, UtilTime.convert(90L, mineplex.core.common.util.UtilTime.TimeUnit.DAYS, mineplex.core.common.util.UtilTime.TimeUnit.MILLISECONDS), finalMessage, null, ban -> {}); }); } }; @@ -254,17 +255,18 @@ public class AntiHack extends MiniPlugin else { runBanAnimation(player, () -> - doPunish.accept(result -> + { + doPunish.accept(result -> + { + if (result == PunishmentResponse.Punished) { - if (result == PunishmentResponse.Punished) - { - announceBan(player); - _banned.add(player.getUniqueId()); - _banWaveManager.flagDone(coreClient); - } - _pendingBan.remove(player); - }) - ); + announceBan(player); + _banned.add(player.getUniqueId()); + _banWaveManager.flagDone(coreClient); + } + _pendingBan.remove(player); + }); + }); } }, custom); } @@ -286,7 +288,7 @@ public class AntiHack extends MiniPlugin { _punish.getClansPunish().loadClient(coreClient.getUniqueId(), client -> { - _punish.getClansPunish().ban(client, null, AntiHack.NAME, 90 * 24 * 60 * 60 * 1000, info.getMessage(), null, ban -> {}); + _punish.getClansPunish().ban(client, null, AntiHack.NAME, UtilTime.convert(90L, mineplex.core.common.util.UtilTime.TimeUnit.DAYS, mineplex.core.common.util.UtilTime.TimeUnit.MILLISECONDS), info.getMessage(), null, ban -> {}); }); } }; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/AnticheatDatabase.java b/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/AnticheatDatabase.java index 087b68d3c..721abb330 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/AnticheatDatabase.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/AnticheatDatabase.java @@ -5,7 +5,6 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import mineplex.core.common.util.UtilTasks; -import mineplex.core.database.MinecraftRepository; import mineplex.serverdata.database.DBPool; import mineplex.serverdata.database.RepositoryBase; @@ -45,4 +44,4 @@ public class AnticheatDatabase extends RepositoryBase } } } -} +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/AnticheatMetadata.java b/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/AnticheatMetadata.java index dc015a66a..9ae46926e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/AnticheatMetadata.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/AnticheatMetadata.java @@ -20,4 +20,4 @@ public abstract class AnticheatMetadata implements Listener public abstract JsonElement build(UUID player); public abstract void remove(UUID player); -} +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/builtin/PartyInfoMetadata.java b/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/builtin/PartyInfoMetadata.java index 5b56687d8..6d0be3f48 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/builtin/PartyInfoMetadata.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/builtin/PartyInfoMetadata.java @@ -28,7 +28,12 @@ public class PartyInfoMetadata extends AnticheatMetadata @Override public JsonElement build(UUID player) { - Party party = require(PartyManager.class).getPartyByPlayer(player); + PartyManager pm = require(PartyManager.class); + if (pm == null) + { + return JsonNull.INSTANCE; + } + Party party = pm.getPartyByPlayer(player); if (party != null) { JsonObject partyData = new JsonObject(); @@ -52,4 +57,4 @@ public class PartyInfoMetadata extends AnticheatMetadata { } -} +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/builtin/PlayerInfoMetadata.java b/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/builtin/PlayerInfoMetadata.java index 479db70d2..509561a76 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/builtin/PlayerInfoMetadata.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/builtin/PlayerInfoMetadata.java @@ -48,4 +48,4 @@ public class PlayerInfoMetadata extends AnticheatMetadata { } -} +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/builtin/ViolationInfoMetadata.java b/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/builtin/ViolationInfoMetadata.java index 556cea86b..69685a46c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/builtin/ViolationInfoMetadata.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/builtin/ViolationInfoMetadata.java @@ -156,4 +156,4 @@ public class ViolationInfoMetadata extends AnticheatMetadata violations.add(data); } -} +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/punish/clans/ClansBanRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/punish/clans/ClansBanRepository.java index 3444e3eb0..702968d98 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/punish/clans/ClansBanRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/punish/clans/ClansBanRepository.java @@ -108,20 +108,19 @@ public class ClansBanRepository extends RepositoryBase { // Yes, this is garbage. // Yes, it would be better implemented in a functional language. - return CompletableFuture.supplyAsync(() -> Managers.get(CoreClientManager.class).loadUUIDFromDB(name)) - .thenCompose(uuid -> - { - if (uuid == null) - { - CompletableFuture> future = new CompletableFuture<>(); - future.complete(Optional.empty()); - return future; - } - else - { - return loadClient(uuid).thenApply(Optional::of); - } - }); + return CompletableFuture.supplyAsync(() -> Managers.get(CoreClientManager.class).loadUUIDFromDB(name)).thenCompose(uuid -> + { + if (uuid == null) + { + CompletableFuture> future = new CompletableFuture<>(); + future.complete(Optional.empty()); + return future; + } + else + { + return loadClient(uuid).thenApply(Optional::of); + } + }); } public void removeBan(ClansBan ban)