Example #1
0
 public void setDefaultGameMode(GameMode mode) {
   GameMode oldMode = defaultGameMode;
   defaultGameMode = mode;
   for (Player player : getOnlinePlayers()) {
     if (player.getGameMode() == oldMode) {
       player.setGameMode(mode);
     }
   }
   config.set("server.def-game-mode", mode.name());
 }
Example #2
0
  /** Initializes the channel and pipeline factories. */
  private void init() {
    Bukkit.setServer(this);

    monitor = new DeadlockMonitor();
    monitor.start();

    ChannelFactory factory = new NioServerSocketChannelFactory(executor, executor);
    bootstrap.setFactory(factory);

    ChannelPipelineFactory pipelineFactory = new MinecraftPipelineFactory(this);
    bootstrap.setPipelineFactory(pipelineFactory);

    // TODO: This needs a cleanup badly
    InputStream stream = getClass().getClassLoader().getResourceAsStream("defaults/glowstone.yml");
    if (stream == null) {
      logger.severe("Error creating default config: Config not found in classpath");
      return;
    }
    try {
      config.setDefaults(YamlConfiguration.loadConfiguration(stream));
    } finally {
      try {
        stream.close();
      } catch (IOException e) {
      }
    }
    config.set("server.view-distance", GlowChunk.VISIBLE_RADIUS);

    // If the configuration is empty, attempt to migrate non-Glowstone configs
    if (config.getKeys(false).size() <= 1) {
      System.out.println("Generating default configuration config/glowstone.yml...");

      // bukkit.yml
      File bukkitYml = new File("bukkit.yml");
      if (bukkitYml.exists()) {
        YamlConfiguration bukkit = YamlConfiguration.loadConfiguration(bukkitYml);
        String moved = "", separator = "";

        if (bukkit.get("database") != null) {
          config.createSection(
              "database", bukkit.getConfigurationSection("database").getValues(true));
          moved += separator + "database settings";
          separator = ", ";
        }

        if (bukkit.get("settings.spawn-radius") != null) {
          config.set("server.spawn-radius", bukkit.getInt("settings.spawn-radius", 16));
          moved += separator + "spawn radius";
          separator = ", ";
        }

        if (bukkit.getString("settings.update-folder") != null) {
          config.set("server.folders.update", bukkit.getString("settings.update-folder"));
          moved += separator + "update folder";
          separator = ", ";
        }

        if (bukkit.getString("settings.world-container") != null) {
          config.set(
              "server.folders.world-container", bukkit.getString("settings.world-container"));
          moved += separator + "world container";
          separator = "m ";
        }

        if (bukkit.get("worlds") != null) {
          config.createSection("worlds", bukkit.getConfigurationSection("worlds").getValues(true));
          moved += separator + "world generators";
          separator = ", ";
        }

        // TODO: move aliases when those are implemented

        if (moved.length() > 0) {
          System.out.println("Copied " + moved + " from bukkit.yml");
        }
      }

      // server.properties
      File serverProps = new File("server.properties");
      if (serverProps.exists()) {
        try {
          Properties properties = new Properties();
          properties.load(new FileInputStream(serverProps));
          String moved = "", separator = "";

          if (properties.containsKey("level-name")) {
            String world = properties.getProperty("level-name", "world");
            config.set("server.world-name", world);
            moved += separator + "world name";
            separator = ", ";
          }

          if (properties.containsKey("online-mode")) {
            String value = properties.getProperty("online-mode", "true");
            boolean bool =
                value.equalsIgnoreCase("on")
                    || value.equalsIgnoreCase("yes")
                    || value.equalsIgnoreCase("true");
            config.set("server.online-mode", bool);
            moved += separator + "online mode";
            separator = ", ";
          }

          if (properties.containsKey("server-port")) {
            String value = properties.getProperty("server-port", "25565");
            try {
              int port = Integer.parseInt(value);
              config.set("server.port", port);
              moved += separator + "port";
              separator = ", ";
            } catch (NumberFormatException ex) {
            }
          }

          if (properties.containsKey("max-players")) {
            String value = properties.getProperty("max-players", "20");
            try {
              int players = Integer.parseInt(value);
              config.set("server.max-players", players);
              moved += separator + "max players";
              separator = ", ";
            } catch (NumberFormatException e) {
            }
          }

          if (properties.containsKey("motd")) {
            String motd = properties.getProperty("motd", "Glowstone server");
            config.set("server.motd", motd);
            moved += separator + "MOTD";
            separator = ", ";
          }

          if (properties.containsKey("gamemode")) {
            String value = properties.getProperty("gamemode", "0");
            try {
              int mode = Integer.parseInt(value);
              GameMode gMode = GameMode.getByValue(mode);
              if (gMode == null) gMode = GameMode.SURVIVAL;
              config.set("server.def-game-mode", gMode.name());
              moved += separator + "default game mode";
              separator = ", ";
            } catch (NumberFormatException ex) {
            }
          }

          // TODO: move nether, view distance, monsters, etc when implemented

          if (moved.length() > 0) {
            System.out.println("Copied " + moved + " from server.properties");
          }
        } catch (IOException ex) {
        }
      }
    }
    config.options().copyDefaults(true);
    config.save();
  }
Example #3
0
 public void setMotd(String motd) {
   config.set("server.motd", motd);
 }
Example #4
0
 public void setWhitelist(boolean enabled) {
   config.set("server.whitelist", enabled);
 }
Example #5
0
 public void setSpawnRadius(int value) {
   config.set("server.spawn-radius", value);
 }