Java Code Examples for org.bukkit.configuration.ConfigurationSection#getItemStack()
The following examples show how to use
org.bukkit.configuration.ConfigurationSection#getItemStack() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlayerShopkeeper.java From Shopkeepers with GNU General Public License v3.0 | 6 votes |
@Override protected void load(ConfigurationSection config) throws ShopkeeperCreateException { super.load(config); try { ownerUUID = UUID.fromString(config.getString("owner uuid")); } catch (Exception e) { // uuid invalid or non-existent: throw new ShopkeeperCreateException("Missing owner uuid!"); } ownerName = config.getString("owner", "unknown"); if (!config.isInt("chestx") || !config.isInt("chesty") || !config.isInt("chestz")) { throw new ShopkeeperCreateException("Missing chest coordinate(s)"); } // update chest: this.setChest(config.getInt("chestx"), config.getInt("chesty"), config.getInt("chestz")); forHire = config.getBoolean("forhire"); hireCost = config.getItemStack("hirecost"); if (forHire && hireCost == null) { Log.warning("Couldn't load hire cost! Disabling 'for hire' for shopkeeper at " + this.getPositionString()); forHire = false; } }
Example 2
Source File: PriceOffer.java From Shopkeepers with GNU General Public License v3.0 | 6 votes |
public static List<PriceOffer> loadFromConfigOld(ConfigurationSection config, String node) { List<PriceOffer> offers = new ArrayList<PriceOffer>(); ConfigurationSection offersSection = config.getConfigurationSection(node); if (offersSection != null) { for (String key : offersSection.getKeys(false)) { ConfigurationSection offerSection = offersSection.getConfigurationSection(key); ItemStack item = offerSection.getItemStack("item"); if (item != null) { // legacy: the amount was stored separately from the item item.setAmount(offerSection.getInt("amount", 1)); if (offerSection.contains("attributes")) { String attributes = offerSection.getString("attributes"); if (attributes != null && !attributes.isEmpty()) { item = NMSManager.getProvider().loadItemAttributesFromString(item, attributes); } } } int price = offerSection.getInt("cost"); if (Utils.isEmpty(item) || price < 0) continue; // invalid offer offers.add(new PriceOffer(item, price)); } } return offers; }
Example 3
Source File: TradingOffer.java From Shopkeepers with GNU General Public License v3.0 | 5 votes |
public static List<TradingOffer> loadFromConfigOld(ConfigurationSection config, String node) { List<TradingOffer> offers = new ArrayList<TradingOffer>(); ConfigurationSection offersSection = config.getConfigurationSection(node); if (offersSection != null) { for (String key : offersSection.getKeys(false)) { ConfigurationSection offerSection = offersSection.getConfigurationSection(key); ItemStack resultItem = offerSection.getItemStack("item"); if (resultItem != null) { // legacy: the amount was stored separately from the item resultItem.setAmount(offerSection.getInt("amount", 1)); if (offerSection.contains("attributes")) { String attributes = offerSection.getString("attributes"); if (attributes != null && !attributes.isEmpty()) { resultItem = NMSManager.getProvider().loadItemAttributesFromString(resultItem, attributes); } } } if (Utils.isEmpty(resultItem)) continue; // invalid offer ItemStack item1 = offerSection.getItemStack("item1"); if (Utils.isEmpty(item1)) continue; // invalid offer ItemStack item2 = offerSection.getItemStack("item2"); // legacy: no attributes were stored for item1 and item2 offers.add(new TradingOffer(resultItem, item1, item2)); } } return offers; }
Example 4
Source File: AdminShopkeeper.java From Shopkeepers with GNU General Public License v3.0 | 5 votes |
/** * Loads an ItemStack from a config section. * * @param section * @return */ private ItemStack loadItemStackOld(ConfigurationSection section) { ItemStack item = section.getItemStack("item"); if (item != null) { if (section.contains("attributes")) { String attributes = section.getString("attributes"); if (attributes != null && !attributes.isEmpty()) { item = NMSManager.getProvider().loadItemAttributesFromString(item, attributes); } } } return item; }
Example 5
Source File: BackpackConverter.java From PlayerVaults with GNU General Public License v3.0 | 4 votes |
private int convert(File worldFolder, int intoVaultNum) { PlayerVaults plugin = PlayerVaults.getInstance(); VaultManager vaults = VaultManager.getInstance(); int converted = 0; long lastUpdate = 0; File[] files = worldFolder.listFiles(); for (File file : files != null ? files : new File[0]) { if (file.isFile() && file.getName().toLowerCase().endsWith(".yml")) { try { OfflinePlayer player = Bukkit.getOfflinePlayer(file.getName().substring(0, file.getName().lastIndexOf('.'))); if (player == null || player.getUniqueId() == null) { plugin.getLogger().warning("Unable to convert Backpack for player: " + (player != null ? player.getName() : file.getName())); } else { UUID uuid = player.getUniqueId(); FileConfiguration yaml = YamlConfiguration.loadConfiguration(file); ConfigurationSection section = yaml.getConfigurationSection("backpack"); if (section.getKeys(false).size() <= 0) { continue; // No slots } Inventory vault = vaults.getVault(uuid.toString(), intoVaultNum); if (vault == null) { vault = plugin.getServer().createInventory(null, section.getKeys(false).size()); } for (String key : section.getKeys(false)) { ConfigurationSection slotSection = section.getConfigurationSection(key); ItemStack item = slotSection.getItemStack("ItemStack"); if (item == null) { continue; } // Overwrite vault.setItem(Integer.parseInt(key.split(" ")[1]), item); } vaults.saveVault(vault, uuid.toString(), intoVaultNum); converted++; if (System.currentTimeMillis() - lastUpdate >= 1500) { plugin.getLogger().info(converted + " backpacks have been converted in " + worldFolder.getAbsolutePath()); lastUpdate = System.currentTimeMillis(); } } } catch (Exception e) { plugin.getLogger().warning("Error converting " + file.getAbsolutePath()); e.printStackTrace(); } } } return converted; }