diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java index fefe722..95807e1 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java @@ -23,6 +23,7 @@ public class Bot { @Getter private final int port; private final String _username; @Getter private final boolean kaboom; + @Getter private final String serverName; @Getter private final List allBots; @Getter private final Configuration config; @@ -44,13 +45,15 @@ public class Bot { @Getter private final MusicPlayerPlugin music; @Getter private final TPSPlugin tps; @Getter private final EvalRunnerPlugin eval; - @Getter private final AntiClearChatPlugin antiClearChat; + @Getter private final ClearChatUsernamePlugin clearChatUsername; + @Getter private final TrustedPlugin trusted; - public Bot (String host, int port, String _username, boolean kaboom, List allBots, Configuration config) { + public Bot (String host, int port, String _username, boolean kaboom, String serverName, List allBots, Configuration config) { this.host = host; this.port = port; this._username = _username; this.kaboom = kaboom; + this.serverName = serverName; this.allBots = allBots; this.config = config; @@ -70,7 +73,8 @@ public class Bot { this.music = new MusicPlayerPlugin(this); this.tps = new TPSPlugin(this); this.eval = new EvalRunnerPlugin(this); - this.antiClearChat = new AntiClearChatPlugin(this); + this.clearChatUsername = new ClearChatUsernamePlugin(this); + this.trusted = new TrustedPlugin(this); reconnect(); } 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 388892d..bddb90c 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java @@ -2,6 +2,7 @@ package land.chipmunk.chayapak.chomens_bot; import lombok.Getter; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -18,6 +19,7 @@ public class Configuration { @Getter public Core core = new Core(); @Getter public Discord discord = new Discord(); + @Getter public List trusted = new ArrayList<>(); @Getter public SelfCare selfCare = new SelfCare(); @Getter public Bots[] bots = new Bots[]{}; @@ -60,5 +62,6 @@ public class Configuration { @Getter public int port; @Getter public String username; @Getter public boolean kaboom = false; + @Getter public String serverName; } } diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/Main.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/Main.java index 1837b27..c86dbe7 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Main.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Main.java @@ -58,9 +58,10 @@ public class Main { final int port = botOption.port(); final String username = botOption.username(); final boolean kaboom = botOption.kaboom(); + final String serverName = botOption.serverName(); new Thread(() -> { - final Bot bot = new Bot(host, port, username, kaboom, allBots, config); + final Bot bot = new Bot(host, port, username, kaboom, serverName, allBots, config); allBots.add(bot); latch.countDown(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/AntiClearChatPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ClearChatUsernamePlugin.java similarity index 91% rename from src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/AntiClearChatPlugin.java rename to src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ClearChatUsernamePlugin.java index fecab45..096ebd0 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/AntiClearChatPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ClearChatUsernamePlugin.java @@ -7,10 +7,10 @@ import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.format.NamedTextColor; // idea totallynotskidded™ from chipmunkbot (the js one) -public class AntiClearChatPlugin extends ChatPlugin.ChatListener { +public class ClearChatUsernamePlugin extends ChatPlugin.ChatListener { private final Bot bot; - public AntiClearChatPlugin (Bot bot) { + public ClearChatUsernamePlugin(Bot bot) { this.bot = bot; bot.chat().addListener(this); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CorePlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CorePlugin.java index 09d476f..4c473dc 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CorePlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CorePlugin.java @@ -53,6 +53,8 @@ public class CorePlugin extends PositionPlugin.PositionListener { } public void run (String command) { + if (!ready) return; + bot.session().send(new ServerboundSetCommandBlockPacket( absoluteCorePosition(), "", 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 new file mode 100644 index 0000000..bf0b3d4 --- /dev/null +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/TrustedPlugin.java @@ -0,0 +1,62 @@ +package land.chipmunk.chayapak.chomens_bot.plugins; + +import land.chipmunk.chayapak.chomens_bot.Bot; +import land.chipmunk.chayapak.chomens_bot.chatParsers.data.MutablePlayerListEntry; +import lombok.Getter; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +import java.util.List; + +public class TrustedPlugin extends PlayersPlugin.PlayerListener { + private final Bot bot; + + @Getter private final List trusted; + + public TrustedPlugin (Bot bot) { + this.bot = bot; + + this.trusted = bot.config().trusted(); + + bot.players().addListener(this); + } + + public void broadcast (Component message) { + for (Bot allBot : bot.allBots()) { + for (String player : trusted) { + final Component component = Component.translatable( + "[%s] [%s] %s", + Component.text("ChomeNS Bot").color(NamedTextColor.YELLOW), + Component.text(bot.serverName()).color(NamedTextColor.GRAY), + message.color(NamedTextColor.WHITE) + ).color(NamedTextColor.DARK_GRAY); + + allBot.chat().tellraw(component, player); + } + } + } + + @Override + public void playerJoined (MutablePlayerListEntry target) { + if (!trusted.contains(target.profile().getName())) return; + + broadcast( + Component.translatable( + "Trusted player %s is now online", + Component.text(target.profile().getName()).color(NamedTextColor.GREEN) + ) + ); + } + + @Override + public void playerLeft (MutablePlayerListEntry target) { + if (!trusted.contains(target.profile().getName())) return; + + broadcast( + Component.translatable( + "Trusted player %s is now offline", + Component.text(target.profile().getName()).color(NamedTextColor.GREEN) + ) + ); + } +} diff --git a/src/main/resources/default-config.yml b/src/main/resources/default-config.yml index c95e62e..20f1cec 100644 --- a/src/main/resources/default-config.yml +++ b/src/main/resources/default-config.yml @@ -17,6 +17,9 @@ discord: servers: localhost:25565: 'channel id' +trusted: + - 'player name' + keys: normalKey: 'normal hash key here' ownerKey: 'OwnerHash™ key here' @@ -50,3 +53,4 @@ bots: port: 25565 username: 'ChomeNS_Bot' kaboom: false + serverName: 'Localhost' # name it whatever you like, it will be used as server name in trusted broadcast