Read description

Updated libs disguise to use custom datawatchers.
This ensures that I can now set custom flags on disguises.

Also fixes it looking bugged
This commit is contained in:
Andrew 2013-05-19 15:44:13 +12:00
parent 567200ca4d
commit 86eb1f9af3
36 changed files with 561 additions and 163 deletions

1
.gitignore vendored
View File

@ -15,6 +15,7 @@ local.properties
.classpath .classpath
.settings/ .settings/
.loadpath .loadpath
target/
# External tool builders # External tool builders
.externalToolBuilders/ .externalToolBuilders/

View File

@ -3,8 +3,6 @@ package me.libraryaddict.disguise;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import me.libraryaddict.disguise.DisguiseTypes.Disguise; import me.libraryaddict.disguise.DisguiseTypes.Disguise;
import me.libraryaddict.disguise.DisguiseTypes.MobDisguise;
import me.libraryaddict.disguise.DisguiseTypes.PlayerDisguise;
import net.minecraft.server.v1_5_R3.*; import net.minecraft.server.v1_5_R3.*;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -42,26 +40,7 @@ public class DisguiseAPI {
public static void disguiseToPlayer(Player disguiser, Player observer, Disguise disguise) { public static void disguiseToPlayer(Player disguiser, Player observer, Disguise disguise) {
disguises.put(disguiser.getName(), disguise); disguises.put(disguiser.getName(), disguise);
Packet29DestroyEntity destroyPacket = new Packet29DestroyEntity(new int[] { disguiser.getEntityId() }); Packet29DestroyEntity destroyPacket = new Packet29DestroyEntity(new int[] { disguiser.getEntityId() });
Packet spawnPacket = null; Packet spawnPacket = disguise.constructPacket(disguiser);
if (disguise.getType().isMob()) {
EntityLiving entityLiving = ((MobDisguise) disguise).getEntityLiving(((CraftPlayer) disguiser).getHandle().world,
disguiser.getLocation(), disguiser.getEntityId());
spawnPacket = new Packet24MobSpawn(entityLiving);
} else if (disguise.getType().isMisc()) {
Entity entity = disguise.getEntity(((CraftPlayer) disguiser).getHandle().world, disguiser.getLocation(),
disguiser.getEntityId());
spawnPacket = new Packet23VehicleSpawn(entity, 0);
} else if (disguise.getType().isPlayer()) {
EntityHuman entityHuman = ((CraftPlayer) disguiser).getHandle();
spawnPacket = new Packet20NamedEntitySpawn(entityHuman);
((Packet20NamedEntitySpawn) spawnPacket).b = ((PlayerDisguise) disguise).getName();
}
((CraftPlayer) observer).getHandle().playerConnection.sendPacket(destroyPacket); ((CraftPlayer) observer).getHandle().playerConnection.sendPacket(destroyPacket);
((CraftPlayer) observer).getHandle().playerConnection.sendPacket(spawnPacket); ((CraftPlayer) observer).getHandle().playerConnection.sendPacket(spawnPacket);

View File

@ -0,0 +1,16 @@
package me.libraryaddict.disguise.DisguiseTypes;
public enum AnimalColor {
BLACK(15), BLUE(11), BROWN(
12), CYAN(9), GRAY(7), GREEN(13), LIGHT_BLUE(3), LIME(5), MAGENTA(2), ORANGE(1), PINK(6), PURPLE(10), RED(14), SILVER(8), WHITE(0), YELLOW(4);
private int value;
private AnimalColor(int newValue) {
value = newValue;
}
public int getId() {
return value;
}
}

View File

@ -1,20 +1,58 @@
package me.libraryaddict.disguise.DisguiseTypes; package me.libraryaddict.disguise.DisguiseTypes;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import me.libraryaddict.disguise.DisguiseTypes.Watchers.AgeableWatcher;
import net.minecraft.server.v1_5_R3.Entity; import net.minecraft.server.v1_5_R3.Entity;
import net.minecraft.server.v1_5_R3.EntityCreeper; import net.minecraft.server.v1_5_R3.EntityAgeable;
import net.minecraft.server.v1_5_R3.EntityHuman;
import net.minecraft.server.v1_5_R3.EntityLiving;
import net.minecraft.server.v1_5_R3.EntitySkeleton; import net.minecraft.server.v1_5_R3.EntitySkeleton;
import net.minecraft.server.v1_5_R3.Packet;
import net.minecraft.server.v1_5_R3.Packet20NamedEntitySpawn;
import net.minecraft.server.v1_5_R3.Packet23VehicleSpawn;
import net.minecraft.server.v1_5_R3.Packet24MobSpawn;
import net.minecraft.server.v1_5_R3.World; import net.minecraft.server.v1_5_R3.World;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class Disguise { public class Disguise {
protected DisguiseType disguiseType; protected DisguiseType disguiseType;
private Entity entity; private Entity entity;
private LibsBaseWatcher watcher;
protected Disguise(DisguiseType newType) { protected Disguise(DisguiseType newType) {
disguiseType = newType; disguiseType = newType;
} }
public Packet constructPacket(Player p) {
Packet spawnPacket = null;
if (getType().isMob()) {
EntityLiving entityLiving = ((MobDisguise) this).getEntityLiving(((CraftPlayer) p).getHandle().world,
p.getLocation(), p.getEntityId());
spawnPacket = new Packet24MobSpawn(entityLiving);
} else if (getType().isMisc()) {
Entity entity = getEntity(((CraftPlayer) p).getHandle().world, p.getLocation(), p.getEntityId());
spawnPacket = new Packet23VehicleSpawn(entity, 0);
} else if (getType().isPlayer()) {
EntityHuman entityHuman = ((CraftPlayer) p).getHandle();
spawnPacket = new Packet20NamedEntitySpawn(entityHuman);
((Packet20NamedEntitySpawn) spawnPacket).b = ((PlayerDisguise) this).getName();
}
return spawnPacket;
}
public Entity getEntity() {
return entity;
}
public Entity getEntity(World world, Location loc, int entityId) { public Entity getEntity(World world, Location loc, int entityId) {
Entity entity = null; Entity entity = null;
try { try {
@ -22,9 +60,6 @@ public class Disguise {
if (disguiseType == DisguiseType.WITHER_SKELETON) { if (disguiseType == DisguiseType.WITHER_SKELETON) {
name = "Skeleton"; name = "Skeleton";
} }
if (disguiseType == DisguiseType.CHARGED_CREEPER) {
name = "Creeper";
}
if (disguiseType == DisguiseType.TNT_PRIMED) { if (disguiseType == DisguiseType.TNT_PRIMED) {
name = "TNTPrimed"; name = "TNTPrimed";
} }
@ -34,15 +69,31 @@ public class Disguise {
if (disguiseType == DisguiseType.WITHER_SKELETON) { if (disguiseType == DisguiseType.WITHER_SKELETON) {
((EntitySkeleton) entity).setSkeletonType(1); ((EntitySkeleton) entity).setSkeletonType(1);
} }
if (disguiseType == DisguiseType.CHARGED_CREEPER) {
((EntityCreeper) entity).setPowered(true);
}
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
entity.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); entity.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
entity.id = entityId; entity.id = entityId;
this.entity = entity; this.entity = entity;
try {
String name;
if (getType().isPlayer()) {
name = "Player";
} else {
name = toReadable(getType().name());
}
Class watcherClass = Class.forName("me.libraryaddict.disguise.DisguiseTypes.Watchers." + name + "Watcher");
Constructor<?> contructor = watcherClass.getDeclaredConstructor(int.class);
watcher = (LibsBaseWatcher) contructor.newInstance(entityId);
} catch (Exception ex) {
// There is no watcher for this entity
}
if (watcher == null && entity instanceof EntityAgeable && this instanceof MobDisguise) {
watcher = new AgeableWatcher(entityId);
}
if (watcher instanceof AgeableWatcher && this instanceof MobDisguise) {
((AgeableWatcher) watcher).setValue(12, ((MobDisguise) this).isAdult() ? 0 : -23999);
}
return entity; return entity;
} }
@ -50,8 +101,12 @@ public class Disguise {
return disguiseType; return disguiseType;
} }
public Entity getEntity() { public LibsBaseWatcher getWatcher() {
return entity; return watcher;
}
public boolean hasWatcher() {
return watcher != null;
} }
private String toReadable(String string) { private String toReadable(String string) {

View File

@ -1,14 +1,13 @@
package me.libraryaddict.disguise.DisguiseTypes; package me.libraryaddict.disguise.DisguiseTypes;
public enum DisguiseType { public enum DisguiseType {
BAT(EntityType.MOB), BLAZE(EntityType.MOB), CAVE_SPIDER(EntityType.MOB), CHARGED_CREEPER(EntityType.MOB), CHICKEN( BAT(EntityType.MOB), BLAZE(EntityType.MOB), CAVE_SPIDER(EntityType.MOB), CHICKEN(EntityType.MOB), COW(EntityType.MOB), CREEPER(
EntityType.MOB), COW(EntityType.MOB), CREEPER(EntityType.MOB), ENDER_CRYSTAL(EntityType.MISC), ENDER_DRAGON( EntityType.MOB), ENDER_CRYSTAL(EntityType.MISC), ENDER_DRAGON(EntityType.MOB), ENDERMAN(EntityType.MOB), GHAST(
EntityType.MOB), ENDERMAN(EntityType.MOB), GHAST(EntityType.MOB), GIANT_ZOMBIE(EntityType.MOB), IRON_GOLEM(EntityType.MOB), MAGMA_CUBE( EntityType.MOB), GIANT_ZOMBIE(EntityType.MOB), IRON_GOLEM(EntityType.MOB), MAGMA_CUBE(EntityType.MOB), MUSHROOM_COW(
EntityType.MOB), MUSHROOM_COW(EntityType.MOB), OCELOT(EntityType.MOB), PIG(EntityType.MOB), PIG_ZOMBIE(EntityType.MOB), PLAYER( EntityType.MOB), OCELOT(EntityType.MOB), PIG(EntityType.MOB), PIG_ZOMBIE(EntityType.MOB), PLAYER(EntityType.PLAYER), SHEEP(EntityType.MOB), SILVERFISH(EntityType.MOB), SKELETON(EntityType.MOB), SLIME(EntityType.MOB), SNOWMAN(
EntityType.PLAYER), TNT_PRIMED(EntityType.MISC), SHEEP(EntityType.MOB), SILVERFISH(EntityType.MOB), SKELETON( EntityType.MOB), SPIDER(EntityType.MOB), SQUID(EntityType.MOB), TNT_PRIMED(
EntityType.MOB), SLIME(EntityType.MOB), SNOWMAN(EntityType.MOB), SPIDER(EntityType.MOB), SQUID(EntityType.MOB), VILLAGER( EntityType.MISC), VILLAGER(EntityType.MOB), WITCH(EntityType.MOB), WITHER(
EntityType.MOB), WITCH(EntityType.MOB), WITHER(EntityType.MOB), WITHER_SKELETON(EntityType.MOB), WOLF(EntityType.MOB), ZOMBIE( EntityType.MOB), WITHER_SKELETON(EntityType.MOB), WOLF(EntityType.MOB), ZOMBIE(EntityType.MOB);
EntityType.MOB);
public static enum EntityType { public static enum EntityType {
MISC, MOB, PLAYER; MISC, MOB, PLAYER;

View File

@ -0,0 +1,91 @@
package me.libraryaddict.disguise.DisguiseTypes;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_5_R3.Packet40EntityMetadata;
import net.minecraft.server.v1_5_R3.WatchableObject;
public abstract class LibsBaseWatcher {
private static HashMap<Class, Integer> classTypes = new HashMap<Class, Integer>();
static {
classTypes.put(Byte.class, 0);
classTypes.put(Short.class, 1);
classTypes.put(Integer.class, 2);
classTypes.put(String.class, 4);
}
private int entityId;
private HashMap<Integer, Object> entityValues = new HashMap<Integer, Object>();
protected LibsBaseWatcher(int entityId) {
this.entityId = entityId;
}
public List<WatchableObject> convert(List<WatchableObject> list) {
Iterator<WatchableObject> itel = list.iterator();
List<WatchableObject> newList = new ArrayList<WatchableObject>();
while (itel.hasNext()) {
WatchableObject watch = itel.next();
if (entityValues.containsKey(watch.a())) {
boolean doD = watch.d();
watch = new WatchableObject(watch.c(), watch.a(), watch.b());
if (!doD)
watch.a(false);
if (entityValues.get(watch.a()) == null) {
continue;
} else {
Object value = entityValues.get(watch.a());
if (watch.b().getClass() != value.getClass()) {
watch.a(value);
try {
Field field = WatchableObject.class.getDeclaredField("a");
field.setAccessible(true);
field.set(watch, classTypes.get(value.getClass()));
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
watch.a(entityValues.get(watch.a()));
}
}
}
newList.add(watch);
}
return newList;
}
protected Object getValue(int no) {
return entityValues.get(no);
}
protected void sendData(int data) {
Packet40EntityMetadata packet = new Packet40EntityMetadata();
try {
packet.a = entityId;
Field field = Packet40EntityMetadata.class.getDeclaredField("b");
field.setAccessible(true);
Object value = entityValues.get(data);
List<WatchableObject> list = new ArrayList<WatchableObject>();
list.add(new WatchableObject(classTypes.get(value.getClass()), data, value));
field.set(packet, list);
} catch (Exception ex) {
ex.printStackTrace();
}
for (Player p : Bukkit.getOnlinePlayers()) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
}
}
protected void setValue(int no, Object value) {
entityValues.put(no, value);
}
}

View File

@ -17,7 +17,7 @@ public class MobDisguise extends Disguise {
adult = isAdult; adult = isAdult;
} }
public EntityLiving getEntityLiving(World w, Location loc, int id) { protected EntityLiving getEntityLiving(World w, Location loc, int id) {
Entity entity = getEntity(w, loc, id); Entity entity = getEntity(w, loc, id);
if (!adult) { if (!adult) {
if (entity instanceof EntityAgeable) if (entity instanceof EntityAgeable)

View File

@ -0,0 +1,23 @@
package me.libraryaddict.disguise.DisguiseTypes.Watchers;
import me.libraryaddict.disguise.DisguiseTypes.LibsBaseWatcher;
public class AgeableWatcher extends LibsBaseWatcher {
public AgeableWatcher(int entityId) {
super(entityId);
setValue(12, 0);
}
public boolean isAdult() {
return (Integer) getValue(12) >= 0;
}
public void setAdult(boolean isAdult) {
if (isAdult != isAdult()) {
setValue(12, isAdult ? 0 : -23999);
sendData(12);
}
}
}

View File

@ -0,0 +1,21 @@
package me.libraryaddict.disguise.DisguiseTypes.Watchers;
import me.libraryaddict.disguise.DisguiseTypes.LibsBaseWatcher;
public class BlazeWatcher extends LibsBaseWatcher {
public BlazeWatcher(int entityId) {
super(entityId);
setValue(16, (byte) 0);
}
public boolean isBlazing() {
return (Byte) getValue(16) == 0;
}
public void setBlazing(boolean isBlazing) {
setValue(16, (byte) (isBlazing ? 1 : 0));
sendData(16);
}
}

View File

@ -0,0 +1,31 @@
package me.libraryaddict.disguise.DisguiseTypes.Watchers;
import me.libraryaddict.disguise.DisguiseTypes.LibsBaseWatcher;
public class CreeperWatcher extends LibsBaseWatcher {
public CreeperWatcher(int entityId) {
super(entityId);
setValue(16, (byte) -1);
setValue(17, 0);
}
public boolean isFused() {
return (Byte) getValue(16) == 1;
}
public boolean isPowered() {
return (Byte) getValue(17) == 0;
}
public void setFuse(boolean isFused) {
setValue(16, (byte) (isFused ? 1 : -1));
sendData(16);
}
public void setPowered(boolean powered) {
setValue(17, (byte) (powered ? 1 : 0));
sendData(17);
}
}

View File

@ -0,0 +1,21 @@
package me.libraryaddict.disguise.DisguiseTypes.Watchers;
import me.libraryaddict.disguise.DisguiseTypes.LibsBaseWatcher;
public class EnderDragonWatcher extends LibsBaseWatcher {
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

@ -0,0 +1,21 @@
package me.libraryaddict.disguise.DisguiseTypes.Watchers;
import me.libraryaddict.disguise.DisguiseTypes.LibsBaseWatcher;
public class EndermanWatcher extends LibsBaseWatcher {
public EndermanWatcher(int entityId) {
super(entityId);
setValue(18, (byte) 0);
}
public boolean isAgressive() {
return (Integer) getValue(18) == 1;
}
public void setAgressive(boolean isAgressive) {
setValue(18, (byte) (isAgressive ? 1 : 0));
sendData(18);
}
}

View File

@ -0,0 +1,21 @@
package me.libraryaddict.disguise.DisguiseTypes.Watchers;
import me.libraryaddict.disguise.DisguiseTypes.LibsBaseWatcher;
public class GhastWatcher extends LibsBaseWatcher {
public GhastWatcher(int entityId) {
super(entityId);
setValue(16, (byte) 0);
}
public boolean isAgressive() {
return (Byte) getValue(16) == 1;
}
public void setAgressive(boolean isAgressive) {
setValue(16, (byte) (isAgressive ? 1 : 0));
sendData(16);
}
}

View File

@ -0,0 +1,9 @@
package me.libraryaddict.disguise.DisguiseTypes.Watchers;
public class MagmaCubeWatcher extends SlimeWatcher {
public MagmaCubeWatcher(int entityId) {
super(entityId);
}
}

View File

@ -0,0 +1,56 @@
package me.libraryaddict.disguise.DisguiseTypes.Watchers;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Ocelot.Type;
public class OcelotWatcher extends AgeableWatcher {
private boolean isSitting;
private boolean isTamed;
private Type type = Ocelot.Type.WILD_OCELOT;
public OcelotWatcher(int entityId) {
super(entityId);
setValue(16, (byte) 0);
setValue(17, "");
setValue(18, (byte) 0);
}
public String getOwner() {
return (String) getValue(17);
}
public Type getType() {
return type;
}
public void setOwner(String newOwner) {
setValue(17, newOwner);
}
public void setSitting(boolean sitting) {
if (isSitting != sitting) {
isSitting = sitting;
updateStatus();
}
}
public void setTamed(boolean tamed) {
if (isTamed != tamed) {
isTamed = tamed;
updateStatus();
}
}
public void setType(Type newType) {
if (type != newType) {
type = newType;
setValue(18, (byte) type.getId());
sendData(18);
}
}
private void updateStatus() {
setValue(16, (byte) ((isSitting ? 1 : 0) + (isTamed ? 4 : 0)));
sendData(16);
}
}

View File

@ -0,0 +1,18 @@
package me.libraryaddict.disguise.DisguiseTypes.Watchers;
public class PigWatcher extends AgeableWatcher {
public PigWatcher(int entityId) {
super(entityId);
setValue(16, (byte) 0);
}
public boolean isSaddled() {
return (Byte) getValue(16) == 0;
}
public void setSaddled(boolean isSaddled) {
setValue(16, (byte) (isSaddled ? 1 : 0));
sendData(16);
}
}

View File

@ -0,0 +1,30 @@
package me.libraryaddict.disguise.DisguiseTypes.Watchers;
import me.libraryaddict.disguise.DisguiseTypes.AnimalColor;
public class SheepWatcher extends AgeableWatcher {
private AnimalColor color = AnimalColor.WHITE;
private boolean isSheared;
public SheepWatcher(int entityId) {
super(entityId);
setValue(16, (byte) 0);
}
public boolean isSheared() {
return isSheared;
}
public void setColor(AnimalColor newColor) {
setValue(16, (byte) (newColor.getId() + (isSheared ? 16 : 0)));
sendData(16);
}
public void setSheared(boolean sheared) {
if (sheared != isSheared) {
isSheared = sheared;
setColor(color);
}
}
}

View File

@ -0,0 +1,23 @@
package me.libraryaddict.disguise.DisguiseTypes.Watchers;
import java.util.Random;
import me.libraryaddict.disguise.DisguiseTypes.LibsBaseWatcher;
public class SlimeWatcher extends LibsBaseWatcher {
public SlimeWatcher(int entityId) {
super(entityId);
setValue(16, (byte) new Random().nextInt(4) + 1);
}
public int getSize() {
return (Integer) getValue(16);
}
public void setSize(int size) {
setValue(16, (byte) size);
sendData(16);
}
}

View File

@ -0,0 +1,24 @@
package me.libraryaddict.disguise.DisguiseTypes.Watchers;
import java.util.Random;
import org.bukkit.entity.Villager.Profession;
public class VillagerWatcher extends AgeableWatcher {
private Profession profession;
public VillagerWatcher(int entityId) {
super(entityId);
profession = Profession.values()[new Random().nextInt(Profession.values().length)];
setValue(16, profession.getId());
}
public void setProfession(Profession newProfession) {
if (profession != newProfession) {
profession = newProfession;
setValue(16, profession.getId());
sendData(16);
}
}
}

View File

@ -0,0 +1,78 @@
package me.libraryaddict.disguise.DisguiseTypes.Watchers;
import me.libraryaddict.disguise.DisguiseTypes.AnimalColor;
public class WolfWatcher extends AgeableWatcher {
private AnimalColor collarColor = AnimalColor.RED;
private boolean isAgressive;
private boolean isSitting;
private boolean isTamed;
public WolfWatcher(int entityId) {
super(entityId);
setValue(16, (byte) 7);
setValue(17, "");
setValue(18, 8);
setValue(19, (byte) 0);
setValue(20, (byte) collarColor.getId());
}
public AnimalColor getCollarColor() {
return collarColor;
}
public int getHealth() {
return (Integer) getValue(18);
}
public String getName() {
return (String) getValue(17);
}
public boolean isAgressive() {
return isAgressive;
}
public boolean isSitting() {
return isSitting;
}
public boolean isTamed() {
return isTamed;
}
public void setAgressive(boolean aggressive) {
if (isAgressive != aggressive) {
isAgressive = aggressive;
updateStatus();
}
}
public void setCollarColor(AnimalColor newColor) {
if (newColor != collarColor) {
collarColor = newColor;
setValue(20, (byte) newColor.getId());
sendData(20);
}
}
public void setSitting(boolean sitting) {
if (isSitting != sitting) {
isSitting = sitting;
updateStatus();
}
}
public void setTamed(boolean tamed) {
if (isTamed != tamed) {
isTamed = tamed;
updateStatus();
}
}
private void updateStatus() {
setValue(16, (byte) ((isTamed ? 4 : 0) + (isSitting ? 1 : 0) + (isAgressive ? 2 : 0)));
sendData(16);
}
}

View File

@ -1,17 +1,13 @@
package me.libraryaddict.disguise; package me.libraryaddict.disguise;
import java.lang.reflect.Method;
import java.util.List; import java.util.List;
import me.libraryaddict.disguise.DisguiseTypes.Disguise; import me.libraryaddict.disguise.DisguiseTypes.Disguise;
import me.libraryaddict.disguise.DisguiseTypes.MiscDisguise; import me.libraryaddict.disguise.DisguiseTypes.MiscDisguise;
import me.libraryaddict.disguise.DisguiseTypes.MobDisguise; import me.libraryaddict.disguise.DisguiseTypes.MobDisguise;
import me.libraryaddict.disguise.DisguiseTypes.PlayerDisguise; import me.libraryaddict.disguise.DisguiseTypes.PlayerDisguise;
import net.minecraft.server.v1_5_R3.DataWatcher; import net.minecraft.server.v1_5_R3.WatchableObject;
import net.minecraft.server.v1_5_R3.Entity;
import net.minecraft.server.v1_5_R3.EntityLiving;
import net.minecraft.server.v1_5_R3.EntityPlayer;
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -54,7 +50,8 @@ public class LibsDisguises extends JavaPlugin {
} }
} }
} else if (!disguise.getType().isPlayer()) { } else if (!disguise.getType().isPlayer()) {
mods.write(1, modifyDataWatcher(disguise, watched)); if (disguise.hasWatcher())
mods.write(1, disguise.getWatcher().convert((List<WatchableObject>) mods.read(1)));
} }
} }
} }
@ -63,39 +60,5 @@ public class LibsDisguises extends JavaPlugin {
} }
} }
}); });
}
private List modifyDataWatcher(Disguise disguise, Player p) {
Entity e = disguise.getEntity();
EntityPlayer hE = ((CraftPlayer) p).getHandle();
e.setAirTicks(hE.getAirTicks());
e.fireTicks = p.getFireTicks();
a(e.getDataWatcher(), 0, e.fireTicks > 0);
e.setSprinting(p.isSprinting());
e.setSneaking(p.isSneaking());
if (e instanceof EntityLiving) {
EntityLiving lE = (EntityLiving) e;
lE.setInvisible(hE.isInvisible());
lE.effects = hE.effects;
lE.updateEffects = true;
try {
Method method = EntityLiving.class.getDeclaredMethod("bA");
method.setAccessible(true);
method.invoke(lE);
} catch (Exception e1) {
e1.printStackTrace();
}
}
return e.getDataWatcher().b();
}
protected void a(DataWatcher datawatcher, int i, boolean flag) {
byte b0 = datawatcher.getByte(0);
if (flag) {
datawatcher.watch(0, Byte.valueOf((byte) (b0 | 1 << i)));
} else {
datawatcher.watch(0, Byte.valueOf((byte) (b0 & ~(1 << i))));
}
} }
} }

Binary file not shown.

View File

@ -1,7 +0,0 @@
#Generated by Maven Integration for Eclipse
#Sat May 18 09:45:06 NZST 2013
version=v1.0
groupId=LibsDisguises
m2e.projectName=LibsDisguises
m2e.projectLocation=C\:\\Users\\Andrew\\Documents\\eclipse\\LibsDisguises
artifactId=LibsDisguises

View File

@ -1,62 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>LibsDisguises</groupId>
<artifactId>LibsDisguises</artifactId>
<version>v1.0</version>
<build>
<sourceDirectory>src</sourceDirectory>
<defaultGoal>clean package</defaultGoal>
<directory>target</directory>
<finalName>LibsDisguises</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${project.basedir}</directory>
<includes>
<include>plugin.yml</include>
<include>README.md</include>
</includes>
</resource>
</resources>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>comphenix-rep</id>
<name>Comphenix Repository</name>
<url>http://repo.comphenix.net/content/groups/public</url>
</repository>
<repository>
<id>bukkit-repo</id>
<url>http://repo.bukkit.org/content/groups/public</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.5.2-R0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -1,8 +0,0 @@
name: LibsDisguises
main: me.libraryaddict.disguise.LibsDisguises
version: v1.0
author: libraryaddict
depend: [ProtocolLib]
commands:
disguise:
aliases: [d, dis]

View File

@ -1,5 +0,0 @@
#Generated by Maven
#Sat May 18 09:04:19 NZST 2013
version=v1.0
groupId=LibsDisguises
artifactId=LibsDisguises