Clean up code. Add in code. Forgot what I did.

This commit is contained in:
libraryaddict 2013-12-02 03:31:54 +13:00
parent a969811c64
commit 4dc6853945
3 changed files with 38 additions and 16 deletions

View File

@ -3,6 +3,7 @@ package me.libraryaddict.disguise;
import java.lang.reflect.Field;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.TargettedDisguise;
import me.libraryaddict.disguise.disguisetypes.TargettedDisguise.TargetType;
import me.libraryaddict.disguise.events.DisguiseEvent;
import me.libraryaddict.disguise.events.UndisguiseEvent;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
@ -48,11 +49,13 @@ public class DisguiseAPI {
* Disguise this entity with this disguise
*/
public static void disguiseToAll(Entity entity, Disguise disguise) {
// TODO Make everyone see this disguise. Remove any old disguises.
// If they are trying to disguise a null entity or use a null disguise
// Just return.
if (entity == null || disguise == null)
return;
// You called the disguiseToAll method foolish mortal! Prepare to have your custom settings wiped!!!
((TargettedDisguise) disguise).setTargetType(TargetType.HIDE_FROM_THESE);
((TargettedDisguise) disguise).getObservers().clear();
// Fire a disguise event
DisguiseEvent event = new DisguiseEvent(entity, disguise);
Bukkit.getPluginManager().callEvent(event);
@ -71,7 +74,7 @@ public class DisguiseAPI {
// Set the disguise's entity
disguise.setEntity(entity);
} // If there was a old disguise
Disguise oldDisguise = getDisguise(entity);
Disguise[] oldDisguises = getDisguises(entity);
// Stick the disguise in the disguises bin
DisguiseUtilities.addDisguise(entity.getEntityId(), (TargettedDisguise) disguise);
// Resend the disguised entity's packet
@ -79,8 +82,11 @@ public class DisguiseAPI {
// If he is a player, then self disguise himself
DisguiseUtilities.setupFakeDisguise(disguise);
// Discard the disguise
if (oldDisguise != null)
for (Disguise oldDisguise : oldDisguises) {
oldDisguise.removeDisguise();
// Make everyone see this disguise. Remove any old disguises.
DisguiseUtilities.getDisguises().remove(entity.getEntityId());
}
}
/**
@ -93,6 +99,15 @@ public class DisguiseAPI {
return DisguiseUtilities.getDisguise(disguised.getEntityId());
}
/**
* Get the disguises of a entity
*/
public static Disguise[] getDisguises(Entity disguised) {
if (disguised == null)
return null;
return DisguiseUtilities.getDisguises(disguised.getEntityId());
}
/**
* Get the disguise of a entity
*/
@ -237,16 +252,15 @@ public class DisguiseAPI {
* the world.
*/
public static void undisguiseToAll(Entity entity) {
// TODO Make all of these disguises be removed
Disguise disguise = getDisguise(entity);
if (disguise == null)
return;
Disguise[] disguises = getDisguises(entity);
for (Disguise disguise : disguises) {
UndisguiseEvent event = new UndisguiseEvent(entity, disguise);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
continue;
disguise.removeDisguise();
}
}
private DisguiseAPI() {
}

View File

@ -129,7 +129,8 @@ public class FlagWatcher {
}
}
// Here we check for if there is a health packet that says they died.
if (disguise.isSelfDisguiseVisible() && getDisguise().getEntity() != null && getDisguise().getEntity() instanceof Player) {
if (getDisguise().isSelfDisguiseVisible() && getDisguise().getEntity() != null
&& getDisguise().getEntity() instanceof Player) {
for (WrappedWatchableObject watch : newList) {
// Its a health packet
if (watch.getIndex() == 6) {
@ -217,7 +218,7 @@ public class FlagWatcher {
}
protected void sendData(int data) {
if (disguise.getWatcher() == null || DisguiseAPI.getDisguise(disguise.getEntity()) != disguise)
if (getDisguise().getWatcher() == null || !DisguiseAPI.isDisguiseInUse(getDisguise()))
return;
if (!entityValues.containsKey(data) || entityValues.get(data) == null)
return;
@ -283,7 +284,7 @@ public class FlagWatcher {
// Itemstack which is null means that its not replacing the disguises itemstack.
if (itemStack == null) {
// Find the item to replace it with
if (disguise.getEntity() instanceof LivingEntity) {
if (getDisguise().getEntity() instanceof LivingEntity) {
EntityEquipment enquipment = ((LivingEntity) getDisguise().getEntity()).getEquipment();
if (slot == 0) {
itemStack = enquipment.getItemInHand();
@ -299,7 +300,7 @@ public class FlagWatcher {
if (itemStack != null && itemStack.getTypeId() != 0)
itemToSend = ReflectionManager.getNmsItem(itemStack);
items[slot] = itemStack;
if (DisguiseAPI.getDisguise(disguise.getEntity()) != disguise)
if (!DisguiseAPI.isDisguiseInUse(getDisguise()))
return;
slot++;
if (slot > 4)

View File

@ -266,6 +266,13 @@ public class DisguiseUtilities {
return toReturn;
}
public static TargettedDisguise[] getDisguises(int entityId) {
if (getDisguises().containsKey(entityId)) {
return getDisguises().get(entityId).toArray(new TargettedDisguise[getDisguises().get(entityId).size()]);
}
return new TargettedDisguise[0];
}
public static TargettedDisguise getDisguise(Player observer, int entityId) {
if (getDisguises().containsKey(entityId)) {
for (TargettedDisguise disguise : getDisguises().get(entityId)) {