Exemple #1
0
  public void playerSectionRead() {
    boolean isSection = (plugin.getConfig().isConfigurationSection("players"));

    if (isSection) {
      Map<String, Object> playerList =
          plugin.getConfig().getConfigurationSection("players").getValues(false);

      if (playerList != null) {
        //				System.out.println("PlayerClassRank List");
        for (String playerName : playerList.keySet()) {
          PlayerClazz playerClazz = new PlayerClazz(playerName, "");

          Map<String, Object> playerClassRank =
              plugin.getConfig().getConfigurationSection("players." + playerName).getValues(false);
          for (String clazzName : playerClassRank.keySet()) {
            String rankName =
                plugin.getConfig().getString("players." + playerName + "." + clazzName, "");
            playerClazz.addPlayerClassRank(clazzName, rankName);
          }
          playersClazzList.put(playerName, playerClazz);
        }
        // Test output
        for (PlayerClazz playerClazz : playersClazzList.values()) {
          for (String clazzName : playerClazz.playerClazzRanks().keySet()) {
            String rankName = playerClazz.playerClazzRanks().get(clazzName);
            //						System.out.println(playerClazz.getUuid() + ":" + clazzName+ ":" + rankName);
          }
        }
      }
    }
  }
Exemple #2
0
 /**
  * set PlayerSection to ConfigSection
  *
  * @param player
  * @param className
  * @param rank
  */
 public void playerSectionWrite(PlayerClazz playerClazz) {
   for (String clazzName : playerClazz.playerClazzRanks().keySet()) {
     String rank = playerClazz.playerClazzRanks().get(clazzName);
     plugin.getConfig().set("players." + playerClazz.getUuid() + "." + clazzName, rank);
     plugin.db.i(
         "Write to config rank "
             + rank
             + " to player "
             + playerClazz.getUuid()
             + ", no world support");
   }
   plugin.saveConfig();
 }
Exemple #3
0
 /**
  * Remove ClazzRank from player set PlayerSection to ConfigSection save config to File
  *
  * @param player
  * @param className
  */
 public void playerSectionRemove(Player player, String className) {
   if (className != null) {
     plugin.db.i("Remove config " + player.getUniqueId().toString() + " : " + className);
     PlayerClazz playerClazz = playersClazzList.get(player.getUniqueId().toString());
     if (playerClazz != null) {
       if (playerClazz.playerClazzRanks().containsKey(className)) {
         playerClazz.playerClazzRanks().remove(className);
         plugin.db.i("Save player section after remove ");
         playerSectionWrite(playerClazz);
         plugin.saveConfig();
       }
     }
   }
 }
Exemple #4
0
  /** write ClazzRankList to Config save config to File */
  public void writeClazzConfig() {
    plugin.db.i("saving config...");
    for (Clazz cClass : plugin.clazzList().getClazzes().values()) {
      plugin.db.i(" - " + cClass.clazzName());
      for (Rank rRank : cClass.ranks().values()) {

        plugin
            .getConfig()
            .set(
                "classes." + cClass.clazzName() + "." + rRank.getPermName() + ".name",
                String.valueOf(rRank.getDispName()));
        plugin
            .getConfig()
            .set(
                "classes." + cClass.clazzName() + "." + rRank.getPermName() + ".color",
                String.valueOf("&" + Integer.toHexString(rRank.getColor().ordinal())));
        plugin
            .getConfig()
            .set(
                "classes." + cClass.clazzName() + "." + rRank.getPermName() + ".price",
                String.valueOf(rRank.getCost()));

        if (rRank.getExp() > -1)
          plugin
              .getConfig()
              .set(
                  "classes." + cClass.clazzName() + "." + rRank.getPermName() + ".exp",
                  String.valueOf(rRank.getExp()));
        if (rRank.getItems() != null)
          plugin
              .getConfig()
              .set(
                  "classes." + cClass.clazzName() + "." + rRank.getPermName() + ".items",
                  rRank.getItems());
        if (rRank.getCost() != -1337D)
          plugin
              .getConfig()
              .set(
                  "classes." + cClass.clazzName() + "." + rRank.getPermName() + ".price",
                  String.valueOf(rRank.getCost()));
      }
    }
    plugin.saveConfig();
  }
Exemple #5
0
 /** write config data to configsection save config to file */
 public void saveConfig() {
   plugin.getConfig().set("debug", isDebug());
   plugin.getConfig().set("checkprices", isCheckprices());
   plugin.getConfig().set("checkexp", isCheckexp());
   plugin.getConfig().set("checkitems", isCheckitems());
   plugin.getConfig().set("clearranks", isClearranks());
   plugin.getConfig().set("onlyoneclass", isOnlyoneclass());
   plugin.getConfig().set("rankpublic", isRankpublic());
   plugin.getConfig().set("signcheck", isSigncheck());
   plugin.getConfig().set("cooldown", coolDown);
   plugin.saveConfig();
 }
Exemple #6
0
  /** Load Config file , stores data in parmeters */
  public void load_config() {

    if (plugin.getConfig() == null
        || !plugin.getConfig().getString("cversion").equals(debugVersion)) {
      ClassRanks.log("creating default config.yml", Level.INFO);
      plugin.getConfig().set("cversion", debugVersion);
      plugin.getConfig().options().copyDefaults(true);
      plugin.saveConfig();
    }
    // DebugManager.active = plugin.getConfig().getBoolean("debug", false);
    debug = plugin.getConfig().getBoolean("debug", false);
    plugin.db.active = debug;
    // AutoUpdate Config
    autoUpdate = plugin.getConfig().getBoolean("autoupdate", false);
    // UpdateCheck Config
    updateCheck = plugin.getConfig().getBoolean("updatecheck", false);

    // check for section is available
    checkprices = plugin.getConfig().getBoolean("checkprices", false);

    // useUUID
    useUUID = plugin.getConfig().getBoolean("useUUID", false);
    // permissionpluginhasworldsupport
    permissionpluginhasworldsupport =
        plugin.getConfig().getBoolean("permissionpluginhasworldsupport", true);
    boolean isSection = false;
    if (plugin.getConfig().getConfigurationSection("prices") != null) {
      isSection = true;
    }

    // if ( isCheckprices() && isSection)
    if (isSection) {
      plugin.db.i("Config prices reading...");
      // set prices
      prices =
          (Map<String, Object>)
              plugin.getConfig().getConfigurationSection("prices").getValues(true);

      if (prices.size() > 0) {
        moneyCost = new Double[prices.size()];
      } else {
        moneyCost = new Double[1];
      }

      int i = 0;
      for (String Key : prices.keySet()) {
        String sVal = (String) prices.get(Key);
        try {
          moneyCost[i] = Double.parseDouble(sVal);
          plugin.db.i("#" + i + " => " + String.valueOf(Double.parseDouble(sVal)));
        } catch (Exception e) {
          moneyCost[i] = 0.0;
          ClassRanks.log(
              "Unrecognized cost key '" + String.valueOf(Key) + "': " + sVal, Level.INFO);
        }
        i++;
      }
    }

    // check for section is available

    checkexp = plugin.getConfig().getBoolean("checkexp", false);
    isSection = (plugin.getConfig().getConfigurationSection("exp") != null);
    // if ((isCheckexp()) && (isSection))

    if (isSection) {
      // set exp prices
      plugin.db.i("CONFG exp costs reading...");

      expprices =
          (Map<String, Object>) plugin.getConfig().getConfigurationSection("exp").getValues(true);
      // cmdMgr.expCost = new int[expprices.size()];

      int i = 0;
      // array erweitern, wenn zu klein
      if (expCost.length < expprices.size()) {
        expCost = new int[expprices.size()];
      }
      // config in array uebertragen
      for (String Key : expprices.keySet()) {
        String sVal = (String) expprices.get(Key);
        ClassRanks.log("ExpPrice : " + sVal, Level.INFO);
        try {
          expCost[i] = Integer.parseInt(sVal);
          plugin.db.i("#" + i + " => " + String.valueOf(Integer.parseInt(sVal)));
        } catch (Exception e) {

          expCost = new int[i + 1];
          expCost[i] = 0;
          ClassRanks.log(
              "Unrecognized exp cost key '" + String.valueOf(Key) + "': " + sVal, Level.INFO);
        }
        i++;
      }
    }

    // set subcolors
    FormatManager.setColors(
        plugin.getConfig().getString("playercolor"), plugin.getConfig().getString("worldcolor"));

    // set other variables
    rankPublic = plugin.getConfig().getBoolean("rankpublic", false);

    defaultRankAllWorlds = plugin.getConfig().getBoolean("defaultrankallworlds", false);

    onlyOneClass = plugin.getConfig().getBoolean("onlyoneclass", true);

    trackRanks = plugin.getConfig().getBoolean("trackRanks", false);

    // Sign
    signcheck = plugin.getConfig().getBoolean("signcheck", false);

    plugin.db.i("sign check Read!");
    signs[0] = plugin.getConfig().getString("signchoose", "[choose]");
    signs[1] = plugin.getConfig().getString("signrankup", "[rankup]");
    signs[2] = plugin.getConfig().getString("signrankdown", "[rankdown]");

    setClearranks(plugin.getConfig().getBoolean("clearranks", false));

    // /PlayerManager.coolDown = plugin.getConfig().getInt("cooldown", 0);
    coolDown = plugin.getConfig().getInt("cooldown", 0);

    itemStacks = null;
    checkitems = plugin.getConfig().getBoolean("checkitems");

    // check section is available
    plugin.db.i("read items section");
    isSection = plugin.getConfig().getConfigurationSection("items") != null;
    // item read and check
    if (isSection) {
      plugin.db.i("items exist, parsing...");

      items =
          (Map<String, Object>)
              plugin.getConfig().getConfigurationSection("items").getValues(false);
      // items error check
      if (items == null) {
        plugin.db.i("items invalid, setting to null");
        itemStacks = new ItemStack[plugin.clazzList().getClazzes().size()][1];
      } else {
        // for each items => ItemStack[][1,2,3]
        int iI = 0;
        itemStacks = new ItemStack[items.size()][];
        for (String isKey : items.keySet()) {
          plugin.db.i("Item Key : " + isKey.toString());
          List<?> values = plugin.getConfig().getList("items." + isKey);
          itemStacks[iI] = new ItemStack[values.size()];
          plugin.db.i("creating itemstack:");
          for (int iJ = 0; iJ < values.size(); iJ++) {
            String[] vValue = (String.valueOf(values.get(iJ))).split(":");

            int vAmount = vValue.length > 1 ? Integer.parseInt(vValue[1]) : 1;
            try {
              itemStacks[iI][iJ] = new ItemStack(Material.valueOf(vValue[0]), vAmount);

            } catch (Exception e) {

              ClassRanks.log("Unrecognized reagent: " + vValue[0], Level.WARNING);
              continue;
            }
          }
          plugin.db.i(iI + " - " + FormatManager.formatItemStacks(itemStacks[iI]));
          iI++;
        }
      }
    }
    setRankItems(itemStacks);

    // read basis class and ranks initialize the object
    Map<String, Object> classes =
        plugin.getConfig().getConfigurationSection("classes").getValues(false);
    for (String sClassName : classes.keySet()) {
      Map<String, Object> ranks = ((ConfigurationSection) classes.get(sClassName)).getValues(false);
      for (String sRankName : ranks.keySet()) {
        // Rank definition
        // this.sPermissionName = sPermName;
        // this.sDisplayName = sDispName;
        // this.cColor = cC;
        // this.crcSuper = crc;
        // this.items = isItems;
        // this.cost = dCost;
        // this.exp = iExp;

        String rankName = null;
        String rankColor = "&f";
        double rankCost = -1337D;
        ItemStack[] rankItems = null;
        int rankExp = -1;
        String nodeName = "classes." + sClassName + "." + sRankName + ".name";
        if (plugin.getConfig().get(nodeName) != null) {
          rankName = plugin.getConfig().getString(nodeName);
        }
        nodeName = "classes." + sClassName + "." + sRankName + ".color";
        if (plugin.getConfig().get(nodeName) != null) {
          rankColor = plugin.getConfig().getString(nodeName);
        }
        nodeName = "classes." + sClassName + "." + sRankName + ".price";
        if (plugin.getConfig().get(nodeName) != null) {
          rankCost = Double.valueOf(plugin.getConfig().getString(nodeName));
        }
        nodeName = "classes." + sClassName + "." + sRankName + ".items";
        if (plugin.getConfig().get(nodeName) != null) {
          rankItems =
              FormatManager.getItemStacksFromStringList(plugin.getConfig().getStringList(nodeName));
        }
        nodeName = "classes." + sClassName + "." + sRankName + ".exp";
        if (plugin.getConfig().get(nodeName) != null) {
          rankExp = Integer.parseInt(plugin.getConfig().getString(nodeName));
        }

        plugin
            .clazzList()
            .importClazz(
                sClassName, sRankName, rankName, rankColor, rankItems, rankCost, rankExp, null);
      }
    }

    // getConfig().getString("progress."+pPlayer.getName());
    playerSectionRead();

    plugin.saveConfig();
  }