Esempio n. 1
0
 public KitInfo(ConfigurationSection config) {
   this(config.getName());
   icon = config.getItemStack("icon");
   helmet = config.getItemStack("helmet");
   chest = config.getItemStack("chest");
   legs = config.getItemStack("legs");
   boots = config.getItemStack("boots");
   try {
     items = (List<ItemStack>) config.get("items", new ArrayList<ItemStack>());
   } catch (ClassCastException e) {
     Bukkit.getLogger().log(Level.WARNING, "[SimpleTeamPvP] Could not load items for kit " + name);
   }
 }
 @Override
 protected void load(ConfigurationSection config) {
   super.load(config);
   costs = new HashMap<ItemStack, Cost>();
   ConfigurationSection costsSection = config.getConfigurationSection("costs");
   if (costsSection != null) {
     for (String key : costsSection.getKeys(false)) {
       ConfigurationSection itemSection = costsSection.getConfigurationSection(key);
       ItemStack item = itemSection.getItemStack("item");
       if (itemSection.contains("attributes")) {
         String attr = itemSection.getString("attributes");
         if (attr != null && !attr.isEmpty()) {
           item = NMSManager.getProvider().loadItemAttributesFromString(item, attr);
         }
       }
       Cost cost = new Cost();
       cost.amount = itemSection.getInt("amount");
       cost.item1 = itemSection.getItemStack("item1");
       cost.item2 = itemSection.getItemStack("item2");
       costs.put(item, cost);
     }
   }
 }
  public Map<UUID, ItemStack> getVaultContents(Player p) {

    String vaultPath = new StringBuilder(43).append("vaults.").append(p.getUniqueId()).toString();
    ConfigurationSection singlePlayerVaultSection = data.getConfigurationSection(vaultPath);

    HashMap<UUID, ItemStack> result = new HashMap<>();

    for (String lotUuidString : singlePlayerVaultSection.getKeys(false)) {

      if (lotUuidString.length() != 36) continue; // There is an itemCount field

      result.put(
          UUID.fromString(lotUuidString), singlePlayerVaultSection.getItemStack(lotUuidString));
    }

    return result;
  }
  /**
   * Loads the inventories items.
   *
   * @param inventory
   * @param file
   * @throws InvalidConfigurationException
   * @throws IOException
   * @throws FileNotFoundException
   */
  public void loadInventory(Inventory inventory, File file)
      throws IOException, InvalidConfigurationException {
    YamlConfiguration yaml = new AlphaYamlConfiguration();
    yaml.load(file);

    int size = yaml.getInt("size", 6 * 9);

    ConfigurationSection items = yaml.getConfigurationSection("items");
    for (int slot = 0; slot < size; slot++) {
      if (slot < inventory.getSize()) {
        if (items.isItemStack(slot + "")) {
          ItemStack item = items.getItemStack(slot + "");
          inventory.setItem(slot, item);
        }
      }
    }
  }
  private void load() {

    ConfigurationSection lotsSection = data.getConfigurationSection("lots");

    for (String uuidString : lotsSection.getKeys(false)) {

      ConfigurationSection singleLotSection = lotsSection.getConfigurationSection(uuidString);

      ItemStack item = singleLotSection.getItemStack("item");
      boolean started = singleLotSection.getBoolean("started");
      double price = singleLotSection.getDouble("price");
      String lastBidPlayerName = singleLotSection.getString("lastBidPlayerName");
      UUID lastBidPlayerUuid =
          singleLotSection.isSet("lastBidPlayerUuid")
              ? UUID.fromString(singleLotSection.getString("lastBidPlayerUuid"))
              : null;
      double lastBidPrice = singleLotSection.getDouble("lastBidPrice");
      double minimumIncrement = singleLotSection.getDouble("minimumIncrement");
      long preserveTimeExpire = singleLotSection.getLong("preserveTimeExpire");
      long auctionDurationExpire = singleLotSection.getLong("auctionDurationExpire");

      Lot lot =
          new Lot(
              UUID.fromString(uuidString),
              item,
              started,
              price,
              lastBidPlayerName,
              lastBidPlayerUuid,
              lastBidPrice,
              minimumIncrement,
              preserveTimeExpire,
              auctionDurationExpire);
      lots.add(lot);
    }
  }
 public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
   if (!(sender instanceof Player)) {
     sender.sendMessage(ChatColor.RED + "Only players may use this command");
     return true;
   }
   if (args.length == 1) {
     if (args[0].equalsIgnoreCase("list")) {
       if (!plugin.getConfig().contains("drops")) {
         sender.sendMessage(ChatColor.RED + "No drops exist yet");
         return true;
       }
       sender.sendMessage(ChatColor.GOLD + "The following items can drop");
       ConfigurationSection cs = plugin.getConfig().getConfigurationSection("drops");
       for (String item : cs.getKeys(false)) {
         ConfigurationSection i = cs.getConfigurationSection(item);
         sender.sendMessage(
             ChatColor.AQUA
                 + item
                 + ChatColor.GOLD
                 + " | "
                 + ChatColor.AQUA
                 + ChatColor.stripColor(i.getItemStack("item").serialize().toString())
                 + ChatColor.GOLD
                 + " with weight "
                 + ChatColor.AQUA
                 + i.getDouble("weight"));
       }
     }
     return true;
   }
   if (args.length == 2) {
     if (args[0].equalsIgnoreCase("add")) {
       double weight = 1;
       try {
         weight = Double.parseDouble(args[1]);
       } catch (NumberFormatException e) {
         sender.sendMessage(ChatColor.RED + "That's not a number");
         return true;
       }
       if (weight <= 0) {
         sender.sendMessage(ChatColor.RED + "Weight must be greater than zero");
         return true;
       }
       ConfigurationSection cs = plugin.getConfig().getConfigurationSection("drops");
       int maxItem = 0;
       if (plugin.getConfig().contains("drops")) {
         for (String c : cs.getKeys(false)) {
           int crate = Integer.parseInt(c);
           if (crate > maxItem) {
             maxItem = crate;
           }
         }
       }
       maxItem++;
       ItemStack item = ((Player) sender).getItemInHand().clone();
       if (StrangeWeapon.isStrangeWeapon(item)) {
         item = new StrangeWeapon(item).clone();
       }
       plugin.getConfig().set("drops." + maxItem + ".item", item);
       plugin.getConfig().set("drops." + maxItem + ".weight", weight);
       sender.sendMessage(
           ChatColor.GOLD
               + "Added "
               + ChatColor.AQUA
               + ChatColor.stripColor(item.serialize().toString())
               + ChatColor.GOLD
               + " with weight "
               + weight);
       plugin.saveConfig();
       return true;
     }
     if (args[0].equalsIgnoreCase("remove")) {
       int item = 1;
       try {
         item = Integer.parseInt(args[1]);
       } catch (NumberFormatException e) {
         sender.sendMessage(ChatColor.RED + "That's not a number");
         return true;
       }
       plugin.getConfig().set("drops." + item, null);
       plugin.saveConfig();
       sender.sendMessage(
           ChatColor.GOLD
               + "Removed item "
               + ChatColor.AQUA
               + item
               + ChatColor.GOLD
               + " from the drop list");
       return true;
     }
   }
   sender.sendMessage(
       new String[] {
         ChatColor.RED + "Valid commands are:",
         ChatColor.GOLD
             + "list "
             + ChatColor.AQUA
             + "- "
             + ChatColor.RED
             + "List what items can drop and their weights",
         ChatColor.GOLD
             + "add "
             + ChatColor.YELLOW
             + "<weight> "
             + ChatColor.AQUA
             + "- "
             + ChatColor.RED
             + "Add the item you are holding to the drops list",
         ChatColor.GOLD
             + "remove "
             + ChatColor.YELLOW
             + "<id> "
             + ChatColor.AQUA
             + "- "
             + ChatColor.RED
             + "Remove the specified item from the drops list"
       });
   return true;
 }