Package com.bergerkiller.bukkit.common.wrappers

Examples of com.bergerkiller.bukkit.common.wrappers.EntityTracker


  @SuppressWarnings({"rawtypes", "unchecked"})
  public void setNetworkController(EntityNetworkController controller) {
    if (getWorld() == null) {
      throw new RuntimeException("Can not set the network controller when no world is known! (need to spawn it?)");
    }
    final EntityTracker tracker = WorldUtil.getTracker(getWorld());
    final Object storedEntry = tracker.getEntry(entity);

    // Properly handle a previously set controller
    if (storedEntry instanceof NMSEntityTrackerEntry) {
      final EntityNetworkController oldController = ((NMSEntityTrackerEntry) storedEntry).getController();
      if (oldController == controller) {
        return;
      } else if (oldController != null) {
        oldController.onDetached();
      }
    }

    // Take care of null controllers - stop tracking
    if (controller == null) {
      tracker.stopTracking(entity);
      return;
    }

    final Object newEntry;
    if (controller instanceof DefaultEntityNetworkController) {
      // Assign the default Entity Tracker Entry
      if (EntityTrackerEntryRef.TEMPLATE.isType(storedEntry)) {
        // Nothing to be done here
        newEntry = storedEntry;
      } else {
        // Create a new entry
        final CommonEntityType type = CommonEntityType.byEntity(entity);
        newEntry = new EntityTrackerEntry(getHandle(Entity.class), type.networkViewDistance, type.networkUpdateInterval, type.networkIsMobile);
        // Transfer data if needed
        if (storedEntry != null) {
          EntityTrackerEntryRef.TEMPLATE.transfer(storedEntry, newEntry);
        }
      }
    } else if (controller instanceof ExternalEntityNetworkController) {
      // Use the entry as stored by the external network controller
      newEntry = controller.getHandle();
      // Be sure to refresh stats using the old entry
      if (storedEntry != null && newEntry != null) {
        EntityTrackerEntryRef.TEMPLATE.transfer(storedEntry, newEntry);
      }
    } else {
      // Assign a new Entity Tracker Entry with controller capabilities
      if (storedEntry instanceof NMSEntityTrackerEntry) {
        // Use the previous entry - hotswap the controller
        newEntry = storedEntry;
        EntityTrackerEntryRef.viewers.get(newEntry).clear();
      } else {
        // Create a new entry from scratch
        newEntry = new NMSEntityTrackerEntry(this.getEntity());
        // Transfer possible information over
        if (storedEntry != null) {
          EntityTrackerEntryRef.TEMPLATE.transfer(storedEntry, newEntry);
        }
      }
    }

    // Attach the entry to the controller
    controller.bind(this, newEntry);

    // Attach (new?) entry to the world
    if (storedEntry != newEntry) {
      tracker.setEntry(entity, newEntry);

      // Make sure to update the viewers
      EntityTrackerEntryRef.scanPlayers(newEntry, getWorld().getPlayers());
    }
  }
View Full Code Here


        });
      }
      entitiesById.put(newInstance.getId(), newInstance);

      // *** EntityTrackerEntry ***
      final EntityTracker tracker = WorldUtil.getTracker(getWorld());
      Object entry = tracker.getEntry(entity);
      if (entry != null) {
        EntityTrackerEntryRef.tracker.set(entry, entity);
      }
      if (hasPassenger()) {
        entry = tracker.getEntry(getPassenger());
        if (entry != null) {
          EntityTrackerEntryRef.vehicle.set(entry, entity);
        }
      }

View Full Code Here

    // Perform actual teleportation
    final boolean succ;
    if (!isWorldChange || entity instanceof Player) {
      // First: stop tracking the entity
      final EntityTracker tracker = WorldUtil.getTracker(getWorld());
      tracker.stopTracking(entity);

      // Destroy packets are queued: Make sure to send them RIGHT NOW
      for (Player bukkitPlayer : WorldUtil.getPlayers(getWorld())) {
        CommonPlayer player = get(bukkitPlayer);
        if (player != null) {
          player.flushEntityRemoveQueue();
        }
      }

      // Teleport
      succ = entity.teleport(location, cause);

      // Start tracking the entity again
      if (!hasNetworkController && !isWorldChange) {
        tracker.startTracking(entity);
      }
    } else {
      // Remove from one world and add to the other
      entityHandle.world.removeEntity(entityHandle);
      entityHandle.dead = false;
View Full Code Here

TOP

Related Classes of com.bergerkiller.bukkit.common.wrappers.EntityTracker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.