/** Binds the query server to the address specified in the configuration. */
  private void bindQuery() {
    if (!config.getBoolean(ServerConfig.Key.QUERY_ENABLED)) {
      return;
    }

    SocketAddress address = getBindAddress(ServerConfig.Key.QUERY_PORT);
    queryServer = new QueryServer(this, config.getBoolean(ServerConfig.Key.QUERY_PLUGINS));

    logger.info("Binding query to address: " + address + "...");
    ChannelFuture future = queryServer.bind(address);
    Channel channel = future.awaitUninterruptibly().channel();
    if (!channel.isActive()) {
      logger.warning("Failed to bind query. Address already in use?");
    }
  }
  /** Load the server configuration. */
  private void loadConfig() {
    config.load();

    // modifiable values
    spawnRadius = config.getInt(ServerConfig.Key.SPAWN_RADIUS);
    whitelistEnabled = config.getBoolean(ServerConfig.Key.WHITELIST);
    idleTimeout = config.getInt(ServerConfig.Key.PLAYER_IDLE_TIMEOUT);
    craftingManager.initialize();

    // special handling
    warnState = Warning.WarningState.value(config.getString(ServerConfig.Key.WARNING_STATE));
    try {
      defaultGameMode = GameMode.valueOf(config.getString(ServerConfig.Key.GAMEMODE));
    } catch (IllegalArgumentException | NullPointerException e) {
      defaultGameMode = GameMode.SURVIVAL;
    }

    // server icon
    defaultIcon = new GlowServerIcon();
    try {
      File file = config.getFile("server-icon.png");
      if (file.isFile()) {
        defaultIcon = new GlowServerIcon(file);
      }
    } catch (Exception e) {
      logger.log(Level.WARNING, "Failed to load server-icon.png", e);
    }
  }
  /** Binds the rcon server to the address specified in the configuration. */
  private void bindRcon() {
    if (!config.getBoolean(ServerConfig.Key.RCON_ENABLED)) {
      return;
    }

    SocketAddress address = getBindAddress(ServerConfig.Key.RCON_PORT);
    rconServer = new RconServer(this, config.getString(ServerConfig.Key.RCON_PASSWORD));

    logger.info("Binding rcon to address: " + address + "...");
    ChannelFuture future = rconServer.bind(address);
    Channel channel = future.awaitUninterruptibly().channel();
    if (!channel.isActive()) {
      logger.warning("Failed to bind rcon. Address already in use?");
    }
  }
 /**
  * Get whether achievements should be announced.
  *
  * @return True if achievements should be announced in chat.
  */
 public boolean getAnnounceAchievements() {
   return config.getBoolean(ServerConfig.Key.ANNOUNCE_ACHIEVEMENTS);
 }
 /**
  * Get whether to use color codes in Rcon responses.
  *
  * @return True if color codes will be present in Rcon responses
  */
 public boolean useRconColors() {
   return config.getBoolean(ServerConfig.Key.RCON_COLORS);
 }
 /**
  * Get whether parsing of data provided by a proxy is enabled.
  *
  * @return True if a proxy is providing data to use.
  */
 public boolean getProxySupport() {
   return config.getBoolean(ServerConfig.Key.PROXY_SUPPORT);
 }
 /**
  * Get whether worlds should keep their spawns loaded by default.
  *
  * @return Whether to keep spawns loaded by default.
  */
 public boolean keepSpawnLoaded() {
   return config.getBoolean(ServerConfig.Key.PERSIST_SPAWN);
 }
  /** Starts this server. */
  public void start() {
    // Determine console mode and start reading input
    consoleManager.startConsole(config.getBoolean(ServerConfig.Key.USE_JLINE));
    consoleManager.startFile(config.getString(ServerConfig.Key.LOG_FILE));

    if (getProxySupport()) {
      if (getOnlineMode()) {
        logger.warning("Proxy support is enabled, but online mode is enabled.");
      } else {
        logger.info("Proxy support is enabled.");
      }
    } else if (!getOnlineMode()) {
      logger.warning(
          "The server is running in offline mode! Only do this if you know what you're doing.");
    }

    // Load player lists
    opsList.load();
    whitelist.load();
    nameBans.load();
    ipBans.load();

    // DRAGONET-Start
    this.dragonetServer = new DragonetServer(this);
    this.dragonetServer.initialize();
    // DRAGONET-End

    // Start loading plugins
    loadPlugins();
    enablePlugins(PluginLoadOrder.STARTUP);

    // Create worlds
    String name = config.getString(ServerConfig.Key.LEVEL_NAME);
    String seedString = config.getString(ServerConfig.Key.LEVEL_SEED);
    boolean structs = getGenerateStructures();
    WorldType type = WorldType.getByName(getWorldType());
    if (type == null) {
      type = WorldType.NORMAL;
    }

    long seed = new Random().nextLong();
    if (!seedString.isEmpty()) {
      try {
        long parsed = Long.parseLong(seedString);
        if (parsed != 0) {
          seed = parsed;
        }
      } catch (NumberFormatException ex) {
        seed = seedString.hashCode();
      }
    }

    createWorld(
        WorldCreator.name(name)
            .environment(Environment.NORMAL)
            .seed(seed)
            .type(type)
            .generateStructures(structs));
    if (getAllowNether()) {
      createWorld(
          WorldCreator.name(name + "_nether")
              .environment(Environment.NETHER)
              .seed(seed)
              .type(type)
              .generateStructures(structs));
    }
    if (getAllowEnd()) {
      createWorld(
          WorldCreator.name(name + "_the_end")
              .environment(Environment.THE_END)
              .seed(seed)
              .type(type)
              .generateStructures(structs));
    }

    // Finish loading plugins
    enablePlugins(PluginLoadOrder.POSTWORLD);
    commandMap.registerServerAliases();
    scheduler.start();
  }
 @Override
 public boolean useExactLoginLocation() {
   return config.getBoolean(ServerConfig.Key.EXACT_LOGIN_LOCATION);
 }
 @Override
 public boolean getAllowFlight() {
   return config.getBoolean(ServerConfig.Key.ALLOW_FLIGHT);
 }
 @Override
 public boolean isHardcore() {
   return config.getBoolean(ServerConfig.Key.HARDCORE);
 }
 @Override
 public boolean getGenerateStructures() {
   return config.getBoolean(ServerConfig.Key.GENERATE_STRUCTURES);
 }
 @Override
 public boolean getAllowEnd() {
   return config.getBoolean(ServerConfig.Key.ALLOW_END);
 }
 @Override
 public boolean getAllowNether() {
   return config.getBoolean(ServerConfig.Key.ALLOW_NETHER);
 }
 @Override
 public boolean getOnlineMode() {
   return config.getBoolean(ServerConfig.Key.ONLINE_MODE);
 }