优化命令注册
This commit is contained in:
parent
3f60239579
commit
f8d4460cdc
2 changed files with 22 additions and 8 deletions
|
@ -2,24 +2,21 @@
|
||||||
package net.mcreator.superbwarfare.command;
|
package net.mcreator.superbwarfare.command;
|
||||||
|
|
||||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import net.mcreator.superbwarfare.network.ModVariables;
|
import net.mcreator.superbwarfare.network.ModVariables;
|
||||||
import net.mcreator.superbwarfare.tools.GunInfo;
|
import net.mcreator.superbwarfare.tools.GunInfo;
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.Commands;
|
import net.minecraft.commands.Commands;
|
||||||
import net.minecraft.commands.arguments.EntityArgument;
|
import net.minecraft.commands.arguments.EntityArgument;
|
||||||
import net.minecraft.network.chat.Component;
|
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 net.minecraftforge.server.command.EnumArgument;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber
|
|
||||||
public class AmmoCommand {
|
public class AmmoCommand {
|
||||||
@SubscribeEvent
|
public static LiteralArgumentBuilder<CommandSourceStack> get() {
|
||||||
public static void registerCommand(RegisterCommandsEvent event) {
|
|
||||||
// mojang你看看你写的是个牛魔Builder😅
|
// 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 -> {
|
.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");
|
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);
|
context.getSource().sendSuccess(() -> Component.translatable("commands.ammo.add", Component.translatable(type.translatableKey), value, players.size()), true);
|
||||||
return 0;
|
return 0;
|
||||||
}))))));
|
})))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue