Search in sources :

Example 1 with ServerCommandSource

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

Example 2 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource in project Rug by RubixDev.

the class MaxEffectCommand method register.

public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
    LiteralArgumentBuilder<ServerCommandSource> command = literal("maxeffect").requires((player) -> SettingsManager.canUseCommand(player, RugSettings.commandMaxEffect)).then(argument("effect", StatusEffectArgumentType.statusEffect()).executes(context -> {
        ServerCommandSource source = context.getSource();
        ServerPlayerEntity player = source.getPlayer();
        StatusEffect effect = StatusEffectArgumentType.getStatusEffect(context, "effect");
        boolean success = false;
        if (player instanceof LivingEntity) {
            StatusEffectInstance statusEffectInstance = new StatusEffectInstance(effect, effect.isInstant() ? 999999 : (999999 * 20), 255, false, false);
            success = (player).addStatusEffect(statusEffectInstance, source.getEntity());
        }
        if (!success) {
            throw new SimpleCommandExceptionType(new TranslatableText("commands.effect.give.failed")).create();
        }
        source.sendFeedback(new TranslatableText("commands.effect.give.success.single", effect.getName(), player.getDisplayName(), 999999), true);
        return 1;
    }));
    dispatcher.register(command);
}
Also used : StatusEffectArgumentType(net.minecraft.command.argument.StatusEffectArgumentType) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) LivingEntity(net.minecraft.entity.LivingEntity) SettingsManager(carpet.settings.SettingsManager) 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) StatusEffect(net.minecraft.entity.effect.StatusEffect) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) TranslatableText(net.minecraft.text.TranslatableText) StatusEffect(net.minecraft.entity.effect.StatusEffect) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) SimpleCommandExceptionType(com.mojang.brigadier.exceptions.SimpleCommandExceptionType) ServerCommandSource(net.minecraft.server.command.ServerCommandSource)

Example 3 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource in project Rug by RubixDev.

the class PeekCommand method execute.

private static int execute(CommandContext<ServerCommandSource> context, boolean isEnderChest) throws CommandSyntaxException {
    ServerCommandSource source = context.getSource();
    PlayerManager playerManager = source.getServer().getPlayerManager();
    GameProfile targetPlayerProfile = GameProfileArgumentType.getProfileArgument(context, "player").iterator().next();
    ServerPlayerEntity targetPlayer = playerManager.getPlayer(targetPlayerProfile.getName());
    ServerPlayerEntity executingPlayer = source.getPlayer();
    if (targetPlayer == null) {
        targetPlayer = playerManager.createPlayer(targetPlayerProfile);
        NbtCompound targetPlayerData = playerManager.loadPlayerData(targetPlayer);
        if (targetPlayerData == null) {
            source.sendError(Text.of("Targeted player's data could not be found. Was he ever in this world?"));
            return 0;
        }
        @SuppressWarnings("deprecation") ServerWorld world = source.getServer().getWorld(DimensionType.worldFromDimensionNbt(new Dynamic<>(NbtOps.INSTANCE, targetPlayerData.get("Dimension"))).result().orElseThrow());
        if (world != null)
            targetPlayer.setWorld(world);
    }
    if (isEnderChest) {
        showEnderChest(executingPlayer, targetPlayer);
    } else {
        showInventory(executingPlayer, targetPlayer);
    }
    return 1;
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) Dynamic(com.mojang.serialization.Dynamic) NbtCompound(net.minecraft.nbt.NbtCompound) PlayerManager(net.minecraft.server.PlayerManager) GameProfile(com.mojang.authlib.GameProfile) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource)

Example 4 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource in project KahzerxMod by otakucraft.

the class SpoofExtension method spoofInv.

public int spoofInv(ServerCommandSource source, String playerE) throws CommandSyntaxException {
    int invSize = 54;
    int hotBarSize = 9;
    int hotBarStartPos = 27;
    int invStartPos = 9;
    Inventory inventory = new SimpleInventory(invSize);
    ServerPlayerEntity player = source.getPlayer();
    ServerPlayerEntity player2 = source.getServer().getPlayerManager().getPlayer(playerE);
    assert player2 != null;
    for (int i = 0; i < player2.getInventory().main.size(); i++) {
        if (i < hotBarSize) {
            inventory.setStack(i + hotBarStartPos, player2.getInventory().main.get(i));
        } else {
            inventory.setStack(i - invStartPos, player2.getInventory().main.get(i));
        }
    }
    int armorSlotStartPos = 45;
    for (int j = 0; j < player2.getInventory().armor.size(); j++) {
        inventory.setStack(j + armorSlotStartPos, player2.getInventory().armor.get(j));
    }
    int offHandSlotPos = 36;
    inventory.setStack(offHandSlotPos, player2.getInventory().offHand.get(0));
    ScreenHandlerListener listener = new ScreenHandlerListener() {

        @Override
        public void onSlotUpdate(ScreenHandler handler, int slotId, ItemStack stack) {
        // source.getServer().getPlayerManager().saveAllPlayerData();
        }

        @Override
        public void onPropertyUpdate(ScreenHandler handler, int property, int value) {
        }
    };
    player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> {
        GenericContainerScreenHandler invCont = GenericContainerScreenHandler.createGeneric9x6(i, playerInventory, inventory);
        invCont.addListener(listener);
        return invCont;
    }, new LiteralText(String.format("%s stop hax >:(", player.getName().getString()))));
    return 1;
}
Also used : ExtensionSettings(com.kahzerx.kahzerxmod.extensions.ExtensionSettings) LiteralText(net.minecraft.text.LiteralText) ScreenHandler(net.minecraft.screen.ScreenHandler) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) GenericExtension(com.kahzerx.kahzerxmod.extensions.GenericExtension) EnderChestInventory(net.minecraft.inventory.EnderChestInventory) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) ScreenHandlerListener(net.minecraft.screen.ScreenHandlerListener) SimpleNamedScreenHandlerFactory(net.minecraft.screen.SimpleNamedScreenHandlerFactory) Extensions(com.kahzerx.kahzerxmod.Extensions) Inventory(net.minecraft.inventory.Inventory) SimpleInventory(net.minecraft.inventory.SimpleInventory) ItemStack(net.minecraft.item.ItemStack) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) GenericContainerScreenHandler(net.minecraft.screen.GenericContainerScreenHandler) ScreenHandlerListener(net.minecraft.screen.ScreenHandlerListener) GenericContainerScreenHandler(net.minecraft.screen.GenericContainerScreenHandler) SimpleNamedScreenHandlerFactory(net.minecraft.screen.SimpleNamedScreenHandlerFactory) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ScreenHandler(net.minecraft.screen.ScreenHandler) GenericContainerScreenHandler(net.minecraft.screen.GenericContainerScreenHandler) ItemStack(net.minecraft.item.ItemStack) EnderChestInventory(net.minecraft.inventory.EnderChestInventory) Inventory(net.minecraft.inventory.Inventory) SimpleInventory(net.minecraft.inventory.SimpleInventory) SimpleInventory(net.minecraft.inventory.SimpleInventory) LiteralText(net.minecraft.text.LiteralText)

Example 5 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource in project KahzerxMod by otakucraft.

the class SpoofExtension method spoofEC.

public int spoofEC(ServerCommandSource source, String playerE) throws CommandSyntaxException {
    ServerPlayerEntity player = source.getPlayer();
    ServerPlayerEntity player2 = source.getServer().getPlayerManager().getPlayer(playerE);
    if (player2 != null) {
        EnderChestInventory enderChestInventory = player2.getEnderChestInventory();
        // Generar la pantalla de enderChest.
        player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> GenericContainerScreenHandler.createGeneric9x3(i, playerInventory, enderChestInventory), new LiteralText(String.format("%s stop hax >:(", player.getName().getString()))));
    } else {
        source.sendFeedback(new LiteralText("player offline"), false);
    }
    return 1;
}
Also used : ExtensionSettings(com.kahzerx.kahzerxmod.extensions.ExtensionSettings) LiteralText(net.minecraft.text.LiteralText) ScreenHandler(net.minecraft.screen.ScreenHandler) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) GenericExtension(com.kahzerx.kahzerxmod.extensions.GenericExtension) EnderChestInventory(net.minecraft.inventory.EnderChestInventory) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) ScreenHandlerListener(net.minecraft.screen.ScreenHandlerListener) SimpleNamedScreenHandlerFactory(net.minecraft.screen.SimpleNamedScreenHandlerFactory) Extensions(com.kahzerx.kahzerxmod.Extensions) Inventory(net.minecraft.inventory.Inventory) SimpleInventory(net.minecraft.inventory.SimpleInventory) ItemStack(net.minecraft.item.ItemStack) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) GenericContainerScreenHandler(net.minecraft.screen.GenericContainerScreenHandler) SimpleNamedScreenHandlerFactory(net.minecraft.screen.SimpleNamedScreenHandlerFactory) EnderChestInventory(net.minecraft.inventory.EnderChestInventory) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) 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