Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HUGE_EXPLOSION("hugeexplosion", "EXPLOSION_HUGE"),
- LARGE_EXPLODE("largeexplode", "EXPLOSION_LARGE"),
- BUBBLE("bubble", "WATER_BUBBLE"),
- SUSPEND("suspended", "SUSPENDED"),
- DEPTH_SUSPEND("depthsuspend", "SUSPENDED_DEPTH"),
- MAGIC_CRIT("magicCrit", "CRIT_MAGIC"),
- MOB_SPELL("mobSpell", "SPELL_MOB", true),
- MOB_SPELL_AMBIENT("mobSpellAmbient", "SPELL_MOB_AMBIENT"),
- INSTANT_SPELL("instantSpell", "SPELL_INSTANT"),
- WITCH_MAGIC("witchMagic", "SPELL_WITCH"),
- EXPLODE("explode", "EXPLOSION_NORMAL"),
- SPLASH("splash", "WATER_SPLASH"),
- LARGE_SMOKE("largesmoke", "SMOKE_LARGE"),
- RED_DUST("reddust", "REDSTONE", true),
- SNOWBALL_POOF("snowballpoof", "SNOWBALL"),
- ANGRY_VILLAGER("angryVillager", "VILLAGER_ANGRY"),
- HAPPY_VILLAGER("happyVillager", "VILLAGER_HAPPY"),
- EXPLOSION_NORMAL(EXPLODE.getName()),
- EXPLOSION_LARGE(LARGE_EXPLODE.getName()),
- EXPLOSION_HUGE(HUGE_EXPLOSION.getName()),
- FIREWORKS_SPARK("fireworksSpark"),
- WATER_BUBBLE(BUBBLE.getName()),
- WATER_SPLASH(SPLASH.getName()),
- WATER_WAKE("wake"),
- SUSPENDED(SUSPEND.getName()),
- SUSPENDED_DEPTH(DEPTH_SUSPEND.getName()),
- CRIT("crit"),
- CRIT_MAGIC(MAGIC_CRIT.getName()),
- SMOKE_NORMAL("smoke"),
- SMOKE_LARGE(LARGE_SMOKE.getName()),
- SPELL("spell"),
- SPELL_INSTANT(INSTANT_SPELL.getName()),
- SPELL_MOB(MOB_SPELL.getName(), true),
- SPELL_MOB_AMBIENT(MOB_SPELL_AMBIENT.getName()),
- SPELL_WITCH(WITCH_MAGIC.getName()),
- DRIP_WATER("dripWater"),
- DRIP_LAVA("dripLava"),
- VILLAGER_ANGRY(ANGRY_VILLAGER.getName()),
- VILLAGER_HAPPY(HAPPY_VILLAGER.getName()),
- TOWN_AURA("townaura"),
- NOTE("note", true),
- PORTAL("portal"),
- ENCHANTMENT_TABLE("enchantmenttable"),
- FLAME("flame"),
- LAVA("lava"),
- FOOTSTEP("footstep"),
- CLOUD("cloud"),
- REDSTONE("reddust", true),
- SNOWBALL("snowballpoof"),
- SNOW_SHOVEL("snowshovel"),
- SLIME("slime"),
- HEART("heart"),
- BARRIER("barrier"),
- ITEM_CRACK("iconcrack_"),
- BLOCK_CRACK("blockcrack_"),
- BLOCK_DUST("blockdust_"),
- WATER_DROP("droplet"),
- ITEM_TAKE("take"),
- MOB_APPEARANCE("mobappearance");
- private String particleName;
- private String enumValue;
- private boolean hasColor;
- ParticleEffect(String particleName, String enumValue, boolean hasColor)
- {
- this.particleName = particleName;
- this.enumValue = enumValue;
- this.hasColor = hasColor;
- }
- ParticleEffect(String particleName, String enumValue)
- {
- this(particleName, enumValue, false);
- }
- ParticleEffect(String particleName)
- {
- this(particleName, null);
- }
- ParticleEffect(String particleName, boolean hasColor)
- {
- this(particleName, null, hasColor);
- }
- //<editor-fold desc="getName">
- public String getName()
- {
- return this.particleName;
- }
- //</editor-fold>
- //<editor-fold desc="hasColor">
- public boolean hasColor()
- {
- return hasColor;
- }
- //</editor-fold>
- private static Class<?> nmsPacketPlayOutParticle = ReflectionUtilities.getNMSClass("PacketPlayOutWorldParticles");
- private static Class<?> nmsEnumParticle;
- private static int particleRange = 25;
- //<editor-fold desc="setRange">
- public static void setRange(int range)
- {
- if (range < 0)
- {
- throw new IllegalArgumentException("Range must be positive!");
- }
- particleRange = range;
- }
- //</editor-fold>
- //<editor-fold desc="getRange">
- public static int getRange()
- {
- return particleRange;
- }
- //</editor-fold>
- //<editor-fold desc="sendToPlayer">
- private void sendToPlayer(Player player, Location location, float offsetX, float offsetY, float offsetZ, float speed, int count, int... extra)
- {
- sendToPlayer(player, location, offsetX, offsetY, offsetZ, speed, count, false, extra);
- }
- //</editor-fold>
- //<editor-fold desc="sendToPlayer">
- private void sendToPlayer(Player player, Location location, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force, int... extra)
- {
- if (!force && !isPlayerInRange(player, location))
- {
- return;
- }
- if (ReflectionUtilities.getVersion().contains("v1_8"))
- {
- try
- {
- if (nmsEnumParticle == null)
- {
- nmsEnumParticle = ReflectionUtilities.getNMSClass("EnumParticle");
- }
- if (this == BLOCK_CRACK)
- {
- int id = 0;
- int data = 0;
- if (extra.length > 0)
- {
- id = extra[0];
- }
- if (extra.length > 1)
- {
- data = extra[1];
- }
- extra = new int[]{
- id,
- id | data << 12};
- }
- Object packet = nmsPacketPlayOutParticle.getConstructor(new Class[]{
- nmsEnumParticle,
- boolean.class,
- float.class,
- float.class,
- float.class,
- float.class,
- float.class,
- float.class,
- float.class,
- int.class,
- int[].class}).newInstance(getEnum(nmsEnumParticle.getName() + "." + (this.enumValue != null ? this.enumValue : this.name().toUpperCase())), true, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count, extra);
- Object handle = ReflectionUtilities.getHandle(player);
- Object connection = ReflectionUtilities.getField(handle.getClass(), "playerConnection").get(handle);
- ReflectionUtilities.getMethod(connection.getClass(), "sendPacket", new Class[0]).invoke(connection, packet);
- } catch (Exception e)
- {
- try
- {
- throw e;
- } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e1)
- {
- e1.printStackTrace();
- }
- }
- } else
- {
- try
- {
- if (this.particleName == null)
- {
- this.particleName = this.name().toLowerCase();
- }
- String name = this.particleName;
- if (this == BLOCK_CRACK || this == ITEM_CRACK || this == BLOCK_DUST)
- {
- int id = 0;
- int data = 0;
- if (extra.length > 0)
- {
- id = extra[0];
- }
- if (extra.length > 1)
- {
- data = extra[1];
- }
- name += id + "_" + data;
- }
- Object packet = nmsPacketPlayOutParticle.getConstructor(new Class[]{
- String.class,
- float.class,
- float.class,
- float.class,
- float.class,
- float.class,
- float.class,
- float.class,
- int.class}).newInstance(name, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count);
- Object handle = ReflectionUtilities.getHandle(player);
- Object connection = ReflectionUtilities.getField(handle.getClass(), "playerConnection").get(handle);
- ReflectionUtilities.getMethod(connection.getClass(), "sendPacket", new Class[0]).invoke(connection, packet);
- } catch (Exception e)
- {
- try
- {
- throw e;
- } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e1)
- {
- e1.printStackTrace();
- }
- }
- }
- }
- //</editor-fold>
- //<editor-fold desc="sendToPlayer">
- public void sendToPlayer(Player player, Location location, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force)
- {
- this.sendToPlayer(player, location, offsetX, offsetY, offsetZ, speed, count, force, new int[0]);
- }
- //</editor-fold>
- //<editor-fold desc="sendToPlayer">
- public void sendToPlayer(Player player, Location location, float offsetX, float offsetY, float offsetZ, float speed, int count)
- {
- this.sendToPlayer(player, location, offsetX, offsetY, offsetZ, speed, count, false);
- }
- //</editor-fold>
- //<editor-fold desc="sendToPlayer">
- public void sendToPlayers(Collection<? extends Player> players, Location location, float offsetX, float offsetY, float offsetZ, float speed, int count)
- {
- for (Player p : players)
- {
- this.sendToPlayer(p, location, offsetX, offsetY, offsetZ, speed, count);
- }
- }
- //</editor-fold>
- //<editor-fold desc="sendToPlayer">
- public void sendToPlayers(Collection<? extends Player> players, Location location, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force)
- {
- for (Player p : players)
- {
- this.sendToPlayer(p, location, offsetX, offsetY, offsetZ, speed, count, force);
- }
- }
- //</editor-fold>
- //<editor-fold desc="sendToPlayer">
- public void sendToPlayers(Player[] players, Location location, float offsetX, float offsetY, float offsetZ, float speed, int count)
- {
- for (Player p : players)
- {
- this.sendToPlayer(p, location, offsetX, offsetY, offsetZ, speed, count);
- }
- }
- //</editor-fold>
- //<editor-fold desc="sendColor">
- public void sendColor(Player p, Location location, org.bukkit.Color color)
- {
- if (!this.hasColor)
- {
- return;
- }
- this.sendToPlayer(p, location, this.getColor(color.getRed()), this.getColor(color.getGreen()), this.getColor(color.getBlue()), 1, 0);
- }
- //</editor-fold>
- //<editor-fold desc="sendColor">
- public void sendColor(Player p, Location location, org.bukkit.Color color, boolean force)
- {
- if (!this.hasColor)
- {
- return;
- }
- this.sendToPlayer(p, location, this.getColor(color.getRed()), this.getColor(color.getGreen()), this.getColor(color.getBlue()), 1, 0, force);
- }
- //</editor-fold>
- //<editor-fold desc="sendColor">
- public void sendColor(Player p, Location location, java.awt.Color color)
- {
- if (!this.hasColor)
- {
- return;
- }
- this.sendToPlayer(p, location, this.getColor(color.getRed()), this.getColor(color.getGreen()), this.getColor(color.getBlue()), 1, 0);
- }
- //</editor-fold>
- //<editor-fold desc="sendColor">
- public void sendColor(Player p, Location location, java.awt.Color color, boolean force)
- {
- if (!this.hasColor)
- {
- return;
- }
- this.sendToPlayer(p, location, this.getColor(color.getRed()), this.getColor(color.getGreen()), this.getColor(color.getBlue()), 1, 0, force);
- }
- //</editor-fold>
- //<editor-fold desc="sendColor">
- public void sendColor(Collection<? extends Player> players, Location location, java.awt.Color color)
- {
- if (!this.hasColor)
- {
- return;
- }
- for (Player p : players)
- {
- this.sendColor(p, location, color);
- }
- }
- //</editor-fold>
- //<editor-fold desc="sendColor">
- public void sendColor(Collection<? extends Player> players, Location location, java.awt.Color color, boolean force)
- {
- if (!this.hasColor)
- {
- return;
- }
- for (Player p : players)
- {
- this.sendColor(p, location, color, force);
- }
- }
- //</editor-fold>
- //<editor-fold desc="sendColor">
- public void sendColor(Collection<? extends Player> players, Location location, org.bukkit.Color color)
- {
- if (!this.hasColor)
- {
- return;
- }
- for (Player p : players)
- {
- this.sendColor(p, location, color);
- }
- }
- //</editor-fold>
- //<editor-fold desc="sendColor">
- public void sendColor(Collection<? extends Player> players, Location location, org.bukkit.Color color, boolean force)
- {
- if (!this.hasColor)
- {
- return;
- }
- for (Player p : players)
- {
- this.sendColor(p, location, color, force);
- }
- }
- //</editor-fold>
- //<editor-fold desc="sendColor">
- public void sendColor(Player[] players, Location location, org.bukkit.Color color)
- {
- if (!this.hasColor)
- {
- return;
- }
- for (Player p : players)
- {
- this.sendColor(p, location, color);
- }
- }
- //</editor-fold>
- //<editor-fold desc="Description">
- public void sendColor(Player[] players, Location location, java.awt.Color color)
- {
- if (!this.hasColor)
- {
- return;
- }
- for (Player p : players)
- {
- this.sendColor(p, location, color);
- }
- }
- //</editor-fold>
- //<editor-fold desc="getColor">
- protected float getColor(float value)
- {
- if (value <= 0)
- {
- value = -1;
- }
- return value / 255;
- }
- //</editor-fold>
- //<editor-fold desc="sendBlockCrack">
- public void sendBlockCrack(Player player, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count)
- {
- if (this != BLOCK_CRACK)
- {
- throw new IllegalArgumentException("This method is only available for BLOCK_CRACK!");
- }
- this.sendToPlayer(player, location, offsetX, offsetY, offsetZ, speed, count, id, data);
- }
- //</editor-fold>
- //<editor-fold desc="sendBlockCrack">
- public void sendBlockCrack(Player player, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force)
- {
- if (this != BLOCK_CRACK)
- {
- throw new IllegalArgumentException("This method is only available for BLOCK_CRACK!");
- }
- this.sendToPlayer(player, location, offsetX, offsetY, offsetZ, speed, count, force, id, data);
- }
- //</editor-fold>
- //<editor-fold desc="sendBlockCrack">
- public void sendBlockCrack(Collection<? extends Player> players, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count)
- {
- if (this != BLOCK_CRACK)
- {
- throw new IllegalArgumentException("This method is only available for BLOCK_CRACK!");
- }
- for (Player p : players)
- {
- this.sendBlockCrack(p, location, id, data, offsetX, offsetY, offsetZ, speed, count);
- }
- }
- //</editor-fold>
- //<editor-fold desc="sendBlockCrack">
- public void sendBlockCrack(Collection<? extends Player> players, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force)
- {
- if (this != BLOCK_CRACK)
- {
- throw new IllegalArgumentException("This method is only available for BLOCK_CRACK!");
- }
- for (Player p : players)
- {
- this.sendBlockCrack(p, location, id, data, offsetX, offsetY, offsetZ, speed, count, force);
- }
- }
- //</editor-fold>
- //<editor-fold desc="sendBlockCrack">
- public void sendBlockCrack(Player[] players, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count)
- {
- if (this != BLOCK_CRACK)
- {
- throw new IllegalArgumentException("This method is only available for BLOCK_CRACK!");
- }
- for (Player p : players)
- {
- this.sendBlockCrack(p, location, id, data, offsetX, offsetY, offsetZ, speed, count);
- }
- }
- //</editor-fold>
- //<editor-fold desc="sendItemCrack">
- public void sendItemCrack(Player player, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count)
- {
- if (this != ITEM_CRACK)
- {
- throw new IllegalArgumentException("This method is only available for ITEM_CRACK!");
- }
- this.sendToPlayer(player, location, offsetX, offsetY, offsetZ, speed, count, id, data);
- }
- //</editor-fold>
- //<editor-fold desc="sendItemCrack">
- public void sendItemCrack(Player player, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force)
- {
- if (this != ITEM_CRACK)
- {
- throw new IllegalArgumentException("This method is only available for ITEM_CRACK!");
- }
- this.sendToPlayer(player, location, offsetX, offsetY, offsetZ, speed, count, force, id, data);
- }
- //</editor-fold>
- //<editor-fold desc="sendItemCrack">
- public void sendItemCrack(Collection<? extends Player> players, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count)
- {
- if (this != ITEM_CRACK)
- {
- throw new IllegalArgumentException("This method is only available for ITEM_CRACK!");
- }
- for (Player p : players)
- {
- this.sendItemCrack(p, location, id, data, offsetX, offsetY, offsetZ, speed, count);
- }
- }
- //</editor-fold>
- //<editor-fold desc="sendItemCrack">
- public void sendItemCrack(Collection<? extends Player> players, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force)
- {
- if (this != ITEM_CRACK)
- {
- throw new IllegalArgumentException("This method is only available for ITEM_CRACK!");
- }
- for (Player p : players)
- {
- this.sendItemCrack(p, location, id, data, offsetX, offsetY, offsetZ, speed, count, force);
- }
- }
- //</editor-fold>
- //<editor-fold desc="sendItemCrack">
- public void sendItemCrack(Player[] players, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count)
- {
- if (this != ITEM_CRACK)
- {
- throw new IllegalArgumentException("This method is only available for ITEM_CRACK!");
- }
- for (Player p : players)
- {
- this.sendItemCrack(p, location, id, data, offsetX, offsetY, offsetZ, speed, count);
- }
- }
- //</editor-fold>
- //<editor-fold desc="sendBlockDust">
- public void sendBlockDust(Player p, Location location, int id, float offsetX, float offsetY, float offsetZ, float speed, int count)
- {
- if (this != BLOCK_DUST)
- {
- throw new IllegalArgumentException("This method is only available for BLOCK_DUST!");
- }
- this.sendToPlayer(p, location, offsetX, offsetY, offsetZ, speed, count, id);
- }
- //</editor-fold>
- //<editor-fold desc="sendBlockDust">
- public void sendBlockDust(Player p, Location location, int id, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force)
- {
- if (this != BLOCK_DUST)
- {
- throw new IllegalArgumentException("This method is only available for BLOCK_DUST!");
- }
- this.sendToPlayer(p, location, offsetX, offsetY, offsetZ, speed, count, force, id);
- }
- //</editor-fold>
- //<editor-fold desc="sendBlockDust">
- public void sendBlockDust(Collection<? extends Player> players, Location location, int id, float offsetX, float offsetY, float offsetZ, float speed, int count)
- {
- if (this != BLOCK_DUST)
- {
- throw new IllegalArgumentException("This method is only available for BLOCK_DUST!");
- }
- for (Player p : players)
- {
- this.sendBlockDust(p, location, id, offsetX, offsetY, offsetZ, speed, count);
- }
- }
- //</editor-fold>
- //<editor-fold desc="sendBlockDust">
- public void sendBlockDust(Collection<? extends Player> players, Location location, int id, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force)
- {
- if (this != BLOCK_DUST)
- {
- throw new IllegalArgumentException("This method is only available for BLOCK_DUST!");
- }
- for (Player p : players)
- {
- this.sendBlockDust(p, location, id, offsetX, offsetY, offsetZ, speed, count, force);
- }
- }
- //</editor-fold>
- //<editor-fold desc="sendBlockDust">
- public void sendBlockDust(Player[] players, Location location, int id, float offsetX, float offsetY, float offsetZ, float speed, int count)
- {
- if (this != BLOCK_DUST)
- {
- throw new IllegalArgumentException("This method is only available for BLOCK_DUST!");
- }
- for (Player p : players)
- {
- this.sendBlockDust(p, location, id, offsetX, offsetY, offsetZ, speed, count);
- }
- }
- //</editor-fold>
- private static Class<?> nmsPlayerConnection;
- private static Class<?> nmsEntityPlayer;
- private static Class<?> ioNettyChannel;
- private static Method nmsNetworkGetVersion;
- private static Field nmsFieldPlayerConnection;
- private static Field nmsFieldNetworkManager;
- private static Field nmsFieldNetworkManagerI;
- private static Field nmsFieldNetworkManagerM;
- static
- {
- String ver = ReflectionUtilities.getVersion();
- try
- {
- nmsPlayerConnection = ReflectionUtilities.getNMSClass("PlayerConnection");
- nmsEntityPlayer = ReflectionUtilities.getNMSClass("EntityPlayer");
- ioNettyChannel = ver.contains("1_7") ? Class.forName("net.minecraft.util.io.netty.channel.Channel") : Class.forName("io.netty.channel.Channel");
- nmsFieldPlayerConnection = ReflectionUtilities.getField(nmsEntityPlayer, "playerConnection");
- nmsFieldNetworkManager = ReflectionUtilities.getField(nmsPlayerConnection, "networkManager");
- nmsFieldNetworkManagerI = ReflectionUtilities.getField(nmsFieldNetworkManager.getType(), "i");
- nmsFieldNetworkManagerM = ReflectionUtilities.getField(nmsFieldNetworkManager.getType(), "m");
- nmsNetworkGetVersion = ReflectionUtilities.getMethod(nmsFieldNetworkManager.getType(), "getVersion", ioNettyChannel);
- } catch (Exception e)
- {
- System.err.println("[ParticleLIB] Error while loading: " + e.getMessage());
- e.printStackTrace(System.err);
- Bukkit.getPluginManager().disablePlugin(Bukkit.getPluginManager().getPlugin("ParticleLIB"));
- }
- }
- //<editor-fold desc="getEnum">
- private static Enum<?> getEnum(String enumFullName)
- {
- String[] x = enumFullName.split("\\.(?=[^\\.]+$)");
- if (x.length == 2)
- {
- String enumClassName = x[0];
- String enumName = x[1];
- try
- {
- Class<Enum> cl = (Class<Enum>) Class.forName(enumClassName);
- return Enum.valueOf(cl, enumName);
- } catch (ClassNotFoundException e)
- {
- e.printStackTrace();
- }
- }
- return null;
- }
- //</editor-fold>
- //<editor-fold desc="isPlayerInRange">
- public static boolean isPlayerInRange(Player p, Location center)
- {
- double distance = 0;
- if (!p.getLocation().getWorld().equals(center.getWorld()))
- {
- return false;
- }
- if ((distance = center.distanceSquared(p.getLocation())) > Double.MAX_VALUE)
- {
- return false;
- }
- return distance < particleRange * particleRange;
- }
- //</editor-fold>
- //<editor-fold desc="ReflectionUtilities">
- public static class ReflectionUtilities {
- public static void setValue(Object instance, String fieldName, Object value)
- {
- Field field = null;
- try
- {
- field = instance.getClass().getDeclaredField(fieldName);
- } catch (NoSuchFieldException e)
- {
- e.printStackTrace();
- }
- field.setAccessible(true);
- try
- {
- field.set(instance, value);
- } catch (IllegalAccessException e)
- {
- e.printStackTrace();
- }
- }
- public static Object getValue(Object instance, String fieldName)
- {
- Field field = null;
- try
- {
- field = instance.getClass().getDeclaredField(fieldName);
- } catch (NoSuchFieldException e)
- {
- e.printStackTrace();
- }
- field.setAccessible(true);
- try
- {
- return field.get(instance);
- } catch (IllegalAccessException e)
- {
- e.printStackTrace();
- }
- return null;
- }
- public static String getVersion()
- {
- String name = Bukkit.getServer().getClass().getPackage().getName();
- String version = name.substring(name.lastIndexOf('.') + 1) + ".";
- return version;
- }
- public static Class<?> getNMSClass(String className)
- {
- String fullName = "net.minecraft.server." + getVersion() + className;
- Class<?> clazz = null;
- try
- {
- clazz = Class.forName(fullName);
- } catch (Exception e)
- {
- e.printStackTrace();
- }
- return clazz;
- }
- public static Class<?> getOBCClass(String className)
- {
- String fullName = "org.bukkit.craftbukkit." + getVersion() + className;
- Class<?> clazz = null;
- try
- {
- clazz = Class.forName(fullName);
- } catch (Exception e)
- {
- e.printStackTrace();
- }
- return clazz;
- }
- public static Object getHandle(Object obj)
- {
- try
- {
- return getMethod(obj.getClass(), "getHandle", new Class[0]).invoke(obj, new Object[0]);
- } catch (Exception e)
- {
- e.printStackTrace();
- }
- return null;
- }
- public static Field getField(Class<?> clazz, String name)
- {
- try
- {
- Field field = clazz.getDeclaredField(name);
- field.setAccessible(true);
- return field;
- } catch (Exception e)
- {
- e.printStackTrace();
- }
- return null;
- }
- public static Method getMethod(Class<?> clazz, String name, Class<?>... args)
- {
- for (Method m : clazz.getMethods())
- {
- if (m.getName().equals(name) && (args.length == 0 || ClassListEqual(args, m.getParameterTypes())))
- {
- m.setAccessible(true);
- return m;
- }
- }
- return null;
- }
- public static boolean ClassListEqual(Class<?>[] l1, Class<?>[] l2)
- {
- boolean equal = true;
- if (l1.length != l2.length)
- {
- return false;
- }
- for (int i = 0; i < l1.length; i++)
- {
- if (l1[i] != l2[i])
- {
- equal = false;
- break;
- }
- }
- return equal;
- }
- }
- //</editor-fold>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement