diff --git a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java index 120ed000..d106339a 100644 --- a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java @@ -501,11 +501,11 @@ public class LibsDisguises extends JavaPlugin { bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0); WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity); - ArrayList indexes = MetaIndex.getFlags(disguiseType.getWatcherClass()); + ArrayList indexes = MetaIndex.getMetaIndexes(disguiseType.getWatcherClass()); boolean loggedName = false; for (WrappedWatchableObject watch : watcher.getWatchableObjects()) { - MetaIndex flagType = MetaIndex.getFlag(watcherClass, watch.getIndex()); + MetaIndex flagType = MetaIndex.getMetaIndex(watcherClass, watch.getIndex()); if (flagType == null) { getLogger().severe("MetaIndex not found for " + disguiseType + "! Index: " + watch.getIndex()); diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java index 91511e26..64a919c7 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -689,9 +689,9 @@ public abstract class Disguise { * datawatcher. */ private void setupWatcher() { - ArrayList disguiseFlags = MetaIndex.getFlags(getType().getWatcherClass()); + ArrayList disguiseFlags = MetaIndex.getMetaIndexes(getType().getWatcherClass()); ArrayList entityFlags = MetaIndex - .getFlags(DisguiseType.getType(getEntity().getType()).getWatcherClass()); + .getMetaIndexes(DisguiseType.getType(getEntity().getType()).getWatcherClass()); for (MetaIndex flag : entityFlags) { if (disguiseFlags.contains(flag)) diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java index bca8306b..a4e1c965 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java @@ -22,47 +22,98 @@ import java.util.Map.Entry; public class MetaIndex { private static MetaIndex[] _values = new MetaIndex[0]; + /** + * True if entity is a baby + */ public static MetaIndex AGEABLE_BABY = new MetaIndex<>(AgeableWatcher.class, 0, false); + /** + * The color of the Area Effect Cloud as RGB integer + */ public static MetaIndex AREA_EFFECT_CLOUD_COLOR = new MetaIndex<>(AreaEffectCloudWatcher.class, 1, Color.BLACK.asRGB()); + /** + * Ignore radius and show effect as single point, not area + */ public static MetaIndex AREA_EFFECT_IGNORE_RADIUS = new MetaIndex<>(AreaEffectCloudWatcher.class, 2, false); + /** + * The type of particle to display + */ public static MetaIndex AREA_EFFECT_PARTICLE = new MetaIndex<>(AreaEffectCloudWatcher.class, 3, Particle.SPELL_MOB); + /** + * The size of the area + */ public static MetaIndex AREA_EFFECT_RADIUS = new MetaIndex<>(AreaEffectCloudWatcher.class, 0, 3F); + /** + * Armorstand body eular vector + */ public static MetaIndex ARMORSTAND_BODY = new MetaIndex<>(ArmorStandWatcher.class, 2, new Vector3F(0, 0, 0)); + /** + * Armorstand head eular vector + */ public static MetaIndex ARMORSTAND_HEAD = new MetaIndex<>(ArmorStandWatcher.class, 1, new Vector3F(0, 0, 0)); + /** + * Armorstand left arm eular vector + */ public static MetaIndex ARMORSTAND_LEFT_ARM = new MetaIndex<>(ArmorStandWatcher.class, 3, new Vector3F(-10, 0, -10)); + /** + * Armorstand left leg eular vector + */ public static MetaIndex ARMORSTAND_LEFT_LEG = new MetaIndex<>(ArmorStandWatcher.class, 5, new Vector3F(-1, 0, -1)); + /** + * Armorstand metadata + */ public static MetaIndex ARMORSTAND_META = new MetaIndex<>(ArmorStandWatcher.class, 0, (byte) 0); + /** + * Armorstand right arm eular vector + */ public static MetaIndex ARMORSTAND_RIGHT_ARM = new MetaIndex<>(ArmorStandWatcher.class, 4, new Vector3F(-15, 0, 10)); + /** + * Armorstand right leg eular vector + */ public static MetaIndex ARMORSTAND_RIGHT_LEG = new MetaIndex<>(ArmorStandWatcher.class, 6, new Vector3F(1, 0, 1)); + /** + * If the arrow is a critical strike + */ public static MetaIndex ARROW_CRITICAL = new MetaIndex<>(ArrowWatcher.class, 0, (byte) 0); + /** + * The shooter of the arrow, no visible effect if set + */ public static MetaIndex> ARROW_UUID = new MetaIndex<>(ArrowWatcher.class, 1, Optional.empty()); + /** + * If the bat is hanging, false/true state + */ public static MetaIndex BAT_HANGING = new MetaIndex<>(BatWatcher.class, 0, (byte) 1); + /** + * If the blaze is ignited, false/true state + */ public static MetaIndex BLAZE_BLAZING = new MetaIndex<>(BlazeWatcher.class, 0, (byte) 0); + /** + * How damaged the boat is + */ public static MetaIndex BOAT_DAMAGE = new MetaIndex<>(BoatWatcher.class, 2, 0F); public static MetaIndex BOAT_DIRECTION = new MetaIndex<>(BoatWatcher.class, 1, 1); @@ -73,49 +124,96 @@ public class MetaIndex { public static MetaIndex BOAT_RIGHT_PADDLING = new MetaIndex<>(BoatWatcher.class, 4, false); + /** + * The type of the boat, birch, pine, oak, etc. + */ public static MetaIndex BOAT_TYPE = new MetaIndex<>(BoatWatcher.class, 3, 0); public static MetaIndex BOAT_SHAKE = new MetaIndex<>(BoatWatcher.class, 6, 0); + /** + * If creeper is ignited, about to blow up + */ public static MetaIndex CREEPER_IGNITED = new MetaIndex<>(CreeperWatcher.class, 2, false); + /** + * If creeper has glowing aura, struck by lightning + */ public static MetaIndex CREEPER_POWERED = new MetaIndex<>(CreeperWatcher.class, 1, false); + /** + * No visible effect + */ public static MetaIndex CREEPER_STATE = new MetaIndex<>(CreeperWatcher.class, 0, -1); + /** + * No visible effect + */ public static MetaIndex DOLPHIN_TREASURE_POS = new MetaIndex<>(DolphinWatcher.class, 0, BlockPosition.ORIGIN); - + /** + * No visible effect + */ public static MetaIndex DOLPHIN_HAS_FISH = new MetaIndex<>(DolphinWatcher.class, 1, false); + /** + * No visible effect + */ public static MetaIndex DOLPHIN_BREATH = new MetaIndex<>(DolphinWatcher.class, 2, 2400); + /** + * The itemstack of the dropped item, must be set + */ public static MetaIndex DROPPED_ITEM = new MetaIndex<>(DroppedItemWatcher.class, 0, new ItemStack(Material.AIR)); public static MetaIndex> ENDER_CRYSTAL_BEAM = new MetaIndex<>(EnderCrystalWatcher.class, 0, Optional.empty()); + /** + * If the ender crystal has a plate + */ public static MetaIndex ENDER_CRYSTAL_PLATE = new MetaIndex<>(EnderCrystalWatcher.class, 1, true); public static MetaIndex ENDER_DRAGON_PHASE = new MetaIndex<>(EnderDragonWatcher.class, 0, 10); + /** + * If the enderman is screaming + */ public static MetaIndex ENDERMAN_AGRESSIVE = new MetaIndex<>(EndermanWatcher.class, 1, false); + /** + * What block the enderman is holding + */ public static MetaIndex> ENDERMAN_ITEM = new MetaIndex<>(EndermanWatcher.class, 0, Optional.empty()); public static MetaIndex ENTITY_AIR_TICKS = new MetaIndex<>(FlagWatcher.class, 1, 300); + /** + * The custom name of the entity, empty if not set + */ public static MetaIndex> ENTITY_CUSTOM_NAME = new MetaIndex<>(FlagWatcher.class, 2, Optional.empty()); + /** + * If custom name should always be visible even when not looked at + */ public static MetaIndex ENTITY_CUSTOM_NAME_VISIBLE = new MetaIndex<>(FlagWatcher.class, 3, false); + /** + * A bit shifted byte indicating several flags on the entity, sprinting, burning, sneaking, etc + */ public static MetaIndex ENTITY_META = new MetaIndex<>(FlagWatcher.class, 0, (byte) 0); + /** + * If entity is effected by gravity, some visial effects + */ public static MetaIndex ENTITY_NO_GRAVITY = new MetaIndex<>(FlagWatcher.class, 5, false); + /** + * If entity can make sounds, no noticable effects + */ public static MetaIndex ENTITY_SILENT = new MetaIndex<>(FlagWatcher.class, 4, false); public static MetaIndex FALLING_BLOCK_POSITION = new MetaIndex<>(FallingBlockWatcher.class, 0, @@ -130,21 +228,45 @@ public class MetaIndex { public static MetaIndex FISHING_HOOK_HOOKED = new MetaIndex<>(FishingHookWatcher.class, 0, 0); + /** + * Changes the face of the ghast + */ public static MetaIndex GHAST_AGRESSIVE = new MetaIndex<>(GhastWatcher.class, 0, false); + /** + * Switch between the guardian spikes enabled/disabled + */ public static MetaIndex GUARDIAN_RETRACT_SPIKES = new MetaIndex<>(GuardianWatcher.class, 0, false); + /** + * Play a guardian beam between guardian and target entity id + */ public static MetaIndex GUARDIAN_TARGET = new MetaIndex<>(GuardianWatcher.class, 1, 0); + /** + * What type of armor the horse has + */ public static MetaIndex HORSE_ARMOR = new MetaIndex<>(HorseWatcher.class, 1, 0); + /** + * If horse has chest, set for donkey + */ public static MetaIndex HORSE_CHESTED_CARRYING_CHEST = new MetaIndex<>(ChestedHorseWatcher.class, 0, false); + /** + * Color of the horse, uses enum not RGB + */ public static MetaIndex HORSE_COLOR = new MetaIndex<>(HorseWatcher.class, 0, 0); + /** + * Sets several bit shifted flags, grazing, rearing, etc + */ public static MetaIndex HORSE_META = new MetaIndex<>(AbstractHorseWatcher.class, 0, (byte) 0); + /** + * Owner of the horse, no visual effect + */ public static MetaIndex> HORSE_OWNER = new MetaIndex<>(AbstractHorseWatcher.class, 1, Optional.empty()); @@ -156,31 +278,67 @@ public class MetaIndex { public static MetaIndex IRON_GOLEM_PLAYER_CREATED = new MetaIndex<>(IronGolemWatcher.class, 0, (byte) 0); + /** + * The itemstack inside the itemframe + */ public static MetaIndex ITEMFRAME_ITEM = new MetaIndex<>(ItemFrameWatcher.class, 0, new ItemStack(Material.AIR)); + /** + * The itemstack rotation inside the itemframe + */ public static MetaIndex ITEMFRAME_ROTATION = new MetaIndex<>(ItemFrameWatcher.class, 1, 0); + /** + * How many arrows sticking out of the living entity, currently used on player + */ public static MetaIndex LIVING_ARROWS = new MetaIndex<>(LivingWatcher.class, 4, 0); + /** + * The main hand of the living entity + */ public static MetaIndex LIVING_HAND = new MetaIndex<>(LivingWatcher.class, 0, (byte) 0); + /** + * How much health the living entity has, generally only visible on bosses due to their health bar + */ public static MetaIndex LIVING_HEALTH = new MetaIndex<>(LivingWatcher.class, 1, 1F); + /** + * If the potion effect particles should be faded + */ public static MetaIndex LIVING_POTION_AMBIENT = new MetaIndex<>(LivingWatcher.class, 3, false); + /** + * The RGB color of the potion particles, 0 if not set + */ public static MetaIndex LIVING_POTIONS = new MetaIndex<>(LivingWatcher.class, 2, 0); + /** + * If there is no carpet, -1. Otherwise it's a color enum value + */ public static MetaIndex LLAMA_CARPET = new MetaIndex<>(LlamaWatcher.class, 1, -1); + /** + * The color of the llama, color enum value + */ public static MetaIndex LLAMA_COLOR = new MetaIndex<>(LlamaWatcher.class, 2, 0); public static MetaIndex LLAMA_STRENGTH = new MetaIndex<>(LlamaWatcher.class, 0, 0); + /** + * The block id:data combined id, 0 if no block + */ public static MetaIndex MINECART_BLOCK = new MetaIndex<>(MinecartWatcher.class, 3, 0); + /** + * If there is a block inside the minecart + */ public static MetaIndex MINECART_BLOCK_VISIBLE = new MetaIndex<>(MinecartWatcher.class, 5, false); + /** + * How much gap there should be between minecart and block, 6 by default + */ public static MetaIndex MINECART_BLOCK_Y = new MetaIndex<>(MinecartWatcher.class, 4, 6); public static MetaIndex MINECART_SHAKING_DIRECTION = new MetaIndex<>(MinecartWatcher.class, 1, 1); @@ -189,11 +347,17 @@ public class MetaIndex { public static MetaIndex MINECART_SHAKING_POWER = new MetaIndex<>(MinecartWatcher.class, 0, 0); + /** + * The command run if the minecraft is a command minecart block + */ public static MetaIndex MINECART_COMMAND_STRING = new MetaIndex<>(MinecartCommandWatcher.class, 0, ""); public static MetaIndex MINECART_COMMAND_LAST_OUTPUT = new MetaIndex<>( MinecartCommandWatcher.class, 1, WrappedChatComponent.fromText("")); + /** + * If the minecart furnace is fueled and burning + */ public static MetaIndex MINECART_FURANCE_FUELED = new MetaIndex<>(MinecartFurnaceWatcher.class, 0, false); public static MetaIndex OCELOT_TYPE = new MetaIndex<>(OcelotWatcher.class, 0, 0); @@ -204,6 +368,9 @@ public class MetaIndex { public static MetaIndex PIG_SADDLED = new MetaIndex<>(PigWatcher.class, 0, false); + /** + * If pig runs faster, no visible effect + */ public static MetaIndex PIG_BOOST = new MetaIndex<>(PigWatcher.class, 1, 0); public static MetaIndex PLAYER_ABSORPTION = new MetaIndex<>(PlayerWatcher.class, 0, 0F); @@ -307,6 +474,9 @@ public class MetaIndex { public static MetaIndex ZOMBIE_VILLAGER_PROFESSION = new MetaIndex<>(ZombieVillagerWatcher.class, 1, 0); + /** + * Shown for villager conversion + */ public static MetaIndex ZOMBIE_VILLAGER_SHAKING = new MetaIndex<>(ZombieVillagerWatcher.class, 0, false); static { @@ -356,10 +526,12 @@ public class MetaIndex { } } + /** + * Simple verification for the dev that he's setting up the FlagType's properly. + * All flag types should be from 0 to with no empty numbers. + * All flag types should never occur twice. + */ public static void validateMetadata() { - // Simple verification for the dev that he's setting up the FlagType's properly. - // All flag types should be from 0 to with no empty numbers. - // All flag types should never occur twice. HashMap maxValues = new HashMap<>(); @@ -403,6 +575,9 @@ public class MetaIndex { } } + /** + * Used for debugging purposes, prints off the registered MetaIndexes + */ @Deprecated public static void printMetadata() { ArrayList toPrint = new ArrayList<>(); @@ -430,7 +605,12 @@ public class MetaIndex { } } - public static MetaIndex getFlag(Class watcherClass, int flagNo) { + /** + * @param watcherClass - A FlagWatcher class + * @param flagNo - The meta index number + * @return The MetaIndex which corresponds to that FlagWatcher at that index + */ + public static MetaIndex getMetaIndex(Class watcherClass, int flagNo) { for (MetaIndex type : values()) { if (type.getIndex() != flagNo) continue; @@ -444,7 +624,11 @@ public class MetaIndex { return null; } - public static ArrayList getFlags(Class watcherClass) { + /** + * @param watcherClass - A flagwatcher class + * @return ArrayList registered to that FlagWatcher + */ + public static ArrayList getMetaIndexes(Class watcherClass) { ArrayList list = new ArrayList<>(); for (MetaIndex type : values()) { @@ -476,10 +660,18 @@ public class MetaIndex { return found; } + /** + * Get all the MetaIndex's registered + * + * @return MetaIndex[] + */ public static MetaIndex[] values() { return _values; } + /** + * Get the field name of a registered MetaIndex + */ @Deprecated public static String getName(MetaIndex metaIndex) { try { @@ -498,13 +690,18 @@ public class MetaIndex { return null; } + /** + * Add @metaIndexes to the existing MetaIndexes, was intended for backwards support + * + * @param metaIndexes + */ public static void addMetaIndexes(MetaIndex... metaIndexes) { _values = Arrays.copyOf(values(), values().length + metaIndexes.length); for (int i = values().length - metaIndexes.length, a = 0; i < values().length; i++, a++) { MetaIndex index = metaIndexes[a]; - ArrayList list = getFlags(index.getFlagWatcher()); + ArrayList list = getMetaIndexes(index.getFlagWatcher()); for (int b = index.getIndex(); b < list.size(); b++) { list.get(b)._index++; @@ -526,6 +723,9 @@ public class MetaIndex { } } + /** + * Resets the metaindex array and regenerates it from the fields + */ public static void setValues() { try { _values = new MetaIndex[0]; @@ -549,7 +749,7 @@ public class MetaIndex { } /** - * Returns true if success, false if the field doesn't exist + * Returns true if field was replaced, false if the field doesn't exist or exception occured */ public static boolean setMetaIndex(String name, MetaIndex metaIndex) { try { @@ -557,15 +757,15 @@ public class MetaIndex { MetaIndex index = (MetaIndex) field.get(null); field.set(null, metaIndex); + return true; } - catch (NoSuchFieldException ex) { - return false; + catch (NoSuchFieldException ignored) { } catch (Exception ex) { ex.printStackTrace(); } - return true; + return false; } private Y _defaultValue; diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AbstractHorseWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AbstractHorseWatcher.java index cd4b0b00..6a032ae0 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AbstractHorseWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AbstractHorseWatcher.java @@ -15,18 +15,38 @@ public abstract class AbstractHorseWatcher extends AgeableWatcher { return getData(MetaIndex.HORSE_OWNER); } + /** + * If the horse has a chest + * + * @return Does horse have chest + */ public boolean hasChest() { return isHorseFlag(8); } + /** + * If the horse can be breeded, no visible effect + * + * @return Is horse breedable + */ public boolean isBreedable() { return isHorseFlag(16); } + /** + * If the horse is grazing + * + * @return Is horse grazing + */ public boolean isGrazing() { return isHorseFlag(32); } + /** + * If the horse has it's mouth open + * + * @return Horse has mouth open + */ public boolean isMouthOpen() { return isHorseFlag(128); } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index fe6a8df5..b9a95b7b 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -860,14 +860,23 @@ public class DisguiseUtilities { Object world = ReflectionManager.getWorldServer(Bukkit.getWorlds().get(0)); Class chunkClass = ReflectionManager.getNmsClass("Chunk"); Object bedChunk = null; + Object[] biomes = (Object[]) Array.newInstance(ReflectionManager.getNmsClass("BiomeBase"), 256); + + Class registry = ReflectionManager.getNmsClass("IRegistry"); + Field biomeRegistry = ReflectionManager.getNmsField(registry, "BIOME"); + Iterator itel = ((Iterator) registry.getMethod("iterator").invoke(biomeRegistry.get(null))); + + for (int i = 0; i < biomes.length && itel.hasNext(); i++) { + while (itel.hasNext()) { + biomes[i] = itel.next(); + } + } for (Constructor constructor : chunkClass.getConstructors()) { if (constructor.getParameterTypes().length != 8) continue; - bedChunk = constructor - .newInstance(world, 0, 0, Array.newInstance(ReflectionManager.getNmsClass("BiomeBase"), 0), - null, null, null, 0L); + bedChunk = constructor.newInstance(world, 0, 0, biomes, null, null, null, 0L); break; } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java b/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java index 1fadcc6a..0d32d66f 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java @@ -9,28 +9,8 @@ import java.net.URLClassLoader; * Created by libraryaddict on 2/06/2017. */ public class LibsPremium { - // I believe I was tired and frustrated when I wrote this, but leaving it in because it's an entertaining read. - - /** - * If you're seriously going to modify this to get the premium stuff for free, can you at least not - * distribute it? You didn't pay for it despite how cheap it is. You spend $8 on a trip to McDonalds - * but you balk at the idea of actually supporting someone when you can just steal it for free. - * Is the only reason you don't rob McDonalds because they can catch you? Is the only reason you don't rob your - * Grandma being that she knows who was in her house? If you see someone's credit card drop out their pocket, - * you planning on taking it and going shopping? - * Do you really have the right to give someones work away for free? - * You know enough to start coding, but you resist the idea of contributing to this plugin. Its even - * open-source, no one is stopping you. You're the guy who files a bug report because the hacked version has - * malware installed. - * I'd hate to work with you. - */ private static Boolean thisPluginIsPaidFor; - /** - * Don't even think about disabling this unless you purchased the premium plugin. It will uh, corrupt your server - * and stuff. Also my dog will cry because I can't afford to feed him. And my sister will be beaten by my dad - * again because I'm not bringing enough money in. - */ public static Boolean isPremium() { return thisPluginIsPaidFor == null ? !"%%__USER__%%".contains("__USER__") : thisPluginIsPaidFor; } @@ -62,8 +42,8 @@ public class LibsPremium { break; } else { - DisguiseUtilities.getLogger() - .warning("You have a non-premium Lib's Disguises jar (" + file.getName() + ") in the folder!"); + DisguiseUtilities.getLogger().warning( + "You have a non-premium Lib's Disguises jar (" + file.getName() + ") in the folder!"); } } catch (Exception ex) { diff --git a/src/main/java/me/libraryaddict/disguise/utilities/json/SerializerFlagWatcher.java b/src/main/java/me/libraryaddict/disguise/utilities/json/SerializerFlagWatcher.java index e2d94c10..7fc7d6f7 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/json/SerializerFlagWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/json/SerializerFlagWatcher.java @@ -48,7 +48,7 @@ public class SerializerFlagWatcher implements JsonDeserializer, Jso if (!(entry.getValue() instanceof Double)) continue; - MetaIndex index = MetaIndex.getFlag(flagWatcher, entry.getKey()); + MetaIndex index = MetaIndex.getMetaIndex(flagWatcher, entry.getKey()); Object def = index.getDefault();