Example #1
0
  /** 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);
    }
  }
  /** Creates or loads the config file. */
  public void loadPluginConfig() {
    this.settings = new Settings();
    ItemStack[] itemsChest = {
      new ItemStack(Material.ICE, 2),
      new ItemStack(Material.SAPLING, 5),
      new ItemStack(Material.MELON, 3),
      new ItemStack(Material.CACTUS, 1),
      new ItemStack(Material.LAVA_BUCKET, 1),
      new ItemStack(Material.PUMPKIN, 1)
    };

    if (!this.filePlugin.exists()) {
      settings.setIslandDistance(50);
      settings.setItemsChest(itemsChest);
      settings.setIsOnline(true);
      settings.setAllowContent(false);
      settings.setLanguage("english");
      settings.setGameMode(GameMode.BUILD);
      settings.setIslandsPerPlayer(1);
      settings.setLivesPerIsland(1);
      settings.setRespawnWithInventory(true);
      settings.setWithProtectedArea(true);
      settings.setAllowEnderPearl(false);
      settings.setWorldName(this.getDescription().getName());
      settings.setRemoveCreaturesByTeleport(true);
      settings.setIslandSchematic("");
      settings.setIslandYPosition(64);
      settings.setTowerSchematic("");
      settings.setTowerYPosition(80);

      for (EnumPluginConfig c : EnumPluginConfig.values()) {
        this.setStringbyPath(this.configPlugin, this.filePlugin, c.getPath(), c.getValue());
      }
    } else {
      try {
        this.configPlugin.load(this.filePlugin);
      } catch (Exception e) {
        e.printStackTrace();
      }

      try {
        settings.setIslandDistance(
            Integer.parseInt(
                this.getStringbyPath(
                    this.configPlugin,
                    this.filePlugin,
                    EnumPluginConfig.OPTIONS_ISLANDDISTANCE.getPath(),
                    50,
                    true)));
      } catch (Exception e) {
        settings.setIslandDistance(50);
      }

      String[] dataItems =
          this.getStringbyPath(
                  this.configPlugin,
                  this.filePlugin,
                  EnumPluginConfig.OPTIONS_CHESTITEMS.getPath(),
                  "79:2 6:5 360:3 81:1 327:1 86:1",
                  true)
              .split(" ");
      ArrayList<ItemStack> alitemsChest = new ArrayList<ItemStack>();

      for (String s : dataItems) {
        if (s.trim() != "") {
          String[] dataValues = s.split(":");
          try {
            int id = Integer.parseInt(dataValues[0]);
            int amount = Integer.parseInt(dataValues[1]);

            Material m = Material.matchMaterial("" + dataValues[0]);
            if (m != null) {
              if (dataValues.length == 2) {
                alitemsChest.add(new ItemStack(id, amount));
              } else if (dataValues.length == 3) {
                alitemsChest.add(
                    new ItemStack(id, amount, (short) 0, Byte.parseByte(dataValues[2])));
              }
            }

          } catch (Exception ex) {
          }
        }
      }

      itemsChest = new ItemStack[alitemsChest.size()];
      for (int i = 0; i < itemsChest.length; i++) {
        itemsChest[i] = alitemsChest.get(i);
      }

      try {
        settings.setLivesPerIsland(
            Integer.parseInt(
                this.getStringbyPath(
                    this.configPlugin,
                    this.filePlugin,
                    EnumPluginConfig.OPTIONS_PVP_LIVESPERISLAND.getPath(),
                    1,
                    true)));
      } catch (Exception e) {
        settings.setLivesPerIsland(1);
      }

      try {
        settings.setIslandsPerPlayer(
            Integer.parseInt(
                this.getStringbyPath(
                    this.configPlugin,
                    this.filePlugin,
                    EnumPluginConfig.OPTIONS_PVP_ISLANDSPERPLAYER.getPath(),
                    1,
                    true)));
      } catch (Exception e) {
        settings.setIslandsPerPlayer(1);
      }

      try {
        settings.setTowerYPosition(
            Integer.parseInt(
                this.getStringbyPath(
                    this.configPlugin,
                    this.filePlugin,
                    EnumPluginConfig.OPTIONS_SCHEMATIC_TOWER_YHEIGHT.getPath(),
                    80,
                    true)));
      } catch (Exception e) {
        settings.setTowerYPosition(80);
      }

      try {
        settings.setIslandYPosition(
            Integer.parseInt(
                this.getStringbyPath(
                    this.configPlugin,
                    this.filePlugin,
                    EnumPluginConfig.OPTIONS_SCHEMATIC_ISLAND_Y_POSITION.getPath(),
                    64,
                    true)));
        if (settings.getIslandYPosition() < 0) {
          settings.setIslandYPosition(64);
        }
      } catch (Exception e) {
        settings.setIslandYPosition(64);
      }

      settings.setItemsChest(itemsChest);
      settings.setIsOnline(
          Boolean.parseBoolean(
              this.getStringbyPath(
                  this.configPlugin,
                  this.filePlugin,
                  EnumPluginConfig.OPTIONS_SKYBLOCKONLINE.getPath(),
                  true,
                  true)));
      settings.setLanguage(
          this.getStringbyPath(
              this.configPlugin,
              this.filePlugin,
              EnumPluginConfig.OPTIONS_LANGUAGE.getPath(),
              "english",
              true));
      settings.setAllowContent(
          Boolean.parseBoolean(
              this.getStringbyPath(
                  this.configPlugin,
                  this.filePlugin,
                  EnumPluginConfig.OPTIONS_ALLOWCONTENT.getPath(),
                  false,
                  true)));
      settings.setGameMode(
          GameMode.valueOf(
              this.getStringbyPath(
                      this.configPlugin,
                      this.filePlugin,
                      EnumPluginConfig.OPTIONS_GAMEMODE.getPath(),
                      "build",
                      true)
                  .toUpperCase()));
      settings.setRespawnWithInventory(
          Boolean.parseBoolean(
              this.getStringbyPath(
                  this.configPlugin,
                  this.filePlugin,
                  EnumPluginConfig.OPTIONS_BUILD_RESPAWNWITHINVENTORY.getPath(),
                  true,
                  true)));
      settings.setWithProtectedArea(
          Boolean.parseBoolean(
              this.getStringbyPath(
                  this.configPlugin,
                  this.filePlugin,
                  EnumPluginConfig.OPTIONS_BUILD_WITHPROTECTEDAREA.getPath(),
                  true,
                  true)));
      settings.setAllowEnderPearl(
          Boolean.parseBoolean(
              this.getStringbyPath(
                  this.configPlugin,
                  this.filePlugin,
                  EnumPluginConfig.OPTIONS_BUILD_ALLOWENDERPEARL.getPath(),
                  false,
                  true)));
      settings.setWithProtectedBorder(
          Boolean.parseBoolean(
              this.getStringbyPath(
                  this.configPlugin,
                  this.filePlugin,
                  EnumPluginConfig.OPTIONS_BUILD_WITHPROTECTEDBORDER.getPath(),
                  true,
                  true)));
      settings.setWorldName(
          this.getStringbyPath(
              this.configPlugin,
              this.filePlugin,
              EnumPluginConfig.OPTIONS_WORLDNAME.getPath(),
              this.getDescription().getName(),
              true));
      settings.setIsLocked(
          Boolean.parseBoolean(
              this.getStringbyPath(
                  this.configPlugin,
                  this.filePlugin,
                  EnumPluginConfig.OPTIONS_CLOSED.getPath(),
                  false,
                  true)));
      settings.setRemoveCreaturesByTeleport(
          Boolean.parseBoolean(
              this.getStringbyPath(
                  this.configPlugin,
                  this.filePlugin,
                  EnumPluginConfig.OPTIONS_REMOVECREATURESBYTELEPORT.getPath(),
                  true,
                  true)));
      settings.setIslandSchematic(
          this.getStringbyPath(
              this.configPlugin,
              this.filePlugin,
              EnumPluginConfig.OPTIONS_SCHEMATIC_ISLAND_FILENAME.getPath(),
              "",
              true));
      settings.setTowerSchematic(
          this.getStringbyPath(
              this.configPlugin,
              this.filePlugin,
              EnumPluginConfig.OPTIONS_SCHEMATIC_TOWER_FILENAME.getPath(),
              "",
              true));
    }
  }