Breaks existing API usage for setEntity to return a disguise object
This commit is contained in:
		| @@ -24,7 +24,6 @@ import org.bukkit.Bukkit; | |||||||
| import org.bukkit.Location; | import org.bukkit.Location; | ||||||
| import org.bukkit.entity.Entity; | import org.bukkit.entity.Entity; | ||||||
| import org.bukkit.entity.Horse.Variant; | import org.bukkit.entity.Horse.Variant; | ||||||
| import org.bukkit.entity.LivingEntity; |  | ||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
| import org.bukkit.plugin.java.JavaPlugin; | import org.bukkit.plugin.java.JavaPlugin; | ||||||
| import org.bukkit.scheduler.BukkitTask; | import org.bukkit.scheduler.BukkitTask; | ||||||
| @@ -39,7 +38,7 @@ public abstract class Disguise { | |||||||
|     private static JavaPlugin plugin; |     private static JavaPlugin plugin; | ||||||
|     private boolean disguiseInUse; |     private boolean disguiseInUse; | ||||||
|     private DisguiseType disguiseType; |     private DisguiseType disguiseType; | ||||||
|     private Entity entity; |     protected Entity entity; | ||||||
|     private boolean hearSelfDisguise = DisguiseConfig.isSelfDisguisesSoundsReplaced(); |     private boolean hearSelfDisguise = DisguiseConfig.isSelfDisguisesSoundsReplaced(); | ||||||
|     private boolean hideArmorFromSelf = DisguiseConfig.isHidingArmorFromSelf(); |     private boolean hideArmorFromSelf = DisguiseConfig.isHidingArmorFromSelf(); | ||||||
|     private boolean hideHeldItemFromSelf = DisguiseConfig.isHidingHeldItemFromSelf(); |     private boolean hideHeldItemFromSelf = DisguiseConfig.isHidingHeldItemFromSelf(); | ||||||
| @@ -413,7 +412,7 @@ public abstract class Disguise { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Removes the disguise and undisguises the entity if its using this disguise. This doesn't fire a UndisguiseEvent |      * Removes the disguise and undisguises the entity if its using this disguise. | ||||||
|      */ |      */ | ||||||
|     public void removeDisguise() { |     public void removeDisguise() { | ||||||
|         if (disguiseInUse) { |         if (disguiseInUse) { | ||||||
| @@ -474,19 +473,7 @@ public abstract class Disguise { | |||||||
|     /** |     /** | ||||||
|      * Set the entity of the disguise. Only used for internal things. |      * Set the entity of the disguise. Only used for internal things. | ||||||
|      */ |      */ | ||||||
|     public void setEntity(Entity entity) { |     public abstract Disguise setEntity(Entity entity); | ||||||
|         if (this.getEntity() != null) { |  | ||||||
|             if (getEntity() == entity) |  | ||||||
|                 return; |  | ||||||
|             throw new RuntimeException("This disguise is already in use! Try .clone()"); |  | ||||||
|         } |  | ||||||
|         if (this.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() && entity instanceof LivingEntity) { |  | ||||||
|             throw new RuntimeException( |  | ||||||
|                     "Cannot disguise a living entity with a misc disguise. Renable MiscDisguisesForLiving in the config to do this"); |  | ||||||
|         } |  | ||||||
|         this.entity = entity; |  | ||||||
|         setupWatcher(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void setHearSelfDisguise(boolean hearSelfDisguise) { |     public void setHearSelfDisguise(boolean hearSelfDisguise) { | ||||||
|         this.hearSelfDisguise = hearSelfDisguise; |         this.hearSelfDisguise = hearSelfDisguise; | ||||||
| @@ -539,7 +526,7 @@ public abstract class Disguise { | |||||||
|      * Sets up the FlagWatcher with the entityclass, it creates all the data it needs to prevent conflicts when sending the |      * Sets up the FlagWatcher with the entityclass, it creates all the data it needs to prevent conflicts when sending the | ||||||
|      * datawatcher. |      * datawatcher. | ||||||
|      */ |      */ | ||||||
|     private void setupWatcher() { |     protected void setupWatcher() { | ||||||
|         HashMap<Integer, Object> disguiseValues = DisguiseValues.getMetaValues(getType()); |         HashMap<Integer, Object> disguiseValues = DisguiseValues.getMetaValues(getType()); | ||||||
|         HashMap<Integer, Object> entityValues = DisguiseValues.getMetaValues(DisguiseType.getType(getEntity().getType())); |         HashMap<Integer, Object> entityValues = DisguiseValues.getMetaValues(DisguiseType.getType(getEntity().getType())); | ||||||
|         // Start from 2 as they ALL share 0 and 1 |         // Start from 2 as they ALL share 0 and 1 | ||||||
|   | |||||||
| @@ -1,13 +1,17 @@ | |||||||
| package me.libraryaddict.disguise.disguisetypes; | package me.libraryaddict.disguise.disguisetypes; | ||||||
|  |  | ||||||
| import java.security.InvalidParameterException; | import java.security.InvalidParameterException; | ||||||
|  |  | ||||||
|  | import me.libraryaddict.disguise.DisguiseConfig; | ||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.DroppedItemWatcher; | import me.libraryaddict.disguise.disguisetypes.watchers.DroppedItemWatcher; | ||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher; | import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher; | ||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.PaintingWatcher; | import me.libraryaddict.disguise.disguisetypes.watchers.PaintingWatcher; | ||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.SplashPotionWatcher; | import me.libraryaddict.disguise.disguisetypes.watchers.SplashPotionWatcher; | ||||||
|  |  | ||||||
| import org.bukkit.Art; | import org.bukkit.Art; | ||||||
|  | import org.bukkit.entity.Entity; | ||||||
| import org.bukkit.entity.EntityType; | import org.bukkit.entity.EntityType; | ||||||
|  | import org.bukkit.entity.LivingEntity; | ||||||
| import org.bukkit.inventory.ItemStack; | import org.bukkit.inventory.ItemStack; | ||||||
|  |  | ||||||
| public class MiscDisguise extends TargetedDisguise { | public class MiscDisguise extends TargetedDisguise { | ||||||
| @@ -146,4 +150,20 @@ public class MiscDisguise extends TargetedDisguise { | |||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public MiscDisguise setEntity(Entity entity) { | ||||||
|  |         if (this.getEntity() != null) { | ||||||
|  |             if (getEntity() == entity) | ||||||
|  |                 return this; | ||||||
|  |             throw new RuntimeException("This disguise is already in use! Try .clone()"); | ||||||
|  |         } | ||||||
|  |         if (!DisguiseConfig.isMiscDisguisesForLivingEnabled() && entity instanceof LivingEntity) { | ||||||
|  |             throw new RuntimeException( | ||||||
|  |                     "Cannot disguise a living entity with a misc disguise. Renable MiscDisguisesForLiving in the config to do this"); | ||||||
|  |         } | ||||||
|  |         this.entity = entity; | ||||||
|  |         setupWatcher(); | ||||||
|  |         return this; | ||||||
|  |     } | ||||||
|  |  | ||||||
| } | } | ||||||
| @@ -5,6 +5,7 @@ import java.security.InvalidParameterException; | |||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; | import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; | ||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; | import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; | ||||||
|  |  | ||||||
|  | import org.bukkit.entity.Entity; | ||||||
| import org.bukkit.entity.EntityType; | import org.bukkit.entity.EntityType; | ||||||
|  |  | ||||||
| public class MobDisguise extends TargetedDisguise { | public class MobDisguise extends TargetedDisguise { | ||||||
| @@ -80,4 +81,16 @@ public class MobDisguise extends TargetedDisguise { | |||||||
|     public boolean isMobDisguise() { |     public boolean isMobDisguise() { | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public MobDisguise setEntity(Entity entity) { | ||||||
|  |         if (this.getEntity() != null) { | ||||||
|  |             if (getEntity() == entity) | ||||||
|  |                 return this; | ||||||
|  |             throw new RuntimeException("This disguise is already in use! Try .clone()"); | ||||||
|  |         } | ||||||
|  |         this.entity = entity; | ||||||
|  |         setupWatcher(); | ||||||
|  |         return this; | ||||||
|  |     } | ||||||
| } | } | ||||||
| @@ -3,7 +3,7 @@ package me.libraryaddict.disguise.disguisetypes; | |||||||
| import java.util.UUID; | import java.util.UUID; | ||||||
|  |  | ||||||
| import org.apache.commons.lang.Validate; | import org.apache.commons.lang.Validate; | ||||||
|  | import org.bukkit.entity.Entity; | ||||||
| import com.comphenix.protocol.wrappers.WrappedGameProfile; | import com.comphenix.protocol.wrappers.WrappedGameProfile; | ||||||
|  |  | ||||||
| import me.libraryaddict.disguise.utilities.DisguiseUtilities; | import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||||
| @@ -82,6 +82,18 @@ public class PlayerDisguise extends TargetedDisguise { | |||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public PlayerDisguise setEntity(Entity entity) { | ||||||
|  |         if (this.getEntity() != null) { | ||||||
|  |             if (getEntity() == entity) | ||||||
|  |                 return this; | ||||||
|  |             throw new RuntimeException("This disguise is already in use! Try .clone()"); | ||||||
|  |         } | ||||||
|  |         this.entity = entity; | ||||||
|  |         setupWatcher(); | ||||||
|  |         return this; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Deprecated |     @Deprecated | ||||||
|     public void setSkin(String skinToUse) { |     public void setSkin(String skinToUse) { | ||||||
|         this.skinToUse = skinToUse; |         this.skinToUse = skinToUse; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user