Fixed typos, added DisguiseParser.parsetoString(Disguise)
This commit is contained in:
		| @@ -13,6 +13,7 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities; | |||||||
| import me.libraryaddict.disguise.utilities.LibsPremium; | 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.reflection.DisguiseValues; | import me.libraryaddict.disguise.utilities.reflection.DisguiseValues; | ||||||
| import me.libraryaddict.disguise.utilities.reflection.FakeBoundingBox; | import me.libraryaddict.disguise.utilities.reflection.FakeBoundingBox; | ||||||
| import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; | import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; | ||||||
| @@ -77,6 +78,8 @@ public class LibsDisguises extends JavaPlugin { | |||||||
|  |  | ||||||
|         DisguiseConfig.loadConfig(); |         DisguiseConfig.loadConfig(); | ||||||
|  |  | ||||||
|  |         DisguiseParser.createDefaultMethods(); | ||||||
|  |  | ||||||
|         PacketsManager.addPacketListeners(); |         PacketsManager.addPacketListeners(); | ||||||
|  |  | ||||||
|         listener = new DisguiseListener(this); |         listener = new DisguiseListener(this); | ||||||
|   | |||||||
| @@ -87,7 +87,7 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter | |||||||
|  |  | ||||||
|     private boolean setViewDisguise(String[] strings) { |     private boolean setViewDisguise(String[] strings) { | ||||||
|         for (String string : strings) { |         for (String string : strings) { | ||||||
|             if (!string.equalsIgnoreCase("setViewSelfDisguise")) |             if (!string.equalsIgnoreCase("setSelfDisguiseVisible")) | ||||||
|                 continue; |                 continue; | ||||||
|  |  | ||||||
|             return true; |             return true; | ||||||
|   | |||||||
| @@ -131,7 +131,7 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom | |||||||
|  |  | ||||||
|     private boolean setViewDisguise(String[] strings) { |     private boolean setViewDisguise(String[] strings) { | ||||||
|         for (String string : strings) { |         for (String string : strings) { | ||||||
|             if (!string.equalsIgnoreCase("setViewSelfDisguise")) |             if (!string.equalsIgnoreCase("setSelfDisguiseVisible")) | ||||||
|                 continue; |                 continue; | ||||||
|  |  | ||||||
|             return true; |             return true; | ||||||
|   | |||||||
| @@ -219,7 +219,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom | |||||||
|  |  | ||||||
|     private boolean setViewDisguise(String[] strings) { |     private boolean setViewDisguise(String[] strings) { | ||||||
|         for (String string : strings) { |         for (String string : strings) { | ||||||
|             if (!string.equalsIgnoreCase("setViewSelfDisguise")) |             if (!string.equalsIgnoreCase("setSelfDisguiseVisible")) | ||||||
|                 continue; |                 continue; | ||||||
|  |  | ||||||
|             return true; |             return true; | ||||||
|   | |||||||
| @@ -406,14 +406,24 @@ public abstract class Disguise { | |||||||
|         return playerHiddenFromTab; |         return playerHiddenFromTab; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Deprecated | ||||||
|     public boolean isHidingArmorFromSelf() { |     public boolean isHidingArmorFromSelf() { | ||||||
|         return hideArmorFromSelf; |         return hideArmorFromSelf; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Deprecated | ||||||
|     public boolean isHidingHeldItemFromSelf() { |     public boolean isHidingHeldItemFromSelf() { | ||||||
|         return hideHeldItemFromSelf; |         return hideHeldItemFromSelf; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public boolean isHideArmorFromSelf() { | ||||||
|  |         return hideArmorFromSelf; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public boolean isHideHeldItemFromSelf() { | ||||||
|  |         return hideHeldItemFromSelf; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public boolean isKeepDisguiseOnPlayerDeath() { |     public boolean isKeepDisguiseOnPlayerDeath() { | ||||||
|         return this.keepDisguisePlayerDeath; |         return this.keepDisguisePlayerDeath; | ||||||
|     } |     } | ||||||
| @@ -442,6 +452,7 @@ public abstract class Disguise { | |||||||
|                 (getEntity() instanceof Player ? !isKeepDisguiseOnPlayerDeath() : getEntity().isDead()); |                 (getEntity() instanceof Player ? !isKeepDisguiseOnPlayerDeath() : getEntity().isDead()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Deprecated | ||||||
|     public boolean isSelfDisguiseSoundsReplaced() { |     public boolean isSelfDisguiseSoundsReplaced() { | ||||||
|         return hearSelfDisguise; |         return hearSelfDisguise; | ||||||
|     } |     } | ||||||
| @@ -455,6 +466,10 @@ public abstract class Disguise { | |||||||
|         return viewSelfDisguise; |         return viewSelfDisguise; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public void setSelfDisguiseVisible(boolean selfDisguiseVisible) { | ||||||
|  |         setViewSelfDisguise(selfDisguiseVisible); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Returns true if the entity's name is showing through the disguise |      * Returns true if the entity's name is showing through the disguise | ||||||
|      * |      * | ||||||
| @@ -619,6 +634,10 @@ public abstract class Disguise { | |||||||
|         return this; |         return this; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public boolean isHearSelfDisguise() { | ||||||
|  |         return hearSelfDisguise; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public Disguise setHearSelfDisguise(boolean hearSelfDisguise) { |     public Disguise setHearSelfDisguise(boolean hearSelfDisguise) { | ||||||
|         this.hearSelfDisguise = hearSelfDisguise; |         this.hearSelfDisguise = hearSelfDisguise; | ||||||
|  |  | ||||||
| @@ -711,8 +730,6 @@ public abstract class Disguise { | |||||||
|             getWatcher().setBackupValue(flag, backup == null ? null : backup.getDefault()); |             getWatcher().setBackupValue(flag, backup == null ? null : backup.getDefault()); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         getWatcher().setNoGravity(true); |  | ||||||
|  |  | ||||||
|         if (getEntity() instanceof Player && !getWatcher().hasCustomName()) { |         if (getEntity() instanceof Player && !getWatcher().hasCustomName()) { | ||||||
|             getWatcher().setCustomName(""); |             getWatcher().setCustomName(""); | ||||||
|         } |         } | ||||||
| @@ -730,6 +747,7 @@ public abstract class Disguise { | |||||||
|      * @param viewSelfDisguise |      * @param viewSelfDisguise | ||||||
|      * @return |      * @return | ||||||
|      */ |      */ | ||||||
|  |     @Deprecated | ||||||
|     public Disguise setViewSelfDisguise(boolean viewSelfDisguise) { |     public Disguise setViewSelfDisguise(boolean viewSelfDisguise) { | ||||||
|         if (isSelfDisguiseVisible() != viewSelfDisguise) { |         if (isSelfDisguiseVisible() != viewSelfDisguise) { | ||||||
|             this.viewSelfDisguise = viewSelfDisguise; |             this.viewSelfDisguise = viewSelfDisguise; | ||||||
|   | |||||||
| @@ -44,6 +44,8 @@ public class FlagWatcher { | |||||||
|     public FlagWatcher(Disguise disguise) { |     public FlagWatcher(Disguise disguise) { | ||||||
|         this.disguise = (TargetedDisguise) disguise; |         this.disguise = (TargetedDisguise) disguise; | ||||||
|         equipment = new LibsEquipment(this); |         equipment = new LibsEquipment(this); | ||||||
|  |  | ||||||
|  |         setNoGravity(true); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private byte addEntityAnimations(byte originalValue, byte entityValue) { |     private byte addEntityAnimations(byte originalValue, byte entityValue) { | ||||||
| @@ -265,7 +267,7 @@ public class FlagWatcher { | |||||||
|         return getCustomName() != null; |         return getCustomName() != null; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     protected boolean hasValue(MetaIndex no) { |     public boolean hasValue(MetaIndex no) { | ||||||
|         if (no == null) |         if (no == null) | ||||||
|             return false; |             return false; | ||||||
|  |  | ||||||
| @@ -280,6 +282,7 @@ public class FlagWatcher { | |||||||
|         return getData(MetaIndex.ENTITY_CUSTOM_NAME_VISIBLE); |         return getData(MetaIndex.ENTITY_CUSTOM_NAME_VISIBLE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Deprecated | ||||||
|     public boolean isEntityAnimationsAdded() { |     public boolean isEntityAnimationsAdded() { | ||||||
|         return addEntityAnimations; |         return addEntityAnimations; | ||||||
|     } |     } | ||||||
| @@ -335,7 +338,8 @@ public class FlagWatcher { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     protected void sendData(MetaIndex... dataValues) { |     protected void sendData(MetaIndex... dataValues) { | ||||||
|         if (!DisguiseAPI.isDisguiseInUse(getDisguise()) || getDisguise().getWatcher() != this) { |         if (getDisguise() == null || !DisguiseAPI.isDisguiseInUse(getDisguise()) || | ||||||
|  |                 getDisguise().getWatcher() != this) { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -391,6 +395,10 @@ public class FlagWatcher { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public boolean isAddEntityAnimations() { | ||||||
|  |         return isEntityAnimationsAdded(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public void setAddEntityAnimations(boolean isEntityAnimationsAdded) { |     public void setAddEntityAnimations(boolean isEntityAnimationsAdded) { | ||||||
|         addEntityAnimations = isEntityAnimationsAdded; |         addEntityAnimations = isEntityAnimationsAdded; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -24,6 +24,10 @@ public abstract class AbstractHorseWatcher extends AgeableWatcher { | |||||||
|         return isHorseFlag(8); |         return isHorseFlag(8); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public boolean isCarryingChest() { | ||||||
|  |         return hasChest(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * If the horse can be breeded, no visible effect |      * If the horse can be breeded, no visible effect | ||||||
|      * |      * | ||||||
| @@ -71,6 +75,11 @@ public abstract class AbstractHorseWatcher extends AgeableWatcher { | |||||||
|         return getData(MetaIndex.HORSE_META); |         return getData(MetaIndex.HORSE_META); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public void setBreedable(boolean breedable) { | ||||||
|  |         setCanBreed(breedable); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Deprecated | ||||||
|     public void setCanBreed(boolean breed) { |     public void setCanBreed(boolean breed) { | ||||||
|         setHorseFlag(16, breed); |         setHorseFlag(16, breed); | ||||||
|     } |     } | ||||||
| @@ -84,8 +93,7 @@ public abstract class AbstractHorseWatcher extends AgeableWatcher { | |||||||
|  |  | ||||||
|         if (flag) { |         if (flag) { | ||||||
|             setData(MetaIndex.HORSE_META, (byte) (j | i)); |             setData(MetaIndex.HORSE_META, (byte) (j | i)); | ||||||
|         } |         } else { | ||||||
|         else { |  | ||||||
|             setData(MetaIndex.HORSE_META, (byte) (j & ~i)); |             setData(MetaIndex.HORSE_META, (byte) (j & ~i)); | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -116,5 +124,4 @@ public abstract class AbstractHorseWatcher extends AgeableWatcher { | |||||||
|     public void setTamed(boolean tamed) { |     public void setTamed(boolean tamed) { | ||||||
|         setHorseFlag(2, tamed); |         setHorseFlag(2, tamed); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -15,4 +15,12 @@ public class AbstractVillagerWatcher extends AgeableWatcher { | |||||||
|         setData(MetaIndex.ABSTRACT_VILLAGER_ANGRY, ticks); |         setData(MetaIndex.ABSTRACT_VILLAGER_ANGRY, ticks); | ||||||
|         sendData(MetaIndex.ABSTRACT_VILLAGER_ANGRY); |         sendData(MetaIndex.ABSTRACT_VILLAGER_ANGRY); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public int getAngry() { | ||||||
|  |         return getData(MetaIndex.ABSTRACT_VILLAGER_ANGRY); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public boolean isAngry() { | ||||||
|  |         return getAngry() > 0; | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ import com.comphenix.protocol.wrappers.WrappedParticle; | |||||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||||
| import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | ||||||
| import me.libraryaddict.disguise.disguisetypes.MetaIndex; | import me.libraryaddict.disguise.disguisetypes.MetaIndex; | ||||||
|  | import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; | ||||||
| import org.apache.commons.lang.math.RandomUtils; | import org.apache.commons.lang.math.RandomUtils; | ||||||
| import org.bukkit.Color; | import org.bukkit.Color; | ||||||
| import org.bukkit.Particle; | import org.bukkit.Particle; | ||||||
| @@ -36,6 +37,7 @@ public class AreaEffectCloudWatcher extends FlagWatcher { | |||||||
|         return Color.fromRGB(color); |         return Color.fromRGB(color); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @RandomDefaultValue | ||||||
|     public void setColor(Color color) { |     public void setColor(Color color) { | ||||||
|         setData(MetaIndex.AREA_EFFECT_CLOUD_COLOR, color.asRGB()); |         setData(MetaIndex.AREA_EFFECT_CLOUD_COLOR, color.asRGB()); | ||||||
|         sendData(MetaIndex.AREA_EFFECT_CLOUD_COLOR); |         sendData(MetaIndex.AREA_EFFECT_CLOUD_COLOR); | ||||||
|   | |||||||
| @@ -3,23 +3,19 @@ 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; | ||||||
|  |  | ||||||
| public class BatWatcher extends InsentientWatcher | public class BatWatcher extends InsentientWatcher { | ||||||
| { |  | ||||||
|  |  | ||||||
|     public BatWatcher(Disguise disguise) |     public BatWatcher(Disguise disguise) { | ||||||
|     { |  | ||||||
|         super(disguise); |         super(disguise); | ||||||
|  |  | ||||||
|         setHanging(false); |         setHanging(false); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isHanging() |     public boolean isHanging() { | ||||||
|     { |  | ||||||
|         return getData(MetaIndex.BAT_HANGING) == 1; |         return getData(MetaIndex.BAT_HANGING) == 1; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setHanging(boolean hanging) |     public void setHanging(boolean hanging) { | ||||||
|     { |  | ||||||
|         setData(MetaIndex.BAT_HANGING, hanging ? (byte) 1 : (byte) 0); |         setData(MetaIndex.BAT_HANGING, hanging ? (byte) 1 : (byte) 0); | ||||||
|         sendData(MetaIndex.BAT_HANGING); |         sendData(MetaIndex.BAT_HANGING); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ 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.parser.RandomDefaultValue; | ||||||
| import org.bukkit.DyeColor; | import org.bukkit.DyeColor; | ||||||
| import org.bukkit.entity.Cat; | import org.bukkit.entity.Cat; | ||||||
|  |  | ||||||
| @@ -22,6 +23,7 @@ public class CatWatcher extends TameableWatcher { | |||||||
|         return Cat.Type.values()[getData(MetaIndex.CAT_TYPE)]; |         return Cat.Type.values()[getData(MetaIndex.CAT_TYPE)]; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @RandomDefaultValue | ||||||
|     public void setType(Cat.Type type) { |     public void setType(Cat.Type type) { | ||||||
|         setData(MetaIndex.CAT_TYPE, type.ordinal()); |         setData(MetaIndex.CAT_TYPE, type.ordinal()); | ||||||
|         sendData(MetaIndex.CAT_TYPE); |         sendData(MetaIndex.CAT_TYPE); | ||||||
| @@ -37,7 +39,7 @@ public class CatWatcher extends TameableWatcher { | |||||||
|             setTamed(true); |             setTamed(true); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (newColor == getCollarColor().getDyeColor()) { |         if (newColor == getCollarColor()) { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -45,8 +47,8 @@ public class CatWatcher extends TameableWatcher { | |||||||
|         sendData(MetaIndex.CAT_COLLAR); |         sendData(MetaIndex.CAT_COLLAR); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public AnimalColor getCollarColor() { |     public DyeColor getCollarColor() { | ||||||
|         return AnimalColor.getColorByWool(getData(MetaIndex.CAT_COLLAR)); |         return AnimalColor.getColorByWool(getData(MetaIndex.CAT_COLLAR)).getDyeColor(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setLyingDown(boolean value) { |     public void setLyingDown(boolean value) { | ||||||
|   | |||||||
| @@ -10,33 +10,26 @@ import java.util.Optional; | |||||||
| /** | /** | ||||||
|  * @author Navid |  * @author Navid | ||||||
|  */ |  */ | ||||||
| public class EnderCrystalWatcher extends FlagWatcher | public class EnderCrystalWatcher extends FlagWatcher { | ||||||
| { |     public EnderCrystalWatcher(Disguise disguise) { | ||||||
|     public EnderCrystalWatcher(Disguise disguise) |  | ||||||
|     { |  | ||||||
|         super(disguise); |         super(disguise); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setBeamTarget(BlockPosition position) |     public void setBeamTarget(BlockPosition position) { | ||||||
|     { |         setData(MetaIndex.ENDER_CRYSTAL_BEAM, position == null ? Optional.empty() : Optional.of(position)); | ||||||
|         setData(MetaIndex.ENDER_CRYSTAL_BEAM, Optional.of(position)); |  | ||||||
|         sendData(MetaIndex.ENDER_CRYSTAL_BEAM); |         sendData(MetaIndex.ENDER_CRYSTAL_BEAM); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public Optional<BlockPosition> getBeamTarget() |     public BlockPosition getBeamTarget() { | ||||||
|     { |         return getData(MetaIndex.ENDER_CRYSTAL_BEAM).orElse(null); | ||||||
|         return getData(MetaIndex.ENDER_CRYSTAL_BEAM); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setShowBottom(boolean bool) |     public void setShowBottom(boolean bool) { | ||||||
|     { |  | ||||||
|         setData(MetaIndex.ENDER_CRYSTAL_PLATE, bool); |         setData(MetaIndex.ENDER_CRYSTAL_PLATE, bool); | ||||||
|         sendData(MetaIndex.ENDER_CRYSTAL_PLATE); |         sendData(MetaIndex.ENDER_CRYSTAL_PLATE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isShowBottom() |     public boolean isShowBottom() { | ||||||
|     { |  | ||||||
|         return getData(MetaIndex.ENDER_CRYSTAL_PLATE); |         return getData(MetaIndex.ENDER_CRYSTAL_PLATE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -55,9 +55,4 @@ public class EndermanWatcher extends InsentientWatcher { | |||||||
|         setData(MetaIndex.ENDERMAN_AGRESSIVE, isAggressive); |         setData(MetaIndex.ENDERMAN_AGRESSIVE, isAggressive); | ||||||
|         sendData(MetaIndex.ENDERMAN_AGRESSIVE); |         sendData(MetaIndex.ENDERMAN_AGRESSIVE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setUnknown(boolean bo) { |  | ||||||
|         setData(MetaIndex.ENDERMAN_UNKNOWN, bo); |  | ||||||
|         sendData(MetaIndex.ENDERMAN_UNKNOWN); |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ 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.parser.RandomDefaultValue; | ||||||
| import org.bukkit.entity.Fox; | import org.bukkit.entity.Fox; | ||||||
|  |  | ||||||
| import java.util.Random; | import java.util.Random; | ||||||
| @@ -40,6 +41,7 @@ public class FoxWatcher extends AgeableWatcher { | |||||||
|         setFoxFlag(32, value); |         setFoxFlag(32, value); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @RandomDefaultValue | ||||||
|     public Fox.Type getType() { |     public Fox.Type getType() { | ||||||
|         return Fox.Type.values()[getData(MetaIndex.FOX_TYPE)]; |         return Fox.Type.values()[getData(MetaIndex.FOX_TYPE)]; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -31,6 +31,13 @@ public class GuardianWatcher extends InsentientWatcher { | |||||||
|         sendData(MetaIndex.GUARDIAN_TARGET); |         sendData(MetaIndex.GUARDIAN_TARGET); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return Entity id of target | ||||||
|  |      */ | ||||||
|  |     public int getTarget() { | ||||||
|  |         return getData(MetaIndex.GUARDIAN_TARGET); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public void setTarget(Entity entity) { |     public void setTarget(Entity entity) { | ||||||
|         setTarget(entity == null ? 0 : entity.getEntityId()); |         setTarget(entity == null ? 0 : entity.getEntityId()); | ||||||
|     } |     } | ||||||
| @@ -58,5 +65,4 @@ public class GuardianWatcher extends InsentientWatcher { | |||||||
|         setData(MetaIndex.GUARDIAN_RETRACT_SPIKES, isRetracting); |         setData(MetaIndex.GUARDIAN_RETRACT_SPIKES, isRetracting); | ||||||
|         sendData(MetaIndex.GUARDIAN_RETRACT_SPIKES); |         sendData(MetaIndex.GUARDIAN_RETRACT_SPIKES); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,13 +1,12 @@ | |||||||
| package me.libraryaddict.disguise.disguisetypes.watchers; | package me.libraryaddict.disguise.disguisetypes.watchers; | ||||||
|  |  | ||||||
| import org.bukkit.Material; |  | ||||||
| import org.bukkit.entity.Horse.Color; |  | ||||||
| import org.bukkit.entity.Horse.Style; |  | ||||||
| import org.bukkit.inventory.ItemStack; |  | ||||||
|  |  | ||||||
| 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.DisguiseUtilities; | import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||||
|  | import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; | ||||||
|  | import org.bukkit.entity.Horse.Color; | ||||||
|  | import org.bukkit.entity.Horse.Style; | ||||||
|  | import org.bukkit.inventory.ItemStack; | ||||||
|  |  | ||||||
| public class HorseWatcher extends AbstractHorseWatcher { | public class HorseWatcher extends AbstractHorseWatcher { | ||||||
|     public HorseWatcher(Disguise disguise) { |     public HorseWatcher(Disguise disguise) { | ||||||
| @@ -25,11 +24,13 @@ public class HorseWatcher extends AbstractHorseWatcher { | |||||||
|         return Style.values()[(getData(MetaIndex.HORSE_COLOR) >>> 8)]; |         return Style.values()[(getData(MetaIndex.HORSE_COLOR) >>> 8)]; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @RandomDefaultValue | ||||||
|     public void setColor(Color color) { |     public void setColor(Color color) { | ||||||
|         setData(MetaIndex.HORSE_COLOR, color.ordinal() & 0xFF | getStyle().ordinal() << 8); |         setData(MetaIndex.HORSE_COLOR, color.ordinal() & 0xFF | getStyle().ordinal() << 8); | ||||||
|         sendData(MetaIndex.HORSE_COLOR); |         sendData(MetaIndex.HORSE_COLOR); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @RandomDefaultValue | ||||||
|     public void setStyle(Style style) { |     public void setStyle(Style style) { | ||||||
|         setData(MetaIndex.HORSE_COLOR, getColor().ordinal() & 0xFF | style.ordinal() << 8); |         setData(MetaIndex.HORSE_COLOR, getColor().ordinal() & 0xFF | style.ordinal() << 8); | ||||||
|         sendData(MetaIndex.HORSE_COLOR); |         sendData(MetaIndex.HORSE_COLOR); | ||||||
|   | |||||||
| @@ -17,10 +17,7 @@ import org.bukkit.entity.Player; | |||||||
| import org.bukkit.potion.PotionEffectType; | import org.bukkit.potion.PotionEffectType; | ||||||
|  |  | ||||||
| import java.lang.reflect.InvocationTargetException; | import java.lang.reflect.InvocationTargetException; | ||||||
| import java.util.ArrayList; | import java.util.*; | ||||||
| import java.util.HashSet; |  | ||||||
| import java.util.List; |  | ||||||
| import java.util.Optional; |  | ||||||
|  |  | ||||||
| public class LivingWatcher extends FlagWatcher { | public class LivingWatcher extends FlagWatcher { | ||||||
|     private double maxHealth; |     private double maxHealth; | ||||||
| @@ -122,6 +119,22 @@ public class LivingWatcher extends FlagWatcher { | |||||||
|         return maxHealthSet; |         return maxHealthSet; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public PotionEffectType[] getPotionEffects() { | ||||||
|  |         PotionEffectType[] effects = new PotionEffectType[potionEffects.size()]; | ||||||
|  |  | ||||||
|  |         int i = 0; | ||||||
|  |  | ||||||
|  |         Iterator<String> itel = potionEffects.iterator(); | ||||||
|  |  | ||||||
|  |         while (itel.hasNext()) { | ||||||
|  |             PotionEffectType type = PotionEffectType.getByName(itel.next()); | ||||||
|  |  | ||||||
|  |             effects[i++] = type; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return effects; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public void addPotionEffect(PotionEffectType potionEffect) { |     public void addPotionEffect(PotionEffectType potionEffect) { | ||||||
|         if (!hasPotionEffect(potionEffect)) { |         if (!hasPotionEffect(potionEffect)) { | ||||||
|             potionEffects.add(potionEffect.getName()); |             potionEffects.add(potionEffect.getName()); | ||||||
|   | |||||||
| @@ -31,8 +31,12 @@ public class LlamaWatcher extends ChestedHorseWatcher { | |||||||
|         setCarpet(color.getDyeColor()); |         setCarpet(color.getDyeColor()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public AnimalColor getCarpet() { |     public DyeColor getCarpet() { | ||||||
|         return AnimalColor.getColorByWool(getData(MetaIndex.LLAMA_CARPET)); |         if (!hasValue(MetaIndex.LLAMA_CARPET)) { | ||||||
|  |             return null; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return AnimalColor.getColorByWool(getData(MetaIndex.LLAMA_CARPET)).getDyeColor(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setStrength(int strength) { |     public void setStrength(int strength) { | ||||||
|   | |||||||
| @@ -14,13 +14,22 @@ public class MinecartWatcher extends FlagWatcher { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public ItemStack getBlockInCart() { |     public ItemStack getBlockInCart() { | ||||||
|  |         if (!hasValue(MetaIndex.MINECART_BLOCK)) { | ||||||
|  |             return new ItemStack(Material.AIR); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         return ReflectionManager.getItemStackByCombinedId(getData(MetaIndex.MINECART_BLOCK)); |         return ReflectionManager.getItemStackByCombinedId(getData(MetaIndex.MINECART_BLOCK)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Deprecated | ||||||
|     public int getBlockYOffset() { |     public int getBlockYOffset() { | ||||||
|         return getData(MetaIndex.MINECART_BLOCK_Y); |         return getData(MetaIndex.MINECART_BLOCK_Y); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public int getBlockOffset() { | ||||||
|  |         return getData(MetaIndex.MINECART_BLOCK_Y); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public boolean isViewBlockInCart() { |     public boolean isViewBlockInCart() { | ||||||
|         return getData(MetaIndex.MINECART_BLOCK_VISIBLE); |         return getData(MetaIndex.MINECART_BLOCK_VISIBLE); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ 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.parser.RandomDefaultValue; | ||||||
| import org.bukkit.entity.Panda; | import org.bukkit.entity.Panda; | ||||||
|  |  | ||||||
| import java.util.Random; | import java.util.Random; | ||||||
| @@ -45,11 +46,13 @@ public class PandaWatcher extends AgeableWatcher { | |||||||
|         return Panda.Gene.NORMAL; |         return Panda.Gene.NORMAL; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @RandomDefaultValue | ||||||
|     public void setMainGene(Panda.Gene gene) { |     public void setMainGene(Panda.Gene gene) { | ||||||
|         setData(MetaIndex.PANDA_MAIN_GENE, (byte) gene.ordinal()); |         setData(MetaIndex.PANDA_MAIN_GENE, (byte) gene.ordinal()); | ||||||
|         sendData(MetaIndex.PANDA_MAIN_GENE); |         sendData(MetaIndex.PANDA_MAIN_GENE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @RandomDefaultValue | ||||||
|     public void setHiddenGene(Panda.Gene gene) { |     public void setHiddenGene(Panda.Gene gene) { | ||||||
|         setData(MetaIndex.PANDA_HIDDEN_GENE, (byte) gene.ordinal()); |         setData(MetaIndex.PANDA_HIDDEN_GENE, (byte) gene.ordinal()); | ||||||
|         sendData(MetaIndex.PANDA_HIDDEN_GENE); |         sendData(MetaIndex.PANDA_HIDDEN_GENE); | ||||||
| @@ -92,6 +95,11 @@ public class PandaWatcher extends AgeableWatcher { | |||||||
|         sendData(MetaIndex.PANDA_HEAD_SHAKING); |         sendData(MetaIndex.PANDA_HEAD_SHAKING); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public int getHeadShaking() { | ||||||
|  |         return getHeadShakingTicks(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Deprecated | ||||||
|     public int getHeadShakingTicks() { |     public int getHeadShakingTicks() { | ||||||
|         return getData(MetaIndex.PANDA_HEAD_SHAKING); |         return getData(MetaIndex.PANDA_HEAD_SHAKING); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ public class PillagerWatcher extends IllagerWatcher { | |||||||
|         super(disguise); |         super(disguise); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setAimimgBow(boolean value) { |     public void setAimingBow(boolean value) { | ||||||
|         setData(MetaIndex.PILLAGER_AIMING_BOW, value); |         setData(MetaIndex.PILLAGER_AIMING_BOW, value); | ||||||
|         sendData(MetaIndex.PILLAGER_AIMING_BOW); |         sendData(MetaIndex.PILLAGER_AIMING_BOW); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -1,22 +1,14 @@ | |||||||
| package me.libraryaddict.disguise.disguisetypes.watchers; | package me.libraryaddict.disguise.disguisetypes.watchers; | ||||||
|  |  | ||||||
| import me.libraryaddict.disguise.disguisetypes.EntityPose; |  | ||||||
| import org.bukkit.block.BlockFace; |  | ||||||
| import org.bukkit.entity.Player; |  | ||||||
| import org.bukkit.inventory.MainHand; |  | ||||||
|  |  | ||||||
| import com.comphenix.protocol.PacketType.Play.Server; |  | ||||||
| import com.comphenix.protocol.ProtocolLibrary; |  | ||||||
| import com.comphenix.protocol.events.PacketContainer; |  | ||||||
| import com.comphenix.protocol.reflect.StructureModifier; |  | ||||||
| import com.comphenix.protocol.wrappers.WrappedGameProfile; | import com.comphenix.protocol.wrappers.WrappedGameProfile; | ||||||
|  | import com.google.gson.Gson; | ||||||
| import me.libraryaddict.disguise.DisguiseAPI; | import com.mojang.authlib.GameProfile; | ||||||
| import me.libraryaddict.disguise.DisguiseConfig; | import me.libraryaddict.disguise.DisguiseConfig; | ||||||
| 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.disguisetypes.PlayerDisguise; | import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; | ||||||
| import me.libraryaddict.disguise.utilities.DisguiseUtilities; | import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; | ||||||
|  | import org.bukkit.inventory.MainHand; | ||||||
|  |  | ||||||
| public class PlayerWatcher extends LivingWatcher { | public class PlayerWatcher extends LivingWatcher { | ||||||
|     private boolean alwaysShowInTab = DisguiseConfig.isShowDisguisedPlayersInTab(); |     private boolean alwaysShowInTab = DisguiseConfig.isShowDisguisedPlayersInTab(); | ||||||
| @@ -70,7 +62,7 @@ public class PlayerWatcher extends LivingWatcher { | |||||||
|         return isSkinFlag(1); |         return isSkinFlag(1); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isJackedEnabled() { |     public boolean isJacketEnabled() { | ||||||
|         return isSkinFlag(2); |         return isSkinFlag(2); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -136,10 +128,15 @@ public class PlayerWatcher extends LivingWatcher { | |||||||
|         sendData(MetaIndex.PLAYER_SKIN); |         sendData(MetaIndex.PLAYER_SKIN); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public WrappedGameProfile getSkin() { | ||||||
|  |         return ((PlayerDisguise) getDisguise()).getGameProfile(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public void setSkin(String playerName) { |     public void setSkin(String playerName) { | ||||||
|         ((PlayerDisguise) getDisguise()).setSkin(playerName); |         ((PlayerDisguise) getDisguise()).setSkin(playerName); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @RandomDefaultValue | ||||||
|     public void setSkin(WrappedGameProfile profile) { |     public void setSkin(WrappedGameProfile profile) { | ||||||
|         ((PlayerDisguise) getDisguise()).setSkin(profile); |         ((PlayerDisguise) getDisguise()).setSkin(profile); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -4,25 +4,22 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; | |||||||
| import me.libraryaddict.disguise.disguisetypes.MetaIndex; | import me.libraryaddict.disguise.disguisetypes.MetaIndex; | ||||||
| import me.libraryaddict.disguise.disguisetypes.RabbitType; | import me.libraryaddict.disguise.disguisetypes.RabbitType; | ||||||
| import me.libraryaddict.disguise.utilities.DisguiseUtilities; | import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||||
|  | import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; | ||||||
|  |  | ||||||
| public class RabbitWatcher extends AgeableWatcher | public class RabbitWatcher extends AgeableWatcher { | ||||||
| { |  | ||||||
|  |  | ||||||
|     public RabbitWatcher(Disguise disguise) |     public RabbitWatcher(Disguise disguise) { | ||||||
|     { |  | ||||||
|         super(disguise); |         super(disguise); | ||||||
|         setType(RabbitType.values()[DisguiseUtilities.random.nextInt(RabbitType.values().length)]); |         setType(RabbitType.values()[DisguiseUtilities.random.nextInt(RabbitType.values().length)]); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public RabbitType getType() |     public RabbitType getType() { | ||||||
|     { |  | ||||||
|         return RabbitType.getType(getData(MetaIndex.RABBIT_TYPE)); |         return RabbitType.getType(getData(MetaIndex.RABBIT_TYPE)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setType(RabbitType type) |     @RandomDefaultValue | ||||||
|     { |     public void setType(RabbitType type) { | ||||||
|         setData(MetaIndex.RABBIT_TYPE, type.getTypeId()); |         setData(MetaIndex.RABBIT_TYPE, type.getTypeId()); | ||||||
|         sendData(MetaIndex.RABBIT_TYPE); |         sendData(MetaIndex.RABBIT_TYPE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -11,8 +11,8 @@ public class SheepWatcher extends AgeableWatcher { | |||||||
|         super(disguise); |         super(disguise); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public AnimalColor getColor() { |     public DyeColor getColor() { | ||||||
|         return AnimalColor.getColorByWool(((int) getData(MetaIndex.SHEEP_WOOL) & 15)); |         return AnimalColor.getColorByWool(((int) getData(MetaIndex.SHEEP_WOOL) & 15)).getDyeColor(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isSheared() { |     public boolean isSheared() { | ||||||
|   | |||||||
| @@ -29,7 +29,7 @@ public class ShulkerWatcher extends InsentientWatcher { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public BlockPosition getAttachmentPosition() { |     public BlockPosition getAttachmentPosition() { | ||||||
|         return getData(MetaIndex.SHULKER_ATTACHED).get(); |         return getData(MetaIndex.SHULKER_ATTACHED).orElse(BlockPosition.ORIGIN); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setAttachmentPosition(BlockPosition pos) { |     public void setAttachmentPosition(BlockPosition pos) { | ||||||
| @@ -59,7 +59,7 @@ public class ShulkerWatcher extends InsentientWatcher { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setColor(DyeColor newColor) { |     public void setColor(DyeColor newColor) { | ||||||
|         if (newColor == getColor().getDyeColor()) { |         if (newColor == getColor()) { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -67,7 +67,11 @@ public class ShulkerWatcher extends InsentientWatcher { | |||||||
|         sendData(MetaIndex.SHULKER_COLOR); |         sendData(MetaIndex.SHULKER_COLOR); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public AnimalColor getColor() { |     public DyeColor getColor() { | ||||||
|         return AnimalColor.getColorByWool(getData(MetaIndex.SHULKER_COLOR)); |         if (!hasValue(MetaIndex.SHULKER_COLOR)) { | ||||||
|  |             return DyeColor.PURPLE; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return AnimalColor.getColorByWool(getData(MetaIndex.SHULKER_COLOR)).getDyeColor(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -3,11 +3,13 @@ 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.DisguiseUtilities; | import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||||
|  | import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; | ||||||
|  |  | ||||||
| public class SlimeWatcher extends InsentientWatcher { | public class SlimeWatcher extends InsentientWatcher { | ||||||
|  |  | ||||||
|     public SlimeWatcher(Disguise disguise) { |     public SlimeWatcher(Disguise disguise) { | ||||||
|         super(disguise); |         super(disguise); | ||||||
|  |  | ||||||
|         setSize(DisguiseUtilities.random.nextInt(4) + 1); |         setSize(DisguiseUtilities.random.nextInt(4) + 1); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -15,6 +17,7 @@ public class SlimeWatcher extends InsentientWatcher { | |||||||
|         return getData(MetaIndex.SLIME_SIZE); |         return getData(MetaIndex.SLIME_SIZE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @RandomDefaultValue | ||||||
|     public void setSize(int size) { |     public void setSize(int size) { | ||||||
|         if (size < 1) { |         if (size < 1) { | ||||||
|             size = 1; |             size = 1; | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; | |||||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||||
| import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | ||||||
| import me.libraryaddict.disguise.disguisetypes.MetaIndex; | import me.libraryaddict.disguise.disguisetypes.MetaIndex; | ||||||
|  | import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; | ||||||
| import org.bukkit.inventory.ItemStack; | import org.bukkit.inventory.ItemStack; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -21,6 +22,7 @@ public abstract class ThrowableWatcher extends FlagWatcher { | |||||||
|         return getData(MetaIndex.THROWABLE_ITEM); |         return getData(MetaIndex.THROWABLE_ITEM); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @RandomDefaultValue | ||||||
|     public void setItemStack(ItemStack item) { |     public void setItemStack(ItemStack item) { | ||||||
|         setData(MetaIndex.THROWABLE_ITEM, item); |         setData(MetaIndex.THROWABLE_ITEM, item); | ||||||
|         sendData(MetaIndex.THROWABLE_ITEM); |         sendData(MetaIndex.THROWABLE_ITEM); | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; | |||||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||||
| import me.libraryaddict.disguise.disguisetypes.DisguiseType; | import me.libraryaddict.disguise.disguisetypes.DisguiseType; | ||||||
| import me.libraryaddict.disguise.disguisetypes.MetaIndex; | import me.libraryaddict.disguise.disguisetypes.MetaIndex; | ||||||
|  | import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; | ||||||
| import org.apache.commons.lang.math.RandomUtils; | import org.apache.commons.lang.math.RandomUtils; | ||||||
| import org.bukkit.Color; | import org.bukkit.Color; | ||||||
|  |  | ||||||
| @@ -20,10 +21,15 @@ public class TippedArrowWatcher extends ArrowWatcher { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public Color getColor() { |     public Color getColor() { | ||||||
|  |         if (!hasValue(MetaIndex.TIPPED_ARROW_COLOR)) { | ||||||
|  |             return Color.GRAY; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         int color = getData(MetaIndex.TIPPED_ARROW_COLOR); |         int color = getData(MetaIndex.TIPPED_ARROW_COLOR); | ||||||
|         return Color.fromRGB(color); |         return Color.fromRGB(color); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @RandomDefaultValue | ||||||
|     public void setColor(Color color) { |     public void setColor(Color color) { | ||||||
|         setData(MetaIndex.TIPPED_ARROW_COLOR, color.asRGB()); |         setData(MetaIndex.TIPPED_ARROW_COLOR, color.asRGB()); | ||||||
|         sendData(MetaIndex.TIPPED_ARROW_COLOR); |         sendData(MetaIndex.TIPPED_ARROW_COLOR); | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ 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.parser.RandomDefaultValue; | ||||||
| import org.bukkit.DyeColor; | import org.bukkit.DyeColor; | ||||||
| import org.bukkit.entity.TropicalFish; | import org.bukkit.entity.TropicalFish; | ||||||
|  |  | ||||||
| @@ -71,6 +72,7 @@ public class TropicalFishWatcher extends FishWatcher { | |||||||
|         return DyeColor.getByWoolData((byte) (getVariant() >> 24 & 0xFF)); |         return DyeColor.getByWoolData((byte) (getVariant() >> 24 & 0xFF)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @RandomDefaultValue | ||||||
|     public void setPatternColor(DyeColor dyeColor) { |     public void setPatternColor(DyeColor dyeColor) { | ||||||
|         setVariant(getData(dyeColor, getBodyColor(), getPattern())); |         setVariant(getData(dyeColor, getBodyColor(), getPattern())); | ||||||
|     } |     } | ||||||
| @@ -84,6 +86,7 @@ public class TropicalFishWatcher extends FishWatcher { | |||||||
|         return DyeColor.getByWoolData((byte) (getVariant() >> 16 & 0xFF)); |         return DyeColor.getByWoolData((byte) (getVariant() >> 16 & 0xFF)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @RandomDefaultValue | ||||||
|     public void setBodyColor(DyeColor dyeColor) { |     public void setBodyColor(DyeColor dyeColor) { | ||||||
|         setVariant(getData(dyeColor, dyeColor, getPattern())); |         setVariant(getData(dyeColor, dyeColor, getPattern())); | ||||||
|     } |     } | ||||||
| @@ -92,6 +95,7 @@ public class TropicalFishWatcher extends FishWatcher { | |||||||
|         return CraftPattern.fromData(getVariant() & 0xFFFF); |         return CraftPattern.fromData(getVariant() & 0xFFFF); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @RandomDefaultValue | ||||||
|     public void setPattern(TropicalFish.Pattern pattern) { |     public void setPattern(TropicalFish.Pattern pattern) { | ||||||
|         setVariant(getData(getPatternColor(), getBodyColor(), pattern)); |         setVariant(getData(getPatternColor(), getBodyColor(), pattern)); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; | |||||||
| import me.libraryaddict.disguise.disguisetypes.MetaIndex; | import me.libraryaddict.disguise.disguisetypes.MetaIndex; | ||||||
| import me.libraryaddict.disguise.disguisetypes.VillagerData; | import me.libraryaddict.disguise.disguisetypes.VillagerData; | ||||||
| import me.libraryaddict.disguise.utilities.DisguiseUtilities; | import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||||
|  | import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; | ||||||
| import org.bukkit.entity.Villager; | import org.bukkit.entity.Villager; | ||||||
| import org.bukkit.entity.Villager.Profession; | import org.bukkit.entity.Villager.Profession; | ||||||
|  |  | ||||||
| @@ -45,6 +46,7 @@ public class VillagerWatcher extends AbstractVillagerWatcher { | |||||||
|         return getVillagerData().getLevel(); |         return getVillagerData().getLevel(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @RandomDefaultValue | ||||||
|     public void setProfession(Profession profession) { |     public void setProfession(Profession profession) { | ||||||
|         setVillagerData(new VillagerData(getType(), profession, getLevel())); |         setVillagerData(new VillagerData(getType(), profession, getLevel())); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -11,8 +11,8 @@ public class WolfWatcher extends TameableWatcher { | |||||||
|         super(disguise); |         super(disguise); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public AnimalColor getCollarColor() { |     public DyeColor getCollarColor() { | ||||||
|         return AnimalColor.getColorByWool(getData(MetaIndex.WOLF_COLLAR)); |         return AnimalColor.getColorByWool(getData(MetaIndex.WOLF_COLLAR)).getDyeColor(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isBegging() { |     public boolean isBegging() { | ||||||
| @@ -42,7 +42,7 @@ public class WolfWatcher extends TameableWatcher { | |||||||
|             setTamed(true); |             setTamed(true); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (newColor == getCollarColor().getDyeColor()) { |         if (newColor == getCollarColor()) { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ 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.disguisetypes.VillagerData; | import me.libraryaddict.disguise.disguisetypes.VillagerData; | ||||||
|  | import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; | ||||||
| import org.bukkit.entity.Villager; | import org.bukkit.entity.Villager; | ||||||
| import org.bukkit.entity.Villager.Profession; | import org.bukkit.entity.Villager.Profession; | ||||||
|  |  | ||||||
| @@ -55,6 +56,7 @@ public class ZombieVillagerWatcher extends ZombieWatcher { | |||||||
|         return getVillagerData().getLevel(); |         return getVillagerData().getLevel(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @RandomDefaultValue | ||||||
|     public void setProfession(Profession profession) { |     public void setProfession(Profession profession) { | ||||||
|         setVillagerData(new VillagerData(getType(), profession, getLevel())); |         setVillagerData(new VillagerData(getType(), profession, getLevel())); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -1,15 +1,13 @@ | |||||||
| package me.libraryaddict.disguise.utilities; | package me.libraryaddict.disguise.utilities; | ||||||
|  |  | ||||||
| import com.comphenix.protocol.PacketType; |  | ||||||
| import com.comphenix.protocol.PacketType.Play.Server; | import com.comphenix.protocol.PacketType.Play.Server; | ||||||
| import com.comphenix.protocol.ProtocolLibrary; | import com.comphenix.protocol.ProtocolLibrary; | ||||||
| import com.comphenix.protocol.ProtocolManager; | import com.comphenix.protocol.ProtocolManager; | ||||||
| import com.comphenix.protocol.events.PacketContainer; | import com.comphenix.protocol.events.PacketContainer; | ||||||
| import com.comphenix.protocol.reflect.StructureModifier; |  | ||||||
| import com.comphenix.protocol.wrappers.*; | import com.comphenix.protocol.wrappers.*; | ||||||
| import com.google.common.collect.ConcurrentHashMultiset; |  | ||||||
| import com.google.gson.Gson; | import com.google.gson.Gson; | ||||||
| import com.google.gson.GsonBuilder; | import com.google.gson.GsonBuilder; | ||||||
|  | import com.google.gson.JsonSyntaxException; | ||||||
| import com.mojang.authlib.properties.PropertyMap; | import com.mojang.authlib.properties.PropertyMap; | ||||||
| import me.libraryaddict.disguise.DisguiseAPI; | import me.libraryaddict.disguise.DisguiseAPI; | ||||||
| import me.libraryaddict.disguise.DisguiseConfig; | import me.libraryaddict.disguise.DisguiseConfig; | ||||||
| @@ -18,7 +16,6 @@ import me.libraryaddict.disguise.LibsDisguises; | |||||||
| import me.libraryaddict.disguise.disguisetypes.*; | import me.libraryaddict.disguise.disguisetypes.*; | ||||||
| import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType; | import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType; | ||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; | import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; | ||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; |  | ||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; | import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; | ||||||
| import me.libraryaddict.disguise.utilities.json.*; | import me.libraryaddict.disguise.utilities.json.*; | ||||||
| import me.libraryaddict.disguise.utilities.packets.LibsPackets; | import me.libraryaddict.disguise.utilities.packets.LibsPackets; | ||||||
| @@ -29,8 +26,10 @@ import me.libraryaddict.disguise.utilities.reflection.LibsProfileLookup; | |||||||
| import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; | import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; | ||||||
| import me.libraryaddict.disguise.utilities.translations.LibsMsg; | import me.libraryaddict.disguise.utilities.translations.LibsMsg; | ||||||
| import org.apache.logging.log4j.util.Strings; | import org.apache.logging.log4j.util.Strings; | ||||||
| import org.bukkit.*; | import org.bukkit.Bukkit; | ||||||
| import org.bukkit.block.BlockFace; | import org.bukkit.Location; | ||||||
|  | import org.bukkit.Material; | ||||||
|  | import org.bukkit.World; | ||||||
| import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils; | import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils; | ||||||
| import org.bukkit.entity.*; | import org.bukkit.entity.*; | ||||||
| import org.bukkit.inventory.EquipmentSlot; | import org.bukkit.inventory.EquipmentSlot; | ||||||
| @@ -600,6 +599,12 @@ public class DisguiseUtilities { | |||||||
|  |  | ||||||
|             return gson.fromJson(cached, WrappedGameProfile.class); |             return gson.fromJson(cached, WrappedGameProfile.class); | ||||||
|         } |         } | ||||||
|  |         catch (JsonSyntaxException ex) { | ||||||
|  |             DisguiseUtilities.getLogger() | ||||||
|  |                     .warning("Gameprofile " + file.getName() + " had invalid gson and has been deleted"); | ||||||
|  |             cachedNames.remove(playerName.toLowerCase()); | ||||||
|  |             file.delete(); | ||||||
|  |         } | ||||||
|         catch (Exception e) { |         catch (Exception e) { | ||||||
|             e.printStackTrace(); |             e.printStackTrace(); | ||||||
|         } |         } | ||||||
| @@ -705,8 +710,14 @@ public class DisguiseUtilities { | |||||||
|         final String playerName = origName.toLowerCase(); |         final String playerName = origName.toLowerCase(); | ||||||
|  |  | ||||||
|         if (DisguiseConfig.isSaveGameProfiles() && hasGameProfile(playerName)) { |         if (DisguiseConfig.isSaveGameProfiles() && hasGameProfile(playerName)) { | ||||||
|             return getGameProfile(playerName); |             WrappedGameProfile profile = getGameProfile(playerName); | ||||||
|         } else if (Pattern.matches("([A-Za-z0-9_]){1,16}", origName)) { |  | ||||||
|  |             if (profile != null) { | ||||||
|  |                 return profile; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (Pattern.matches("([A-Za-z0-9_]){1,16}", origName)) { | ||||||
|             final Player player = Bukkit.getPlayerExact(playerName); |             final Player player = Bukkit.getPlayerExact(playerName); | ||||||
|  |  | ||||||
|             if (player != null) { |             if (player != null) { | ||||||
|   | |||||||
| @@ -182,17 +182,19 @@ public class PacketListenerClientInteract extends PacketAdapter { | |||||||
|                     if (disguise.getType() == DisguiseType.SHEEP) { |                     if (disguise.getType() == DisguiseType.SHEEP) { | ||||||
|                         SheepWatcher watcher = (SheepWatcher) disguise.getWatcher(); |                         SheepWatcher watcher = (SheepWatcher) disguise.getWatcher(); | ||||||
|  |  | ||||||
|                         watcher.setColor(DisguiseConfig.isSheepDyeable() ? color : watcher.getColor()); |                         watcher.setColor(DisguiseConfig.isSheepDyeable() ? color.getDyeColor() : watcher.getColor()); | ||||||
|                         break; |                         break; | ||||||
|                     } else if (disguise.getType() == DisguiseType.WOLF) { |                     } else if (disguise.getType() == DisguiseType.WOLF) { | ||||||
|                         WolfWatcher watcher = (WolfWatcher) disguise.getWatcher(); |                         WolfWatcher watcher = (WolfWatcher) disguise.getWatcher(); | ||||||
|  |  | ||||||
|                         watcher.setCollarColor(DisguiseConfig.isWolfDyeable() ? color : watcher.getCollarColor()); |                         watcher.setCollarColor( | ||||||
|  |                                 DisguiseConfig.isWolfDyeable() ? color.getDyeColor() : watcher.getCollarColor()); | ||||||
|                         break; |                         break; | ||||||
|                     } else if (disguise.getType() == DisguiseType.CAT) { |                     } else if (disguise.getType() == DisguiseType.CAT) { | ||||||
|                         CatWatcher watcher = (CatWatcher) disguise.getWatcher(); |                         CatWatcher watcher = (CatWatcher) disguise.getWatcher(); | ||||||
|  |  | ||||||
|                         watcher.setCollarColor(DisguiseConfig.isCatDyeable() ? color : watcher.getCollarColor()); |                         watcher.setCollarColor( | ||||||
|  |                                 DisguiseConfig.isCatDyeable() ? color.getDyeColor() : watcher.getCollarColor()); | ||||||
|                         break; |                         break; | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| package me.libraryaddict.disguise.utilities.parser; | package me.libraryaddict.disguise.utilities.parser; | ||||||
|  |  | ||||||
| import com.comphenix.protocol.wrappers.WrappedGameProfile; | import com.comphenix.protocol.wrappers.WrappedGameProfile; | ||||||
|  | import com.google.gson.Gson; | ||||||
| import me.libraryaddict.disguise.DisguiseConfig; | import me.libraryaddict.disguise.DisguiseConfig; | ||||||
| import me.libraryaddict.disguise.disguisetypes.*; | import me.libraryaddict.disguise.disguisetypes.*; | ||||||
| import me.libraryaddict.disguise.utilities.DisguiseUtilities; | import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||||
| @@ -17,6 +18,7 @@ import org.bukkit.entity.Entity; | |||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
| import org.bukkit.inventory.ItemStack; | import org.bukkit.inventory.ItemStack; | ||||||
| import org.bukkit.permissions.PermissionAttachmentInfo; | import org.bukkit.permissions.PermissionAttachmentInfo; | ||||||
|  | import org.bukkit.potion.PotionEffectType; | ||||||
|  |  | ||||||
| import java.lang.reflect.InvocationTargetException; | import java.lang.reflect.InvocationTargetException; | ||||||
| import java.lang.reflect.Method; | import java.lang.reflect.Method; | ||||||
| @@ -25,6 +27,185 @@ import java.util.Map.Entry; | |||||||
| import java.util.concurrent.TimeUnit; | import java.util.concurrent.TimeUnit; | ||||||
|  |  | ||||||
| public class DisguiseParser { | public class DisguiseParser { | ||||||
|  |     private static HashMap<Method, Map.Entry<Method, Object>> defaultWatcherValues = new HashMap<>(); | ||||||
|  |  | ||||||
|  |     public static void createDefaultMethods() { | ||||||
|  |         try { | ||||||
|  |             for (DisguiseType type : DisguiseType.values()) { | ||||||
|  |                 Disguise disguise; | ||||||
|  |  | ||||||
|  |                 if (type.isMisc()) { | ||||||
|  |                     disguise = new MiscDisguise(type); | ||||||
|  |                 } else if (type.isMob()) { | ||||||
|  |                     disguise = new MobDisguise(type); | ||||||
|  |                 } else { | ||||||
|  |                     disguise = new PlayerDisguise("Foobar"); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 FlagWatcher watcher = type.getWatcherClass().getConstructor(Disguise.class).newInstance(disguise); | ||||||
|  |  | ||||||
|  |                 Method[] methods = ParamInfoManager.getDisguiseWatcherMethods(watcher.getClass()); | ||||||
|  |  | ||||||
|  |                 for (Method setMethod : methods) { | ||||||
|  |                     // Invalidate methods that can't be handled normally | ||||||
|  |                     if (setMethod.getName().equals("addPotionEffect") || (setMethod.getName().equals("setSkin") && | ||||||
|  |                             setMethod.getParameterTypes()[0] == String.class) || | ||||||
|  |                             (setMethod.getName().equals("setTarget") && | ||||||
|  |                                     setMethod.getParameterTypes()[0] != int.class) || | ||||||
|  |                             (setMethod.getName().equals("setItemInMainHand") && | ||||||
|  |                                     setMethod.getParameterTypes()[0] == Material.class)) { | ||||||
|  |                         continue; | ||||||
|  |                     } | ||||||
|  |  | ||||||
|  |                     String getName = setMethod.getName().substring(3); // Remove 'set' | ||||||
|  |  | ||||||
|  |                     if (getName.equals("HasNectar")) { | ||||||
|  |                         getName = "hasNectar"; | ||||||
|  |                     } else if (getName.equals("HasStung")) { | ||||||
|  |                         getName = "hasStung"; | ||||||
|  |                     } else if (setMethod.getParameterTypes()[0].isAssignableFrom(boolean.class)) { | ||||||
|  |                         getName = "is" + getName; | ||||||
|  |                     } else { | ||||||
|  |                         getName = "get" + getName; | ||||||
|  |                     } | ||||||
|  |  | ||||||
|  |                     Method getMethod = null; | ||||||
|  |  | ||||||
|  |                     for (Method m : setMethod.getDeclaringClass().getDeclaredMethods()) { | ||||||
|  |                         if (!m.getName().equals(getName)) { | ||||||
|  |                             continue; | ||||||
|  |                         } | ||||||
|  |  | ||||||
|  |                         if (m.getParameterTypes().length > 0 || m.getReturnType() != setMethod.getParameterTypes()[0]) { | ||||||
|  |                             continue; | ||||||
|  |                         } | ||||||
|  |  | ||||||
|  |                         getMethod = m; | ||||||
|  |                         break; | ||||||
|  |                     } | ||||||
|  |  | ||||||
|  |                     if (getMethod == null) { | ||||||
|  |                         DisguiseUtilities.getLogger().severe(String | ||||||
|  |                                 .format("No such method '%s' when looking for the companion of '%s' in '%s'", getName, | ||||||
|  |                                         setMethod.getName(), setMethod.getDeclaringClass().getSimpleName())); | ||||||
|  |                         continue; | ||||||
|  |                     } | ||||||
|  |  | ||||||
|  |                     Object defaultValue = null; | ||||||
|  |  | ||||||
|  |                     // Value is randomish so shouldn't be checked, should always specify value when setting | ||||||
|  |                     if (!setMethod.isAnnotationPresent(RandomDefaultValue.class)) { | ||||||
|  |                         Object invokeWith = watcher; | ||||||
|  |  | ||||||
|  |                         if (!FlagWatcher.class.isAssignableFrom(getMethod.getDeclaringClass())) { | ||||||
|  |                             invokeWith = disguise; | ||||||
|  |                         } | ||||||
|  |  | ||||||
|  |                         defaultValue = getMethod.invoke(invokeWith); | ||||||
|  |                     } | ||||||
|  |  | ||||||
|  |                     addWatcherDefault(setMethod, getMethod, defaultValue); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { | ||||||
|  |             e.printStackTrace(); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static String parseToString(Disguise disguise) { | ||||||
|  |         try { | ||||||
|  |             StringBuilder stringBuilder = new StringBuilder(); | ||||||
|  |  | ||||||
|  |             stringBuilder.append(disguise.getType().name()); | ||||||
|  |  | ||||||
|  |             if (disguise.isPlayerDisguise()) { | ||||||
|  |                 stringBuilder.append(" ").append(((PlayerDisguise) disguise).getName()); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             for (Method m : ParamInfoManager.getDisguiseWatcherMethods(disguise.getType().getWatcherClass())) { | ||||||
|  |                 // Special handling for this method | ||||||
|  |                 if (m.getName().equals("addPotionEffect")) { | ||||||
|  |                     PotionEffectType[] types = (PotionEffectType[]) m.getDeclaringClass().getMethod("getPotionEffects") | ||||||
|  |                             .invoke(disguise.getWatcher()); | ||||||
|  |  | ||||||
|  |                     for (PotionEffectType type : types) { | ||||||
|  |                         if (type == null) { | ||||||
|  |                             continue; | ||||||
|  |                         } | ||||||
|  |  | ||||||
|  |                         stringBuilder.append(" ").append(m.getName()).append(" ").append(type.getName()); | ||||||
|  |                     } | ||||||
|  |                 } else { | ||||||
|  |                     Entry<Method, Object> entry = defaultWatcherValues.get(m); | ||||||
|  |  | ||||||
|  |                     if (entry == null) { | ||||||
|  |                         continue; | ||||||
|  |                     } | ||||||
|  |  | ||||||
|  |                     Object invokeWith = m.getDeclaringClass().isInstance(disguise) ? disguise : disguise.getWatcher(); | ||||||
|  |  | ||||||
|  |                     Object ourValue = entry.getKey().invoke(invokeWith); | ||||||
|  |  | ||||||
|  |                     // Escape a hacky fix for custom names, disguised players with custom names don't want to show it | ||||||
|  |                     // so it was set to an empty string. | ||||||
|  |                     if ("".equals(ourValue) && m.getName().equals("setCustomName")) { | ||||||
|  |                         ourValue = null; | ||||||
|  |                     } | ||||||
|  |  | ||||||
|  |                     // If its the same as default, continue | ||||||
|  |                     if (!m.isAnnotationPresent(RandomDefaultValue.class) && | ||||||
|  |                             Objects.deepEquals(entry.getValue(), ourValue)) { | ||||||
|  |                         continue; | ||||||
|  |                     } | ||||||
|  |  | ||||||
|  |                     stringBuilder.append(" ").append(m.getName()); | ||||||
|  |  | ||||||
|  |                     if (ourValue instanceof Boolean && (Boolean) ourValue) { | ||||||
|  |                         continue; | ||||||
|  |                     } | ||||||
|  |  | ||||||
|  |                     String valueString; | ||||||
|  |  | ||||||
|  |                     if (ourValue != null) { | ||||||
|  |                         valueString = ParamInfoManager.getParamInfo(ourValue.getClass()).toString(ourValue); | ||||||
|  |  | ||||||
|  |                         if (valueString.contains(" ") || valueString.contains("\"")) { | ||||||
|  |                             valueString = "\"" + valueString.replace("\\", "\\\\").replace("\"", "\\\"") + "\""; | ||||||
|  |                         } | ||||||
|  |                     } else { | ||||||
|  |                         valueString = "null"; | ||||||
|  |                     } | ||||||
|  |  | ||||||
|  |                     stringBuilder.append(" ").append(valueString); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             return stringBuilder.toString(); | ||||||
|  |         } | ||||||
|  |         catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { | ||||||
|  |             e.printStackTrace(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     private static void addWatcherDefault(Method setMethod, Method getMethod, Object object) { | ||||||
|  |         Map.Entry<Method, Object> entry = new HashMap.SimpleEntry<>(getMethod, object); | ||||||
|  |  | ||||||
|  |         if (defaultWatcherValues.containsKey(setMethod)) { | ||||||
|  |             Object dObj = defaultWatcherValues.get(setMethod); | ||||||
|  |  | ||||||
|  |             if (!Objects.deepEquals(defaultWatcherValues.get(setMethod).getValue(), object)) { | ||||||
|  |                 throw new IllegalStateException(String.format("%s has conflicting values!", setMethod.getName())); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         defaultWatcherValues.put(setMethod, entry); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     private static void doCheck(CommandSender sender, DisguisePermissions permissions, DisguisePerm disguisePerm, |     private static void doCheck(CommandSender sender, DisguisePermissions permissions, DisguisePerm disguisePerm, | ||||||
|             Collection<String> usedOptions) throws DisguiseParseException { |             Collection<String> usedOptions) throws DisguiseParseException { | ||||||
|  |  | ||||||
|   | |||||||
| @@ -0,0 +1,14 @@ | |||||||
|  | package me.libraryaddict.disguise.utilities.parser; | ||||||
|  |  | ||||||
|  | import java.lang.annotation.ElementType; | ||||||
|  | import java.lang.annotation.Retention; | ||||||
|  | import java.lang.annotation.RetentionPolicy; | ||||||
|  | import java.lang.annotation.Target; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Created by libraryaddict on 31/12/2019. | ||||||
|  |  */ | ||||||
|  | @Retention(RetentionPolicy.RUNTIME) | ||||||
|  | @Target(ElementType.METHOD) | ||||||
|  | public @interface RandomDefaultValue { | ||||||
|  | } | ||||||
| @@ -77,6 +77,8 @@ public abstract class ParamInfo { | |||||||
|  |  | ||||||
|     protected abstract Object fromString(String string) throws DisguiseParseException; |     protected abstract Object fromString(String string) throws DisguiseParseException; | ||||||
|  |  | ||||||
|  |     public abstract String toString(Object object); | ||||||
|  |  | ||||||
|     public Object fromString(List<String> arguments) throws DisguiseParseException { |     public Object fromString(List<String> arguments) throws DisguiseParseException { | ||||||
|         // Don't consume a string immediately, if it errors we need to check other param types |         // Don't consume a string immediately, if it errors we need to check other param types | ||||||
|         String string = arguments.get(0); |         String string = arguments.get(0); | ||||||
| @@ -101,7 +103,7 @@ public abstract class ParamInfo { | |||||||
|         return getValues() != null; |         return getValues() != null; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private Class getParamClass() { |     protected Class getParamClass() { | ||||||
|         return paramClass; |         return paramClass; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -105,8 +105,8 @@ public class ParamInfoManager { | |||||||
|         }); |         }); | ||||||
|  |  | ||||||
|         // Add these last as it's what we want to present to be called the least |         // Add these last as it's what we want to present to be called the least | ||||||
|         for (String methodName : new String[]{"setViewSelfDisguise", "setHideHeldItemFromSelf", "setHideArmorFromSelf", |         for (String methodName : new String[]{"setSelfDisguiseVisible", "setHideHeldItemFromSelf", | ||||||
|                 "setHearSelfDisguise", "setHidePlayer", "setExpires"}) { |                 "setHideArmorFromSelf", "setHearSelfDisguise", "setHidePlayer", "setExpires"}) { | ||||||
|             try { |             try { | ||||||
|                 methods.add(Disguise.class |                 methods.add(Disguise.class | ||||||
|                         .getMethod(methodName, methodName.equals("setExpires") ? long.class : boolean.class)); |                         .getMethod(methodName, methodName.equals("setExpires") ? long.class : boolean.class)); | ||||||
|   | |||||||
| @@ -107,9 +107,9 @@ public class ParamInfoTypes { | |||||||
|         return paramInfos; |         return paramInfos; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private Map<String, Object> getColors() { |     private Map<String, Color> getColors() { | ||||||
|         try { |         try { | ||||||
|             Map<String, Object> map = new HashMap<>(); |             Map<String, Color> map = new HashMap<>(); | ||||||
|             Class cl = Class.forName("org.bukkit.Color"); |             Class cl = Class.forName("org.bukkit.Color"); | ||||||
|  |  | ||||||
|             for (Field field : cl.getFields()) { |             for (Field field : cl.getFields()) { | ||||||
| @@ -117,7 +117,7 @@ public class ParamInfoTypes { | |||||||
|                     continue; |                     continue; | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 map.put(field.getName(), field.get(null)); |                 map.put(field.getName(), (Color) field.get(null)); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             return map; |             return map; | ||||||
|   | |||||||
| @@ -21,7 +21,7 @@ public class ParamInfoEnum extends ParamInfo { | |||||||
|         super(paramClass, name, name, description, possibleValues); |         super(paramClass, name, name, description, possibleValues); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public ParamInfoEnum(Class paramClass, String name, String description, Map<String,Object> possibleValues) { |     public ParamInfoEnum(Class paramClass, String name, String description, Map<String, Object> possibleValues) { | ||||||
|         super(paramClass, name, name, description, possibleValues); |         super(paramClass, name, name, description, possibleValues); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -39,4 +39,9 @@ public class ParamInfoEnum extends ParamInfo { | |||||||
|  |  | ||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public String toString(Object object) { | ||||||
|  |         return object.toString(); | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -42,6 +42,11 @@ public class ParamInfoBoolean extends ParamInfo { | |||||||
|         throw new IllegalStateException("This shouldn't be called"); |         throw new IllegalStateException("This shouldn't be called"); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public String toString(Object object) { | ||||||
|  |         return object.toString(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public int getMinArguments() { |     public int getMinArguments() { | ||||||
|         return 0; |         return 0; | ||||||
|   | |||||||
| @@ -19,4 +19,9 @@ public class ParamInfoDouble extends ParamInfo { | |||||||
|     protected Object fromString(String string) { |     protected Object fromString(String string) { | ||||||
|         return Double.parseDouble(string); |         return Double.parseDouble(string); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public String toString(Object object) { | ||||||
|  |         return object.toString(); | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -19,4 +19,9 @@ public class ParamInfoFloat extends ParamInfo { | |||||||
|     protected Object fromString(String string) { |     protected Object fromString(String string) { | ||||||
|         return Float.parseFloat(string); |         return Float.parseFloat(string); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public String toString(Object object) { | ||||||
|  |         return object.toString(); | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -19,4 +19,9 @@ public class ParamInfoInteger extends ParamInfo { | |||||||
|     protected Object fromString(String string) { |     protected Object fromString(String string) { | ||||||
|         return Integer.parseInt(string); |         return Integer.parseInt(string); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public String toString(Object object) { | ||||||
|  |         return object.toString(); | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -15,4 +15,9 @@ public class ParamInfoString extends ParamInfo { | |||||||
|     protected Object fromString(String string) { |     protected Object fromString(String string) { | ||||||
|         return ChatColor.translateAlternateColorCodes('&', string); |         return ChatColor.translateAlternateColorCodes('&', string); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public String toString(Object object) { | ||||||
|  |         return object.toString(); | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -21,4 +21,11 @@ public class ParamInfoBlockPosition extends ParamInfo { | |||||||
|  |  | ||||||
|         return new BlockPosition(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])); |         return new BlockPosition(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public String toString(Object object) { | ||||||
|  |         BlockPosition position = (BlockPosition) object; | ||||||
|  |  | ||||||
|  |         return String.format("%s,%s,%s", position.getX(), position.getY(), position.getZ()); | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -9,23 +9,23 @@ import java.util.Map; | |||||||
|  * Created by libraryaddict on 19/09/2018. |  * Created by libraryaddict on 19/09/2018. | ||||||
|  */ |  */ | ||||||
| public class ParamInfoColor extends ParamInfoEnum { | public class ParamInfoColor extends ParamInfoEnum { | ||||||
|     private static Map<String, Object> staticColors; |     private static Map<String, Color> staticColors; | ||||||
|  |  | ||||||
|     public ParamInfoColor(Class paramClass, String name, String description, Map<String, Object> possibleValues) { |     public ParamInfoColor(Class paramClass, String name, String description, Map possibleValues) { | ||||||
|         super(paramClass, name, description, possibleValues); |         super(paramClass, name, description, possibleValues); | ||||||
|  |  | ||||||
|         staticColors = possibleValues; |         staticColors = (Map<String, Color>) possibleValues; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     protected static Color parseToColor(String string) { |     protected Color parseToColor(String string) { | ||||||
|         string = string.replace("_", ""); |         string = string.replace("_", ""); | ||||||
|  |  | ||||||
|         for (Map.Entry<String, Object> entry : staticColors.entrySet()) { |         for (Map.Entry<String, Color> entry : staticColors.entrySet()) { | ||||||
|             if (!entry.getKey().replace("_", "").equalsIgnoreCase(string)) { |             if (!entry.getKey().replace("_", "").equalsIgnoreCase(string)) { | ||||||
|                 continue; |                 continue; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             return (Color) entry.getValue(); |             return entry.getValue(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         String[] split = string.split(","); |         String[] split = string.split(","); | ||||||
| @@ -39,6 +39,23 @@ public class ParamInfoColor extends ParamInfoEnum { | |||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public String toString(Object object) { | ||||||
|  |         Color color = (Color) object; | ||||||
|  |  | ||||||
|  |         if (staticColors.containsValue(color)) { | ||||||
|  |             for (String key : staticColors.keySet()) { | ||||||
|  |                 if (staticColors.get(key) != color) { | ||||||
|  |                     continue; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 return key; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return String.format("%s,%s,%s", color.getRed(), color.getGreen(), color.getBlue()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     protected Object fromString(String string) { |     protected Object fromString(String string) { | ||||||
|         return parseToColor(string); |         return parseToColor(string); | ||||||
|   | |||||||
| @@ -21,4 +21,11 @@ public class ParamInfoEulerAngle extends ParamInfo { | |||||||
|  |  | ||||||
|         return new EulerAngle(Double.parseDouble(split[0]), Double.parseDouble(split[1]), Double.parseDouble(split[2])); |         return new EulerAngle(Double.parseDouble(split[0]), Double.parseDouble(split[1]), Double.parseDouble(split[2])); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public String toString(Object object) { | ||||||
|  |         EulerAngle angle = (EulerAngle) object; | ||||||
|  |  | ||||||
|  |         return String.format("%s,%s,%s", angle.getX(), angle.getY(), angle.getZ()); | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,11 +1,11 @@ | |||||||
| package me.libraryaddict.disguise.utilities.parser.params.types.custom; | package me.libraryaddict.disguise.utilities.parser.params.types.custom; | ||||||
|  |  | ||||||
| import com.comphenix.protocol.wrappers.WrappedGameProfile; | import com.comphenix.protocol.wrappers.WrappedGameProfile; | ||||||
|  | import com.google.gson.Gson; | ||||||
|  | import com.mojang.authlib.GameProfile; | ||||||
| import me.libraryaddict.disguise.utilities.DisguiseUtilities; | import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||||
| import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; | import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; | ||||||
|  |  | ||||||
| import java.lang.reflect.Method; |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Created by libraryaddict on 7/09/2018. |  * Created by libraryaddict on 7/09/2018. | ||||||
|  */ |  */ | ||||||
| @@ -15,7 +15,12 @@ public class ParamInfoGameProfile extends ParamInfo { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     protected Object fromString( String string) { |     protected Object fromString(String string) { | ||||||
|         return DisguiseUtilities.getGson().fromJson(string, WrappedGameProfile.class); |         return DisguiseUtilities.getGson().fromJson(string, WrappedGameProfile.class); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public String toString(Object object) { | ||||||
|  |         return DisguiseUtilities.getGson().toJson(((WrappedGameProfile) object).getHandle(), GameProfile.class); | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,10 +1,12 @@ | |||||||
| package me.libraryaddict.disguise.utilities.parser.params.types.custom; | package me.libraryaddict.disguise.utilities.parser.params.types.custom; | ||||||
|  |  | ||||||
|  | import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||||
| import me.libraryaddict.disguise.utilities.translations.TranslateType; | import me.libraryaddict.disguise.utilities.translations.TranslateType; | ||||||
| import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum; | import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum; | ||||||
| import org.bukkit.Material; | import org.bukkit.Material; | ||||||
| import org.bukkit.enchantments.Enchantment; | import org.bukkit.enchantments.Enchantment; | ||||||
| import org.bukkit.inventory.ItemStack; | import org.bukkit.inventory.ItemStack; | ||||||
|  | import org.bukkit.inventory.meta.ItemMeta; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Created by libraryaddict on 7/09/2018. |  * Created by libraryaddict on 7/09/2018. | ||||||
| @@ -32,7 +34,20 @@ public class ParamInfoItemStack extends ParamInfoEnum { | |||||||
|         return parseToItemstack(string); |         return parseToItemstack(string); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public String toString(Object object) { | ||||||
|  |         return DisguiseUtilities.getGson().toJson(object); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     protected static ItemStack parseToItemstack(String string) { |     protected static ItemStack parseToItemstack(String string) { | ||||||
|  |         if (string.startsWith("{") && string.endsWith("}")) { | ||||||
|  |             try { | ||||||
|  |                 return DisguiseUtilities.getGson().fromJson(string, ItemStack.class); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) { | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|         return parseToItemstack(string.split("[:,]")); // Split on colon or comma |         return parseToItemstack(string.split("[:,]")); // Split on colon or comma | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -70,4 +85,8 @@ public class ParamInfoItemStack extends ParamInfoEnum { | |||||||
|  |  | ||||||
|         return itemStack; |         return itemStack; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public boolean isParam(Class paramClass) { | ||||||
|  |         return getParamClass().isAssignableFrom(paramClass); | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| package me.libraryaddict.disguise.utilities.parser.params.types.custom; | package me.libraryaddict.disguise.utilities.parser.params.types.custom; | ||||||
|  |  | ||||||
|  | import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||||
| import org.bukkit.inventory.ItemStack; | import org.bukkit.inventory.ItemStack; | ||||||
|  |  | ||||||
| import java.util.LinkedHashSet; | import java.util.LinkedHashSet; | ||||||
| @@ -36,8 +37,21 @@ public class ParamInfoItemStackArray extends ParamInfoItemStack { | |||||||
|         return toReturn; |         return toReturn; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public String toString(Object object) { | ||||||
|  |         return DisguiseUtilities.getGson().toJson(object); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public Object fromString(String string) { |     public Object fromString(String string) { | ||||||
|  |         if (string.startsWith("{") && string.endsWith("}")) { | ||||||
|  |             try { | ||||||
|  |                 return DisguiseUtilities.getGson().fromJson(string, ItemStack[].class); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) { | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|         String[] split = string.split(",", -1); |         String[] split = string.split(",", -1); | ||||||
|  |  | ||||||
|         if (split.length != 4) { |         if (split.length != 4) { | ||||||
|   | |||||||
| @@ -2,13 +2,15 @@ package me.libraryaddict.disguise.utilities.parser.params.types.custom; | |||||||
|  |  | ||||||
| import com.comphenix.protocol.wrappers.WrappedBlockData; | import com.comphenix.protocol.wrappers.WrappedBlockData; | ||||||
| import com.comphenix.protocol.wrappers.WrappedParticle; | import com.comphenix.protocol.wrappers.WrappedParticle; | ||||||
| import me.libraryaddict.disguise.utilities.translations.LibsMsg; |  | ||||||
| import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; | import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; | ||||||
|  | import me.libraryaddict.disguise.utilities.parser.params.ParamInfoManager; | ||||||
| import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum; | import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum; | ||||||
|  | import me.libraryaddict.disguise.utilities.translations.LibsMsg; | ||||||
| import org.apache.commons.lang.StringUtils; | import org.apache.commons.lang.StringUtils; | ||||||
| import org.bukkit.Color; | import org.bukkit.Color; | ||||||
| import org.bukkit.Material; | import org.bukkit.Material; | ||||||
| import org.bukkit.Particle; | import org.bukkit.Particle; | ||||||
|  | import org.bukkit.inventory.ItemStack; | ||||||
|  |  | ||||||
| import java.util.Arrays; | import java.util.Arrays; | ||||||
| import java.util.HashSet; | import java.util.HashSet; | ||||||
| @@ -57,6 +59,32 @@ public class ParamInfoParticle extends ParamInfoEnum { | |||||||
|         return enums; |         return enums; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public String toString(Object object) { | ||||||
|  |         WrappedParticle particle = (WrappedParticle) object; | ||||||
|  |  | ||||||
|  |         Object data = particle.getData(); | ||||||
|  |         String returns = particle.getParticle().name(); | ||||||
|  |  | ||||||
|  |         if (data != null) { | ||||||
|  |             if (data instanceof ItemStack) { | ||||||
|  |                 returns += "," + ((ItemStack) data).getType().name(); | ||||||
|  |             } else if (data instanceof WrappedBlockData) { | ||||||
|  |  | ||||||
|  |                 returns += "," + ((WrappedBlockData) data).getType().name(); | ||||||
|  |             } else if (data instanceof Particle.DustOptions) { | ||||||
|  |                 returns += "," + | ||||||
|  |                         ParamInfoManager.getParamInfo(Color.class).toString(((Particle.DustOptions) data).getColor()); | ||||||
|  |  | ||||||
|  |                 if (((Particle.DustOptions) data).getSize() != 1f) { | ||||||
|  |                     returns += "," + ((Particle.DustOptions) data).getSize(); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return returns; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public Object fromString(String string) throws DisguiseParseException { |     public Object fromString(String string) throws DisguiseParseException { | ||||||
|         String[] split = string.split("[:,]"); // Split on comma or colon |         String[] split = string.split("[:,]"); // Split on comma or colon | ||||||
| @@ -99,7 +127,7 @@ public class ParamInfoParticle extends ParamInfoEnum { | |||||||
|                     throw new DisguiseParseException(LibsMsg.PARSE_PARTICLE_REDSTONE, particle.name(), string); |                     throw new DisguiseParseException(LibsMsg.PARSE_PARTICLE_REDSTONE, particle.name(), string); | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 Color color = ParamInfoColor.parseToColor( |                 Color color = ((ParamInfoColor) ParamInfoManager.getParamInfo(Color.class)).parseToColor( | ||||||
|                         StringUtils.join(Arrays.copyOfRange(split, 1, split.length - (split.length % 2)), ",")); |                         StringUtils.join(Arrays.copyOfRange(split, 1, split.length - (split.length % 2)), ",")); | ||||||
|  |  | ||||||
|                 if (color == null) { |                 if (color == null) { | ||||||
|   | |||||||
| @@ -15,6 +15,10 @@ public class ParamInfoTime extends ParamInfo { | |||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     protected Object fromString(String string) throws DisguiseParseException { |     protected Object fromString(String string) throws DisguiseParseException { | ||||||
|  |         if (string.matches("[0-9]{13,}")) { | ||||||
|  |             return Long.parseLong(string); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         long time = DisguiseParser.parseStringToTime(string); |         long time = DisguiseParser.parseStringToTime(string); | ||||||
|  |  | ||||||
|         // If disguise expires X ticks afterwards |         // If disguise expires X ticks afterwards | ||||||
| @@ -27,4 +31,9 @@ public class ParamInfoTime extends ParamInfo { | |||||||
|  |  | ||||||
|         return time; |         return time; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public String toString(Object object) { | ||||||
|  |         return object.toString(); | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -650,6 +650,9 @@ public class ReflectionManager { | |||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Gets the UUID of the player, as well as properly capitalized playername | ||||||
|  |      */ | ||||||
|     public static WrappedGameProfile grabProfileAddUUID(String playername) { |     public static WrappedGameProfile grabProfileAddUUID(String playername) { | ||||||
|         try { |         try { | ||||||
|             Object minecraftServer = getMinecraftServer(); |             Object minecraftServer = getMinecraftServer(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user