From 07f4e766c1047297e5904b103d5a54f9ba6abe2c Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 11 Mar 2022 00:02:52 +1300 Subject: [PATCH] Hide methods from disguises that can't use them, fixes #603 --- .../commands/DisguiseBaseCommand.java | 2 +- .../commands/utils/DisguiseHelpCommand.java | 4 +++ .../disguise/disguisetypes/DisguiseType.java | 4 +-- .../disguise/disguisetypes/FlagWatcher.java | 26 ++++++++++++-- .../disguise/disguisetypes/MetaIndex.java | 4 +-- .../watchers/AbstractSkeletonWatcher.java | 2 +- .../watchers/AbstractVillagerWatcher.java | 2 +- .../watchers/AreaEffectCloudWatcher.java | 2 +- .../disguisetypes/watchers/ArrowWatcher.java | 2 +- .../disguisetypes/watchers/BeeWatcher.java | 2 +- .../disguisetypes/watchers/BoatWatcher.java | 2 +- .../disguisetypes/watchers/CatWatcher.java | 2 +- .../watchers/EnderSignalWatcher.java | 2 +- .../watchers/FallingBlockWatcher.java | 2 +- .../watchers/FireballWatcher.java | 2 +- .../watchers/FireworkWatcher.java | 2 +- .../disguisetypes/watchers/FoxWatcher.java | 2 +- .../watchers/IllagerWizardWatcher.java | 4 +-- .../watchers/InsentientWatcher.java | 2 +- .../watchers/IronGolemWatcher.java | 2 +- .../disguisetypes/watchers/LivingWatcher.java | 9 ++++- .../watchers/MinecartWatcher.java | 2 +- .../watchers/MushroomCowWatcher.java | 2 +- .../disguisetypes/watchers/OcelotWatcher.java | 4 +-- .../disguisetypes/watchers/PandaWatcher.java | 2 +- .../watchers/PillagerWatcher.java | 2 +- .../watchers/RavagerWatcher.java | 2 +- .../watchers/SkeletonWatcher.java | 2 +- .../watchers/ThrowableWatcher.java | 2 +- .../watchers/TraderLlamaWatcher.java | 2 +- .../watchers/TridentWatcher.java | 2 +- .../watchers/VillagerWatcher.java | 2 +- .../watchers/VindicatorWatcher.java | 2 +- .../disguisetypes/watchers/WolfWatcher.java | 2 +- .../watchers/ZombieVillagerWatcher.java | 2 +- .../disguisetypes/watchers/ZombieWatcher.java | 4 +-- .../utilities/parser/WatcherMethod.java | 6 ++++ .../reflection/ReflectionManager.java | 2 ++ .../utilities/reflection/WatcherInfo.java | 10 ++++++ .../annotations/MethodGroupType.java | 36 +++++++++++++++++++ .../annotations/MethodIgnoredBy.java | 13 +++++++ .../annotations/MethodOnlyUsedBy.java | 13 +++++++ .../{ => annotations}/NmsAddedIn.java | 4 ++- .../{ => annotations}/NmsRemovedIn.java | 4 ++- .../utilities/watchers/CompileMethods.java | 30 ++++++++++++++-- .../utilities/watchers/DisguiseMethods.java | 9 ++--- 46 files changed, 192 insertions(+), 50 deletions(-) create mode 100644 plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/annotations/MethodGroupType.java create mode 100644 plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/annotations/MethodIgnoredBy.java create mode 100644 plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/annotations/MethodOnlyUsedBy.java rename plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/{ => annotations}/NmsAddedIn.java (62%) rename plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/{ => annotations}/NmsRemovedIn.java (63%) diff --git a/plugin/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java b/plugin/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java index e1716952..5ff5bdfc 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java @@ -242,7 +242,7 @@ public abstract class DisguiseBaseCommand implements CommandExecutor { if (addMethods) { // If this is a method, add. Else if it can be a param of the previous argument, add. for (WatcherMethod method : ParamInfoManager.getDisguiseWatcherMethods(disguisePerm.getWatcherClass())) { - if (!perms.isAllowedDisguise(disguisePerm, Collections.singletonList(method.getName()))) { + if (!perms.isAllowedDisguise(disguisePerm, Collections.singletonList(method.getName())) || !method.isUsable(disguisePerm.getType())) { continue; } diff --git a/plugin/src/main/java/me/libraryaddict/disguise/commands/utils/DisguiseHelpCommand.java b/plugin/src/main/java/me/libraryaddict/disguise/commands/utils/DisguiseHelpCommand.java index efd29e2e..4cb7aa8a 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/commands/utils/DisguiseHelpCommand.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/commands/utils/DisguiseHelpCommand.java @@ -78,6 +78,10 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl try { for (WatcherMethod method : ParamInfoManager.getDisguiseWatcherMethods(watcher)) { + if (!method.isUsable(type.getType())) { + continue; + } + if (args.length < 2 || !args[1].equalsIgnoreCase(LibsMsg.DHELP_SHOW.get())) { if (!perms.isAllowedDisguise(type, Collections.singleton(method.getName().toLowerCase(Locale.ENGLISH)))) { ignored++; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java index f0a88cdc..a923d4ea 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java @@ -1,7 +1,7 @@ package me.libraryaddict.disguise.disguisetypes; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; -import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsRemovedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.translations.TranslateType; import org.apache.commons.lang.StringUtils; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index 8e9da61b..89b292fd 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -19,7 +19,10 @@ import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.LibsPremium; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.MethodGroupType; +import me.libraryaddict.disguise.utilities.reflection.annotations.MethodIgnoredBy; +import me.libraryaddict.disguise.utilities.reflection.annotations.MethodOnlyUsedBy; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import net.md_5.bungee.api.chat.BaseComponent; @@ -83,6 +86,7 @@ public class FlagWatcher { return pitchLock != null; } + @MethodIgnoredBy(value = {}, group = MethodGroupType.NO_LOOK) public void setPitchLocked(boolean pitchLocked) { if (isPitchLocked() == pitchLocked) { return; @@ -137,6 +141,7 @@ public class FlagWatcher { return yawLock != null; } + @MethodIgnoredBy(value = {}, group = MethodGroupType.NO_LOOK) public void setYawLocked(boolean yawLocked) { if (!DisguiseConfig.isMovementPacketsEnabled()) { return; @@ -149,6 +154,7 @@ public class FlagWatcher { setYawLock(yawLocked ? 0F : null); } + @MethodIgnoredBy(value = {}, group = MethodGroupType.NO_LOOK) public void setPitchLock(Float pitch) { if (!DisguiseConfig.isMovementPacketsEnabled()) { return; @@ -183,6 +189,7 @@ public class FlagWatcher { } } + @MethodIgnoredBy(value = {}, group = MethodGroupType.NO_LOOK) public void setYawLock(Float yaw) { this.yawLock = yaw; @@ -236,6 +243,7 @@ public class FlagWatcher { return getEquipment().getHelmet(); } + @MethodOnlyUsedBy(value = {}, group = MethodGroupType.EQUIPPABLE) public void setHelmet(ItemStack itemStack) { getEquipment().setHelmet(itemStack); } @@ -244,6 +252,7 @@ public class FlagWatcher { return getEquipment().getBoots(); } + @MethodOnlyUsedBy(value = {}, group = MethodGroupType.EQUIPPABLE) public void setBoots(ItemStack itemStack) { getEquipment().setBoots(itemStack); } @@ -252,6 +261,7 @@ public class FlagWatcher { return getEquipment().getLeggings(); } + @MethodOnlyUsedBy(value = {}, group = MethodGroupType.EQUIPPABLE) public void setLeggings(ItemStack itemStack) { getEquipment().setLeggings(itemStack); } @@ -260,6 +270,7 @@ public class FlagWatcher { return getEquipment().getChestplate(); } + @MethodOnlyUsedBy(value = {}, group = MethodGroupType.EQUIPPABLE) public void setChestplate(ItemStack itemStack) { getEquipment().setChestplate(itemStack); } @@ -269,6 +280,7 @@ public class FlagWatcher { this.upsideDown = upsideDown; } + @MethodIgnoredBy(value = {}, group = MethodGroupType.NO_LOOK) public void setUpsideDown(boolean upsideDown) { if (isUpsideDown() == upsideDown) { return; @@ -467,6 +479,7 @@ public class FlagWatcher { } @NmsAddedIn(NmsVersion.v1_14) + @MethodIgnoredBy(value = {}, group = MethodGroupType.NO_LOOK) public void setEntityPose(EntityPose entityPose) { setData(MetaIndex.ENTITY_POSE, entityPose); sendData(MetaIndex.ENTITY_POSE); @@ -476,6 +489,7 @@ public class FlagWatcher { return getEquipment().getArmorContents(); } + @MethodOnlyUsedBy(value = {}, group = MethodGroupType.EQUIPPABLE) public void setArmor(ItemStack[] items) { getEquipment().setArmorContents(items); } @@ -664,6 +678,7 @@ public class FlagWatcher { return equipment.getItemInMainHand(); } + @MethodOnlyUsedBy(value = {}, group = MethodGroupType.HOLDABLE) public void setItemInMainHand(ItemStack itemstack) { setItemStack(EquipmentSlot.HAND, itemstack); } @@ -672,6 +687,7 @@ public class FlagWatcher { return equipment.getItemInOffHand(); } + @MethodOnlyUsedBy(value = {}, group = MethodGroupType.HOLDABLE) public void setItemInOffHand(ItemStack itemstack) { setItemStack(EquipmentSlot.OFF_HAND, itemstack); } @@ -753,6 +769,7 @@ public class FlagWatcher { return getEntityFlag(7); } + @MethodIgnoredBy(value = {}, group = MethodGroupType.NO_LOOK) public void setFlyingWithElytra(boolean flying) { setEntityFlag(7, flying); sendData(MetaIndex.ENTITY_META); @@ -816,16 +833,16 @@ public class FlagWatcher { @Deprecated @NmsAddedIn(NmsVersion.v1_12) + @MethodOnlyUsedBy(value = {}, group = MethodGroupType.HOLDABLE) public void setRightClicking(boolean rightClicking) { setMainHandRaised(rightClicking); } - //@NmsRemovedIn(val = NmsVersion.v1_13) public boolean isMainHandRaised() { return !NmsVersion.v1_13.isSupported() && getEntityFlag(4); } - //@NmsRemovedIn(val = NmsVersion.v1_13) + @MethodOnlyUsedBy(value = {}, group = MethodGroupType.HOLDABLE) public void setMainHandRaised(boolean setRightClicking) { if (NmsVersion.v1_13.isSupported()) { return; @@ -839,6 +856,7 @@ public class FlagWatcher { return getEntityFlag(1); } + @MethodOnlyUsedBy(value = {DisguiseType.PLAYER}) public void setSneaking(boolean setSneaking) { setEntityFlag(1, setSneaking); sendData(MetaIndex.ENTITY_META); @@ -1027,6 +1045,7 @@ public class FlagWatcher { } @NmsAddedIn(NmsVersion.v1_14) + @MethodIgnoredBy(value = {}, group = MethodGroupType.NO_LOOK) public void setSleeping(boolean sleeping) { if (isSleeping() == sleeping) { return; @@ -1043,6 +1062,7 @@ public class FlagWatcher { } @NmsAddedIn(NmsVersion.v1_14) + @MethodIgnoredBy(value = {}, group = MethodGroupType.NO_LOOK) public void setSwimming(boolean swimming) { if (isSwimming() == swimming) { return; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java index 82115444..58854f23 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java @@ -92,8 +92,8 @@ import me.libraryaddict.disguise.disguisetypes.watchers.ZoglinWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.ZombieVillagerWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; -import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsRemovedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.translations.LibsMsg; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AbstractSkeletonWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AbstractSkeletonWatcher.java index 1f9f016d..323fa64b 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AbstractSkeletonWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AbstractSkeletonWatcher.java @@ -2,7 +2,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsRemovedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; /** diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AbstractVillagerWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AbstractVillagerWatcher.java index 2b81e6ec..ee27aa1d 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AbstractVillagerWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AbstractVillagerWatcher.java @@ -2,7 +2,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; /** diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java index b18fba78..42300888 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java @@ -6,7 +6,7 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.apache.commons.lang.math.RandomUtils; import org.bukkit.Color; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java index 5e9415bc..a5b3931e 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java @@ -3,7 +3,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; public class ArrowWatcher extends FlagWatcher { diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BeeWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BeeWatcher.java index 4d78fb84..55cd990c 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BeeWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BeeWatcher.java @@ -2,7 +2,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; /** diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BoatWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BoatWatcher.java index da6b9650..ac5cb71e 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BoatWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BoatWatcher.java @@ -3,7 +3,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.TreeSpecies; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/CatWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/CatWatcher.java index f51dc305..a2a59af9 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/CatWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/CatWatcher.java @@ -5,7 +5,7 @@ import me.libraryaddict.disguise.disguisetypes.AnimalColor; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.DyeColor; import org.bukkit.entity.Cat; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EnderSignalWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EnderSignalWatcher.java index 9c670338..1490d6c2 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EnderSignalWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EnderSignalWatcher.java @@ -3,7 +3,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FallingBlockWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FallingBlockWatcher.java index e581df62..5e523c76 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FallingBlockWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FallingBlockWatcher.java @@ -8,7 +8,7 @@ import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.translations.TranslateType; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FireballWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FireballWatcher.java index ede56601..8943a63c 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FireballWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FireballWatcher.java @@ -3,7 +3,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FireworkWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FireworkWatcher.java index b63ecfae..4b9f2b9f 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FireworkWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FireworkWatcher.java @@ -3,7 +3,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FoxWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FoxWatcher.java index cf876b8c..10af6631 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FoxWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FoxWatcher.java @@ -4,7 +4,7 @@ import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.entity.Fox; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/IllagerWizardWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/IllagerWizardWatcher.java index a3c4dced..6c1153de 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/IllagerWizardWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/IllagerWizardWatcher.java @@ -2,8 +2,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; -import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsRemovedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.entity.Spellcaster; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/InsentientWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/InsentientWatcher.java index 5f2c6ba4..d435ad79 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/InsentientWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/InsentientWatcher.java @@ -2,7 +2,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.inventory.MainHand; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/IronGolemWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/IronGolemWatcher.java index 8c4a619d..725b9c89 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/IronGolemWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/IronGolemWatcher.java @@ -2,7 +2,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.GolemCrack; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; public class IronGolemWatcher extends InsentientWatcher { diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java index 6f0c083b..ab638743 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java @@ -9,11 +9,14 @@ import com.comphenix.protocol.wrappers.WrappedAttribute.Builder; import lombok.Getter; import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; +import me.libraryaddict.disguise.utilities.reflection.annotations.MethodGroupType; +import me.libraryaddict.disguise.utilities.reflection.annotations.MethodOnlyUsedBy; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import org.bukkit.Color; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -124,6 +127,7 @@ public class LivingWatcher extends FlagWatcher { @Override @NmsAddedIn(NmsVersion.v1_13) + @MethodOnlyUsedBy(value = {}, group = MethodGroupType.HOLDABLE) public void setMainHandRaised(boolean setRightClicking) { setHandInUse(true); @@ -136,6 +140,7 @@ public class LivingWatcher extends FlagWatcher { } @NmsAddedIn(NmsVersion.v1_13) + @MethodOnlyUsedBy(value = {}, group = MethodGroupType.HOLDABLE) public void setOffhandRaised(boolean setLeftClicking) { setHandInUse(false); @@ -296,6 +301,7 @@ public class LivingWatcher extends FlagWatcher { return getData(MetaIndex.LIVING_ARROWS); } + @MethodOnlyUsedBy(value = {DisguiseType.PLAYER}) public void setArrowsSticking(int arrowsNo) { setData(MetaIndex.LIVING_ARROWS, Math.max(0, Math.min(127, arrowsNo))); sendData(MetaIndex.LIVING_ARROWS); @@ -324,6 +330,7 @@ public class LivingWatcher extends FlagWatcher { @Deprecated @NmsAddedIn(NmsVersion.v1_12) + @MethodOnlyUsedBy(value = {}, group = MethodGroupType.HOLDABLE) public void setRightClicking(boolean rightClicking) { setMainHandRaised(rightClicking); } diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java index b96eceb1..0f673b22 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java @@ -3,7 +3,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import org.bukkit.Material; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/MushroomCowWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/MushroomCowWatcher.java index df1382b9..db145ac7 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/MushroomCowWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/MushroomCowWatcher.java @@ -2,7 +2,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.entity.MushroomCow; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java index ed044554..5d3e4ae9 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java @@ -2,8 +2,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; -import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsRemovedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.entity.Ocelot; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PandaWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PandaWatcher.java index f7a6285b..c3cdada4 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PandaWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PandaWatcher.java @@ -4,7 +4,7 @@ import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.entity.Panda; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PillagerWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PillagerWatcher.java index e9cea4a8..e485fcab 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PillagerWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PillagerWatcher.java @@ -2,7 +2,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; /** diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/RavagerWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/RavagerWatcher.java index 72949a5f..87d4220d 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/RavagerWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/RavagerWatcher.java @@ -1,7 +1,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; /** diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java index 06cf074e..75832561 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java @@ -2,7 +2,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; /** diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ThrowableWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ThrowableWatcher.java index a9a5b514..6a448aff 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ThrowableWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ThrowableWatcher.java @@ -4,7 +4,7 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.inventory.ItemStack; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TraderLlamaWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TraderLlamaWatcher.java index e36d4794..492ecac4 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TraderLlamaWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TraderLlamaWatcher.java @@ -1,7 +1,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; /** diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TridentWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TridentWatcher.java index 717d1169..6fa7ffdc 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TridentWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TridentWatcher.java @@ -2,7 +2,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; /** diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java index d3cdac6f..06443231 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java @@ -6,7 +6,7 @@ import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.VillagerData; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.entity.Villager; import org.bukkit.entity.Villager.Profession; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/VindicatorWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/VindicatorWatcher.java index 48802f0b..4c4ce1b8 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/VindicatorWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/VindicatorWatcher.java @@ -2,7 +2,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsRemovedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; public class VindicatorWatcher extends IllagerWatcher { diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java index 75e27e51..4bece16c 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java @@ -3,7 +3,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.AnimalColor; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsRemovedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.DyeColor; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ZombieVillagerWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ZombieVillagerWatcher.java index dbc2c622..0bccaa6d 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ZombieVillagerWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ZombieVillagerWatcher.java @@ -5,7 +5,7 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.VillagerData; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.entity.Villager; import org.bukkit.entity.Villager.Profession; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java index b72e6646..01328c07 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java @@ -2,8 +2,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; -import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsRemovedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; public class ZombieWatcher extends InsentientWatcher { diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/parser/WatcherMethod.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/parser/WatcherMethod.java index ec58040a..fde1e270 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/parser/WatcherMethod.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/parser/WatcherMethod.java @@ -2,6 +2,7 @@ package me.libraryaddict.disguise.utilities.parser; import lombok.Getter; import lombok.RequiredArgsConstructor; +import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import java.lang.invoke.MethodHandle; @@ -19,6 +20,11 @@ public class WatcherMethod { private final Class param; private final boolean randomDefault; private final boolean hideFromTab; + private final boolean[] unusableBy; + + public boolean isUsable(DisguiseType type) { + return !unusableBy[type.ordinal()]; + } @Override public String toString() { diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java index f923d3a6..ff57202b 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java @@ -41,6 +41,8 @@ import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseValues; import me.libraryaddict.disguise.utilities.LibsPremium; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsRemovedIn; import me.libraryaddict.disguise.utilities.sounds.SoundGroup; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/WatcherInfo.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/WatcherInfo.java index 7c502172..dec57c0f 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/WatcherInfo.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/WatcherInfo.java @@ -2,6 +2,7 @@ package me.libraryaddict.disguise.utilities.reflection; import lombok.Getter; import lombok.Setter; +import me.libraryaddict.disguise.disguisetypes.DisguiseType; /** * Created by libraryaddict on 17/02/2020. @@ -18,6 +19,15 @@ public class WatcherInfo { private String method; private String param; private String descriptor; + private boolean[] unusableBy; + + public void setUnusableBy(DisguiseType[] types) { + unusableBy = new boolean[DisguiseType.values().length]; + + for (DisguiseType type : types) { + unusableBy[type.ordinal()] = true; + } + } public boolean isSupported() { if (getAdded() >= 0 && added > ReflectionManager.getVersion().ordinal()) { diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/annotations/MethodGroupType.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/annotations/MethodGroupType.java new file mode 100644 index 00000000..c7a35e88 --- /dev/null +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/annotations/MethodGroupType.java @@ -0,0 +1,36 @@ +package me.libraryaddict.disguise.utilities.reflection.annotations; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import me.libraryaddict.disguise.disguisetypes.DisguiseType; + +import java.util.Arrays; + +@Getter +public enum MethodGroupType { + NO_LOOK(DisguiseType.AREA_EFFECT_CLOUD, DisguiseType.DRAGON_FIREBALL, DisguiseType.DROPPED_ITEM, DisguiseType.EGG, DisguiseType.ENDER_CRYSTAL, + DisguiseType.ENDER_PEARL, DisguiseType.ENDER_SIGNAL, DisguiseType.FALLING_BLOCK, DisguiseType.FIREBALL, DisguiseType.FIREWORK, + DisguiseType.FISHING_HOOK, DisguiseType.LEASH_HITCH, DisguiseType.MARKER, DisguiseType.PRIMED_TNT, DisguiseType.SHULKER, DisguiseType.SMALL_FIREBALL, + DisguiseType.SNOWBALL, DisguiseType.SPLASH_POTION, DisguiseType.THROWN_EXP_BOTTLE), + + EQUIPPABLE(DisguiseType.ARMOR_STAND, DisguiseType.DROWNED, DisguiseType.GIANT, DisguiseType.HUSK, DisguiseType.MODDED_LIVING, DisguiseType.MODDED_MISC, + DisguiseType.PIG_ZOMBIE, DisguiseType.PIGLIN, DisguiseType.PIGLIN_BRUTE, DisguiseType.PLAYER, DisguiseType.SKELETON, DisguiseType.STRAY, + DisguiseType.WITHER_SKELETON, DisguiseType.ZOMBIE), + + HOLDABLE(EQUIPPABLE, DisguiseType.ENDERMAN, DisguiseType.EVOKER, DisguiseType.ILLUSIONER, DisguiseType.IRON_GOLEM, DisguiseType.PILLAGER, + DisguiseType.RAVAGER, DisguiseType.VEX, DisguiseType.VINDICATOR, DisguiseType.WANDERING_TRADER, DisguiseType.WITCH, DisguiseType.ZOMBIE_VILLAGER), + + NONE(); + + private final DisguiseType[] disguiseTypes; + + MethodGroupType(DisguiseType... types) { + this.disguiseTypes = types; + } + + MethodGroupType(MethodGroupType inheritFrom, DisguiseType... types) { + this.disguiseTypes = Arrays.copyOf(types, types.length + inheritFrom.getDisguiseTypes().length); + + System.arraycopy(inheritFrom.getDisguiseTypes(), 0, getDisguiseTypes(), types.length, inheritFrom.getDisguiseTypes().length); + } +} diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/annotations/MethodIgnoredBy.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/annotations/MethodIgnoredBy.java new file mode 100644 index 00000000..50a95a4b --- /dev/null +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/annotations/MethodIgnoredBy.java @@ -0,0 +1,13 @@ +package me.libraryaddict.disguise.utilities.reflection.annotations; + +import me.libraryaddict.disguise.disguisetypes.DisguiseType; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface MethodIgnoredBy { + DisguiseType[] value(); + + MethodGroupType group() default MethodGroupType.NONE; +} diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/annotations/MethodOnlyUsedBy.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/annotations/MethodOnlyUsedBy.java new file mode 100644 index 00000000..6893272c --- /dev/null +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/annotations/MethodOnlyUsedBy.java @@ -0,0 +1,13 @@ +package me.libraryaddict.disguise.utilities.reflection.annotations; + +import me.libraryaddict.disguise.disguisetypes.DisguiseType; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface MethodOnlyUsedBy { + DisguiseType[] value(); + + MethodGroupType group() default MethodGroupType.NONE; +} diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsAddedIn.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/annotations/NmsAddedIn.java similarity index 62% rename from plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsAddedIn.java rename to plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/annotations/NmsAddedIn.java index 320af668..4eb5cd95 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsAddedIn.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/annotations/NmsAddedIn.java @@ -1,4 +1,6 @@ -package me.libraryaddict.disguise.utilities.reflection; +package me.libraryaddict.disguise.utilities.reflection.annotations; + +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsRemovedIn.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/annotations/NmsRemovedIn.java similarity index 63% rename from plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsRemovedIn.java rename to plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/annotations/NmsRemovedIn.java index 59d9a0a8..14776c35 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsRemovedIn.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/annotations/NmsRemovedIn.java @@ -1,4 +1,6 @@ -package me.libraryaddict.disguise.utilities.reflection; +package me.libraryaddict.disguise.utilities.reflection.annotations; + +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java index 2c619704..1780b01d 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java @@ -1,12 +1,15 @@ package me.libraryaddict.disguise.utilities.watchers; import com.google.gson.Gson; +import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.utilities.LibsPremium; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; import me.libraryaddict.disguise.utilities.reflection.ClassGetter; -import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; -import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.MethodIgnoredBy; +import me.libraryaddict.disguise.utilities.reflection.annotations.MethodOnlyUsedBy; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.annotations.NmsRemovedIn; import me.libraryaddict.disguise.utilities.reflection.WatcherInfo; import me.libraryaddict.disguise.utilities.sounds.DisguiseSoundEnums; import me.libraryaddict.disguise.utilities.sounds.SoundGroup; @@ -19,9 +22,11 @@ import java.lang.annotation.RetentionPolicy; import java.lang.reflect.Method; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Random; +import java.util.stream.Collectors; /** * Created by libraryaddict on 13/02/2020. @@ -120,6 +125,7 @@ public class CompileMethods { int added = -1; int removed = -1; + DisguiseType[] unusableBy = new DisguiseType[0]; if (method.isAnnotationPresent(NmsAddedIn.class)) { added = method.getAnnotation(NmsAddedIn.class).value().ordinal(); @@ -133,12 +139,32 @@ public class CompileMethods { removed = method.getDeclaringClass().getAnnotation(NmsRemovedIn.class).value().ordinal(); } + if (method.isAnnotationPresent(MethodOnlyUsedBy.class)) { + DisguiseType[] usableBy = method.getAnnotation(MethodOnlyUsedBy.class).value(); + + if (usableBy.length == 0) { + usableBy = method.getAnnotation(MethodOnlyUsedBy.class).group().getDisguiseTypes(); + } + + List list = Arrays.asList(usableBy); + + unusableBy = + Arrays.stream(DisguiseType.values()).filter(type -> !list.contains(type)).collect(Collectors.toList()).toArray(new DisguiseType[0]); + } else if (method.isAnnotationPresent(MethodIgnoredBy.class)) { + unusableBy = method.getAnnotation(MethodIgnoredBy.class).value(); + + if (unusableBy.length == 0) { + unusableBy = method.getAnnotation(MethodIgnoredBy.class).group().getDisguiseTypes(); + } + } + String param = method.getParameterCount() == 1 ? method.getParameterTypes()[0].getName() : null; WatcherInfo info = new WatcherInfo(); info.setMethod(method.getName()); info.setAdded(added); info.setRemoved(removed); + info.setUnusableBy(unusableBy); info.setDeprecated(method.isAnnotationPresent(Deprecated.class)); info.setParam(param); info.setDescriptor(getMethodDescriptor(method)); diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/watchers/DisguiseMethods.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/watchers/DisguiseMethods.java index a1d85445..a50f95e9 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/watchers/DisguiseMethods.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/watchers/DisguiseMethods.java @@ -103,8 +103,9 @@ public class DisguiseMethods { MethodHandle method = MethodHandles.publicLookup().findVirtual(watcher, info.getMethod(), type); - WatcherMethod m = new WatcherMethod(watcher, method, info.getMethod(), returnType, param, info.isRandomDefault(), - info.isDeprecated() && info.getAdded() == 0); + WatcherMethod m = + new WatcherMethod(watcher, method, info.getMethod(), returnType, param, info.isRandomDefault(), info.isDeprecated() && info.getAdded() == 0, + info.getUnusableBy()); methods.add(m); @@ -156,7 +157,7 @@ public class DisguiseMethods { try { WatcherMethod method = new WatcherMethod(disguiseClass, MethodHandles.publicLookup().findVirtual(disguiseClass, methodName, MethodType.methodType(returnType, cl)), methodName, null, - cl, randomDefault, false); + cl, randomDefault, false, new boolean[DisguiseType.values().length]); methods.add(method); @@ -167,7 +168,7 @@ public class DisguiseMethods { WatcherMethod getMethod = new WatcherMethod(disguiseClass, MethodHandles.publicLookup().findVirtual(disguiseClass, getName, MethodType.methodType(cl)), - getName, cl, null, randomDefault, false); + getName, cl, null, randomDefault, false, new boolean[DisguiseType.values().length]); methods.add(getMethod); break;