From fce33d3313a01809cad52872ae6ec29c0f26b168 Mon Sep 17 00:00:00 2001 From: AlexTheCoder Date: Sat, 26 Aug 2017 04:54:43 -0400 Subject: [PATCH] Log removals of Clans blacklists --- .../mineplex/core/punish/clans/ClansBan.java | 16 +++++++++++++++- .../core/punish/clans/ClansBanManager.java | 4 ++-- .../core/punish/clans/ClansBanRepository.java | 17 +++++++++++------ .../punish/clans/command/ClansBanCommand.java | 7 ++++--- .../core/punish/clans/ui/ClansBanPage.java | 19 ++++++++++++++----- 5 files changed, 46 insertions(+), 17 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/punish/clans/ClansBan.java b/Plugins/Mineplex.Core/src/mineplex/core/punish/clans/ClansBan.java index 1b1c092e4..dab9b21d1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/punish/clans/ClansBan.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/punish/clans/ClansBan.java @@ -18,9 +18,11 @@ public class ClansBan private Timestamp _unbanTime; private boolean _permanent; private boolean _removed; + private String _removeAdmin; + private String _removeReason; private UUID _uuid; - public ClansBan(int id, UUID uuid, String admin, String reason, Timestamp banTime, Timestamp unbanTime, boolean permanent, boolean removed) + public ClansBan(int id, UUID uuid, String admin, String reason, Timestamp banTime, Timestamp unbanTime, boolean permanent, boolean removed, String removeAdmin, String removeReason) { _id = id; _uuid = uuid; @@ -30,6 +32,8 @@ public class ClansBan _unbanTime = unbanTime; _permanent = permanent; _removed = removed; + _removeAdmin = removeAdmin; + _removeReason = removeReason; } public int getId() @@ -93,6 +97,16 @@ public class ClansBan { return _uuid; } + + public String getRemoveAdmin() + { + return _removeAdmin; + } + + public String getRemoveReason() + { + return _removeReason; + } public void remove() { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/punish/clans/ClansBanManager.java b/Plugins/Mineplex.Core/src/mineplex/core/punish/clans/ClansBanManager.java index 80244ad9d..3d4a18e52 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/punish/clans/ClansBanManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/punish/clans/ClansBanManager.java @@ -137,7 +137,7 @@ public class ClansBanManager extends MiniPlugin })); } - public void unban(ClansBanClient target, ClansBan ban, Runnable callback) + public void unban(ClansBanClient target, ClansBan ban, String admin, String reason, Runnable callback) { if (!target._uuid.equals(ban.getUUID())) { @@ -145,7 +145,7 @@ public class ClansBanManager extends MiniPlugin } ban.remove(); - _repository.removeBan(ban); + _repository.removeBan(ban, admin, reason); callback.run(); } 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 702968d98..eb4c84c5b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/punish/clans/ClansBanRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/punish/clans/ClansBanRepository.java @@ -18,11 +18,12 @@ import mineplex.core.account.CoreClientManager; import mineplex.serverdata.database.DBPool; import mineplex.serverdata.database.RepositoryBase; import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnVarChar; public class ClansBanRepository extends RepositoryBase { - private static final String BAN_PLAYER = "INSERT INTO clanBans (uuid, admin, reason, banTime, unbanTime, permanent, removed) VALUES (?, ?, ?, ?, ?, ?, ?);"; - private static final String REMOVE_BAN = "UPDATE clanBans SET removed = 1 WHERE id = ?;"; + private static final String BAN_PLAYER = "INSERT INTO clanBans (uuid, admin, reason, banTime, unbanTime, permanent, removed, removeAdmin, removeReason) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);"; + private static final String REMOVE_BAN = "UPDATE clanBans SET removed = 1, removeAdmin = ?, removeReason = ? WHERE id = ?;"; private static final String GET_ALL_BANS = "SELECT * FROM clanBans WHERE uuid = ?;"; public ClansBanRepository(JavaPlugin plugin) @@ -47,13 +48,15 @@ public class ClansBanRepository extends RepositoryBase stmt.setTimestamp(5, unbanTime); stmt.setBoolean(6, time == -1); stmt.setBoolean(7, false); + stmt.setString(8, null); + stmt.setString(9, null); stmt.executeUpdate(); ResultSet resultSet = stmt.getGeneratedKeys(); if (resultSet.next()) { int id = resultSet.getInt(1); - return Optional.of(new ClansBan(id, uuid, admin, reason, banTime, unbanTime, time == -1, false)); + return Optional.of(new ClansBan(id, uuid, admin, reason, banTime, unbanTime, time == -1, false, null, null)); } else { @@ -90,8 +93,10 @@ public class ClansBanRepository extends RepositoryBase Timestamp unbanTime = resultSet.getTimestamp(6); boolean permanent = resultSet.getBoolean(7); boolean removed = resultSet.getBoolean(8); + String removeAdmin = resultSet.getString(9); + String removeReason = resultSet.getString(10); - bans.add(new ClansBan(id, UUID.fromString(ruuid), admin, reason, banTime, unbanTime, permanent, removed)); + bans.add(new ClansBan(id, UUID.fromString(ruuid), admin, reason, banTime, unbanTime, permanent, removed, removeAdmin, removeReason)); } return new ClansBanClient(uuid, bans); @@ -123,8 +128,8 @@ public class ClansBanRepository extends RepositoryBase }); } - public void removeBan(ClansBan ban) + public void removeBan(ClansBan ban, String admin, String reason) { - executeUpdate(REMOVE_BAN, new ColumnInt("id", ban.getId())); + executeUpdate(REMOVE_BAN, new ColumnVarChar("removeAdmin", admin.length(), admin), new ColumnVarChar("removeReason", reason.length(), reason), new ColumnInt("id", ban.getId())); } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/punish/clans/command/ClansBanCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/punish/clans/command/ClansBanCommand.java index ca52f4cad..17eeea976 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/punish/clans/command/ClansBanCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/punish/clans/command/ClansBanCommand.java @@ -26,14 +26,15 @@ public class ClansBanCommand extends CommandBase { final String playerName = args[0]; - String reason = args[1]; + StringBuilder reasonBuilder = new StringBuilder(args[1]); for (int i = 2; i < args.length; i++) { - reason += " " + args[i]; + reasonBuilder.append(' '); + reasonBuilder.append(args[i]); } - final String finalReason = reason; + final String finalReason = reasonBuilder.toString(); Plugin.loadClient(playerName, client -> { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/punish/clans/ui/ClansBanPage.java b/Plugins/Mineplex.Core/src/mineplex/core/punish/clans/ui/ClansBanPage.java index f26c4a0b2..55bd6a898 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/punish/clans/ui/ClansBanPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/punish/clans/ui/ClansBanPage.java @@ -96,9 +96,11 @@ public class ClansBanPage extends ShopPageBase .addLore(C.cGray + "Admin: " + C.cYellow + ban.getAdmin()) .addLore(C.cGray + "Permanent: " + C.cYellow + (ban.isPermanent() ? "Yes" : "No")) .addLore(C.cGray + "Reason: " + C.cYellow + ban.getReason(), 16) - .addLore(C.cGray + "Disabled: " + C.cYellow + (ban.isRemoved() ? "Yes" : "No")) + .addLore(C.cGray + "Removed: " + C.cYellow + (ban.isRemoved() ? "Yes" : "No")) + .addLore(ban.getRemoveAdmin() != null ? C.cGray + "Removed By: " + C.cYellow + ban.getRemoveAdmin() : null) + .addLore(ban.getRemoveReason() != null ? C.cGray + "Remove Reason: " + C.cYellow + ban.getRemoveReason() : null) .addLore(ban.isActive() ? " " : null) - .addLore(ban.isActive() ? C.cDAqua + "Left-Click to disable ban" : null) + .addLore(ban.isActive() ? C.cDAqua + "Left-Click to Remove Ban" : null) .setGlow(ban.isActive()) .build(); } @@ -112,9 +114,11 @@ public class ClansBanPage extends ShopPageBase .addLore(C.cGray + "Time Left: " + C.cYellow + (ban.isActive() ? ban.getBanTimeFormatted(false) : "None")) .addLore(C.cGray + "Permanent: " + C.cYellow + (ban.isPermanent() ? "Yes" : "No")) .addLore(C.cGray + "Reason: " + C.cYellow + ban.getReason(), 16) - .addLore(C.cGray + "Disabled: " + C.cYellow + (ban.isRemoved() ? "Yes" : "No")) + .addLore(C.cGray + "Removed: " + C.cYellow + (ban.isRemoved() ? "Yes" : "No")) + .addLore(ban.getRemoveAdmin() != null ? C.cGray + "Removed By: " + C.cYellow + ban.getRemoveAdmin() : null) + .addLore(ban.getRemoveReason() != null ? C.cGray + "Remove Reason: " + C.cYellow + ban.getRemoveReason() : null) .addLore(ban.isActive() ? " " : null) - .addLore(ban.isActive() ? C.cDAqua + "Left-Click to disable ban" : null) + .addLore(ban.isActive() ? C.cDAqua + "Left-Click to Remove Ban" : null) .setGlow(ban.isActive()) .build(); } @@ -125,7 +129,7 @@ public class ClansBanPage extends ShopPageBase { getPlugin().runAsync(() -> { - getPlugin().unban(_victimClient, ban, () -> + getPlugin().unban(_victimClient, ban, getPlayer().getName(), _reason, () -> { refresh(); playAcceptSound(player); @@ -138,6 +142,11 @@ public class ClansBanPage extends ShopPageBase private void performBan() { + if (_time == 0 && !_permanent) + { + playDenySound(getPlayer()); + return; + } getPlugin().ban(_victimClient, _victimName, getPlayer().getName(), _permanent ? -1 : _time, _reason, getPlayer(), ban -> { if (ban.isPresent())