Search in sources :

Example 6 with EntityTrackerEntryHandle

use of com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle in project BKCommonLib by bergerhealer.

the class EntityTrackerEntryHook_1_8_to_1_13_2 method hideForAll.

@HookMethod("public void hideForAll:???()")
public void hideForAll() {
    try {
        controller.makeHiddenForAll();
        // This is usually only called when the entity tracker entry is removed from the mapping
        // Detect that it is, and if it is, call onDetached() on the network controller
        CommonEntity<?> entity = controller.getEntity();
        if (entity != null) {
            World world = entity.getWorld();
            EntityTrackerEntryHandle eh = EntityTrackerEntryHandle.createHandle(instance());
            if (world != null && !WorldUtil.getTracker(world).containsEntry(eh)) {
                controller.bind(null, null);
            }
        }
    } catch (Throwable t) {
        Logging.LOGGER_NETWORK.log(Level.SEVERE, "Failed to hide for all viewers", t);
    }
}
Also used : EntityTrackerEntryHandle(com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle) World(org.bukkit.World)

Example 7 with EntityTrackerEntryHandle

use of com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle in project BKCommonLib by bergerhealer.

the class EntityAddRemoveHandler_1_8_to_1_13_2 method replaceInEntityTracker.

private static void replaceInEntityTracker(int entityId, EntityHandle newInstance) {
    final EntityTracker trackerMap = WorldUtil.getTracker(newInstance.getWorld().getWorld());
    EntityTrackerEntryHandle entry = trackerMap.getEntry(entityId);
    if (entry != null) {
        EntityHandle tracker = entry.getState().getEntity();
        if (tracker != null && tracker.getId() == newInstance.getId()) {
            entry.setEntity(newInstance);
        }
        List<EntityHandle> passengers = new ArrayList<EntityHandle>(tracker.getPassengers());
        replaceInList(passengers, newInstance);
        tracker.setPassengers(passengers);
    }
}
Also used : EntityTrackerEntryHandle(com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle) EntityTracker(com.bergerkiller.bukkit.common.wrappers.EntityTracker) ArrayList(java.util.ArrayList) EntityHandle(com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle)

Example 8 with EntityTrackerEntryHandle

use of com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle in project BKCommonLib by bergerhealer.

the class EntityAddRemoveHandler_1_14_to_1_16_5 method replaceInEntityTracker.

@SuppressWarnings("unchecked")
private static void replaceInEntityTracker(EntityHandle entity, EntityHandle oldEntity, EntityHandle newEntity) {
    final EntityTracker trackerMap = WorldUtil.getTracker(newEntity.getBukkitWorld());
    EntityTrackerEntryHandle entry = trackerMap.getEntry(entity.getIdField());
    if (entry != null) {
        // PlayerChunkMap$EntityTracker entity
        EntityHandle entryEntity = entry.getEntity();
        if (entryEntity != null && entryEntity.getIdField() == oldEntity.getIdField()) {
            entry.setEntity(newEntity);
        }
        // EntityTrackerEntry 'tracker' entity
        EntityTrackerEntryStateHandle stateHandle = entry.getState();
        EntityHandle stateEntity = stateHandle.getEntity();
        if (stateEntity != null && stateEntity.getIdField() == oldEntity.getIdField() && stateEntity.getRaw() != newEntity.getRaw()) {
            stateHandle.setEntity(newEntity);
        }
        // EntityTrackerEntry List of passengers
        List<Object> statePassengers = (List<Object>) EntityTrackerEntryStateHandle.T.opt_passengers.raw.get(stateHandle.getRaw());
        replaceInList(statePassengers, oldEntity, newEntity);
    }
}
Also used : EntityTrackerEntryHandle(com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle) EntityTrackerEntryStateHandle(com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryStateHandle) EntityTracker(com.bergerkiller.bukkit.common.wrappers.EntityTracker) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) EntityHandle(com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle)

Example 9 with EntityTrackerEntryHandle

use of com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle in project BKCommonLib by bergerhealer.

the class PacketUtil method broadcastEntityPacket.

/**
 * Sends a packet relating a certain entity to all players that can see it
 *
 * @param entity the packet is about
 * @param packet to send
 * @param sendToSelf whether to also send to the player itself, if the entity is a player
 */
public static void broadcastEntityPacket(Entity entity, CommonPacket packet, boolean sendToSelf) {
    if (entity == null || packet == null)
        return;
    EntityTracker tracker = WorldUtil.getTracker(entity.getWorld());
    EntityTrackerEntryHandle entry = tracker.getEntry(entity);
    if (entry != null) {
        for (Player viewer : entry.getViewers()) {
            sendPacket(viewer, packet);
        }
    }
    if (sendToSelf && entity instanceof Player) {
        sendPacket((Player) entity, packet);
    }
}
Also used : EntityTrackerEntryHandle(com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle) Player(org.bukkit.entity.Player) EntityTracker(com.bergerkiller.bukkit.common.wrappers.EntityTracker)

Example 10 with EntityTrackerEntryHandle

use of com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle in project BKCommonLib by bergerhealer.

the class ItemFrameInfo method updateViewers.

/**
 * Synchronizes the viewers that view this item frame.
 * For every viewer that is added or removed, the synchronizer callbacks are called.
 *
 * @param viewerSynchronizer Synchronizer to call callbacks of
 */
public void updateViewers(LogicUtil.ItemSynchronizer<Player, Player> viewerSynchronizer) {
    // Update list of players for item frames showing maps
    if (lastMapUUID != null) {
        if (entityTrackerEntryState == null) {
            EntityTrackerEntryHandle entry = WorldUtil.getTracker(itemFrame.getWorld()).getEntry(itemFrame);
            // Item Frame isn't tracked on the server, so no players can view it
            if (entry == null) {
                this.removed = true;
                this.needsItemRefresh.set(false);
                return;
            }
            entityTrackerEntryState = entry.getState();
            entityTrackerViewers = entry.getViewers();
        }
        boolean changes = LogicUtil.synchronizeUnordered(viewers, entityTrackerViewers, viewerSynchronizer);
        if (changes && displayInfo != null) {
            displayInfo.hasFrameViewerChanges.set(true);
        }
        // Only do this for non-vanilla maps
        if (!lastMapUUID.isStaticUUID()) {
            entityTrackerEntryState.setTickCounter(1);
        }
    }
}
Also used : EntityTrackerEntryHandle(com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle)

Aggregations

EntityTrackerEntryHandle (com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryHandle)11 EntityTracker (com.bergerkiller.bukkit.common.wrappers.EntityTracker)5 EntityHandle (com.bergerkiller.generated.net.minecraft.world.entity.EntityHandle)4 ArrayList (java.util.ArrayList)4 Entity (org.bukkit.entity.Entity)3 ExtendedEntity (com.bergerkiller.bukkit.common.bases.ExtendedEntity)2 CommonPacket (com.bergerkiller.bukkit.common.protocol.CommonPacket)2 EntityTrackerEntryStateHandle (com.bergerkiller.generated.net.minecraft.server.level.EntityTrackerEntryStateHandle)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 World (org.bukkit.World)2 CommonPlayer (com.bergerkiller.bukkit.common.entity.type.CommonPlayer)1 EntityTrackerEntryHook (com.bergerkiller.bukkit.common.internal.hooks.EntityTrackerEntryHook)1 org.bukkit.entity (org.bukkit.entity)1 Player (org.bukkit.entity.Player)1