add actionbar ig

useful for servers with command block ratelimit
This commit is contained in:
Chayapak 2023-07-01 09:39:38 +07:00
parent 3328fa4ff1
commit 1547326a54
2 changed files with 26 additions and 7 deletions

View file

@ -60,10 +60,10 @@ public class MusicCommand {
.then( .then(
literal("list") literal("list")
.executes(c -> instance.list(c, root)) .executes(c -> instance.list(root))
.then( .then(
argument("location", filepath(root)) 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( .then(
literal("pitch") literal("pitch")
.then( .then(
@ -156,9 +164,7 @@ public class MusicCommand {
return 1; return 1;
} }
public int list (CommandContext<FabricClientCommandSource> context, Path path) throws CommandSyntaxException { public int list (Path path) throws CommandSyntaxException {
final FabricClientCommandSource source = context.getSource();
final CommandManager commandManager = CommandManager.INSTANCE; final CommandManager commandManager = CommandManager.INSTANCE;
final String prefix = commandManager.prefix; final String prefix = commandManager.prefix;
@ -291,6 +297,18 @@ public class MusicCommand {
return 1; return 1;
} }
public int actionbar (CommandContext<FabricClientCommandSource> 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<FabricClientCommandSource> context) { public int pitch (CommandContext<FabricClientCommandSource> context) {
final FabricClientCommandSource source = context.getSource(); final FabricClientCommandSource source = context.getSource();

View file

@ -49,6 +49,7 @@ public class SongPlayer {
private int ticksUntilPausedActionbar = 20; private int ticksUntilPausedActionbar = 20;
@Getter @Setter private boolean useCore = true; @Getter @Setter private boolean useCore = true;
@Getter @Setter private boolean actionbar = true;
@Getter @Setter private float pitch = 0; @Getter @Setter private float pitch = 0;
@ -129,8 +130,8 @@ public class SongPlayer {
else ticksUntilPausedActionbar = 20; else ticksUntilPausedActionbar = 20;
try { try {
if (!useCore) client.player.sendActionBar(generateActionbar()); if (!useCore && actionbar) client.player.sendActionBar(generateActionbar());
else CommandCore.INSTANCE.run("title " + SELECTOR + " actionbar " + GsonComponentSerializer.gson().serialize(generateActionbar())); else if (actionbar) CommandCore.INSTANCE.run("title " + SELECTOR + " actionbar " + GsonComponentSerializer.gson().serialize(generateActionbar()));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }