Ejemplo n.º 1
0
 @Override
 public BlockIterator getAlignedBlocks() {
   Player player = (Player) getOwner();
   Transform ptr = player.get(PlayerHead.class).getHeadTransform();
   Transform tr = new Transform();
   tr.setRotation(
       QuaternionMath.rotationTo(Vector3.FORWARD, ptr.getRotation().getDirection().multiply(-1)));
   tr.setPosition(ptr.getPosition());
   return new BlockIterator(player.getWorld(), tr, getRange());
 }
Ejemplo n.º 2
0
  @Override
  public void handleClient(Session session, EntityVelocityMessage message) {
    if (!session.hasPlayer()) {
      return;
    }

    Player player = session.getPlayer();
    World world = player.getWorld();
    Entity entity = world.getEntity(message.getEntityId());

    System.out.println(message.toString());
  }
Ejemplo n.º 3
0
  @Command(
      aliases = "weather",
      usage = "<0|1|2> (0 = CLEAR, 1 = RAIN/SNOW, 2 = THUNDERSTORM) [world]",
      desc = "Changes the weather",
      min = 1,
      max = 2)
  @CommandPermissions("vanilla.command.weather")
  public void weather(CommandContext args, CommandSource source) throws CommandException {
    World world;
    if (source instanceof Player && args.length() == 1) {
      world = ((Player) source).getWorld();
    } else if (args.length() == 2) {
      world = plugin.getEngine().getWorld(args.getString(1));

      if (world == null) {
        throw new CommandException("Invalid world '" + args.getString(1) + "'.");
      }
    } else {
      throw new CommandException("You need to specify a world.");
    }

    Weather weather;
    try {
      if (args.isInteger(0)) {
        weather = Weather.get(args.getInteger(0));
      } else {
        weather = Weather.get(args.getString(0).replace("snow", "rain"));
      }
    } catch (Exception e) {
      throw new CommandException(
          "Weather must be a mode between 0 and 2, 'CLEAR', 'RAIN', 'SNOW', or 'THUNDERSTORM'");
    }

    VanillaSky sky = VanillaSky.getSky(world);
    if (sky == null) {
      throw new CommandException("The sky of world '" + world.getName() + "' is not availible.");
    }

    sky.setWeather(weather);
    ChatArguments message;

    switch (weather) {
      case RAIN:
        message =
            new ChatArguments(
                plugin.getPrefix(),
                ChatStyle.BRIGHT_GREEN,
                "Weather set to ",
                ChatStyle.WHITE,
                "RAIN/SNOW",
                ChatStyle.BRIGHT_GREEN,
                ".");
        break;
      default:
        message =
            new ChatArguments(
                plugin.getPrefix(),
                ChatStyle.BRIGHT_GREEN,
                "Weather set to ",
                ChatStyle.WHITE,
                weather.name(),
                ChatStyle.BRIGHT_GREEN,
                ".");
        break;
    }
    if (Spout.getEngine() instanceof Client) {
      source.sendMessage(message);
    } else {
      for (Player player : ((Server) Spout.getEngine()).getOnlinePlayers()) {
        if (player.getWorld().equals(world)) {
          player.sendMessage(message);
        }
      }
    }
  }
Ejemplo n.º 4
0
  @Command(
      aliases = {"time"},
      usage = "<add|set> <0-24000|day|night|dawn|dusk> [world]",
      desc = "Set the time of the server",
      min = 2,
      max = 3)
  @CommandPermissions("vanilla.command.time")
  public void time(CommandContext args, CommandSource source) throws CommandException {
    long time = 0;
    boolean relative = false;
    if (args.getString(0).equalsIgnoreCase("set")) {
      if (args.isInteger(1)) {
        time = args.getInteger(1);
      } else {
        try {
          time = Time.get(args.getString(1)).getTime();
        } catch (Exception e) {
          throw new CommandException("'" + args.getString(1) + "' is not a valid time.");
        }
      }
    } else if (args.getString(0).equalsIgnoreCase("add")) {
      relative = true;
      if (args.isInteger(1)) {
        time = args.getInteger(1);
      } else {
        throw new CommandException("Argument to 'add' must be an integer.");
      }
    }

    World world;
    if (args.length() == 3) {
      world = plugin.getEngine().getWorld(args.getString(2));
      if (world == null) {
        throw new CommandException("'" + args.getString(2) + "' is not a valid world.");
      }
    } else if (source instanceof Player) {
      Player player = (Player) source;
      world = player.getWorld();
    } else {
      throw new CommandException("You must specify a world.");
    }

    VanillaSky sky = VanillaSky.getSky(world);
    if (sky == null) {
      throw new CommandException("The sky for " + world.getName() + " is not available.");
    }

    sky.setTime(relative ? (sky.getTime() + time) : time);
    if (Spout.getEngine() instanceof Client) {
      source.sendMessage(
          plugin.getPrefix(),
          ChatStyle.BRIGHT_GREEN,
          "You set ",
          ChatStyle.WHITE,
          world.getName(),
          ChatStyle.BRIGHT_GREEN,
          " to time: ",
          ChatStyle.WHITE,
          sky.getTime());
    } else {
      ((Server) Spout.getEngine())
          .broadcastMessage(
              plugin.getPrefix(),
              ChatStyle.WHITE,
              world.getName(),
              ChatStyle.BRIGHT_GREEN,
              " set to: ",
              ChatStyle.WHITE,
              sky.getTime());
    }
  }