public static EntityCategory fromEntity(Entity entity) { for (Class<? extends Entity> entityClass : map.keySet()) { if (entityClass.isAssignableFrom(entity.getClass())) { return map.get(entityClass); } } return null; }
public static Class getNMSClass(Class inClass) { Class bukkit = null; Class search = inClass; while (bukkit == null && search != Object.class) { bukkit = s_classes.get(search); search = search.getSuperclass(); } return bukkit; }
/** * Returns whether our running CraftBukkit already supports the HangingEvent instead of the * PaintingEvent * * @return true if the hanging event is supported */ public static boolean hasHangingEvent() { Class<?> tmp = null; try { tmp = Class.forName("org.bukkit.event.hanging.HangingEvent"); } catch (ClassNotFoundException ignored) { } return (tmp != null); }
private static Field getField(final Class<?> clazz, final String name) { try { final Field field = clazz.getDeclaredField(name); field.setAccessible(true); return field; } catch (Exception e) { e.printStackTrace(); return null; } }
public boolean setSkin(final String url) { try { Class.forName("org.getspout.spout.Spout"); final SpoutPlayer sp = this.getSpoutPlayer(); sp.setSkin(url); return true; } catch (final ClassNotFoundException e) { return false; } }
private static Method getMethod(final Class<?> clazz, final String name, final Class<?>... args) { Method[] methods; for (int length = (methods = clazz.getMethods()).length, i = 0; i < length; ++i) { final Method m = methods[i]; if (m.getName().equals(name) && (args.length == 0 || ClassListEqual(args, m.getParameterTypes()))) { m.setAccessible(true); return m; } } return null; }
public SpoutPlayer getSpoutPlayer() { try { Class.forName("org.getspout.spout.Spout"); if (!(this.getEntity().getBukkitEntity() instanceof SpoutCraftPlayer)) ((NPCEntity) this.getEntity()) .setBukkitEntity( new SpoutCraftPlayer( (CraftServer) Bukkit.getServer(), (EntityPlayer) this.getEntity())); return (SpoutPlayer) this.getEntity().getBukkitEntity(); } catch (final ClassNotFoundException e) { return null; } }
private static Class<?> getVersionedClass(final String className) throws ClassNotFoundException { if (className.startsWith("net.minecraft.server")) { if (InventoryUtil.version.isEmpty()) { return Class.forName(className); } return Class.forName( String.format( "net.minecraft.server%s.%s", InventoryUtil.version, className.substring("net.minecraft.server.".length()))); } else { if (!className.startsWith("org.bukkit.craftbukkit")) { throw new IllegalArgumentException("Not a versioned class!"); } if (InventoryUtil.version.isEmpty()) { return Class.forName(className); } return Class.forName( String.format( "net.minecraft.server%s.%s", InventoryUtil.version, className.substring("org.bukkit.craftbukkit.".length()))); } }
static { ParticleUtils.version = ""; try { ParticleUtils.version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; ParticleUtils.packetType = Class.forName(getPacketPlayOutParticles()); final Class<?> typeCraftPlayer = Class.forName(getCraftPlayerClasspath()); final Class<?> typeNMSPlayer = Class.forName(getNMSPlayerClasspath()); final Class<?> typePlayerConnection = Class.forName(getPlayerConnectionClasspath()); ParticleUtils.getHandle = typeCraftPlayer.getMethod("getHandle", (Class<?>[]) new Class[0]); ParticleUtils.playerConnection = typeNMSPlayer.getField("playerConnection"); ParticleUtils.sendPacket = typePlayerConnection.getMethod("sendPacket", Class.forName(getPacketClasspath())); } catch (Exception e) { System.out.println("Failed to setup reflection for PacketPlayOutWorldParticles"); e.printStackTrace(); } }