Search in sources :

Example 6 with ChunkMap

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

the class EntityHelperImpl method setTrackingRange.

@Override
public void setTrackingRange(Entity entity, int range) {
    try {
        ChunkMap map = ((CraftWorld) entity.getWorld()).getHandle().getChunkProvider().chunkMap;
        ChunkMap.TrackedEntity entry = map.G.get(entity.getEntityId());
        TRACKING_RANGE_SETTER.invoke(entry, range);
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
}
Also used : ChunkMap(net.minecraft.server.level.ChunkMap) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld)

Example 7 with ChunkMap

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

the class PacketHelperImpl method sendRename.

@Override
public void sendRename(Player player, Entity entity, String name, boolean listMode) {
    try {
        if (entity.getType() == EntityType.PLAYER) {
            if (listMode) {
                send(player, new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.UPDATE_DISPLAY_NAME, ((CraftPlayer) player).getHandle()));
            } else {
                // For player entities, force a respawn packet and let the dynamic intercept correct the details
                ChunkMap tracker = ((ServerLevel) ((CraftEntity) entity).getHandle().level).getChunkProvider().chunkMap;
                ChunkMap.TrackedEntity entityTracker = tracker.G.get(entity.getEntityId());
                if (entityTracker != null) {
                    try {
                        ServerEntity entry = (ServerEntity) ENTITY_TRACKER_ENTRY_GETTER.get(entityTracker);
                        if (entry != null) {
                            entry.removePairing(((CraftPlayer) player).getHandle());
                            entry.addPairing(((CraftPlayer) player).getHandle());
                        }
                    } catch (Throwable ex) {
                        Debug.echoError(ex);
                    }
                }
            }
            return;
        }
        SynchedEntityData fakeData = new SynchedEntityData(((CraftEntity) entity).getHandle());
        ClientboundSetEntityDataPacket packet = new ClientboundSetEntityDataPacket(entity.getEntityId(), fakeData, false);
        List<SynchedEntityData.DataItem<?>> list = new ArrayList<>();
        list.add(new SynchedEntityData.DataItem<>(ENTITY_CUSTOM_NAME_METADATA, Optional.of(Handler.componentToNMS(FormattedTextHelper.parse(name, ChatColor.WHITE)))));
        list.add(new SynchedEntityData.DataItem<>(ENTITY_CUSTOM_NAME_VISIBLE_METADATA, true));
        ENTITY_METADATA_LIST_SETTER.invoke(packet, list);
        send(player, packet);
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
}
Also used : ChunkMap(net.minecraft.server.level.ChunkMap) ServerEntity(net.minecraft.server.level.ServerEntity) SynchedEntityData(net.minecraft.network.syncher.SynchedEntityData) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)

Example 8 with ChunkMap

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

the class PacketHelperImpl method sendRename.

@Override
public void sendRename(Player player, Entity entity, String name, boolean listMode) {
    try {
        if (entity.getType() == EntityType.PLAYER) {
            if (listMode) {
                send(player, new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.UPDATE_DISPLAY_NAME, ((CraftPlayer) player).getHandle()));
            } else {
                // For player entities, force a respawn packet and let the dynamic intercept correct the details
                ChunkMap tracker = ((ServerLevel) ((CraftEntity) entity).getHandle().level).getChunkSource().chunkMap;
                ChunkMap.TrackedEntity entityTracker = tracker.entityMap.get(entity.getEntityId());
                if (entityTracker != null) {
                    try {
                        ServerEntity entry = (ServerEntity) ENTITY_TRACKER_ENTRY_GETTER.get(entityTracker);
                        if (entry != null) {
                            entry.removePairing(((CraftPlayer) player).getHandle());
                            entry.addPairing(((CraftPlayer) player).getHandle());
                        }
                    } catch (Throwable ex) {
                        Debug.echoError(ex);
                    }
                }
            }
            return;
        }
        SynchedEntityData fakeData = new SynchedEntityData(((CraftEntity) entity).getHandle());
        ClientboundSetEntityDataPacket packet = new ClientboundSetEntityDataPacket(entity.getEntityId(), fakeData, false);
        List<SynchedEntityData.DataItem<?>> list = new ArrayList<>();
        list.add(new SynchedEntityData.DataItem<>(ENTITY_CUSTOM_NAME_METADATA, Optional.of(Handler.componentToNMS(FormattedTextHelper.parse(name, ChatColor.WHITE)))));
        list.add(new SynchedEntityData.DataItem<>(ENTITY_CUSTOM_NAME_VISIBLE_METADATA, true));
        ENTITY_METADATA_LIST_SETTER.invoke(packet, list);
        send(player, packet);
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
}
Also used : ChunkMap(net.minecraft.server.level.ChunkMap) ServerEntity(net.minecraft.server.level.ServerEntity) SynchedEntityData(net.minecraft.network.syncher.SynchedEntityData) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)

Example 9 with ChunkMap

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

the class EntityHelperImpl method setTrackingRange.

@Override
public void setTrackingRange(Entity entity, int range) {
    try {
        ChunkMap map = ((CraftWorld) entity.getWorld()).getHandle().getChunkSource().chunkMap;
        ChunkMap.TrackedEntity entry = map.entityMap.get(entity.getEntityId());
        TRACKING_RANGE_SETTER.invoke(entry, range);
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
}
Also used : ChunkMap(net.minecraft.server.level.ChunkMap) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Example 10 with ChunkMap

use of net.minecraft.server.level.ChunkMap 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)

Aggregations

ChunkMap (net.minecraft.server.level.ChunkMap)10 ServerPlayer (net.minecraft.server.level.ServerPlayer)6 net.minecraft.world.entity (net.minecraft.world.entity)4 org.bukkit.entity (org.bukkit.entity)4 ClientboundRemoveEntitiesPacket (net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket)2 SynchedEntityData (net.minecraft.network.syncher.SynchedEntityData)2 ServerEntity (net.minecraft.server.level.ServerEntity)2 ServerPlayerConnection (net.minecraft.server.network.ServerPlayerConnection)2 org.bukkit.craftbukkit.v1_17_R1.entity (org.bukkit.craftbukkit.v1_17_R1.entity)2 org.bukkit.craftbukkit.v1_18_R1.entity (org.bukkit.craftbukkit.v1_18_R1.entity)2 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)1 CraftPlayer (org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)1 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)1 CraftPlayer (org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)1