Changed TargetedDisguise to have its methods return disguises

This finishes the commits which allows you to now use a disguise builder
while breaking tons of plugins using Lib's Disguises.
In retrospect. I should make a DisguiseBuilder instead.
This commit is contained in:
libraryaddict 2014-07-11 17:16:19 +12:00
parent 54d785b680
commit 3d44760b1b
5 changed files with 110 additions and 15 deletions

View File

@ -412,10 +412,6 @@ public abstract class Disguise {
return velocitySent;
}
public boolean stopDisguise() {
return removeDisguise();
}
/**
* Removes the disguise and undisguises the entity if its using this disguise.
*
@ -715,4 +711,8 @@ public abstract class Disguise {
}
return false;
}
public boolean stopDisguise() {
return removeDisguise();
}
}

View File

@ -10,6 +10,7 @@ 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.Player;
import org.bukkit.inventory.ItemStack;
public class MiscDisguise extends TargetedDisguise {
@ -104,6 +105,14 @@ public class MiscDisguise extends TargetedDisguise {
this(DisguiseType.getType(disguiseType), id, data);
}
public PlayerDisguise addPlayer(Player player) {
return (PlayerDisguise) super.addPlayer(player);
}
public MiscDisguise addPlayer(String playername) {
return (MiscDisguise) super.addPlayer(playername);
}
@Override
public MiscDisguise clone() {
MiscDisguise disguise = new MiscDisguise(getType(), getData());
@ -148,10 +157,24 @@ public class MiscDisguise extends TargetedDisguise {
return true;
}
public MiscDisguise removePlayer(Player player) {
return (MiscDisguise) super.removePlayer(player);
}
public MiscDisguise removePlayer(String playername) {
return (MiscDisguise) super.removePlayer(playername);
}
public MiscDisguise setDisguiseTarget(TargetType newTargetType) {
return (MiscDisguise) super.setDisguiseTarget(newTargetType);
}
@Override
public MiscDisguise setEntity(Entity entity) {
return (MiscDisguise) super.setEntity(entity);
} public MiscDisguise setHearSelfDisguise(boolean hearSelfDisguise) {
}
public MiscDisguise setHearSelfDisguise(boolean hearSelfDisguise) {
return (MiscDisguise) super.setHearSelfDisguise(hearSelfDisguise);
}
@ -195,4 +218,12 @@ public class MiscDisguise extends TargetedDisguise {
return (MiscDisguise) super.setWatcher(newWatcher);
}
public MiscDisguise silentlyAddPlayer(String playername) {
return (MiscDisguise) super.silentlyAddPlayer(playername);
}
public MiscDisguise silentlyRemovePlayer(String playername) {
return (MiscDisguise) super.silentlyRemovePlayer(playername);
}
}

View File

@ -7,6 +7,7 @@ import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
public class MobDisguise extends TargetedDisguise {
@ -48,6 +49,14 @@ public class MobDisguise extends TargetedDisguise {
this.setReplaceSounds(replaceSounds);
}
public PlayerDisguise addPlayer(Player player) {
return (PlayerDisguise) super.addPlayer(player);
}
public MobDisguise addPlayer(String playername) {
return (MobDisguise) super.addPlayer(playername);
}
@Override
public MobDisguise clone() {
MobDisguise disguise = new MobDisguise(getType(), isAdult());
@ -82,6 +91,18 @@ public class MobDisguise extends TargetedDisguise {
return true;
}
public MobDisguise removePlayer(Player player) {
return (MobDisguise) super.removePlayer(player);
}
public MobDisguise removePlayer(String playername) {
return (MobDisguise) super.removePlayer(playername);
}
public MobDisguise setDisguiseTarget(TargetType newTargetType) {
return (MobDisguise) super.setDisguiseTarget(newTargetType);
}
@Override
public MobDisguise setEntity(Entity entity) {
return (MobDisguise) super.setEntity(entity);
@ -109,9 +130,7 @@ public class MobDisguise extends TargetedDisguise {
public MobDisguise setKeepDisguiseOnPlayerLogout(boolean keepDisguise) {
return (MobDisguise) super.setKeepDisguiseOnPlayerLogout(keepDisguise);
}
public MobDisguise setModifyBoundingBox(boolean modifyBox) {
} public MobDisguise setModifyBoundingBox(boolean modifyBox) {
return (MobDisguise) super.setModifyBoundingBox(modifyBox);
}
@ -130,4 +149,12 @@ public class MobDisguise extends TargetedDisguise {
public MobDisguise setWatcher(FlagWatcher newWatcher) {
return (MobDisguise) super.setWatcher(newWatcher);
}
public MobDisguise silentlyAddPlayer(String playername) {
return (MobDisguise) super.silentlyAddPlayer(playername);
}
public MobDisguise silentlyRemovePlayer(String playername) {
return (MobDisguise) super.silentlyRemovePlayer(playername);
}
}

View File

@ -4,6 +4,8 @@ import java.util.UUID;
import org.apache.commons.lang.Validate;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
@ -36,6 +38,14 @@ public class PlayerDisguise extends TargetedDisguise {
setSkin(skinToUse);
}
public PlayerDisguise addPlayer(Player player) {
return (PlayerDisguise) super.addPlayer(player);
}
public PlayerDisguise addPlayer(String playername) {
return (PlayerDisguise) super.addPlayer(playername);
}
@Override
public PlayerDisguise clone() {
PlayerDisguise disguise = new PlayerDisguise(getName());
@ -82,6 +92,18 @@ public class PlayerDisguise extends TargetedDisguise {
return true;
}
public PlayerDisguise removePlayer(Player player) {
return (PlayerDisguise) super.removePlayer(player);
}
public PlayerDisguise removePlayer(String playername) {
return (PlayerDisguise) super.removePlayer(playername);
}
public PlayerDisguise setDisguiseTarget(TargetType newTargetType) {
return (PlayerDisguise) super.setDisguiseTarget(newTargetType);
}
@Override
public PlayerDisguise setEntity(Entity entity) {
return (PlayerDisguise) super.setEntity(entity);
@ -184,4 +206,12 @@ public class PlayerDisguise extends TargetedDisguise {
public PlayerDisguise setWatcher(FlagWatcher newWatcher) {
return (PlayerDisguise) super.setWatcher(newWatcher);
}
public PlayerDisguise silentlyAddPlayer(String playername) {
return (PlayerDisguise) super.silentlyAddPlayer(playername);
}
public PlayerDisguise silentlyRemovePlayer(String playername) {
return (PlayerDisguise) super.silentlyRemovePlayer(playername);
}
}

View File

@ -17,11 +17,12 @@ public abstract class TargetedDisguise extends Disguise {
private List<String> disguiseViewers = new ArrayList<String>();
private TargetType targetType = TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS;
public void addPlayer(Player player) {
public TargetedDisguise addPlayer(Player player) {
addPlayer(player.getName());
return this;
}
public void addPlayer(String playername) {
public TargetedDisguise addPlayer(String playername) {
if (!disguiseViewers.contains(playername)) {
disguiseViewers.add(playername);
if (DisguiseAPI.isDisguiseInUse(this)) {
@ -29,6 +30,7 @@ public abstract class TargetedDisguise extends Disguise {
DisguiseUtilities.refreshTracker(this, playername);
}
}
return this;
}
public boolean canSee(Player player) {
@ -51,11 +53,12 @@ public abstract class TargetedDisguise extends Disguise {
return Collections.unmodifiableList(disguiseViewers);
}
public void removePlayer(Player player) {
public TargetedDisguise removePlayer(Player player) {
removePlayer(player.getName());
return this;
}
public void removePlayer(String playername) {
public TargetedDisguise removePlayer(String playername) {
if (disguiseViewers.contains(playername)) {
disguiseViewers.remove(playername);
if (DisguiseAPI.isDisguiseInUse(this)) {
@ -63,24 +66,28 @@ public abstract class TargetedDisguise extends Disguise {
DisguiseUtilities.refreshTracker(this, playername);
}
}
return this;
}
public void setDisguiseTarget(TargetType newTargetType) {
public TargetedDisguise setDisguiseTarget(TargetType newTargetType) {
if (DisguiseUtilities.isDisguiseInUse(this)) {
throw new RuntimeException("Cannot set the disguise target after the entity has been disguised");
}
targetType = newTargetType;
return this;
}
public void silentlyAddPlayer(String playername) {
public TargetedDisguise silentlyAddPlayer(String playername) {
if (!disguiseViewers.contains(playername)) {
disguiseViewers.add(playername);
}
return this;
}
public void silentlyRemovePlayer(String playername) {
public TargetedDisguise silentlyRemovePlayer(String playername) {
if (disguiseViewers.contains(playername)) {
disguiseViewers.remove(playername);
}
return this;
}
}