Search in sources :

Example 21 with ServerPlayerEntity

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

the class FabricServer method getOnlinePlayers.

@Override
public DynmapPlayer[] getOnlinePlayers() {
    if (server.getPlayerManager() == null)
        return new DynmapPlayer[0];
    List<ServerPlayerEntity> players = server.getPlayerManager().getPlayerList();
    int playerCount = players.size();
    DynmapPlayer[] dplay = new DynmapPlayer[players.size()];
    for (int i = 0; i < playerCount; i++) {
        ServerPlayerEntity player = players.get(i);
        dplay[i] = plugin.getOrAddPlayer(player);
    }
    return dplay;
}
Also used : ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) DynmapPlayer(org.dynmap.common.DynmapPlayer)

Example 22 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;
        TitleFadeS2CPacket times = new TitleFadeS2CPacket(fadeInTicks, stayTicks, fadeOutTicks);
        player.networkHandler.sendPacket(times);
        if (title != null) {
            TitleS2CPacket titlepkt = new TitleS2CPacket(new LiteralText(title));
            player.networkHandler.sendPacket(titlepkt);
        }
        if (subtitle != null) {
            SubtitleS2CPacket subtitlepkt = new SubtitleS2CPacket(new LiteralText(subtitle));
            player.networkHandler.sendPacket(subtitlepkt);
        }
    }
}
Also used : TitleFadeS2CPacket(net.minecraft.network.packet.s2c.play.TitleFadeS2CPacket) SubtitleS2CPacket(net.minecraft.network.packet.s2c.play.SubtitleS2CPacket) TitleS2CPacket(net.minecraft.network.packet.s2c.play.TitleS2CPacket) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) LiteralText(net.minecraft.text.LiteralText)

Example 23 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity in project BlockMeter by ModProg.

the class BlockMeterServer method buildS2CPacket.

/**
 * Builds a S2CPacket containing the BoxList
 *
 * @return S2CPacket containing the BoxList
 */
private PacketByteBuf buildS2CPacket() {
    PacketByteBuf data = new PacketByteBuf(Unpooled.buffer());
    synchronized (playerBoxes) {
        data.writeInt(playerBoxes.size());
        Set<Map.Entry<UUID, List<MeasureBox>>> knownPlayers = playerBoxes.entrySet();
        for (Map.Entry<UUID, List<MeasureBox>> playerBoxEntry : knownPlayers) {
            ServerPlayerEntity player = server.getPlayerManager().getPlayer(playerBoxEntry.getKey());
            data.writeText(player.getDisplayName());
            data.writeInt(playerBoxEntry.getValue().size());
            for (int i = 0; i < playerBoxEntry.getValue().size(); i++) {
                playerBoxEntry.getValue().get(i).writePacketBuf(data);
            }
        }
    }
    return data;
}
Also used : PacketByteBuf(net.minecraft.network.PacketByteBuf) ArrayList(java.util.ArrayList) List(java.util.List) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) MeasureBox(win.baruna.blockmeter.measurebox.MeasureBox) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity in project FabricWaystones by LordDeatHunter.

the class WaystonesEventManager method registerEvents.

public static void registerEvents() {
    ServerLifecycleEvents.SERVER_STARTED.register((server) -> {
        if (Waystones.WAYSTONE_STORAGE == null) {
            Waystones.WAYSTONE_STORAGE = new WaystoneStorage(server);
        }
    });
    ServerLifecycleEvents.SERVER_STOPPED.register((server) -> {
        Waystones.WAYSTONE_STORAGE.loadOrSaveWaystones(true);
        Waystones.WAYSTONE_STORAGE = null;
    });
    ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
        PacketByteBuf data = PacketByteBufs.create();
        data.writeNbt(Config.getInstance().toNbtCompound());
        ServerPlayNetworking.send(handler.player, Utils.ID("waystone_config_update"), data);
        Waystones.WAYSTONE_STORAGE.sendToPlayer(handler.player);
        Waystones.WAYSTONE_STORAGE.sendCompatData(handler.player);
    });
    ServerLifecycleEvents.SERVER_STARTING.register(WaystonesWorldgen::registerVanillaVillageWorldgen);
    ServerPlayerEvents.AFTER_RESPAWN.register((oldPlayer, newPlayer, alive) -> ((PlayerEntityMixinAccess) newPlayer).syncData());
    CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(CommandManager.literal("waystones").then(CommandManager.literal("reload").requires(source -> source.hasPermissionLevel(1)).executes(context -> {
        Config.getInstance().loadConfig();
        PacketByteBuf data = PacketByteBufs.create();
        data.writeNbt(Config.getInstance().toNbtCompound());
        for (ServerPlayerEntity player : context.getSource().getServer().getPlayerManager().getPlayerList()) {
            ServerPlayNetworking.send(player, Utils.ID("waystone_config_update"), data);
        }
        ServerPlayerEntity player = context.getSource().getPlayer();
        if (player != null) {
            player.sendMessage(new LiteralText("§6[§eWaystones§6] §3has successfully reloaded!"), false);
        }
        return 1;
    })).then(CommandManager.literal("display").executes(context -> {
        ServerPlayerEntity player = context.getSource().getPlayer();
        if (player == null) {
            return 1;
        }
        Config.getInstance().print(player);
        return 1;
    }))));
}
Also used : LiteralText(net.minecraft.text.LiteralText) Waystones(wraith.waystones.Waystones) PlayerEntityMixinAccess(wraith.waystones.access.PlayerEntityMixinAccess) ServerPlayConnectionEvents(net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerPlayerEvents(net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents) CommandRegistrationCallback(net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback) ServerPlayNetworking(net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking) PacketByteBuf(net.minecraft.network.PacketByteBuf) ServerLifecycleEvents(net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents) PacketByteBufs(net.fabricmc.fabric.api.networking.v1.PacketByteBufs) CommandManager(net.minecraft.server.command.CommandManager) PacketByteBuf(net.minecraft.network.PacketByteBuf) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) LiteralText(net.minecraft.text.LiteralText)

Example 25 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity in project FallingAttackFabric by hamusuke0323.

the class FallingAttackShockWave method damage.

private void damage(Entity target, float damageModifier) {
    if (target.isAttackable()) {
        if (!target.handleAttack(this.owner)) {
            float damageAmount = (float) this.owner.getAttributeValue(EntityAttributes.GENERIC_ATTACK_DAMAGE);
            float attackDamage;
            if (target instanceof LivingEntity) {
                attackDamage = EnchantmentHelper.getAttackDamage(this.sword, ((LivingEntity) target).getGroup());
            } else {
                attackDamage = EnchantmentHelper.getAttackDamage(this.sword, EntityGroup.DEFAULT);
            }
            if (damageAmount > 0.0F || attackDamage > 0.0F) {
                float distanceToTarget = (float) this.pos.distanceTo(target.getPos());
                int fallingAttackLevel = EnchantmentHelper.getLevel(FallingAttack.SHARPNESS_OF_FALLING_ATTACK, this.sword) + 1;
                fallingAttackLevel = MathHelper.clamp(fallingAttackLevel, 1, 255);
                attackDamage += this.fallingAttackDamageComputer.apply(distanceToTarget, fallingAttackLevel);
                this.world.playSound(null, this.owner.getX(), this.owner.getY(), this.owner.getZ(), SoundEvents.ENTITY_PLAYER_ATTACK_KNOCKBACK, this.owner.getSoundCategory(), 1.0F, 1.0F);
                boolean bl3 = !this.owner.isClimbing() && !this.owner.isTouchingWater() && !this.owner.hasStatusEffect(StatusEffects.BLINDNESS) && !this.owner.hasVehicle() && target instanceof LivingEntity;
                if (bl3) {
                    damageAmount *= 1.5F;
                }
                damageAmount += attackDamage;
                float targetHealth = 0.0F;
                boolean fireAspectEnchanted = false;
                int fireAspectLevel = EnchantmentHelper.getLevel(Enchantments.FIRE_ASPECT, this.sword);
                if (target instanceof LivingEntity) {
                    targetHealth = ((LivingEntity) target).getHealth();
                    if (fireAspectLevel > 0 && !target.isOnFire()) {
                        fireAspectEnchanted = true;
                        target.setOnFireFor(1);
                    }
                }
                Vec3d vec3d = target.getVelocity();
                boolean tookDamage = target.damage(DamageSource.player(this.owner), damageAmount * damageModifier);
                if (tookDamage) {
                    float yaw = (float) -MathHelper.atan2(target.getX() - this.pos.getX(), target.getZ() - this.pos.getZ());
                    float strength = this.knockbackStrengthComputer.apply(distanceToTarget, fallingAttackLevel);
                    if (target instanceof LivingEntity) {
                        ((LivingEntity) target).takeKnockback(strength, MathHelper.sin(yaw), -MathHelper.cos(yaw));
                    } else {
                        target.addVelocity(-MathHelper.sin(yaw) * strength, 0.1D, MathHelper.cos(yaw) * strength);
                    }
                    this.owner.setVelocity(this.owner.getVelocity().multiply(0.6D, 1.0D, 0.6D));
                    this.owner.setSprinting(false);
                    if (target instanceof ServerPlayerEntity && target.velocityModified) {
                        ((ServerPlayerEntity) target).networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(target));
                        target.velocityModified = false;
                        target.setVelocity(vec3d);
                    }
                    if (bl3) {
                        this.world.playSound(null, this.owner.getX(), this.owner.getY(), this.owner.getZ(), SoundEvents.ENTITY_PLAYER_ATTACK_CRIT, this.owner.getSoundCategory(), 1.0F, 1.0F);
                        this.owner.addCritParticles(target);
                    }
                    if (attackDamage > 0.0F) {
                        this.owner.addEnchantedHitParticles(target);
                    }
                    this.owner.onAttacking(target);
                    if (target instanceof LivingEntity) {
                        float n = targetHealth - ((LivingEntity) target).getHealth();
                        this.owner.increaseStat(Stats.DAMAGE_DEALT, Math.round(n * 10.0F));
                        if (fireAspectLevel > 0) {
                            target.setOnFireFor(fireAspectLevel * 4);
                        }
                        if (n > 2.0F) {
                            int o = (int) ((double) n * 0.5D);
                            this.world.spawnParticles(ParticleTypes.DAMAGE_INDICATOR, target.getX(), target.getBodyY(0.5D), target.getZ(), o, 0.1D, 0.0D, 0.1D, 0.2D);
                        }
                    }
                } else {
                    this.world.playSound(null, this.owner.getX(), this.owner.getY(), this.owner.getZ(), SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, this.owner.getSoundCategory(), 1.0F, 1.0F);
                    if (fireAspectEnchanted) {
                        target.extinguish();
                    }
                }
            }
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Vec3d(net.minecraft.util.math.Vec3d) EntityVelocityUpdateS2CPacket(net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket)

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