Search in sources :

Example 1 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity in project LuckPerms by lucko.

the class PluginMessageMessenger method sendOutgoingMessage.

@Override
public void sendOutgoingMessage(@NonNull OutgoingMessage outgoingMessage) {
    AtomicReference<SchedulerTask> taskRef = new AtomicReference<>();
    SchedulerTask task = this.plugin.getBootstrap().getScheduler().asyncRepeating(() -> {
        MinecraftServer server = this.plugin.getBootstrap().getServer().orElse(null);
        if (server == null) {
            return;
        }
        Collection<ServerPlayerEntity> players = server.getPlayerManager().getPlayerList();
        ServerPlayerEntity p = Iterables.getFirst(players, null);
        if (p == null) {
            return;
        }
        PacketByteBuf buf = PacketByteBufs.create();
        buf.writeString(outgoingMessage.asEncodedString());
        ServerPlayNetworking.send(p, CHANNEL, buf);
        SchedulerTask t = taskRef.getAndSet(null);
        if (t != null) {
            t.cancel();
        }
    }, 10, TimeUnit.SECONDS);
    taskRef.set(task);
}
Also used : PacketByteBuf(net.minecraft.network.PacketByteBuf) AtomicReference(java.util.concurrent.atomic.AtomicReference) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) SchedulerTask(me.lucko.luckperms.common.plugin.scheduler.SchedulerTask) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 2 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity in project LuckPerms by lucko.

the class FabricSenderFactory method sendMessage.

@Override
protected void sendMessage(ServerCommandSource sender, Component message) {
    Locale locale = null;
    if (sender.getEntity() instanceof ServerPlayerEntity) {
        locale = ((MixinUser) sender.getEntity()).getCachedLocale();
    }
    sender.sendFeedback(toNativeText(TranslationManager.render(message, locale)), false);
}
Also used : Locale(java.util.Locale) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 3 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity in project EnvironmentZ by Globox1997.

the class CommandInit method executeEnvCommand.

private static int executeEnvCommand(ServerCommandSource source, Collection<ServerPlayerEntity> targets, String environment, boolean affected) {
    Iterator<ServerPlayerEntity> var3 = targets.iterator();
    while (var3.hasNext()) {
        ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity) var3.next();
        if (environment.equals("hot"))
            ((PlayerEnvAccess) serverPlayerEntity).setHotEnvAffected(affected);
        if (environment.equals("cold"))
            ((PlayerEnvAccess) serverPlayerEntity).setColdEnvAffected(affected);
        EnvironmentServerPacket.writeS2CSyncEnvPacket(serverPlayerEntity, ((PlayerEnvAccess) serverPlayerEntity).isHotEnvAffected(), ((PlayerEnvAccess) serverPlayerEntity).isColdEnvAffected());
    }
    source.sendFeedback(new TranslatableText("commands.environment.changed"), true);
    return targets.size();
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 4 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity in project nbt-crafting by Siphalor.

the class MixinAnvilContainer method updateResult.

@Inject(method = "updateResult", at = @At("HEAD"), cancellable = true)
public void updateResult(CallbackInfo callbackInfo) {
    recipe = player.world.getRecipeManager().getFirstMatch(NbtCrafting.ANVIL_RECIPE_TYPE, inventory, player.world).orElse(null);
    if (recipe != null) {
        ItemStack resultStack = recipe.craft(inventory);
        repairItemUsage = 1;
        if (userChangedName) {
            if (!StringUtils.isBlank(newItemName) && !newItemName.equals(resultStack.getName().getString())) {
                resultStack.setCustomName(new LiteralText(newItemName));
            }
            userChangedName = false;
        } else {
            newItemName = resultStack.getName().getString();
            if (player instanceof ServerPlayerEntity) {
                if (NbtCrafting.hasClientMod((ServerPlayerEntity) player)) {
                    PacketByteBuf packetByteBuf = new PacketByteBuf(Unpooled.buffer());
                    packetByteBuf.writeString(newItemName);
                    ServerSidePacketRegistry.INSTANCE.sendToPlayer(player, NbtCrafting.UPDATE_ANVIL_TEXT_S2C_PACKET_ID, packetByteBuf);
                }
            }
        }
        result.setInvStack(0, resultStack);
        levelCost.set(recipe.getLevels());
        sendContentUpdates();
        callbackInfo.cancel();
    }
}
Also used : PacketByteBuf(net.minecraft.util.PacketByteBuf) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ItemStack(net.minecraft.item.ItemStack) LiteralText(net.minecraft.text.LiteralText) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity in project MCDoom by AzureDoom.

the class GunTableScreenHandler method close.

public void close(PlayerEntity player) {
    super.close(player);
    if (!this.playerInventory.player.world.isClient) {
        if (player.isAlive() && (!(player instanceof ServerPlayerEntity) || !((ServerPlayerEntity) player).isDisconnected())) {
            player.getInventory().offerOrDrop(this.gunTableInventory.removeStack(0));
            player.getInventory().offerOrDrop(this.gunTableInventory.removeStack(1));
            player.getInventory().offerOrDrop(this.gunTableInventory.removeStack(2));
            player.getInventory().offerOrDrop(this.gunTableInventory.removeStack(3));
            player.getInventory().offerOrDrop(this.gunTableInventory.removeStack(4));
        } else {
            ItemStack itemStack0 = this.gunTableInventory.removeStack(0);
            ItemStack itemStack1 = this.gunTableInventory.removeStack(1);
            ItemStack itemStack2 = this.gunTableInventory.removeStack(2);
            ItemStack itemStack3 = this.gunTableInventory.removeStack(3);
            ItemStack itemStack4 = this.gunTableInventory.removeStack(4);
            if (!itemStack0.isEmpty()) {
                player.dropItem(itemStack0, false);
            }
            if (!itemStack1.isEmpty()) {
                player.dropItem(itemStack1, false);
            }
            if (!itemStack2.isEmpty()) {
                player.dropItem(itemStack2, false);
            }
            if (!itemStack3.isEmpty()) {
                player.dropItem(itemStack3, false);
            }
            if (!itemStack4.isEmpty()) {
                player.dropItem(itemStack4, false);
            }
        }
    }
}
Also used : ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ItemStack(net.minecraft.item.ItemStack)

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