Advertisement
JackOUT

Untitled

Sep 15th, 2022
865
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.17 KB | None | 0 0
  1. package games.coob.laserturrets.model;
  2.  
  3. public class ArmorStand { // TODO
  4.  
  5.     /*public Object entity;
  6.  
  7.     Object item;
  8.  
  9.     private Object getMinecraftServerNMS() {
  10.         try {
  11.             final Method getHandle = Bukkit.getServer().getClass().getMethod("getServer");
  12.             return getHandle.invoke(Bukkit.getServer());
  13.         } catch (final Exception e) {
  14.             e.printStackTrace();
  15.         }
  16.         return null;
  17.     }
  18.  
  19.     private void addPlayerConnection() {
  20.         try {
  21.             final Object MinecraftServer = getMinecraftServerNMS();
  22.             final Constructor<?> newPC = ReflectionUtil.getNMSClass("PlayerConnection").getConstructors()[0];
  23.             final Object EnumNetworkManager = ReflectionUtil.getNMSClass("EnumProtocolDirection").getField("SERVERBOUND").get(null);
  24.             final Object NetworkManager = ReflectionUtil.getNMSClass("NetworkManager").getConstructors()[0].newInstance(EnumNetworkManager);
  25.             newPC.newInstance(MinecraftServer, NetworkManager, entity);
  26.         } catch (final Exception e) {
  27.             e.printStackTrace();
  28.         }
  29.     }
  30.  
  31.     public ArmorStand(final Location location, final ItemStack itemStack) {
  32.         try {
  33.             final Object world = getWorldNMS(location.getWorld());
  34.             entity = ReflectionUtil.getNMSClass("EntityArmorStand").getConstructors()[0].newInstance(world);
  35.             entity.getClass().getSuperclass().getSuperclass().getMethod("setLocation", double.class, double.class, double.class, float.class, float.class).invoke(entity, location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
  36.             entity.getClass().getMethod("setInvisible", boolean.class).invoke(entity, true);
  37.             entity.getClass().getMethod("setGravity", boolean.class).invoke(entity, false);
  38.             entity.getClass().getMethod("setArms", boolean.class).invoke(entity, true);
  39.             entity.getClass().getMethod("setBasePlate", boolean.class).invoke(entity, false);
  40.             ReflectionUtil.invoke("setEquipment", entity, 1, getCraftItemStack(itemStack));
  41.             //entity.getClass().getMethod("setEquipment", Object.class).invoke(entity, getCraftItemStack(itemStack, location.getWorld()));
  42.  
  43.             addPlayerConnection();
  44.         } catch (final Exception e) {
  45.             e.printStackTrace();
  46.         }
  47.     }
  48.  
  49.     public Object getEntity() {
  50.         try {
  51.             return entity.getClass().getSuperclass().getSuperclass().getMethod("getBukkitEntity").invoke(entity);
  52.         } catch (final Exception e) {
  53.             e.printStackTrace();
  54.         }
  55.         return null;
  56.     }
  57.  
  58.     private Object getCraftItemStack(final ItemStack itemStack) {
  59.         try {
  60.             //item = ReflectionUtil.getNMSClass("inventory.CraftItemStack");
  61.             //item.getClass().getMethod("asNMSCopy", ItemStack.class).invoke(item, itemStack);
  62.             item = ReflectionUtil.getOBCClass("inventory.CraftItemStack");
  63.  
  64.             item.getClass().getMethod("asNMSCopy", ItemStack.class).invoke(entity, itemStack);
  65.             //ReflectionUtil.invoke("asNMSCopy", item, itemStack);
  66.             return item;
  67.         } catch (final Exception e) {
  68.             e.printStackTrace();
  69.         }
  70.  
  71.         return null;
  72.     }
  73.  
  74.     private Object getWorldNMS(final World world) {
  75.         try {
  76.             final Method getHandle = world.getClass().getMethod("getHandle");
  77.             final Object nmsWorld = getHandle.invoke(world);
  78.             return ReflectionUtil.getNMSClass("World").cast(nmsWorld);
  79.         } catch (final Exception e) {
  80.             e.printStackTrace();
  81.         }
  82.  
  83.         return null;
  84.     }*/
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement