From 702fd1e2731fbb3166a48276e31d1719bb89bf92 Mon Sep 17 00:00:00 2001 From: Chipmunk <65827213+ChipmunkMC@users.noreply.github.com> Date: Mon, 22 May 2023 16:12:32 -0400 Subject: [PATCH] commandspy self care --- .../chipmunk/chipmunkbot/plugins/CommandSpyPlugin.java | 8 ++++++++ .../land/chipmunk/chipmunkbot/plugins/SelfCarePlugin.java | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/land/chipmunk/chipmunkbot/plugins/CommandSpyPlugin.java b/src/main/java/land/chipmunk/chipmunkbot/plugins/CommandSpyPlugin.java index 8da3db0..0e97f9c 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/plugins/CommandSpyPlugin.java +++ b/src/main/java/land/chipmunk/chipmunkbot/plugins/CommandSpyPlugin.java @@ -7,16 +7,20 @@ import net.kyori.adventure.text.format.Style; import net.kyori.adventure.text.format.NamedTextColor; import land.chipmunk.chipmunkbot.data.MutablePlayerListEntry; import lombok.Getter; +import lombok.Setter; import java.util.List; import java.util.ArrayList; public class CommandSpyPlugin extends ChatPlugin.Listener { private final ChipmunkBot client; @Getter private List listeners = new ArrayList<>(); + @Getter @Setter private boolean enabled = false; private static final Style ENABLED_STYLE = Style.style(NamedTextColor.YELLOW); private static final Style DISABLED_STYLE = Style.style(NamedTextColor.AQUA); + private static final Component COMMANDSPY_ENABLED_COMPONENT = Component.text("Successfully enabled CommandSpy"); + private static final Component COMMANDSPY_DISABLED_COMPONENT = Component.text("Successfully disabled CommandSpy"); private static final Component COMMAND_SEPARATOR_COMPONENT = Component.text(": "); private static final Component SIGN_CREATED_TEXT_COMPONENT = Component.text(" created a sign with contents:"); private static final Component SIGN_LINE_SEPARATOR_COMPONENT = Component.text("\n "); @@ -29,6 +33,10 @@ public class CommandSpyPlugin extends ChatPlugin.Listener { @Override public void systemMessageReceived (Component component, boolean overlay) { if (overlay || !(component instanceof final TextComponent t_component)) return; + + if (component.equals(COMMANDSPY_ENABLED_COMPONENT)) { this.enabled = true; return; } + if (component.equals(COMMANDSPY_DISABLED_COMPONENT)) { this.enabled = false; return; } + final boolean enabled = component.style().equals(ENABLED_STYLE); if (!enabled && !component.style().equals(DISABLED_STYLE)) return; diff --git a/src/main/java/land/chipmunk/chipmunkbot/plugins/SelfCarePlugin.java b/src/main/java/land/chipmunk/chipmunkbot/plugins/SelfCarePlugin.java index e8188d6..11785bf 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/plugins/SelfCarePlugin.java +++ b/src/main/java/land/chipmunk/chipmunkbot/plugins/SelfCarePlugin.java @@ -52,8 +52,9 @@ public class SelfCarePlugin extends SessionAdapter { } public void tick () { - if (gamemode != GameMode.CREATIVE) client.chat().command("minecraft:gamemode creative"); if (permissionLevel < 2) client.chat().command("minecraft:op @s[type=player]"); + else if (gamemode != GameMode.CREATIVE) client.chat().command("minecraft:gamemode creative"); + else if (!client.commandSpy().enabled()) client.chat().command("c on"); } @Override