From 1547326a54def1fcbe6b3b0d38befe05ff91779a Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sat, 1 Jul 2023 09:39:38 +0700 Subject: [PATCH] add actionbar ig useful for servers with command block ratelimit --- .../chipmunkmod/commands/MusicCommand.java | 28 +++++++++++++++---- .../chipmunkmod/modules/SongPlayer.java | 5 ++-- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/MusicCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/MusicCommand.java index bb78038..0e34a42 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/MusicCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/MusicCommand.java @@ -60,10 +60,10 @@ public class MusicCommand { .then( literal("list") - .executes(c -> instance.list(c, root)) + .executes(c -> instance.list(root)) .then( argument("location", filepath(root)) - .executes(c -> instance.list(c, getPath(c, "location"))) + .executes(c -> instance.list(getPath(c, "location"))) ) ) @@ -92,6 +92,14 @@ public class MusicCommand { ) ) + .then( + literal("actionbar") + .then( + argument("boolean", bool()) + .executes(instance::actionbar) + ) + ) + .then( literal("pitch") .then( @@ -156,9 +164,7 @@ public class MusicCommand { return 1; } - public int list (CommandContext context, Path path) throws CommandSyntaxException { - final FabricClientCommandSource source = context.getSource(); - + public int list (Path path) throws CommandSyntaxException { final CommandManager commandManager = CommandManager.INSTANCE; final String prefix = commandManager.prefix; @@ -291,6 +297,18 @@ public class MusicCommand { return 1; } + public int actionbar (CommandContext context) { + final FabricClientCommandSource source = context.getSource(); + + final boolean enabled = getBool(context, "boolean"); + + SongPlayer.INSTANCE.actionbar(enabled); + + source.sendFeedback(Text.literal("Showing actionbar is now " + (enabled ? "enabled" : "disabled"))); + + return 1; + } + public int pitch (CommandContext context) { final FabricClientCommandSource source = context.getSource(); diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java b/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java index 331edb4..1bcb73b 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java @@ -49,6 +49,7 @@ public class SongPlayer { private int ticksUntilPausedActionbar = 20; @Getter @Setter private boolean useCore = true; + @Getter @Setter private boolean actionbar = true; @Getter @Setter private float pitch = 0; @@ -129,8 +130,8 @@ public class SongPlayer { else ticksUntilPausedActionbar = 20; try { - if (!useCore) client.player.sendActionBar(generateActionbar()); - else CommandCore.INSTANCE.run("title " + SELECTOR + " actionbar " + GsonComponentSerializer.gson().serialize(generateActionbar())); + if (!useCore && actionbar) client.player.sendActionBar(generateActionbar()); + else if (actionbar) CommandCore.INSTANCE.run("title " + SELECTOR + " actionbar " + GsonComponentSerializer.gson().serialize(generateActionbar())); } catch (Exception e) { e.printStackTrace(); }