From 487b828c6238a2258f908b20837571a28db05fbd Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 10 Sep 2023 11:26:21 +0700 Subject: [PATCH] many owner names.... --- .../chayapak/chomens_bot/Configuration.java | 2 +- .../chomens_bot/plugins/AuthPlugin.java | 38 +++++++++++++------ .../chomens_bot/plugins/ConsolePlugin.java | 2 +- .../chomens_bot/plugins/TrustedPlugin.java | 7 +++- src/main/resources/default-config.yml | 5 ++- 5 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java index cbcf778..f402b2c 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java @@ -25,7 +25,7 @@ public class Configuration { public ColorPalette colorPalette = new ColorPalette(); - public String ownerName = "chayapak"; // mabe mabe + public List ownerNames = new ArrayList<>(); public OwnerAuthentication ownerAuthentication = new OwnerAuthentication(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/AuthPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/AuthPlugin.java index 05c4eb1..2f58c13 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/AuthPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/AuthPlugin.java @@ -41,13 +41,20 @@ public class AuthPlugin extends PlayersPlugin.Listener { bot.executor.scheduleAtFixedRate(this::check, 0, 1, TimeUnit.SECONDS); } - private String getSanitizedOwnerName() { - return bot.config.ownerName.replaceAll("§[a-f0-9rlonmk]", ""); + private List getSanitizedOwnerName() { + return bot.config.ownerNames.stream().map(each -> each.replaceAll("§[a-f0-9rlonmk]", "")).toList(); } @Override public void playerJoined(PlayerEntry target) { - if (!target.profile.getName().equals(getSanitizedOwnerName()) || !bot.options.useCore) return; + boolean has = false; + for (String name : getSanitizedOwnerName()) { + if (!target.profile.getName().equals(name) || !bot.options.useCore) continue; + + has = true; + } + + if (!has) return; bot.executor.schedule(() -> sendVerificationMessage(target, true), 2, TimeUnit.SECONDS); } @@ -77,7 +84,14 @@ public class AuthPlugin extends PlayersPlugin.Listener { @Override public void playerLeft(PlayerEntry target) { - if (!target.profile.getName().equals(getSanitizedOwnerName())) return; + boolean has = false; + for (String name : getSanitizedOwnerName()) { + if (!target.profile.getName().equals(name) || !bot.options.useCore) continue; + + has = true; + } + + if (!has) return; hasCorrectHash = false; started = false; @@ -110,17 +124,19 @@ public class AuthPlugin extends PlayersPlugin.Listener { private void check() { if (!started) return; - final PlayerEntry entry = bot.players.getEntry(getSanitizedOwnerName()); + for (String name : getSanitizedOwnerName()) { + final PlayerEntry entry = bot.players.getEntry(name); - if (entry == null) return; + if (entry == null) return; - final long timeSinceJoined = System.currentTimeMillis() - timeJoined; + final long timeSinceJoined = System.currentTimeMillis() - timeJoined; - if (!hasCorrectHash) sendVerificationMessage(entry, false); + if (!hasCorrectHash) sendVerificationMessage(entry, false); - if (timeSinceJoined > bot.config.ownerAuthentication.timeout && !hasCorrectHash) { - bot.filter.mute(entry, "Not verified"); - bot.filter.deOp(entry); + if (timeSinceJoined > bot.config.ownerAuthentication.timeout && !hasCorrectHash) { + bot.filter.mute(entry, "Not verified"); + bot.filter.deOp(entry); + } } } } diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ConsolePlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ConsolePlugin.java index bbe7a53..77ed380 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ConsolePlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ConsolePlugin.java @@ -105,7 +105,7 @@ public class ConsolePlugin implements Completer { Component.translatable( "[%s] %s › %s", Component.text(bot.username + " Console").color(NamedTextColor.GRAY), - Component.text(bot.config.ownerName).color(ColorUtilities.getColorByString(bot.config.colorPalette.ownerName)), + Component.text(bot.config.ownerNames.get(0)).color(ColorUtilities.getColorByString(bot.config.colorPalette.ownerName)), Component.text(line).color(NamedTextColor.GRAY) ).color(NamedTextColor.DARK_GRAY) ); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/TrustedPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/TrustedPlugin.java index 9ac7126..aed36c1 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/TrustedPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/TrustedPlugin.java @@ -56,9 +56,14 @@ public class TrustedPlugin extends PlayersPlugin.Listener { public void playerJoined (PlayerEntry target) { if (!list.contains(target.profile.getName())) return; + boolean doesntHaveOwner = true; + for (String name : bot.config.ownerNames) { + if (target.profile.getName().equals(name)) doesntHaveOwner = false; + } + // based (VERY) Component component; - if (!target.profile.getName().equals(bot.config.ownerName)) { + if (doesntHaveOwner) { component = Component.translatable( "Hello, %s!", Component.text(target.profile.getName()).color(ColorUtilities.getColorByString(bot.config.colorPalette.username)) diff --git a/src/main/resources/default-config.yml b/src/main/resources/default-config.yml index f09f849..0f758fe 100644 --- a/src/main/resources/default-config.yml +++ b/src/main/resources/default-config.yml @@ -49,7 +49,10 @@ colorPalette: number: 'gold' ownerName: 'green' -ownerName: 'chayapak' # currently this is only used in the console +# currently this is only used in the console +ownerNames: + # don't leave this array blank or it can cause errors + - 'chayapak' ownerAuthentication: enabled: false