simple fix

This commit is contained in:
NK 2022-11-27 21:39:43 +00:00
parent 07af2596d8
commit bf8681a385
2 changed files with 10 additions and 12 deletions

View file

@ -94,14 +94,14 @@ public class CustomItemEvents implements Listener {
ItemStack weapon = player.getInventory().getItemInMainHand(); ItemStack weapon = player.getInventory().getItemInMainHand();
ItemMeta weaponMeta = weapon.getItemMeta(); ItemMeta weaponMeta = weapon.getItemMeta();
if (weaponMeta != null) {
PersistentDataContainer container = weaponMeta.getPersistentDataContainer(); PersistentDataContainer container = weaponMeta.getPersistentDataContainer();
if (container != null) { NamespacedKey ammoKey = CustomItemManager.keys.get(name + ".ammo");
NamespacedKey ammocount = CustomItemManager.keys.get("Snow Gun.ammo"); int ammo = container.get(ammoKey, PersistentDataType.INTEGER);
int ammo = container.get(ammocount, PersistentDataType.INTEGER); container.set(ammoKey, PersistentDataType.INTEGER, ammo - 1);
container.set(ammocount, PersistentDataType.INTEGER, ammo - 1); int max = container.get(CustomItemManager.keys.get(name + ".maxload"), PersistentDataType.INTEGER);
int maxload = container.get(CustomItemManager.keys.get("Snow Gun.maxload"), PersistentDataType.INTEGER);
weapon.setItemMeta(weaponMeta); weapon.setItemMeta(weaponMeta);
e.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', "&6AK-47 ( " + (ammo - 1) + "/ " + maxload + " )"))); e.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', "&6AK-47 ( " + (ammo - 1) + "/ " + max + " )")));
} }

View file

@ -29,9 +29,7 @@ public class CustomItemManager {
CustomItemManager.main = main; CustomItemManager.main = main;
main.getConfig().options().copyDefaults(); main.getConfig().options().copyDefaults();
main.saveDefaultConfig(); main.saveDefaultConfig();
if(!main.getDataFolder().exists()) { if(!main.getDataFolder().exists()) main.getDataFolder().mkdir();
main.getDataFolder().mkdir();
}
createDirectoryInPluginFolder("ItemData"); createDirectoryInPluginFolder("ItemData");
createFilesFromConfig(main.getConfig()); createFilesFromConfig(main.getConfig());
register(); register();
@ -116,12 +114,12 @@ public class CustomItemManager {
if (property.equals("ammo")) { if (property.equals("ammo")) {
PersistentDataContainer container = itemMeta.getPersistentDataContainer(); PersistentDataContainer container = itemMeta.getPersistentDataContainer();
NamespacedKey key1 = new NamespacedKey(main, "ammo"); NamespacedKey key1 = new NamespacedKey(main, "ammo");
keys.put(fileConfig.getString("name") + "." + property, key1); keys.put(Rarity.getRarity(fileConfig.getString("rarity")).getColor() + fileConfig.getString("name") + "." + property, key1);
container.set(key1, PersistentDataType.INTEGER, fileConfig.getInt(key)); container.set(key1, PersistentDataType.INTEGER, fileConfig.getInt(key));
} else if (property.equals("maxload")) { } else if (property.equals("maxload")) {
PersistentDataContainer container = itemMeta.getPersistentDataContainer(); PersistentDataContainer container = itemMeta.getPersistentDataContainer();
NamespacedKey key2 = new NamespacedKey(main, "maxload"); NamespacedKey key2 = new NamespacedKey(main, "maxload");
keys.put(fileConfig.getString("name") + "." + property, key2); keys.put(Rarity.getRarity(fileConfig.getString("rarity")).getColor() + fileConfig.getString("name") + "." + property, key2);
container.set(key2, PersistentDataType.INTEGER, fileConfig.getInt(key)); container.set(key2, PersistentDataType.INTEGER, fileConfig.getInt(key));
} }
} }