use of net.minecraft.server.command.CommandManager in project Rug by RubixDev.
the class FrameCommand method register.
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
LiteralArgumentBuilder<ServerCommandSource> command = CommandManager.literal("frame").requires((player) -> SettingsManager.canUseCommand(player, RugSettings.commandFrame)).then(CommandManager.literal("hide").executes((context) -> {
ServerCommandSource playerSource = context.getSource();
ServerCommandSource source = playerSource.getServer().getCommandSource();
ServerPlayerEntity playerEntity = playerSource.getPlayer();
CommandManager manager = playerSource.getServer().getCommandManager();
String playerName = playerEntity.getName().getString();
manager.execute(source, "execute at " + playerName + " run tag @e[type=minecraft:item_frame,distance=..5] remove hasItem");
manager.execute(source, "execute at " + playerName + " run tag @e[type=minecraft:item_frame,distance=..5,nbt={Item:{}}] add hasItem");
manager.execute(source, "execute at " + playerName + " as @e[type=item_frame,distance=..5,tag=hasItem,limit=1,sort=nearest,nbt={Fixed:0b,Invisible:0b}]" + " run data merge entity @s {Invisible:1b,Fixed:1b}");
manager.execute(source, "execute at " + playerName + " run tag @e[type=minecraft:item_frame,distance=..5] remove hasItem");
return 1;
})).then(CommandManager.literal("show").executes((context -> {
ServerCommandSource playerSource = context.getSource();
ServerCommandSource source = playerSource.getServer().getCommandSource();
ServerPlayerEntity playerEntity = playerSource.getPlayer();
CommandManager manager = playerSource.getServer().getCommandManager();
String playerName = playerEntity.getName().getString();
manager.execute(source, "execute at " + playerName + " as @e[type=item_frame,distance=..5,limit=1,sort=nearest,nbt={Fixed:1b,Invisible:1b}]" + " run data merge entity @s {Invisible:0b,Fixed:0b}");
return 1;
})));
dispatcher.register(command);
}
use of net.minecraft.server.command.CommandManager in project allium by hugeblank.
the class CommandLib method create.
public static LuaLibrary create(Plugin plugin) {
LuaTable mt = new LuaTable();
mt.rawset("__index", new VarArgFunction() {
@Override
public Varargs invoke(LuaState state, Varargs args) throws LuaError {
if (isServerNull(plugin))
return Constants.NIL;
String command = args.arg(2).checkString();
CommandManager manager = Allium.SERVER.getCommandManager();
CommandDispatcher<ServerCommandSource> dispatcher = manager.getDispatcher();
for (CommandNode<?> child : dispatcher.getRoot().getChildren()) {
if (child.getName().equals(command)) {
return new ExecuteCommandFunction(plugin, command);
}
}
return Constants.NIL;
}
});
return LibBuilder.create("commands").set("exec", // commands.exec(String... command)
new ExecuteCommandFunction(plugin)::invoke).addMetatable(// commands.command(String... arguments)
mt).build();
}
use of net.minecraft.server.command.CommandManager in project Rug by RubixDev.
the class SkullCommand method execute.
private static int execute(CommandContext<ServerCommandSource> context, int count) throws CommandSyntaxException {
ServerCommandSource playerSource = context.getSource();
ServerCommandSource source = playerSource.getServer().getCommandSource();
CommandManager manager = playerSource.getServer().getCommandManager();
ServerPlayerEntity playerEntity = playerSource.getPlayer();
String playerName = playerEntity.getName().getString();
String skullOwner = count == 0 ? playerName : context.getArgument("player", String.class);
if (count == 0)
count = 1;
return manager.execute(source, "give " + playerName + " minecraft:player_head{SkullOwner:" + skullOwner + "} " + count);
}
Aggregations