!Fixed 1.12 comp issue

This commit is contained in:
Indyuce 2020-04-05 19:34:43 +02:00
parent 67ce4130ed
commit f526dff073

View File

@ -14,7 +14,6 @@ import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
@ -33,7 +32,7 @@ public class ConfigItem {
private final int damage, modeldata; private final int damage, modeldata;
private boolean unbreakable; private boolean unbreakable;
private Map<String, String> placeholders = new HashMap<>(); private final Map<String, String> placeholders = new HashMap<>();
public ConfigItem(ConfigurationSection config) { public ConfigItem(ConfigurationSection config) {
id = config.getName(); id = config.getName();
@ -107,13 +106,13 @@ public class ConfigItem {
ItemStack item = getItem(amount); ItemStack item = getItem(amount);
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
if (meta instanceof Damageable) if (MMOLib.plugin.getVersion().getWrapper().isDamageable(item))
((Damageable) meta).setDamage(damage); MMOLib.plugin.getVersion().getWrapper().applyDurability(item, meta, damage);
if(MMOLib.plugin.getVersion().isStrictlyHigher(1, 13)) if (MMOLib.plugin.getVersion().isStrictlyHigher(1, 13))
meta.setCustomModelData(modeldata); meta.setCustomModelData(modeldata);
if (item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial() && texture != null) { if (item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial() && texture != null)
try { try {
Field profileField = meta.getClass().getDeclaredField("profile"); Field profileField = meta.getClass().getDeclaredField("profile");
profileField.setAccessible(true); profileField.setAccessible(true);
@ -123,7 +122,6 @@ public class ConfigItem {
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException exception) { } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException exception) {
MMOCore.log(Level.WARNING, "Could not load config item texture of " + id); MMOCore.log(Level.WARNING, "Could not load config item texture of " + id);
} }
}
meta.addItemFlags(ItemFlag.values()); meta.addItemFlags(ItemFlag.values());
meta.setDisplayName(format(name)); meta.setDisplayName(format(name));