コード例 #1
0
  @Override
  public void handle(Session session, Player player, PingMessage message) {
    if (!(player.getEntity().getController() instanceof VanillaPlayer)) {
      return;
    }

    VanillaPlayer mp = (VanillaPlayer) player.getEntity().getController();
    mp.resetTimeoutTicks();
  }
コード例 #2
0
 /** Flush any changes. This is called at the end. */
 @Override
 public void flushChanges() {
   if (items != null) {
     Inventory inv = player.getEntity().getInventory();
     for (int i = 0; i < items.length && i < player.getEntity().getInventorySize(); ++i) {
       inv.setItem(items[i], i);
     }
     items = null;
   }
 }
コード例 #3
0
ファイル: VanillaSky.java プロジェクト: TomyLobo/Vanilla
 public void broadcastMessage(Message message) {
   for (Player player : world.getPlayers()) {
     if (!player.isOnline()) {
       continue;
     }
     if (!player.getEntity().getWorld().getName().equals(world.getName())) {
       continue;
     }
     player.getSession().send(message);
   }
 }
コード例 #4
0
  public void run() {
    if (player.isOnline()) {
      // Inform the new player of existing players
      for (Player p : Spout.getGame().getOnlinePlayers()) {
        if (!p.equals(player)) {
          Point playerPoint = p.getEntity().getLiveTransform().getPosition();
          float playerPitch = p.getEntity().getLiveTransform().getRotation().getAxisAngles().getZ();
          float playerYaw = p.getEntity().getLiveTransform().getRotation().getAxisAngles().getY();

          /*player.getSession().send(
          new SpawnPlayerMessage(p.getEntity().getId(), p.getName(), (int)(playerPoint.getX() * 32),
          (int)(playerPoint.getY() * 32), (int)(playerPoint.getZ() * 32),
          (int)(playerYaw  * 256.0F / 360.0F), (int)(playerPitch * 256.0F / 360.0F), 0));*/
        }
      }
    }
  }
コード例 #5
0
  @Override
  public void onTick(float dt) {
    Controller cont = controllerLive.get();
    // Pulse all player messages here, so they can interact with the entities position safely
    if (cont instanceof PlayerController) {
      Player player = ((PlayerController) cont).getPlayer();
      if (player != null && player.getSession() != null) {
        ((SpoutSession) player.getSession()).pulse();
      }
    }

    // Tick the controller
    if (cont != null) {
      // Sanity check
      if (cont.getParent() != this) {
        if (Spout.debugMode()) {
          throw new IllegalStateException("Controller parent does not match entity");
        } else {
          cont.attachToEntity(this);
        }
      }
      // If this is the first tick, we need to attach the controller
      // Controller is attached here instead of inside of the constructor
      // because the constructor can not access getChunk if the entity is being deserialized
      if (!attached) {
        cont.onAttached();
        attached = true;
      }
      cont.onTick(dt);
    }

    // Copy values last (position may change during controller or session pulses)
    if (!isDead()
        && this.transform.getPosition() != null
        && this.transform.getPosition().getWorld() != null) {
      // Note: if the chunk is null, this effectively kills the entity (since dead: {chunkLive.get()
      // == null})
      chunkLive.set(
          transform.getPosition().getWorld().getChunkFromBlock(transform.getPosition(), false));

      entityManagerLive.set(((SpoutRegion) getRegion()).getEntityManager());
      lastTransform = transform.copy();
    }
  }
コード例 #6
0
  @Override
  public void handleServer(Session session, Player player, PlayerInputMessage message) {
    PlayerInputState input = player.input();
    if (message.isFwd()) {
      input.setForward(1);
    } else if (message.isBack()) {
      input.setForward(-1);
    } else {
      input.setForward(0);
    }

    if (message.isLeft()) {
      input.setHorizantal(1);
    } else if (message.isRight()) {
      input.setHorizantal(-1);
    } else {
      input.setHorizantal(0);
    }

    input.setLookX(message.getMouseDx());
    input.setLookY(message.getMouseDy());
  }
コード例 #7
0
 public VanillaNetworkSynchronizer(Player player, Entity entity) {
   super(player, player.getSession(), entity, 3);
   registerProtocolEvents(this);
 }
コード例 #8
0
  @Override
  public void finalizeRun() {
    // Moving from one region to another
    if (entityManager != null) {
      if (entityManager != entityManagerLive.get()) {
        // Deallocate entity
        if (entityManager.getRegion() != null) {
          entityManager.getRegion().removeEntity(this);
        } else {
          entityManager.deallocate(this);
        }
      }
    }
    if (entityManagerLive.get() != null) {
      if (entityManager != entityManagerLive.get()) {
        // Allocate entity
        entityManagerLive.get().allocate(this);
      }
    }

    // Could be 1 of 3 scenarios:
    //    1.) Entity is dead (ControllerLive == null)
    //    2.) Entity is swapping controllers (ControllerLive != Controller, niether is null)
    //    3.) Entity has just spawned and has never executed copy snapshot, Controller == null,
    // ControllerLive != null
    if (controller != controllerLive.get()) {
      // 1.) Entity is dead
      if (controller != null && controllerLive.get() == null) {
        // Sanity check
        if (!isDead())
          throw new IllegalStateException("ControllerLive is null, but entity is not dead!");

        // Kill old controller
        controller.onDeath();
        if (controller instanceof PlayerController) {
          Player p = ((PlayerController) controller).getPlayer();
          if (p != null) {
            p.getNetworkSynchronizer().onDeath();
          }
        }
      }
      // 2.) Entity is changing controllers
      else if (controller != null && controllerLive.get() != null) {
        // Kill old controller
        controller.onDeath();
        if (controller instanceof PlayerController) {
          Player p = ((PlayerController) controller).getPlayer();
          if (p != null) {
            p.getNetworkSynchronizer().onDeath();
          }
        }

        // Allocate new controller
        if (entityManagerLive.get() != null) {
          entityManagerLive.get().allocate(this);
        }
      }
      // 3.) Entity was just spawned, has not copied snapshots yet
      else if (controller == null && controllerLive.get() != null) {
        // Sanity check
        if (!this.justSpawned())
          throw new IllegalStateException(
              "Controller is null, ControllerLive is not-null, and the entity did not just spawn.");
      }
    }

    if (chunkLive.get() != chunk) {
      if (observer) {
        if (!isDead()) {
          updateObserver();
        } else {
          removeObserver();
        }
      }
      if (chunkLive.get() != null) {
        ((SpoutChunk) chunkLive.get()).addEntity(this);
      }
      if (chunk != null && chunk.isLoaded()) {
        ((SpoutChunk) chunk).removeEntity(this);
      }
      if (chunkLive.get() == null) {
        if (chunk != null && chunk.isLoaded()) {
          ((SpoutChunk) chunk).removeEntity(this);
        }
        if (entityManagerLive.get() != null) {
          entityManagerLive.get().deallocate(this);
        }
      }
    }

    if (observerLive.get() != observer) {
      observer = !observer;
      if (observer) {
        updateObserver();
      } else {
        removeObserver();
      }
    }
  }
コード例 #9
0
 /** Loads inventory on first use. */
 private void loadInventory() {
   if (items == null) {
     items = player.getEntity().getInventory().getContents();
   }
 }