Search in sources :

Example 41 with ServerCommandSource

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);
}
Also used : CommandManager(net.minecraft.server.command.CommandManager) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource)

Example 42 with ServerCommandSource

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);
}
Also used : StructureWorldAccess(net.minecraft.world.StructureWorldAccess) LiteralText(net.minecraft.text.LiteralText) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) ChunkRandom(net.minecraft.world.gen.random.ChunkRandom) Util(net.minecraft.util.Util) SettingsManager(carpet.settings.SettingsManager) ChunkPos(net.minecraft.util.math.ChunkPos) RugSettings(de.rubixdev.rug.RugSettings) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) CommandManager(net.minecraft.server.command.CommandManager) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ChunkPos(net.minecraft.util.math.ChunkPos) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) StructureWorldAccess(net.minecraft.world.StructureWorldAccess) LiteralText(net.minecraft.text.LiteralText)

Example 43 with ServerCommandSource

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);
}
Also used : LiteralText(net.minecraft.text.LiteralText) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) Collection(java.util.Collection) SettingsManager(carpet.settings.SettingsManager) MessageType(net.minecraft.network.MessageType) PlayerManager(net.minecraft.server.PlayerManager) TranslatableText(net.minecraft.text.TranslatableText) RugSettings(de.rubixdev.rug.RugSettings) CommandManager.literal(net.minecraft.server.command.CommandManager.literal) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) SimpleCommandExceptionType(com.mojang.brigadier.exceptions.SimpleCommandExceptionType) CommandManager.argument(net.minecraft.server.command.CommandManager.argument) StringArgumentType(com.mojang.brigadier.arguments.StringArgumentType) MinecraftServer(net.minecraft.server.MinecraftServer) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) CommandSource.suggestMatching(net.minecraft.command.CommandSource.suggestMatching) Message(com.mojang.brigadier.Message) Text(net.minecraft.text.Text) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) TranslatableText(net.minecraft.text.TranslatableText) Message(com.mojang.brigadier.Message) PlayerManager(net.minecraft.server.PlayerManager) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) LiteralText(net.minecraft.text.LiteralText) TranslatableText(net.minecraft.text.TranslatableText) Text(net.minecraft.text.Text) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) MinecraftServer(net.minecraft.server.MinecraftServer) SimpleCommandExceptionType(com.mojang.brigadier.exceptions.SimpleCommandExceptionType) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) LiteralText(net.minecraft.text.LiteralText)

Aggregations

ServerCommandSource (net.minecraft.server.command.ServerCommandSource)43 LiteralText (net.minecraft.text.LiteralText)35 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)33 CommandDispatcher (com.mojang.brigadier.CommandDispatcher)14 CommandManager.literal (net.minecraft.server.command.CommandManager.literal)11 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)9 CommandManager.argument (net.minecraft.server.command.CommandManager.argument)9 Extensions (com.kahzerx.kahzerxmod.Extensions)7 GenericExtension (com.kahzerx.kahzerxmod.extensions.GenericExtension)7 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)6 UUID (java.util.UUID)6 CommandManager (net.minecraft.server.command.CommandManager)6 ExtensionSettings (com.kahzerx.kahzerxmod.extensions.ExtensionSettings)5 IntegerArgumentType (com.mojang.brigadier.arguments.IntegerArgumentType)5 StringArgumentType (com.mojang.brigadier.arguments.StringArgumentType)5 MinecraftServer (net.minecraft.server.MinecraftServer)5 ExtensionManager (com.kahzerx.kahzerxmod.ExtensionManager)4 GameProfile (com.mojang.authlib.GameProfile)4 ClickEvent (net.minecraft.text.ClickEvent)4 MutableText (net.minecraft.text.MutableText)4