goldodemon/Minecraft-JavaSet / ExampleCommands.java
goldodemon's picture
download
raw
2.49 kB
package com.example.examplemod;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.entity.Entity;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text;
/**
* Brigadier command registration via Fabric's CommandRegistrationCallback.
* Unchanged across 1.21.7 - 1.21.11.
*/
public final class ExampleCommands {
private ExampleCommands() {}
public static void register() {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
dispatcher.register(CommandManager.literal("examplemod")
.then(CommandManager.literal("hello")
.executes(ExampleCommands::executeHello))
.then(CommandManager.literal("give")
.then(CommandManager.argument("amount", IntegerArgumentType.integer(1, 64))
.executes(ExampleCommands::executeGive)))
.then(CommandManager.literal("ping")
.then(CommandManager.argument("target", EntityArgumentType.player())
.executes(ExampleCommands::executePing)))
);
});
}
private static int executeHello(com.mojang.brigadier.context.CommandContext<ServerCommandSource> ctx) {
ctx.getSource().sendFeedback(() -> Text.literal("Hello from ExampleMod!"), false);
return 1;
}
private static int executeGive(com.mojang.brigadier.context.CommandContext<ServerCommandSource> ctx) {
int amount = IntegerArgumentType.getInteger(ctx, "amount");
var player = ctx.getSource().getPlayerOrThrow();
player.giveItemStack(new net.minecraft.item.ItemStack(ExampleMod.EXAMPLE_GEM, amount));
ctx.getSource().sendFeedback(() -> Text.literal("Gave " + amount + " example gems."), true);
return 1;
}
private static int executePing(com.mojang.brigadier.context.CommandContext<ServerCommandSource> ctx)
throws com.mojang.brigadier.exceptions.CommandSyntaxException {
Entity target = EntityArgumentType.getPlayer(ctx, "target");
ctx.getSource().sendFeedback(() -> Text.literal("Pinged " + target.getName().getString()), false);
return 1;
}
}

Xet Storage Details

Size:
2.49 kB
·
Xet hash:
7c5b64e5c944a4ad0e9b4433c38b2a2fdf1d8b9416970271adeb1c477b2183a4

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.