コード例 #1
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());
    }
  }
コード例 #2
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);
        }
      }
    }
  }
コード例 #3
0
  @Override
  protected void worldChanged(World world) {
    WorldConfigurationNode node = VanillaConfiguration.WORLDS.get(world);
    maxY = node.MAX_Y.getInt() & (~Chunk.BLOCKS.MASK);
    minY = node.MIN_Y.getInt() & (~Chunk.BLOCKS.MASK);
    stepY = node.STEP_Y.getInt() & (~Chunk.BLOCKS.MASK);
    lowY = maxY - stepY;
    highY = minY + stepY;
    lastY = Integer.MAX_VALUE;

    final DatatableComponent data = world.getComponentHolder().getData();
    final Human human = player.get(Human.class);
    GameMode gamemode = null;
    Difficulty difficulty = data.get(VanillaData.DIFFICULTY);
    Dimension dimension = data.get(VanillaData.DIMENSION);
    WorldType worldType = data.get(VanillaData.WORLD_TYPE);

    int entityId = player.getId();

    if (first) {
      first = false;
      if (human != null && human.getAttachedCount() > 1) {
        gamemode = human.getGameMode();
      } else {
        gamemode = data.get(VanillaData.GAMEMODE);
        if (human != null) {
          human.setGamemode(gamemode);
        }
      }

      Server server = (Server) session.getEngine();
      PlayerLoginRequestMessage idMsg =
          new PlayerLoginRequestMessage(
              entityId,
              worldType.toString(),
              gamemode.getId(),
              (byte) dimension.getId(),
              difficulty.getId(),
              (byte) server.getMaxPlayers());
      player.getSession().send(false, true, idMsg);
      player.getSession().setState(State.GAME);
    } else {
      if (human != null) {
        gamemode = human.getGameMode();
      }
      player
          .getSession()
          .send(
              false,
              new PlayerRespawnMessage(
                  0, difficulty.getId(), gamemode.getId(), 256, worldType.toString()));
      player
          .getSession()
          .send(
              false,
              new PlayerRespawnMessage(
                  1, difficulty.getId(), gamemode.getId(), 256, worldType.toString()));
      player
          .getSession()
          .send(
              false,
              new PlayerRespawnMessage(
                  dimension.getId(),
                  difficulty.getId(),
                  gamemode.getId(),
                  256,
                  worldType.toString()));
    }

    if (human != null) {
      if (first) {
        human.setGamemode(gamemode, false);
      }
      human.updateAbilities();
    }

    PlayerInventory inv = player.get(PlayerInventory.class);
    if (inv != null) {
      inv.updateAll();
    }

    Point pos = world.getSpawnPoint().getPosition();
    PlayerSpawnPositionMessage SPMsg =
        new PlayerSpawnPositionMessage(
            (int) pos.getX(), (int) pos.getY(), (int) pos.getZ(), getRepositionManager());
    player.getSession().send(false, SPMsg);
    session.send(
        false,
        new PlayerHeldItemChangeMessage(
            session
                .getPlayer()
                .add(PlayerInventory.class)
                .getQuickbar()
                .getSelectedSlot()
                .getIndex()));

    VanillaSky.getSky(world).updatePlayer(player);
  }