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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations