Search in sources :

Example 11 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity 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 12 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity 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 13 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity in project UniversalGraves by Patbox.

the class Commands method listOthers.

private static int listOthers(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
    ServerPlayerEntity player = context.getSource().getPlayer();
    List<GameProfile> profiles = new ArrayList(context.getArgument("player", GameProfileArgumentType.GameProfileArgument.class).getNames(context.getSource()));
    if (profiles.size() == 0) {
        context.getSource().sendFeedback(new LiteralText("This player doesn't exist!"), false);
        return 0;
    } else if (profiles.size() > 1) {
        context.getSource().sendFeedback(new LiteralText("Only one player can be selected!"), false);
        return 0;
    }
    try {
        new GraveListGui(player, profiles.get(0)).open();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0;
}
Also used : GameProfileArgumentType(net.minecraft.command.argument.GameProfileArgumentType) GameProfile(com.mojang.authlib.GameProfile) ArrayList(java.util.ArrayList) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) LiteralText(net.minecraft.text.LiteralText)

Example 14 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity in project dynmap by webbukkit.

the class DynmapPlugin method handleCommand.

// TODO: Clean a bit
public void handleCommand(ServerCommandSource commandSource, String cmd, String[] args) throws CommandSyntaxException {
    DynmapCommandSender dsender;
    ServerPlayerEntity psender = null;
    // getPlayer throws a CommandSyntaxException, so getEntity and instanceof for safety
    if (commandSource.getEntity() instanceof ServerPlayerEntity) {
        psender = commandSource.getPlayer();
    }
    if (psender != null) {
        // FIXME: New Player? Why not query the current player list.
        dsender = new FabricPlayer(this, psender);
    } else {
        dsender = new FabricCommandSender(commandSource);
    }
    core.processCommand(dsender, cmd, cmd, args);
}
Also used : DynmapCommandSender(org.dynmap.common.DynmapCommandSender) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 15 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity in project dynmap by webbukkit.

the class FabricPlayer method sendTitleText.

/**
 * Send title and subtitle text (called from server thread)
 */
@Override
public void sendTitleText(String title, String subtitle, int fadeInTicks, int stayTicks, int fadeOutTicks) {
    if (player != null) {
        ServerPlayerEntity player = this.player;
        TitleS2CPacket times = new TitleS2CPacket(fadeInTicks, stayTicks, fadeOutTicks);
        player.networkHandler.sendPacket(times);
        if (title != null) {
            TitleS2CPacket titlepkt = new TitleS2CPacket(TitleS2CPacket.Action.TITLE, new LiteralText(title));
            player.networkHandler.sendPacket(titlepkt);
        }
        if (subtitle != null) {
            TitleS2CPacket subtitlepkt = new TitleS2CPacket(TitleS2CPacket.Action.SUBTITLE, new LiteralText(subtitle));
            player.networkHandler.sendPacket(subtitlepkt);
        }
    }
}
Also used : TitleS2CPacket(net.minecraft.network.packet.s2c.play.TitleS2CPacket) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) LiteralText(net.minecraft.text.LiteralText)

Aggregations

ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)169 LiteralText (net.minecraft.text.LiteralText)51 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)32 ItemStack (net.minecraft.item.ItemStack)23 PlayerEntity (net.minecraft.entity.player.PlayerEntity)19 Entity (net.minecraft.entity.Entity)15 UUID (java.util.UUID)14 LivingEntity (net.minecraft.entity.LivingEntity)14 CommandDispatcher (com.mojang.brigadier.CommandDispatcher)12 TranslatableText (net.minecraft.text.TranslatableText)12 Inject (org.spongepowered.asm.mixin.injection.Inject)12 ServerWorld (net.minecraft.server.world.ServerWorld)11 PacketByteBuf (net.minecraft.network.PacketByteBuf)10 GameProfile (com.mojang.authlib.GameProfile)9 Formatting (net.minecraft.util.Formatting)9 BlockPos (net.minecraft.util.math.BlockPos)9 ArrayList (java.util.ArrayList)8 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)6 Collectors (java.util.stream.Collectors)6 ArmorStandEntity (net.minecraft.entity.decoration.ArmorStandEntity)6