优化命令注册

This commit is contained in:
Light_Quanta 2024-11-22 13:47:20 +08:00
parent 3f60239579
commit f8d4460cdc
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
2 changed files with 22 additions and 8 deletions

View file

@ -2,24 +2,21 @@
package net.mcreator.superbwarfare.command;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.mcreator.superbwarfare.network.ModVariables;
import net.mcreator.superbwarfare.tools.GunInfo;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.network.chat.Component;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.server.command.EnumArgument;
import java.util.Objects;
@Mod.EventBusSubscriber
public class AmmoCommand {
@SubscribeEvent
public static void registerCommand(RegisterCommandsEvent event) {
public static LiteralArgumentBuilder<CommandSourceStack> get() {
// mojang你看看你写的是个牛魔Builder😅
event.getDispatcher().register(Commands.literal("ammo").requires(s -> s.hasPermission(0))
return Commands.literal("ammo").requires(s -> s.hasPermission(0))
.then(Commands.literal("get").then(Commands.argument("player", EntityArgument.player()).then(Commands.argument("type", EnumArgument.enumArgument(GunInfo.Type.class)).executes(context -> {
var player = EntityArgument.getPlayer(context, "player");
@ -89,6 +86,6 @@ public class AmmoCommand {
context.getSource().sendSuccess(() -> Component.translatable("commands.ammo.add", Component.translatable(type.translatableKey), value, players.size()), true);
return 0;
}))))));
})))));
}
}

View file

@ -0,0 +1,17 @@
package net.mcreator.superbwarfare.command;
import net.minecraft.commands.Commands;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@Mod.EventBusSubscriber
public class CommandRegister {
@SubscribeEvent
public static void registerCommand(RegisterCommandsEvent event) {
var command = Commands.literal("sbw");
command.then(AmmoCommand.get());
event.getDispatcher().register(command);
}
}