Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.filipenock.mg.Utils;
- import java.lang.reflect.Field;
- import java.lang.reflect.Method;
- import java.util.Collection;
- import org.bukkit.Bukkit;
- import org.bukkit.Color;
- import org.bukkit.Location;
- import org.bukkit.entity.Player;
- @SuppressWarnings("all")
- public enum ParticleEffect
- {
- //EXAMPLE:
- // ParticleEffect.ANGRY_VILLAGER.sendToPlayer(player, location, offsetX, offsetY, offsetZ, speed, count);
- 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(ParticleEffect.EXPLODE.getName()),
- EXPLOSION_LARGE(ParticleEffect.LARGE_EXPLODE.getName()),
- EXPLOSION_HUGE(ParticleEffect.HUGE_EXPLOSION.getName()),
- FIREWORKS_SPARK("fireworksSpark"),
- WATER_BUBBLE(ParticleEffect.BUBBLE.getName()),
- WATER_SPLASH(ParticleEffect.SPLASH.getName()),
- WATER_WAKE("wake"),
- SUSPENDED(ParticleEffect.SUSPEND.getName()),
- SUSPENDED_DEPTH(ParticleEffect.DEPTH_SUSPEND.getName()),
- CRIT("crit"),
- CRIT_MAGIC(ParticleEffect.MAGIC_CRIT.getName()),
- SMOKE_NORMAL("smoke"),
- SMOKE_LARGE(ParticleEffect.LARGE_SMOKE.getName()),
- SPELL("spell"),
- SPELL_INSTANT(ParticleEffect.INSTANT_SPELL.getName()),
- SPELL_MOB(ParticleEffect.MOB_SPELL.getName(), true),
- SPELL_MOB_AMBIENT(ParticleEffect.MOB_SPELL_AMBIENT.getName()),
- SPELL_WITCH(ParticleEffect.WITCH_MAGIC.getName()),
- DRIP_WATER("dripWater"),
- DRIP_LAVA("dripLava"),
- VILLAGER_ANGRY(ParticleEffect.ANGRY_VILLAGER.getName()),
- VILLAGER_HAPPY(ParticleEffect.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;
- private static Class<?> nmsPacketPlayOutParticle;
- private static Class<?> nmsEnumParticle;
- private static int particleRange;
- 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;
- private ParticleEffect(String particleName, String enumValue, boolean hasColor) {
- this.particleName = particleName;
- this.enumValue = enumValue;
- this.hasColor = hasColor;
- }
- private ParticleEffect(String particleName, String enumValue) {
- this(particleName, enumValue, false);
- }
- private ParticleEffect(String particleName) {
- this(particleName, null);
- }
- private ParticleEffect(String particleName, boolean hasColor) {
- this(particleName, null, hasColor);
- }
- public String getName() {
- return this.particleName;
- }
- public boolean hasColor() {
- return this.hasColor;
- }
- @Deprecated
- public static void setRange(int range) {
- if (range < 0) {
- throw new IllegalArgumentException("Range must be positive!");
- }
- ParticleEffect.particleRange = range;
- }
- @Deprecated
- public static int getRange() {
- return ParticleEffect.particleRange;
- }
- @Deprecated
- private void sendToPlayer(Player player, Location location, float offsetX, float offsetY, float offsetZ, float speed, int count, int... extra) throws Exception {
- this.sendToPlayer(player, location, offsetX, offsetY, offsetZ, speed, count, false, extra);
- }
- private void sendToPlayer(Player player, Location location, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force, int... extra) throws Exception {
- if (!force && !isPlayerInRange(player, location)) {
- return;
- }
- if (ReflectionUtilities.getVersion().contains("v1_8")) {
- try {
- if (ParticleEffect.nmsEnumParticle == null) {
- ParticleEffect.nmsEnumParticle = ReflectionUtilities.getNMSClass("EnumParticle");
- }
- if (this == ParticleEffect.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 = ParticleEffect.nmsPacketPlayOutParticle.getConstructor(ParticleEffect.nmsEnumParticle, Boolean.TYPE, Float.TYPE, Float.TYPE, Float.TYPE, Float.TYPE, Float.TYPE, Float.TYPE, Float.TYPE, Integer.TYPE, int[].class).newInstance(getEnum(ParticleEffect.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", (Class<?>[])new Class[0]).invoke(connection, packet);
- return;
- }
- catch (Exception e) {
- throw e;
- }
- }
- try {
- if (this.particleName == null) {
- this.particleName = this.name().toLowerCase();
- }
- String name = this.particleName;
- if (this == ParticleEffect.BLOCK_CRACK || this == ParticleEffect.ITEM_CRACK || this == ParticleEffect.BLOCK_DUST) {
- int id2 = 0;
- int data2 = 0;
- if (extra.length > 0) {
- id2 = extra[0];
- }
- if (extra.length > 1) {
- data2 = extra[1];
- }
- name = name + id2 + "_" + data2;
- }
- Object packet2 = ParticleEffect.nmsPacketPlayOutParticle.getConstructor(String.class, Float.TYPE, Float.TYPE, Float.TYPE, Float.TYPE, Float.TYPE, Float.TYPE, Float.TYPE, Integer.TYPE).newInstance(name, (float)location.getX(), (float)location.getY(), (float)location.getZ(), offsetX, offsetY, offsetZ, speed, count);
- Object handle2 = ReflectionUtilities.getHandle(player);
- Object connection2 = ReflectionUtilities.getField(handle2.getClass(), "playerConnection").get(handle2);
- ReflectionUtilities.getMethod(connection2.getClass(), "sendPacket", (Class<?>[])new Class[0]).invoke(connection2, packet2);
- }
- catch (Exception e) {
- throw e;
- }
- }
- public void sendToPlayer(Player player, Location location, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force) throws Exception {
- this.sendToPlayer(player, location, offsetX, offsetY, offsetZ, speed, count, force, new int[0]);
- }
- @Deprecated
- public void sendToPlayer(Player player, Location location, float offsetX, float offsetY, float offsetZ, float speed, int count) throws Exception {
- this.sendToPlayer(player, location, offsetX, offsetY, offsetZ, speed, count, false);
- }
- @Deprecated
- public void sendToPlayers(Collection<? extends Player> players, Location location, float offsetX, float offsetY, float offsetZ, float speed, int count) throws Exception {
- for (Player p : players) {
- this.sendToPlayer(p, location, offsetX, offsetY, offsetZ, speed, count);
- }
- }
- public void sendToPlayers(Collection<? extends Player> players, Location location, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force) throws Exception {
- for (Player p : players) {
- this.sendToPlayer(p, location, offsetX, offsetY, offsetZ, speed, count, force);
- }
- }
- @Deprecated
- public void sendToPlayers(Player[] players, Location location, float offsetX, float offsetY, float offsetZ, float speed, int count) throws Exception {
- for (Player p : players) {
- this.sendToPlayer(p, location, offsetX, offsetY, offsetZ, speed, count);
- }
- }
- @Deprecated
- public void sendColor(Player p, Location location, Color color) throws Exception {
- if (!this.hasColor) {
- return;
- }
- this.sendToPlayer(p, location, this.getColor(color.getRed()), this.getColor(color.getGreen()), this.getColor(color.getBlue()), 1.0f, 0);
- }
- public void sendColor(Player p, Location location, Color color, boolean force) throws Exception {
- if (!this.hasColor) {
- return;
- }
- this.sendToPlayer(p, location, this.getColor(color.getRed()), this.getColor(color.getGreen()), this.getColor(color.getBlue()), 1.0f, 0, force);
- }
- @Deprecated
- public void sendColor(Player p, Location location, java.awt.Color color) throws Exception {
- if (!this.hasColor) {
- return;
- }
- this.sendToPlayer(p, location, this.getColor(color.getRed()), this.getColor(color.getGreen()), this.getColor(color.getBlue()), 1.0f, 0);
- }
- public void sendColor(Player p, Location location, java.awt.Color color, boolean force) throws Exception {
- if (!this.hasColor) {
- return;
- }
- this.sendToPlayer(p, location, this.getColor(color.getRed()), this.getColor(color.getGreen()), this.getColor(color.getBlue()), 1.0f, 0, force);
- }
- @Deprecated
- public void sendColor(Collection<? extends Player> players, Location location, java.awt.Color color) throws Exception {
- if (!this.hasColor) {
- return;
- }
- for (Player p : players) {
- this.sendColor(p, location, color);
- }
- }
- public void sendColor(Collection<? extends Player> players, Location location, java.awt.Color color, boolean force) throws Exception {
- if (!this.hasColor) {
- return;
- }
- for (Player p : players) {
- this.sendColor(p, location, color, force);
- }
- }
- public void sendColor(Collection<? extends Player> players, Location location, Color color) throws Exception {
- if (!this.hasColor) {
- return;
- }
- for (Player p : players) {
- this.sendColor(p, location, color);
- }
- }
- @Deprecated
- public void sendColor(Collection<? extends Player> players, Location location, Color color, boolean force) throws Exception {
- if (!this.hasColor) {
- return;
- }
- for (Player p : players) {
- this.sendColor(p, location, color, force);
- }
- }
- @Deprecated
- public void sendColor(Player[] players, Location location, Color color) throws Exception {
- if (!this.hasColor) {
- return;
- }
- for (Player p : players) {
- this.sendColor(p, location, color);
- }
- }
- @Deprecated
- public void sendColor(Player[] players, Location location, java.awt.Color color) throws Exception {
- if (!this.hasColor) {
- return;
- }
- for (Player p : players) {
- this.sendColor(p, location, color);
- }
- }
- protected float getColor(float value) {
- if (value <= 0.0f) {
- value = -1.0f;
- }
- return value / 255.0f;
- }
- @Deprecated
- public void sendBlockCrack(Player player, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count) throws Exception {
- if (this != ParticleEffect.BLOCK_CRACK) {
- throw new IllegalArgumentException("This method is only available for BLOCK_CRACK!");
- }
- this.sendToPlayer(player, location, offsetX, offsetY, offsetZ, speed, count, id, data);
- }
- public void sendBlockCrack(Player player, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force) throws Exception {
- if (this != ParticleEffect.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);
- }
- @Deprecated
- public void sendBlockCrack(Collection<? extends Player> players, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count) throws Exception {
- if (this != ParticleEffect.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);
- }
- }
- 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) throws Exception {
- if (this != ParticleEffect.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);
- }
- }
- @Deprecated
- public void sendBlockCrack(Player[] players, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count) throws Exception {
- if (this != ParticleEffect.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);
- }
- }
- @Deprecated
- public void sendItemCrack(Player player, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count) throws Exception {
- if (this != ParticleEffect.ITEM_CRACK) {
- throw new IllegalArgumentException("This method is only available for ITEM_CRACK!");
- }
- this.sendToPlayer(player, location, offsetX, offsetY, offsetZ, speed, count, id, data);
- }
- public void sendItemCrack(Player player, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force) throws Exception {
- if (this != ParticleEffect.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);
- }
- @Deprecated
- public void sendItemCrack(Collection<? extends Player> players, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count) throws Exception {
- if (this != ParticleEffect.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);
- }
- }
- 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) throws Exception {
- if (this != ParticleEffect.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);
- }
- }
- @Deprecated
- public void sendItemCrack(Player[] players, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count) throws Exception {
- if (this != ParticleEffect.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);
- }
- }
- @Deprecated
- public void sendBlockDust(Player p, Location location, int id, float offsetX, float offsetY, float offsetZ, float speed, int count) throws Exception {
- if (this != ParticleEffect.BLOCK_DUST) {
- throw new IllegalArgumentException("This method is only available for BLOCK_DUST!");
- }
- this.sendToPlayer(p, location, offsetX, offsetY, offsetZ, speed, count, id);
- }
- public void sendBlockDust(Player p, Location location, int id, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force) throws Exception {
- if (this != ParticleEffect.BLOCK_DUST) {
- throw new IllegalArgumentException("This method is only available for BLOCK_DUST!");
- }
- this.sendToPlayer(p, location, offsetX, offsetY, offsetZ, speed, count, force, id);
- }
- @Deprecated
- public void sendBlockDust(Collection<? extends Player> players, Location location, int id, float offsetX, float offsetY, float offsetZ, float speed, int count) throws Exception {
- if (this != ParticleEffect.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);
- }
- }
- public void sendBlockDust(Collection<? extends Player> players, Location location, int id, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force) throws Exception {
- if (this != ParticleEffect.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);
- }
- }
- @Deprecated
- public void sendBlockDust(Player[] players, Location location, int id, float offsetX, float offsetY, float offsetZ, float speed, int count) throws Exception {
- if (this != ParticleEffect.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);
- }
- }
- protected static int getVersion(Player p) {
- try {
- Object handle = ReflectionUtilities.getHandle(p);
- Object connection = ParticleEffect.nmsFieldPlayerConnection.get(handle);
- Object network = ParticleEffect.nmsFieldNetworkManager.get(connection);
- Object channel;
- if (ReflectionUtilities.getVersion().contains("1_7")) {
- channel = ParticleEffect.nmsFieldNetworkManagerM.get(network);
- }
- else {
- channel = ParticleEffect.nmsFieldNetworkManagerI.get(network);
- }
- Object version = ReflectionUtilities.getVersion().contains("1_7") ? ParticleEffect.nmsNetworkGetVersion.invoke(network, channel) : 47;
- return (int)version;
- }
- catch (Exception e) {
- e.printStackTrace();
- return 0;
- }
- }
- 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;
- }
- public static boolean isPlayerInRange(Player p, Location center) {
- double distance = 0.0;
- return p.getLocation().getWorld().equals(center.getWorld()) && (distance = center.distanceSquared(p.getLocation())) <= Double.MAX_VALUE && distance < ParticleEffect.particleRange * ParticleEffect.particleRange;
- }
- static {
- ParticleEffect.nmsPacketPlayOutParticle = ReflectionUtilities.getNMSClass("PacketPlayOutWorldParticles");
- ParticleEffect.particleRange = 25;
- String ver = ReflectionUtilities.getVersion();
- try {
- ParticleEffect.nmsPlayerConnection = ReflectionUtilities.getNMSClass("PlayerConnection");
- ParticleEffect.nmsEntityPlayer = ReflectionUtilities.getNMSClass("EntityPlayer");
- ParticleEffect.ioNettyChannel = (ver.contains("1_7") ? Class.forName("net.minecraft.util.io.netty.channel.Channel") : Class.forName("io.netty.channel.Channel"));
- ParticleEffect.nmsFieldPlayerConnection = ReflectionUtilities.getField(ParticleEffect.nmsEntityPlayer, "playerConnection");
- ParticleEffect.nmsFieldNetworkManager = ReflectionUtilities.getField(ParticleEffect.nmsPlayerConnection, "networkManager");
- ParticleEffect.nmsFieldNetworkManagerI = ReflectionUtilities.getField(ParticleEffect.nmsFieldNetworkManager.getType(), "i");
- ParticleEffect.nmsFieldNetworkManagerM = ReflectionUtilities.getField(ParticleEffect.nmsFieldNetworkManager.getType(), "m");
- ParticleEffect.nmsNetworkGetVersion = ReflectionUtilities.getMethod(ParticleEffect.nmsFieldNetworkManager.getType(), "getVersion", ParticleEffect.ioNettyChannel);
- }
- catch (Exception e) {
- System.err.println("[ParticleLIB] Error while loading: " + e.getMessage());
- e.printStackTrace(System.err);
- Bukkit.getPluginManager().disablePlugin(Bukkit.getPluginManager().getPlugin("ParticleLIB"));
- }
- }
- public static class ReflectionUtilities
- {
- public static void setValue(Object instance, String fieldName, Object value) throws Exception {
- Field field = instance.getClass().getDeclaredField(fieldName);
- field.setAccessible(true);
- field.set(instance, value);
- }
- public static Object getValue(Object instance, String fieldName) throws Exception {
- Field field = instance.getClass().getDeclaredField(fieldName);
- field.setAccessible(true);
- return field.get(instance);
- }
- public static String getVersion() {
- String name = Bukkit.getServer().getClass().getPackage().getName();
- String version = name.substring(name.lastIndexOf(46) + 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", (Class<?>[])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;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment