Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
Former-commit-id: c4c4e99
  • Loading branch information
xxneox committed Feb 21, 2021
1 parent a3eaaeb commit 22c79ee
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
Expand All @@ -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]));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!";
Expand Down Expand Up @@ -98,7 +98,7 @@ public class MessagesConfiguration {
@CfgCollectionStyle(CfgCollectionStyle.CollectionStyle.ALWAYS_NEW_LINE)
public List<String> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public Optional<String> 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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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<String> getBlacklist() {
return this.blacklist;
Expand Down
15 changes: 0 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,11 @@
<shadedPattern>libs</shadedPattern>
</relocation>

<relocation>
<pattern>org.apache</pattern>
<shadedPattern>libs</shadedPattern>
</relocation>

<relocation>
<pattern>org.diorite</pattern>
<shadedPattern>libs</shadedPattern>
</relocation>

<relocation>
<pattern>com.google</pattern>
<shadedPattern>libs</shadedPattern>
</relocation>

<relocation>
<pattern>com.fasterxml</pattern>
<shadedPattern>libs</shadedPattern>
Expand All @@ -93,11 +83,6 @@
<shadedPattern>libs</shadedPattern>
</relocation>

<relocation>
<pattern>org.apache</pattern>
<shadedPattern>libs</shadedPattern>
</relocation>

<relocation>
<pattern>de.leonhard.storage</pattern>
<shadedPattern>libs</shadedPattern>
Expand Down

0 comments on commit 22c79ee

Please sign in to comment.