mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-02-03 05:51:22 +01:00
[Experimental] Support Unbreakable meta tag
This commit is contained in:
parent
b8f7918a4a
commit
62c2c57d4d
@ -19,6 +19,7 @@ import org.bukkit.potion.Potion;
|
|||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -167,6 +168,8 @@ public class MetaItemStack {
|
|||||||
final ItemMeta meta = stack.getItemMeta();
|
final ItemMeta meta = stack.getItemMeta();
|
||||||
meta.setLore(lore);
|
meta.setLore(lore);
|
||||||
stack.setItemMeta(meta);
|
stack.setItemMeta(meta);
|
||||||
|
} else if (split.length > 1 && (split[0].equalsIgnoreCase("unbreakable") && hasMetaPermission(sender, "unbreakable", false, true, ess))) {
|
||||||
|
setUnbreakable(stack, Boolean.valueOf(split[1]));
|
||||||
} else if (split.length > 1 && (split[0].equalsIgnoreCase("player") || split[0].equalsIgnoreCase("owner")) && stack.getType() == Material.SKULL_ITEM && hasMetaPermission(sender, "head", false, true, ess)) {
|
} else if (split.length > 1 && (split[0].equalsIgnoreCase("player") || split[0].equalsIgnoreCase("owner")) && stack.getType() == Material.SKULL_ITEM && hasMetaPermission(sender, "head", false, true, ess)) {
|
||||||
if (stack.getDurability() == 3) {
|
if (stack.getDurability() == 3) {
|
||||||
final String owner = split[1];
|
final String owner = split[1];
|
||||||
@ -467,4 +470,26 @@ public class MetaItemStack {
|
|||||||
throw new Exception(tl("noMetaPerm", metaPerm));
|
throw new Exception(tl("noMetaPerm", metaPerm));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Method spigotMethod;
|
||||||
|
private static Method setUnbreakableMethod;
|
||||||
|
|
||||||
|
private void setUnbreakable(ItemStack is, boolean unbreakable) {
|
||||||
|
ItemMeta meta = is.getItemMeta();
|
||||||
|
try {
|
||||||
|
if (spigotMethod == null) {
|
||||||
|
spigotMethod = meta.getClass().getDeclaredMethod("spigot");
|
||||||
|
spigotMethod.setAccessible(true);
|
||||||
|
}
|
||||||
|
Object itemStackSpigot = spigotMethod.invoke(meta);
|
||||||
|
if (setUnbreakableMethod == null) {
|
||||||
|
setUnbreakableMethod = itemStackSpigot.getClass().getDeclaredMethod("setUnbreakable", Boolean.TYPE);
|
||||||
|
setUnbreakableMethod.setAccessible(true);
|
||||||
|
}
|
||||||
|
setUnbreakableMethod.invoke(itemStackSpigot, unbreakable);
|
||||||
|
is.setItemMeta(meta);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user