Cleanups here. Cleanups there. Cleanups everywhere.

This commit is contained in:
libraryaddict 2013-12-17 07:47:29 +13:00
parent e221dc4757
commit f7878f411d
5 changed files with 39 additions and 54 deletions

View File

@ -16,6 +16,7 @@ import me.libraryaddict.disguise.utilities.ReflectionManager;
import me.libraryaddict.disguise.utilities.DisguiseValues; import me.libraryaddict.disguise.utilities.DisguiseValues;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Horse.Variant; import org.bukkit.entity.Horse.Variant;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -30,7 +31,7 @@ import com.comphenix.protocol.reflect.StructureModifier;
public abstract class Disguise { public abstract class Disguise {
private static JavaPlugin plugin; private static JavaPlugin plugin;
private DisguiseType disguiseType; private DisguiseType disguiseType;
private org.bukkit.entity.Entity entity; private Entity entity;
private boolean hearSelfDisguise = DisguiseAPI.isSelfDisguisesSoundsReplaced(); private boolean hearSelfDisguise = DisguiseAPI.isSelfDisguisesSoundsReplaced();
private boolean hideArmorFromSelf = DisguiseAPI.isHidingArmorFromSelf(); private boolean hideArmorFromSelf = DisguiseAPI.isHidingArmorFromSelf();
private boolean hideHeldItemFromSelf = DisguiseAPI.isHidingHeldItemFromSelf(); private boolean hideHeldItemFromSelf = DisguiseAPI.isHidingHeldItemFromSelf();
@ -282,7 +283,7 @@ public abstract class Disguise {
/** /**
* Get the disguised entity * Get the disguised entity
*/ */
public org.bukkit.entity.Entity getEntity() { public Entity getEntity() {
return entity; return entity;
} }
@ -410,7 +411,7 @@ public abstract class Disguise {
/** /**
* Set the entity of the disguise. Only used for internal things. * Set the entity of the disguise. Only used for internal things.
*/ */
public void setEntity(org.bukkit.entity.Entity entity) { public void setEntity(Entity entity) {
if (this.getEntity() != null) { if (this.getEntity() != null) {
throw new RuntimeException("This disguise is already in use! Try .clone()"); throw new RuntimeException("This disguise is already in use! Try .clone()");
} }

View File

@ -131,21 +131,19 @@ public enum DisguiseType {
ZOMBIE_VILLAGER(); ZOMBIE_VILLAGER();
static { static {
// We set the entity type in this so that we can safely ignore disguisetypes which don't exist in older versions of MC.
// Without erroring up everything.
for (DisguiseType type : values()) { for (DisguiseType type : values()) {
try { try {
EntityType entityType = null; EntityType entityType = null;
switch (type) { switch (type) {
// Disguise item frame isn't supported. So we don't give it a entity type which should prevent it from being..
// Usable.
case ITEM_FRAME: case ITEM_FRAME:
break; break;
case DONKEY: case DONKEY:
entityType = EntityType.HORSE;
break;
case MULE: case MULE:
entityType = EntityType.HORSE;
break;
case UNDEAD_HORSE: case UNDEAD_HORSE:
entityType = EntityType.HORSE;
break;
case SKELETON_HORSE: case SKELETON_HORSE:
entityType = EntityType.HORSE; entityType = EntityType.HORSE;
break; break;
@ -176,11 +174,10 @@ public enum DisguiseType {
} }
} }
private int defaultData;
private int defaultId; private int defaultId;
private int entityId; private int entityId;
private EntityType entityType; private EntityType entityType;
private Class watcherClass; private Class<? extends FlagWatcher> watcherClass;
private DisguiseType(int... obj) { private DisguiseType(int... obj) {
for (int i = 0; i < obj.length; i++) { for (int i = 0; i < obj.length; i++) {
@ -192,19 +189,12 @@ public enum DisguiseType {
case 1: case 1:
defaultId = value; defaultId = value;
break; break;
case 2:
defaultData = value;
break;
default: default:
break; break;
} }
} }
} }
public int getDefaultData() {
return defaultData;
}
public int getDefaultId() { public int getDefaultId() {
return defaultId; return defaultId;
} }
@ -237,7 +227,7 @@ public enum DisguiseType {
this.entityType = entityType; this.entityType = entityType;
} }
public void setWatcherClass(Class c) { public void setWatcherClass(Class<? extends FlagWatcher> c) {
watcherClass = c; watcherClass = c;
} }

View File

@ -11,6 +11,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.EntityEquipment; import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolLibrary;
@ -52,15 +53,10 @@ public class FlagWatcher {
this.disguise = (TargetedDisguise) disguise; this.disguise = (TargetedDisguise) disguise;
} }
@Override public FlagWatcher clone(Disguise owningDisguise) {
protected Object clone() {
throw new RuntimeException("Please use clone(disguise) instead of clone()");
}
public FlagWatcher clone(Disguise disguise) {
FlagWatcher cloned = null; FlagWatcher cloned = null;
try { try {
cloned = getClass().getConstructor(Disguise.class).newInstance(disguise); cloned = getClass().getConstructor(Disguise.class).newInstance(owningDisguise);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -151,8 +147,8 @@ public class FlagWatcher {
return newList; return newList;
} }
public org.bukkit.inventory.ItemStack[] getArmor() { public ItemStack[] getArmor() {
org.bukkit.inventory.ItemStack[] armor = new org.bukkit.inventory.ItemStack[4]; ItemStack[] armor = new ItemStack[4];
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
armor[i] = items[i]; armor[i] = items[i];
} }
@ -163,24 +159,24 @@ public class FlagWatcher {
return disguise; return disguise;
} }
private boolean getFlag(int i) { private boolean getFlag(int byteValue) {
return ((Byte) getValue(0, (byte) 0) & 1 << i) != 0; return ((Byte) getValue(0, (byte) 0) & 1 << byteValue) != 0;
} }
@Deprecated @Deprecated
public org.bukkit.inventory.ItemStack getHeldItem() { public ItemStack getHeldItem() {
return getItemInHand(); return getItemInHand();
} }
public org.bukkit.inventory.ItemStack getItemInHand() { public ItemStack getItemInHand() {
return getItemStack(SlotType.HELD_ITEM); return getItemStack(SlotType.HELD_ITEM);
} }
public org.bukkit.inventory.ItemStack getItemStack(int slot) { public ItemStack getItemStack(int slot) {
return items[slot]; return items[slot];
} }
public org.bukkit.inventory.ItemStack getItemStack(SlotType slot) { public ItemStack getItemStack(SlotType slot) {
return getItemStack(slot.getSlot()); return getItemStack(slot.getSlot());
} }
@ -251,7 +247,7 @@ public class FlagWatcher {
this.addEntityAnimations = isEntityAnimationsAdded; this.addEntityAnimations = isEntityAnimationsAdded;
} }
public void setArmor(org.bukkit.inventory.ItemStack[] itemstack) { public void setArmor(ItemStack[] itemstack) {
for (int i = 0; i < itemstack.length; i++) for (int i = 0; i < itemstack.length; i++)
setItemStack(i, itemstack[i]); setItemStack(i, itemstack[i]);
} }
@ -261,37 +257,35 @@ public class FlagWatcher {
} }
public void setBurning(boolean setBurning) { public void setBurning(boolean setBurning) {
setFlag(0, 0, setBurning); setFlag(0, setBurning);
sendData(0); sendData(0);
} }
protected void setFlag(int no, int i, boolean flag) { private void setFlag(int byteValue, boolean flag) {
if (no == 0) { modifiedEntityAnimations.add(byteValue);
modifiedEntityAnimations.add(i); byte b0 = (Byte) getValue(0, (byte) 0);
}
byte b0 = (Byte) getValue(no, (byte) 0);
if (flag) { if (flag) {
setValue(no, (byte) (b0 | 1 << i)); setValue(0, (byte) (b0 | 1 << byteValue));
} else { } else {
setValue(no, (byte) (b0 & ~(1 << i))); setValue(0, (byte) (b0 & ~(1 << byteValue)));
} }
} }
@Deprecated @Deprecated
public void setHeldItem(org.bukkit.inventory.ItemStack itemstack) { public void setHeldItem(ItemStack itemstack) {
setItemInHand(itemstack); setItemInHand(itemstack);
} }
public void setInvisible(boolean setInvis) { public void setInvisible(boolean setInvis) {
setFlag(0, 5, setInvis); setFlag(5, setInvis);
sendData(0); sendData(0);
} }
public void setItemInHand(org.bukkit.inventory.ItemStack itemstack) { public void setItemInHand(ItemStack itemstack) {
setItemStack(SlotType.HELD_ITEM, itemstack); setItemStack(SlotType.HELD_ITEM, itemstack);
} }
public void setItemStack(int slot, org.bukkit.inventory.ItemStack itemStack) { public void setItemStack(int slot, ItemStack itemStack) {
// Itemstack which is null means that its not replacing the disguises itemstack. // Itemstack which is null means that its not replacing the disguises itemstack.
if (itemStack == null) { if (itemStack == null) {
// Find the item to replace it with // Find the item to replace it with
@ -332,28 +326,28 @@ public class FlagWatcher {
} }
} }
public void setItemStack(SlotType slot, org.bukkit.inventory.ItemStack itemStack) { public void setItemStack(SlotType slot, ItemStack itemStack) {
setItemStack(slot.getSlot(), itemStack); setItemStack(slot.getSlot(), itemStack);
} }
@Deprecated @Deprecated
public void setRiding(boolean setRiding) { public void setRiding(boolean setRiding) {
setFlag(0, 2, setRiding); setFlag(2, setRiding);
sendData(0); sendData(0);
} }
public void setRightClicking(boolean setRightClicking) { public void setRightClicking(boolean setRightClicking) {
setFlag(0, 4, setRightClicking); setFlag(4, setRightClicking);
sendData(0); sendData(0);
} }
public void setSneaking(boolean setSneaking) { public void setSneaking(boolean setSneaking) {
setFlag(0, 1, setSneaking); setFlag(1, setSneaking);
sendData(0); sendData(0);
} }
public void setSprinting(boolean setSprinting) { public void setSprinting(boolean setSprinting) {
setFlag(0, 3, setSprinting); setFlag(3, setSprinting);
sendData(0); sendData(0);
} }

View File

@ -55,7 +55,7 @@ public class MiscDisguise extends TargetedDisguise {
if (getType() == DisguiseType.PAINTING) { if (getType() == DisguiseType.PAINTING) {
data = new Random().nextInt(Art.values().length); data = new Random().nextInt(Art.values().length);
} else { } else {
data = disguiseType.getDefaultData(); data = 0;
} }
} }
this.data = data; this.data = data;

View File

@ -52,7 +52,7 @@ public class WolfWatcher extends AgeableWatcher {
private void setFlag(int no, boolean flag) { private void setFlag(int no, boolean flag) {
byte b0 = (Byte) getValue(16, (byte) 0); byte b0 = (Byte) getValue(16, (byte) 0);
if (flag) { if (flag) {
setValue(16, (byte) (b0 | (no))); setValue(16, (byte) (b0 | no));
} else { } else {
setValue(16, (byte) (b0 & -(no + 1))); setValue(16, (byte) (b0 & -(no + 1)));
} }