use of net.minecraft.server.command.ServerCommandSource 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);
}
use of net.minecraft.server.command.ServerCommandSource in project Rug by RubixDev.
the class SlimeChunkCommand method register.
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
LiteralArgumentBuilder<ServerCommandSource> command = CommandManager.literal("slimechunk").requires((player) -> SettingsManager.canUseCommand(player, RugSettings.commandSlimeChunk)).executes(c -> {
ServerPlayerEntity playerEntity = c.getSource().getPlayer();
ChunkPos chunkPos = new ChunkPos(playerEntity.getBlockPos());
StructureWorldAccess worldAccess = c.getSource().getWorld();
boolean isSlimeChunk = ChunkRandom.getSlimeRandom(chunkPos.x, chunkPos.z, worldAccess.getSeed(), 987234911L).nextInt(10) < RugSettings.slimeChunkPercentage / 10;
playerEntity.sendSystemMessage(new LiteralText("You are " + (isSlimeChunk ? "" : "not ") + "in a Slime Chunk"), Util.NIL_UUID);
return 1;
});
dispatcher.register(command);
}
use of net.minecraft.server.command.ServerCommandSource in project Rug by RubixDev.
the class SudoCommand method register.
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
LiteralArgumentBuilder<ServerCommandSource> command = literal("sudo").requires((player) -> SettingsManager.canUseCommand(player, RugSettings.commandSudo)).then(argument("player", StringArgumentType.word()).suggests(((context, builder) -> suggestMatching(getPlayers(context.getSource()), builder))).then(literal("chat").then(argument("message", StringArgumentType.greedyString()).executes(context -> {
String targetPlayerName = StringArgumentType.getString(context, "player");
MinecraftServer server = context.getSource().getServer();
PlayerManager playerManager = server.getPlayerManager();
ServerPlayerEntity targetPlayer = playerManager.getPlayer(targetPlayerName);
if (targetPlayer == null) {
context.getSource().sendError(new LiteralText("Targeted Player could not be found"));
return 0;
}
Text text = new TranslatableText("chat.type.text", targetPlayerName, StringArgumentType.getString(context, "message"));
playerManager.broadcast(text, MessageType.CHAT, targetPlayer.getUuid());
return 1;
}))).then(literal("command").redirect(dispatcher.getRoot(), context -> {
String targetPlayerName = StringArgumentType.getString(context, "player");
MinecraftServer server = context.getSource().getServer();
ServerPlayerEntity player = server.getPlayerManager().getPlayer(targetPlayerName);
if (player == null) {
Message errorMessage = new LiteralText("Targeted player could not be found");
throw new CommandSyntaxException(new SimpleCommandExceptionType(errorMessage), errorMessage);
}
return player.getCommandSource();
})));
dispatcher.register(command);
}
Aggregations