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();
ItemMeta weaponMeta = weapon.getItemMeta();
if (weaponMeta != null) {
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);
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 + " )")));
}

View file

@ -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));
}
}