Add backwards compatibility for 1.14
This commit is contained in:
		@@ -6,6 +6,7 @@ import me.libraryaddict.disguise.utilities.LibsPremium;
 | 
				
			|||||||
import me.libraryaddict.disguise.utilities.metrics.MetricsInitalizer;
 | 
					import me.libraryaddict.disguise.utilities.metrics.MetricsInitalizer;
 | 
				
			||||||
import me.libraryaddict.disguise.utilities.packets.PacketsManager;
 | 
					import me.libraryaddict.disguise.utilities.packets.PacketsManager;
 | 
				
			||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
 | 
					import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
 | 
				
			||||||
 | 
					import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
 | 
				
			||||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
 | 
					import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
 | 
				
			||||||
import org.apache.commons.lang.StringUtils;
 | 
					import org.apache.commons.lang.StringUtils;
 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
@@ -54,7 +55,8 @@ public class LibsDisguises extends JavaPlugin {
 | 
				
			|||||||
        YamlConfiguration pluginYml = ReflectionManager.getPluginYaml(getClassLoader());
 | 
					        YamlConfiguration pluginYml = ReflectionManager.getPluginYaml(getClassLoader());
 | 
				
			||||||
        buildNumber = StringUtils.stripToNull(pluginYml.getString("build-number"));
 | 
					        buildNumber = StringUtils.stripToNull(pluginYml.getString("build-number"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        getLogger().info("Discovered nms version: " + ReflectionManager.getBukkitVersion());
 | 
					        getLogger().info("Discovered nms version: " + ReflectionManager.getBukkitVersion() + " | " +
 | 
				
			||||||
 | 
					                ReflectionManager.getVersion());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        getLogger().info("Jenkins Build: " + (isNumberedBuild() ? "#" : "") + getBuildNo());
 | 
					        getLogger().info("Jenkins Build: " + (isNumberedBuild() ? "#" : "") + getBuildNo());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -68,9 +70,9 @@ public class LibsDisguises extends JavaPlugin {
 | 
				
			|||||||
                            " Command " + "Blocks, Admins)");
 | 
					                            " Command " + "Blocks, Admins)");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!ReflectionManager.getMinecraftVersion().startsWith("1.15")) {
 | 
					        if (ReflectionManager.getVersion() == null) {
 | 
				
			||||||
            getLogger().severe("You're using the wrong version of Lib's Disguises for your server! This is " +
 | 
					            getLogger().severe("You're using the wrong version of Lib's Disguises for your server! This is " +
 | 
				
			||||||
                    "intended for 1.15!");
 | 
					                    "intended for 1.14 & 1.15!");
 | 
				
			||||||
            getPluginLoader().disablePlugin(this);
 | 
					            getPluginLoader().disablePlugin(this);
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -90,6 +92,8 @@ public class LibsDisguises extends JavaPlugin {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        listener = new DisguiseListener(this);
 | 
					        listener = new DisguiseListener(this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        registerCommand("libsdisguises", new LibsDisguisesCommand());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!DisguiseConfig.isDisableCommands()) {
 | 
					        if (!DisguiseConfig.isDisableCommands()) {
 | 
				
			||||||
            registerCommand("disguise", new DisguiseCommand());
 | 
					            registerCommand("disguise", new DisguiseCommand());
 | 
				
			||||||
            registerCommand("undisguise", new UndisguiseCommand());
 | 
					            registerCommand("undisguise", new UndisguiseCommand());
 | 
				
			||||||
@@ -101,7 +105,6 @@ public class LibsDisguises extends JavaPlugin {
 | 
				
			|||||||
            registerCommand("undisguiseradius", new UndisguiseRadiusCommand(getConfig().getInt("UndisguiseRadiusMax")));
 | 
					            registerCommand("undisguiseradius", new UndisguiseRadiusCommand(getConfig().getInt("UndisguiseRadiusMax")));
 | 
				
			||||||
            registerCommand("disguisehelp", new DisguiseHelpCommand());
 | 
					            registerCommand("disguisehelp", new DisguiseHelpCommand());
 | 
				
			||||||
            registerCommand("disguiseclone", new DisguiseCloneCommand());
 | 
					            registerCommand("disguiseclone", new DisguiseCloneCommand());
 | 
				
			||||||
            registerCommand("libsdisguises", new LibsDisguisesCommand());
 | 
					 | 
				
			||||||
            registerCommand("disguiseviewself", new DisguiseViewSelfCommand());
 | 
					            registerCommand("disguiseviewself", new DisguiseViewSelfCommand());
 | 
				
			||||||
            registerCommand("disguisemodify", new DisguiseModifyCommand());
 | 
					            registerCommand("disguisemodify", new DisguiseModifyCommand());
 | 
				
			||||||
            registerCommand("disguisemodifyentity", new DisguiseModifyEntityCommand());
 | 
					            registerCommand("disguisemodifyentity", new DisguiseModifyEntityCommand());
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -64,6 +64,10 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
 | 
				
			|||||||
            ArrayList<String> classes = new ArrayList<>();
 | 
					            ArrayList<String> classes = new ArrayList<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for (DisguiseType type : DisguiseType.values()) {
 | 
					            for (DisguiseType type : DisguiseType.values()) {
 | 
				
			||||||
 | 
					                if (type.getEntityType() == null) {
 | 
				
			||||||
 | 
					                    continue;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                classes.add(type.toReadable());
 | 
					                classes.add(type.toReadable());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -79,6 +83,10 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if (!isInteger(args[0])) {
 | 
					        if (!isInteger(args[0])) {
 | 
				
			||||||
            for (DisguiseType t : DisguiseType.values()) {
 | 
					            for (DisguiseType t : DisguiseType.values()) {
 | 
				
			||||||
 | 
					                if (t.getEntityType() == null) {
 | 
				
			||||||
 | 
					                    continue;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (t.toReadable().replaceAll(" ", "").equalsIgnoreCase(args[0].replaceAll("_", ""))) {
 | 
					                if (t.toReadable().replaceAll(" ", "").equalsIgnoreCase(args[0].replaceAll("_", ""))) {
 | 
				
			||||||
                    baseType = t;
 | 
					                    baseType = t;
 | 
				
			||||||
                    starting = 1;
 | 
					                    starting = 1;
 | 
				
			||||||
@@ -193,6 +201,10 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if (args.length == 0) {
 | 
					        if (args.length == 0) {
 | 
				
			||||||
            for (DisguiseType type : DisguiseType.values()) {
 | 
					            for (DisguiseType type : DisguiseType.values()) {
 | 
				
			||||||
 | 
					                if (type.getEntityType() == null) {
 | 
				
			||||||
 | 
					                    continue;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                tabs.add(type.toReadable().replaceAll(" ", "_"));
 | 
					                tabs.add(type.toReadable().replaceAll(" ", "_"));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -203,6 +215,10 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if (!isInteger(args[0])) {
 | 
					        if (!isInteger(args[0])) {
 | 
				
			||||||
            for (DisguiseType t : DisguiseType.values()) {
 | 
					            for (DisguiseType t : DisguiseType.values()) {
 | 
				
			||||||
 | 
					                if (t.getEntityType() == null) {
 | 
				
			||||||
 | 
					                    continue;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (t.toReadable().replaceAll(" ", "").equalsIgnoreCase(args[0].replaceAll("_", ""))) {
 | 
					                if (t.toReadable().replaceAll(" ", "").equalsIgnoreCase(args[0].replaceAll("_", ""))) {
 | 
				
			||||||
                    starting = 2;
 | 
					                    starting = 2;
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,10 +1,11 @@
 | 
				
			|||||||
package me.libraryaddict.disguise.disguisetypes;
 | 
					package me.libraryaddict.disguise.disguisetypes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import me.libraryaddict.disguise.utilities.reflection.NmsAdded;
 | 
				
			||||||
 | 
					import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
 | 
				
			||||||
import me.libraryaddict.disguise.utilities.translations.TranslateType;
 | 
					import me.libraryaddict.disguise.utilities.translations.TranslateType;
 | 
				
			||||||
import org.apache.commons.lang.StringUtils;
 | 
					import org.apache.commons.lang.StringUtils;
 | 
				
			||||||
import org.bukkit.entity.Entity;
 | 
					import org.bukkit.entity.Entity;
 | 
				
			||||||
import org.bukkit.entity.EntityType;
 | 
					import org.bukkit.entity.EntityType;
 | 
				
			||||||
import org.omg.CORBA.UNKNOWN;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
public enum DisguiseType {
 | 
					public enum DisguiseType {
 | 
				
			||||||
    AREA_EFFECT_CLOUD(3, 0),
 | 
					    AREA_EFFECT_CLOUD(3, 0),
 | 
				
			||||||
@@ -15,7 +16,7 @@ public enum DisguiseType {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    BAT,
 | 
					    BAT,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    BEE,
 | 
					    @NmsAdded(added = NmsVersion.v1_15) BEE,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    BLAZE,
 | 
					    BLAZE,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -256,7 +257,11 @@ public enum DisguiseType {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        setEntityType(EntityType.valueOf(name()));
 | 
					        try {
 | 
				
			||||||
 | 
					            setEntityType(EntityType.valueOf(name()));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        catch (Exception ex) {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public int getDefaultData() {
 | 
					    public int getDefaultData() {
 | 
				
			||||||
@@ -275,6 +280,10 @@ public enum DisguiseType {
 | 
				
			|||||||
        return entityType;
 | 
					        return entityType;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void setEntityType(EntityType entityType) {
 | 
				
			||||||
 | 
					        this.entityType = entityType;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * The object type send in packets when spawning a misc entity. Otherwise, -1.
 | 
					     * The object type send in packets when spawning a misc entity. Otherwise, -1.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@@ -301,6 +310,10 @@ public enum DisguiseType {
 | 
				
			|||||||
        return watcherClass;
 | 
					        return watcherClass;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setWatcherClass(Class<? extends FlagWatcher> c) {
 | 
				
			||||||
 | 
					        watcherClass = c;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public boolean isMisc() {
 | 
					    public boolean isMisc() {
 | 
				
			||||||
        return getEntityType() != null && !getEntityType().isAlive();
 | 
					        return getEntityType() != null && !getEntityType().isAlive();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -317,14 +330,6 @@ public enum DisguiseType {
 | 
				
			|||||||
        return this == DisguiseType.UNKNOWN;
 | 
					        return this == DisguiseType.UNKNOWN;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void setEntityType(EntityType entityType) {
 | 
					 | 
				
			||||||
        this.entityType = entityType;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void setWatcherClass(Class<? extends FlagWatcher> c) {
 | 
					 | 
				
			||||||
        watcherClass = c;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public String toReadable() {
 | 
					    public String toReadable() {
 | 
				
			||||||
        String[] split = name().split("_");
 | 
					        String[] split = name().split("_");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,6 +7,10 @@ import com.comphenix.protocol.wrappers.nbt.NbtFactory;
 | 
				
			|||||||
import com.comphenix.protocol.wrappers.nbt.NbtType;
 | 
					import com.comphenix.protocol.wrappers.nbt.NbtType;
 | 
				
			||||||
import me.libraryaddict.disguise.disguisetypes.watchers.*;
 | 
					import me.libraryaddict.disguise.disguisetypes.watchers.*;
 | 
				
			||||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
 | 
					import me.libraryaddict.disguise.utilities.DisguiseUtilities;
 | 
				
			||||||
 | 
					import me.libraryaddict.disguise.utilities.reflection.NmsAdded;
 | 
				
			||||||
 | 
					import me.libraryaddict.disguise.utilities.reflection.NmsRemoved;
 | 
				
			||||||
 | 
					import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
 | 
				
			||||||
 | 
					import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
 | 
				
			||||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
 | 
					import me.libraryaddict.disguise.utilities.translations.LibsMsg;
 | 
				
			||||||
import org.bukkit.Color;
 | 
					import org.bukkit.Color;
 | 
				
			||||||
import org.bukkit.Material;
 | 
					import org.bukkit.Material;
 | 
				
			||||||
@@ -108,8 +112,10 @@ public class MetaIndex<Y> {
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public static MetaIndex<Byte> BAT_HANGING = new MetaIndex<>(BatWatcher.class, 0, (byte) 1);
 | 
					    public static MetaIndex<Byte> BAT_HANGING = new MetaIndex<>(BatWatcher.class, 0, (byte) 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @NmsAdded(added = NmsVersion.v1_15)
 | 
				
			||||||
    public static MetaIndex<Byte> BEE_META = new MetaIndex<>(BeeWatcher.class, 0, (byte) 0);
 | 
					    public static MetaIndex<Byte> BEE_META = new MetaIndex<>(BeeWatcher.class, 0, (byte) 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @NmsAdded(added = NmsVersion.v1_15)
 | 
				
			||||||
    public static MetaIndex<Integer> BEE_ANGER = new MetaIndex<>(BeeWatcher.class, 1, 0);
 | 
					    public static MetaIndex<Integer> BEE_ANGER = new MetaIndex<>(BeeWatcher.class, 1, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -199,6 +205,7 @@ public class MetaIndex<Y> {
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public static MetaIndex<Boolean> ENDERMAN_AGRESSIVE = new MetaIndex<>(EndermanWatcher.class, 1, false);
 | 
					    public static MetaIndex<Boolean> ENDERMAN_AGRESSIVE = new MetaIndex<>(EndermanWatcher.class, 1, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @NmsAdded(added = NmsVersion.v1_15)
 | 
				
			||||||
    public static MetaIndex<Boolean> ENDERMAN_UNKNOWN = new MetaIndex<>(EndermanWatcher.class, 2, false);
 | 
					    public static MetaIndex<Boolean> ENDERMAN_UNKNOWN = new MetaIndex<>(EndermanWatcher.class, 2, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -351,6 +358,7 @@ public class MetaIndex<Y> {
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * How many bee stings does the entity have
 | 
					     * How many bee stings does the entity have
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
 | 
					    @NmsAdded(added = NmsVersion.v1_15)
 | 
				
			||||||
    public static MetaIndex<Integer> LIVING_STINGS = new MetaIndex<>(LivingWatcher.class, 5, 0);
 | 
					    public static MetaIndex<Integer> LIVING_STINGS = new MetaIndex<>(LivingWatcher.class, 5, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static MetaIndex<Optional<BlockPosition>> LIVING_BED_POSITION = new MetaIndex<>(LivingWatcher.class, 6,
 | 
					    public static MetaIndex<Optional<BlockPosition>> LIVING_BED_POSITION = new MetaIndex<>(LivingWatcher.class, 6,
 | 
				
			||||||
@@ -488,6 +496,7 @@ public class MetaIndex<Y> {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public static MetaIndex<Byte> TRIDENT_ENCHANTS = new MetaIndex<>(TridentWatcher.class, 0, (byte) 0);
 | 
					    public static MetaIndex<Byte> TRIDENT_ENCHANTS = new MetaIndex<>(TridentWatcher.class, 0, (byte) 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @NmsAdded(added = NmsVersion.v1_15)
 | 
				
			||||||
    public static MetaIndex<Boolean> TRIDENT_ENCHANTED = new MetaIndex<>(TridentWatcher.class, 1, false);
 | 
					    public static MetaIndex<Boolean> TRIDENT_ENCHANTED = new MetaIndex<>(TridentWatcher.class, 1, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static MetaIndex<Integer> TROPICAL_FISH_VARIANT = new MetaIndex<>(TropicalFishWatcher.class, 0, 0);
 | 
					    public static MetaIndex<Integer> TROPICAL_FISH_VARIANT = new MetaIndex<>(TropicalFishWatcher.class, 0, 0);
 | 
				
			||||||
@@ -525,9 +534,12 @@ public class MetaIndex<Y> {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public static MetaIndex<Boolean> WITHER_SKULL_BLUE = new MetaIndex<>(WitherSkullWatcher.class, 0, false);
 | 
					    public static MetaIndex<Boolean> WITHER_SKULL_BLUE = new MetaIndex<>(WitherSkullWatcher.class, 0, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static MetaIndex<Boolean> WOLF_BEGGING = new MetaIndex<>(WolfWatcher.class, 0, false);
 | 
					    public static MetaIndex<Boolean> WOLF_BEGGING = new MetaIndex<>(WolfWatcher.class, 1, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static MetaIndex<Integer> WOLF_COLLAR = new MetaIndex<>(WolfWatcher.class, 1, 14);
 | 
					    @NmsRemoved(removed = NmsVersion.v1_15)
 | 
				
			||||||
 | 
					    public static MetaIndex<Float> WOLF_DAMAGE = new MetaIndex<>(WolfWatcher.class, 0, 1F);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static MetaIndex<Integer> WOLF_COLLAR = new MetaIndex<>(WolfWatcher.class, 2, 14);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static MetaIndex<Boolean> ZOMBIE_BABY = new MetaIndex<>(ZombieWatcher.class, 0, false);
 | 
					    public static MetaIndex<Boolean> ZOMBIE_BABY = new MetaIndex<>(ZombieWatcher.class, 0, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -545,6 +557,7 @@ public class MetaIndex<Y> {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    static {
 | 
					    static {
 | 
				
			||||||
        setValues();
 | 
					        setValues();
 | 
				
			||||||
 | 
					        eliminateBlankIndexes();
 | 
				
			||||||
        orderMetaIndexes();
 | 
					        orderMetaIndexes();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -826,6 +839,10 @@ public class MetaIndex<Y> {
 | 
				
			|||||||
                if (field.getType() != MetaIndex.class)
 | 
					                if (field.getType() != MetaIndex.class)
 | 
				
			||||||
                    continue;
 | 
					                    continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (!ReflectionManager.isSupported(field)) {
 | 
				
			||||||
 | 
					                    continue;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                MetaIndex index = (MetaIndex) field.get(null);
 | 
					                MetaIndex index = (MetaIndex) field.get(null);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (index == null)
 | 
					                if (index == null)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
					import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
				
			||||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
 | 
					import me.libraryaddict.disguise.disguisetypes.MetaIndex;
 | 
				
			||||||
 | 
					import me.libraryaddict.disguise.utilities.reflection.NmsAdded;
 | 
				
			||||||
 | 
					import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Created by libraryaddict on 6/08/2018.
 | 
					 * Created by libraryaddict on 6/08/2018.
 | 
				
			||||||
@@ -11,12 +13,14 @@ public class TridentWatcher extends ArrowWatcher {
 | 
				
			|||||||
        super(disguise);
 | 
					        super(disguise);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @NmsAdded(added = NmsVersion.v1_15)
 | 
				
			||||||
 | 
					    public boolean isEnchanted() {
 | 
				
			||||||
 | 
					        return getData(MetaIndex.TRIDENT_ENCHANTED);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @NmsAdded(added = NmsVersion.v1_15)
 | 
				
			||||||
    public void setEnchanted(boolean enchanted) {
 | 
					    public void setEnchanted(boolean enchanted) {
 | 
				
			||||||
        setData(MetaIndex.TRIDENT_ENCHANTED, enchanted);
 | 
					        setData(MetaIndex.TRIDENT_ENCHANTED, enchanted);
 | 
				
			||||||
        sendData(MetaIndex.TRIDENT_ENCHANTED);
 | 
					        sendData(MetaIndex.TRIDENT_ENCHANTED);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    public boolean isEnchanted() {
 | 
					 | 
				
			||||||
        return getData(MetaIndex.TRIDENT_ENCHANTED);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
				
			|||||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
 | 
					import me.libraryaddict.disguise.disguisetypes.AnimalColor;
 | 
				
			||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
					import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
				
			||||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
 | 
					import me.libraryaddict.disguise.disguisetypes.MetaIndex;
 | 
				
			||||||
 | 
					import me.libraryaddict.disguise.utilities.reflection.NmsRemoved;
 | 
				
			||||||
 | 
					import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
 | 
				
			||||||
import org.bukkit.DyeColor;
 | 
					import org.bukkit.DyeColor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class WolfWatcher extends TameableWatcher {
 | 
					public class WolfWatcher extends TameableWatcher {
 | 
				
			||||||
@@ -15,23 +17,6 @@ public class WolfWatcher extends TameableWatcher {
 | 
				
			|||||||
        return AnimalColor.getColorByWool(getData(MetaIndex.WOLF_COLLAR)).getDyeColor();
 | 
					        return AnimalColor.getColorByWool(getData(MetaIndex.WOLF_COLLAR)).getDyeColor();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public boolean isBegging() {
 | 
					 | 
				
			||||||
        return getData(MetaIndex.WOLF_BEGGING);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void setBegging(boolean begging) {
 | 
					 | 
				
			||||||
        setData(MetaIndex.WOLF_BEGGING, begging);
 | 
					 | 
				
			||||||
        sendData(MetaIndex.WOLF_BEGGING);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public boolean isAngry() {
 | 
					 | 
				
			||||||
        return isTameableFlag(2);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void setAngry(boolean angry) {
 | 
					 | 
				
			||||||
        setTameableFlag(2, angry);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Deprecated
 | 
					    @Deprecated
 | 
				
			||||||
    public void setCollarColor(AnimalColor color) {
 | 
					    public void setCollarColor(AnimalColor color) {
 | 
				
			||||||
        setCollarColor(color.getDyeColor());
 | 
					        setCollarColor(color.getDyeColor());
 | 
				
			||||||
@@ -49,4 +34,42 @@ public class WolfWatcher extends TameableWatcher {
 | 
				
			|||||||
        setData(MetaIndex.WOLF_COLLAR, (int) newColor.getWoolData());
 | 
					        setData(MetaIndex.WOLF_COLLAR, (int) newColor.getWoolData());
 | 
				
			||||||
        sendData(MetaIndex.WOLF_COLLAR);
 | 
					        sendData(MetaIndex.WOLF_COLLAR);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public boolean isBegging() {
 | 
				
			||||||
 | 
					        return getData(MetaIndex.WOLF_BEGGING);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setBegging(boolean begging) {
 | 
				
			||||||
 | 
					        setData(MetaIndex.WOLF_BEGGING, begging);
 | 
				
			||||||
 | 
					        sendData(MetaIndex.WOLF_BEGGING);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public boolean isAngry() {
 | 
				
			||||||
 | 
					        return isTameableFlag(2);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setAngry(boolean angry) {
 | 
				
			||||||
 | 
					        setTameableFlag(2, angry);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Used for tail rotation.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @NmsRemoved(removed = NmsVersion.v1_15)
 | 
				
			||||||
 | 
					    public float getDamageTaken() {
 | 
				
			||||||
 | 
					        return getData(MetaIndex.WOLF_DAMAGE);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Used for tail rotation.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param damage
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @NmsRemoved(removed = NmsVersion.v1_15)
 | 
				
			||||||
 | 
					    public void setDamageTaken(float damage) {
 | 
				
			||||||
 | 
					        setData(MetaIndex.WOLF_DAMAGE, damage);
 | 
				
			||||||
 | 
					        sendData(MetaIndex.WOLF_DAMAGE);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,8 +19,8 @@ public enum DisguiseSound {
 | 
				
			|||||||
    BAT(Sound.ENTITY_BAT_HURT, null, Sound.ENTITY_BAT_DEATH, Sound.ENTITY_BAT_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL,
 | 
					    BAT(Sound.ENTITY_BAT_HURT, null, Sound.ENTITY_BAT_DEATH, Sound.ENTITY_BAT_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL,
 | 
				
			||||||
            Sound.ENTITY_BAT_LOOP, Sound.ENTITY_PLAYER_BIG_FALL, Sound.ENTITY_BAT_TAKEOFF),
 | 
					            Sound.ENTITY_BAT_LOOP, Sound.ENTITY_PLAYER_BIG_FALL, Sound.ENTITY_BAT_TAKEOFF),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    BEE(Sound.ENTITY_BEE_HURT, null, Sound.ENTITY_BEE_DEATH, null, Sound.ENTITY_BEE_LOOP,
 | 
					    BEE("ENTITY_BEE_HURT", null, "ENTITY_BEE_DEATH", null, "ENTITY_BEE_LOOP", "ENTITY_BEE_LOOP_AGGRESSIVE",
 | 
				
			||||||
            Sound.ENTITY_BEE_LOOP_AGGRESSIVE, Sound.ENTITY_BEE_POLLINATE, Sound.ENTITY_BEE_STING),
 | 
					            "ENTITY_BEE_POLLINATE", "ENTITY_BEE_STING"),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    BLAZE(Sound.ENTITY_BLAZE_HURT, null, Sound.ENTITY_BLAZE_DEATH, Sound.ENTITY_BLAZE_AMBIENT,
 | 
					    BLAZE(Sound.ENTITY_BLAZE_HURT, null, Sound.ENTITY_BLAZE_DEATH, Sound.ENTITY_BLAZE_AMBIENT,
 | 
				
			||||||
            Sound.ENTITY_PLAYER_SMALL_FALL, Sound.ENTITY_PLAYER_BIG_FALL, Sound.ENTITY_BLAZE_BURN,
 | 
					            Sound.ENTITY_PLAYER_SMALL_FALL, Sound.ENTITY_PLAYER_BIG_FALL, Sound.ENTITY_BLAZE_BURN,
 | 
				
			||||||
@@ -249,28 +249,60 @@ public enum DisguiseSound {
 | 
				
			|||||||
    private float damageSoundVolume = 1F;
 | 
					    private float damageSoundVolume = 1F;
 | 
				
			||||||
    private LinkedHashMap<Object, SoundType> disguiseSounds = new LinkedHashMap<>();
 | 
					    private LinkedHashMap<Object, SoundType> disguiseSounds = new LinkedHashMap<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    DisguiseSound(Object hurt, Object step, Object death, Object idle, Sound... sounds) {
 | 
					    DisguiseSound(Object hurt, Object step, Object death, Object idle, Object... sounds) {
 | 
				
			||||||
        addSound(hurt, SoundType.HURT);
 | 
					        addSound(hurt, SoundType.HURT);
 | 
				
			||||||
        addSound(step, SoundType.STEP);
 | 
					        addSound(step, SoundType.STEP);
 | 
				
			||||||
        addSound(death, SoundType.DEATH);
 | 
					        addSound(death, SoundType.DEATH);
 | 
				
			||||||
        addSound(idle, SoundType.IDLE);
 | 
					        addSound(idle, SoundType.IDLE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (Sound obj : sounds) {
 | 
					        for (Object obj : sounds) {
 | 
				
			||||||
            addSound(obj, SoundType.CANCEL);
 | 
					            addSound(obj, SoundType.CANCEL);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private Sound parseSound(String name) {
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            return Sound.valueOf(name);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        catch (Exception ex) {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void addSound(Object sound, SoundType type) {
 | 
					    private void addSound(Object sound, SoundType type) {
 | 
				
			||||||
        if (sound == null) {
 | 
					        if (sound == null) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (sound instanceof Sound) {
 | 
					        if (sound instanceof String[]) {
 | 
				
			||||||
            addSound((Sound) sound, type);
 | 
					            for (String s : (String[]) sound) {
 | 
				
			||||||
 | 
					                Sound so = parseSound(s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (so == null) {
 | 
				
			||||||
 | 
					                    continue;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                addSound(so, type);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        } else if (sound instanceof String) {
 | 
				
			||||||
 | 
					            Sound so = parseSound((String) sound);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (so == null) {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            addSound(so, type);
 | 
				
			||||||
        } else if (sound instanceof Sound[]) {
 | 
					        } else if (sound instanceof Sound[]) {
 | 
				
			||||||
            for (Sound s : (Sound[]) sound) {
 | 
					            for (Sound s : (Sound[]) sound) {
 | 
				
			||||||
 | 
					                if (s == null) {
 | 
				
			||||||
 | 
					                    continue;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                addSound(s, type);
 | 
					                addSound(s, type);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        } else if (sound instanceof Sound) {
 | 
				
			||||||
 | 
					            addSound((Sound) sound, type);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            throw new IllegalArgumentException("Was given an unknown object " + sound);
 | 
					            throw new IllegalArgumentException("Was given an unknown object " + sound);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -290,6 +322,10 @@ public enum DisguiseSound {
 | 
				
			|||||||
        return damageSoundVolume;
 | 
					        return damageSoundVolume;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setDamageAndIdleSoundVolume(float strength) {
 | 
				
			||||||
 | 
					        this.damageSoundVolume = strength;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Object getSound(SoundType type) {
 | 
					    public Object getSound(SoundType type) {
 | 
				
			||||||
        if (type == null) {
 | 
					        if (type == null) {
 | 
				
			||||||
            return null;
 | 
					            return null;
 | 
				
			||||||
@@ -334,8 +370,4 @@ public enum DisguiseSound {
 | 
				
			|||||||
    public boolean isCancelSound(String sound) {
 | 
					    public boolean isCancelSound(String sound) {
 | 
				
			||||||
        return getSound(sound) == SoundType.CANCEL;
 | 
					        return getSound(sound) == SoundType.CANCEL;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void setDamageAndIdleSoundVolume(float strength) {
 | 
					 | 
				
			||||||
        this.damageSoundVolume = strength;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,6 +17,7 @@ import me.libraryaddict.disguise.utilities.packets.IPacketHandler;
 | 
				
			|||||||
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
 | 
					import me.libraryaddict.disguise.utilities.packets.LibsPackets;
 | 
				
			||||||
import me.libraryaddict.disguise.utilities.packets.PacketsHandler;
 | 
					import me.libraryaddict.disguise.utilities.packets.PacketsHandler;
 | 
				
			||||||
import me.libraryaddict.disguise.utilities.reflection.DisguiseValues;
 | 
					import me.libraryaddict.disguise.utilities.reflection.DisguiseValues;
 | 
				
			||||||
 | 
					import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
 | 
				
			||||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
 | 
					import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
 | 
				
			||||||
import org.bukkit.Art;
 | 
					import org.bukkit.Art;
 | 
				
			||||||
import org.bukkit.Location;
 | 
					import org.bukkit.Location;
 | 
				
			||||||
@@ -224,11 +225,15 @@ public class PacketHandlerSpawn implements IPacketHandler {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            packets.addPacket(spawnPlayer);
 | 
					            packets.addPacket(spawnPlayer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            PacketContainer metaPacket = ProtocolLibrary.getProtocolManager()
 | 
					            if (ReflectionManager.isSupported(NmsVersion.v1_15)) {
 | 
				
			||||||
                    .createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entityId, newWatcher, true)
 | 
					                PacketContainer metaPacket = ProtocolLibrary.getProtocolManager()
 | 
				
			||||||
                    .createPacket(entityId, newWatcher, true);
 | 
					                        .createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entityId, newWatcher, true)
 | 
				
			||||||
 | 
					                        .createPacket(entityId, newWatcher, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            packets.addPacket(metaPacket);
 | 
					                packets.addPacket(metaPacket);
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                spawnPlayer.getDataWatcherModifier().write(0, newWatcher);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!selfDisguise) {
 | 
					            if (!selfDisguise) {
 | 
				
			||||||
                // Teleport the player back to where he's supposed to be
 | 
					                // Teleport the player back to where he's supposed to be
 | 
				
			||||||
@@ -248,7 +253,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
 | 
				
			|||||||
                packets.addDelayedPacket(teleportPacket, 3);
 | 
					                packets.addDelayedPacket(teleportPacket, 3);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                // Send a metadata packet
 | 
					                // Send a metadata packet
 | 
				
			||||||
                metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
 | 
					                PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                newWatcher = DisguiseUtilities
 | 
					                newWatcher = DisguiseUtilities
 | 
				
			||||||
                        .createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity),
 | 
					                        .createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity),
 | 
				
			||||||
@@ -309,11 +314,15 @@ public class PacketHandlerSpawn implements IPacketHandler {
 | 
				
			|||||||
                    .createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity),
 | 
					                    .createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity),
 | 
				
			||||||
                            disguise.getWatcher());
 | 
					                            disguise.getWatcher());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            PacketContainer metaPacket = ProtocolLibrary.getProtocolManager()
 | 
					            if (ReflectionManager.isSupported(NmsVersion.v1_15)) {
 | 
				
			||||||
                    .createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, disguisedEntity.getEntityId(),
 | 
					                PacketContainer metaPacket = ProtocolLibrary.getProtocolManager()
 | 
				
			||||||
                            newWatcher, true).createPacket(disguisedEntity.getEntityId(), newWatcher, true);
 | 
					                        .createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, disguisedEntity.getEntityId(),
 | 
				
			||||||
 | 
					                                newWatcher, true).createPacket(disguisedEntity.getEntityId(), newWatcher, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            packets.addPacket(metaPacket);
 | 
					                packets.addPacket(metaPacket);
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                spawnEntity.getDataWatcherModifier().write(0, newWatcher);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        } else if (disguise.getType().isMisc()) {
 | 
					        } else if (disguise.getType().isMisc()) {
 | 
				
			||||||
            int data = ((MiscDisguise) disguise).getData();
 | 
					            int data = ((MiscDisguise) disguise).getData();
 | 
				
			||||||
            double x = loc.getX();
 | 
					            double x = loc.getX();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -37,6 +37,10 @@ public class DisguiseParser {
 | 
				
			|||||||
    public static void createDefaultMethods() {
 | 
					    public static void createDefaultMethods() {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            for (DisguiseType type : DisguiseType.values()) {
 | 
					            for (DisguiseType type : DisguiseType.values()) {
 | 
				
			||||||
 | 
					                if (type.getEntityType() == null) {
 | 
				
			||||||
 | 
					                    continue;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                Disguise disguise;
 | 
					                Disguise disguise;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (type.isMisc()) {
 | 
					                if (type.isMisc()) {
 | 
				
			||||||
@@ -284,19 +288,21 @@ public class DisguiseParser {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static DisguisePerm[] getDisguisePerms() {
 | 
					    public static DisguisePerm[] getDisguisePerms() {
 | 
				
			||||||
        DisguisePerm[] perms = new DisguisePerm[DisguiseType.values().length +
 | 
					        ArrayList<DisguisePerm> perms = new ArrayList<>();
 | 
				
			||||||
                DisguiseConfig.getCustomDisguises().size()];
 | 
					 | 
				
			||||||
        int i = 0;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (DisguiseType disguiseType : DisguiseType.values()) {
 | 
					        for (DisguiseType disguiseType : DisguiseType.values()) {
 | 
				
			||||||
            perms[i++] = new DisguisePerm(disguiseType);
 | 
					            if (disguiseType.getEntityType() == null) {
 | 
				
			||||||
 | 
					                continue;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            perms.add(new DisguisePerm(disguiseType));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (Entry<DisguisePerm, String> entry : DisguiseConfig.getCustomDisguises().entrySet()) {
 | 
					        for (Entry<DisguisePerm, String> entry : DisguiseConfig.getCustomDisguises().entrySet()) {
 | 
				
			||||||
            perms[i++] = entry.getKey();
 | 
					            perms.add(entry.getKey());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return perms;
 | 
					        return perms.toArray(new DisguisePerm[0]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,6 +9,7 @@ import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
 | 
				
			|||||||
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
 | 
					import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
 | 
				
			||||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
 | 
					import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
 | 
				
			||||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfoTypes;
 | 
					import me.libraryaddict.disguise.utilities.parser.params.ParamInfoTypes;
 | 
				
			||||||
 | 
					import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					import org.bukkit.ChatColor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.annotation.Nullable;
 | 
					import javax.annotation.Nullable;
 | 
				
			||||||
@@ -90,7 +91,9 @@ public class ParamInfoManager {
 | 
				
			|||||||
        while (itel.hasNext()) {
 | 
					        while (itel.hasNext()) {
 | 
				
			||||||
            Method method = itel.next();
 | 
					            Method method = itel.next();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (method.getParameterTypes().length != 1) {
 | 
					            if (!ReflectionManager.isSupported(method)) {
 | 
				
			||||||
 | 
					                itel.remove();
 | 
				
			||||||
 | 
					            } else if (method.getParameterTypes().length != 1) {
 | 
				
			||||||
                itel.remove();
 | 
					                itel.remove();
 | 
				
			||||||
            } else if (method.getName().startsWith("get")) {
 | 
					            } else if (method.getName().startsWith("get")) {
 | 
				
			||||||
                itel.remove();
 | 
					                itel.remove();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					package me.libraryaddict.disguise.utilities.reflection;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.lang.annotation.Retention;
 | 
				
			||||||
 | 
					import java.lang.annotation.RetentionPolicy;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Created by libraryaddict on 6/02/2020.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					@Retention(RetentionPolicy.RUNTIME)
 | 
				
			||||||
 | 
					public @interface NmsAdded {
 | 
				
			||||||
 | 
					    NmsVersion added();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					package me.libraryaddict.disguise.utilities.reflection;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.lang.annotation.Retention;
 | 
				
			||||||
 | 
					import java.lang.annotation.RetentionPolicy;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Created by libraryaddict on 6/02/2020.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					@Retention(RetentionPolicy.RUNTIME)
 | 
				
			||||||
 | 
					public @interface NmsRemoved {
 | 
				
			||||||
 | 
					    NmsVersion removed();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					package me.libraryaddict.disguise.utilities.reflection;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Created by libraryaddict on 6/02/2020.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public enum NmsVersion {
 | 
				
			||||||
 | 
					    v1_14,
 | 
				
			||||||
 | 
					    v1_15;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -5,6 +5,7 @@ import com.comphenix.protocol.wrappers.*;
 | 
				
			|||||||
import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
 | 
					import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
 | 
				
			||||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
 | 
					import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
 | 
				
			||||||
import com.comphenix.protocol.wrappers.nbt.NbtWrapper;
 | 
					import com.comphenix.protocol.wrappers.nbt.NbtWrapper;
 | 
				
			||||||
 | 
					import lombok.Getter;
 | 
				
			||||||
import me.libraryaddict.disguise.DisguiseConfig;
 | 
					import me.libraryaddict.disguise.DisguiseConfig;
 | 
				
			||||||
import me.libraryaddict.disguise.LibsDisguises;
 | 
					import me.libraryaddict.disguise.LibsDisguises;
 | 
				
			||||||
import me.libraryaddict.disguise.disguisetypes.*;
 | 
					import me.libraryaddict.disguise.disguisetypes.*;
 | 
				
			||||||
@@ -47,6 +48,12 @@ public class ReflectionManager {
 | 
				
			|||||||
    private static Field chunkProviderField;
 | 
					    private static Field chunkProviderField;
 | 
				
			||||||
    private static Field entityTrackerField;
 | 
					    private static Field entityTrackerField;
 | 
				
			||||||
    private static Field trackedEntitiesField;
 | 
					    private static Field trackedEntitiesField;
 | 
				
			||||||
 | 
					    @Getter
 | 
				
			||||||
 | 
					    private static NmsVersion version;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static boolean isSupported(NmsVersion version) {
 | 
				
			||||||
 | 
					        return getVersion().ordinal() >= version.ordinal();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static void init() {
 | 
					    public static void init() {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
@@ -96,6 +103,52 @@ public class ReflectionManager {
 | 
				
			|||||||
        entityCountField.setAccessible(true);
 | 
					        entityCountField.setAccessible(true);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static boolean isSupported(AccessibleObject obj) {
 | 
				
			||||||
 | 
					        if (obj.isAnnotationPresent(NmsAdded.class)) {
 | 
				
			||||||
 | 
					            NmsAdded added = obj.getAnnotation(NmsAdded.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // If it was added after/on this version
 | 
				
			||||||
 | 
					            if (!isSupported(added.added())) {
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (obj.isAnnotationPresent(NmsRemoved.class)) {
 | 
				
			||||||
 | 
					            NmsRemoved removed = obj.getAnnotation(NmsRemoved.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (isSupported(removed.removed())) {
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static boolean isSupported(Class cl, String name) {
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            for (Field field : cl.getFields()) {
 | 
				
			||||||
 | 
					                if (!field.getName().equals(name)) {
 | 
				
			||||||
 | 
					                    continue;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                return isSupported(field);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            for (Method method : cl.getMethods()) {
 | 
				
			||||||
 | 
					                if (!method.getName().equals(name)) {
 | 
				
			||||||
 | 
					                    continue;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                return isSupported(method);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        catch (Exception ex) {
 | 
				
			||||||
 | 
					            ex.printStackTrace();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static YamlConfiguration getPluginYaml(ClassLoader loader) {
 | 
					    public static YamlConfiguration getPluginYaml(ClassLoader loader) {
 | 
				
			||||||
        try (InputStream stream = loader.getResourceAsStream("plugin.yml")) {
 | 
					        try (InputStream stream = loader.getResourceAsStream("plugin.yml")) {
 | 
				
			||||||
            YamlConfiguration config = new YamlConfiguration();
 | 
					            YamlConfiguration config = new YamlConfiguration();
 | 
				
			||||||
@@ -286,6 +339,15 @@ public class ReflectionManager {
 | 
				
			|||||||
    public static String getBukkitVersion() {
 | 
					    public static String getBukkitVersion() {
 | 
				
			||||||
        if (bukkitVersion == null) {
 | 
					        if (bukkitVersion == null) {
 | 
				
			||||||
            bukkitVersion = Bukkit.getServer().getClass().getName().split("\\.")[3];
 | 
					            bukkitVersion = Bukkit.getServer().getClass().getName().split("\\.")[3];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            for (NmsVersion v : NmsVersion.values()) {
 | 
				
			||||||
 | 
					                if (!getBukkitVersion().startsWith(v.name())) {
 | 
				
			||||||
 | 
					                    continue;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                version = v;
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return bukkitVersion;
 | 
					        return bukkitVersion;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,7 +17,8 @@ public class TranslateFiller {
 | 
				
			|||||||
        // Fill the configs
 | 
					        // Fill the configs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (ParamInfo info : ParamInfoManager.getParamInfos()) {
 | 
					        for (ParamInfo info : ParamInfoManager.getParamInfos()) {
 | 
				
			||||||
            TranslateType.DISGUISE_OPTIONS_PARAMETERS.save(info.getRawName(), "A disguise option name, has description " + info.getDescription());
 | 
					            TranslateType.DISGUISE_OPTIONS_PARAMETERS
 | 
				
			||||||
 | 
					                    .save(info.getRawName(), "A disguise option name, has description " + info.getDescription());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!info.getRawName().equals(info.getRawDescriptiveName())) {
 | 
					            if (!info.getRawName().equals(info.getRawDescriptiveName())) {
 | 
				
			||||||
                TranslateType.DISGUISE_OPTIONS_PARAMETERS
 | 
					                TranslateType.DISGUISE_OPTIONS_PARAMETERS
 | 
				
			||||||
@@ -51,6 +52,10 @@ public class TranslateFiller {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            TranslateType.DISGUISES.save(StringUtils.join(split, " "), "Name for the " + type.name() + " disguise");
 | 
					            TranslateType.DISGUISES.save(StringUtils.join(split, " "), "Name for the " + type.name() + " disguise");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (type.getEntityType() == null) {
 | 
				
			||||||
 | 
					                continue;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for (Method method : ParamInfoManager.getDisguiseWatcherMethods(type.getWatcherClass())) {
 | 
					            for (Method method : ParamInfoManager.getDisguiseWatcherMethods(type.getWatcherClass())) {
 | 
				
			||||||
                Class para = method.getParameterTypes()[0];
 | 
					                Class para = method.getParameterTypes()[0];
 | 
				
			||||||
                String className = method.getDeclaringClass().getSimpleName().replace("Watcher", "");
 | 
					                String className = method.getDeclaringClass().getSimpleName().replace("Watcher", "");
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user