Read description

Changed how I set the default datavalues.
Crashes should now be a thing of the past..
Painting is no longer glitched. (Still goes in floor)
Horse watcher is better.
Updated outdated values.
Updated incorrect yaw for disguises
This commit is contained in:
Andrew 2013-07-15 19:33:23 +12:00
parent 14b76f73c8
commit 9ea389eaf8
32 changed files with 297 additions and 206 deletions

View File

@ -11,6 +11,8 @@ import me.libraryaddict.disguise.DisguiseTypes.Watchers.AgeableWatcher;
import me.libraryaddict.disguise.DisguiseTypes.Watchers.LivingWatcher;
import net.minecraft.server.v1_6_R2.DataWatcher;
import net.minecraft.server.v1_6_R2.Entity;
import net.minecraft.server.v1_6_R2.EntityAgeable;
import net.minecraft.server.v1_6_R2.EntityInsentient;
import net.minecraft.server.v1_6_R2.EntityLiving;
import net.minecraft.server.v1_6_R2.EntityTypes;
import net.minecraft.server.v1_6_R2.ItemStack;
@ -41,16 +43,16 @@ public class Disguise {
replaceSounds = doSounds;
}
public PacketContainer constructPacket(org.bukkit.entity.Entity e) {
PacketContainer spawnPacket = null;
public PacketContainer[] constructPacket(org.bukkit.entity.Entity e) {
PacketContainer[] spawnPackets = new PacketContainer[1];
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
Entity entity = ((CraftEntity) e).getHandle();
Location loc = e.getLocation();
if (getType() == DisguiseType.EXPERIENCE_ORB) {
spawnPacket = manager.createPacket(Packets.Server.ADD_EXP_ORB);
StructureModifier<Object> mods = spawnPacket.getModifier();
spawnPackets[0] = manager.createPacket(Packets.Server.ADD_EXP_ORB);
StructureModifier<Object> mods = spawnPackets[0].getModifier();
mods.write(0, e.getEntityId());
mods.write(1, (int) Math.floor(loc.getX() * 32));
mods.write(2, (int) Math.floor(loc.getY() * 32) + 2);
@ -58,9 +60,9 @@ public class Disguise {
mods.write(4, 1);
} else if (getType() == DisguiseType.PAINTING) {
spawnPacket = manager.createPacket(Packets.Server.ENTITY_PAINTING);
StructureModifier<Object> mods = spawnPacket.getModifier();
spawnPackets = new PacketContainer[2];
spawnPackets[0] = manager.createPacket(Packets.Server.ENTITY_PAINTING);
StructureModifier<Object> mods = spawnPackets[0].getModifier();
mods.write(0, e.getEntityId());
mods.write(1, loc.getBlockX());
mods.write(2, loc.getBlockY());
@ -71,6 +73,18 @@ public class Disguise {
id = new Random().nextInt(EnumArt.values().length);
mods.write(5, EnumArt.values()[id].B);
// Make the teleport packet to make it visible..
spawnPackets[1] = manager.createPacket(Packets.Server.ENTITY_TELEPORT);
mods = spawnPackets[1].getModifier();
mods.write(0, e.getEntityId());
mods.write(1, (int) Math.floor(loc.getX() * 32D));
mods.write(2, (int) Math.floor(loc.getY() * 32D));
mods.write(3, (int) Math.floor(loc.getZ() * 32D));
mods.write(4, (byte) (int) (loc.getYaw() * 256.0F / 360.0F));
mods.write(5, (byte) (int) (loc.getPitch() * 256.0F / 360.0F));
// Need to fake a teleport packet as well to make the painting visible as a moving.
} else if (getType().isMob()) {
double d1 = 3.9D;
@ -90,8 +104,8 @@ public class Disguise {
d3 = d1;
if (d4 > d1)
d4 = d1;
spawnPacket = manager.createPacket(Packets.Server.MOB_SPAWN);
StructureModifier<Object> mods = spawnPacket.getModifier();
spawnPackets[0] = manager.createPacket(Packets.Server.MOB_SPAWN);
StructureModifier<Object> mods = spawnPackets[0].getModifier();
mods.write(0, e.getEntityId());
mods.write(1, (byte) EntityTypes.a(entity));
String name = toReadable(disguiseType.name());
@ -136,8 +150,6 @@ public class Disguise {
byte yawValue = (byte) (int) (entity.yaw * 256.0F / 360.0F);
if (getType() == DisguiseType.ENDER_DRAGON)
yawValue -= 128;
else if (getType() == DisguiseType.GHAST)
yawValue += 64;
mods.write(8, yawValue);
mods.write(9, (byte) (int) (entity.pitch * 256.0F / 360.0F));
mods.write(10, (byte) (int) (((EntityLiving) entity).aA * 256.0F / 360.0F));
@ -154,7 +166,7 @@ public class Disguise {
ex.printStackTrace();
}
mods.write(11, newWatcher);
// TODO May need to do the list
// Theres a list sometimes written with this. But no problems have appeared!
} else if (getType().isMisc()) {
@ -166,8 +178,8 @@ public class Disguise {
else
data = ((MiscDisguise) this).getId();
spawnPacket = manager.createPacket(Packets.Server.VEHICLE_SPAWN);
StructureModifier<Object> mods = spawnPacket.getModifier();
spawnPackets[0] = manager.createPacket(Packets.Server.VEHICLE_SPAWN);
StructureModifier<Object> mods = spawnPackets[0].getModifier();
mods.write(0, e.getEntityId());
mods.write(1, (int) Math.floor(loc.getX() * 32D));
mods.write(2, (int) Math.floor(loc.getY() * 32D));
@ -195,14 +207,14 @@ public class Disguise {
mods.write(6, (int) (d3 * 8000.0D));
}
mods.write(7, MathHelper.d(entity.pitch * 256.0F / 360.0F));
mods.write(8, MathHelper.d(entity.yaw * 256.0F / 360.0F) + 64);
mods.write(8, MathHelper.d(entity.yaw * 256.0F / 360.0F) - 64);
mods.write(9, id);
mods.write(10, data);
} else if (getType().isPlayer()) {
spawnPacket = manager.createPacket(Packets.Server.NAMED_ENTITY_SPAWN);
StructureModifier<Object> mods = spawnPacket.getModifier();
spawnPackets[0] = manager.createPacket(Packets.Server.NAMED_ENTITY_SPAWN);
StructureModifier<Object> mods = spawnPackets[0].getModifier();
mods.write(0, e.getEntityId());
mods.write(1, ((PlayerDisguise) this).getName());
mods.write(2, (int) Math.floor(loc.getX() * 32));
@ -218,7 +230,7 @@ public class Disguise {
}
return spawnPacket;
return spawnPackets;
}
public void constructWatcher(EntityType type, int entityId) {
@ -248,17 +260,63 @@ public class Disguise {
else
watcher = new FlagWatcher(entityId);
}
HashMap<Integer, Object> entity = Values.getMetaValues(DisguiseType.getType(type));
HashMap<Integer, Object> disguise = Values.getMetaValues(getType());
for (int i : entity.keySet()) {
if (!disguise.containsKey(i) || entity.get(i) != disguise.get(i)
|| entity.get(i).getClass() != disguise.get(i).getClass()) {
if (disguise.containsKey(i)) {
watcher.setValue(i, disguise.get(i));
} else {
watcher.setValue(i, null);
}
HashMap<Integer, Object> disguiseValues = Values.getMetaValues(getType());
HashMap<Integer, Object> entityValues = Values.getMetaValues(DisguiseType.getType(type));
// Start from 2 as they ALL share 0 and 1
for (int dataNo = 2; dataNo <= 31; dataNo++) {
// If the watcher already set a metadata on this
if (watcher.getValue(dataNo, null) != null)
continue;
// If neither of them touch it
if (!entityValues.containsKey(dataNo) && !disguiseValues.containsKey(dataNo))
continue;
// If the disguise has this, but not the entity. Then better set it!
if (!entityValues.containsKey(dataNo) && disguiseValues.containsKey(dataNo)) {
watcher.setValue(dataNo, disguiseValues.get(dataNo));
continue;
}
// Else if the disguise doesn't have it. But the entity does. Better remove it!
if (entityValues.containsKey(dataNo) && !disguiseValues.containsKey(dataNo)) {
watcher.setValue(dataNo, null);
continue;
}
// Hmm. They both have the datavalue. Time to check if they have different default values!
if (!entityValues.get(dataNo).equals(disguiseValues.get(dataNo))) {
// They do! Set the default value!
watcher.setValue(dataNo, disguiseValues.get(dataNo));
continue;
}
// Hmm. They both now have data values which are exactly the same. I need to do more intensive background checks.
// I HAVE to find juicy gossip on these!
// Maybe if I check that they extend each other..
// Entity is 0 & 1 - But we aint gonna be checking that
// EntityAgeable is 16
// EntityInsentient is 10 & 11
// EntityLiving is 6 & 7 & 8 & 9
// Lets use switch
Class owningData = null;
switch (dataNo) {
case 6:
case 7:
case 8:
case 9:
owningData = EntityLiving.class;
case 10:
case 11:
owningData = EntityInsentient.class;
case 16:
owningData = EntityAgeable.class;
default:
break;
}
// If they both extend the same base class. They OBVIOUSLY share the same datavalue. Right..?
if (owningData != null && Values.getEntityClass(getType()).isInstance(owningData)
&& Values.getEntityClass(DisguiseType.getType(type)).isInstance(owningData))
continue;
// Well I can't find a reason I should leave it alone. They will probably conflict.
// Time to set the value to the disguises value so no conflicts!
watcher.setValue(dataNo, disguiseValues.get(dataNo));
}
}

View File

@ -81,11 +81,13 @@ public class FlagWatcher {
}
private boolean getFlag(int i) {
return ((Byte) getValue(0) & 1 << i) != 0;
return ((Byte) getValue(0, (byte) 0) & 1 << i) != 0;
}
protected Object getValue(int no) {
return entityValues.get(no);
protected Object getValue(int no, Object backup) {
if (entityValues.containsKey(no))
return entityValues.get(no);
return backup;
}
public boolean isBurning() {
@ -112,6 +114,10 @@ public class FlagWatcher {
return getFlag(3);
}
protected boolean isTrue(int id, int no) {
return ((Byte) getValue(id, (byte) 0) & no) != 0;
}
protected void sendData(int data) {
Object value = entityValues.get(data);
List<WatchableObject> list = new ArrayList<WatchableObject>();
@ -133,51 +139,54 @@ public class FlagWatcher {
public void setBurning(boolean setBurning) {
if (isSneaking() != setBurning) {
setFlag(0, true);
setFlag(0, 0, true);
sendData(0);
}
}
private void setFlag(int i, boolean flag) {
byte currentValue = (Byte) getValue(0);
if (flag) {
setValue(0, Byte.valueOf((byte) (currentValue | 1 << i)));
} else {
setValue(0, Byte.valueOf((byte) (currentValue & ~(1 << i))));
protected void setFlag(int id, int no, boolean flag) {
if (isTrue(id, no) != flag) {
byte b0 = (Byte) getValue(id, (byte) 0);
if (flag) {
setValue(id, (byte) (b0 | (no)));
} else {
setValue(id, (byte) (b0 & -(no + 1)));
}
sendData(id);
}
}
public void setInvisible(boolean setInvis) {
if (isInvisible() != setInvis) {
setFlag(5, true);
setFlag(0, 5, true);
sendData(5);
}
}
public void setRiding(boolean setRiding) {
if (isSprinting() != setRiding) {
setFlag(2, true);
setFlag(0, 2, true);
sendData(2);
}
}
public void setRightClicking(boolean setRightClicking) {
if (isRightClicking() != setRightClicking) {
setFlag(4, true);
setFlag(0, 4, true);
sendData(4);
}
}
public void setSneaking(boolean setSneaking) {
if (isSneaking() != setSneaking) {
setFlag(1, true);
setFlag(0, 1, true);
sendData(1);
}
}
public void setSprinting(boolean setSprinting) {
if (isSprinting() != setSprinting) {
setFlag(3, true);
setFlag(0, 3, true);
sendData(3);
}
}

View File

@ -4,22 +4,21 @@ import java.util.HashMap;
public class Values {
private static HashMap<DisguiseType, HashMap<String, Double>> attributesValues = new HashMap<DisguiseType, HashMap<String, Double>>();
private static HashMap<DisguiseType, HashMap<Integer, Object>> metaValues = new HashMap<DisguiseType, HashMap<Integer, Object>>();
private static HashMap<DisguiseType, Values> values = new HashMap<DisguiseType, Values>();
public static HashMap<String, Double> getAttributesValues(DisguiseType type) {
if (type == DisguiseType.DONKEY || type == DisguiseType.MULE || type == DisguiseType.ZOMBIE_HORSE
|| type == DisguiseType.SKELETON_HORSE)
type = DisguiseType.HORSE;
if (type == DisguiseType.MINECART_CHEST || type == DisguiseType.MINECART_FURNACE || type == DisguiseType.MINECART_HOPPER
|| type == DisguiseType.MINECART_TNT || type == DisguiseType.MINECART_MOB_SPAWNER)
type = DisguiseType.MINECART_RIDEABLE;
if (type == DisguiseType.WITHER_SKELETON)
type = DisguiseType.SKELETON;
return attributesValues.get(type);
return getValues(type).getAttributesValues();
}
public static Class getEntityClass(DisguiseType type) {
return getValues(type).getEntityClass();
}
public static HashMap<Integer, Object> getMetaValues(DisguiseType type) {
return getValues(type).getMetaValues();
}
public static Values getValues(DisguiseType type) {
if (type == DisguiseType.DONKEY || type == DisguiseType.MULE || type == DisguiseType.ZOMBIE_HORSE
|| type == DisguiseType.SKELETON_HORSE)
type = DisguiseType.HORSE;
@ -28,22 +27,35 @@ public class Values {
type = DisguiseType.MINECART_RIDEABLE;
if (type == DisguiseType.WITHER_SKELETON)
type = DisguiseType.SKELETON;
return metaValues.get(type);
return values.get(type);
}
private DisguiseType type;
private HashMap<String, Double> attributesValues = new HashMap<String, Double>();
public Values(DisguiseType type) {
this.type = type;
metaValues.put(this.type, new HashMap<Integer, Object>());
attributesValues.put(this.type, new HashMap<String, Double>());
private Class declared;
private HashMap<Integer, Object> metaValues = new HashMap<Integer, Object>();
public Values(DisguiseType type, Class classType) {
values.put(type, this);
declared = classType;
}
public HashMap<String, Double> getAttributesValues() {
return attributesValues;
}
public Class getEntityClass() {
return declared;
}
public HashMap<Integer, Object> getMetaValues() {
return metaValues;
}
public void setAttributesValue(String attribute, Double value) {
attributesValues.get(type).put(attribute, value);
attributesValues.put(attribute, value);
}
public void setMetaValue(int no, Object value) {
metaValues.get(type).put(no, value);
metaValues.put(no, value);
}
}

View File

@ -4,11 +4,10 @@ public abstract class AgeableWatcher extends LivingWatcher {
public AgeableWatcher(int entityId) {
super(entityId);
setValue(12, 0);
}
public boolean isAdult() {
return (Integer) getValue(12) >= 0;
return (Integer) getValue(12, 0) >= 0;
}
public void setAdult(boolean isAdult) {

View File

@ -6,16 +6,14 @@ public class ArrowWatcher extends FlagWatcher {
public ArrowWatcher(int entityId) {
super(entityId);
setValue(16, (byte) 0);
}
public boolean isMoving() {
return (Byte) getValue(16) == 1;
return (Byte) getValue(16, (byte) 0) == 1;
}
public void setMoving(boolean moving) {
setValue(16, (byte) (moving ? 1 : 0));
}
}

View File

@ -4,15 +4,14 @@ public class BatWatcher extends LivingWatcher {
public BatWatcher(int entityId) {
super(entityId);
setValue(16, (byte) 1);
}
public boolean isFlying() {
return (Byte) getValue(16) == 0;
return (Byte) getValue(16, (byte) 1) == 0;
}
public void setFlying(boolean flying) {
if ((Byte) getValue(16) != (flying ? 1 : 0)) {
if ((Byte) getValue(16, (byte) 1) != (flying ? 1 : 0)) {
setValue(16, (byte) (flying ? 1 : 0));
sendData(16);
}

View File

@ -4,11 +4,10 @@ public class BlazeWatcher extends LivingWatcher {
public BlazeWatcher(int entityId) {
super(entityId);
setValue(16, (byte) 0);
}
public boolean isBlazing() {
return (Byte) getValue(16) == 1;
return (Byte) getValue(16, (byte) 0) == 1;
}
public void setBlazing(boolean isBlazing) {

View File

@ -6,20 +6,25 @@ public class BoatWatcher extends FlagWatcher {
public BoatWatcher(int entityId) {
super(entityId);
setValue(17, 10);
setValue(18, 0);
setValue(19, 40);
}
public void setDamage(int dmg) {
if ((Integer) getValue(19) != dmg) {
public int getDamage() {
return (Integer) getValue(19, 40F);
}
public int getHealth() {
return (Integer) getValue(17, 10);
}
public void setDamage(float dmg) {
if ((Float) getValue(19, 40F) != dmg) {
setValue(19, dmg);
sendData(19);
}
}
public void setHealth(int health) {
if ((Integer) getValue(17) != health) {
if ((Integer) getValue(17, 10) != health) {
setValue(17, health);
sendData(17);
}

View File

@ -4,24 +4,26 @@ public class CreeperWatcher extends LivingWatcher {
public CreeperWatcher(int entityId) {
super(entityId);
setValue(16, (byte) 0);
setValue(17, 0);
}
public boolean isFused() {
return (Byte) getValue(16) == 1;
return (Byte) getValue(16, (byte) 0) == 1;
}
public boolean isPowered() {
return (Byte) getValue(17) == 0;
return (Byte) getValue(17, (byte) 0) == 1;
}
public void setFuse(boolean isFused) {
if (isFused == isFused())
return;
setValue(16, (byte) (isFused ? 1 : -1));
sendData(16);
}
public void setPowered(boolean powered) {
if (powered == isPowered())
return;
setValue(17, (byte) (powered ? 1 : 0));
sendData(17);
}

View File

@ -4,7 +4,7 @@ public class DonkeyWatcher extends HorseWatcher {
public DonkeyWatcher(int entityId) {
super(entityId);
setHorseType(1);
setValue(19, (byte) 1);
}
}

View File

@ -9,11 +9,11 @@ public class DroppedItemWatcher extends FlagWatcher {
public DroppedItemWatcher(int entityId) {
super(entityId);
setValue(10, CraftItemStack.asNMSCopy(new ItemStack(1)));
}
public ItemStack getItemStack() {
return CraftItemStack.asBukkitCopy((net.minecraft.server.v1_6_R2.ItemStack) getValue(10));
return CraftItemStack.asBukkitCopy((net.minecraft.server.v1_6_R2.ItemStack) getValue(10,
CraftItemStack.asNMSCopy(new ItemStack(1))));
}
public void setItemStack(ItemStack item) {

View File

@ -4,16 +4,6 @@ public class EnderDragonWatcher extends LivingWatcher {
public EnderDragonWatcher(int entityId) {
super(entityId);
setValue(16, 300);
}
public int getHealth() {
return (Integer) getValue(16);
}
public void setHealth(int health) {
setValue(16, health);
sendData(16);
}
}

View File

@ -4,30 +4,29 @@ public class EndermanWatcher extends LivingWatcher {
public EndermanWatcher(int entityId) {
super(entityId);
setValue(16, (byte) 0);
setValue(17, (byte) 0);
setValue(18, (byte) 0);
}
public int getCarriedData() {
return ((Byte) getValue(17));
return ((Byte) getValue(17, (byte) 0));
}
public int getCarriedId() {
return ((Byte) getValue(16));
return ((Byte) getValue(16, (byte) 0));
}
public boolean isAgressive() {
return (Integer) getValue(18) == 1;
return (Integer) getValue(18, (byte) 0) == 1;
}
public void setAgressive(boolean isAgressive) {
setValue(18, (byte) (isAgressive ? 1 : 0));
sendData(18);
if (isAgressive() != isAgressive()) {
setValue(18, (byte) (isAgressive ? 1 : 0));
sendData(18);
}
}
public void setCarriedItem(int id, int dataValue) {
if ((Byte) getValue(16) != id || (Byte) getValue(17) != dataValue) {
if (getCarriedId() != id || getCarriedData() != dataValue) {
setValue(16, (byte) (id & 255));
setValue(17, (byte) (dataValue & 255));
sendData(16);

View File

@ -4,16 +4,17 @@ public class GhastWatcher extends LivingWatcher {
public GhastWatcher(int entityId) {
super(entityId);
setValue(16, (byte) 0);
}
public boolean isAgressive() {
return (Byte) getValue(16) == 1;
return (Byte) getValue(16, (byte) 0) == 1;
}
public void setAgressive(boolean isAgressive) {
setValue(16, (byte) (isAgressive ? 1 : 0));
sendData(16);
if (isAgressive() != isAgressive) {
setValue(16, (byte) (isAgressive ? 1 : 0));
sendData(16);
}
}
}

View File

@ -2,23 +2,24 @@ package me.libraryaddict.disguise.DisguiseTypes.Watchers;
import java.util.Random;
import org.bukkit.entity.Horse.Color;
import org.bukkit.entity.Horse.Style;
public class HorseWatcher extends AgeableWatcher {
public HorseWatcher(int entityId) {
super(entityId);
setValue(16, 0);
setValue(19, (byte) 0);
setValue(20, new Random().nextInt(7));
setValue(21, "");
setValue(22, 0);
}
public int getColoring() {
return (Integer) getValue(20);
public Color getColor() {
return Color.values()[((Integer) getValue(20, 0) & 0xFF)];
}
public int getHorseType() {
return (int) (Byte) getValue(19);
public Style getStyle() {
return Style.values()[((Integer) getValue(20, 0) >>> 8)];
}
public boolean hasChest() {
@ -50,7 +51,7 @@ public class HorseWatcher extends AgeableWatcher {
}
private boolean isTrue(int i) {
return ((Integer) getValue(16) & i) != 0;
return ((Integer) getValue(16, (byte) 0) & i) != 0;
}
public void setCanBred(boolean bred) {
@ -61,14 +62,14 @@ public class HorseWatcher extends AgeableWatcher {
setFlag(8, true);
}
public void setColoring(int color) {
setValue(20, color);
public void setColor(Color color) {
setValue(20, color.ordinal() & 0xFF | getStyle().ordinal() << 8);
sendData(20);
}
private void setFlag(int i, boolean flag) {
if (isTrue(i) != flag) {
int j = (Integer) getValue(16);
int j = (Integer) getValue(16, (byte) 0);
if (flag) {
setValue(16, j | i);
} else {
@ -82,11 +83,6 @@ public class HorseWatcher extends AgeableWatcher {
setFlag(32, grazing);
}
public void setHorseType(int type) {
setValue(19, (byte) type);
sendData(19);
}
public void setMouthOpen(boolean mouthOpen) {
setFlag(128, mouthOpen);
}
@ -99,6 +95,11 @@ public class HorseWatcher extends AgeableWatcher {
setFlag(4, saddled);
}
public void setStyle(Style style) {
setValue(20, getColor().ordinal() & 0xFF | style.ordinal() << 8);
sendData(20);
}
public void setTamed(boolean tamed) {
setFlag(2, tamed);
}

View File

@ -9,14 +9,14 @@ public class ItemFrameWatcher extends FlagWatcher {
public ItemFrameWatcher(int entityId) {
super(entityId);
setValue(2, 5);
setValue(3, (byte) 0);
// setValue(2, CraftItemStack.asCraftCopy(new ItemStack(0)));
// setValue(3, (byte) 0);
}
public ItemStack getItemStack() {
if (getValue(3) instanceof Integer)
if (getValue(3, (byte) 0) instanceof Integer)
return new ItemStack(0);
return CraftItemStack.asBukkitCopy((net.minecraft.server.v1_6_R2.ItemStack) getValue(3));
return CraftItemStack.asBukkitCopy((net.minecraft.server.v1_6_R2.ItemStack) getValue(3, null));
}
public void setItemStack(ItemStack newItem) {

View File

@ -16,8 +16,6 @@ public class LivingWatcher extends FlagWatcher {
public LivingWatcher(int entityId) {
super(entityId);
setValue(10, "");
setValue(11, (byte) 0);
}
public void addPotionEffect(PotionEffect potionEffect) {
@ -28,11 +26,15 @@ public class LivingWatcher extends FlagWatcher {
}
public String getCustomName() {
return (String) getValue(10);
return (String) getValue(10, "");
}
public float getHealth() {
return (Float) getValue(6, 0F);
}
public boolean getPotionParticlesRemoved() {
return (Byte) getValue(8) == 1;
return (Byte) getValue(8, (byte) 0) == 1;
}
public boolean hasCustomName() {
@ -46,6 +48,10 @@ public class LivingWatcher extends FlagWatcher {
return false;
}
public boolean isCustomNameVisible() {
return (Byte) getValue(11, (byte) 0) == 1;
}
public void removePotionEffect(PotionEffectType type) {
Iterator<MobEffect> itel = potionEffects.iterator();
while (itel.hasNext()) {
@ -78,10 +84,15 @@ public class LivingWatcher extends FlagWatcher {
}
public void setCustomNameVisible(boolean display) {
if ((Byte) getValue(11) != (display ? 1 : 0)) {
if (this.isCustomNameVisible()) {
setValue(11, (byte) (display ? 1 : 0));
sendData(11);
}
}
public void setHealth(float health) {
setValue(6, health);
sendData(6);
}
}

View File

@ -8,14 +8,14 @@ public class MinecartWatcher extends FlagWatcher {
super(entityId);
}
public float getDamage() {
if (getValue(19, 0F) != null)
return (Float) getValue(19, 0F);
return 0F;
}
public void setDamage(float damage) {
setValue(19, damage);
}
public float getDamage() {
if (getValue(19) != null)
return (Float) getValue(19);
return 0F;
}
}

View File

@ -4,7 +4,7 @@ public class MuleWatcher extends HorseWatcher {
public MuleWatcher(int entityId) {
super(entityId);
setHorseType(2);
setValue(19, (byte) 2);
}
}

View File

@ -7,33 +7,14 @@ public class OcelotWatcher extends AgeableWatcher {
public OcelotWatcher(int entityId) {
super(entityId);
setValue(16, (byte) 0);
setValue(17, "");
setValue(18, (byte) 0);
}
public String getOwner() {
return (String) getValue(17);
return (String) getValue(17, "");
}
public Type getType() {
return Ocelot.Type.getType((Byte) getValue(18));
}
private boolean isTrue(int no) {
return ((Byte) getValue(16) & no) != 0;
}
private void setFlag(int no, boolean flag) {
if (isTrue(no) != flag) {
byte b0 = (Byte) getValue(16);
if (flag) {
setValue(16, (byte) (b0 | (no)));
} else {
setValue(16, (byte) (b0 & -(no + 1)));
}
sendData(16);
}
return Ocelot.Type.getType((Byte) getValue(18, (byte) 0));
}
public void setOwner(String newOwner) {
@ -41,11 +22,11 @@ public class OcelotWatcher extends AgeableWatcher {
}
public void setSitting(boolean sitting) {
setFlag(1, sitting);
setFlag(16, 1, sitting);
}
public void setTamed(boolean tamed) {
setFlag(4, tamed);
setFlag(16, 4, tamed);
}
public void setType(Type newType) {

View File

@ -4,11 +4,10 @@ public class PigWatcher extends AgeableWatcher {
public PigWatcher(int entityId) {
super(entityId);
setValue(16, (byte) 0);
}
public boolean isSaddled() {
return (Byte) getValue(16) == 0;
return (Byte) getValue(16, (byte) 0) == 1;
}
public void setSaddled(boolean isSaddled) {

View File

@ -4,11 +4,10 @@ public class PigZombieWatcher extends LivingWatcher {
public PigZombieWatcher(int entityId) {
super(entityId);
setValue(12, (byte) 0);
}
public boolean isBaby() {
return (Byte) getValue(12) == 1;
return (Byte) getValue(12, (byte) 0) == 1;
}
public void setBaby(boolean baby) {

View File

@ -4,12 +4,10 @@ public class PlayerWatcher extends LivingWatcher {
public PlayerWatcher(int entityId) {
super(entityId);
setValue(9, (byte) 0);
setValue(18, 0);
}
public int getArrowsSticking() {
return (Byte) getValue(9);
return (Byte) getValue(9, (byte) 0);
}
public void setArrowsSticking(int arrowsNo) {

View File

@ -10,16 +10,16 @@ public class SheepWatcher extends AgeableWatcher {
}
public AnimalColor getColor() {
return AnimalColor.values()[(Byte) getValue(16) & 15];
return AnimalColor.values()[(Byte) getValue(16, (byte) 0) & 15];
}
public boolean isSheared() {
return ((Byte) getValue(16) & 16) != 0;
return ((Byte) getValue(16, (byte) 0) & 16) != 0;
}
public void setColor(AnimalColor color) {
if (getColor() != color) {
byte b0 = (Byte) getValue(16);
byte b0 = (Byte) getValue(16, (byte) 0);
setValue(16, (byte) (b0 & 240 | color.getId() & 15));
sendData(16);
}
@ -27,7 +27,7 @@ public class SheepWatcher extends AgeableWatcher {
public void setSheared(boolean flag) {
if (isSheared() != flag) {
byte b0 = (Byte) getValue(16);
byte b0 = (Byte) getValue(16, (byte) 0);
if (flag) {
setValue(16, (byte) (b0 | 16));
} else {

View File

@ -4,7 +4,7 @@ public class SkeletonHorseWatcher extends HorseWatcher {
public SkeletonHorseWatcher(int entityId) {
super(entityId);
setHorseType(4);
setValue(19, (byte) 4);
}
}

View File

@ -4,7 +4,6 @@ public class SkeletonWatcher extends LivingWatcher {
public SkeletonWatcher(int entityId) {
super(entityId);
setValue(13, (byte) 0);
}
}

View File

@ -7,11 +7,10 @@ public class SlimeWatcher extends LivingWatcher {
public SlimeWatcher(int entityId) {
super(entityId);
setValue(16, (byte) (new Random().nextInt(4) + 1));
setValue(18, (byte) 0);
}
public int getSize() {
return (Integer) getValue(16);
return (Integer) getValue(16, (byte) 1);
}
public void setSize(int size) {

View File

@ -12,7 +12,7 @@ public class VillagerWatcher extends AgeableWatcher {
}
public Profession getProfession() {
return Profession.values()[(Integer) getValue(16)];
return Profession.values()[(Integer) getValue(16, 0)];
}
public void setProfession(Profession newProfession) {

View File

@ -6,23 +6,18 @@ public class WolfWatcher extends AgeableWatcher {
public WolfWatcher(int entityId) {
super(entityId);
setValue(16, (byte) 0);
setValue(17, "");
setValue(18, 8F);
setValue(19, (byte) 0);
setValue(20, (byte) 14);
}
public AnimalColor getCollarColor() {
return AnimalColor.values()[(Byte) getValue(20)];
return AnimalColor.values()[(Byte) getValue(20, (byte) 14)];
}
public float getHealth() {
return (Float) getValue(18);
return (Float) getValue(18, 8F);
}
public String getName() {
return (String) getValue(17);
return (String) getValue(17, "");
}
public boolean isAngry() {
@ -38,7 +33,7 @@ public class WolfWatcher extends AgeableWatcher {
}
private boolean isTrue(int no) {
return ((Byte) getValue(16) & no) != 0;
return ((Byte) getValue(16, (byte) 0) & no) != 0;
}
public void setAngry(boolean angry) {
@ -54,7 +49,7 @@ public class WolfWatcher extends AgeableWatcher {
private void setFlag(int no, boolean flag) {
if (isTrue(no) != flag) {
byte b0 = (Byte) getValue(16);
byte b0 = (Byte) getValue(16, (byte) 0);
if (flag) {
setValue(16, (byte) (b0 | (no)));
} else {

View File

@ -4,7 +4,7 @@ public class ZombieHorseWatcher extends HorseWatcher {
public ZombieHorseWatcher(int entityId) {
super(entityId);
setHorseType(3);
setValue(19, (byte) 3);
}
}

View File

@ -4,11 +4,10 @@ public class ZombieWatcher extends PigZombieWatcher {
public ZombieWatcher(int entityId) {
super(entityId);
setValue(13, (byte) 0);
}
public boolean isVillager() {
return (Byte) getValue(13) == 1;
return (Byte) getValue(13, (byte) 0) == 1;
}
public void setVillager(boolean villager) {

View File

@ -1,5 +1,6 @@
package me.libraryaddict.disguise;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@ -93,7 +94,7 @@ public class LibsDisguises extends JavaPlugin implements Listener {
@Override
public void onPacketSending(PacketEvent event) {
try {
Player observer = event.getPlayer();
final Player observer = event.getPlayer();
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld());
org.bukkit.entity.Entity entity = entityModifer.read((Packets.Server.COLLECT == event.getPacketID() ? 1 : 0));
if (entity == observer)
@ -131,18 +132,54 @@ public class LibsDisguises extends JavaPlugin implements Listener {
String name = (String) mods.read(1);
if (!name.equals(((PlayerDisguise) disguise).getName())) {
// manager.sendServerPacket(observer, disguise.constructDestroyPacket(entity.getEntityId()));
event.setPacket(disguise.constructPacket(entity));
final PacketContainer[] packets = disguise.constructPacket(entity);
event.setPacket(packets[0]);
if (packets.length > 1) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
try {
manager.sendServerPacket(observer, packets[1]);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
});
}
}
} else {
// manager.sendServerPacket(observer, disguise.constructDestroyPacket(entity.getEntityId()));
event.setPacket(disguise.constructPacket(entity));
final PacketContainer[] packets = disguise.constructPacket(entity);
event.setPacket(packets[0]);
if (packets.length > 1) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
try {
manager.sendServerPacket(observer, packets[1]);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
});
}
}
} else if (event.getPacketID() == Packets.Server.MOB_SPAWN
|| event.getPacketID() == Packets.Server.ADD_EXP_ORB
|| event.getPacketID() == Packets.Server.VEHICLE_SPAWN
|| event.getPacketID() == Packets.Server.ENTITY_PAINTING) {
// manager.sendServerPacket(observer, disguise.constructDestroyPacket(entity.getEntityId()));
event.setPacket(disguise.constructPacket(entity));
final PacketContainer[] packets = disguise.constructPacket(entity);
event.setPacket(packets[0]);
if (packets.length > 1) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
try {
manager.sendServerPacket(observer, packets[1]);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
});
}
} else if (event.getPacketID() == Packets.Server.ARM_ANIMATION
|| event.getPacketID() == Packets.Server.COLLECT) {
if (disguise.getType().isMisc()) {
@ -156,13 +193,13 @@ public class LibsDisguises extends JavaPlugin implements Listener {
if (disguise.getType() == DisguiseType.ENDER_DRAGON) {
byte value = (Byte) mods.read(4);
mods.write(4, (byte) (value - 128));
} else if (disguise.getType().isMisc() || disguise.getType() == DisguiseType.GHAST) {
} else if (disguise.getType().isMisc()) {
byte value = (Byte) mods.read(4);
if (disguise.getType() != DisguiseType.PAINTING)
mods.write(4, (byte) (value + 128));
else if (disguise.getType().isMisc())
mods.write(4, (byte) -(value + 128));
else
if (disguise.getType() == DisguiseType.ITEM_FRAME) {
mods.write(4, -value);
} else if (disguise.getType() == DisguiseType.PAINTING) {
mods.write(4, -(value + 128));
} else if (disguise.getType().isMisc())
mods.write(4, (byte) (value - 64));
}
}
@ -255,13 +292,15 @@ public class LibsDisguises extends JavaPlugin implements Listener {
name = "LargeFireball";
try {
net.minecraft.server.v1_6_R2.Entity entity = null;
Class entityClass;
if (disguiseType == DisguiseType.PLAYER) {
entityClass = EntityHuman.class;
entity = new DisguiseHuman(world);
} else {
Class entityClass = Class.forName("net.minecraft.server.v1_6_R2.Entity" + name);
entityClass = Class.forName("net.minecraft.server.v1_6_R2.Entity" + name);
entity = (net.minecraft.server.v1_6_R2.Entity) entityClass.getConstructor(World.class).newInstance(world);
}
Values value = new Values(disguiseType);
Values value = new Values(disguiseType, entityClass);
List<WatchableObject> watchers = entity.getDataWatcher().c();
for (WatchableObject watch : watchers)
value.setMetaValue(watch.a(), watch.b());