From 0e8e69a422ab83084270fabfdeb5a148d6381f45 Mon Sep 17 00:00:00 2001 From: BoomEaro <21033866+BoomEaro@users.noreply.github.com> Date: Sat, 17 Aug 2024 23:08:48 +0300 Subject: [PATCH] More correctly make aban feature --- .../banmanager/bukkit/BukkitServer.java | 6 +- .../bukkit/api/events/PlayerABanEvent.java | 6 +- .../bukkit/api/events/PlayerABannedEvent.java | 6 +- .../bukkit/api/events/PlayerAUnbanEvent.java | 6 +- .../banmanager/bungee/BungeeServer.java | 6 +- .../bungee/api/events/PlayerABanEvent.java | 6 +- .../bungee/api/events/PlayerABannedEvent.java | 6 +- .../bungee/api/events/PlayerAUnbanEvent.java | 6 +- .../common/commands/ABanCommand.java | 6 +- .../common/commands/AUnbanCommand.java | 4 +- .../common/configs/LocalDatabaseConfig.java | 4 +- .../common/data/PlayerABanData.java | 85 ++++++++++++++++++ .../common/data/PlayerABanRecord.java | 86 +++++++++++++++++++ .../common/listeners/CommonBanListener.java | 40 +++++++++ .../common/listeners/CommonHooksListener.java | 37 ++++++++ .../common/listeners/CommonJoinListener.java | 58 ++++++++----- .../storage/PlayerABanRecordStorage.java | 24 +++--- .../common/storage/PlayerABanStorage.java | 46 +++++----- .../common/storage/conversion/H2.java | 8 +- 19 files changed, 354 insertions(+), 92 deletions(-) create mode 100644 common/src/main/java/me/confuser/banmanager/common/data/PlayerABanData.java create mode 100644 common/src/main/java/me/confuser/banmanager/common/data/PlayerABanRecord.java diff --git a/bukkit/src/main/java/me/confuser/banmanager/bukkit/BukkitServer.java b/bukkit/src/main/java/me/confuser/banmanager/bukkit/BukkitServer.java index 0d8ab3a1..7e6454bf 100644 --- a/bukkit/src/main/java/me/confuser/banmanager/bukkit/BukkitServer.java +++ b/bukkit/src/main/java/me/confuser/banmanager/bukkit/BukkitServer.java @@ -129,19 +129,19 @@ public CommonEvent callEvent(String name, Object... args) { event = new PlayerBanEvent((PlayerBanData) args[0], (boolean) args[1]); break; case "PlayerABanEvent": - event = new PlayerABanEvent((PlayerBanData) args[0], (boolean) args[1]); + event = new PlayerABanEvent((PlayerABanData) args[0], (boolean) args[1]); break; case "PlayerBannedEvent": event = new PlayerBannedEvent((PlayerBanData) args[0], (boolean) args[1]); break; case "PlayerABannedEvent": - event = new PlayerABannedEvent((PlayerBanData) args[0], (boolean) args[1]); + event = new PlayerABannedEvent((PlayerABanData) args[0], (boolean) args[1]); break; case "PlayerUnbanEvent": event = new PlayerUnbanEvent((PlayerBanData) args[0], (PlayerData) args[1], (String) args[2]); break; case "PlayerAUnbanEvent": - event = new PlayerAUnbanEvent((PlayerBanData) args[0], (PlayerData) args[1], (String) args[2]); + event = new PlayerAUnbanEvent((PlayerABanData) args[0], (PlayerData) args[1], (String) args[2]); break; case "IpBanEvent": event = new IpBanEvent((IpBanData) args[0], (boolean) args[1]); diff --git a/bukkit/src/main/java/me/confuser/banmanager/bukkit/api/events/PlayerABanEvent.java b/bukkit/src/main/java/me/confuser/banmanager/bukkit/api/events/PlayerABanEvent.java index e72aa78b..786754a8 100644 --- a/bukkit/src/main/java/me/confuser/banmanager/bukkit/api/events/PlayerABanEvent.java +++ b/bukkit/src/main/java/me/confuser/banmanager/bukkit/api/events/PlayerABanEvent.java @@ -1,15 +1,15 @@ package me.confuser.banmanager.bukkit.api.events; import lombok.Getter; -import me.confuser.banmanager.common.data.PlayerBanData; +import me.confuser.banmanager.common.data.PlayerABanData; public class PlayerABanEvent extends SilentCancellableEvent { @Getter - private PlayerBanData ban; + private PlayerABanData ban; - public PlayerABanEvent(PlayerBanData ban, boolean isSilent) { + public PlayerABanEvent(PlayerABanData ban, boolean isSilent) { super(isSilent, true); this.ban = ban; } diff --git a/bukkit/src/main/java/me/confuser/banmanager/bukkit/api/events/PlayerABannedEvent.java b/bukkit/src/main/java/me/confuser/banmanager/bukkit/api/events/PlayerABannedEvent.java index b9de0449..c7798539 100644 --- a/bukkit/src/main/java/me/confuser/banmanager/bukkit/api/events/PlayerABannedEvent.java +++ b/bukkit/src/main/java/me/confuser/banmanager/bukkit/api/events/PlayerABannedEvent.java @@ -1,15 +1,15 @@ package me.confuser.banmanager.bukkit.api.events; import lombok.Getter; -import me.confuser.banmanager.common.data.PlayerBanData; +import me.confuser.banmanager.common.data.PlayerABanData; public class PlayerABannedEvent extends SilentEvent { @Getter - private PlayerBanData ban; + private PlayerABanData ban; - public PlayerABannedEvent(PlayerBanData ban, boolean isSilent) { + public PlayerABannedEvent(PlayerABanData ban, boolean isSilent) { super(isSilent, true); this.ban = ban; } diff --git a/bukkit/src/main/java/me/confuser/banmanager/bukkit/api/events/PlayerAUnbanEvent.java b/bukkit/src/main/java/me/confuser/banmanager/bukkit/api/events/PlayerAUnbanEvent.java index 3690e55b..f7823e4f 100644 --- a/bukkit/src/main/java/me/confuser/banmanager/bukkit/api/events/PlayerAUnbanEvent.java +++ b/bukkit/src/main/java/me/confuser/banmanager/bukkit/api/events/PlayerAUnbanEvent.java @@ -1,20 +1,20 @@ package me.confuser.banmanager.bukkit.api.events; import lombok.Getter; -import me.confuser.banmanager.common.data.PlayerBanData; +import me.confuser.banmanager.common.data.PlayerABanData; import me.confuser.banmanager.common.data.PlayerData; public class PlayerAUnbanEvent extends CustomCancellableEvent { @Getter - private PlayerBanData ban; + private PlayerABanData ban; @Getter private PlayerData actor; @Getter private String reason; - public PlayerAUnbanEvent(PlayerBanData ban, PlayerData actor, String reason) { + public PlayerAUnbanEvent(PlayerABanData ban, PlayerData actor, String reason) { super(true); this.ban = ban; diff --git a/bungee/src/main/java/me/confuser/banmanager/bungee/BungeeServer.java b/bungee/src/main/java/me/confuser/banmanager/bungee/BungeeServer.java index 68a959d7..ace92f5b 100755 --- a/bungee/src/main/java/me/confuser/banmanager/bungee/BungeeServer.java +++ b/bungee/src/main/java/me/confuser/banmanager/bungee/BungeeServer.java @@ -114,19 +114,19 @@ public CommonEvent callEvent(String name, Object... args) { event = new PlayerBanEvent((PlayerBanData) args[0], (boolean) args[1]); break; case "PlayerABanEvent": - event = new PlayerABanEvent((PlayerBanData) args[0], (boolean) args[1]); + event = new PlayerABanEvent((PlayerABanData) args[0], (boolean) args[1]); break; case "PlayerBannedEvent": event = new PlayerBannedEvent((PlayerBanData) args[0], (boolean) args[1]); break; case "PlayerABannedEvent": - event = new PlayerABannedEvent((PlayerBanData) args[0], (boolean) args[1]); + event = new PlayerABannedEvent((PlayerABanData) args[0], (boolean) args[1]); break; case "PlayerUnbanEvent": event = new PlayerUnbanEvent((PlayerBanData) args[0], (PlayerData) args[1], (String) args[2]); break; case "PlayerAUnbanEvent": - event = new PlayerAUnbanEvent((PlayerBanData) args[0], (PlayerData) args[1], (String) args[2]); + event = new PlayerAUnbanEvent((PlayerABanData) args[0], (PlayerData) args[1], (String) args[2]); break; case "IpBanEvent": event = new IpBanEvent((IpBanData) args[0], (boolean) args[1]); diff --git a/bungee/src/main/java/me/confuser/banmanager/bungee/api/events/PlayerABanEvent.java b/bungee/src/main/java/me/confuser/banmanager/bungee/api/events/PlayerABanEvent.java index 41521a1b..cb1273b6 100644 --- a/bungee/src/main/java/me/confuser/banmanager/bungee/api/events/PlayerABanEvent.java +++ b/bungee/src/main/java/me/confuser/banmanager/bungee/api/events/PlayerABanEvent.java @@ -1,15 +1,15 @@ package me.confuser.banmanager.bungee.api.events; import lombok.Getter; -import me.confuser.banmanager.common.data.PlayerBanData; +import me.confuser.banmanager.common.data.PlayerABanData; public class PlayerABanEvent extends SilentCancellableEvent { @Getter - private PlayerBanData ban; + private PlayerABanData ban; - public PlayerABanEvent(PlayerBanData ban, boolean isSilent) { + public PlayerABanEvent(PlayerABanData ban, boolean isSilent) { super(isSilent); this.ban = ban; } diff --git a/bungee/src/main/java/me/confuser/banmanager/bungee/api/events/PlayerABannedEvent.java b/bungee/src/main/java/me/confuser/banmanager/bungee/api/events/PlayerABannedEvent.java index 23bd7d04..b3a3214b 100644 --- a/bungee/src/main/java/me/confuser/banmanager/bungee/api/events/PlayerABannedEvent.java +++ b/bungee/src/main/java/me/confuser/banmanager/bungee/api/events/PlayerABannedEvent.java @@ -1,15 +1,15 @@ package me.confuser.banmanager.bungee.api.events; import lombok.Getter; -import me.confuser.banmanager.common.data.PlayerBanData; +import me.confuser.banmanager.common.data.PlayerABanData; public class PlayerABannedEvent extends SilentEvent { @Getter - private PlayerBanData ban; + private PlayerABanData ban; - public PlayerABannedEvent(PlayerBanData ban, boolean isSilent) { + public PlayerABannedEvent(PlayerABanData ban, boolean isSilent) { super(isSilent); this.ban = ban; } diff --git a/bungee/src/main/java/me/confuser/banmanager/bungee/api/events/PlayerAUnbanEvent.java b/bungee/src/main/java/me/confuser/banmanager/bungee/api/events/PlayerAUnbanEvent.java index c6cf2412..64df3a89 100644 --- a/bungee/src/main/java/me/confuser/banmanager/bungee/api/events/PlayerAUnbanEvent.java +++ b/bungee/src/main/java/me/confuser/banmanager/bungee/api/events/PlayerAUnbanEvent.java @@ -1,20 +1,20 @@ package me.confuser.banmanager.bungee.api.events; import lombok.Getter; -import me.confuser.banmanager.common.data.PlayerBanData; +import me.confuser.banmanager.common.data.PlayerABanData; import me.confuser.banmanager.common.data.PlayerData; public class PlayerAUnbanEvent extends CustomCancellableEvent { @Getter - private PlayerBanData ban; + private PlayerABanData ban; @Getter private PlayerData actor; @Getter private String reason; - public PlayerAUnbanEvent(PlayerBanData ban, PlayerData actor, String reason) { + public PlayerAUnbanEvent(PlayerABanData ban, PlayerData actor, String reason) { super(); this.ban = ban; diff --git a/common/src/main/java/me/confuser/banmanager/common/commands/ABanCommand.java b/common/src/main/java/me/confuser/banmanager/common/commands/ABanCommand.java index eb2685be..3caa2776 100644 --- a/common/src/main/java/me/confuser/banmanager/common/commands/ABanCommand.java +++ b/common/src/main/java/me/confuser/banmanager/common/commands/ABanCommand.java @@ -2,7 +2,7 @@ import me.confuser.banmanager.common.BanManagerPlugin; import me.confuser.banmanager.common.CommonPlayer; -import me.confuser.banmanager.common.data.PlayerBanData; +import me.confuser.banmanager.common.data.PlayerABanData; import me.confuser.banmanager.common.data.PlayerData; import me.confuser.banmanager.common.util.DateUtils; import me.confuser.banmanager.common.util.Message; @@ -112,7 +112,7 @@ public boolean onCommand(CommonSender sender, CommandParser parser) { if (actor == null) return; if (isBanned) { - PlayerBanData ban; + PlayerABanData ban; if (isUUID) { ban = getPlugin().getPlayerABanStorage().getBan(UUID.fromString(playerName)); @@ -131,7 +131,7 @@ public boolean onCommand(CommonSender sender, CommandParser parser) { } } - final PlayerBanData ban = new PlayerBanData(player, actor, parser.getReason().getMessage(), isSilent); + final PlayerABanData ban = new PlayerABanData(player, actor, parser.getReason().getMessage(), isSilent); boolean created; try { diff --git a/common/src/main/java/me/confuser/banmanager/common/commands/AUnbanCommand.java b/common/src/main/java/me/confuser/banmanager/common/commands/AUnbanCommand.java index 29c45f8a..d72cbf79 100644 --- a/common/src/main/java/me/confuser/banmanager/common/commands/AUnbanCommand.java +++ b/common/src/main/java/me/confuser/banmanager/common/commands/AUnbanCommand.java @@ -2,7 +2,7 @@ import me.confuser.banmanager.common.BanManagerPlugin; -import me.confuser.banmanager.common.data.PlayerBanData; +import me.confuser.banmanager.common.data.PlayerABanData; import me.confuser.banmanager.common.data.PlayerData; import me.confuser.banmanager.common.util.Message; import me.confuser.banmanager.common.util.parsers.UnbanCommandParser; @@ -57,7 +57,7 @@ public boolean onCommand(final CommonSender sender, CommandParser originalParser final String reason = parser.getReason().getMessage(); getPlugin().getScheduler().runAsync(() -> { - PlayerBanData ban; + PlayerABanData ban; if (isUUID) { ban = getPlugin().getPlayerABanStorage().getBan(UUID.fromString(playerName)); diff --git a/common/src/main/java/me/confuser/banmanager/common/configs/LocalDatabaseConfig.java b/common/src/main/java/me/confuser/banmanager/common/configs/LocalDatabaseConfig.java index 9155460e..4311eccc 100644 --- a/common/src/main/java/me/confuser/banmanager/common/configs/LocalDatabaseConfig.java +++ b/common/src/main/java/me/confuser/banmanager/common/configs/LocalDatabaseConfig.java @@ -13,10 +13,10 @@ public class LocalDatabaseConfig extends DatabaseConfig { put("duplicatePlayers", DuplicatePlayerData.class); put("playerBans", PlayerBanData.class); - put("playerABans", PlayerBanData.class); + put("playerABans", PlayerABanData.class); put("playerBanRecords", PlayerBanRecord.class); - put("playerABanRecords", PlayerBanRecord.class); + put("playerABanRecords", PlayerABanRecord.class); put("playerMutes", PlayerMuteData.class); put("playerMuteRecords", PlayerMuteRecord.class); diff --git a/common/src/main/java/me/confuser/banmanager/common/data/PlayerABanData.java b/common/src/main/java/me/confuser/banmanager/common/data/PlayerABanData.java new file mode 100644 index 00000000..8af52725 --- /dev/null +++ b/common/src/main/java/me/confuser/banmanager/common/data/PlayerABanData.java @@ -0,0 +1,85 @@ +package me.confuser.banmanager.common.data; + +import lombok.Getter; +import me.confuser.banmanager.common.ormlite.field.DatabaseField; +import me.confuser.banmanager.common.ormlite.table.DatabaseTable; +import me.confuser.banmanager.common.storage.mysql.ByteArray; + +@DatabaseTable +public class PlayerABanData { + + @DatabaseField(generatedId = true) + @Getter + private int id; + @DatabaseField(canBeNull = false, foreign = true, foreignAutoRefresh = true, uniqueIndex = true, persisterClass = ByteArray.class, columnDefinition = "BINARY(16) NOT NULL") + @Getter + private PlayerData player; + @DatabaseField(canBeNull = false) + @Getter + private String reason; + @Getter + @DatabaseField(canBeNull = false, foreign = true, foreignAutoRefresh = true, persisterClass = ByteArray.class, columnDefinition = "BINARY(16) NOT NULL") + private PlayerData actor; + + // Should always be database time + @DatabaseField(index = true, columnDefinition = "BIGINT UNSIGNED NOT NULL") + @Getter + private long created = System.currentTimeMillis() / 1000L; + @DatabaseField(index = true, columnDefinition = "BIGINT UNSIGNED NOT NULL") + @Getter + private long updated = System.currentTimeMillis() / 1000L; + @DatabaseField(index = true, columnDefinition = "BIGINT UNSIGNED NOT NULL") + @Getter + private long expires = 0; + + @DatabaseField + @Getter + private boolean silent = false; + + PlayerABanData() { + + } + + public PlayerABanData(PlayerData player, PlayerData actor, String reason, boolean silent) { + this.player = player; + this.reason = reason; + this.actor = actor; + this.silent = silent; + } + + public PlayerABanData(PlayerData player, PlayerData actor, String reason, boolean silent, long expires) { + this(player, actor, reason, silent); + + this.expires = expires; + } + + // Only use for imports! + public PlayerABanData(PlayerData player, PlayerData actor, String reason, boolean silent, long expires, long created) { + this(player, actor, reason, silent, expires); + + this.created = created; + } + + public PlayerABanData(int id, PlayerData player, PlayerData actor, String reason, boolean silent, long expires, long created, long updated) { + this(player, actor, reason, silent, expires, created); + + this.id = id; + this.updated = updated; + } + + public PlayerABanData(PlayerBanRecord record) { + this(record.getPlayer(), record.getPastActor(), record.getReason(), record.isSilent(), record.getExpired(), record.getPastCreated()); + } + + public boolean hasExpired() { + return getExpires() != 0 && getExpires() <= (System.currentTimeMillis() / 1000L); + } + + public boolean equalsBan(PlayerABanData ban) { + return ban.getReason().equals(this.reason) + && ban.getExpires() == expires + && ban.getCreated() == this.created + && ban.getPlayer().getUUID().equals(this.getPlayer().getUUID()) + && ban.getActor().getUUID().equals(this.actor.getUUID()); + } +} diff --git a/common/src/main/java/me/confuser/banmanager/common/data/PlayerABanRecord.java b/common/src/main/java/me/confuser/banmanager/common/data/PlayerABanRecord.java new file mode 100644 index 00000000..d5f4737d --- /dev/null +++ b/common/src/main/java/me/confuser/banmanager/common/data/PlayerABanRecord.java @@ -0,0 +1,86 @@ +package me.confuser.banmanager.common.data; + +import lombok.Getter; +import me.confuser.banmanager.common.ormlite.field.DatabaseField; +import me.confuser.banmanager.common.ormlite.table.DatabaseTable; +import me.confuser.banmanager.common.storage.mysql.ByteArray; + +@DatabaseTable +public class PlayerABanRecord { + + @DatabaseField(generatedId = true) + @Getter + private int id; + + @DatabaseField(canBeNull = false, foreign = true, persisterClass = ByteArray.class, columnDefinition = "BINARY(16) NOT NULL") + @Getter + private PlayerData player; + + @DatabaseField(canBeNull = false) + @Getter + private String reason; + + @DatabaseField(canBeNull = false, columnDefinition = "BIGINT UNSIGNED NOT NULL") + @Getter + private long expired; + + @DatabaseField(canBeNull = false, foreign = true, foreignAutoRefresh = true, persisterClass = ByteArray.class, columnDefinition = "BINARY(16) NOT NULL") + @Getter + private PlayerData actor; + + @Getter + @DatabaseField(canBeNull = false, foreign = true, foreignAutoRefresh = true, persisterClass = ByteArray.class, columnDefinition = "BINARY(16) NOT NULL") + private PlayerData pastActor; + + @DatabaseField(canBeNull = false, columnDefinition = "BIGINT UNSIGNED NOT NULL") + @Getter + private long pastCreated; + + @DatabaseField(index = true, canBeNull = false, columnDefinition = "BIGINT UNSIGNED NOT NULL") + @Getter + private long created = System.currentTimeMillis() / 1000L; + + @DatabaseField(canBeNull = false) + @Getter + private String createdReason; + + @DatabaseField + @Getter + private boolean silent = false; + + PlayerABanRecord() { + + } + + public PlayerABanRecord(PlayerABanData ban, PlayerData actor, String reason) { + player = ban.getPlayer(); + expired = ban.getExpires(); + pastActor = ban.getActor(); + pastCreated = ban.getCreated(); + createdReason = reason; + silent = ban.isSilent(); + + this.reason = ban.getReason(); + this.actor = actor; + } + + public PlayerABanRecord(PlayerABanData ban, PlayerData actor, long created) { + player = ban.getPlayer(); + reason = ban.getReason(); + expired = ban.getExpires(); + pastActor = ban.getActor(); + pastCreated = ban.getCreated(); + silent = ban.isSilent(); + + this.actor = actor; + this.created = created; + } + + public boolean equalsBan(PlayerABanData ban) { + return ban.getReason().equals(this.reason) + && ban.getExpires() == expired + && ban.getCreated() == this.pastCreated + && ban.getPlayer().getUUID().equals(this.getPlayer().getUUID()) + && ban.getActor().getUUID().equals(this.pastActor.getUUID()); + } +} diff --git a/common/src/main/java/me/confuser/banmanager/common/listeners/CommonBanListener.java b/common/src/main/java/me/confuser/banmanager/common/listeners/CommonBanListener.java index f24496f3..50a85124 100755 --- a/common/src/main/java/me/confuser/banmanager/common/listeners/CommonBanListener.java +++ b/common/src/main/java/me/confuser/banmanager/common/listeners/CommonBanListener.java @@ -95,6 +95,46 @@ public void notifyOnABan(PlayerBanData data, boolean silent) { } } + public void notifyOnABan(PlayerABanData data, boolean silent) { + String broadcastPermission; + Message message; + + if (data.getExpires() == 0) { + broadcastPermission = "bm.notify.aban"; + message = Message.get("aban.notify"); + } else { + broadcastPermission = "bm.notify.atempban"; + message = Message.get("atempban.notify"); + message.set("expires", DateUtils.getDifferenceFormat(data.getExpires())); + } + + message + .set("id", data.getId()) + .set("player", data.getPlayer().getName()) + .set("playerId", data.getPlayer().getUUID().toString()) + .set("actor", data.getActor().getName()) + .set("reason", data.getReason()); + + if (!silent) { + plugin.getServer().broadcast(message.toString(), broadcastPermission); + } else if (plugin.getPlayerStorage().getConsole().getUUID().equals(data.getActor().getUUID())) { + plugin.getServer().getConsoleSender().sendMessage(message); + return; + } + + // Check if the sender is online and does not have the + // broadcastPermission + CommonPlayer player = plugin.getServer().getPlayer(data.getActor().getUUID()); + + if (player == null || !player.isOnline()) { + return; + } + + if (silent || !player.hasPermission(broadcastPermission)) { + message.sendTo(player); + } + } + public void notifyOnBan(IpBanData data, boolean silent) { String broadcastPermission; diff --git a/common/src/main/java/me/confuser/banmanager/common/listeners/CommonHooksListener.java b/common/src/main/java/me/confuser/banmanager/common/listeners/CommonHooksListener.java index bcb33b97..d1510083 100755 --- a/common/src/main/java/me/confuser/banmanager/common/listeners/CommonHooksListener.java +++ b/common/src/main/java/me/confuser/banmanager/common/listeners/CommonHooksListener.java @@ -36,6 +36,25 @@ public void onBan(PlayerBanData data, boolean pre) { } } + public void onBan(PlayerABanData data, boolean pre) { + HooksConfig config = plugin.getConfig().getHooksConfig(); + final Hook hook = data.getExpires() == 0 ? config.getHook("ban") : config.getHook("tempban"); + + if (hook == null) return; + + List commands = pre ? hook.getPre() : hook.getPost(); + + if (commands.size() != 0) { + executeCommands(commands, ImmutableMap.of( + "player", data.getPlayer().getName() + , "playerId", data.getPlayer().getUUID().toString() + , "actor", data.getActor().getName() + , "reason", data.getReason() + , "expires", Long.toString(data.getExpires()) + )); + } + } + public void onUnban(PlayerBanData data, PlayerData actor, String reason) { HooksConfig config = plugin.getConfig().getHooksConfig(); final Hook hook = config.getHook("unban"); @@ -53,6 +72,24 @@ public void onUnban(PlayerBanData data, PlayerData actor, String reason) { } } + public void onUnban(PlayerABanData data, PlayerData actor, String reason) { + HooksConfig config = plugin.getConfig().getHooksConfig(); + final Hook hook = config.getHook("unban"); + + if (hook == null) return; + + if (hook.getPost().size() != 0) { + executeCommands(hook.getPost(), ImmutableMap.of( + "player", data.getPlayer().getName() + , "playerId", data.getPlayer().getUUID().toString() + , "actor", actor.getName() + , "reason", reason + , "expires", Long.toString(data.getExpires()) + )); + } + } + + public void onMute(PlayerMuteData data, boolean pre) { HooksConfig config = plugin.getConfig().getHooksConfig(); final Hook hook = data.getExpires() == 0 ? config.getHook("mute") : config.getHook("tempmute"); diff --git a/common/src/main/java/me/confuser/banmanager/common/listeners/CommonJoinListener.java b/common/src/main/java/me/confuser/banmanager/common/listeners/CommonJoinListener.java index f5e1f436..beaa7b35 100755 --- a/common/src/main/java/me/confuser/banmanager/common/listeners/CommonJoinListener.java +++ b/common/src/main/java/me/confuser/banmanager/common/listeners/CommonJoinListener.java @@ -64,7 +64,7 @@ public void banCheck(UUID id, String name, IPAddress address, CommonJoinHandler if (!plugin.getPlayerABanStorage().isBanned(id)) { try { - PlayerBanData ban = plugin.getPlayerABanStorage().retrieveBan(id); + PlayerABanData ban = plugin.getPlayerABanStorage().retrieveBan(id); if (ban != null) plugin.getPlayerABanStorage().addBan(ban); } catch (SQLException e) { @@ -241,7 +241,7 @@ public void banCheck(UUID id, String name, IPAddress address, CommonJoinHandler } if (plugin.getPlayerABanStorage().isBanned(id)) { - PlayerBanData data = plugin.getPlayerABanStorage().getBan(id); + PlayerABanData data = plugin.getPlayerABanStorage().getBan(id); if (data != null && data.hasExpired()) { try { @@ -593,31 +593,45 @@ private void denyAlts(List duplicates, final UUID uuid) { PlayerBanData ban = plugin.getPlayerBanStorage().getBan(player.getUUID()); - if (ban == null) continue; + if (ban != null && !ban.hasExpired()) { + CommonPlayer bukkitPlayer = plugin.getServer().getPlayer(uuid); + if (bukkitPlayer == null) continue; - ban = plugin.getPlayerABanStorage().getBan(player.getUUID()); + plugin.getScheduler().runSync(() -> { + if (!bukkitPlayer.isOnline()) { + return; + } - if (ban == null) continue; + Message kickMessage = Message.get("denyalts.player.disallowed") + .set("player", player.getName()) + .set("reason", ban.getReason()) + .set("id", ban.getId()) + .set("actor", ban.getActor().getName()); - if (ban.hasExpired()) continue; + bukkitPlayer.kick(kickMessage.toString()); + }); + continue; + } - CommonPlayer bukkitPlayer = plugin.getServer().getPlayer(uuid); - if (bukkitPlayer == null) continue; + PlayerABanData aBan = plugin.getPlayerABanStorage().getBan(player.getUUID()); + if (aBan != null && !aBan.hasExpired()) { + CommonPlayer bukkitPlayer = plugin.getServer().getPlayer(uuid); + if (bukkitPlayer == null) continue; - PlayerBanData finalBan = ban; - plugin.getScheduler().runSync(() -> { - if (!bukkitPlayer.isOnline()) { - return; - } + plugin.getScheduler().runSync(() -> { + if (!bukkitPlayer.isOnline()) { + return; + } - Message kickMessage = Message.get("denyalts.player.disallowed") - .set("player", player.getName()) - .set("reason", finalBan.getReason()) - .set("id", finalBan.getId()) - .set("actor", finalBan.getActor().getName()); + Message kickMessage = Message.get("denyalts.player.disallowed") + .set("player", player.getName()) + .set("reason", aBan.getReason()) + .set("id", aBan.getId()) + .set("actor", aBan.getActor().getName()); - bukkitPlayer.kick(kickMessage.toString()); - }); + bukkitPlayer.kick(kickMessage.toString()); + }); + } } } @@ -662,12 +676,12 @@ private void punishAlts(List duplicates, UUID uuid) throws SQLExcept continue; } - PlayerBanData ban = plugin.getPlayerABanStorage().getBan(player.getUUID()); + PlayerABanData ban = plugin.getPlayerABanStorage().getBan(player.getUUID()); if (ban == null) continue; if (ban.hasExpired()) continue; - final PlayerBanData newBan = new PlayerBanData(plugin.getPlayerStorage().queryForId(UUIDUtils.toBytes(uuid)), + final PlayerABanData newBan = new PlayerABanData(plugin.getPlayerStorage().queryForId(UUIDUtils.toBytes(uuid)), plugin.getPlayerStorage().getConsole(), ban.getReason(), ban.isSilent(), diff --git a/common/src/main/java/me/confuser/banmanager/common/storage/PlayerABanRecordStorage.java b/common/src/main/java/me/confuser/banmanager/common/storage/PlayerABanRecordStorage.java index 82aab1dd..cfab0f7c 100644 --- a/common/src/main/java/me/confuser/banmanager/common/storage/PlayerABanRecordStorage.java +++ b/common/src/main/java/me/confuser/banmanager/common/storage/PlayerABanRecordStorage.java @@ -2,8 +2,8 @@ import me.confuser.banmanager.common.BanManagerPlugin; import me.confuser.banmanager.common.configs.CleanUp; -import me.confuser.banmanager.common.data.PlayerBanData; -import me.confuser.banmanager.common.data.PlayerBanRecord; +import me.confuser.banmanager.common.data.PlayerABanData; +import me.confuser.banmanager.common.data.PlayerABanRecord; import me.confuser.banmanager.common.data.PlayerData; import me.confuser.banmanager.common.ormlite.dao.BaseDaoImpl; import me.confuser.banmanager.common.ormlite.dao.CloseableIterator; @@ -17,10 +17,10 @@ import java.sql.SQLException; -public class PlayerABanRecordStorage extends BaseDaoImpl { +public class PlayerABanRecordStorage extends BaseDaoImpl { public PlayerABanRecordStorage(BanManagerPlugin plugin) throws SQLException { - super(plugin.getLocalConn(), (DatabaseTableConfig) plugin.getConfig() + super(plugin.getLocalConn(), (DatabaseTableConfig) plugin.getConfig() .getLocalDb() .getTable("playerABanRecords")); @@ -50,22 +50,22 @@ public PlayerABanRecordStorage(BanManagerPlugin plugin) throws SQLException { } public PlayerABanRecordStorage(ConnectionSource connection, DatabaseTableConfig table) throws SQLException { - super(connection, (DatabaseTableConfig) table); + super(connection, (DatabaseTableConfig) table); } - public void addRecord(PlayerBanData ban, PlayerData actor, String reason) throws SQLException { - create(new PlayerBanRecord(ban, actor, reason)); + public void addRecord(PlayerABanData ban, PlayerData actor, String reason) throws SQLException { + create(new PlayerABanRecord(ban, actor, reason)); } - public CloseableIterator findUnbans(long fromTime) throws SQLException { + public CloseableIterator findUnbans(long fromTime) throws SQLException { if (fromTime == 0) { return iterator(); } long checkTime = fromTime + DateUtils.getTimeDiff(); - QueryBuilder query = queryBuilder(); - Where where = query.where(); + QueryBuilder query = queryBuilder(); + Where where = query.where(); where.ge("created", checkTime); @@ -80,7 +80,7 @@ public long getCount(PlayerData player) throws SQLException { return queryBuilder().where().eq("player_id", player).countOf(); } - public CloseableIterator getRecords(PlayerData player) throws SQLException { + public CloseableIterator getRecords(PlayerData player) throws SQLException { return queryBuilder().where().eq("player_id", player).iterator(); } @@ -91,7 +91,7 @@ public void purge(CleanUp cleanup) throws SQLException { } public int deleteAll(PlayerData player) throws SQLException { - DeleteBuilder builder = deleteBuilder(); + DeleteBuilder builder = deleteBuilder(); builder.where().eq("player_id", player); diff --git a/common/src/main/java/me/confuser/banmanager/common/storage/PlayerABanStorage.java b/common/src/main/java/me/confuser/banmanager/common/storage/PlayerABanStorage.java index bc1105cd..9a1e4d29 100644 --- a/common/src/main/java/me/confuser/banmanager/common/storage/PlayerABanStorage.java +++ b/common/src/main/java/me/confuser/banmanager/common/storage/PlayerABanStorage.java @@ -2,7 +2,7 @@ import me.confuser.banmanager.common.BanManagerPlugin; import me.confuser.banmanager.common.api.events.CommonEvent; -import me.confuser.banmanager.common.data.PlayerBanData; +import me.confuser.banmanager.common.data.PlayerABanData; import me.confuser.banmanager.common.data.PlayerData; import me.confuser.banmanager.common.ipaddr.AddressValueException; import me.confuser.banmanager.common.ipaddr.IPAddress; @@ -28,18 +28,18 @@ import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -public class PlayerABanStorage extends BaseDaoImpl { +public class PlayerABanStorage extends BaseDaoImpl { private BanManagerPlugin plugin; - private ConcurrentHashMap bans = new ConcurrentHashMap<>(); + private ConcurrentHashMap bans = new ConcurrentHashMap<>(); public PlayerABanStorage(BanManagerPlugin plugin) throws SQLException { - super(plugin.getLocalConn(), (DatabaseTableConfig) plugin.getConfig().getLocalDb() + super(plugin.getLocalConn(), (DatabaseTableConfig) plugin.getConfig().getLocalDb() .getTable("playerABans")); this.plugin = plugin; - DatabaseTableConfig test = (DatabaseTableConfig) plugin.getConfig().getLocalDb() + DatabaseTableConfig test = (DatabaseTableConfig) plugin.getConfig().getLocalDb() .getTable("playerABans"); test.getTableName(); @@ -69,7 +69,7 @@ public PlayerABanStorage(BanManagerPlugin plugin) throws SQLException { } public PlayerABanStorage(ConnectionSource connection, DatabaseTableConfig table) throws SQLException { - super(connection, (DatabaseTableConfig) table); + super(connection, (DatabaseTableConfig) table); } private void loadAll() throws SQLException { @@ -136,7 +136,7 @@ private void loadAll() throws SQLException { continue; } - PlayerBanData ban = new PlayerBanData(results.getInt(0), player, actor, + PlayerABanData ban = new PlayerABanData(results.getInt(0), player, actor, results.getString(9), results.getBoolean(13), results.getLong(10), @@ -154,7 +154,7 @@ private void loadAll() throws SQLException { } } - public ConcurrentHashMap getBans() { + public ConcurrentHashMap getBans() { return bans; } @@ -166,25 +166,25 @@ public boolean isBanned(String playerName) { return getBan(playerName) != null; } - public PlayerBanData retrieveBan(UUID uuid) throws SQLException { - List bans = queryForEq("player_id", UUIDUtils.toBytes(uuid)); + public PlayerABanData retrieveBan(UUID uuid) throws SQLException { + List bans = queryForEq("player_id", UUIDUtils.toBytes(uuid)); if (bans.isEmpty()) return null; return bans.get(0); } - public PlayerBanData getBan(UUID uuid) { + public PlayerABanData getBan(UUID uuid) { return bans.get(uuid); } - public void addBan(PlayerBanData ban) { + public void addBan(PlayerABanData ban) { bans.put(ban.getPlayer().getUUID(), ban); plugin.getServer().callEvent("PlayerABannedEvent", ban, ban.isSilent() || !plugin.getConfig().isBroadcastOnSync()); } - public void removeBan(PlayerBanData ban) { + public void removeBan(PlayerABanData ban) { removeBan(ban.getPlayer().getUUID()); } @@ -192,8 +192,8 @@ public void removeBan(UUID uuid) { bans.remove(uuid); } - public PlayerBanData getBan(String playerName) { - for (PlayerBanData ban : bans.values()) { + public PlayerABanData getBan(String playerName) { + for (PlayerABanData ban : bans.values()) { if (ban.getPlayer().getName().equalsIgnoreCase(playerName)) { return ban; } @@ -202,7 +202,7 @@ public PlayerBanData getBan(String playerName) { return null; } - public boolean ban(PlayerBanData ban) throws SQLException { + public boolean ban(PlayerABanData ban) throws SQLException { CommonEvent event = plugin.getServer().callEvent("PlayerABanEvent", ban, ban.isSilent()); if (event.isCancelled()) { @@ -217,15 +217,15 @@ public boolean ban(PlayerBanData ban) throws SQLException { return true; } - public boolean unban(PlayerBanData ban, PlayerData actor) throws SQLException { + public boolean unban(PlayerABanData ban, PlayerData actor) throws SQLException { return unban(ban, actor, ""); } - public boolean unban(PlayerBanData ban, PlayerData actor, String reason) throws SQLException { + public boolean unban(PlayerABanData ban, PlayerData actor, String reason) throws SQLException { return unban(ban, actor, reason, false); } - public boolean unban(PlayerBanData ban, PlayerData actor, String reason, boolean delete) throws SQLException { + public boolean unban(PlayerABanData ban, PlayerData actor, String reason, boolean delete) throws SQLException { CommonEvent event = plugin.getServer().callEvent("PlayerAUnbanEvent", ban, actor, reason); if (event.isCancelled()) { @@ -235,20 +235,20 @@ public boolean unban(PlayerBanData ban, PlayerData actor, String reason, boolean delete(ban); bans.remove(ban.getPlayer().getUUID()); - if (!delete) plugin.getPlayerBanRecordStorage().addRecord(ban, actor, reason); + if (!delete) plugin.getPlayerABanRecordStorage().addRecord(ban, actor, reason); return true; } - public CloseableIterator findBans(long fromTime) throws SQLException { + public CloseableIterator findBans(long fromTime) throws SQLException { if (fromTime == 0) { return iterator(); } long checkTime = fromTime + DateUtils.getTimeDiff(); - QueryBuilder query = queryBuilder(); - Where where = query.where(); + QueryBuilder query = queryBuilder(); + Where where = query.where(); where .ge("created", checkTime) .or() diff --git a/common/src/main/java/me/confuser/banmanager/common/storage/conversion/H2.java b/common/src/main/java/me/confuser/banmanager/common/storage/conversion/H2.java index 340f3352..b0aff6cd 100644 --- a/common/src/main/java/me/confuser/banmanager/common/storage/conversion/H2.java +++ b/common/src/main/java/me/confuser/banmanager/common/storage/conversion/H2.java @@ -183,9 +183,9 @@ public void importPlayerBans() { public void importPlayerABans() { plugin.getLogger().info("Importing player abans"); - try (CloseableIterator itr = playerABanStorage.closeableIterator()) { + try (CloseableIterator itr = playerABanStorage.closeableIterator()) { while (itr.hasNext()) { - PlayerBanData data = itr.next(); + PlayerABanData data = itr.next(); try { plugin.getPlayerABanStorage().createIfNotExists(data); @@ -202,9 +202,9 @@ public void importPlayerABans() { plugin.getLogger().info("Importing player aban records"); - try (CloseableIterator itr = playerABanRecordStorage.closeableIterator()) { + try (CloseableIterator itr = playerABanRecordStorage.closeableIterator()) { while (itr.hasNext()) { - PlayerBanRecord data = itr.next(); + PlayerABanRecord data = itr.next(); try { plugin.getPlayerABanRecordStorage().createIfNotExists(data);