Added new config option AddEntityAnimations

This commit is contained in:
libraryaddict 2013-11-24 10:05:08 +13:00
parent 4e72ad359c
commit 0e0418b7be
5 changed files with 48 additions and 12 deletions

View File

@ -24,3 +24,7 @@ SendVelocity: true
# It just makes the client think the armor was removed so that it doesn't render it! # It just makes the client think the armor was removed so that it doesn't render it!
RemoveArmor: true RemoveArmor: true
RemoveHeldItem: true RemoveHeldItem: true
# If you set a disguise to burning, it will no longer be able to be shown as sneaking or invisible.
# Set this to true if you want the disguise to get the animations of the disguised entity. Such as invisible, on fire, sprinting, sneaking, blocking
# This is only valid if you set a animation on the disguise itself. Because the entitys animations are applied otherwise.
AddEntityAnimations: false

View File

@ -13,9 +13,9 @@ import org.bukkit.entity.Entity;
public class DisguiseAPI { public class DisguiseAPI {
private static boolean hearSelfDisguise; private static boolean hearSelfDisguise;
private static boolean hidingArmor; private static boolean hidingArmor;
private static boolean hidingHeldItem; private static boolean hidingHeldItem;
private static boolean isEntityAnimationsAdded;
private static boolean sendVelocity; private static boolean sendVelocity;
@Deprecated @Deprecated
@ -107,6 +107,10 @@ public class DisguiseAPI {
return getDisguise(disguised) != null; return getDisguise(disguised) != null;
} }
public static boolean isEntityAnimationsAdded() {
return isEntityAnimationsAdded;
}
/** /**
* Is the plugin modifying the inventory packets so that players when self disguised, do not see their armor floating around * Is the plugin modifying the inventory packets so that players when self disguised, do not see their armor floating around
*/ */
@ -150,6 +154,10 @@ public class DisguiseAPI {
return PacketsManager.isViewDisguisesListenerEnabled(); return PacketsManager.isViewDisguisesListenerEnabled();
} }
public static void setAddEntityAnimations(boolean isEntityAnimationsAdded) {
DisguiseAPI.isEntityAnimationsAdded = isEntityAnimationsAdded;
}
/** /**
* Can players hear their own disguises * Can players hear their own disguises
*/ */

View File

@ -63,6 +63,7 @@ public class LibsDisguises extends JavaPlugin {
DisguiseAPI.setHearSelfDisguise(getConfig().getBoolean("HearSelfDisguise")); DisguiseAPI.setHearSelfDisguise(getConfig().getBoolean("HearSelfDisguise"));
DisguiseAPI.setHideArmorFromSelf(getConfig().getBoolean("RemoveArmor")); DisguiseAPI.setHideArmorFromSelf(getConfig().getBoolean("RemoveArmor"));
DisguiseAPI.setHideHeldItemFromSelf(getConfig().getBoolean("RemoveHeldItem")); DisguiseAPI.setHideHeldItemFromSelf(getConfig().getBoolean("RemoveHeldItem"));
DisguiseAPI.setAddEntityAnimations(getConfig().getBoolean("AddEntityAnimations"));
if (DisguiseAPI.isHidingArmorFromSelf() || DisguiseAPI.isHidingHeldItemFromSelf()) { if (DisguiseAPI.isHidingArmorFromSelf() || DisguiseAPI.isHidingHeldItemFromSelf()) {
DisguiseAPI.setInventoryListenerEnabled(true); DisguiseAPI.setInventoryListenerEnabled(true);
} }

View File

@ -36,6 +36,7 @@ public class FlagWatcher {
} }
} }
private boolean addEntityAnimations = DisguiseAPI.isEntityAnimationsAdded();
/** /**
* This is the entity values I need to add else it could crash them.. * This is the entity values I need to add else it could crash them..
*/ */
@ -44,6 +45,7 @@ public class FlagWatcher {
private HashMap<Integer, Object> entityValues = new HashMap<Integer, Object>(); private HashMap<Integer, Object> entityValues = new HashMap<Integer, Object>();
private boolean hasDied; private boolean hasDied;
private org.bukkit.inventory.ItemStack[] items = new org.bukkit.inventory.ItemStack[5]; private org.bukkit.inventory.ItemStack[] items = new org.bukkit.inventory.ItemStack[5];
private HashSet<Integer> modifiedEntityAnimations = new HashSet<Integer>();
public FlagWatcher(Disguise disguise) { public FlagWatcher(Disguise disguise) {
this.disguise = disguise; this.disguise = disguise;
@ -63,6 +65,7 @@ public class FlagWatcher {
} }
cloned.entityValues = (HashMap<Integer, Object>) entityValues.clone(); cloned.entityValues = (HashMap<Integer, Object>) entityValues.clone();
cloned.items = items.clone(); cloned.items = items.clone();
cloned.modifiedEntityAnimations = (HashSet) modifiedEntityAnimations.clone();
return cloned; return cloned;
} }
@ -90,6 +93,16 @@ public class FlagWatcher {
value = backupEntityValues.get(dataType); value = backupEntityValues.get(dataType);
} }
if (value != null) { if (value != null) {
if (addEntityAnimations && dataType == 0) {
byte watcher = (Byte) watch.getValue();
byte valueByte = (Byte) value;
for (int i = 0; i < 6; i++) {
if ((watcher & 1 << i) != 0 && !modifiedEntityAnimations.contains(i)) {
valueByte = (byte) (valueByte | 1 << i);
}
}
value = valueByte;
}
boolean doD = watch.getDirtyState(); boolean doD = watch.getDirtyState();
watch = new WrappedWatchableObject(dataType, value); watch = new WrappedWatchableObject(dataType, value);
if (!doD) if (!doD)
@ -177,6 +190,10 @@ public class FlagWatcher {
return getFlag(0); return getFlag(0);
} }
public boolean isEntityAnimationsAdded() {
return addEntityAnimations;
}
public boolean isInvisible() { public boolean isInvisible() {
return getFlag(5); return getFlag(5);
} }
@ -222,6 +239,10 @@ public class FlagWatcher {
} }
} }
public void setAddEntityAnimations(boolean isEntityAnimationsAdded) {
this.addEntityAnimations = isEntityAnimationsAdded;
}
public void setArmor(org.bukkit.inventory.ItemStack[] itemstack) { public void setArmor(org.bukkit.inventory.ItemStack[] itemstack) {
for (int i = 0; i < itemstack.length; i++) for (int i = 0; i < itemstack.length; i++)
setItemStack(i, itemstack[i]); setItemStack(i, itemstack[i]);
@ -237,8 +258,10 @@ public class FlagWatcher {
} }
protected void setFlag(int no, int i, boolean flag) { protected void setFlag(int no, int i, boolean flag) {
if (no == 0) {
modifiedEntityAnimations.add(i);
}
byte b0 = (Byte) getValue(no, (byte) 0); byte b0 = (Byte) getValue(no, (byte) 0);
if (flag) { if (flag) {
setValue(no, (byte) (b0 | 1 << i)); setValue(no, (byte) (b0 | 1 << i));
} else { } else {

View File

@ -8,18 +8,12 @@ public class GhastWatcher extends LivingWatcher {
super(disguise); super(disguise);
} }
@Deprecated public boolean isAggressive() {
public boolean isAgressive() {
return (Byte) getValue(16, (byte) 0) == 1; return (Byte) getValue(16, (byte) 0) == 1;
} }
@Deprecated @Deprecated
public void setAgressive(boolean isAgressive) { public boolean isAgressive() {
setValue(16, (byte) (isAgressive ? 1 : 0));
sendData(16);
}
public boolean isAggressive() {
return (Byte) getValue(16, (byte) 0) == 1; return (Byte) getValue(16, (byte) 0) == 1;
} }
@ -28,4 +22,10 @@ public class GhastWatcher extends LivingWatcher {
sendData(16); sendData(16);
} }
@Deprecated
public void setAgressive(boolean isAgressive) {
setValue(16, (byte) (isAgressive ? 1 : 0));
sendData(16);
}
} }