1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-21 04:05:48 +00:00
Slimefun4/src/me/mrCookieSlime/Slimefun/holograms/ArmorStandFactory.java

161 lines
6.9 KiB
Java
Raw Normal View History

2016-04-14 16:24:03 +00:00
package me.mrCookieSlime.Slimefun.holograms;
import java.lang.reflect.Method;
import me.mrCookieSlime.CSCoreLibPlugin.general.Reflection.ReflectionUtils;
import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.EulerAngle;
public class ArmorStandFactory {
2016-11-20 13:47:46 +00:00
2016-04-14 16:24:03 +00:00
public static ArmorStand createHidden(Location l) {
ArmorStand armorstand = (ArmorStand) l.getWorld().spawnEntity(l, EntityType.ARMOR_STAND);
armorstand.setVisible(false);
armorstand.setGravity(false);
armorstand.setBasePlate(false);
armorstand.setCustomNameVisible(true);
armorstand.setRemoveWhenFarAway(false);
try {
Object nmsEntity = armorstand.getClass().getMethod("getHandle").invoke(armorstand);
if (ReflectionUtils.getVersion().startsWith("v1_9_")) {
2016-05-14 11:29:40 +00:00
try {
ReflectionUtils.setFieldValue(nmsEntity, "bz", 2039583);
2016-11-20 13:47:46 +00:00
} catch (IllegalArgumentException x) {
2016-05-14 11:29:40 +00:00
ReflectionUtils.setFieldValue(nmsEntity, "bA", 2039583);
}
2016-04-14 16:24:03 +00:00
}
2016-07-31 18:36:39 +00:00
else if (ReflectionUtils.getVersion().startsWith("v1_10_")) {
try {
ReflectionUtils.setFieldValue(nmsEntity, "bB", 2039583);
2016-11-20 13:47:46 +00:00
} catch (IllegalArgumentException x) {
2016-11-13 17:16:02 +00:00
ReflectionUtils.setFieldValue(nmsEntity, "bA", true);
2016-07-31 18:36:39 +00:00
}
}
2016-11-20 13:47:46 +00:00
else if (ReflectionUtils.getVersion().startsWith("v1_11_")) {
try {
ReflectionUtils.setFieldValue(nmsEntity, "bA", 2039583);
} catch (IllegalArgumentException x) {
ReflectionUtils.setFieldValue(nmsEntity, "bB", true);
}
}
2016-04-14 16:24:03 +00:00
else {
Method method = nmsEntity.getClass().getMethod("getNBTTag");
Object tag = method.invoke(nmsEntity);
if(tag == null) {
tag = ReflectionUtils.getClass("NBTTagCompound").newInstance();
}
method = nmsEntity.getClass().getMethod("c", ReflectionUtils.getClass("NBTTagCompound"));
method.invoke(nmsEntity, tag);
2016-11-20 13:47:46 +00:00
2016-04-14 16:24:03 +00:00
tag.getClass().getMethod("setBoolean", String.class, boolean.class).invoke(tag, "Invulnerable", true);
nmsEntity.getClass().getMethod("f", ReflectionUtils.getClass("NBTTagCompound")).invoke(nmsEntity, tag);
2016-11-20 13:47:46 +00:00
2016-04-14 16:24:03 +00:00
tag.getClass().getMethod("setInt", String.class, int.class).invoke(tag, "DisabledSlots", 2039583);
nmsEntity.getClass().getMethod("a", ReflectionUtils.getClass("NBTTagCompound")).invoke(nmsEntity, tag);
}
} catch (Exception x) {
x.printStackTrace();
}
return armorstand;
}
2016-11-20 13:47:46 +00:00
2016-04-14 16:24:03 +00:00
public static ArmorStand createSmall(Location l, ItemStack item, EulerAngle arm, float yaw) {
l.setYaw(yaw);
ArmorStand armorstand = (ArmorStand) l.getWorld().spawnEntity(l, EntityType.ARMOR_STAND);
armorstand.getEquipment().setItemInMainHand(item);
armorstand.setVisible(false);
armorstand.setGravity(false);
armorstand.setSmall(true);
armorstand.setArms(true);
armorstand.setRightArmPose(arm);
armorstand.setBasePlate(false);
armorstand.setRemoveWhenFarAway(false);
try {
Object nmsEntity = armorstand.getClass().getMethod("getHandle").invoke(armorstand);
if (ReflectionUtils.getVersion().startsWith("v1_9_")) {
2016-05-14 11:29:40 +00:00
try {
ReflectionUtils.setFieldValue(nmsEntity, "bz", 2039583);
} catch(IllegalArgumentException x) {
ReflectionUtils.setFieldValue(nmsEntity, "bA", 2039583);
}
2016-04-14 16:24:03 +00:00
}
2017-01-18 14:26:46 +00:00
else if (ReflectionUtils.getVersion().startsWith("v1_10_")) {
try {
ReflectionUtils.setFieldValue(nmsEntity, "bB", 2039583);
} catch (IllegalArgumentException x) {
ReflectionUtils.setFieldValue(nmsEntity, "bA", true);
}
}
else if (ReflectionUtils.getVersion().startsWith("v1_11_")) {
try {
ReflectionUtils.setFieldValue(nmsEntity, "bA", 2039583);
} catch (IllegalArgumentException x) {
ReflectionUtils.setFieldValue(nmsEntity, "bB", true);
}
}
2016-04-14 16:24:03 +00:00
else {
Method method = nmsEntity.getClass().getMethod("getNBTTag");
Object tag = method.invoke(nmsEntity);
if(tag == null) {
tag = ReflectionUtils.getClass("NBTTagCompound").newInstance();
}
method = nmsEntity.getClass().getMethod("c", ReflectionUtils.getClass("NBTTagCompound"));
method.invoke(nmsEntity, tag);
2016-11-20 13:47:46 +00:00
2016-04-14 16:24:03 +00:00
tag.getClass().getMethod("setBoolean", String.class, boolean.class).invoke(tag, "Invulnerable", true);
nmsEntity.getClass().getMethod("f", ReflectionUtils.getClass("NBTTagCompound")).invoke(nmsEntity, tag);
2016-11-20 13:47:46 +00:00
2016-04-14 16:24:03 +00:00
tag.getClass().getMethod("setInt", String.class, int.class).invoke(tag, "DisabledSlots", 2039583);
nmsEntity.getClass().getMethod("a", ReflectionUtils.getClass("NBTTagCompound")).invoke(nmsEntity, tag);
}
} catch (Exception x) {
x.printStackTrace();
}
return armorstand;
}
2016-11-20 13:47:46 +00:00
2016-04-14 16:24:03 +00:00
public static ArmorStand createSmall(Location l, ItemStack head, float yaw) {
l.setYaw(yaw);
ArmorStand armorstand = (ArmorStand) l.getWorld().spawnEntity(l, EntityType.ARMOR_STAND);
armorstand.getEquipment().setHelmet(head);
armorstand.setVisible(false);
armorstand.setGravity(false);
armorstand.setSmall(true);
armorstand.setBasePlate(false);
armorstand.setRemoveWhenFarAway(false);
try {
Object nmsEntity = armorstand.getClass().getMethod("getHandle").invoke(armorstand);
if (ReflectionUtils.getVersion().startsWith("v1_9_")) {
2016-05-14 11:29:40 +00:00
try {
ReflectionUtils.setFieldValue(nmsEntity, "bz", 2039583);
} catch(IllegalArgumentException x) {
ReflectionUtils.setFieldValue(nmsEntity, "bA", 2039583);
}
2016-04-14 16:24:03 +00:00
}
else {
Method method = nmsEntity.getClass().getMethod("getNBTTag");
Object tag = method.invoke(nmsEntity);
if(tag == null) {
tag = ReflectionUtils.getClass("NBTTagCompound").newInstance();
}
method = nmsEntity.getClass().getMethod("c", ReflectionUtils.getClass("NBTTagCompound"));
method.invoke(nmsEntity, tag);
2016-11-20 13:47:46 +00:00
2016-04-14 16:24:03 +00:00
tag.getClass().getMethod("setBoolean", String.class, boolean.class).invoke(tag, "Invulnerable", true);
nmsEntity.getClass().getMethod("f", ReflectionUtils.getClass("NBTTagCompound")).invoke(nmsEntity, tag);
2016-11-20 13:47:46 +00:00
2016-04-14 16:24:03 +00:00
tag.getClass().getMethod("setInt", String.class, int.class).invoke(tag, "DisabledSlots", 2039583);
nmsEntity.getClass().getMethod("a", ReflectionUtils.getClass("NBTTagCompound")).invoke(nmsEntity, tag);
}
} catch (Exception x) {
x.printStackTrace();
}
return armorstand;
}
}