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:
parent
14b76f73c8
commit
9ea389eaf8
@ -11,6 +11,8 @@ import me.libraryaddict.disguise.DisguiseTypes.Watchers.AgeableWatcher;
|
|||||||
import me.libraryaddict.disguise.DisguiseTypes.Watchers.LivingWatcher;
|
import me.libraryaddict.disguise.DisguiseTypes.Watchers.LivingWatcher;
|
||||||
import net.minecraft.server.v1_6_R2.DataWatcher;
|
import net.minecraft.server.v1_6_R2.DataWatcher;
|
||||||
import net.minecraft.server.v1_6_R2.Entity;
|
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.EntityLiving;
|
||||||
import net.minecraft.server.v1_6_R2.EntityTypes;
|
import net.minecraft.server.v1_6_R2.EntityTypes;
|
||||||
import net.minecraft.server.v1_6_R2.ItemStack;
|
import net.minecraft.server.v1_6_R2.ItemStack;
|
||||||
@ -41,16 +43,16 @@ public class Disguise {
|
|||||||
replaceSounds = doSounds;
|
replaceSounds = doSounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacketContainer constructPacket(org.bukkit.entity.Entity e) {
|
public PacketContainer[] constructPacket(org.bukkit.entity.Entity e) {
|
||||||
PacketContainer spawnPacket = null;
|
PacketContainer[] spawnPackets = new PacketContainer[1];
|
||||||
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
|
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
|
||||||
Entity entity = ((CraftEntity) e).getHandle();
|
Entity entity = ((CraftEntity) e).getHandle();
|
||||||
Location loc = e.getLocation();
|
Location loc = e.getLocation();
|
||||||
|
|
||||||
if (getType() == DisguiseType.EXPERIENCE_ORB) {
|
if (getType() == DisguiseType.EXPERIENCE_ORB) {
|
||||||
|
|
||||||
spawnPacket = manager.createPacket(Packets.Server.ADD_EXP_ORB);
|
spawnPackets[0] = manager.createPacket(Packets.Server.ADD_EXP_ORB);
|
||||||
StructureModifier<Object> mods = spawnPacket.getModifier();
|
StructureModifier<Object> mods = spawnPackets[0].getModifier();
|
||||||
mods.write(0, e.getEntityId());
|
mods.write(0, e.getEntityId());
|
||||||
mods.write(1, (int) Math.floor(loc.getX() * 32));
|
mods.write(1, (int) Math.floor(loc.getX() * 32));
|
||||||
mods.write(2, (int) Math.floor(loc.getY() * 32) + 2);
|
mods.write(2, (int) Math.floor(loc.getY() * 32) + 2);
|
||||||
@ -58,9 +60,9 @@ public class Disguise {
|
|||||||
mods.write(4, 1);
|
mods.write(4, 1);
|
||||||
|
|
||||||
} else if (getType() == DisguiseType.PAINTING) {
|
} else if (getType() == DisguiseType.PAINTING) {
|
||||||
|
spawnPackets = new PacketContainer[2];
|
||||||
spawnPacket = manager.createPacket(Packets.Server.ENTITY_PAINTING);
|
spawnPackets[0] = manager.createPacket(Packets.Server.ENTITY_PAINTING);
|
||||||
StructureModifier<Object> mods = spawnPacket.getModifier();
|
StructureModifier<Object> mods = spawnPackets[0].getModifier();
|
||||||
mods.write(0, e.getEntityId());
|
mods.write(0, e.getEntityId());
|
||||||
mods.write(1, loc.getBlockX());
|
mods.write(1, loc.getBlockX());
|
||||||
mods.write(2, loc.getBlockY());
|
mods.write(2, loc.getBlockY());
|
||||||
@ -71,6 +73,18 @@ public class Disguise {
|
|||||||
id = new Random().nextInt(EnumArt.values().length);
|
id = new Random().nextInt(EnumArt.values().length);
|
||||||
mods.write(5, EnumArt.values()[id].B);
|
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()) {
|
} else if (getType().isMob()) {
|
||||||
|
|
||||||
double d1 = 3.9D;
|
double d1 = 3.9D;
|
||||||
@ -90,8 +104,8 @@ public class Disguise {
|
|||||||
d3 = d1;
|
d3 = d1;
|
||||||
if (d4 > d1)
|
if (d4 > d1)
|
||||||
d4 = d1;
|
d4 = d1;
|
||||||
spawnPacket = manager.createPacket(Packets.Server.MOB_SPAWN);
|
spawnPackets[0] = manager.createPacket(Packets.Server.MOB_SPAWN);
|
||||||
StructureModifier<Object> mods = spawnPacket.getModifier();
|
StructureModifier<Object> mods = spawnPackets[0].getModifier();
|
||||||
mods.write(0, e.getEntityId());
|
mods.write(0, e.getEntityId());
|
||||||
mods.write(1, (byte) EntityTypes.a(entity));
|
mods.write(1, (byte) EntityTypes.a(entity));
|
||||||
String name = toReadable(disguiseType.name());
|
String name = toReadable(disguiseType.name());
|
||||||
@ -136,8 +150,6 @@ public class Disguise {
|
|||||||
byte yawValue = (byte) (int) (entity.yaw * 256.0F / 360.0F);
|
byte yawValue = (byte) (int) (entity.yaw * 256.0F / 360.0F);
|
||||||
if (getType() == DisguiseType.ENDER_DRAGON)
|
if (getType() == DisguiseType.ENDER_DRAGON)
|
||||||
yawValue -= 128;
|
yawValue -= 128;
|
||||||
else if (getType() == DisguiseType.GHAST)
|
|
||||||
yawValue += 64;
|
|
||||||
mods.write(8, yawValue);
|
mods.write(8, yawValue);
|
||||||
mods.write(9, (byte) (int) (entity.pitch * 256.0F / 360.0F));
|
mods.write(9, (byte) (int) (entity.pitch * 256.0F / 360.0F));
|
||||||
mods.write(10, (byte) (int) (((EntityLiving) entity).aA * 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();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
mods.write(11, newWatcher);
|
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()) {
|
} else if (getType().isMisc()) {
|
||||||
|
|
||||||
@ -166,8 +178,8 @@ public class Disguise {
|
|||||||
else
|
else
|
||||||
data = ((MiscDisguise) this).getId();
|
data = ((MiscDisguise) this).getId();
|
||||||
|
|
||||||
spawnPacket = manager.createPacket(Packets.Server.VEHICLE_SPAWN);
|
spawnPackets[0] = manager.createPacket(Packets.Server.VEHICLE_SPAWN);
|
||||||
StructureModifier<Object> mods = spawnPacket.getModifier();
|
StructureModifier<Object> mods = spawnPackets[0].getModifier();
|
||||||
mods.write(0, e.getEntityId());
|
mods.write(0, e.getEntityId());
|
||||||
mods.write(1, (int) Math.floor(loc.getX() * 32D));
|
mods.write(1, (int) Math.floor(loc.getX() * 32D));
|
||||||
mods.write(2, (int) Math.floor(loc.getY() * 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(6, (int) (d3 * 8000.0D));
|
||||||
}
|
}
|
||||||
mods.write(7, MathHelper.d(entity.pitch * 256.0F / 360.0F));
|
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(9, id);
|
||||||
mods.write(10, data);
|
mods.write(10, data);
|
||||||
|
|
||||||
} else if (getType().isPlayer()) {
|
} else if (getType().isPlayer()) {
|
||||||
|
|
||||||
spawnPacket = manager.createPacket(Packets.Server.NAMED_ENTITY_SPAWN);
|
spawnPackets[0] = manager.createPacket(Packets.Server.NAMED_ENTITY_SPAWN);
|
||||||
StructureModifier<Object> mods = spawnPacket.getModifier();
|
StructureModifier<Object> mods = spawnPackets[0].getModifier();
|
||||||
mods.write(0, e.getEntityId());
|
mods.write(0, e.getEntityId());
|
||||||
mods.write(1, ((PlayerDisguise) this).getName());
|
mods.write(1, ((PlayerDisguise) this).getName());
|
||||||
mods.write(2, (int) Math.floor(loc.getX() * 32));
|
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) {
|
public void constructWatcher(EntityType type, int entityId) {
|
||||||
@ -248,17 +260,63 @@ public class Disguise {
|
|||||||
else
|
else
|
||||||
watcher = new FlagWatcher(entityId);
|
watcher = new FlagWatcher(entityId);
|
||||||
}
|
}
|
||||||
HashMap<Integer, Object> entity = Values.getMetaValues(DisguiseType.getType(type));
|
HashMap<Integer, Object> disguiseValues = Values.getMetaValues(getType());
|
||||||
HashMap<Integer, Object> disguise = Values.getMetaValues(getType());
|
HashMap<Integer, Object> entityValues = Values.getMetaValues(DisguiseType.getType(type));
|
||||||
for (int i : entity.keySet()) {
|
// Start from 2 as they ALL share 0 and 1
|
||||||
if (!disguise.containsKey(i) || entity.get(i) != disguise.get(i)
|
for (int dataNo = 2; dataNo <= 31; dataNo++) {
|
||||||
|| entity.get(i).getClass() != disguise.get(i).getClass()) {
|
// If the watcher already set a metadata on this
|
||||||
if (disguise.containsKey(i)) {
|
if (watcher.getValue(dataNo, null) != null)
|
||||||
watcher.setValue(i, disguise.get(i));
|
continue;
|
||||||
} else {
|
// If neither of them touch it
|
||||||
watcher.setValue(i, null);
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,11 +81,13 @@ public class FlagWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean getFlag(int i) {
|
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) {
|
protected Object getValue(int no, Object backup) {
|
||||||
return entityValues.get(no);
|
if (entityValues.containsKey(no))
|
||||||
|
return entityValues.get(no);
|
||||||
|
return backup;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBurning() {
|
public boolean isBurning() {
|
||||||
@ -112,6 +114,10 @@ public class FlagWatcher {
|
|||||||
return getFlag(3);
|
return getFlag(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isTrue(int id, int no) {
|
||||||
|
return ((Byte) getValue(id, (byte) 0) & no) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
protected void sendData(int data) {
|
protected void sendData(int data) {
|
||||||
Object value = entityValues.get(data);
|
Object value = entityValues.get(data);
|
||||||
List<WatchableObject> list = new ArrayList<WatchableObject>();
|
List<WatchableObject> list = new ArrayList<WatchableObject>();
|
||||||
@ -133,51 +139,54 @@ public class FlagWatcher {
|
|||||||
|
|
||||||
public void setBurning(boolean setBurning) {
|
public void setBurning(boolean setBurning) {
|
||||||
if (isSneaking() != setBurning) {
|
if (isSneaking() != setBurning) {
|
||||||
setFlag(0, true);
|
setFlag(0, 0, true);
|
||||||
sendData(0);
|
sendData(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setFlag(int i, boolean flag) {
|
protected void setFlag(int id, int no, boolean flag) {
|
||||||
byte currentValue = (Byte) getValue(0);
|
if (isTrue(id, no) != flag) {
|
||||||
if (flag) {
|
byte b0 = (Byte) getValue(id, (byte) 0);
|
||||||
setValue(0, Byte.valueOf((byte) (currentValue | 1 << i)));
|
if (flag) {
|
||||||
} else {
|
setValue(id, (byte) (b0 | (no)));
|
||||||
setValue(0, Byte.valueOf((byte) (currentValue & ~(1 << i))));
|
} else {
|
||||||
|
setValue(id, (byte) (b0 & -(no + 1)));
|
||||||
|
}
|
||||||
|
sendData(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInvisible(boolean setInvis) {
|
public void setInvisible(boolean setInvis) {
|
||||||
if (isInvisible() != setInvis) {
|
if (isInvisible() != setInvis) {
|
||||||
setFlag(5, true);
|
setFlag(0, 5, true);
|
||||||
sendData(5);
|
sendData(5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRiding(boolean setRiding) {
|
public void setRiding(boolean setRiding) {
|
||||||
if (isSprinting() != setRiding) {
|
if (isSprinting() != setRiding) {
|
||||||
setFlag(2, true);
|
setFlag(0, 2, true);
|
||||||
sendData(2);
|
sendData(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRightClicking(boolean setRightClicking) {
|
public void setRightClicking(boolean setRightClicking) {
|
||||||
if (isRightClicking() != setRightClicking) {
|
if (isRightClicking() != setRightClicking) {
|
||||||
setFlag(4, true);
|
setFlag(0, 4, true);
|
||||||
sendData(4);
|
sendData(4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSneaking(boolean setSneaking) {
|
public void setSneaking(boolean setSneaking) {
|
||||||
if (isSneaking() != setSneaking) {
|
if (isSneaking() != setSneaking) {
|
||||||
setFlag(1, true);
|
setFlag(0, 1, true);
|
||||||
sendData(1);
|
sendData(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSprinting(boolean setSprinting) {
|
public void setSprinting(boolean setSprinting) {
|
||||||
if (isSprinting() != setSprinting) {
|
if (isSprinting() != setSprinting) {
|
||||||
setFlag(3, true);
|
setFlag(0, 3, true);
|
||||||
sendData(3);
|
sendData(3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,22 +4,21 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
public class Values {
|
public class Values {
|
||||||
|
|
||||||
private static HashMap<DisguiseType, HashMap<String, Double>> attributesValues = new HashMap<DisguiseType, HashMap<String, Double>>();
|
private static HashMap<DisguiseType, Values> values = new HashMap<DisguiseType, Values>();
|
||||||
private static HashMap<DisguiseType, HashMap<Integer, Object>> metaValues = new HashMap<DisguiseType, HashMap<Integer, Object>>();
|
|
||||||
|
|
||||||
public static HashMap<String, Double> getAttributesValues(DisguiseType type) {
|
public static HashMap<String, Double> getAttributesValues(DisguiseType type) {
|
||||||
if (type == DisguiseType.DONKEY || type == DisguiseType.MULE || type == DisguiseType.ZOMBIE_HORSE
|
return getValues(type).getAttributesValues();
|
||||||
|| type == DisguiseType.SKELETON_HORSE)
|
}
|
||||||
type = DisguiseType.HORSE;
|
|
||||||
if (type == DisguiseType.MINECART_CHEST || type == DisguiseType.MINECART_FURNACE || type == DisguiseType.MINECART_HOPPER
|
public static Class getEntityClass(DisguiseType type) {
|
||||||
|| type == DisguiseType.MINECART_TNT || type == DisguiseType.MINECART_MOB_SPAWNER)
|
return getValues(type).getEntityClass();
|
||||||
type = DisguiseType.MINECART_RIDEABLE;
|
|
||||||
if (type == DisguiseType.WITHER_SKELETON)
|
|
||||||
type = DisguiseType.SKELETON;
|
|
||||||
return attributesValues.get(type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<Integer, Object> getMetaValues(DisguiseType type) {
|
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
|
if (type == DisguiseType.DONKEY || type == DisguiseType.MULE || type == DisguiseType.ZOMBIE_HORSE
|
||||||
|| type == DisguiseType.SKELETON_HORSE)
|
|| type == DisguiseType.SKELETON_HORSE)
|
||||||
type = DisguiseType.HORSE;
|
type = DisguiseType.HORSE;
|
||||||
@ -28,22 +27,35 @@ public class Values {
|
|||||||
type = DisguiseType.MINECART_RIDEABLE;
|
type = DisguiseType.MINECART_RIDEABLE;
|
||||||
if (type == DisguiseType.WITHER_SKELETON)
|
if (type == DisguiseType.WITHER_SKELETON)
|
||||||
type = DisguiseType.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) {
|
private Class declared;
|
||||||
this.type = type;
|
|
||||||
metaValues.put(this.type, new HashMap<Integer, Object>());
|
private HashMap<Integer, Object> metaValues = new HashMap<Integer, Object>();
|
||||||
attributesValues.put(this.type, new HashMap<String, Double>());
|
|
||||||
|
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) {
|
public void setAttributesValue(String attribute, Double value) {
|
||||||
attributesValues.get(type).put(attribute, value);
|
attributesValues.put(attribute, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMetaValue(int no, Object value) {
|
public void setMetaValue(int no, Object value) {
|
||||||
metaValues.get(type).put(no, value);
|
metaValues.put(no, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,10 @@ public abstract class AgeableWatcher extends LivingWatcher {
|
|||||||
|
|
||||||
public AgeableWatcher(int entityId) {
|
public AgeableWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setValue(12, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAdult() {
|
public boolean isAdult() {
|
||||||
return (Integer) getValue(12) >= 0;
|
return (Integer) getValue(12, 0) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAdult(boolean isAdult) {
|
public void setAdult(boolean isAdult) {
|
||||||
|
@ -6,16 +6,14 @@ public class ArrowWatcher extends FlagWatcher {
|
|||||||
|
|
||||||
public ArrowWatcher(int entityId) {
|
public ArrowWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setValue(16, (byte) 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMoving() {
|
public boolean isMoving() {
|
||||||
return (Byte) getValue(16) == 1;
|
return (Byte) getValue(16, (byte) 0) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMoving(boolean moving) {
|
public void setMoving(boolean moving) {
|
||||||
setValue(16, (byte) (moving ? 1 : 0));
|
setValue(16, (byte) (moving ? 1 : 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,15 +4,14 @@ public class BatWatcher extends LivingWatcher {
|
|||||||
|
|
||||||
public BatWatcher(int entityId) {
|
public BatWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setValue(16, (byte) 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFlying() {
|
public boolean isFlying() {
|
||||||
return (Byte) getValue(16) == 0;
|
return (Byte) getValue(16, (byte) 1) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFlying(boolean flying) {
|
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));
|
setValue(16, (byte) (flying ? 1 : 0));
|
||||||
sendData(16);
|
sendData(16);
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,10 @@ public class BlazeWatcher extends LivingWatcher {
|
|||||||
|
|
||||||
public BlazeWatcher(int entityId) {
|
public BlazeWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setValue(16, (byte) 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBlazing() {
|
public boolean isBlazing() {
|
||||||
return (Byte) getValue(16) == 1;
|
return (Byte) getValue(16, (byte) 0) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBlazing(boolean isBlazing) {
|
public void setBlazing(boolean isBlazing) {
|
||||||
|
@ -6,20 +6,25 @@ public class BoatWatcher extends FlagWatcher {
|
|||||||
|
|
||||||
public BoatWatcher(int entityId) {
|
public BoatWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setValue(17, 10);
|
|
||||||
setValue(18, 0);
|
|
||||||
setValue(19, 40);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDamage(int dmg) {
|
public int getDamage() {
|
||||||
if ((Integer) getValue(19) != dmg) {
|
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);
|
setValue(19, dmg);
|
||||||
sendData(19);
|
sendData(19);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHealth(int health) {
|
public void setHealth(int health) {
|
||||||
if ((Integer) getValue(17) != health) {
|
if ((Integer) getValue(17, 10) != health) {
|
||||||
setValue(17, health);
|
setValue(17, health);
|
||||||
sendData(17);
|
sendData(17);
|
||||||
}
|
}
|
||||||
|
@ -4,24 +4,26 @@ public class CreeperWatcher extends LivingWatcher {
|
|||||||
|
|
||||||
public CreeperWatcher(int entityId) {
|
public CreeperWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setValue(16, (byte) 0);
|
|
||||||
setValue(17, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFused() {
|
public boolean isFused() {
|
||||||
return (Byte) getValue(16) == 1;
|
return (Byte) getValue(16, (byte) 0) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPowered() {
|
public boolean isPowered() {
|
||||||
return (Byte) getValue(17) == 0;
|
return (Byte) getValue(17, (byte) 0) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFuse(boolean isFused) {
|
public void setFuse(boolean isFused) {
|
||||||
|
if (isFused == isFused())
|
||||||
|
return;
|
||||||
setValue(16, (byte) (isFused ? 1 : -1));
|
setValue(16, (byte) (isFused ? 1 : -1));
|
||||||
sendData(16);
|
sendData(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPowered(boolean powered) {
|
public void setPowered(boolean powered) {
|
||||||
|
if (powered == isPowered())
|
||||||
|
return;
|
||||||
setValue(17, (byte) (powered ? 1 : 0));
|
setValue(17, (byte) (powered ? 1 : 0));
|
||||||
sendData(17);
|
sendData(17);
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ public class DonkeyWatcher extends HorseWatcher {
|
|||||||
|
|
||||||
public DonkeyWatcher(int entityId) {
|
public DonkeyWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setHorseType(1);
|
setValue(19, (byte) 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,11 +9,11 @@ public class DroppedItemWatcher extends FlagWatcher {
|
|||||||
|
|
||||||
public DroppedItemWatcher(int entityId) {
|
public DroppedItemWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setValue(10, CraftItemStack.asNMSCopy(new ItemStack(1)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getItemStack() {
|
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) {
|
public void setItemStack(ItemStack item) {
|
||||||
|
@ -4,16 +4,6 @@ public class EnderDragonWatcher extends LivingWatcher {
|
|||||||
|
|
||||||
public EnderDragonWatcher(int entityId) {
|
public EnderDragonWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setValue(16, 300);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getHealth() {
|
|
||||||
return (Integer) getValue(16);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHealth(int health) {
|
|
||||||
setValue(16, health);
|
|
||||||
sendData(16);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,30 +4,29 @@ public class EndermanWatcher extends LivingWatcher {
|
|||||||
|
|
||||||
public EndermanWatcher(int entityId) {
|
public EndermanWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setValue(16, (byte) 0);
|
|
||||||
setValue(17, (byte) 0);
|
|
||||||
setValue(18, (byte) 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCarriedData() {
|
public int getCarriedData() {
|
||||||
return ((Byte) getValue(17));
|
return ((Byte) getValue(17, (byte) 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCarriedId() {
|
public int getCarriedId() {
|
||||||
return ((Byte) getValue(16));
|
return ((Byte) getValue(16, (byte) 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAgressive() {
|
public boolean isAgressive() {
|
||||||
return (Integer) getValue(18) == 1;
|
return (Integer) getValue(18, (byte) 0) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAgressive(boolean isAgressive) {
|
public void setAgressive(boolean isAgressive) {
|
||||||
setValue(18, (byte) (isAgressive ? 1 : 0));
|
if (isAgressive() != isAgressive()) {
|
||||||
sendData(18);
|
setValue(18, (byte) (isAgressive ? 1 : 0));
|
||||||
|
sendData(18);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCarriedItem(int id, int dataValue) {
|
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(16, (byte) (id & 255));
|
||||||
setValue(17, (byte) (dataValue & 255));
|
setValue(17, (byte) (dataValue & 255));
|
||||||
sendData(16);
|
sendData(16);
|
||||||
|
@ -4,16 +4,17 @@ public class GhastWatcher extends LivingWatcher {
|
|||||||
|
|
||||||
public GhastWatcher(int entityId) {
|
public GhastWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setValue(16, (byte) 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAgressive() {
|
public boolean isAgressive() {
|
||||||
return (Byte) getValue(16) == 1;
|
return (Byte) getValue(16, (byte) 0) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAgressive(boolean isAgressive) {
|
public void setAgressive(boolean isAgressive) {
|
||||||
setValue(16, (byte) (isAgressive ? 1 : 0));
|
if (isAgressive() != isAgressive) {
|
||||||
sendData(16);
|
setValue(16, (byte) (isAgressive ? 1 : 0));
|
||||||
|
sendData(16);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,23 +2,24 @@ package me.libraryaddict.disguise.DisguiseTypes.Watchers;
|
|||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Horse.Color;
|
||||||
|
import org.bukkit.entity.Horse.Style;
|
||||||
|
|
||||||
public class HorseWatcher extends AgeableWatcher {
|
public class HorseWatcher extends AgeableWatcher {
|
||||||
|
|
||||||
public HorseWatcher(int entityId) {
|
public HorseWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setValue(16, 0);
|
setValue(16, 0);
|
||||||
setValue(19, (byte) 0);
|
|
||||||
setValue(20, new Random().nextInt(7));
|
setValue(20, new Random().nextInt(7));
|
||||||
setValue(21, "");
|
|
||||||
setValue(22, 0);
|
setValue(22, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getColoring() {
|
public Color getColor() {
|
||||||
return (Integer) getValue(20);
|
return Color.values()[((Integer) getValue(20, 0) & 0xFF)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHorseType() {
|
public Style getStyle() {
|
||||||
return (int) (Byte) getValue(19);
|
return Style.values()[((Integer) getValue(20, 0) >>> 8)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasChest() {
|
public boolean hasChest() {
|
||||||
@ -50,7 +51,7 @@ public class HorseWatcher extends AgeableWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isTrue(int i) {
|
private boolean isTrue(int i) {
|
||||||
return ((Integer) getValue(16) & i) != 0;
|
return ((Integer) getValue(16, (byte) 0) & i) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCanBred(boolean bred) {
|
public void setCanBred(boolean bred) {
|
||||||
@ -61,14 +62,14 @@ public class HorseWatcher extends AgeableWatcher {
|
|||||||
setFlag(8, true);
|
setFlag(8, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColoring(int color) {
|
public void setColor(Color color) {
|
||||||
setValue(20, color);
|
setValue(20, color.ordinal() & 0xFF | getStyle().ordinal() << 8);
|
||||||
sendData(20);
|
sendData(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setFlag(int i, boolean flag) {
|
private void setFlag(int i, boolean flag) {
|
||||||
if (isTrue(i) != flag) {
|
if (isTrue(i) != flag) {
|
||||||
int j = (Integer) getValue(16);
|
int j = (Integer) getValue(16, (byte) 0);
|
||||||
if (flag) {
|
if (flag) {
|
||||||
setValue(16, j | i);
|
setValue(16, j | i);
|
||||||
} else {
|
} else {
|
||||||
@ -82,11 +83,6 @@ public class HorseWatcher extends AgeableWatcher {
|
|||||||
setFlag(32, grazing);
|
setFlag(32, grazing);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHorseType(int type) {
|
|
||||||
setValue(19, (byte) type);
|
|
||||||
sendData(19);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMouthOpen(boolean mouthOpen) {
|
public void setMouthOpen(boolean mouthOpen) {
|
||||||
setFlag(128, mouthOpen);
|
setFlag(128, mouthOpen);
|
||||||
}
|
}
|
||||||
@ -99,6 +95,11 @@ public class HorseWatcher extends AgeableWatcher {
|
|||||||
setFlag(4, saddled);
|
setFlag(4, saddled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setStyle(Style style) {
|
||||||
|
setValue(20, getColor().ordinal() & 0xFF | style.ordinal() << 8);
|
||||||
|
sendData(20);
|
||||||
|
}
|
||||||
|
|
||||||
public void setTamed(boolean tamed) {
|
public void setTamed(boolean tamed) {
|
||||||
setFlag(2, tamed);
|
setFlag(2, tamed);
|
||||||
}
|
}
|
||||||
|
@ -9,14 +9,14 @@ public class ItemFrameWatcher extends FlagWatcher {
|
|||||||
|
|
||||||
public ItemFrameWatcher(int entityId) {
|
public ItemFrameWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setValue(2, 5);
|
// setValue(2, CraftItemStack.asCraftCopy(new ItemStack(0)));
|
||||||
setValue(3, (byte) 0);
|
// setValue(3, (byte) 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getItemStack() {
|
public ItemStack getItemStack() {
|
||||||
if (getValue(3) instanceof Integer)
|
if (getValue(3, (byte) 0) instanceof Integer)
|
||||||
return new ItemStack(0);
|
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) {
|
public void setItemStack(ItemStack newItem) {
|
||||||
|
@ -16,8 +16,6 @@ public class LivingWatcher extends FlagWatcher {
|
|||||||
|
|
||||||
public LivingWatcher(int entityId) {
|
public LivingWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setValue(10, "");
|
|
||||||
setValue(11, (byte) 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPotionEffect(PotionEffect potionEffect) {
|
public void addPotionEffect(PotionEffect potionEffect) {
|
||||||
@ -28,11 +26,15 @@ public class LivingWatcher extends FlagWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getCustomName() {
|
public String getCustomName() {
|
||||||
return (String) getValue(10);
|
return (String) getValue(10, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getHealth() {
|
||||||
|
return (Float) getValue(6, 0F);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getPotionParticlesRemoved() {
|
public boolean getPotionParticlesRemoved() {
|
||||||
return (Byte) getValue(8) == 1;
|
return (Byte) getValue(8, (byte) 0) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasCustomName() {
|
public boolean hasCustomName() {
|
||||||
@ -46,6 +48,10 @@ public class LivingWatcher extends FlagWatcher {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isCustomNameVisible() {
|
||||||
|
return (Byte) getValue(11, (byte) 0) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
public void removePotionEffect(PotionEffectType type) {
|
public void removePotionEffect(PotionEffectType type) {
|
||||||
Iterator<MobEffect> itel = potionEffects.iterator();
|
Iterator<MobEffect> itel = potionEffects.iterator();
|
||||||
while (itel.hasNext()) {
|
while (itel.hasNext()) {
|
||||||
@ -78,10 +84,15 @@ public class LivingWatcher extends FlagWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setCustomNameVisible(boolean display) {
|
public void setCustomNameVisible(boolean display) {
|
||||||
if ((Byte) getValue(11) != (display ? 1 : 0)) {
|
if (this.isCustomNameVisible()) {
|
||||||
setValue(11, (byte) (display ? 1 : 0));
|
setValue(11, (byte) (display ? 1 : 0));
|
||||||
sendData(11);
|
sendData(11);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setHealth(float health) {
|
||||||
|
setValue(6, health);
|
||||||
|
sendData(6);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,14 @@ public class MinecartWatcher extends FlagWatcher {
|
|||||||
super(entityId);
|
super(entityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getDamage() {
|
||||||
|
if (getValue(19, 0F) != null)
|
||||||
|
return (Float) getValue(19, 0F);
|
||||||
|
return 0F;
|
||||||
|
}
|
||||||
|
|
||||||
public void setDamage(float damage) {
|
public void setDamage(float damage) {
|
||||||
setValue(19, damage);
|
setValue(19, damage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getDamage() {
|
|
||||||
if (getValue(19) != null)
|
|
||||||
return (Float) getValue(19);
|
|
||||||
return 0F;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ public class MuleWatcher extends HorseWatcher {
|
|||||||
|
|
||||||
public MuleWatcher(int entityId) {
|
public MuleWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setHorseType(2);
|
setValue(19, (byte) 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,33 +7,14 @@ public class OcelotWatcher extends AgeableWatcher {
|
|||||||
|
|
||||||
public OcelotWatcher(int entityId) {
|
public OcelotWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setValue(16, (byte) 0);
|
|
||||||
setValue(17, "");
|
|
||||||
setValue(18, (byte) 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOwner() {
|
public String getOwner() {
|
||||||
return (String) getValue(17);
|
return (String) getValue(17, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type getType() {
|
public Type getType() {
|
||||||
return Ocelot.Type.getType((Byte) getValue(18));
|
return Ocelot.Type.getType((Byte) getValue(18, (byte) 0));
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOwner(String newOwner) {
|
public void setOwner(String newOwner) {
|
||||||
@ -41,11 +22,11 @@ public class OcelotWatcher extends AgeableWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setSitting(boolean sitting) {
|
public void setSitting(boolean sitting) {
|
||||||
setFlag(1, sitting);
|
setFlag(16, 1, sitting);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTamed(boolean tamed) {
|
public void setTamed(boolean tamed) {
|
||||||
setFlag(4, tamed);
|
setFlag(16, 4, tamed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(Type newType) {
|
public void setType(Type newType) {
|
||||||
|
@ -4,11 +4,10 @@ public class PigWatcher extends AgeableWatcher {
|
|||||||
|
|
||||||
public PigWatcher(int entityId) {
|
public PigWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setValue(16, (byte) 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSaddled() {
|
public boolean isSaddled() {
|
||||||
return (Byte) getValue(16) == 0;
|
return (Byte) getValue(16, (byte) 0) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSaddled(boolean isSaddled) {
|
public void setSaddled(boolean isSaddled) {
|
||||||
|
@ -4,11 +4,10 @@ public class PigZombieWatcher extends LivingWatcher {
|
|||||||
|
|
||||||
public PigZombieWatcher(int entityId) {
|
public PigZombieWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setValue(12, (byte) 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBaby() {
|
public boolean isBaby() {
|
||||||
return (Byte) getValue(12) == 1;
|
return (Byte) getValue(12, (byte) 0) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBaby(boolean baby) {
|
public void setBaby(boolean baby) {
|
||||||
|
@ -4,12 +4,10 @@ public class PlayerWatcher extends LivingWatcher {
|
|||||||
|
|
||||||
public PlayerWatcher(int entityId) {
|
public PlayerWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setValue(9, (byte) 0);
|
|
||||||
setValue(18, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getArrowsSticking() {
|
public int getArrowsSticking() {
|
||||||
return (Byte) getValue(9);
|
return (Byte) getValue(9, (byte) 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setArrowsSticking(int arrowsNo) {
|
public void setArrowsSticking(int arrowsNo) {
|
||||||
|
@ -10,16 +10,16 @@ public class SheepWatcher extends AgeableWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public AnimalColor getColor() {
|
public AnimalColor getColor() {
|
||||||
return AnimalColor.values()[(Byte) getValue(16) & 15];
|
return AnimalColor.values()[(Byte) getValue(16, (byte) 0) & 15];
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSheared() {
|
public boolean isSheared() {
|
||||||
return ((Byte) getValue(16) & 16) != 0;
|
return ((Byte) getValue(16, (byte) 0) & 16) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColor(AnimalColor color) {
|
public void setColor(AnimalColor color) {
|
||||||
if (getColor() != color) {
|
if (getColor() != color) {
|
||||||
byte b0 = (Byte) getValue(16);
|
byte b0 = (Byte) getValue(16, (byte) 0);
|
||||||
setValue(16, (byte) (b0 & 240 | color.getId() & 15));
|
setValue(16, (byte) (b0 & 240 | color.getId() & 15));
|
||||||
sendData(16);
|
sendData(16);
|
||||||
}
|
}
|
||||||
@ -27,7 +27,7 @@ public class SheepWatcher extends AgeableWatcher {
|
|||||||
|
|
||||||
public void setSheared(boolean flag) {
|
public void setSheared(boolean flag) {
|
||||||
if (isSheared() != flag) {
|
if (isSheared() != flag) {
|
||||||
byte b0 = (Byte) getValue(16);
|
byte b0 = (Byte) getValue(16, (byte) 0);
|
||||||
if (flag) {
|
if (flag) {
|
||||||
setValue(16, (byte) (b0 | 16));
|
setValue(16, (byte) (b0 | 16));
|
||||||
} else {
|
} else {
|
||||||
|
@ -4,7 +4,7 @@ public class SkeletonHorseWatcher extends HorseWatcher {
|
|||||||
|
|
||||||
public SkeletonHorseWatcher(int entityId) {
|
public SkeletonHorseWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setHorseType(4);
|
setValue(19, (byte) 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ public class SkeletonWatcher extends LivingWatcher {
|
|||||||
|
|
||||||
public SkeletonWatcher(int entityId) {
|
public SkeletonWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setValue(13, (byte) 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,10 @@ public class SlimeWatcher extends LivingWatcher {
|
|||||||
public SlimeWatcher(int entityId) {
|
public SlimeWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setValue(16, (byte) (new Random().nextInt(4) + 1));
|
setValue(16, (byte) (new Random().nextInt(4) + 1));
|
||||||
setValue(18, (byte) 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
return (Integer) getValue(16);
|
return (Integer) getValue(16, (byte) 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSize(int size) {
|
public void setSize(int size) {
|
||||||
|
@ -12,7 +12,7 @@ public class VillagerWatcher extends AgeableWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Profession getProfession() {
|
public Profession getProfession() {
|
||||||
return Profession.values()[(Integer) getValue(16)];
|
return Profession.values()[(Integer) getValue(16, 0)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProfession(Profession newProfession) {
|
public void setProfession(Profession newProfession) {
|
||||||
|
@ -6,23 +6,18 @@ public class WolfWatcher extends AgeableWatcher {
|
|||||||
|
|
||||||
public WolfWatcher(int entityId) {
|
public WolfWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setValue(16, (byte) 0);
|
|
||||||
setValue(17, "");
|
|
||||||
setValue(18, 8F);
|
|
||||||
setValue(19, (byte) 0);
|
|
||||||
setValue(20, (byte) 14);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public AnimalColor getCollarColor() {
|
public AnimalColor getCollarColor() {
|
||||||
return AnimalColor.values()[(Byte) getValue(20)];
|
return AnimalColor.values()[(Byte) getValue(20, (byte) 14)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getHealth() {
|
public float getHealth() {
|
||||||
return (Float) getValue(18);
|
return (Float) getValue(18, 8F);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return (String) getValue(17);
|
return (String) getValue(17, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAngry() {
|
public boolean isAngry() {
|
||||||
@ -38,7 +33,7 @@ public class WolfWatcher extends AgeableWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isTrue(int no) {
|
private boolean isTrue(int no) {
|
||||||
return ((Byte) getValue(16) & no) != 0;
|
return ((Byte) getValue(16, (byte) 0) & no) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAngry(boolean angry) {
|
public void setAngry(boolean angry) {
|
||||||
@ -54,7 +49,7 @@ public class WolfWatcher extends AgeableWatcher {
|
|||||||
|
|
||||||
private void setFlag(int no, boolean flag) {
|
private void setFlag(int no, boolean flag) {
|
||||||
if (isTrue(no) != flag) {
|
if (isTrue(no) != flag) {
|
||||||
byte b0 = (Byte) getValue(16);
|
byte b0 = (Byte) getValue(16, (byte) 0);
|
||||||
if (flag) {
|
if (flag) {
|
||||||
setValue(16, (byte) (b0 | (no)));
|
setValue(16, (byte) (b0 | (no)));
|
||||||
} else {
|
} else {
|
||||||
|
@ -4,7 +4,7 @@ public class ZombieHorseWatcher extends HorseWatcher {
|
|||||||
|
|
||||||
public ZombieHorseWatcher(int entityId) {
|
public ZombieHorseWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setHorseType(3);
|
setValue(19, (byte) 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,10 @@ public class ZombieWatcher extends PigZombieWatcher {
|
|||||||
|
|
||||||
public ZombieWatcher(int entityId) {
|
public ZombieWatcher(int entityId) {
|
||||||
super(entityId);
|
super(entityId);
|
||||||
setValue(13, (byte) 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVillager() {
|
public boolean isVillager() {
|
||||||
return (Byte) getValue(13) == 1;
|
return (Byte) getValue(13, (byte) 0) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVillager(boolean villager) {
|
public void setVillager(boolean villager) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package me.libraryaddict.disguise;
|
package me.libraryaddict.disguise;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -93,7 +94,7 @@ public class LibsDisguises extends JavaPlugin implements Listener {
|
|||||||
@Override
|
@Override
|
||||||
public void onPacketSending(PacketEvent event) {
|
public void onPacketSending(PacketEvent event) {
|
||||||
try {
|
try {
|
||||||
Player observer = event.getPlayer();
|
final Player observer = event.getPlayer();
|
||||||
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld());
|
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld());
|
||||||
org.bukkit.entity.Entity entity = entityModifer.read((Packets.Server.COLLECT == event.getPacketID() ? 1 : 0));
|
org.bukkit.entity.Entity entity = entityModifer.read((Packets.Server.COLLECT == event.getPacketID() ? 1 : 0));
|
||||||
if (entity == observer)
|
if (entity == observer)
|
||||||
@ -131,18 +132,54 @@ public class LibsDisguises extends JavaPlugin implements Listener {
|
|||||||
String name = (String) mods.read(1);
|
String name = (String) mods.read(1);
|
||||||
if (!name.equals(((PlayerDisguise) disguise).getName())) {
|
if (!name.equals(((PlayerDisguise) disguise).getName())) {
|
||||||
// manager.sendServerPacket(observer, disguise.constructDestroyPacket(entity.getEntityId()));
|
// 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 {
|
} else {
|
||||||
// manager.sendServerPacket(observer, disguise.constructDestroyPacket(entity.getEntityId()));
|
// 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
|
} else if (event.getPacketID() == Packets.Server.MOB_SPAWN
|
||||||
|| event.getPacketID() == Packets.Server.ADD_EXP_ORB
|
|| event.getPacketID() == Packets.Server.ADD_EXP_ORB
|
||||||
|| event.getPacketID() == Packets.Server.VEHICLE_SPAWN
|
|| event.getPacketID() == Packets.Server.VEHICLE_SPAWN
|
||||||
|| event.getPacketID() == Packets.Server.ENTITY_PAINTING) {
|
|| event.getPacketID() == Packets.Server.ENTITY_PAINTING) {
|
||||||
// manager.sendServerPacket(observer, disguise.constructDestroyPacket(entity.getEntityId()));
|
// 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
|
} else if (event.getPacketID() == Packets.Server.ARM_ANIMATION
|
||||||
|| event.getPacketID() == Packets.Server.COLLECT) {
|
|| event.getPacketID() == Packets.Server.COLLECT) {
|
||||||
if (disguise.getType().isMisc()) {
|
if (disguise.getType().isMisc()) {
|
||||||
@ -156,13 +193,13 @@ public class LibsDisguises extends JavaPlugin implements Listener {
|
|||||||
if (disguise.getType() == DisguiseType.ENDER_DRAGON) {
|
if (disguise.getType() == DisguiseType.ENDER_DRAGON) {
|
||||||
byte value = (Byte) mods.read(4);
|
byte value = (Byte) mods.read(4);
|
||||||
mods.write(4, (byte) (value - 128));
|
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);
|
byte value = (Byte) mods.read(4);
|
||||||
if (disguise.getType() != DisguiseType.PAINTING)
|
if (disguise.getType() == DisguiseType.ITEM_FRAME) {
|
||||||
mods.write(4, (byte) (value + 128));
|
mods.write(4, -value);
|
||||||
else if (disguise.getType().isMisc())
|
} else if (disguise.getType() == DisguiseType.PAINTING) {
|
||||||
mods.write(4, (byte) -(value + 128));
|
mods.write(4, -(value + 128));
|
||||||
else
|
} else if (disguise.getType().isMisc())
|
||||||
mods.write(4, (byte) (value - 64));
|
mods.write(4, (byte) (value - 64));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -255,13 +292,15 @@ public class LibsDisguises extends JavaPlugin implements Listener {
|
|||||||
name = "LargeFireball";
|
name = "LargeFireball";
|
||||||
try {
|
try {
|
||||||
net.minecraft.server.v1_6_R2.Entity entity = null;
|
net.minecraft.server.v1_6_R2.Entity entity = null;
|
||||||
|
Class entityClass;
|
||||||
if (disguiseType == DisguiseType.PLAYER) {
|
if (disguiseType == DisguiseType.PLAYER) {
|
||||||
|
entityClass = EntityHuman.class;
|
||||||
entity = new DisguiseHuman(world);
|
entity = new DisguiseHuman(world);
|
||||||
} else {
|
} 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);
|
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();
|
List<WatchableObject> watchers = entity.getDataWatcher().c();
|
||||||
for (WatchableObject watch : watchers)
|
for (WatchableObject watch : watchers)
|
||||||
value.setMetaValue(watch.a(), watch.b());
|
value.setMetaValue(watch.a(), watch.b());
|
||||||
|
Loading…
Reference in New Issue
Block a user