Package org.spout.vanilla.component.entity.living

Examples of org.spout.vanilla.component.entity.living.Human


      server.getEventManager().callEvent(new PlayerConnectEvent(session, (String) session.getDataMap().get("username"), 10));
      if (server.debugMode()) {
        server.getLogger().info("Login took " + (System.currentTimeMillis() - session.getDataMap().get(VanillaProtocol.LOGIN_TIME)) + " ms");
      }
      final ManagedMap data = session.getPlayer().getWorld().getData();
      final Human human = session.getPlayer().add(Human.class);
      final Difficulty difficulty = data.get(VanillaData.DIFFICULTY);
      final Dimension dimension = data.get(VanillaData.DIMENSION);
      final WorldType worldType = data.get(VanillaData.WORLD_TYPE);

      GameMode gamemode;

      int entityId = session.getPlayer().getId();

      //  MC Packet Order: 0x01 Login, 0xFA Custom (ServerTypeName), 0x06 SpawnPos, 0xCA PlayerAbilities, 0x10 BlockSwitch
      gamemode = data.get(VanillaData.GAMEMODE);
      final PlayerLoginRequestMessage idMsg = new PlayerLoginRequestMessage(entityId, worldType.toString(), gamemode.getId(), (byte) dimension.getId(), difficulty.getId(), (byte) server.getMaxPlayers());
      session.send(Session.SendType.FORCE, idMsg);
      session.setState(Session.State.GAME);
      if (human.getAttachedCount() <= 1) {
        // If we haven't logged in before, we want to set all abilities to the default gamemode
        human.setGamemode(gamemode, false);
      }
    } else if (message.getStatus() == PlayerStatusMessage.RESPAWN) {
      Player player = session.getPlayer();
      Point point = player.getWorld().getSpawnPoint().getPosition();
      if (PlayerRespawnEvent.getHandlerList().getRegisteredListeners().length > 0) {
        PlayerRespawnEvent event = server.getEventManager().callEvent(new PlayerRespawnEvent(player, point));

        if (event.isCancelled()) {
          return;
        }
        point = event.getPoint();
      }
      //Set position for the server
      player.getPhysics().setPosition(point);
      player.getNetwork().forceRespawn();
      Human human = player.add(Human.class);
      human.getHealth().setHealth(human.getHealth().getMaxHealth(), HealthChangeCause.SPAWN);

      final Transform spawn = new Transform(player.getPhysics().getTransform());
      spawn.setPosition(point);
    }
  }
View Full Code Here


import org.spout.vanilla.util.PlayerUtil;

public final class PlayerHeldItemChangeHandler extends MessageHandler<PlayerHeldItemChangeMessage> {
  @Override
  public void handleServer(ServerSession session, PlayerHeldItemChangeMessage message) {
    Human human = session.getPlayer().get(Human.class);
    if (human == null) {
      return;
    }
    final int newSlot = message.getSlot();
    if (newSlot < 0 || newSlot > 8) {
View Full Code Here

public class PlayerLoginRequestHandler extends MessageHandler<PlayerLoginRequestMessage> {
  @Override
  public void handleClient(ClientSession session, PlayerLoginRequestMessage message) {
    System.out.println(message.toString());

    Human human = session.getPlayer().add(Human.class);
    human.setGamemode(GameMode.get(message.getGameMode()));
  }
View Full Code Here

        // Check if entity can be damaged
        Health health = entity.get(Health.class);
        if (health == null) {
          continue;
        }
        Human human = entity.get(Human.class);
        if (human != null && human.isCreative()) {
          continue;
        }
        health.damage(getDamage(position, entity.getPhysics().getPosition(), size));
      }
    }
View Full Code Here

public class PlayerGroundHandler extends MessageHandler<PlayerGroundMessage> {
  @Override
  public void handleServer(ServerSession session, PlayerGroundMessage message) {
    Player player = session.getPlayer();
    Human human = player.get(Human.class);
    if (human != null) {
      human.setOnGround(message.isOnGround());
    }
    //TODO check and apply fall damage!
  }
View Full Code Here

import org.spout.vanilla.component.entity.living.Human;
import org.spout.vanilla.protocol.msg.entity.SteerVehicleMessage;

public final class SteerVehicleHandler extends MessageHandler<SteerVehicleMessage> {
  public void handleServer(ServerSession session, SteerVehicleMessage message) {
    Human player = session.getPlayer().get(Human.class);
    if (!player.isRiding()) {
      return;
    }
    if (message.isUnmount()) {
      player.setRiding(false);
      // TODO: detach the player from the entity it's riding
      return;
    }

    if (message.isJumping()) {
      player.setJumping(true);
      // TODO: set the ridden entity as jumping also if possible
    }
    // TODO: handle movement onto the entity
  }
View Full Code Here

    Block block = w.getBlock(point);
    BlockMaterial blockMaterial = block.getMaterial();

    short minecraftID = VanillaMaterials.getMinecraftId(blockMaterial);
    BlockFace clickedFace = message.getFace();
    Human human = player.get(Human.class);
    if (human == null) {
      return;
    }
    Slot currentSlot = PlayerUtil.getHeldSlot(player);
    if (currentSlot == null) {
      return;
    }
    ItemStack heldItem = currentSlot.get();

    // Don't block protections if dropping an item, silly Notch...
    if (state != PlayerDiggingMessage.STATE_DROP_ITEM && state != PlayerDiggingMessage.STATE_SHOOT_ARROW_EAT_FOOD) {
      Collection<Protection> protections = player.getEngine().getServiceManager().getRegistration(ProtectionService.class).getProvider().getAllProtections(point);
      for (Protection p : protections) {
        if (p.contains(point) && !human.isOp()) {
          player.getNetwork().getSession().send(new BlockChangeMessage(x, y, z, minecraftID, block.getBlockData() & 0xF, rm));
          player.sendMessage(ChatStyle.DARK_RED + "This area is a protected spawn point!");
          return;
        }
      }
    }

    if (state == PlayerDiggingMessage.STATE_DROP_ITEM && x == 0 && y == 0 && z == 0) {
      human.dropItem();
      return;
    }

    boolean isInteractable = true;
    if (blockMaterial == VanillaMaterials.AIR) {
      isInteractable = false;
    }
    // TODO VanillaPlayerInteractBlockEvent and add in Results to it (to
    // more indepthly take away durability).
    switch (state) {
      case PlayerDiggingMessage.STATE_START_DIGGING:
        if (!isProtected(player, rm, x, y, z, block, minecraftID)) {
          final PlayerInteractBlockEvent event = new PlayerInteractBlockEvent(player, block, point, clickedFace, Action.LEFT_CLICK);
          if (player.getEngine().getEventManager().callEvent(event).isCancelled()) {
            if (human.isCreative() || blockMaterial.getHardness() == 0.0f) {
              session.send(new BlockChangeMessage(block, player.getNetwork().getRepositionManager()));
              Sign sign = block.get(Sign.class);
              if (sign != null) {
                session.send(new SignMessage(block.getX(), block.getY(), block.getZ(), sign.getText(), player.getNetwork().getRepositionManager()));
              }
            }
          } else {
            // Perform interactions
            if (heldItem == null) {
              // interacting using fist
            } else if (!isInteractable) {
              // interacting with nothing using item
              heldItem.getMaterial().onInteract(player, Action.LEFT_CLICK);
            } else {
              // interacting with block using item
              heldItem.getMaterial().onInteract(player, block, Action.LEFT_CLICK, clickedFace);
            }

            if (isInteractable) {
              Block neigh = block.translate(clickedFace);
              boolean fire = neigh.getMaterial().equals(VanillaMaterials.FIRE);
              if (fire) {
                // put out fire
                if (VanillaMaterials.FIRE.onDestroy(neigh, new PlayerBreakCause(player, neigh))) {
                  GeneralEffects.RANDOM_FIZZ.playGlobal(block.getPosition());
                }
              } else if (human.isSurvival() && blockMaterial.getHardness() != 0.0f) {
                ItemStack currentItem = PlayerUtil.getHeldSlot(player).get();
                if (currentItem != null) {
                  player.get(Digging.class).startDigging(new Point(w, x, y, z), currentItem.getMaterial());
                } else {
                  player.get(Digging.class).startDigging(new Point(w, x, y, z), VanillaMaterials.AIR);
                }
              } else {
                // insta-break
                if (breakBlock(blockMaterial, block, human, session)) {
                  GeneralEffects.BREAKBLOCK.playGlobal(block.getPosition(), blockMaterial, player);
                }
              }
            }
          }
        }
        break;
      case PlayerDiggingMessage.STATE_CANCEL_DIGGING:
        if (!isProtected(player, rm, x, y, z, block, minecraftID)) {
          player.get(Digging.class).stopDigging(new Point(w, x, y, z), false);
        }
        break;
      case PlayerDiggingMessage.STATE_DONE_DIGGING:
        if (!isProtected(player, rm, x, y, z, block, minecraftID)) {
          Digging diggingComponent = player.get(Digging.class);

          if (!diggingComponent.stopDigging(new Point(w, x, y, z), true) || !isInteractable) {
            if (!diggingComponent.isDigging()) {
              session.send(new BlockChangeMessage(block, player.getNetwork().getRepositionManager()));
              Sign sign = block.get(Sign.class);
              if (sign != null) {
                session.send(new SignMessage(block.getX(), block.getY(), block.getZ(), sign.getText(), player.getNetwork().getRepositionManager()));
              }
            }
            return;
          }

          if (player.getData().get(VanillaData.GAMEMODE).equals(GameMode.SURVIVAL)) {
            long diggingTicks = diggingComponent.getDiggingTicks();
            int damageDone;
            int totalDamage;

            if (heldItem == null) {
              damageDone = ((int) diggingTicks);
            } else {
              damageDone = ((int) diggingTicks * ((VanillaMaterial) heldItem.getMaterial()).getDamage());
            }
            // TODO: Take into account EFFICIENCY enchantment
            // TODO: Digging is slower while under water, on ladders,
            // etc. AQUA_AFFINITY enchantment speeds up underwater
            // digging

            totalDamage = ((int) blockMaterial.getHardness() - damageDone);
            if (totalDamage <= 40) { // Yes, this is a very high
              // allowance - this is because
              // this is only over a single
              // block, and this will spike
              // due to varying latency.
              if (breakBlock(blockMaterial, block, human, session)) {
                GeneralEffects.BREAKBLOCK.playGlobal(block.getPosition(), blockMaterial, player);

                if (heldItem != null && heldItem.getMaterial() instanceof Tool) {
                  Tool tool = (Tool) heldItem.getMaterial();
                  short damage = tool.getDurabilityPenalty(heldItem);
                  if (currentSlot.get().getData() + damage >= tool.getMaxDurability()) {
                    currentSlot.set(null);
                  } else {
                    currentSlot.addData(damage);
                  }
                }
              }
            }
          }
        }
        break;
      case PlayerDiggingMessage.STATE_DROP_ITEM:
        human.dropItem();
        break;
      case PlayerDiggingMessage.STATE_SHOOT_ARROW_EAT_FOOD:
        if (heldItem.getMaterial() instanceof Food || heldItem.getMaterial() instanceof PotionItem) {
          player.add(Hunger.class).setEating(false, currentSlot);
        } else if (heldItem.getMaterial() instanceof Sword) {
          human.setEatingBlocking(false);
        }
        break;
      case PlayerDiggingMessage.STATE_UPDATE_BLOCK:
        break;
    }
View Full Code Here

    if (!(holder.getNetwork() instanceof VanillaPlayerNetworkComponent)) {
      throw new IllegalStateException("Using Vanilla Protocol without using VanillaNetworkSynchronizer");
    }
    if (!position.equals(newPosition)) {
      final Human human = holder.get(Human.class);
      // TODO: live?
      holder.getPhysics().setTransform(new Transform(newPosition, holder.getPhysics().getRotation(), holder.getPhysics().getScale()), false);

      //Don't use client onGround value, calculate ourselves
      //MC Client is on ground if y value is whole number, or half step (e.g 55.0, or 65.5)
      float yDiff = Math.abs(newPosition.getBlockY() - newPosition.getY());
      if (yDiff > 0.4) {
        yDiff -= 0.5F; //half blocks
      }
      final BlockMaterial ground = newPosition.getBlock().translate(BlockFace.BOTTOM).getMaterial();
      final boolean onGround = yDiff < 0.01 && (ground instanceof VanillaBlockMaterial && ground.getShape() != null);
      final boolean wasOnGround = human.isOnGround();
      human.setOnGround(onGround);

      //Update falling state
      final boolean wasFalling = human.isFalling();
      if (!onGround && newPosition.getY() < position.getY()) {
        human.setFalling(true);
      } else {
        human.setFalling(false);
      }

      //Hover tracking
      if (wasOnGround && !onGround) {
        human.getData().put("position_on_ground", position);
        human.getData().put("time_in_air", holder.getWorld().getAge());
      } else if (!wasOnGround && !onGround) {
        //Changed directions
        if (wasFalling && !human.isFalling() || human.isInWater()) {
          human.getData().remove("time_in_air");
        }
        float time = human.getData().get("time_in_air", holder.getWorld().getAge());
        //hovering or still rising
        if (time + 2000 < holder.getWorld().getAge() && newPosition.getY() - position.getY() >= 0) {
          if (!human.canFly()) {
            holder.sendMessage("Hover cheating?");
          }
        }
      } else if (!wasOnGround && onGround) {
        human.getData().remove("position_on_ground");
        human.getData().remove("time_in_air");
      }

      //Movement tracking
      PositionTracker tracker = null;
      try {
View Full Code Here

    //TODO : Take Level tpye ? : message.getWorldType()

    World world = player.getWorld();
    world.getData().put(VanillaData.DIFFICULTY, Difficulty.get(message.getDifficulty()));

    Human human = player.add(Human.class);
    human.setGamemode(GameMode.get(message.getGameMode()));
  }
View Full Code Here

public class PlayerLocaleViewDistanceHandler extends MessageHandler<PlayerLocaleViewDistanceMessage> {
  @Override
  public void handleServer(ServerSession session, PlayerLocaleViewDistanceMessage message) {
    Player player = session.getPlayer();
    Human human = player.get(Human.class);
    if (human != null) {
      ViewDistance distance = ViewDistance.byId(message.getViewDistance());
      human.setViewDistance(distance);
    }
  }
View Full Code Here

TOP

Related Classes of org.spout.vanilla.component.entity.living.Human

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.