Ejemplo n.º 1
0
 @Override
 public void onTick(float dt) {
   final Random random = GenericMath.getRandom();
   float secondsUntilWeatherChange = sky.getData().get(VanillaData.WEATHER_CHANGE_TIME);
   secondsUntilWeatherChange -= dt;
   if (forceWeatherUpdate.compareAndSet(true, false) || secondsUntilWeatherChange <= 0) {
     this.sky.updateWeather(getCurrent(), getForecast());
     sky.getData().put(VanillaData.WORLD_WEATHER, getForecast());
     final Weather current = getCurrent();
     Weather forecast = current;
     while (forecast == current) {
       // When Rain/Snow or Thunderstorms occur, always go to Clear after.
       if (current == Weather.RAIN || current == Weather.THUNDERSTORM) {
         forecast = Weather.CLEAR;
       } else {
         forecast = Weather.get(random.nextInt(3));
       }
       setForecast(forecast);
     }
     setForecast(forecast);
     secondsUntilWeatherChange =
         current.getBaseWeatherTime() + random.nextInt(current.getRandomWeatherTime());
     if (Spout.debugMode()) {
       Spout.getLogger()
           .info(
               "Weather changed to: "
                   + current
                   + ", next change in "
                   + secondsUntilWeatherChange / 1000F
                   + "s");
     }
   }
   float currentRainStrength = sky.getData().get(VanillaData.CURRENT_RAIN_STRENGTH);
   sky.getData().put(VanillaData.PREVIOUS_RAIN_STRENGTH, currentRainStrength);
   if (this.isRaining()) {
     currentRainStrength = Math.min(1.0f, currentRainStrength + 0.01f);
   } else {
     currentRainStrength = Math.max(0.0f, currentRainStrength - 0.01f);
   }
   sky.getData().put(VanillaData.CURRENT_RAIN_STRENGTH, currentRainStrength);
   if (hasLightning()) {
     lightning.onTick(dt);
   }
   if (getCurrent().isRaining()) {
     snowfall.onTick(dt);
   }
   sky.getData().put(VanillaData.WEATHER_CHANGE_TIME, secondsUntilWeatherChange);
 }
Ejemplo n.º 2
0
 public void setForecast(Weather weather) {
   sky.getData().put(VanillaData.WORLD_FORECAST, weather);
 }
Ejemplo n.º 3
0
 public Weather getForecast() {
   return sky.getData().get(VanillaData.WORLD_FORECAST);
 }
Ejemplo n.º 4
0
 public Weather getCurrent() {
   return sky.getData().get(VanillaData.WORLD_WEATHER);
 }
Ejemplo n.º 5
0
 /**
  * Gets the strength of the rain, which is affected by the duration
  *
  * @param factor to apply to the changing states
  * @return the strength
  */
 public float getRainStrength(float factor) {
   final float prevRainStr = sky.getData().get(VanillaData.PREVIOUS_RAIN_STRENGTH);
   return (prevRainStr
       + factor * (sky.getData().get(VanillaData.CURRENT_RAIN_STRENGTH) - prevRainStr));
 }
Ejemplo n.º 6
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.º 7
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());
    }
  }
Ejemplo n.º 8
0
 @Override
 public void onAttached() {
   super.onAttached();
   getWorld().setSkyLight(MAX_SKY_LIGHT);
 }
Ejemplo n.º 9
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);
  }