更新
This commit is contained in:
@@ -678,18 +678,24 @@ public class NMSUtil19 {
|
||||
try {
|
||||
// 1.12, same as 1.10
|
||||
class_EntityArmorStand_disabledSlotsField = class_EntityArmorStand.getDeclaredField("bB");
|
||||
if (class_EntityArmorStand_disabledSlotsField.getType() != Integer.TYPE) throw new Exception("Looks like 1.11, maybe");
|
||||
if (class_EntityArmorStand_disabledSlotsField.getType() != Integer.TYPE) {
|
||||
throw new Exception("Looks like 1.11, maybe");
|
||||
}
|
||||
} catch (Throwable not12) {
|
||||
try {
|
||||
// 1.11
|
||||
class_EntityArmorStand_disabledSlotsField = class_EntityArmorStand.getDeclaredField("bA");
|
||||
if (class_EntityArmorStand_disabledSlotsField.getType() != Integer.TYPE) throw new Exception("Looks like 1.10");
|
||||
if (class_EntityArmorStand_disabledSlotsField.getType() != Integer.TYPE) {
|
||||
throw new Exception("Looks like 1.10");
|
||||
}
|
||||
} catch (Throwable ignore) {
|
||||
// 1.10 and earlier
|
||||
legacy = true;
|
||||
try {
|
||||
class_EntityArmorStand_disabledSlotsField = class_EntityArmorStand.getDeclaredField("bB");
|
||||
if (class_EntityArmorStand_disabledSlotsField.getType() != Integer.TYPE) throw new Exception("Looks like 1.9");
|
||||
if (class_EntityArmorStand_disabledSlotsField.getType() != Integer.TYPE) {
|
||||
throw new Exception("Looks like 1.9");
|
||||
}
|
||||
} catch (Throwable ignore2) {
|
||||
try {
|
||||
// 1.9.4
|
||||
@@ -742,7 +748,9 @@ public class NMSUtil19 {
|
||||
try {
|
||||
// 1.10 and 1.11
|
||||
class_PlayerConnection_floatCountField = class_PlayerConnection.getDeclaredField("C");
|
||||
if (class_PlayerConnection_floatCountField.getType() != Integer.TYPE) throw new Exception("Looks like 1.9");
|
||||
if (class_PlayerConnection_floatCountField.getType() != Integer.TYPE) {
|
||||
throw new Exception("Looks like 1.9");
|
||||
}
|
||||
class_PlayerConnection_floatCountField.setAccessible(true);
|
||||
} catch (Throwable ignore) {
|
||||
// 1.9 and earlier
|
||||
@@ -954,7 +962,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static Object getHandle(org.bukkit.World world) {
|
||||
if (world == null) return null;
|
||||
if (world == null) {
|
||||
return null;
|
||||
}
|
||||
Object handle = null;
|
||||
try {
|
||||
handle = class_CraftWorld_getHandleMethod.invoke(world);
|
||||
@@ -965,7 +975,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static Object getHandle(org.bukkit.entity.Entity entity) {
|
||||
if (entity == null) return null;
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
Object handle = null;
|
||||
try {
|
||||
handle = class_CraftEntity_getHandleMethod.invoke(entity);
|
||||
@@ -976,7 +988,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static Object getHandle(org.bukkit.entity.LivingEntity entity) {
|
||||
if (entity == null) return null;
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
Object handle = null;
|
||||
try {
|
||||
handle = class_CraftLivingEntity_getHandleMethod.invoke(entity);
|
||||
@@ -1025,7 +1039,9 @@ public class NMSUtil19 {
|
||||
World sourceWorld = source.getWorld();
|
||||
for (Player player : players) {
|
||||
Location location = player.getLocation();
|
||||
if (!location.getWorld().equals(sourceWorld)) continue;
|
||||
if (!location.getWorld().equals(sourceWorld)) {
|
||||
continue;
|
||||
}
|
||||
if (location.distanceSquared(source) <= viewDistanceSquared) {
|
||||
sendPacket(player, packet);
|
||||
}
|
||||
@@ -1064,11 +1080,15 @@ public class NMSUtil19 {
|
||||
|
||||
public static org.bukkit.entity.Entity getBukkitEntity(Object entity)
|
||||
{
|
||||
if (entity == null) return null;
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Method getMethod = entity.getClass().getMethod("getBukkitEntity");
|
||||
Object bukkitEntity = getMethod.invoke(entity);
|
||||
if (!(bukkitEntity instanceof org.bukkit.entity.Entity)) return null;
|
||||
if (!(bukkitEntity instanceof org.bukkit.entity.Entity)) {
|
||||
return null;
|
||||
}
|
||||
return (org.bukkit.entity.Entity)bukkitEntity;
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
@@ -1098,7 +1118,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static ItemStack getCopy(ItemStack stack) {
|
||||
if (stack == null) return null;
|
||||
if (stack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
Object craft = getNMSCopy(stack);
|
||||
@@ -1111,7 +1133,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static ItemStack makeReal(ItemStack stack) {
|
||||
if (stack == null) return null;
|
||||
if (stack == null) {
|
||||
return null;
|
||||
}
|
||||
Object nmsStack = getHandle(stack);
|
||||
if (nmsStack == null) {
|
||||
stack = getCopy(stack);
|
||||
@@ -1146,7 +1170,9 @@ public class NMSUtil19 {
|
||||
Object tag = null;
|
||||
try {
|
||||
Object mcItemStack = getHandle(itemStack);
|
||||
if (mcItemStack == null) return null;
|
||||
if (mcItemStack == null) {
|
||||
return null;
|
||||
}
|
||||
tag = class_ItemStack_tagField.get(mcItemStack);
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
@@ -1155,13 +1181,19 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static Object getNode(ItemStack stack, String tag) {
|
||||
if (NMSUtil19.isEmpty(stack)) return null;
|
||||
if (NMSUtil19.isEmpty(stack)) {
|
||||
return null;
|
||||
}
|
||||
Object meta = null;
|
||||
try {
|
||||
Object craft = getHandle(stack);
|
||||
if (craft == null) return null;
|
||||
if (craft == null) {
|
||||
return null;
|
||||
}
|
||||
Object tagObject = getTag(craft);
|
||||
if (tagObject == null) return null;
|
||||
if (tagObject == null) {
|
||||
return null;
|
||||
}
|
||||
meta = class_NBTTagCompound_getMethod.invoke(tagObject, tag);
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
@@ -1170,7 +1202,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static boolean containsNode(Object nbtBase, String tag) {
|
||||
if (nbtBase == null) return false;
|
||||
if (nbtBase == null) {
|
||||
return false;
|
||||
}
|
||||
Boolean result = false;
|
||||
try {
|
||||
result = (Boolean)class_NBTTagCompound_hasKeyMethod.invoke(nbtBase, tag);
|
||||
@@ -1181,7 +1215,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static Object getNode(Object nbtBase, String tag) {
|
||||
if (nbtBase == null) return null;
|
||||
if (nbtBase == null) {
|
||||
return null;
|
||||
}
|
||||
Object meta = null;
|
||||
try {
|
||||
meta = class_NBTTagCompound_getMethod.invoke(nbtBase, tag);
|
||||
@@ -1192,7 +1228,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static Object createNode(Object nbtBase, String tag) {
|
||||
if (nbtBase == null) return null;
|
||||
if (nbtBase == null) {
|
||||
return null;
|
||||
}
|
||||
Object meta = null;
|
||||
try {
|
||||
meta = class_NBTTagCompound_getCompoundMethod.invoke(nbtBase, tag);
|
||||
@@ -1204,12 +1242,16 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static Object createNode(ItemStack stack, String tag) {
|
||||
if (NMSUtil19.isEmpty(stack)) return null;
|
||||
if (NMSUtil19.isEmpty(stack)) {
|
||||
return null;
|
||||
}
|
||||
Object outputObject = getNode(stack, tag);
|
||||
if (outputObject == null) {
|
||||
try {
|
||||
Object craft = getHandle(stack);
|
||||
if (craft == null) return null;
|
||||
if (craft == null) {
|
||||
return null;
|
||||
}
|
||||
Object tagObject = getTag(craft);
|
||||
if (tagObject == null) {
|
||||
tagObject = class_NBTTagCompound.newInstance();
|
||||
@@ -1230,7 +1272,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static String getMetaString(Object node, String tag) {
|
||||
if (node == null || !class_NBTTagCompound.isInstance(node)) return null;
|
||||
if (node == null || !class_NBTTagCompound.isInstance(node)) {
|
||||
return null;
|
||||
}
|
||||
String meta = null;
|
||||
try {
|
||||
meta = (String)class_NBTTagCompound_getStringMethod.invoke(node, tag);
|
||||
@@ -1241,7 +1285,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static String getMeta(Object node, String tag) {
|
||||
if (node == null || !class_NBTTagCompound.isInstance(node)) return null;
|
||||
if (node == null || !class_NBTTagCompound.isInstance(node)) {
|
||||
return null;
|
||||
}
|
||||
String meta = null;
|
||||
try {
|
||||
meta = (String)class_NBTTagCompound_getStringMethod.invoke(node, tag);
|
||||
@@ -1252,7 +1298,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static Byte getMetaByte(Object node, String tag) {
|
||||
if (node == null || !class_NBTTagCompound.isInstance(node)) return null;
|
||||
if (node == null || !class_NBTTagCompound.isInstance(node)) {
|
||||
return null;
|
||||
}
|
||||
Byte meta = null;
|
||||
try {
|
||||
meta = (Byte)class_NBTTagCompound_getByteMethod.invoke(node, tag);
|
||||
@@ -1263,7 +1311,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static Integer getMetaInt(Object node, String tag) {
|
||||
if (node == null || !class_NBTTagCompound.isInstance(node)) return null;
|
||||
if (node == null || !class_NBTTagCompound.isInstance(node)) {
|
||||
return null;
|
||||
}
|
||||
Integer meta = null;
|
||||
try {
|
||||
meta = (Integer)class_NBTTagCompound_getIntMethod.invoke(node, tag);
|
||||
@@ -1274,7 +1324,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static Boolean getMetaBoolean(Object node, String tag) {
|
||||
if (node == null || !class_NBTTagCompound.isInstance(node)) return null;
|
||||
if (node == null || !class_NBTTagCompound.isInstance(node)) {
|
||||
return null;
|
||||
}
|
||||
Boolean meta = null;
|
||||
try {
|
||||
meta = (Boolean)class_NBTTagCompound_getBooleanMethod.invoke(node, tag);
|
||||
@@ -1285,7 +1337,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static void setMeta(Object node, String tag, String value) {
|
||||
if (node == null|| !class_NBTTagCompound.isInstance(node)) return;
|
||||
if (node == null|| !class_NBTTagCompound.isInstance(node)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (value == null || value.length() == 0) {
|
||||
class_NBTTagCompound_removeMethod.invoke(node, tag);
|
||||
@@ -1298,7 +1352,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static void setMetaLong(Object node, String tag, long value) {
|
||||
if (node == null|| !class_NBTTagCompound.isInstance(node)) return;
|
||||
if (node == null|| !class_NBTTagCompound.isInstance(node)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
class_NBTTagCompound_setLongMethod.invoke(node, tag, value);
|
||||
} catch (Throwable ex) {
|
||||
@@ -1307,7 +1363,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static void setMetaBoolean(Object node, String tag, boolean value) {
|
||||
if (node == null|| !class_NBTTagCompound.isInstance(node)) return;
|
||||
if (node == null|| !class_NBTTagCompound.isInstance(node)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
class_NBTTagCompound_setBooleanMethod.invoke(node, tag, value);
|
||||
} catch (Throwable ex) {
|
||||
@@ -1316,7 +1374,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static void setMetaDouble(Object node, String tag, double value) {
|
||||
if (node == null|| !class_NBTTagCompound.isInstance(node)) return;
|
||||
if (node == null|| !class_NBTTagCompound.isInstance(node)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
class_NBTTagCompound_setDoubleMethod.invoke(node, tag, value);
|
||||
} catch (Throwable ex) {
|
||||
@@ -1325,7 +1385,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static void setMetaInt(Object node, String tag, int value) {
|
||||
if (node == null|| !class_NBTTagCompound.isInstance(node)) return;
|
||||
if (node == null|| !class_NBTTagCompound.isInstance(node)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
class_NBTTagCompound_setIntMethod.invoke(node, tag, value);
|
||||
} catch (Throwable ex) {
|
||||
@@ -1334,7 +1396,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static void removeMeta(Object node, String tag) {
|
||||
if (node == null|| !class_NBTTagCompound.isInstance(node)) return;
|
||||
if (node == null|| !class_NBTTagCompound.isInstance(node)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
class_NBTTagCompound_removeMethod.invoke(node, tag);
|
||||
} catch (Throwable ex) {
|
||||
@@ -1343,13 +1407,19 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static void removeMeta(ItemStack stack, String tag) {
|
||||
if (NMSUtil19.isEmpty(stack)) return;
|
||||
if (NMSUtil19.isEmpty(stack)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Object craft = getHandle(stack);
|
||||
if (craft == null) return;
|
||||
if (craft == null) {
|
||||
return;
|
||||
}
|
||||
Object tagObject = getTag(craft);
|
||||
if (tagObject == null) return;
|
||||
if (tagObject == null) {
|
||||
return;
|
||||
}
|
||||
removeMeta(tagObject, tag);
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
@@ -1357,7 +1427,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static void setMetaNode(Object node, String tag, Object child) {
|
||||
if (node == null || !class_NBTTagCompound.isInstance(node)) return;
|
||||
if (node == null || !class_NBTTagCompound.isInstance(node)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (child == null) {
|
||||
class_NBTTagCompound_removeMethod.invoke(node, tag);
|
||||
@@ -1370,12 +1442,18 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static boolean setMetaNode(ItemStack stack, String tag, Object child) {
|
||||
if (NMSUtil19.isEmpty(stack)) return false;
|
||||
if (NMSUtil19.isEmpty(stack)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Object craft = getHandle(stack);
|
||||
if (craft == null) return false;
|
||||
if (craft == null) {
|
||||
return false;
|
||||
}
|
||||
Object node = getTag(craft);
|
||||
if (node == null) return false;
|
||||
if (node == null) {
|
||||
return false;
|
||||
}
|
||||
if (child == null) {
|
||||
class_NBTTagCompound_removeMethod.invoke(node, tag);
|
||||
} else {
|
||||
@@ -1390,13 +1468,19 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static String getMetaString(ItemStack stack, String tag) {
|
||||
if (NMSUtil19.isEmpty(stack)) return null;
|
||||
if (NMSUtil19.isEmpty(stack)) {
|
||||
return null;
|
||||
}
|
||||
String meta = null;
|
||||
try {
|
||||
Object craft = getHandle(stack);
|
||||
if (craft == null) return null;
|
||||
if (craft == null) {
|
||||
return null;
|
||||
}
|
||||
Object tagObject = getTag(craft);
|
||||
if (tagObject == null) return null;
|
||||
if (tagObject == null) {
|
||||
return null;
|
||||
}
|
||||
meta = (String)class_NBTTagCompound_getStringMethod.invoke(tagObject, tag);
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
@@ -1405,12 +1489,18 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static void setMeta(ItemStack stack, String tag, String value) {
|
||||
if (NMSUtil19.isEmpty(stack)) return;
|
||||
if (NMSUtil19.isEmpty(stack)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Object craft = getHandle(stack);
|
||||
if (craft == null) return;
|
||||
if (craft == null) {
|
||||
return;
|
||||
}
|
||||
Object tagObject = getTag(craft);
|
||||
if (tagObject == null) return;
|
||||
if (tagObject == null) {
|
||||
return;
|
||||
}
|
||||
class_NBTTagCompound_setStringMethod.invoke(tagObject, tag, value);
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
@@ -1418,12 +1508,18 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static void setMetaBoolean(ItemStack stack, String tag, boolean value) {
|
||||
if (NMSUtil19.isEmpty(stack)) return;
|
||||
if (NMSUtil19.isEmpty(stack)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Object craft = getHandle(stack);
|
||||
if (craft == null) return;
|
||||
if (craft == null) {
|
||||
return;
|
||||
}
|
||||
Object tagObject = getTag(craft);
|
||||
if (tagObject == null) return;
|
||||
if (tagObject == null) {
|
||||
return;
|
||||
}
|
||||
setMetaBoolean(tagObject, tag, value);
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
@@ -1431,13 +1527,19 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static boolean getMetaBoolean(ItemStack stack, String tag, boolean defaultValue) {
|
||||
if (NMSUtil19.isEmpty(stack)) return defaultValue;
|
||||
if (NMSUtil19.isEmpty(stack)) {
|
||||
return defaultValue;
|
||||
}
|
||||
boolean result = defaultValue;
|
||||
try {
|
||||
Object craft = getHandle(stack);
|
||||
if (craft == null) return defaultValue;
|
||||
if (craft == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
Object tagObject = getTag(craft);
|
||||
if (tagObject == null) return defaultValue;
|
||||
if (tagObject == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
Boolean value = getMetaBoolean(tagObject, tag);
|
||||
result = value == null ? defaultValue : value;
|
||||
} catch (Throwable ex) {
|
||||
@@ -1447,7 +1549,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static void addGlow(ItemStack stack) {
|
||||
if (NMSUtil19.isEmpty(stack)) return;
|
||||
if (NMSUtil19.isEmpty(stack)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
meta.addEnchant(Enchantment.LUCK, 1, true);
|
||||
@@ -1455,7 +1559,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static void removeGlow(ItemStack stack) {
|
||||
if (NMSUtil19.isEmpty(stack)) return;
|
||||
if (NMSUtil19.isEmpty(stack)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
if (meta.hasEnchant(Enchantment.LUCK)) {
|
||||
@@ -1465,13 +1571,19 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static boolean isUnbreakable(ItemStack stack) {
|
||||
if (NMSUtil19.isEmpty(stack)) return false;
|
||||
if (NMSUtil19.isEmpty(stack)) {
|
||||
return false;
|
||||
}
|
||||
Boolean unbreakableFlag = null;
|
||||
try {
|
||||
Object craft = getHandle(stack);
|
||||
if (craft == null) return false;
|
||||
if (craft == null) {
|
||||
return false;
|
||||
}
|
||||
Object tagObject = getTag(craft);
|
||||
if (tagObject == null) return false;
|
||||
if (tagObject == null) {
|
||||
return false;
|
||||
}
|
||||
unbreakableFlag = getMetaBoolean(tagObject, "Unbreakable");
|
||||
} catch (Throwable ignored) {
|
||||
|
||||
@@ -1481,13 +1593,19 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static void makeUnbreakable(ItemStack stack) {
|
||||
if (NMSUtil19.isEmpty(stack)) return;
|
||||
if (NMSUtil19.isEmpty(stack)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Object craft = getHandle(stack);
|
||||
if (craft == null) return;
|
||||
if (craft == null) {
|
||||
return;
|
||||
}
|
||||
Object tagObject = getTag(craft);
|
||||
if (tagObject == null) return;
|
||||
if (tagObject == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object unbreakableFlag = null;
|
||||
unbreakableFlag = class_NBTTagByte_constructor.newInstance((byte) 1);
|
||||
@@ -1502,13 +1620,19 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static void hideFlags(ItemStack stack, byte flags) {
|
||||
if (NMSUtil19.isEmpty(stack)) return;
|
||||
if (NMSUtil19.isEmpty(stack)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Object craft = getHandle(stack);
|
||||
if (craft == null) return;
|
||||
if (craft == null) {
|
||||
return;
|
||||
}
|
||||
Object tagObject = getTag(craft);
|
||||
if (tagObject == null) return;
|
||||
if (tagObject == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object hideFlag = null;
|
||||
hideFlag = class_NBTTagByte_constructor.newInstance(flags);
|
||||
@@ -1520,10 +1644,14 @@ public class NMSUtil19 {
|
||||
|
||||
public static boolean createExplosion(Entity entity, World world, double x, double y, double z, float power, boolean setFire, boolean breakBlocks) {
|
||||
boolean result = false;
|
||||
if (world == null) return false;
|
||||
if (world == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Object worldHandle = getHandle(world);
|
||||
if (worldHandle == null) return false;
|
||||
if (worldHandle == null) {
|
||||
return false;
|
||||
}
|
||||
Object entityHandle = entity == null ? null : getHandle(entity);
|
||||
|
||||
Object explosion = class_World_explodeMethod.invoke(worldHandle, entityHandle, x, y, z, power, setFire, breakBlocks);
|
||||
@@ -1593,7 +1721,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static Object setStringList(Object nbtBase, String tag, Collection<String> values) {
|
||||
if (nbtBase == null) return null;
|
||||
if (nbtBase == null) {
|
||||
return null;
|
||||
}
|
||||
Object listMeta = null;
|
||||
try {
|
||||
listMeta = class_NBTTagList.newInstance();
|
||||
@@ -1612,7 +1742,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static ItemStack getItem(Object itemTag) {
|
||||
if (itemTag == null) return null;
|
||||
if (itemTag == null) {
|
||||
return null;
|
||||
}
|
||||
ItemStack item = null;
|
||||
try {
|
||||
Object nmsStack = null;
|
||||
@@ -1651,7 +1783,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static Object getTileEntityData(Location location) {
|
||||
if (class_CraftWorld_getTileEntityAtMethod == null || class_TileEntity_saveMethod == null) return null;
|
||||
if (class_CraftWorld_getTileEntityAtMethod == null || class_TileEntity_saveMethod == null) {
|
||||
return null;
|
||||
}
|
||||
Object data = null;
|
||||
try {
|
||||
World world = location.getWorld();
|
||||
@@ -1667,7 +1801,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static Object getTileEntity(Location location) {
|
||||
if (class_CraftWorld_getTileEntityAtMethod == null) return null;
|
||||
if (class_CraftWorld_getTileEntityAtMethod == null) {
|
||||
return null;
|
||||
}
|
||||
Object tileEntity = null;
|
||||
try {
|
||||
World world = location.getWorld();
|
||||
@@ -1679,11 +1815,17 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static void clearItems(Location location) {
|
||||
if (class_TileEntity_loadMethod == null || class_TileEntity_updateMethod == null || class_CraftWorld_getTileEntityAtMethod == null || class_TileEntity_saveMethod == null) return;
|
||||
if (location == null) return;
|
||||
if (class_TileEntity_loadMethod == null || class_TileEntity_updateMethod == null || class_CraftWorld_getTileEntityAtMethod == null || class_TileEntity_saveMethod == null) {
|
||||
return;
|
||||
}
|
||||
if (location == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object tileEntity = class_CraftWorld_getTileEntityAtMethod.invoke(world, location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
if (tileEntity != null) {
|
||||
@@ -1704,15 +1846,23 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static void setTileEntityData(Location location, Object data) {
|
||||
if (class_TileEntity_loadMethod == null || class_TileEntity_updateMethod == null || class_CraftWorld_getTileEntityAtMethod == null) return;
|
||||
if (class_TileEntity_loadMethod == null || class_TileEntity_updateMethod == null || class_CraftWorld_getTileEntityAtMethod == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (location == null || data == null) return;
|
||||
if (location == null || data == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object tileEntity = class_CraftWorld_getTileEntityAtMethod.invoke(world, location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
if (tileEntity == null) return;
|
||||
if (tileEntity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
class_NBTTagCompound_setIntMethod.invoke(data, "x", location.getBlockX());
|
||||
class_NBTTagCompound_setIntMethod.invoke(data, "y", location.getBlockY());
|
||||
@@ -1726,7 +1876,9 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static Vector getPosition(Object entityData, String tag) {
|
||||
if (class_NBTTagList_getDoubleMethod == null) return null;
|
||||
if (class_NBTTagList_getDoubleMethod == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Object posList = class_NBTTagCompound_getListMethod.invoke(entityData, tag, NBT_TYPE_DOUBLE);
|
||||
Double x = (Double)class_NBTTagList_getDoubleMethod.invoke(posList, 0);
|
||||
@@ -1777,7 +1929,9 @@ public class NMSUtil19 {
|
||||
|
||||
public static Map<String, Object> getMap(ConfigurationSection section)
|
||||
{
|
||||
if (section == null) return null;
|
||||
if (section == null) {
|
||||
return null;
|
||||
}
|
||||
if (section instanceof MemorySection)
|
||||
{
|
||||
try {
|
||||
@@ -1801,11 +1955,17 @@ public class NMSUtil19 {
|
||||
}
|
||||
|
||||
public static boolean isEmpty(ItemStack itemStack) {
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR) return true;
|
||||
if (class_ItemStack_isEmptyMethod == null) return false;
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR) {
|
||||
return true;
|
||||
}
|
||||
if (class_ItemStack_isEmptyMethod == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Object handle = getHandle(itemStack);
|
||||
if (handle == null) return false;
|
||||
if (handle == null) {
|
||||
return false;
|
||||
}
|
||||
return (Boolean)class_ItemStack_isEmptyMethod.invoke(handle);
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user