From b7bd19699d508b16321fb53c2cdd8e58be270f86 Mon Sep 17 00:00:00 2001 From: ChomeNS Date: Tue, 21 Mar 2023 15:00:48 +0700 Subject: [PATCH] add stuff and remove stuff about core and self care --- .../chomensbot_mabe/Configuration.java | 24 ++++++++++++ .../chomensbot_mabe/plugins/CorePlugin.java | 37 ++++++++++++++++++- .../plugins/SelfCarePlugin.java | 32 ++++++++++++---- src/main/resources/default-config.yml | 25 ++++++++++++- 4 files changed, 107 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/chayapak1/chomensbot_mabe/Configuration.java b/src/main/java/me/chayapak1/chomensbot_mabe/Configuration.java index ef0e2a5..21678b6 100644 --- a/src/main/java/me/chayapak1/chomensbot_mabe/Configuration.java +++ b/src/main/java/me/chayapak1/chomensbot_mabe/Configuration.java @@ -7,8 +7,32 @@ import java.util.Map; public class Configuration { @Getter public int reconnectDelay = 7000; @Getter public Map keys; + @Getter public Core core = new Core(); + @Getter public SelfCare selfCare = new SelfCare(); @Getter public Bots[] bots = new Bots[]{}; + public static class Core { + @Getter public int layers = 3; + @Getter public int refillInterval = 60 * 1000; + @Getter public String customName = "[{\"text\":\"ChomeNS \",\"color\":\"yellow\"},{\"text\":\"Core\",\"color\":\"green\"},{\"text\":\"™\",\"color\":\"gold\"}]"; + } + + public static class SelfCare { + @Getter public int checkInterval; + + @Getter public boolean op = true; + @Getter public boolean gamemode = true; + @Getter public boolean endCredits = true; + + @Getter public boolean cspy = true; + @Getter public boolean vanish = true; + @Getter public boolean nickname = true; + @Getter public boolean socialspy = true; + @Getter public boolean mute = true; + + @Getter public boolean prefix = true; + } + public static class Bots { @Getter public String host; @Getter public int port; diff --git a/src/main/java/me/chayapak1/chomensbot_mabe/plugins/CorePlugin.java b/src/main/java/me/chayapak1/chomensbot_mabe/plugins/CorePlugin.java index ee8099a..1cae8b1 100644 --- a/src/main/java/me/chayapak1/chomensbot_mabe/plugins/CorePlugin.java +++ b/src/main/java/me/chayapak1/chomensbot_mabe/plugins/CorePlugin.java @@ -1,7 +1,18 @@ package me.chayapak1.chomensbot_mabe.plugins; +import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; +import com.github.steveice10.mc.protocol.data.game.entity.object.Direction; +import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction; import com.github.steveice10.mc.protocol.data.game.level.block.CommandBlockMode; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSetCommandBlockPacket; +import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSetCreativeModeSlotPacket; +import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket; +import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundUseItemOnPacket; +import com.github.steveice10.opennbt.tag.builtin.ByteTag; +import com.github.steveice10.opennbt.tag.builtin.CompoundTag; +import com.github.steveice10.opennbt.tag.builtin.StringTag; +import com.github.steveice10.packetlib.Session; import com.nukkitx.math.vector.Vector3i; import lombok.Getter; import me.chayapak1.chomensbot_mabe.Bot; @@ -97,7 +108,7 @@ public class CorePlugin extends PositionPlugin.PositionListener { public void refill () { final String command = String.format( - "/minecraft:fill %s %s %s %s %s %s minecraft:command_block", + "/minecraft:fill %s %s %s %s %s %s minecraft:command_block{CustomName:'%s'}", coreStart.getX() + origin.getX(), coreStart.getY(), @@ -105,9 +116,31 @@ public class CorePlugin extends PositionPlugin.PositionListener { coreEnd.getX() + origin.getX(), coreEnd.getY(), - coreEnd.getZ() + origin.getZ() + coreEnd.getZ() + origin.getZ(), + + bot.config().core().customName() ); + bot.chat().send(command); + + // no work :( +// CompoundTag tag = new CompoundTag("tag"); +// CompoundTag blockEntityTag = new CompoundTag("BlockEntityTag"); +// blockEntityTag.getValue().put("Command", new StringTag("Command", command)); +// blockEntityTag.getValue().put("auto", new ByteTag("auto", (byte) 1)); +// blockEntityTag.getValue().put("TrackOutput", new ByteTag("TrackOutput", (byte) 1)); +// tag.getValue().put("BlockEntityTag", blockEntityTag); +// +// final Vector3i temporaryBlockPosition = Vector3i.from( +// bot.position().position().getX(), +// bot.position().position().getX() - 1, +// bot.position().position().getZ() +// ); +// +// final Session session = bot.session(); +// session.send(new ServerboundSetCreativeModeSlotPacket(45, new ItemStack(347 /* command block id */, 64, tag))); +// session.send(new ServerboundPlayerActionPacket(PlayerAction.START_DIGGING, temporaryBlockPosition, Direction.NORTH, 0)); +// session.send(new ServerboundUseItemOnPacket(temporaryBlockPosition, Direction.NORTH, Hand.OFF_HAND, 0.5f, 0.5f, 0.5f, false, 0)); } public static class Listener { diff --git a/src/main/java/me/chayapak1/chomensbot_mabe/plugins/SelfCarePlugin.java b/src/main/java/me/chayapak1/chomensbot_mabe/plugins/SelfCarePlugin.java index 259e0d7..e470394 100644 --- a/src/main/java/me/chayapak1/chomensbot_mabe/plugins/SelfCarePlugin.java +++ b/src/main/java/me/chayapak1/chomensbot_mabe/plugins/SelfCarePlugin.java @@ -2,6 +2,7 @@ package me.chayapak1.chomensbot_mabe.plugins; import com.github.steveice10.mc.protocol.MinecraftProtocol; import com.github.steveice10.mc.protocol.data.ProtocolState; +import com.github.steveice10.mc.protocol.data.game.ClientCommand; import com.github.steveice10.mc.protocol.data.game.entity.EntityEvent; import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; import com.github.steveice10.mc.protocol.data.game.level.notify.GameEvent; @@ -9,12 +10,14 @@ import com.github.steveice10.mc.protocol.data.game.level.notify.GameEventValue; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundEntityEventPacket; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundGameEventPacket; +import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundClientCommandPacket; import com.github.steveice10.packetlib.Session; import com.github.steveice10.packetlib.event.session.DisconnectedEvent; import com.github.steveice10.packetlib.event.session.SessionAdapter; import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.PacketProtocol; import me.chayapak1.chomensbot_mabe.Bot; +import me.chayapak1.chomensbot_mabe.Configuration; import net.kyori.adventure.text.Component; import java.util.concurrent.ScheduledFuture; @@ -30,6 +33,7 @@ public class SelfCarePlugin extends SessionAdapter { private int permissionLevel; private boolean cspy = false; private boolean vanish = false; + private boolean nickname = false; private boolean socialspy = false; private boolean muted = false; private boolean prefix = false; @@ -48,6 +52,9 @@ public class SelfCarePlugin extends SessionAdapter { else if (message.equals("Vanish for " + bot.username() + ": enabled")) vanish = true; else if (message.equals("Vanish for " + bot.username() + ": disabled")) vanish = false; + else if (message.equals("You no longer have a nickname.")) nickname = true; + else if (message.startsWith("Your nickname is now ")) nickname = false; + else if (message.equals("SocialSpy for " + bot.username() + ": enabled")) socialspy = true; else if (message.equals("SocialSpy for " + bot.username() + ": disabled")) socialspy = false; @@ -67,13 +74,16 @@ public class SelfCarePlugin extends SessionAdapter { } public void check () { - if (gamemode != GameMode.CREATIVE) bot.chat().send("/minecraft:gamemode creative @s[type=player]"); - else if (permissionLevel < 2) bot.chat().send("/minecraft:op @s[type=player]"); - else if (!cspy) bot.chat().send("/commandspy:commandspy on"); - else if (!vanish) bot.chat().send("/essentials:vanish enable"); - else if (!socialspy) bot.chat().send("/essentials:socialspy enable"); - else if (muted) bot.chat().send("/essentials:mute " + bot.username()); - else if (!prefix) bot.chat().send("/extras:prefix &8[&eChomeNS Bot&8]"); + final Configuration.SelfCare selfCares = bot.config().selfCare(); + + if (selfCares.gamemode() && gamemode != GameMode.CREATIVE) bot.chat().send("/minecraft:gamemode creative @s[type=player]"); + else if (selfCares.op() && permissionLevel < 2) bot.chat().send("/minecraft:op @s[type=player]"); + else if (selfCares.cspy() && !cspy) bot.chat().send("/commandspy:commandspy on"); + else if (selfCares.vanish() && !vanish) bot.chat().send("/essentials:vanish enable"); + else if (selfCares.nickname() && !nickname) bot.chat().send("/essentials:nickname off"); + else if (selfCares.socialspy() && !socialspy) bot.chat().send("/essentials:socialspy enable"); + else if (selfCares.mute() && muted) bot.chat().send("/essentials:mute " + bot.username()); + else if (selfCares.prefix() && !prefix) bot.chat().send("/extras:prefix &8[&eChomeNS Bot&8]"); } @Override @@ -89,6 +99,7 @@ public class SelfCarePlugin extends SessionAdapter { cspy = false; vanish = false; + nickname = false; socialspy = false; muted = false; prefix = false; @@ -107,13 +118,18 @@ public class SelfCarePlugin extends SessionAdapter { check(); }; - futureTask = bot.executor().scheduleAtFixedRate(task, 50, 500, TimeUnit.MILLISECONDS); + futureTask = bot.executor().scheduleAtFixedRate(task, bot.config().selfCare().checkInterval(), 500, TimeUnit.MILLISECONDS); } public void packetReceived (ClientboundGameEventPacket packet) { final GameEvent notification = packet.getNotification(); final GameEventValue value = packet.getValue(); + if (notification == GameEvent.ENTER_CREDITS) { + bot.session().send(new ServerboundClientCommandPacket(ClientCommand.RESPAWN)); + return; + } + if (notification == GameEvent.CHANGE_GAMEMODE) gamemode = (GameMode) value; } diff --git a/src/main/resources/default-config.yml b/src/main/resources/default-config.yml index 3227a99..5a5e464 100644 --- a/src/main/resources/default-config.yml +++ b/src/main/resources/default-config.yml @@ -2,8 +2,31 @@ reconnectDelay: 7000 keys: normalKey: 'normal hash key here' ownerKey: 'OwnerHash™ key here' +core: + layers: 3 + # will add refill interval later after the bot can place command blocks to refill core + # refillInterval: 60000 + # PLEASE give valid JSON component here else the core don't refill at all + customName: '[{"text":"ChomeNS ","color":"yellow"},{"text":"Core","color":"green"},{"text":"™","color":"gold"}]' +selfCare: + checkInterval: 1000, + + # vanilla + op: true, + gamemode: true, + endCredits: true, + + # essentials + cspy: true, + vanish: true, + nickname: true, + socialspy: true, + mute: true, + + # extras + prefix: true bots: - # username is optional, if doesn't exist it will default to random username + # username is optional, if it doesn't exist it will default to random username - host: 'localhost' port: 25565 username: 'ChomeNS_Bot' \ No newline at end of file