Package org.spout.api.entity

Examples of org.spout.api.entity.Player


      switch (target) {

        case NEAREST_PLAYER_CHAR:
          // find the closest suitable player
          List<Player> nearbyPlayers = center.getWorld().getNearbyPlayers(center, filter.maxRadius);
          Player nearbyPlayer = filter.findPlayer(nearbyPlayers);
          if (nearbyPlayer == null) {
            return;
          }
          cmds.add(cmd.replace(statement, nearbyPlayer.getName()));
          break;

        case RANDOM_PLAYER_CHAR:
          // find a random but suitable player in any location
          Collections.shuffle(allPlayers);
          Player player = filter.findPlayer(allPlayers);
          if (player == null) {
            return;
          }
          cmds.add(cmd.replace(statement, player.getName()));
          break;

        case ALL_PLAYERS_CHAR:
          // use all players, but filter out any players that are not suitable
          for (Player p : filter.filter(allPlayers)) {
View Full Code Here


public class EntityMocker {
  public static Player mockPlayer() {
    Engine engine = EngineFaker.setupEngine();

    final Player player = Mockito.mock(Player.class);
    final EntityComponentAnswer componentHolder = new EntityComponentAnswer(player);
    componentHolder.add(NetworkComponent.class);

    //Set up component holder methods
    Mockito.when(player.add(Matchers.argThat(new ClassOrSubclassMatcher<EntityComponent>(EntityComponent.class)))).thenAnswer(componentHolder);
    Mockito.when(player.get(Matchers.argThat(new ClassOrSubclassMatcher<EntityComponent>(EntityComponent.class)))).thenAnswer(componentHolder);
    Mockito.when(player.getExact(Matchers.argThat(new ClassOrSubclassMatcher<EntityComponent>(EntityComponent.class)))).thenAnswer(componentHolder);
    Mockito.when(player.detach(Matchers.argThat(new ClassOrSubclassMatcher<EntityComponent>(EntityComponent.class)))).thenAnswer(componentHolder);
    Mockito.when(player.getData()).thenReturn(componentHolder.getData());
    Mockito.when(player.getEngine()).thenAnswer(new EntityEngineAnswer(engine));
    //Set up entity tick
    Mockito.doAnswer(new EntityTickAnswer(player)).when(player).onTick(Mockito.anyFloat());

    //Set up event manager
    return player;
View Full Code Here

    }
  }

  @EventHandler
  public void onPlayerJoin(PlayerJoinEvent event) {
    Player player = event.getPlayer();
    // TODO: this must here, because when health gets updated on first attach, protocol event uses hunger too. Sleaker?
    player.add(Hunger.class);
    player.add(Human.class).setName(player.getName());
    player.add(PlayerInventory.class);
    player.add(WindowHolder.class);
    player.add(PlayerList.class);
    // TODO: Connection times out when using Spout Protocol because no Ping Message; need a Ping component client-side that somehow updates server
    if (player.getNetwork() instanceof VanillaPlayerNetworkComponent) {
      player.add(Ping.class);
      ((VanillaPlayerNetworkComponent) player.getNetwork()).setEntityProtocol(new PlayerEntityProtocol());
    }
    player.add(PlayerItemCollector.class);
    player.add(Sleep.class);
    player.add(Level.class);
    player.getNetwork().getSession().setUncaughtExceptionHandler(new PasteExceptionHandler(player.getNetwork().getSession()));
    Sky sky = player.getWorld().get(Sky.class);
    if (sky != null) {
      sky.updatePlayer(player);
    }
  }
View Full Code Here

  public void onGameStart(EngineStartEvent event) {
    if (plugin.getEngine().getPlatform() != Platform.CLIENT) {
      return;
    }

    Player player = ((Client) plugin.getEngine()).getPlayer();

    HUD HUD = player.add(org.spout.vanilla.component.entity.player.HUD.class);
    HUD.setDefault(VanillaArmorWidget.class);
    HUD.setDefault(VanillaQuickbar.class);
    HUD.setDefault(VanillaCrosshair.class);
    HUD.setDefault(VanillaExpBar.class);
    HUD.setDefault(VanillaDrowning.class);
    HUD.setDefault(VanillaHunger.class);
    HUD.setupHUD();
    HUD.openHUD();

    // TODO remove comments when Spout only uses fallback
    //player.add(PlayerMovementExecutor.class);

    // Remove Head and default Camera
    player.detach(EntityHead.class);
    player.detach(CameraComponent.class);

    player.add(PlayerHead.class);
  }
View Full Code Here

  @EventHandler
  public void onClientConnect(ClientPlayerConnectedEvent event) {
    if (plugin.getEngine().getPlatform() != Platform.CLIENT) {
      return;
    }
    Player player = ((Client) plugin.getEngine()).getPlayer();

    player.add(Human.class);
    player.add(PlayerInventory.class);
    player.add(WindowHolder.class);
    player.add(Health.class);
    player.add(Hunger.class);
    player.add(PlayerInteract.class).setRange(5f);

    if (VanillaConfiguration.ONLINE_MODE.getBoolean()) {
      String username = VanillaConfiguration.USERNAME.getString();
      String password = VanillaConfiguration.PASSWORD.getString();
      Thread loginAuth = new Thread(new ClientAuthentification(username, password));
View Full Code Here

  @Override
  public void onInteract(final EntityInteractEvent event) {
    super.onInteract(event);
    if (event instanceof PlayerInteractBlockEvent) {
      final PlayerInteractBlockEvent pib = (PlayerInteractBlockEvent) event;
      final Player player = (Player) pib.getEntity();
      switch (pib.getAction()) {
        case RIGHT_CLICK:
          if (open(player)) {
            viewers.add(player);
          }
View Full Code Here

  @CommandDescription (aliases = {"effect", "fx"}, usage = "<type> <duration> [amp]", desc = "Applies an effect.")
  @Permissible ("vanilla.command.debug")
  @Filter (PlayerFilter.class)
  public void effect(CommandSource source, CommandArguments args) throws CommandException {
    Player player = args.checkPlayer(source);
    EntityEffectType type = args.popEnumValue("type", EntityEffectType.class);
    float duration = (float) args.popDouble("duration");
    int amp = args.popInteger("amp", 2);
    args.assertCompletelyParsed();

    player.add(Effects.class).add(new EntityEffect(type, amp, duration));
    player.sendMessage(ChatStyle.GREEN + "Applied effect '" + type + "' with amplitude '" + amp + "' for '" + duration + "' seconds.");
  }
View Full Code Here

  @CommandDescription (aliases = "traceray", desc = "Set all blocks that cross your view to stone.")
  @Permissible ("vanilla.command.debug")
  @Filter (PlayerFilter.class)
  public void traceray(CommandSource source, CommandArguments args) throws CommandException {
    args.assertCompletelyParsed();
    Player player = (Player) source;

    BlockIterator blockIt;
    if (getEngine().getPlatform() != Platform.CLIENT) {
      blockIt = player.get(EntityHead.class).getBlockView();
    } else {
      blockIt = player.get(InteractComponent.class).getAlignedBlocks();
    }

    Block block;
    while (blockIt.hasNext()) {
      block = blockIt.next();
View Full Code Here

  @CommandDescription (aliases = "debug", usage = "<resend|resendall|look|packets)", desc = "Debug commands")
  @Permissible ("vanilla.command.debug")
  public void debug(CommandSource source, CommandArguments args) throws CommandException {
    String action = args.popString("action");
    Player player = args.popPlayerOrMe("player", source);
    args.assertCompletelyParsed();

    if (action.contains("look")) {
      Quaternionf rotation = player.getData().get(VanillaData.HEAD_ROTATION);
      Point startPosition = player.getPhysics().getPosition();
      Vector3f offset = rotation.getDirection().mul(0.1);
      for (int i = 0; i < 100; i++) {
        startPosition = startPosition.add(offset);
        GeneralEffects.NOTE_PARTICLE.playGlobal(startPosition);
      }
      final Vector3f axesAngles = rotation.getAxesAngleDeg();
      player.sendMessage("Yaw = " + axesAngles.getY());
      player.sendMessage("Pitch = " + axesAngles.getX());
    } else if (action.contains("packets")) {
      player.add(ForceMessages.class);
    } else {
      if (getEngine() instanceof Client) {
        throw new CommandException("You cannot resend chunks in client mode.");
      }
      if (action.contains("resendall")) {
        Set<Chunk> chunks = player.getNetwork().getActiveChunks();
        for (Chunk c : chunks) {
          player.getNetwork().callProtocolEvent(new ChunkSendEvent(c, true));
        }

        source.sendMessage("All chunks resent");
      } else if (action.contains("resend")) {
        player.getNetwork().callProtocolEvent(new ChunkSendEvent(player.getChunk(), true));
        source.sendMessage("Chunk resent");
      }
    }
  }
View Full Code Here

  @CommandDescription (aliases = "data", usage = "<key> <value>", desc = "Change Entity data value")
  @Permissible ("vanilla.command.data")
  public void data(CommandSource source, CommandArguments args) throws CommandException {
    String key = args.popString("key");
    String value = args.popRemainingStrings("value");
    Player player = args.popPlayerOrMe("player", source);
    args.assertCompletelyParsed();

    // Figure out what entity to affect
    // Note: this could be put in a method in the Vanilla human component instead
    // This version is rather inaccurate...
    double lastDistanceToEntity = 5.0;
    Point point = player.getPhysics().getPosition();
    Human human = player.get(Human.class);
    Vector3f direction;
    if (human == null) {
      direction = player.getPhysics().getRotation().getDirection();
    } else {
      direction = human.getHead().getLookingAt();
    }
    Entity nearest = null;
    for (double d = 0.0; d <= 50.0; d += 0.25) {
      Point pos = point.add(direction.mul(d));
      Entity near = point.getWorld().getNearestEntity(pos, player, (int) lastDistanceToEntity);
      if (near == null) {
        continue;
      }
      double distance = pos.distance(near.getPhysics().getPosition());
      if (distance < lastDistanceToEntity) {
        lastDistanceToEntity = distance;
        nearest = near;
        if (distance < 0.5) {
          break;
        }
      }
    }
    if (nearest == null) {
      player.sendMessage("Could not find a near Entity you are looking at.");
      return;
    }

    // Send entity information
    Descriptor desc = nearest.get(Descriptor.class);
    if (desc == null) {
      player.sendMessage("Selected Entity: Unknown");
    } else {
      player.sendMessage("Selected Entity: " + desc.getDescription());
    }

    Object currentValue = nearest.getData().get(key);
    if (value == null || value.isEmpty()) {
      if (nearest.getData().containsKey(key)) {
        player.sendMessage(key + " = " + currentValue);
      } else {
        player.sendMessage("No value is mapped to " + key + " for this Entity");
      }
      return;
    }

    // Figure out what type the key is using VanillaData
    Class<?> valueType = null;
    for (Field field : VanillaData.class.getDeclaredFields()) {
      if (!Modifier.isStatic(field.getModifiers())) {
        continue;
      }
      try {
        Object fieldValue = field.get(null);
        if (fieldValue instanceof DefaultedKey) {
          DefaultedKey<?> defKey = (DefaultedKey<?>) fieldValue;
          if (!defKey.getKeyString().equals(key)) {
            continue;
          }
          Object defValue = defKey.getDefaultValue();
          if (defValue != null) {
            // We found our type!
            valueType = defValue.getClass();
            break;
          }
        }
      } catch (Throwable t) {
        // Ignore any field access issues
      }
    }
    // Try using the current value in the datamap
    if (valueType == null) {
      if (currentValue == null) {
        player.sendMessage("Could not figure out the type of value stored by " + key);
        return;
      } else {
        valueType = currentValue.getClass();
      }
    }

    // Set the value in the datamap if possible
    try {
      Serializable newValue;
      if (Double.class.isAssignableFrom(valueType)) {
        newValue = Double.parseDouble(value);
      } else if (Float.class.isAssignableFrom(valueType)) {
        newValue = Float.parseFloat(value);
      } else if (Long.class.isAssignableFrom(valueType)) {
        newValue = Long.parseLong(value);
      } else if (Integer.class.isAssignableFrom(valueType)) {
        newValue = Integer.parseInt(value);
      } else if (Short.class.isAssignableFrom(valueType)) {
        newValue = Short.parseShort(value);
      } else if (Byte.class.isAssignableFrom(valueType)) {
        newValue = Byte.parseByte(value);
      } else if (String.class.isAssignableFrom(valueType)) {
        newValue = value;
      } else {
        player.sendMessage("No idea how to turn " + value + " into " + valueType.getSimpleName());
        return;
      }
      nearest.getData().put(key, newValue);
      player.sendMessage("Value of " + key + " set to " + newValue);
    } catch (Throwable t) {
      player.sendMessage("Error occurred while parsing value " + value);
      player.sendMessage(t.getMessage());
    }
  }
View Full Code Here

TOP

Related Classes of org.spout.api.entity.Player

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.