From e63be0909b730997a6a2e5e879f1c08e5d32eae8 Mon Sep 17 00:00:00 2001 From: Chipmunk <65827213+ChipmunkMC@users.noreply.github.com> Date: Tue, 18 Jun 2024 14:45:54 -0400 Subject: [PATCH] lazy bcraw & bcv implementation --- .../chipmunk/kaboomfabric/extras/Extras.java | 4 +- .../commands/CommandBroadcastVanilla.java | 41 +++++++++++++++++ .../extras/commands/CommandTellraw.java | 45 +++++++++++++++++++ 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandBroadcastVanilla.java create mode 100644 src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandTellraw.java diff --git a/src/main/java/land/chipmunk/kaboomfabric/extras/Extras.java b/src/main/java/land/chipmunk/kaboomfabric/extras/Extras.java index afa2d66..0b0082b 100644 --- a/src/main/java/land/chipmunk/kaboomfabric/extras/Extras.java +++ b/src/main/java/land/chipmunk/kaboomfabric/extras/Extras.java @@ -17,7 +17,7 @@ public class Extras implements ModInitializer { public static void registerCommands (CommandDispatcher dispatcher) { // CommandBroadcastMM.register(dispatcher); - // CommandBroadcastVanilla.register(dispatcher); + CommandBroadcastVanilla.register(dispatcher); CommandClearChat.register(dispatcher); CommandConsole.register(dispatcher); CommandDestroyEntities.register(dispatcher); @@ -32,7 +32,7 @@ public class Extras implements ModInitializer { // CommandSkin.register(dispatcher); CommandSpawn.register(dispatcher); CommandSpidey.register(dispatcher); - // CommandTellraw.register(dispatcher); + CommandTellraw.register(dispatcher); // CommandUsername.register(dispatcher); } diff --git a/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandBroadcastVanilla.java b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandBroadcastVanilla.java new file mode 100644 index 0000000..ca4a5c8 --- /dev/null +++ b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandBroadcastVanilla.java @@ -0,0 +1,41 @@ +package land.chipmunk.kaboomfabric.extras.commands; + +import land.chipmunk.kaboomfabric.extras.Extras; +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.Text; +import com.mojang.brigadier.tree.LiteralCommandNode; +import static net.minecraft.server.command.CommandManager.literal; +import static net.minecraft.server.command.CommandManager.argument; +import static com.mojang.brigadier.arguments.StringArgumentType.greedyString; +import static com.mojang.brigadier.arguments.StringArgumentType.getString; + +public interface CommandBroadcastVanilla { + static void register (CommandDispatcher dispatcher) { + final LiteralCommandNode node = dispatcher.register( + literal("broadcastvanilla") + .requires(CommandBroadcastVanilla::requirement) + .then( + argument("message", greedyString()) + .executes(CommandBroadcastVanilla::tellrawCommand) + ) + ); + + dispatcher.register(literal("bcv").requires(CommandBroadcastVanilla::requirement).executes(CommandTellraw::tellrawCommand).redirect(node)); + } + + static int tellrawCommand (CommandContext context) { + String string = getString(context, "message"); + Text text = Text.literal(Extras.parseEscapeSequences(string)); + + context.getSource().sendFeedback(text, true); + + return Command.SINGLE_SUCCESS; + } + + static boolean requirement (ServerCommandSource source) { + return source.hasPermissionLevel(2); + } +} diff --git a/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandTellraw.java b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandTellraw.java new file mode 100644 index 0000000..f80fa9d --- /dev/null +++ b/src/main/java/land/chipmunk/kaboomfabric/extras/commands/CommandTellraw.java @@ -0,0 +1,45 @@ +package land.chipmunk.kaboomfabric.extras.commands; + +import land.chipmunk.kaboomfabric.extras.Extras; +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.Text; +import net.minecraft.server.network.ServerPlayerEntity; +import com.mojang.brigadier.tree.LiteralCommandNode; +import static net.minecraft.server.command.CommandManager.literal; +import static net.minecraft.server.command.CommandManager.argument; +import static com.mojang.brigadier.arguments.StringArgumentType.greedyString; +import static com.mojang.brigadier.arguments.StringArgumentType.getString; + +public interface CommandTellraw { + static void register (CommandDispatcher dispatcher) { + final LiteralCommandNode node = dispatcher.register( + literal("broadcastraw") + .requires(CommandTellraw::requirement) + .then( + argument("message", greedyString()) + .executes(CommandTellraw::tellrawCommand) + ) + ); + + dispatcher.register(literal("bcraw").requires(CommandTellraw::requirement).executes(CommandTellraw::tellrawCommand).redirect(node)); + // No tellraw alias + } + + static int tellrawCommand (CommandContext context) { + String string = getString(context, "message"); + Text text = Text.literal(Extras.parseEscapeSequences(string)); + + for (ServerPlayerEntity player : context.getSource().getServer().getPlayerManager().getPlayerList()) { + player.sendMessage(text); + } + + return Command.SINGLE_SUCCESS; + } + + static boolean requirement (ServerCommandSource source) { + return source.hasPermissionLevel(2); + } +}