From bf8681a385c4eb8738c42d2830c26f9bd6fde0ec Mon Sep 17 00:00:00 2001 From: NK Date: Sun, 27 Nov 2022 21:39:43 +0000 Subject: [PATCH] simple fix --- .../nullvalkyrie/events/CustomItemEvents.java | 14 +++++++------- .../nullvalkyrie/items/CustomItemManager.java | 8 +++----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/me/night/nullvalkyrie/events/CustomItemEvents.java b/src/main/java/me/night/nullvalkyrie/events/CustomItemEvents.java index 4bf48e3..2f7f6a0 100644 --- a/src/main/java/me/night/nullvalkyrie/events/CustomItemEvents.java +++ b/src/main/java/me/night/nullvalkyrie/events/CustomItemEvents.java @@ -94,14 +94,14 @@ public class CustomItemEvents implements Listener { ItemStack weapon = player.getInventory().getItemInMainHand(); ItemMeta weaponMeta = weapon.getItemMeta(); - PersistentDataContainer container = weaponMeta.getPersistentDataContainer(); - if (container != null) { - NamespacedKey ammocount = CustomItemManager.keys.get("Snow Gun.ammo"); - int ammo = container.get(ammocount, PersistentDataType.INTEGER); - container.set(ammocount, PersistentDataType.INTEGER, ammo - 1); - int maxload = container.get(CustomItemManager.keys.get("Snow Gun.maxload"), PersistentDataType.INTEGER); + if (weaponMeta != null) { + PersistentDataContainer container = weaponMeta.getPersistentDataContainer(); + NamespacedKey ammoKey = CustomItemManager.keys.get(name + ".ammo"); + int ammo = container.get(ammoKey, PersistentDataType.INTEGER); + container.set(ammoKey, PersistentDataType.INTEGER, ammo - 1); + int max = container.get(CustomItemManager.keys.get(name + ".maxload"), PersistentDataType.INTEGER); 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 + " )"))); } diff --git a/src/main/java/me/night/nullvalkyrie/items/CustomItemManager.java b/src/main/java/me/night/nullvalkyrie/items/CustomItemManager.java index d96b5f3..5a4a72a 100644 --- a/src/main/java/me/night/nullvalkyrie/items/CustomItemManager.java +++ b/src/main/java/me/night/nullvalkyrie/items/CustomItemManager.java @@ -29,9 +29,7 @@ public class CustomItemManager { CustomItemManager.main = main; main.getConfig().options().copyDefaults(); main.saveDefaultConfig(); - if(!main.getDataFolder().exists()) { - main.getDataFolder().mkdir(); - } + if(!main.getDataFolder().exists()) main.getDataFolder().mkdir(); createDirectoryInPluginFolder("ItemData"); createFilesFromConfig(main.getConfig()); register(); @@ -116,12 +114,12 @@ public class CustomItemManager { if (property.equals("ammo")) { PersistentDataContainer container = itemMeta.getPersistentDataContainer(); 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)); } else if (property.equals("maxload")) { PersistentDataContainer container = itemMeta.getPersistentDataContainer(); 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)); } }