Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static String mcPackage = null;
- private static Class classItemFrame = null;
- private static Constructor constructor = null;
- private static Method worldGetHandle = null;
- private static Method worldAddEntity = null;
- private static Method itemFrameGetBukkitEntity = null;
- public static ItemFrame spawnItemFrame(Location loc, BlockFace bf) throws Exception {
- int side = 0;
- if(bf == BlockFace.SOUTH) {
- side = 0;
- } else if(bf == BlockFace.WEST) {
- side = 1;
- } else if(bf == BlockFace.NORTH) {
- side = 2;
- } else if(bf == BlockFace.EAST) {
- side = 3;
- }
- World w = loc.getWorld();
- // CACHE CRAFTWORLD METHOD
- if(worldGetHandle == null) worldGetHandle = w.getClass().getMethod("getHandle");
- // GET NMS WORLD
- Object mcWorld = worldGetHandle.invoke(w);
- // CACHE NMS ELEMENTS
- if(mcPackage == null) mcPackage = mcWorld.getClass().getPackage().getName();
- if(classItemFrame == null) classItemFrame = Class.forName(mcPackage + ".EntityItemFrame");
- if(worldAddEntity == null) worldAddEntity = mcWorld.getClass().getMethod("addEntity", classItemFrame.getSuperclass().getSuperclass());
- if(itemFrameGetBukkitEntity == null) itemFrameGetBukkitEntity = classItemFrame.getMethod("getBukkitEntity");
- if(constructor == null) constructor = classItemFrame.getConstructor(mcWorld.getClass().getSuperclass(), int.class, int.class, int.class, int.class);
- // CREATE A NEW ITEMFRAME
- Object mcItemFrame = constructor.newInstance(mcWorld, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), side);
- // ADDS THE ITEMFRAME TO THE WORLD
- worldAddEntity.invoke(mcWorld, mcItemFrame);
- // FINALLY, RETURNS THE BUKKIT ITEMFRAME
- return (ItemFrame)classItemFrame.getMethod("getBukkitEntity").invoke(mcItemFrame);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement