Package org.bukkit.configuration.file

Examples of org.bukkit.configuration.file.FileConfiguration


      // check if the player won anything
      Player p = (Player) sender;
      String pName = p.getName();
      if (quizWinners.containsKey(pName)) {
        // load all items for this player's reward
        FileConfiguration f = CommandsEX.getConf();
        ConfigurationSection configGroups = f.getConfigurationSection("quizDiff." + quizWinners.get(pName));
        Set<String> s = configGroups.getKeys(false);
       
        // first of all, count all rewards and see if they'd fit into player's inventory
        Integer allBlocks = 0;
        Inventory pi = p.getInventory();
        Integer maxStackSize = pi.getMaxStackSize();
        for (String reward : s) {
          Integer blockCount = f.getInt("quizDiff." + quizWinners.get(pName) + "." + reward);
          if (blockCount > maxStackSize) {
            allBlocks = (int) (allBlocks + Math.ceil(blockCount / maxStackSize));
          } else {
            allBlocks++;
          }
        }
       
        // calculate available slots
        Integer fullSlots = 0;
        for (ItemStack istack : p.getInventory().getContents()) {
          if ((istack != null) && istack.getAmount() > 0) {
            fullSlots++;
          }
        }
 
        if ((pi.getSize() - fullSlots) >= allBlocks) {
          // fill player's inventory with the reward
          for (String reward : s) {
            try {
              if (reward.contains(":")) {
                String[] expl = reward.split(":");
                pi.addItem(new ItemStack(Integer.parseInt(expl[0]), f.getInt("quizDiff." + quizWinners.get(pName) + "." + reward), (short) 0, Byte.parseByte(expl[1])));
              } else {
                pi.addItem(new ItemStack(Integer.parseInt(reward), f.getInt("quizDiff." + quizWinners.get(pName) + "." + reward)));
              }
            } catch (Throwable e) {
              // unable to add item into inventory, inform server owner
              LogHelper.logSevere("[CommandsEX] " + _("quizUnableToAddItem", "") + reward + ":" + f.getInt("quizDiff." + quizWinners.get(pName) + "." + reward));
              LogHelper.logDebug("Message: " + e.getMessage() + ", cause: " + e.getCause());
            }
          }
         
          // tell player to check inventory for rewards
View Full Code Here


          quizRunning = false;
        }
   
    try {
      // start new quiz
      FileConfiguration f = CommandsEX.getConf();
      ConfigurationSection configGroups = f.getConfigurationSection("quizzes");
      Set<String> s = configGroups.getKeys(false);
      Integer len = s.size();
      String quizName = null;
     
      if (len > 0) {
        // pick a random one
        Integer pos = (0 + (int)(Math.random() * ((len - 1) + 1)));
        Object[] quizNames = s.toArray();
        quizName = (String) quizNames[pos];
        quizQuestion = f.getString("quizzes." + quizName + ".question", "Ping");
        quizDifficulty = f.getString("quizzes." + quizName + ".difficulty", "easy");
        quizCaseSensitive = f.getBoolean("quizDiff." + quizDifficulty + ".caseSentisive", false);
        quizAnswers = (List<String>) f.getList("quizzes." + quizName + ".answers");
        Integer quizDelay = f.getInt("quizDelay", 10);
       
        // make answers lowecase if the answer we expect does not depend on letters case
        if (!quizCaseSensitive) {
          ListIterator<String> iterator = quizAnswers.listIterator();
            while (iterator.hasNext())
View Full Code Here

      CommandsEX.plugin.getServer().broadcastMessage(ChatColor.GREEN + _("quizWinner1", ""));
      CommandsEX.plugin.getServer().broadcastMessage(ChatColor.YELLOW + _("quizWinner2", "") + ChatColor.WHITE + msg);
      CommandsEX.plugin.getServer().broadcastMessage(ChatColor.YELLOW + _("quizWinner3", "") + ChatColor.WHITE + pName);
     
      // select a random reward
      FileConfiguration f = CommandsEX.getConf();
     
      try {
        ConfigurationSection configGroups = f.getConfigurationSection("quizDiff." + quizDifficulty);
        Set<String> s = configGroups.getKeys(false);
        s.remove("caseSentisive");
        Integer len = s.size();
        String rewardName = null;
     
View Full Code Here

   * @return
   */
  public static void list(CommandSender sender, String[] args) {
    // show all kits available to us
    List<String> available = new ArrayList<String>();
    FileConfiguration f = CommandsEX.getConf();
    ConfigurationSection configGroups = f.getConfigurationSection("kits");
    if (configGroups != null){
      Set<String> kitGroups = configGroups.getKeys(false);
     
      for (String group : kitGroups) {
        if (group.equals("*") || ((sender instanceof Player) && Permissions.checkPermEx(((Player)sender), "cex.kits." + group)) || !(sender instanceof Player)) {
          ConfigurationSection kits = f.getConfigurationSection("kits." + group);
          Set<String> kitNames = kits.getKeys(false);
         
          for (String kit : kitNames) {
            available.add(kit);
          }
View Full Code Here

    Integer kitsAdded = 0;
    Integer stamp = Utils.getUnixTimestamp(0L);

    if (!Utils.checkCommandSpam(sendingPlayer, "kits-give")) {
      // check if we can use the kit in question
      FileConfiguration f = CommandsEX.getConf();
      ConfigurationSection kitConfigGroups = f.getConfigurationSection("kits");
      if (kitConfigGroups != null){
        Set<String> kitGroups = kitConfigGroups.getKeys(false);

        for (String group : kitGroups) {
          if (group.equals("*") || Permissions.checkPermEx(sendingPlayer, "cex.kits." + group)) {
            ConfigurationSection kits = f.getConfigurationSection("kits." + group);
            Set<String> kitNames = kits.getKeys(false);

            for (String kit : kitNames) {
              if (kit.equalsIgnoreCase(args[0])) {
                if (f.getBoolean("kits." + group + "." + kit + ".onetime", false) && usedOneTimeKits.containsKey(pName)) {
                  // a one-time kit that was used by this player already
                  oneTimeKitWarning = true;
                } else if ((f.getInt("kits." + group + "." + kit + ".cooldown", 0) > 0) && !Permissions.checkPermEx(player, "cex.kits.cooldown.bypass") && kitCooldowns.containsKey(pName) && ((stamp - kitCooldowns.get(pName)) < f.getInt("kits." + group + "." + kit + ".cooldown"))) {
                  // kit on a cooldown
                  cooldownWarning = true;
                } else {
                  // one-time kit?
                  if (f.getBoolean("kits." + group + "." + kit + ".onetime", false)) {
                    // store one-time usage into database - if this returns error, the record already exists, so we just return a warning
                    if (CommandsEX.sqlEnabled) {
                      SQLManager.omitErrorLogs = true;
                      if (!SQLManager.query("INSERT INTO "+ SQLManager.prefix +"kits_usage VALUES (?, ?)", pName, kit)) {
                        oneTimeKitWarning = true;
                      } else {
                        usedOneTimeKits.put(pName, kit);
                      }
                      SQLManager.omitErrorLogs = false;
                    }
                  }

                  // cooldown kit?
                  if (f.getInt("kits." + group + "." + kit + ".cooldown", 0) > 0) {
                    kitCooldowns.put(pName, Utils.getUnixTimestamp(0L));
                  }

                  // if we don't have a one-time kit warning from database, give items to the player
                  if (!oneTimeKitWarning) {
                    // load all items for this player's reward
                    ConfigurationSection configGroups = f.getConfigurationSection("kits." + group + "." + kit);
                    Set<String> s = configGroups.getKeys(false);
                    // remove onetime and cooldown keys
                    s.remove("onetime");
                    s.remove("cooldown");
                    s.remove("onjoin");

                    // first of all, count all kit blocks and see if they'd fit into player's inventory
                    Integer allBlocks = 0;
                    Inventory pi = player.getInventory();
                    Integer maxStackSize = pi.getMaxStackSize();
                    for (String kitItem : s) {
                      Integer blockCount = f.getInt("kits." + group + "." + kit + "." + kitItem);
                      if (blockCount > maxStackSize) {
                        allBlocks = (int) (allBlocks + Math.ceil(blockCount / maxStackSize));
                      } else {
                        allBlocks++;
                      }
                    }

                    // calculate available slots
                    Integer fullSlots = 0;
                    for (ItemStack istack : player.getInventory().getContents()) {
                      if ((istack != null) && istack.getAmount() > 0) {
                        fullSlots++;
                      }
                    }

                    if ((pi.getSize() - fullSlots) >= allBlocks) {
                      // fill player's inventory with kit items
                      for (String kitItem : s) {
                        try {
                          if (kitItem.contains(":")) {
                            String[] expl = kitItem.split(":");
                            pi.addItem(new ItemStack(Integer.parseInt(expl[0]), f.getInt("kits." + group + "." + kit + "." + kitItem), (short) 0, Byte.parseByte(expl[1])));
                          } else {
                            pi.addItem(new ItemStack(Integer.parseInt(kitItem), f.getInt("kits." + group + "." + kit + "." + kitItem)));
                          }
                        } catch (Throwable e) {
                          // unable to add item into inventory, inform server owner
                          LogHelper.logSevere("[CommandsEX] " + _("kitsUnableToAddItem", "") + kitItem + ":" + f.getInt("kits." + group + "." + kit + "." + kitItem));
                          LogHelper.logDebug("Message: " + e.getMessage() + ", cause: " + e.getCause());
                        }
                      }
                      kitsAdded++;
                    } else {
View Full Code Here

  @EventHandler(priority = EventPriority.LOWEST)
  public void giveInitialKits(PlayerJoinEvent e) {
    Player player = e.getPlayer();
    if (player.hasPlayedBefore()) return;

    FileConfiguration f = CommandsEX.getConf();
    ConfigurationSection kitConfigGroups = f.getConfigurationSection("kits");
    if (kitConfigGroups == null) return;
   
    Set<String> kitGroups = kitConfigGroups.getKeys(false);
   
    for (String group : kitGroups) {
      if (group.equals("*") || Permissions.checkPermEx(player, "cex.kits." + group)) {
        ConfigurationSection kits = f.getConfigurationSection("kits." + group);
        Set<String> kitNames = kits.getKeys(false);
       
        for (String kit : kitNames) {
          if (f.getBoolean("kits." + group + "." + kit + ".onjoin", false)) {
            // we have an on-join kit, give it out
            give(player, new String[] {kit}, true);
          }
        }
      }
View Full Code Here

  public static String cmdPrefix;
  public static final CommanderCommandSender ccs = new CommanderCommandSender();
  public static Integer lastMessageStamp = Utils.getUnixTimestamp(0L);

  public XMPPer() {
    FileConfiguration cnf = CommandsEX.getConf();
    if (cnf.getBoolean("xmppEnabled")) {
      LogHelper.logInfo("[CommandsEX] " + _("xmppConnecting", ""));
      cmdPrefix = cnf.getString("xmppCommandPrefix", "#");
      participantNicks = new HashMap<String, String>();
      xmppConnection = new XMPPConnection(cnf.getString("xmppHost", "localhost"));
      try {
        xmppConnection.connect();
        if (cnf.getString("xmppUser", "").equals("")) {
          LogHelper.logInfo(_("xmppAnonymousLogin", ""));
          xmppConnection.loginAnonymously();
        } else {
          xmppConnection.login(cnf.getString("xmppUser"), cnf.getString("xmppPassword", ""));
        }
        // Only do this if the connection didn't fail
        DiscussionHistory history = new DiscussionHistory();
        history.setMaxStanzas(0);
        chatRoom = new MultiUserChat(xmppConnection, cnf.getString("xmppRoom.name"));
        chatRoom.addMessageListener(this);
        chatRoom.addParticipantStatusListener(this);
        chatRoom.addSubjectUpdatedListener(this);
        chatRoom.addUserStatusListener(this);
        try {
          chatRoom.join(cnf.getString("xmppBotNick", "CommandsEX"), cnf.getString("xmppRoom.password", ""), history, SmackConfiguration.getPacketReplyTimeout());
          for (Occupant occupant : chatRoom.getParticipants()) {
            participantNicks.put(occupant.getJid(), occupant.getNick());
          }
        } catch(XMPPException e) {
          LogHelper.logSevere("[CommandsEX] " + _("xmppUnableToJoinRoom", ""));
View Full Code Here

   * The actual delayed task to check for timed promotions and promote as needed.
   * Used in 2 places - delayed task and Quit event.
   */
  public static void checkTimedPromotions(Player...players) {
    // load up settings from config file
    FileConfiguration f = CommandsEX.getConf();
    ConfigurationSection configGroups = f.getConfigurationSection("timedPromote");
    boolean promoteSet = CommandsEX.getConf().getBoolean("promoteSet");
   
    // no groups defined
    if (configGroups == null) {
      return;
    }
   
    Map<String, Integer> settings = new HashMap<String, Integer>();
    List<?> exclusions = CommandsEX.getConf().getList("timedPromoteExclude", new ArrayList<String>());
    Set<String> keys = configGroups.getKeys(true);
   
    if (keys.size() > 0) {
      for (String s : keys) {
        // ignore default group with time 0, since that one is an example record
        if (s.equals("default") && (f.getInt("timedPromote." + s) == 0)) continue;
        settings.put(s, f.getInt("timedPromote." + s));
      }
    }
   
    // run through all online players and check their playtime
    Iterator<Entry<String, Integer>> it = CommandsEX.playTimes.entrySet().iterator();
View Full Code Here

   * The actual delayed task to check for economy-based promotions and promote as needed.
   * Used in 2 places - delayed task and Quit event.
   */
  public static void checkEcoPromotions(Player...players) {
    // load up settings from config file
    FileConfiguration f = CommandsEX.getConf();
    ConfigurationSection configGroups = f.getConfigurationSection("ecoPromote");
    boolean promoteSet = CommandsEX.getConf().getBoolean("promoteSet");
   
    // no groups defined
    if (configGroups == null) {
      return;
    }
   
    Map<String, Double> settings = new HashMap<String, Double>();
    List<?> exclusions = CommandsEX.getConf().getList("ecoPromoteExclude", new ArrayList<String>());
    Boolean checkDemotions = f.getBoolean("ecoPromoteAutoDemote");
    Set<String> keys = configGroups.getKeys(true);
   
    if (keys.size() > 0) {
      for (String s : configGroups.getKeys(true)) {
        // ignore default group with wealth of 0, since that one is an example record
        if (s.equals("default") && (f.getInt("ecoPromote." + s) == 0)) continue;
        settings.put(s, f.getDouble("ecoPromote." + s));
      }
    }
   
    // run through all online players and check their wealth
    for(Player p : Bukkit.getServer().getOnlinePlayers()) {
View Full Code Here

      LogHelper.logDebug("[CommandsEX] time2rank could not be invoked because Vault or at least 1 permission plugin is not present");
      return true;
    }
   
    // load up settings from config file
    FileConfiguration f = CommandsEX.getConf();
    ConfigurationSection configGroups = f.getConfigurationSection("timedPromote");
    Player p = (Player)sender;
    Long currentGroupTime = f.getLong("timedPromote." + Vault.perms.getPrimaryGroup(p));
    Long nextGroupTime = 9223372036854775807L; // maximum value of LONG in Java
    String nextRankName = "?";
    for (String s : configGroups.getKeys(true)) {
      // ignore default group with time 0, since that one is an example record
      Long t = f.getLong("timedPromote." + s);
      if (s.equals("default") && (t == 0)) continue;
     
      // check if this group has more time set than current one and set it as the next group's time
      if (t > currentGroupTime) {
        // if our current time for next group is higher than the one we found now, use the one we found,
View Full Code Here

TOP

Related Classes of org.bukkit.configuration.file.FileConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.