Search in sources :

Example 66 with ServerPlayer

use of net.minecraft.server.level.ServerPlayer in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelperImpl method sendShowPacket.

@Override
public void sendShowPacket(Player pl, Entity entity) {
    if (entity instanceof Player) {
        pl.showPlayer(Denizen.getInstance(), (Player) entity);
        return;
    }
    CraftPlayer craftPlayer = (CraftPlayer) pl;
    ServerPlayer entityPlayer = craftPlayer.getHandle();
    if (entityPlayer.connection != null && !craftPlayer.equals(entity)) {
        ChunkMap tracker = ((ServerLevel) craftPlayer.getHandle().level).getChunkSource().chunkMap;
        net.minecraft.world.entity.Entity other = ((CraftEntity) entity).getHandle();
        ChunkMap.TrackedEntity entry = tracker.entityMap.get(other.getId());
        if (entry != null) {
            entry.removePlayer(entityPlayer);
            entry.updatePlayer(entityPlayer);
        }
    }
}
Also used : ServerPlayer(net.minecraft.server.level.ServerPlayer) ChunkMap(net.minecraft.server.level.ChunkMap) ServerPlayer(net.minecraft.server.level.ServerPlayer) org.bukkit.entity(org.bukkit.entity) org.bukkit.craftbukkit.v1_18_R1.entity(org.bukkit.craftbukkit.v1_18_R1.entity) net.minecraft.world.entity(net.minecraft.world.entity)

Example 67 with ServerPlayer

use of net.minecraft.server.level.ServerPlayer in project Denizen-For-Bukkit by DenizenScript.

the class AdvancementHelperImpl method update.

@Override
public void update(Player player) {
    ServerPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
    nmsPlayer.connection.send(new ClientboundUpdateAdvancementsPacket(true, Collections.emptySet(), Collections.emptySet(), Collections.emptyMap()));
    PlayerAdvancements data = nmsPlayer.getAdvancements();
    // save progress
    data.save();
    // clear progress
    data.reload(DedicatedServer.getServer().getAdvancements());
    // load progress and update client
    data.flushDirty(nmsPlayer);
}
Also used : ClientboundUpdateAdvancementsPacket(net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket) PlayerAdvancements(net.minecraft.server.PlayerAdvancements) ServerPlayer(net.minecraft.server.level.ServerPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)

Example 68 with ServerPlayer

use of net.minecraft.server.level.ServerPlayer in project Tropicraft by Tropicraft.

the class SharkEntity method tick.

@Override
public void tick() {
    super.tick();
    if (isBoss()) {
        // Set state to boss
        if (!hasSetBoss) {
            setBossTraits();
        }
        if (!level.isClientSide) {
            // Search for suitable target
            Player nearest = level.getNearestPlayer(this, 64D);
            if (nearest != null) {
                if (hasLineOfSight(nearest) && nearest.isInWater() && !nearest.isCreative() && nearest.isAlive()) {
                    aggressTarget = nearest;
                    setTargetHeading(aggressTarget.getX(), aggressTarget.getY() + 1, aggressTarget.getZ(), true);
                    // Show health bar to target player
                    if (nearest instanceof ServerPlayer) {
                        if (!bossInfo.getPlayers().contains(nearest)) {
                            bossTargets.add((ServerPlayer) nearest);
                            bossInfo.addPlayer((ServerPlayer) nearest);
                        }
                    }
                } else {
                    clearBossTargets();
                }
            } else {
                clearBossTargets();
            }
            // Heal if no target
            if (this.getHealth() < this.getMaxHealth() && this.tickCount % 80 == 0 && this.aggressTarget == null) {
                this.heal(1f);
                this.spawnAnim();
            }
            // Update health bar
            this.bossInfo.setProgress(this.rangeMap(this.getHealth(), 0, this.getMaxHealth(), 0, 1));
        }
    }
}
Also used : ServerPlayer(net.minecraft.server.level.ServerPlayer) Player(net.minecraft.world.entity.player.Player) ServerPlayer(net.minecraft.server.level.ServerPlayer)

Example 69 with ServerPlayer

use of net.minecraft.server.level.ServerPlayer in project MC-Prefab by Brian-Wuest.

the class HouseConfiguration method ConfigurationSpecificBuildStructure.

/**
 * This is used to actually build the structure as it creates the structure instance and calls build structure.
 *
 * @param player      The player which requested the build.
 * @param world       The world instance where the build will occur.
 * @param hitBlockPos This hit block position.
 */
@Override
protected void ConfigurationSpecificBuildStructure(Player player, ServerLevel world, BlockPos hitBlockPos) {
    boolean houseBuilt = true;
    // Build the alternate starter house instead.
    StructureAlternateStart structure = StructureAlternateStart.CreateInstance(this.houseStyle.getStructureLocation(), StructureAlternateStart.class);
    houseBuilt = structure.BuildStructure(this, world, hitBlockPos, player);
    // The house was successfully built, remove the item from the inventory.
    if (houseBuilt) {
        EntityPlayerConfiguration playerConfig = EntityPlayerConfiguration.loadFromEntityData(player);
        playerConfig.builtStarterHouse = true;
        playerConfig.saveToPlayer(player);
        this.RemoveStructureItemFromPlayer(player, ModRegistry.StartHouse.get());
        // Make sure to send a message to the client to sync up the server player information and the client player
        // information.
        Prefab.network.sendTo(new PlayerEntityTagMessage(playerConfig.getModIsPlayerNewTag(player)), ((ServerPlayer) player).connection.connection, NetworkDirection.PLAY_TO_CLIENT);
    }
}
Also used : StructureAlternateStart(com.wuest.prefab.structures.predefined.StructureAlternateStart) PlayerEntityTagMessage(com.wuest.prefab.proxy.messages.PlayerEntityTagMessage) EntityPlayerConfiguration(com.wuest.prefab.config.EntityPlayerConfiguration) ServerPlayer(net.minecraft.server.level.ServerPlayer)

Example 70 with ServerPlayer

use of net.minecraft.server.level.ServerPlayer in project MC-Prefab by Brian-Wuest.

the class ModEventHandler method onPlayerLoginEvent.

/**
 * This event occurs when a player logs in. This is used to send server configuration to the client.
 *
 * @param event The event object.
 */
@SubscribeEvent
public static void onPlayerLoginEvent(PlayerLoggedInEvent event) {
    if (!event.getPlayer().level.isClientSide) {
        CompoundTag tag = CommonProxy.proxyConfiguration.serverConfiguration.ToNBTTagCompound();
        Prefab.network.sendTo(new ConfigSyncMessage(tag), ((ServerPlayer) event.getPlayer()).connection.connection, NetworkDirection.PLAY_TO_CLIENT);
        Prefab.LOGGER.info("Sent config to '" + event.getPlayer().getDisplayName().getString() + "'.");
    }
}
Also used : ConfigSyncMessage(com.wuest.prefab.proxy.messages.ConfigSyncMessage) ServerPlayer(net.minecraft.server.level.ServerPlayer) CompoundTag(net.minecraft.nbt.CompoundTag) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

ServerPlayer (net.minecraft.server.level.ServerPlayer)71 TamableAnimal (net.minecraft.world.entity.TamableAnimal)12 Behavior (de.Keyle.MyPet.api.skill.skills.Behavior)11 ServerLevel (net.minecraft.server.level.ServerLevel)11 ArmorStand (net.minecraft.world.entity.decoration.ArmorStand)11 ItemStack (net.minecraft.world.item.ItemStack)10 CraftPlayer (org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)10 Player (org.bukkit.entity.Player)10 MyPet (de.Keyle.MyPet.api.entity.MyPet)8 EntityMyPet (de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet)8 CraftPlayer (org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)8 Player (net.minecraft.world.entity.player.Player)7 EntityMyPet (de.Keyle.MyPet.compat.v1_18_R1.entity.EntityMyPet)6 ArrayList (java.util.ArrayList)6 ClientboundRemoveEntitiesPacket (net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket)6 ChunkMap (net.minecraft.server.level.ChunkMap)6 ServerGamePacketListenerImpl (net.minecraft.server.network.ServerGamePacketListenerImpl)6 LivingEntity (net.minecraft.world.entity.LivingEntity)6 ItemEntity (net.minecraft.world.entity.item.ItemEntity)6 PlayerEntityTagMessage (com.wuest.prefab.proxy.messages.PlayerEntityTagMessage)5