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