From 22c79ee2b5d724810dc02065d8afd78fdf655ee5 Mon Sep 17 00:00:00 2001 From: xxneox Date: Sun, 21 Feb 2021 13:00:43 +0100 Subject: [PATCH] Some fixes Former-commit-id: c4c4e99aabc19a0dd5257e424638bc7481ccad7e --- .../core/check/impl/BlacklistCheck.java | 3 ++- .../core/check/impl/NicknameCheck.java | 4 +++- .../core/command/CommandExecutor.java | 4 ++-- .../core/config/MessagesConfiguration.java | 4 ++-- .../core/handler/DetectionHandler.java | 3 ++- .../core/manager/StorageManager.java | 24 ++++++++++++++----- pom.xml | 15 ------------ 7 files changed, 29 insertions(+), 28 deletions(-) diff --git a/core/src/main/java/me/xneox/epicguard/core/check/impl/BlacklistCheck.java b/core/src/main/java/me/xneox/epicguard/core/check/impl/BlacklistCheck.java index 612bb0ef..083e5457 100644 --- a/core/src/main/java/me/xneox/epicguard/core/check/impl/BlacklistCheck.java +++ b/core/src/main/java/me/xneox/epicguard/core/check/impl/BlacklistCheck.java @@ -29,7 +29,8 @@ public BlacklistCheck(EpicGuard epicGuard) { @Override public boolean handle(@Nonnull BotUser user) { - return this.epicGuard.getStorageManager().isBlacklisted(user.getAddress()); + return this.epicGuard.getStorageManager().isBlacklisted(user.getAddress()) + || this.epicGuard.getStorageManager().isBlacklisted(user.getNickname()); } @Override diff --git a/core/src/main/java/me/xneox/epicguard/core/check/impl/NicknameCheck.java b/core/src/main/java/me/xneox/epicguard/core/check/impl/NicknameCheck.java index 29df06ed..73f00b41 100644 --- a/core/src/main/java/me/xneox/epicguard/core/check/impl/NicknameCheck.java +++ b/core/src/main/java/me/xneox/epicguard/core/check/impl/NicknameCheck.java @@ -2,6 +2,7 @@ import me.xneox.epicguard.core.EpicGuard; import me.xneox.epicguard.core.check.Check; +import me.xneox.epicguard.core.check.CheckMode; import me.xneox.epicguard.core.user.BotUser; import org.jetbrains.annotations.NotNull; @@ -14,7 +15,8 @@ public NicknameCheck(EpicGuard epicGuard) { @Override public boolean handle(@NotNull BotUser user) { - return user.getNickname().matches(this.epicGuard.getConfig().nicknameCheck); + CheckMode mode = CheckMode.valueOf(this.epicGuard.getConfig().nicknameCheck); + return this.assertCheck(mode, user.getNickname().matches(this.epicGuard.getConfig().nicknameCheckExpression)); } @NotNull diff --git a/core/src/main/java/me/xneox/epicguard/core/command/CommandExecutor.java b/core/src/main/java/me/xneox/epicguard/core/command/CommandExecutor.java index 2602174d..da3226ad 100644 --- a/core/src/main/java/me/xneox/epicguard/core/command/CommandExecutor.java +++ b/core/src/main/java/me/xneox/epicguard/core/command/CommandExecutor.java @@ -81,7 +81,7 @@ public void onCommand(@Nonnull String[] args, @Nonnull Sender sender) { } else if (args[1].equalsIgnoreCase("remove")) { if (this.epicGuard.getStorageManager().isWhitelisted(args[2])) { send(sender, prefix + config.unWhitelisted.replace("{USER}", args[2])); - this.epicGuard.getStorageManager().getWhitelist().remove(args[2]); + this.epicGuard.getStorageManager().removeFromWhitelist(args[2]); } else { send(sender, prefix + config.notWhitelisted.replace("{USER}", args[2])); } @@ -103,7 +103,7 @@ public void onCommand(@Nonnull String[] args, @Nonnull Sender sender) { } else if (args[1].equalsIgnoreCase("remove")) { if (this.epicGuard.getStorageManager().isBlacklisted(args[2])) { send(sender, prefix + config.unBlacklisted.replace("{USER}", args[2])); - this.epicGuard.getStorageManager().getBlacklist().remove(args[2]); + this.epicGuard.getStorageManager().removeFromBlacklist(args[2]); } else { send(sender, prefix + config.notBlacklisted.replace("{USER}", args[2])); } diff --git a/core/src/main/java/me/xneox/epicguard/core/config/MessagesConfiguration.java b/core/src/main/java/me/xneox/epicguard/core/config/MessagesConfiguration.java index 8e4a4cb0..4a213376 100644 --- a/core/src/main/java/me/xneox/epicguard/core/config/MessagesConfiguration.java +++ b/core/src/main/java/me/xneox/epicguard/core/config/MessagesConfiguration.java @@ -47,7 +47,7 @@ public class MessagesConfiguration { public String blacklisted = "&7The user &c{USER} &7has been added to the blacklist."; @CfgName("command-blacklist-remove") - public String unBlacklisted = "&7The user &6{USER} &7has been removed from the whitelist."; + public String unBlacklisted = "&7The user &6{USER} &7has been removed from the blacklist."; @CfgName("command-whitelist-already") public String alreadyWhitelisted = "&cThe user &6{USER} &cis already whitelisted!"; @@ -98,7 +98,7 @@ public class MessagesConfiguration { @CfgCollectionStyle(CfgCollectionStyle.CollectionStyle.ALWAYS_NEW_LINE) public List kickMessageBlacklist = Arrays.asList( "&8» &7You have been kicked by &bAntiBot Protection&7:", - "&8» &cYour IP address is blacklisted on this server."); + "&8» &cYou have been blacklisted on this server."); @CfgName("kick-message-attack") @CfgCollectionStyle(CfgCollectionStyle.CollectionStyle.ALWAYS_NEW_LINE) diff --git a/core/src/main/java/me/xneox/epicguard/core/handler/DetectionHandler.java b/core/src/main/java/me/xneox/epicguard/core/handler/DetectionHandler.java index ae0da72d..28aa9989 100644 --- a/core/src/main/java/me/xneox/epicguard/core/handler/DetectionHandler.java +++ b/core/src/main/java/me/xneox/epicguard/core/handler/DetectionHandler.java @@ -59,7 +59,8 @@ public Optional handle(@Nonnull String address, @Nonnull String nickname this.epicGuard.getAttackManager().setAttack(true); } - if (this.epicGuard.getStorageManager().isWhitelisted(address) || this.epicGuard.getStorageManager().isWhitelisted(nickname)) { + if (this.epicGuard.getStorageManager().isWhitelisted(address) + || this.epicGuard.getStorageManager().isWhitelisted(nickname)) { return Optional.empty(); } diff --git a/core/src/main/java/me/xneox/epicguard/core/manager/StorageManager.java b/core/src/main/java/me/xneox/epicguard/core/manager/StorageManager.java index c8356e45..e9e9338a 100644 --- a/core/src/main/java/me/xneox/epicguard/core/manager/StorageManager.java +++ b/core/src/main/java/me/xneox/epicguard/core/manager/StorageManager.java @@ -101,9 +101,7 @@ public String findByNickname(String nickname) { .orElse(null); } - public void blacklist(@Nonnull String argument) { - Validate.notNull(argument, "Argument cannot be null!"); - + public void blacklist(String argument) { if (InetAddresses.isInetAddress(argument)) { if (!this.blacklist.contains(argument)) { this.blacklist.add(argument); @@ -115,9 +113,7 @@ public void blacklist(@Nonnull String argument) { } } - public void whitelist(@Nonnull String argument) { - Validate.notNull(argument, "Argument cannot be null!"); - + public void whitelist(String argument) { if (InetAddresses.isInetAddress(argument)) { if (!this.whitelist.contains(argument)) { this.whitelist.add(argument); @@ -143,6 +139,22 @@ public boolean isWhitelisted(String argument) { return this.nameWhitelist.contains(argument); } + public void removeFromBlacklist(String argument) { + if (InetAddresses.isInetAddress(argument)) { + this.blacklist.remove(argument); + } else { + this.nameBlacklist.remove(argument); + } + } + + public void removeFromWhitelist(String argument) { + if (InetAddresses.isInetAddress(argument)) { + this.whitelist.remove(argument); + } else { + this.nameWhitelist.remove(argument); + } + } + @Nonnull public Collection getBlacklist() { return this.blacklist; diff --git a/pom.xml b/pom.xml index f81a679c..c85400ee 100644 --- a/pom.xml +++ b/pom.xml @@ -68,21 +68,11 @@ libs - - org.apache - libs - - org.diorite libs - - com.google - libs - - com.fasterxml libs @@ -93,11 +83,6 @@ libs - - org.apache - libs - - de.leonhard.storage libs