mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-22 10:22:29 +00:00
parent
150c178679
commit
4d7f5dc3b7
@ -26,11 +26,12 @@ public class Hologram {
|
|||||||
private ShopChest plugin;
|
private ShopChest plugin;
|
||||||
|
|
||||||
private Class<?> entityArmorStandClass = Utils.getNMSClass("EntityArmorStand");
|
private Class<?> entityArmorStandClass = Utils.getNMSClass("EntityArmorStand");
|
||||||
private Class<?> nmsWorldClass = Utils.getNMSClass("World");
|
private Class<?> worldClass = Utils.getNMSClass("World");
|
||||||
private Class<?> packetPlayOutSpawnEntityLivingClass = Utils.getNMSClass("PacketPlayOutSpawnEntityLiving");
|
private Class<?> packetPlayOutSpawnEntityLivingClass = Utils.getNMSClass("PacketPlayOutSpawnEntityLiving");
|
||||||
private Class<?> packetPlayOutEntityDestroyClass = Utils.getNMSClass("PacketPlayOutEntityDestroy");
|
private Class<?> packetPlayOutEntityDestroyClass = Utils.getNMSClass("PacketPlayOutEntityDestroy");
|
||||||
private Class<?> entityClass = Utils.getNMSClass("Entity");
|
private Class<?> entityClass = Utils.getNMSClass("Entity");
|
||||||
private Class<?> entityLivingClass = Utils.getNMSClass("EntityLiving");
|
private Class<?> entityLivingClass = Utils.getNMSClass("EntityLiving");
|
||||||
|
private Class<?> worldServerClass = Utils.getNMSClass("WorldServer");
|
||||||
|
|
||||||
public Hologram(ShopChest plugin, String[] text, Location location) {
|
public Hologram(ShopChest plugin, String[] text, Location location) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -38,8 +39,9 @@ public class Hologram {
|
|||||||
this.location = location;
|
this.location = location;
|
||||||
|
|
||||||
Class[] requiredClasses = new Class[] {
|
Class[] requiredClasses = new Class[] {
|
||||||
nmsWorldClass, entityArmorStandClass, entityLivingClass, entityClass,
|
worldClass, entityArmorStandClass, entityLivingClass, entityClass,
|
||||||
packetPlayOutSpawnEntityLivingClass, packetPlayOutEntityDestroyClass
|
packetPlayOutSpawnEntityLivingClass, packetPlayOutEntityDestroyClass,
|
||||||
|
worldServerClass
|
||||||
};
|
};
|
||||||
|
|
||||||
for (Class c : requiredClasses) {
|
for (Class c : requiredClasses) {
|
||||||
@ -72,10 +74,10 @@ public class Hologram {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Object craftWorld = loc.getWorld().getClass().cast(loc.getWorld());
|
Object craftWorld = loc.getWorld().getClass().cast(loc.getWorld());
|
||||||
Object nmsWorldServer = craftWorld.getClass().getMethod("getHandle").invoke(craftWorld);
|
Object worldServer = craftWorld.getClass().getMethod("getHandle").invoke(craftWorld);
|
||||||
|
|
||||||
Constructor entityArmorStandConstructor = entityArmorStandClass.getConstructor(nmsWorldClass, double.class, double.class, double.class);
|
Constructor entityArmorStandConstructor = entityArmorStandClass.getConstructor(worldClass, double.class, double.class, double.class);
|
||||||
Object entityArmorStand = entityArmorStandConstructor.newInstance(nmsWorldServer, loc.getX(), loc.getY(),loc.getZ());
|
Object entityArmorStand = entityArmorStandConstructor.newInstance(worldServer, loc.getX(), loc.getY(),loc.getZ());
|
||||||
|
|
||||||
if (text != null) {
|
if (text != null) {
|
||||||
entityArmorStandClass.getMethod("setCustomName", String.class).invoke(entityArmorStand, text);
|
entityArmorStandClass.getMethod("setCustomName", String.class).invoke(entityArmorStand, text);
|
||||||
@ -91,9 +93,9 @@ public class Hologram {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Adds the entity to some lists so it can call interact events
|
// Adds the entity to some lists so it can call interact events
|
||||||
Method addEntityMethod = nmsWorldServer.getClass().getDeclaredMethod((Utils.getMajorVersion() == 8 ? "a" : "b"), entityClass);
|
Method addEntityMethod = worldServerClass.getDeclaredMethod((Utils.getMajorVersion() == 8 ? "a" : "b"), entityClass);
|
||||||
addEntityMethod.setAccessible(true);
|
addEntityMethod.setAccessible(true);
|
||||||
addEntityMethod.invoke(nmsWorldServer, entityArmorStand);
|
addEntityMethod.invoke(worldServerClass.cast(worldServer), entityArmorStand);
|
||||||
|
|
||||||
Object uuid = entityClass.getMethod("getUniqueID").invoke(entityArmorStand);
|
Object uuid = entityClass.getMethod("getUniqueID").invoke(entityArmorStand);
|
||||||
|
|
||||||
@ -106,8 +108,6 @@ public class Hologram {
|
|||||||
plugin.debug("Could not create Hologram with reflection");
|
plugin.debug("Could not create Hologram with reflection");
|
||||||
plugin.debug(e);
|
plugin.debug(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
holograms.add(this);
|
holograms.add(this);
|
||||||
|
Loading…
Reference in New Issue
Block a user