Package org.spout.vanilla.protocol

Examples of org.spout.vanilla.protocol.EntityProtocol


    Transform liveTransform = event.getTransform();
    boolean self = (e == getOwner());
    boolean spawn = event.getAction() == EntityUpdateEvent.UpdateAction.ADD;
    boolean destroy = event.getAction() == EntityUpdateEvent.UpdateAction.REMOVE;
    boolean update = !spawn && !destroy;
    EntityProtocol ep = ((VanillaNetworkProtocol) e.getNetwork()).getEntityProtocol();
    if (ep == null) {
      if (spawn) {
        // For debugging purposes: log all entities with a missing protocol
        // Only do it for spawning - update is called too often
        Spout.getLogger().warning("Failure to spawn entity due to no EntityProtocol. Dropping entity toString...");
        Spout.getLogger().warning(e.toString());
      }
      // Do not send any messages - no protocol to do so
      return;
    }
    if (self && !(ep instanceof PlayerEntityProtocol)) {
      if (spawn) {
        // For debugging purposes: Log all Player entities that can't synchronize to self
        // Only do it for spawning - update is called too often
        Spout.getLogger().warning("Failure to spawn Player entity to self: No PlayerEntityProtocol is used. Dropping entity toString...");
        Spout.getLogger().warning(e.toString());
      }
      // Do not send any messages - no protocol to do so
      return;
    }
    if (self) {
      // Sync using vanilla Player 'self' protocol
      // Note: No messages gathered because all update methods send to the Player
      PlayerEntityProtocol pep = (PlayerEntityProtocol) ep;
      Player player = (Player) e;
      if (destroy) {
        pep.doSelfDestroy(player);
      }
      if (spawn) {
        pep.doSelfSpawn(player, getRepositionManager());
      }
      if (update) {
        boolean force = shouldForce(e.getId());
        pep.doSelfUpdate(player, liveTransform, getRepositionManager(), force);
      }
    } else {
      // Sync using vanilla protocol
      List<Message> messages = new ArrayList<Message>();
      if (destroy) {
        messages.addAll(ep.getDestroyMessages(e));
      }
      if (spawn) {
        messages.addAll(ep.getSpawnMessages(e, getRepositionManager()));
      }
      if (update) {
        boolean force = shouldForce(e.getId());
        messages.addAll(ep.getUpdateMessages(e, liveTransform, getRepositionManager(), force));
      }
      // Send all messages gathered
      for (Message message : messages) {
        getSession().send(message);
      }
View Full Code Here

TOP

Related Classes of org.spout.vanilla.protocol.EntityProtocol

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.