lazy bcraw & bcv implementation
This commit is contained in:
parent
bb9e4fe416
commit
e63be0909b
3 changed files with 88 additions and 2 deletions
|
@ -17,7 +17,7 @@ public class Extras implements ModInitializer {
|
||||||
|
|
||||||
public static void registerCommands (CommandDispatcher dispatcher) {
|
public static void registerCommands (CommandDispatcher dispatcher) {
|
||||||
// CommandBroadcastMM.register(dispatcher);
|
// CommandBroadcastMM.register(dispatcher);
|
||||||
// CommandBroadcastVanilla.register(dispatcher);
|
CommandBroadcastVanilla.register(dispatcher);
|
||||||
CommandClearChat.register(dispatcher);
|
CommandClearChat.register(dispatcher);
|
||||||
CommandConsole.register(dispatcher);
|
CommandConsole.register(dispatcher);
|
||||||
CommandDestroyEntities.register(dispatcher);
|
CommandDestroyEntities.register(dispatcher);
|
||||||
|
@ -32,7 +32,7 @@ public class Extras implements ModInitializer {
|
||||||
// CommandSkin.register(dispatcher);
|
// CommandSkin.register(dispatcher);
|
||||||
CommandSpawn.register(dispatcher);
|
CommandSpawn.register(dispatcher);
|
||||||
CommandSpidey.register(dispatcher);
|
CommandSpidey.register(dispatcher);
|
||||||
// CommandTellraw.register(dispatcher);
|
CommandTellraw.register(dispatcher);
|
||||||
// CommandUsername.register(dispatcher);
|
// CommandUsername.register(dispatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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<ServerCommandSource> 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<ServerCommandSource> 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue