From d37acf8f8449beb69903eab1cf7bb0c622ca1de4 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 11 Jul 2014 16:36:47 +1200 Subject: [PATCH] Breaks existing API usage for setEntity to return a disguise object --- .../disguise/disguisetypes/Disguise.java | 21 ++++--------------- .../disguise/disguisetypes/MiscDisguise.java | 20 ++++++++++++++++++ .../disguise/disguisetypes/MobDisguise.java | 13 ++++++++++++ .../disguisetypes/PlayerDisguise.java | 14 ++++++++++++- 4 files changed, 50 insertions(+), 18 deletions(-) diff --git a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java index c8630fe6..ae94c012 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -24,7 +24,6 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.Horse.Variant; -import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; @@ -39,7 +38,7 @@ public abstract class Disguise { private static JavaPlugin plugin; private boolean disguiseInUse; private DisguiseType disguiseType; - private Entity entity; + protected Entity entity; private boolean hearSelfDisguise = DisguiseConfig.isSelfDisguisesSoundsReplaced(); private boolean hideArmorFromSelf = DisguiseConfig.isHidingArmorFromSelf(); 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() { if (disguiseInUse) { @@ -474,19 +473,7 @@ public abstract class Disguise { /** * Set the entity of the disguise. Only used for internal things. */ - public void 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 abstract Disguise setEntity(Entity entity); public void setHearSelfDisguise(boolean 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 * datawatcher. */ - private void setupWatcher() { + protected void setupWatcher() { HashMap disguiseValues = DisguiseValues.getMetaValues(getType()); HashMap entityValues = DisguiseValues.getMetaValues(DisguiseType.getType(getEntity().getType())); // Start from 2 as they ALL share 0 and 1 diff --git a/src/me/libraryaddict/disguise/disguisetypes/MiscDisguise.java b/src/me/libraryaddict/disguise/disguisetypes/MiscDisguise.java index 99c07bbf..f1f324be 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/MiscDisguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/MiscDisguise.java @@ -1,13 +1,17 @@ package me.libraryaddict.disguise.disguisetypes; import java.security.InvalidParameterException; + +import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.disguisetypes.watchers.DroppedItemWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.PaintingWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.SplashPotionWatcher; import org.bukkit.Art; +import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; import org.bukkit.inventory.ItemStack; public class MiscDisguise extends TargetedDisguise { @@ -146,4 +150,20 @@ public class MiscDisguise extends TargetedDisguise { 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; + } + } \ No newline at end of file diff --git a/src/me/libraryaddict/disguise/disguisetypes/MobDisguise.java b/src/me/libraryaddict/disguise/disguisetypes/MobDisguise.java index 4206040b..7bd9c35d 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/MobDisguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/MobDisguise.java @@ -5,6 +5,7 @@ import java.security.InvalidParameterException; import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; +import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; public class MobDisguise extends TargetedDisguise { @@ -80,4 +81,16 @@ public class MobDisguise extends TargetedDisguise { public boolean isMobDisguise() { 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; + } } \ No newline at end of file diff --git a/src/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java b/src/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java index b6919b43..f37fa33f 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java @@ -3,7 +3,7 @@ package me.libraryaddict.disguise.disguisetypes; import java.util.UUID; import org.apache.commons.lang.Validate; - +import org.bukkit.entity.Entity; import com.comphenix.protocol.wrappers.WrappedGameProfile; import me.libraryaddict.disguise.utilities.DisguiseUtilities; @@ -82,6 +82,18 @@ public class PlayerDisguise extends TargetedDisguise { 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 public void setSkin(String skinToUse) { this.skinToUse = skinToUse;