mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-11 20:00:46 +00:00
Fix unbreakable attribute for kits (#2071) @caseif
This PR fixes the `unbreakable` attribute on kit items. Previously, Essentials was exclusively using an internal Spigot method to set this on `ItemMeta` objects; however, this solution seems to be non-functional on more recent Spigot builds (1.12.2). I have altered the `MetaItemStack#setUnbreakable` method to use the native Bukkit method, available for [some time now](https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/commits/d986a3f), by default. Essentials will still use the old solution as a fallback in case of an older Bukkit version which does not have native support for the attribute.
This commit is contained in:
parent
bad02729db
commit
935b5cfe0f
1 changed files with 25 additions and 11 deletions
|
@ -554,12 +554,25 @@ public class MetaItemStack {
|
|||
}
|
||||
}
|
||||
|
||||
private static int bukkitUnbreakableSupport = -1;
|
||||
private static Method spigotMethod;
|
||||
private static Method setUnbreakableMethod;
|
||||
|
||||
private void setUnbreakable(ItemStack is, boolean unbreakable) {
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
try {
|
||||
if (bukkitUnbreakableSupport == -1) {
|
||||
try {
|
||||
ItemMeta.class.getDeclaredMethod("setUnbreakable", boolean.class);
|
||||
bukkitUnbreakableSupport = 1;
|
||||
} catch (NoSuchMethodException | SecurityException ex) {
|
||||
bukkitUnbreakableSupport = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (bukkitUnbreakableSupport == 1) {
|
||||
meta.setUnbreakable(unbreakable);
|
||||
} else {
|
||||
if (spigotMethod == null) {
|
||||
spigotMethod = meta.getClass().getDeclaredMethod("spigot");
|
||||
spigotMethod.setAccessible(true);
|
||||
|
@ -570,6 +583,7 @@ public class MetaItemStack {
|
|||
setUnbreakableMethod.setAccessible(true);
|
||||
}
|
||||
setUnbreakableMethod.invoke(itemStackSpigot, unbreakable);
|
||||
}
|
||||
is.setItemMeta(meta);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
|
|
Loading…
Reference in a new issue