commandspy self care

This commit is contained in:
Chipmunk 2023-05-22 16:12:32 -04:00
parent fc065d4e57
commit 702fd1e273
2 changed files with 10 additions and 1 deletions

View file

@ -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<Listener> 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;

View file

@ -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