Different approach to FlagWatcher, fixed some errors for the update

This commit is contained in:
libraryaddict 2016-06-13 05:43:41 +12:00
parent e751cf4582
commit daab2c9606
38 changed files with 2431 additions and 1971 deletions

View File

@ -1,398 +1,407 @@
package me.libraryaddict.disguise; package me.libraryaddict.disguise;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Ageable; import org.bukkit.entity.Ageable;
import org.bukkit.entity.Damageable; import org.bukkit.entity.Creature;
import org.bukkit.entity.Entity; import org.bukkit.entity.Damageable;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Tameable; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Zombie; import org.bukkit.entity.Tameable;
import org.bukkit.event.HandlerList; import org.bukkit.entity.Zombie;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;
import com.comphenix.protocol.reflect.FieldAccessException;
import com.comphenix.protocol.wrappers.WrappedDataWatcher; import com.comphenix.protocol.reflect.FieldAccessException;
import com.comphenix.protocol.wrappers.WrappedWatchableObject; import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import me.libraryaddict.disguise.commands.CloneDisguiseCommand;
import me.libraryaddict.disguise.commands.DisguiseCommand; import me.libraryaddict.disguise.commands.CloneDisguiseCommand;
import me.libraryaddict.disguise.commands.DisguiseViewSelf; import me.libraryaddict.disguise.commands.DisguiseCommand;
import me.libraryaddict.disguise.commands.EntityDisguiseCommand; import me.libraryaddict.disguise.commands.DisguiseViewSelf;
import me.libraryaddict.disguise.commands.HelpDisguiseCommand; import me.libraryaddict.disguise.commands.EntityDisguiseCommand;
import me.libraryaddict.disguise.commands.LibsDisguisesCommand; import me.libraryaddict.disguise.commands.HelpDisguiseCommand;
import me.libraryaddict.disguise.commands.PlayerDisguiseCommand; import me.libraryaddict.disguise.commands.LibsDisguisesCommand;
import me.libraryaddict.disguise.commands.RadiusDisguiseCommand; import me.libraryaddict.disguise.commands.PlayerDisguiseCommand;
import me.libraryaddict.disguise.commands.UndisguiseCommand; import me.libraryaddict.disguise.commands.RadiusDisguiseCommand;
import me.libraryaddict.disguise.commands.UndisguiseEntityCommand; import me.libraryaddict.disguise.commands.UndisguiseCommand;
import me.libraryaddict.disguise.commands.UndisguisePlayerCommand; import me.libraryaddict.disguise.commands.UndisguiseEntityCommand;
import me.libraryaddict.disguise.commands.UndisguiseRadiusCommand; import me.libraryaddict.disguise.commands.UndisguisePlayerCommand;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.commands.UndisguiseRadiusCommand;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.ArrowWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SkeletonWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.InsentientWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SlimeWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.TameableWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.SkeletonWatcher;
import me.libraryaddict.disguise.utilities.DisguiseSound; import me.libraryaddict.disguise.disguisetypes.watchers.SlimeWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.disguisetypes.watchers.SpiderWatcher;
import me.libraryaddict.disguise.utilities.DisguiseValues; import me.libraryaddict.disguise.disguisetypes.watchers.TNTWatcher;
import me.libraryaddict.disguise.utilities.FakeBoundingBox; import me.libraryaddict.disguise.disguisetypes.watchers.TameableWatcher;
import me.libraryaddict.disguise.utilities.Metrics; import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import me.libraryaddict.disguise.utilities.PacketsManager; import me.libraryaddict.disguise.utilities.DisguiseSound;
import me.libraryaddict.disguise.utilities.ReflectionManager; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.DisguiseValues;
public class LibsDisguises extends JavaPlugin import me.libraryaddict.disguise.utilities.FakeBoundingBox;
{ import me.libraryaddict.disguise.utilities.Metrics;
private static LibsDisguises instance; import me.libraryaddict.disguise.utilities.PacketsManager;
private DisguiseListener listener; import me.libraryaddict.disguise.utilities.ReflectionManager;
@Override public class LibsDisguises extends JavaPlugin
public void onEnable() {
{ private static LibsDisguises instance;
getLogger().info("Discovered MC version: " + ReflectionManager.getBukkitVersion()); private DisguiseListener listener;
saveDefaultConfig(); @Override
public void onEnable()
PacketsManager.init(this); {
DisguiseUtilities.init(this); getLogger().info("Discovered MC version: " + ReflectionManager.getBukkitVersion());
DisguiseConfig.initConfig(getConfig()); saveDefaultConfig();
PacketsManager.addPacketListeners(); PacketsManager.init(this);
DisguiseUtilities.init(this);
listener = new DisguiseListener(this);
DisguiseConfig.initConfig(getConfig());
Bukkit.getPluginManager().registerEvents(listener, this);
PacketsManager.addPacketListeners();
getCommand("disguise").setExecutor(new DisguiseCommand());
getCommand("undisguise").setExecutor(new UndisguiseCommand()); listener = new DisguiseListener(this);
getCommand("disguiseplayer").setExecutor(new PlayerDisguiseCommand());
getCommand("undisguiseplayer").setExecutor(new UndisguisePlayerCommand()); Bukkit.getPluginManager().registerEvents(listener, this);
getCommand("undisguiseentity").setExecutor(new UndisguiseEntityCommand());
getCommand("disguiseentity").setExecutor(new EntityDisguiseCommand()); getCommand("disguise").setExecutor(new DisguiseCommand());
getCommand("disguiseradius").setExecutor(new RadiusDisguiseCommand(getConfig().getInt("DisguiseRadiusMax"))); getCommand("undisguise").setExecutor(new UndisguiseCommand());
getCommand("undisguiseradius").setExecutor(new UndisguiseRadiusCommand(getConfig().getInt("UndisguiseRadiusMax"))); getCommand("disguiseplayer").setExecutor(new PlayerDisguiseCommand());
getCommand("disguisehelp").setExecutor(new HelpDisguiseCommand()); getCommand("undisguiseplayer").setExecutor(new UndisguisePlayerCommand());
getCommand("disguiseclone").setExecutor(new CloneDisguiseCommand()); getCommand("undisguiseentity").setExecutor(new UndisguiseEntityCommand());
getCommand("libsdisguises").setExecutor(new LibsDisguisesCommand()); getCommand("disguiseentity").setExecutor(new EntityDisguiseCommand());
getCommand("disguiseviewself").setExecutor(new DisguiseViewSelf()); getCommand("disguiseradius").setExecutor(new RadiusDisguiseCommand(getConfig().getInt("DisguiseRadiusMax")));
getCommand("undisguiseradius").setExecutor(new UndisguiseRadiusCommand(getConfig().getInt("UndisguiseRadiusMax")));
registerValues(); getCommand("disguisehelp").setExecutor(new HelpDisguiseCommand());
getCommand("disguiseclone").setExecutor(new CloneDisguiseCommand());
instance = this; getCommand("libsdisguises").setExecutor(new LibsDisguisesCommand());
getCommand("disguiseviewself").setExecutor(new DisguiseViewSelf());
try
{ registerValues();
Metrics metrics = new Metrics(this);
metrics.start(); instance = this;
}
catch (IOException e) try
{ {
} Metrics metrics = new Metrics(this);
} metrics.start();
}
/** catch (IOException e)
* Reloads the config with new config options. {
*/ }
public void reload() }
{
HandlerList.unregisterAll(listener); /**
* Reloads the config with new config options.
reloadConfig(); */
DisguiseConfig.initConfig(getConfig()); public void reload()
} {
HandlerList.unregisterAll(listener);
/**
* Here we create a nms entity for each disguise. Then grab their default values in their datawatcher. Then their sound volume reloadConfig();
* for mob noises. As well as setting their watcher class and entity size. DisguiseConfig.initConfig(getConfig());
*/ }
private void registerValues()
{ /**
for (DisguiseType disguiseType : DisguiseType.values()) * Here we create a nms entity for each disguise. Then grab their default values in their datawatcher. Then their sound volume
{ * for mob noises. As well as setting their watcher class and entity size.
if (disguiseType.getEntityType() == null) */
{ private void registerValues()
continue; {
} for (DisguiseType disguiseType : DisguiseType.values())
{
Class watcherClass = null; if (disguiseType.getEntityType() == null)
{
try continue;
{ }
switch (disguiseType)
{ Class watcherClass = null;
case ITEM_FRAME: // Not really supported...
break; try
case MINECART_CHEST: {
case MINECART_COMMAND: switch (disguiseType)
case MINECART_FURNACE: {
case MINECART_HOPPER: case SPECTRAL_ARROW:
case MINECART_MOB_SPAWNER: watcherClass = ArrowWatcher.class;
case MINECART_TNT: break;
watcherClass = MinecartWatcher.class; case PRIMED_TNT:
break; watcherClass = TNTWatcher.class;
case DONKEY: break;
case MULE: case MINECART_CHEST:
case UNDEAD_HORSE: case MINECART_COMMAND:
case SKELETON_HORSE: case MINECART_FURNACE:
watcherClass = HorseWatcher.class; case MINECART_HOPPER:
break; case MINECART_MOB_SPAWNER:
case ZOMBIE_VILLAGER: case MINECART_TNT:
case PIG_ZOMBIE: watcherClass = MinecartWatcher.class;
watcherClass = ZombieWatcher.class; break;
break; case SPIDER:
case MAGMA_CUBE: case CAVE_SPIDER:
watcherClass = SlimeWatcher.class; watcherClass = SpiderWatcher.class;
break; break;
case ELDER_GUARDIAN: case DONKEY:
watcherClass = GuardianWatcher.class; case MULE:
break; case UNDEAD_HORSE:
case ENDERMITE: case SKELETON_HORSE:
watcherClass = LivingWatcher.class; watcherClass = HorseWatcher.class;
break; break;
case WITHER_SKELETON: case ZOMBIE_VILLAGER:
watcherClass = SkeletonWatcher.class; case PIG_ZOMBIE:
break; watcherClass = ZombieWatcher.class;
default: break;
watcherClass = Class.forName( case MAGMA_CUBE:
"me.libraryaddict.disguise.disguisetypes.watchers." + toReadable(disguiseType.name()) + "Watcher"); watcherClass = SlimeWatcher.class;
break; break;
} case ELDER_GUARDIAN:
} watcherClass = GuardianWatcher.class;
catch (ClassNotFoundException ex) break;
{ case WITHER_SKELETON:
// There is no explicit watcher for this entity. watcherClass = SkeletonWatcher.class;
Class entityClass = disguiseType.getEntityType().getEntityClass(); break;
default:
if (entityClass != null) watcherClass = Class.forName(
{ "me.libraryaddict.disguise.disguisetypes.watchers." + toReadable(disguiseType.name()) + "Watcher");
if (Tameable.class.isAssignableFrom(entityClass)) break;
{ }
watcherClass = TameableWatcher.class; }
} catch (ClassNotFoundException ex)
else if (Ageable.class.isAssignableFrom(entityClass)) {
{ // There is no explicit watcher for this entity.
watcherClass = AgeableWatcher.class; Class entityClass = disguiseType.getEntityType().getEntityClass();
}
else if (LivingEntity.class.isAssignableFrom(entityClass)) if (entityClass != null)
{ {
watcherClass = LivingWatcher.class; if (Tameable.class.isAssignableFrom(entityClass))
} {
else watcherClass = TameableWatcher.class;
{ }
watcherClass = FlagWatcher.class; else if (Ageable.class.isAssignableFrom(entityClass))
} {
} watcherClass = AgeableWatcher.class;
else }
{ else if (Creature.class.isAssignableFrom(entityClass))
watcherClass = FlagWatcher.class; // Disguise is unknown type {
} watcherClass = InsentientWatcher.class;
} }
else if (LivingEntity.class.isAssignableFrom(entityClass))
disguiseType.setWatcherClass(watcherClass); {
watcherClass = LivingWatcher.class;
if (DisguiseValues.getDisguiseValues(disguiseType) != null) }
{ else
continue; {
} watcherClass = FlagWatcher.class;
}
String nmsEntityName = toReadable(disguiseType.name()); }
else
switch (disguiseType) {
{ watcherClass = FlagWatcher.class; // Disguise is unknown type
case WITHER_SKELETON: }
case ZOMBIE_VILLAGER: }
case DONKEY:
case MULE: if (watcherClass == null)
case UNDEAD_HORSE: {
case SKELETON_HORSE: System.err.println("Error loading " + disguiseType.name() + ", FlagWatcher not assigned");
continue; continue;
case PRIMED_TNT: }
nmsEntityName = "TNTPrimed";
break; disguiseType.setWatcherClass(watcherClass);
case MINECART_TNT:
nmsEntityName = "MinecartTNT"; if (DisguiseValues.getDisguiseValues(disguiseType) != null)
break; {
case MINECART: continue;
nmsEntityName = "MinecartRideable"; }
break;
case FIREWORK: String nmsEntityName = toReadable(disguiseType.name());
nmsEntityName = "Fireworks";
break; switch (disguiseType)
case SPLASH_POTION: {
nmsEntityName = "Potion"; case WITHER_SKELETON:
break; case ZOMBIE_VILLAGER:
case GIANT: case DONKEY:
nmsEntityName = "GiantZombie"; case MULE:
break; case UNDEAD_HORSE:
case DROPPED_ITEM: case SKELETON_HORSE:
nmsEntityName = "Item"; continue;
break; case PRIMED_TNT:
case FIREBALL: nmsEntityName = "TNTPrimed";
nmsEntityName = "LargeFireball"; break;
break; case MINECART_TNT:
case LEASH_HITCH: nmsEntityName = "MinecartTNT";
nmsEntityName = "Leash"; break;
break; case MINECART:
case ELDER_GUARDIAN: nmsEntityName = "MinecartRideable";
nmsEntityName = "Guardian"; break;
break; case FIREWORK:
case ARROW: nmsEntityName = "Fireworks";
nmsEntityName = "TippedArrow"; break;
default: case SPLASH_POTION:
break; nmsEntityName = "Potion";
} break;
case GIANT:
try nmsEntityName = "GiantZombie";
{ break;
if (nmsEntityName.equalsIgnoreCase("Unknown")) case DROPPED_ITEM:
{ nmsEntityName = "Item";
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, null, 0, 0); break;
case FIREBALL:
disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0)); nmsEntityName = "LargeFireball";
break;
DisguiseSound sound = DisguiseSound.getType(disguiseType.name()); case LEASH_HITCH:
nmsEntityName = "Leash";
if (sound != null) break;
{ case ELDER_GUARDIAN:
sound.setDamageAndIdleSoundVolume(1f); nmsEntityName = "Guardian";
} break;
case ARROW:
continue; case SPECTRAL_ARROW:
} nmsEntityName = "TippedArrow";
default:
Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName); break;
}
if (nmsEntity == null)
{ try
getLogger().warning("Entity not found! (" + nmsEntityName + ")"); {
if (nmsEntityName.equalsIgnoreCase("Unknown"))
continue; {
} DisguiseValues disguiseValues = new DisguiseValues(disguiseType, null, 0, 0);
Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity); disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0));
int entitySize = 0;
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
for (Field field : ReflectionManager.getNmsClass("Entity").getFields())
{ if (sound != null)
if (field.getType().getName().equals("EnumEntitySize")) {
{ sound.setDamageAndIdleSoundVolume(1f);
Enum enumEntitySize = (Enum) field.get(nmsEntity); }
entitySize = enumEntitySize.ordinal(); continue;
}
break;
} Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName);
}
if (nmsEntity == null)
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, nmsEntity.getClass(), entitySize, {
bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0); getLogger().warning("Entity not found! (" + nmsEntityName + ")");
WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity); continue;
}
for (WrappedWatchableObject watch : watcher.getWatchableObjects())
{ Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity);
FlagType flagType = FlagType.getFlag(watcherClass, watch.getIndex()); int entitySize = 0;
if (flagType == null) for (Field field : ReflectionManager.getNmsClass("Entity").getFields())
{ {
System.err.println("Error finding the FlagType for " + disguiseType.name() + "! " + watch.getIndex() if (field.getType().getName().equals("EnumEntitySize"))
+ " cannot be found!"); {
System.err.println("Lib's Disguises will continue to load, but this will not work properly!"); Enum enumEntitySize = (Enum) field.get(nmsEntity);
continue;
} entitySize = enumEntitySize.ordinal();
disguiseValues.setMetaValue(flagType, watch.getValue()); break;
}
// Uncomment when I need to find the new datawatcher values for a class.. }
// int id = watch.getIndex();
// Object val = watch.getValue(); DisguiseValues disguiseValues = new DisguiseValues(disguiseType, nmsEntity.getClass(), entitySize,
// Class<?> valClazz = val != null ? watch.getValue().getClass() : null; bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0);
// try {
// val = val.toString(); WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity);
// } catch (Exception e) {
// val = val != null ? val.getClass() : "null"; for (WrappedWatchableObject watch : watcher.getWatchableObjects())
// } {
// System.out.println("Disguise: " + disguiseType + ", ID: " + id + ", Class: " + (val == null ? "null" : FlagType flagType = FlagType.getFlag(watcherClass, watch.getIndex());
// valClazz) + ", Value: " + val);
} if (flagType == null)
{
DisguiseSound sound = DisguiseSound.getType(disguiseType.name()); System.err.println("Error finding the FlagType for " + disguiseType.name() + "! Index " + watch.getIndex()
+ " can't be found!");
if (sound != null) System.err.println("Value is " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") ("
{ + nmsEntity.getClass() + ") & " + watcherClass.getSimpleName());
Float soundStrength = ReflectionManager.getSoundModifier(nmsEntity); System.err.println("Lib's Disguises will continue to load, but this will not work properly!");
continue;
if (soundStrength != null) }
{ }
sound.setDamageAndIdleSoundVolume(soundStrength);
} DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
}
if (sound != null)
// Get the bounding box {
disguiseValues.setAdultBox(ReflectionManager.getBoundingBox(bukkitEntity)); Float soundStrength = ReflectionManager.getSoundModifier(nmsEntity);
if (bukkitEntity instanceof Ageable) if (soundStrength != null)
{ {
((Ageable) bukkitEntity).setBaby(); sound.setDamageAndIdleSoundVolume(soundStrength);
}
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity)); }
}
else if (bukkitEntity instanceof Zombie) // Get the bounding box
{ disguiseValues.setAdultBox(ReflectionManager.getBoundingBox(bukkitEntity));
((Zombie) bukkitEntity).setBaby(true);
if (bukkitEntity instanceof Ageable)
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity)); {
} ((Ageable) bukkitEntity).setBaby();
disguiseValues.setEntitySize(ReflectionManager.getSize(bukkitEntity)); disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
} }
catch (SecurityException | IllegalArgumentException | IllegalAccessException | FieldAccessException ex) else if (bukkitEntity instanceof Zombie)
{ {
System.out.print( ((Zombie) bukkitEntity).setBaby(true);
"[LibsDisguises] Uh oh! Trouble while making values for the disguise " + disguiseType.name() + "!");
System.out.print("[LibsDisguises] Before reporting this error, " disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
+ "please make sure you are using the latest version of LibsDisguises and ProtocolLib."); }
System.out.print("[LibsDisguises] Development builds are available at (ProtocolLib) "
+ "http://ci.dmulloy2.net/job/ProtocolLib/ and (LibsDisguises) http://server.o2gaming.com:8080/job/LibsDisguises%201.9+/"); disguiseValues.setEntitySize(ReflectionManager.getSize(bukkitEntity));
}
ex.printStackTrace(System.out); catch (SecurityException | IllegalArgumentException | IllegalAccessException | FieldAccessException ex)
} {
} System.out.print(
} "[LibsDisguises] Uh oh! Trouble while making values for the disguise " + disguiseType.name() + "!");
System.out.print("[LibsDisguises] Before reporting this error, "
private String toReadable(String string) + "please make sure you are using the latest version of LibsDisguises and ProtocolLib.");
{ System.out.print("[LibsDisguises] Development builds are available at (ProtocolLib) "
StringBuilder builder = new StringBuilder(); + "http://ci.dmulloy2.net/job/ProtocolLib/ and (LibsDisguises) http://server.o2gaming.com:8080/job/LibsDisguises%201.9+/");
for (String s : string.split("_")) ex.printStackTrace(System.out);
{ }
builder.append(s.substring(0, 1)).append(s.substring(1).toLowerCase()); }
} }
return builder.toString(); private String toReadable(String string)
} {
StringBuilder builder = new StringBuilder();
public DisguiseListener getListener()
{ for (String s : string.split("_"))
return listener; {
} builder.append(s.substring(0, 1)).append(s.substring(1).toLowerCase());
}
/**
* External APIs shouldn't actually need this instance. DisguiseAPI should be enough to handle most cases. return builder.toString();
* }
* @return The instance of this plugin
*/ public DisguiseListener getListener()
public static LibsDisguises getInstance() {
{ return listener;
return instance; }
}
} /**
* External APIs shouldn't actually need this instance. DisguiseAPI should be enough to handle most cases.
*
* @return The instance of this plugin
*/
public static LibsDisguises getInstance()
{
return instance;
}
}

View File

@ -6,7 +6,6 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -38,7 +37,6 @@ import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import me.libraryaddict.disguise.events.DisguiseEvent; import me.libraryaddict.disguise.events.DisguiseEvent;
import me.libraryaddict.disguise.events.UndisguiseEvent; import me.libraryaddict.disguise.events.UndisguiseEvent;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.DisguiseValues;
import me.libraryaddict.disguise.utilities.PacketsManager; import me.libraryaddict.disguise.utilities.PacketsManager;
import me.libraryaddict.disguise.utilities.ReflectionManager; import me.libraryaddict.disguise.utilities.ReflectionManager;
@ -260,7 +258,7 @@ public abstract class Disguise
deadTicks = 0; deadTicks = 0;
// If the disguise type is tnt, we need to resend the entity packet else it will turn invisible // If the disguise type is tnt, we need to resend the entity packet else it will turn invisible
if (getType() == DisguiseType.PRIMED_TNT || getType() == DisguiseType.FIREWORK) if (getType() == DisguiseType.FIREWORK)
{ {
refreshDisguise++; refreshDisguise++;
@ -783,15 +781,23 @@ public abstract class Disguise
*/ */
private void setupWatcher() private void setupWatcher()
{ {
HashMap<FlagType, Object> disguiseValues = DisguiseValues.getMetaValues(getType()); ArrayList<FlagType> disguiseFlags = FlagType.getFlags(getType().getWatcherClass());
HashMap<FlagType, Object> entityValues = DisguiseValues.getMetaValues(DisguiseType.getType(getEntity().getType())); ArrayList<FlagType> entityFlags = FlagType.getFlags(DisguiseType.getType(getEntity().getType()).getWatcherClass());
for (Entry<FlagType, Object> entry : entityValues.entrySet()) for (FlagType flag : entityFlags)
{ {
if (disguiseValues.containsKey(entry.getKey())) if (disguiseFlags.contains(flag))
continue; continue;
getWatcher().setBackupValue(entry.getKey(), entry.getValue()); FlagType backup = null;
for (FlagType flagType : disguiseFlags)
{
if (flagType.getIndex() == flag.getIndex())
backup = flagType;
}
getWatcher().setBackupValue(flag, backup == null ? null : backup.getDefault());
} }
} }

View File

@ -1,260 +1,423 @@
package me.libraryaddict.disguise.disguisetypes; package me.libraryaddict.disguise.disguisetypes;
import java.util.Arrays; import java.util.ArrayList;
import java.util.HashMap; import java.util.Arrays;
import java.util.UUID; import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.Color;
import org.bukkit.Material; import org.bukkit.Color;
import org.bukkit.inventory.ItemStack; import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import com.google.common.base.Optional; import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import me.libraryaddict.disguise.disguisetypes.watchers.*;
import com.comphenix.protocol.wrappers.BlockPosition;
public class FlagType<Y> import com.google.common.base.Optional;
{
private static FlagType[] _values = new FlagType[0]; import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.AreaEffectCloudWatcher;
public static FlagType<Boolean> AGEABLE_BABY = new FlagType<Boolean>(AgeableWatcher.class, 11, false); import me.libraryaddict.disguise.disguisetypes.watchers.ArmorStandWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ArrowWatcher;
public static FlagType<Integer> AREA_EFFECT_COLOR = new FlagType<Integer>(AreaEffectCloudWatcher.class, 6, import me.libraryaddict.disguise.disguisetypes.watchers.BatWatcher;
Color.BLACK.asRGB()); import me.libraryaddict.disguise.disguisetypes.watchers.BlazeWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.BoatWatcher;
public static FlagType<Boolean> AREA_EFFECT_IGNORE_RADIUS = new FlagType<Boolean>(AreaEffectCloudWatcher.class, 7, false); import me.libraryaddict.disguise.disguisetypes.watchers.CreeperWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.DroppedItemWatcher;
public static FlagType<Integer> AREA_EFFECT_PARTICLE = new FlagType<Integer>(AreaEffectCloudWatcher.class, 8, 0); import me.libraryaddict.disguise.disguisetypes.watchers.EnderCrystalWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.EnderDragonWatcher;
public static FlagType<Float> AREA_EFFECT_RADIUS = new FlagType<Float>(AreaEffectCloudWatcher.class, 6, 0F); import me.libraryaddict.disguise.disguisetypes.watchers.EndermanWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher;
public static FlagType<Byte> ARMORSTAND_META = new FlagType<Byte>(ArmorStandWatcher.class, 10, (byte) 0); import me.libraryaddict.disguise.disguisetypes.watchers.FireworkWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.FishingHookWatcher;
public static FlagType<Byte> ARROW_CRITICAL = new FlagType<Byte>(ArrowWatcher.class, 6, (byte) 0); import me.libraryaddict.disguise.disguisetypes.watchers.GhastWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher;
public static FlagType<Byte> BAT_HANGING = new FlagType<Byte>(BatWatcher.class, 11, (byte) 1); import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.InsentientWatcher;
public static FlagType<Boolean> BLAZE_BLAZING = new FlagType<Boolean>(BlazeWatcher.class, 11, false); import me.libraryaddict.disguise.disguisetypes.watchers.IronGolemWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ItemFrameWatcher;
public static FlagType<Float> BOAT_DAMAGE = new FlagType<Float>(BoatWatcher.class, 7, 40F); import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher;
public static FlagType<Boolean> CREEPER_IGNITED = new FlagType<Boolean>(CreeperWatcher.class, 13, false); import me.libraryaddict.disguise.disguisetypes.watchers.OcelotWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.PigWatcher;
public static FlagType<Boolean> CREEPER_POWERED = new FlagType<Boolean>(CreeperWatcher.class, 12, false); import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.RabbitWatcher;
public static FlagType<ItemStack> DROPPED_ITEM = new FlagType<ItemStack>(DroppedItemWatcher.class, 6, import me.libraryaddict.disguise.disguisetypes.watchers.SheepWatcher;
new ItemStack(Material.AIR)); import me.libraryaddict.disguise.disguisetypes.watchers.ShulkerWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SkeletonWatcher;
public static FlagType<Optional> ENDER_CRYSTAL_BEAM = new FlagType<Optional>(EnderCrystalWatcher.class, 6, Optional.absent()); import me.libraryaddict.disguise.disguisetypes.watchers.SlimeWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SnowmanWatcher;
public static FlagType<Boolean> ENDER_CRYSTAL_PLATE = new FlagType<Boolean>(EnderCrystalWatcher.class, 6, false); import me.libraryaddict.disguise.disguisetypes.watchers.SpiderWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SplashPotionWatcher;
public static FlagType<Integer> ENDERDRAGON_PHASE = new FlagType<Integer>(EnderDragonWatcher.class, 6, 0); import me.libraryaddict.disguise.disguisetypes.watchers.TNTWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.TameableWatcher;
public static FlagType<Boolean> ENDERMAN_AGRESSIVE = new FlagType<Boolean>(EndermanWatcher.class, 12, false); import me.libraryaddict.disguise.disguisetypes.watchers.VillagerWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.WitchWatcher;
public static FlagType<Optional<Integer>> ENDERMAN_ITEM = new FlagType<Optional<Integer>>(EndermanWatcher.class, 11, import me.libraryaddict.disguise.disguisetypes.watchers.WitherSkullWatcher;
Optional.of(1)); import me.libraryaddict.disguise.disguisetypes.watchers.WitherWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher;
public static FlagType<Integer> ENTITY_AIR_TICKS = new FlagType<Integer>(FlagWatcher.class, 1, 0); import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
public static FlagType<String> ENTITY_CUSTOM_NAME = new FlagType<String>(FlagWatcher.class, 2, null); public class FlagType<Y>
{
public static FlagType<Boolean> ENTITY_CUSTOM_NAME_VISIBLE = new FlagType<Boolean>(FlagWatcher.class, 3, false); private static FlagType[] _values = new FlagType[0];
public static FlagType<Byte> ENTITY_META = new FlagType<Byte>(FlagWatcher.class, 0, (byte) 0); public static FlagType<Boolean> AGEABLE_BABY = new FlagType<Boolean>(AgeableWatcher.class, 0, false);
public static FlagType<Boolean> ENTITY_NO_GRAVITY = new FlagType<Boolean>(FlagWatcher.class, 5, false); public static FlagType<Integer> AREA_EFFECT_COLOR = new FlagType<Integer>(AreaEffectCloudWatcher.class, 1,
Color.BLACK.asRGB());
public static FlagType<Integer> ENTITY_SILENT = new FlagType<Integer>(FlagWatcher.class, 4, 0);
public static FlagType<Boolean> AREA_EFFECT_IGNORE_RADIUS = new FlagType<Boolean>(AreaEffectCloudWatcher.class, 2, false);
public static FlagType<Boolean> GHAST_AGRESSIVE = new FlagType<Boolean>(GhastWatcher.class, 11, false);
public static FlagType<Integer> AREA_EFFECT_PARTICLE = new FlagType<Integer>(AreaEffectCloudWatcher.class, 3, 0);
public static FlagType<Byte> GUARDIAN_FLAG = new FlagType<Byte>(GuardianWatcher.class, 11, (byte) 0);
public static FlagType<Integer> AREA_EFFECT_PARTICLE_PARAM_1 = new FlagType<Integer>(AreaEffectCloudWatcher.class, 4, 0);
public static FlagType<Integer> GUARDIAN_TARGET = new FlagType<Integer>(GuardianWatcher.class, 12, 0);
public static FlagType<Integer> AREA_EFFECT_PARTICLE_PARAM_2 = new FlagType<Integer>(AreaEffectCloudWatcher.class, 5, 0);
public static FlagType<Integer> HORSE_ARMOR = new FlagType<Integer>(HorseWatcher.class, 16, 0);
public static FlagType<Float> AREA_EFFECT_RADIUS = new FlagType<Float>(AreaEffectCloudWatcher.class, 0, 0F);
public static FlagType<Integer> HORSE_COLOR = new FlagType<Integer>(HorseWatcher.class, 14, 0);
public static FlagType<Vector> ARMORSTAND_BODY = new FlagType<Vector>(ArmorStandWatcher.class, 2, new Vector());
public static FlagType<Byte> HORSE_META = new FlagType<Byte>(HorseWatcher.class, 12, (byte) 0);
public static FlagType<Vector> ARMORSTAND_HEAD = new FlagType<Vector>(ArmorStandWatcher.class, 1, new Vector());
public static FlagType<Optional<UUID>> HORSE_OWNER = new FlagType<Optional<UUID>>(HorseWatcher.class, 15,
Optional.<UUID> absent()); public static FlagType<Vector> ARMORSTAND_LEFT_ARM = new FlagType<Vector>(ArmorStandWatcher.class, 3, new Vector());
public static FlagType<Integer> HORSE_STYLE = new FlagType<Integer>(HorseWatcher.class, 14, 0); public static FlagType<Vector> ARMORSTAND_LEFT_LEG = new FlagType<Vector>(ArmorStandWatcher.class, 5, new Vector());
public static FlagType<Integer> HORSE_VARIANT = new FlagType<Integer>(HorseWatcher.class, 13, 0); public static FlagType<Byte> ARMORSTAND_META = new FlagType<Byte>(ArmorStandWatcher.class, 0, (byte) 0);
public static FlagType<Byte> INSENTIENT_META = new FlagType<Byte>(LivingWatcher.class, 10, (byte) 0); public static FlagType<Vector> ARMORSTAND_RIGHT_ARM = new FlagType<Vector>(ArmorStandWatcher.class, 4, new Vector());
public static FlagType<ItemStack> ITEMFRAME_ITEM = new FlagType<ItemStack>(ItemFrameWatcher.class, 6, null); public static FlagType<Vector> ARMORSTAND_RIGHT_LEG = new FlagType<Vector>(ArmorStandWatcher.class, 6, new Vector());
public static FlagType<Byte> ITEMFRAME_ROTATION = new FlagType<Byte>(ItemFrameWatcher.class, 6, (byte) 0); public static FlagType<Byte> ARROW_CRITICAL = new FlagType<Byte>(ArrowWatcher.class, 0, (byte) 0);
public static FlagType<Integer> LIVING_ARROWS = new FlagType<Integer>(LivingWatcher.class, 9, 0); public static FlagType<Byte> BAT_HANGING = new FlagType<Byte>(BatWatcher.class, 0, (byte) 1);
public static FlagType<Float> LIVING_HEALTH = new FlagType<Float>(LivingWatcher.class, 6, 0F); public static FlagType<Boolean> BLAZE_BLAZING = new FlagType<Boolean>(BlazeWatcher.class, 0, false);
public static FlagType<Boolean> LIVING_POTION_AMBIENT = new FlagType<Boolean>(LivingWatcher.class, 8, false); public static FlagType<Float> BOAT_DAMAGE = new FlagType<Float>(BoatWatcher.class, 2, 40F);
public static FlagType<Integer> LIVING_POTIONS = new FlagType<Integer>(LivingWatcher.class, 7, 0); public static FlagType<Integer> BOAT_DIRECTION = new FlagType<Integer>(BoatWatcher.class, 1, 0);
public static FlagType<Integer> MINECART_BLOCK = new FlagType<Integer>(MinecartWatcher.class, 8, 0); public static FlagType<Integer> BOAT_LAST_HIT = new FlagType<Integer>(BoatWatcher.class, 0, 0);
public static FlagType<Boolean> MINECART_BLOCK_VISIBLE = new FlagType<Boolean>(MinecartWatcher.class, 10, false); public static FlagType<Boolean> BOAT_LEFT_PADDLING = new FlagType<Boolean>(BoatWatcher.class, 5, false);
public static FlagType<Integer> MINECART_BLOCK_Y = new FlagType<Integer>(MinecartWatcher.class, 9, 0); public static FlagType<Boolean> BOAT_RIGHT_PADDLING = new FlagType<Boolean>(BoatWatcher.class, 4, false);
public static FlagType<Integer> OCELOT_TYPE = new FlagType<Integer>(OcelotWatcher.class, 14, 0); public static FlagType<Integer> BOAT_TYPE = new FlagType<Integer>(BoatWatcher.class, 3, 0);
public static FlagType<Boolean> PIG_SADDLED = new FlagType<Boolean>(PigWatcher.class, 12, false); public static FlagType<Boolean> CREEPER_IGNITED = new FlagType<Boolean>(CreeperWatcher.class, 2, false);
public static FlagType<Byte> PLAYER_SKIN = new FlagType<Byte>(PlayerWatcher.class, 12, (byte) 0); public static FlagType<Boolean> CREEPER_POWERED = new FlagType<Boolean>(CreeperWatcher.class, 1, false);
public static FlagType<Integer> RABBIT_TYPE = new FlagType<Integer>(RabbitWatcher.class, 12, 0); public static FlagType<Integer> CREEPER_STATE = new FlagType<Integer>(CreeperWatcher.class, 0, -1);
public static FlagType<Byte> SHEEP_WOOL = new FlagType<Byte>(SheepWatcher.class, 12, (byte) 0); public static FlagType<ItemStack> DROPPED_ITEM = new FlagType<ItemStack>(DroppedItemWatcher.class, 0,
new ItemStack(Material.AIR));
public static FlagType<Integer> SKELETON_TYPE = new FlagType<Integer>(SkeletonWatcher.class, 11, 0);
public static FlagType<Optional> ENDER_CRYSTAL_BEAM = new FlagType<Optional>(EnderCrystalWatcher.class, 0, Optional.absent());
public static FlagType<Integer> SLIME_SIZE = new FlagType<Integer>(SlimeWatcher.class, 11, 0);
public static FlagType<Boolean> ENDER_CRYSTAL_PLATE = new FlagType<Boolean>(EnderCrystalWatcher.class, 1, false);
public static FlagType<Byte> TAMEABLE_META = new FlagType<Byte>(TameableWatcher.class, 12, (byte) 0);
public static FlagType<Integer> ENDERDRAGON_PHASE = new FlagType<Integer>(EnderDragonWatcher.class, 0, 0);
public static FlagType<Optional<UUID>> TAMEABLE_OWNER = new FlagType<Optional<UUID>>(TameableWatcher.class, 13,
Optional.<UUID> absent()); public static FlagType<Boolean> ENDERMAN_AGRESSIVE = new FlagType<Boolean>(EndermanWatcher.class, 1, false);
public static FlagType<Integer> TIPPED_ARROW_COLOR = new FlagType<Integer>(TippedArrowWatcher.class, 6, Color.WHITE.asRGB()); public static FlagType<Optional<Integer>> ENDERMAN_ITEM = new FlagType<Optional<Integer>>(EndermanWatcher.class, 0,
Optional.of(1));
public static FlagType<Integer> VILLAGER_PROFESSION = new FlagType<Integer>(VillagerWatcher.class, 12, 0);
public static FlagType<Integer> ENTITY_AIR_TICKS = new FlagType<Integer>(FlagWatcher.class, 1, 0);
public static FlagType<Boolean> WITCH_AGGRESSIVE = new FlagType<Boolean>(WitchWatcher.class, 11, false);
public static FlagType<String> ENTITY_CUSTOM_NAME = new FlagType<String>(FlagWatcher.class, 2, "");
public static FlagType<Integer> WITHER_INVUL = new FlagType<Integer>(WitchWatcher.class, 14, 0);
public static FlagType<Boolean> ENTITY_CUSTOM_NAME_VISIBLE = new FlagType<Boolean>(FlagWatcher.class, 3, false);
public static FlagType<Integer> WITHER_TARGET_1 = new FlagType<Integer>(WitherWatcher.class, 11, 0);
public static FlagType<Byte> ENTITY_META = new FlagType<Byte>(FlagWatcher.class, 0, (byte) 0);
public static FlagType<Integer> WITHER_TARGET_2 = new FlagType<Integer>(WitherWatcher.class, 12, 0);
public static FlagType<Boolean> ENTITY_NO_GRAVITY = new FlagType<Boolean>(FlagWatcher.class, 5, false);
public static FlagType<Integer> WITHER_TARGET_3 = new FlagType<Integer>(WitherWatcher.class, 13, 0);
public static FlagType<Boolean> ENTITY_SILENT = new FlagType<Boolean>(FlagWatcher.class, 4, false);
public static FlagType<Boolean> WITHERSKULL_BLUE = new FlagType<Boolean>(WitherSkullWatcher.class, 6, false);
public static FlagType<BlockPosition> FALLING_BLOCK_POSITION = new FlagType<BlockPosition>(FallingBlockWatcher.class, 0,
public static FlagType<Boolean> WOLF_BEGGING = new FlagType<Boolean>(WolfWatcher.class, 15, false); BlockPosition.ORIGIN);
public static FlagType<Integer> WOLF_COLLAR = new FlagType<Integer>(WolfWatcher.class, 16, 14); public static FlagType<Optional<ItemStack>> FIREWORK_ITEM = new FlagType<Optional<ItemStack>>(FireworkWatcher.class, 0,
Optional.<ItemStack> absent());
public static FlagType<Float> WOLF_DAMAGE = new FlagType<Float>(WolfWatcher.class, 14, 0F);
public static FlagType<Integer> FISHING_HOOK = new FlagType<Integer>(FishingHookWatcher.class, 0, 0);
public static FlagType<Boolean> ZOMBIE_AGGRESSIVE = new FlagType<Boolean>(ZombieWatcher.class, 14, false);
public static FlagType<Boolean> GHAST_AGRESSIVE = new FlagType<Boolean>(GhastWatcher.class, 0, false);
public static FlagType<Boolean> ZOMBIE_BABY = new FlagType<Boolean>(ZombieWatcher.class, 11, false);
public static FlagType<Byte> GUARDIAN_FLAG = new FlagType<Byte>(GuardianWatcher.class, 0, (byte) 0);
public static FlagType<Integer> ZOMBIE_PROFESSION = new FlagType<Integer>(ZombieWatcher.class, 12, 0);
public static FlagType<Integer> GUARDIAN_TARGET = new FlagType<Integer>(GuardianWatcher.class, 1, 0);
public static FlagType<Boolean> ZOMBIE_SHAKING = new FlagType<Boolean>(ZombieWatcher.class, 13, false);
public static FlagType<Integer> HORSE_ARMOR = new FlagType<Integer>(HorseWatcher.class, 4, 0);
static
{ public static FlagType<Integer> HORSE_COLOR = new FlagType<Integer>(HorseWatcher.class, 2, 0);
// Simple verification for the dev that he's setting up the FlagType's properly.
// All flag types should be from 0 to <Max Number> with no empty numbers. public static FlagType<Byte> HORSE_META = new FlagType<Byte>(HorseWatcher.class, 0, (byte) 0);
// All flag types should never occur twice.
public static FlagType<Optional<UUID>> HORSE_OWNER = new FlagType<Optional<UUID>>(HorseWatcher.class, 3,
HashMap<Class, Integer> maxValues = new HashMap<Class, Integer>(); Optional.<UUID> absent());
for (FlagType type : values()) public static FlagType<Integer> HORSE_VARIANT = new FlagType<Integer>(HorseWatcher.class, 1, 0);
{
if (maxValues.containsKey(type.getFlagWatcher()) && maxValues.get(type.getFlagWatcher()) > type.getIndex()) public static FlagType<Byte> INSENTIENT_META = new FlagType<Byte>(InsentientWatcher.class, 0, (byte) 0);
continue;
public static FlagType<Byte> IRON_GOLEM_PLAYER_CREATED = new FlagType<Byte>(IronGolemWatcher.class, 0, (byte) 0);
maxValues.put(type.getFlagWatcher(), type.getIndex());
} public static FlagType<Optional<ItemStack>> ITEMFRAME_ITEM = new FlagType<Optional<ItemStack>>(ItemFrameWatcher.class, 0,
Optional.<ItemStack> absent());
for (Entry<Class, Integer> entry : maxValues.entrySet())
{ public static FlagType<Integer> ITEMFRAME_ROTATION = new FlagType<Integer>(ItemFrameWatcher.class, 1, 0);
loop:
public static FlagType<Integer> LIVING_ARROWS = new FlagType<Integer>(LivingWatcher.class, 4, 0);
for (int i = 0; i < entry.getValue(); i++)
{ public static FlagType<Byte> LIVING_HAND = new FlagType<Byte>(LivingWatcher.class, 0, (byte) 0);
FlagType found = null;
public static FlagType<Float> LIVING_HEALTH = new FlagType<Float>(LivingWatcher.class, 1, 0F);
for (FlagType type : values())
{ public static FlagType<Boolean> LIVING_POTION_AMBIENT = new FlagType<Boolean>(LivingWatcher.class, 3, false);
if (type.getIndex() != i)
continue; public static FlagType<Integer> LIVING_POTIONS = new FlagType<Integer>(LivingWatcher.class, 2, 0);
if (!type.getFlagWatcher().isAssignableFrom(entry.getKey())) public static FlagType<Integer> MINECART_BLOCK = new FlagType<Integer>(MinecartWatcher.class, 3, 0);
continue;
public static FlagType<Boolean> MINECART_BLOCK_VISIBLE = new FlagType<Boolean>(MinecartWatcher.class, 5, false);
if (found != null)
{ public static FlagType<Integer> MINECART_BLOCK_Y = new FlagType<Integer>(MinecartWatcher.class, 4, 0);
System.err.println(entry.getKey().getSimpleName() + " has multiple FlagType's registered for the index "
+ i + " (" + type.getFlagWatcher().getSimpleName() + ", " + found.getFlagWatcher().getSimpleName() public static FlagType<Integer> MINECART_SHAKING_DIRECTION = new FlagType<Integer>(MinecartWatcher.class, 1, 1);
+ ")");
continue loop; public static FlagType<Float> MINECART_SHAKING_MULITPLIER = new FlagType<Float>(MinecartWatcher.class, 2, 0F);
}
public static FlagType<Integer> MINECART_SHAKING_POWER = new FlagType<Integer>(MinecartWatcher.class, 0, 0);
found = type;
} public static FlagType<Integer> OCELOT_TYPE = new FlagType<Integer>(OcelotWatcher.class, 0, 0);
if (found != null) public static FlagType<Boolean> PIG_SADDLED = new FlagType<Boolean>(PigWatcher.class, 0, false);
continue;
public static FlagType<Float> PLAYER_ABSORPTION = new FlagType<Float>(PlayerWatcher.class, 0, 0F);
System.err.println(entry.getKey().getSimpleName() + " has no FlagType registered for the index " + i);
} public static FlagType<Byte> PLAYER_HAND = new FlagType<Byte>(PlayerWatcher.class, 3, (byte) 0);
}
} public static FlagType<Integer> PLAYER_SCORE = new FlagType<Integer>(PlayerWatcher.class, 1, 0);
public static FlagType getFlag(Class<? extends FlagWatcher> watcherClass, int flagNo) public static FlagType<Byte> PLAYER_SKIN = new FlagType<Byte>(PlayerWatcher.class, 2, (byte) 0);
{
for (FlagType type : values()) public static FlagType<Integer> RABBIT_TYPE = new FlagType<Integer>(RabbitWatcher.class, 0, 0);
{
if (type.getIndex() != flagNo) public static FlagType<Byte> SHEEP_WOOL = new FlagType<Byte>(SheepWatcher.class, 0, (byte) 0);
continue;
public static FlagType<Optional<BlockPosition>> SHULKER_ATTACHED = new FlagType<Optional<BlockPosition>>(ShulkerWatcher.class,
if (!type.getFlagWatcher().isAssignableFrom(watcherClass)) 1, Optional.<BlockPosition> absent());
continue;
public static FlagType<BlockFace> SHULKER_FACING = new FlagType<BlockFace>(ShulkerWatcher.class, 0, BlockFace.DOWN);
return type;
} public static FlagType<Byte> SHULKER_PEEKING = new FlagType<Byte>(ShulkerWatcher.class, 2, (byte) 0);
return null; public static FlagType<Boolean> SKELETON_SWING_ARMS = new FlagType<Boolean>(SkeletonWatcher.class, 1, false);
}
public static FlagType<Integer> SKELETON_TYPE = new FlagType<Integer>(SkeletonWatcher.class, 0, 0);
public static FlagType[] values()
{ public static FlagType<Integer> SLIME_SIZE = new FlagType<Integer>(SlimeWatcher.class, 0, 0);
return _values;
} public static FlagType<Byte> SNOWMAN_HAT = new FlagType<Byte>(SnowmanWatcher.class, 0, (byte) 1);
private Y _defaultValue; public static FlagType<Byte> SPIDER_CLIMB = new FlagType<Byte>(SpiderWatcher.class, 0, (byte) 0);
private int _index; public static FlagType<Optional<ItemStack>> SPLASH_POTION_ITEM = new FlagType<Optional<ItemStack>>(SplashPotionWatcher.class,
1, Optional.of(new ItemStack(Material.SPLASH_POTION))); // Yeah, the '1' isn't a bug. No idea why but MC thinks
private Class<? extends FlagWatcher> _watcher; // there's a '0' already.
private FlagType(Class<? extends FlagWatcher> watcher, int index, Y defaultValue) public static FlagType<Optional<ItemStack>> SPLASH_POTION_ITEM_BAD = new FlagType<Optional<ItemStack>>(
{ SplashPotionWatcher.class, 0, Optional.of(new ItemStack(Material.SPLASH_POTION))); // Yeah, the '1' isn't a bug. No
_index = index; // idea why but MC thinks there's a
_watcher = watcher; // '0' already.
_values = Arrays.copyOf(_values, _values.length + 1); public static FlagType<Byte> TAMEABLE_META = new FlagType<Byte>(TameableWatcher.class, 0, (byte) 0);
_values[_values.length - 1] = this;
} public static FlagType<Optional<UUID>> TAMEABLE_OWNER = new FlagType<Optional<UUID>>(TameableWatcher.class, 1,
Optional.<UUID> absent());
public Y getDefault()
{ public static FlagType<Integer> TIPPED_ARROW_COLOR = new FlagType<Integer>(ArrowWatcher.class, 1, Color.WHITE.asRGB());
return _defaultValue;
} public static FlagType<Integer> TNT_FUSE_TICKS = new FlagType<Integer>(TNTWatcher.class, 0, Integer.MAX_VALUE);
public Class<? extends FlagWatcher> getFlagWatcher() public static FlagType<Integer> VILLAGER_PROFESSION = new FlagType<Integer>(VillagerWatcher.class, 0, 0);
{
return _watcher; public static FlagType<Boolean> WITCH_AGGRESSIVE = new FlagType<Boolean>(WitchWatcher.class, 0, false);
}
public static FlagType<Integer> WITHER_INVUL = new FlagType<Integer>(WitherWatcher.class, 3, 0);
public int getIndex()
{ public static FlagType<Integer> WITHER_TARGET_1 = new FlagType<Integer>(WitherWatcher.class, 0, 0);
return _index;
} public static FlagType<Integer> WITHER_TARGET_2 = new FlagType<Integer>(WitherWatcher.class, 1, 0);
}
public static FlagType<Integer> WITHER_TARGET_3 = new FlagType<Integer>(WitherWatcher.class, 2, 0);
public static FlagType<Boolean> WITHERSKULL_BLUE = new FlagType<Boolean>(WitherSkullWatcher.class, 0, false);
public static FlagType<Boolean> WOLF_BEGGING = new FlagType<Boolean>(WolfWatcher.class, 1, false);
public static FlagType<Integer> WOLF_COLLAR = new FlagType<Integer>(WolfWatcher.class, 2, 14);
public static FlagType<Float> WOLF_DAMAGE = new FlagType<Float>(WolfWatcher.class, 0, 0F);
public static FlagType<Boolean> ZOMBIE_AGGRESSIVE = new FlagType<Boolean>(ZombieWatcher.class, 3, false);
public static FlagType<Boolean> ZOMBIE_BABY = new FlagType<Boolean>(ZombieWatcher.class, 0, false);
public static FlagType<Integer> ZOMBIE_PROFESSION = new FlagType<Integer>(ZombieWatcher.class, 1, 0);
public static FlagType<Boolean> ZOMBIE_SHAKING = new FlagType<Boolean>(ZombieWatcher.class, 2, false);
static
{
for (FlagType flagType : values())
{
if (flagType.getFlagWatcher() == FlagWatcher.class)
continue;
flagType._index += getNoIndexes(flagType.getFlagWatcher().getSuperclass());
}
// Simple verification for the dev that he's setting up the FlagType's properly.
// All flag types should be from 0 to <Max Number> with no empty numbers.
// All flag types should never occur twice.
HashMap<Class, Integer> maxValues = new HashMap<Class, Integer>();
for (FlagType type : values())
{
if (maxValues.containsKey(type.getFlagWatcher()) && maxValues.get(type.getFlagWatcher()) > type.getIndex())
continue;
maxValues.put(type.getFlagWatcher(), type.getIndex());
}
for (Entry<Class, Integer> entry : maxValues.entrySet())
{
loop:
for (int i = 0; i < entry.getValue(); i++)
{
FlagType found = null;
for (FlagType type : values())
{
if (type.getIndex() != i)
continue;
if (!type.getFlagWatcher().isAssignableFrom(entry.getKey()))
continue;
if (found != null)
{
System.err.println(entry.getKey().getSimpleName() + " has multiple FlagType's registered for the index "
+ i + " (" + type.getFlagWatcher().getSimpleName() + ", " + found.getFlagWatcher().getSimpleName()
+ ")");
continue loop;
}
found = type;
}
if (found != null)
continue;
System.err.println(entry.getKey().getSimpleName() + " has no FlagType registered for the index " + i);
}
}
}
public static FlagType getFlag(Class<? extends FlagWatcher> watcherClass, int flagNo)
{
for (FlagType type : values())
{
if (type.getIndex() != flagNo)
continue;
if (!type.getFlagWatcher().isAssignableFrom(watcherClass))
continue;
return type;
}
return null;
}
public static ArrayList<FlagType> getFlags(Class<? extends FlagWatcher> watcherClass)
{
ArrayList<FlagType> list = new ArrayList<FlagType>();
for (FlagType type : values())
{
if (!type.getFlagWatcher().isAssignableFrom(watcherClass))
continue;
list.add(type);
}
return list;
}
private static int getNoIndexes(Class c)
{
int found = 0;
for (FlagType type : values())
{
if (type.getFlagWatcher() != c)
continue;
found++;
}
if (c != FlagWatcher.class)
{
found += getNoIndexes(c.getSuperclass());
}
return found;
}
public static FlagType[] values()
{
return _values;
}
private Y _defaultValue;
private int _index;
private Class<? extends FlagWatcher> _watcher;
private FlagType(Class<? extends FlagWatcher> watcher, int index, Y defaultValue)
{
_index = index;
_watcher = watcher;
_defaultValue = defaultValue;
_values = Arrays.copyOf(_values, _values.length + 1);
_values[_values.length - 1] = this;
}
public Y getDefault()
{
return _defaultValue;
}
public Class<? extends FlagWatcher> getFlagWatcher()
{
return _watcher;
}
public int getIndex()
{
return _index;
}
}

View File

@ -32,9 +32,9 @@ public class FlagWatcher
/** /**
* These are the entity values I need to add else it could crash them.. * These are the entity values I need to add else it could crash them..
*/ */
private HashMap<FlagType, Object> backupEntityValues = new HashMap<>(); private HashMap<Integer, Object> backupEntityValues = new HashMap<>();
private TargetedDisguise disguise; private TargetedDisguise disguise;
private HashMap<FlagType, Object> entityValues = new HashMap<>(); private HashMap<Integer, Object> entityValues = new HashMap<>();
private EntityEquipment equipment; private EntityEquipment equipment;
private boolean hasDied; private boolean hasDied;
private HashSet<Integer> modifiedEntityAnimations = new HashSet<>(); private HashSet<Integer> modifiedEntityAnimations = new HashSet<>();
@ -77,7 +77,7 @@ public class FlagWatcher
cloned = new FlagWatcher(getDisguise()); cloned = new FlagWatcher(getDisguise());
} }
cloned.entityValues = (HashMap<FlagType, Object>) entityValues.clone(); cloned.entityValues = (HashMap<Integer, Object>) entityValues.clone();
cloned.equipment = ReflectionManager.createEntityEquipment(cloned.getDisguise().getEntity()); cloned.equipment = ReflectionManager.createEntityEquipment(cloned.getDisguise().getEntity());
cloned.modifiedEntityAnimations = (HashSet<Integer>) modifiedEntityAnimations.clone(); cloned.modifiedEntityAnimations = (HashSet<Integer>) modifiedEntityAnimations.clone();
cloned.addEntityAnimations = addEntityAnimations; cloned.addEntityAnimations = addEntityAnimations;
@ -158,7 +158,7 @@ public class FlagWatcher
if (sendAllCustom) if (sendAllCustom)
{ {
// Its sending the entire meta data. Better add the custom meta // Its sending the entire meta data. Better add the custom meta
for (FlagType id : entityValues.keySet()) for (Integer id : entityValues.keySet())
{ {
if (sentValues.contains(id)) if (sentValues.contains(id))
{ {
@ -172,8 +172,7 @@ public class FlagWatcher
continue; continue;
} }
WrappedWatchableObject watch = new WrappedWatchableObject( WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(id, value));
ReflectionManager.createDataWatcherItem(id.getIndex(), value));
newList.add(watch); newList.add(watch);
} }
@ -245,7 +244,7 @@ public class FlagWatcher
private boolean getEntityFlag(int byteValue) private boolean getEntityFlag(int byteValue)
{ {
return ((byte) getValue(FlagType.ENTITY_META) & 1 << byteValue) != 0; return (getValue(FlagType.ENTITY_META) & 1 << byteValue) != 0;
} }
public EntityEquipment getEquipment() public EntityEquipment getEquipment()
@ -293,14 +292,14 @@ public class FlagWatcher
return null; return null;
} }
protected <Y> Y getValue(FlagType<Y> no) protected <Y> Y getValue(FlagType<Y> flagType)
{ {
if (entityValues.containsKey(no)) if (entityValues.containsKey(flagType.getIndex()))
{ {
return (Y) entityValues.get(no); return (Y) entityValues.get(flagType.getIndex());
} }
return no.getDefault(); return flagType.getDefault();
} }
public List<WrappedWatchableObject> getWatchableObjects() public List<WrappedWatchableObject> getWatchableObjects()
@ -318,9 +317,9 @@ public class FlagWatcher
return getCustomName() != null; return getCustomName() != null;
} }
protected boolean hasValue(int no) protected boolean hasValue(FlagType no)
{ {
return entityValues.containsKey(no); return entityValues.containsKey(no.getIndex());
} }
public boolean isBurning() public boolean isBurning()
@ -377,7 +376,7 @@ public class FlagWatcher
{ {
watchableObjects = new ArrayList<>(); watchableObjects = new ArrayList<>();
for (int i = 0; i <= 31; i++) for (int i = 0; i <= 31; i++)// TODO
{ {
WrappedWatchableObject watchable = null; WrappedWatchableObject watchable = null;
@ -468,7 +467,7 @@ public class FlagWatcher
protected void setBackupValue(FlagType no, Object value) protected void setBackupValue(FlagType no, Object value)
{ {
backupEntityValues.put(no, value); backupEntityValues.put(no.getIndex(), value);
} }
public void setBurning(boolean setBurning) public void setBurning(boolean setBurning)
@ -653,7 +652,7 @@ public class FlagWatcher
protected <Y> void setValue(FlagType<Y> id, Y value) protected <Y> void setValue(FlagType<Y> id, Y value)
{ {
entityValues.put(id, value); entityValues.put(id.getIndex(), value);
if (!DisguiseConfig.isMetadataPacketsEnabled()) if (!DisguiseConfig.isMetadataPacketsEnabled())
{ {

View File

@ -3,7 +3,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
public class AgeableWatcher extends LivingWatcher public class AgeableWatcher extends InsentientWatcher
{ {
public AgeableWatcher(Disguise disguise) public AgeableWatcher(Disguise disguise)

View File

@ -1,60 +1,58 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import java.awt.Color; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher; /**
* @author Navid
/** */
* @author Navid public class AreaEffectCloudWatcher extends FlagWatcher
*/ {
public class AreaEffectCloudWatcher extends FlagWatcher
{ public AreaEffectCloudWatcher(Disguise disguise)
{
public AreaEffectCloudWatcher(Disguise disguise) super(disguise);
{ }
super(disguise);
} public float getRadius()
{
public float getRadius() return getValue(FlagType.AREA_EFFECT_RADIUS);
{ }
return getValue(FlagType.AREA_EFFECT_RADIUS);
} public int getColor()
{
public int getColor() return getValue(FlagType.AREA_EFFECT_COLOR);
{ }
return getValue(FlagType.AREA_EFFECT_COLOR);
} public boolean isIgnoreRadius()
{
public boolean isIgnoreRadius() return getValue(FlagType.AREA_EFFECT_IGNORE_RADIUS);
{ }
return getValue(FlagType.AREA_EFFECT_IGNORE_RADIUS);
} public int getParticleId()
{
public int getParticleId() return getValue(FlagType.AREA_EFFECT_PARTICLE);
{ }
return getValue(FlagType.AREA_EFFECT_PARTICLE);
} public void setRadius(float radius)
{
public void setRadius(float radius) setValue(FlagType.AREA_EFFECT_RADIUS, radius);
{ }
setValue(FlagType.AREA_EFFECT_RADIUS, radius);
} public void setColor(int color)
{
public void setColor(int color) setValue(FlagType.AREA_EFFECT_COLOR, color);
{ }
setValue(FlagType.AREA_EFFECT_COLOR, color);
} public void setIgnoreRadius(boolean ignore)
{
public void setIgnoreRadius(boolean ignore) setValue(FlagType.AREA_EFFECT_IGNORE_RADIUS, ignore);
{ }
setValue(FlagType.AREA_EFFECT_IGNORE_RADIUS, ignore);
} public void setParticleId(int particleId)
{
public void setParticleId(int particleId) setValue(FlagType.AREA_EFFECT_PARTICLE, particleId);
{ }
setValue(FlagType.AREA_EFFECT_PARTICLE, particleId);
} }
}

View File

@ -1,91 +1,166 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import org.bukkit.util.Vector;
import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class ArmorStandWatcher extends LivingWatcher import me.libraryaddict.disguise.disguisetypes.FlagType;
{
public class ArmorStandWatcher extends LivingWatcher
public ArmorStandWatcher(Disguise disguise) {
{ public ArmorStandWatcher(Disguise disguise)
super(disguise); {
} super(disguise);
}
private boolean getArmorStandFlag(int value)
{ private boolean getArmorStandFlag(int value)
return (getValue(FlagType.ARMORSTAND_META) & value) != 0; {
} return (getValue(FlagType.ARMORSTAND_META) & value) != 0;
}
public boolean isNoBasePlate()
{ public Vector getBody()
return getArmorStandFlag(8); {
} return getPose(FlagType.ARMORSTAND_BODY);
}
public boolean isNoGravity()
{ public Vector getHead()
return getArmorStandFlag(2); {
} return getPose(FlagType.ARMORSTAND_HEAD);
}
public boolean isShowArms()
{ public Vector getLeftArm()
return getArmorStandFlag(4); {
} return getPose(FlagType.ARMORSTAND_LEFT_ARM);
}
public boolean isSmall()
{ public Vector getLeftLeg()
return getArmorStandFlag(1); {
} return getPose(FlagType.ARMORSTAND_LEFT_LEG);
}
public boolean isMarker()
{ private Vector getPose(FlagType<Vector> type)
return getArmorStandFlag(10); {
} if (!hasValue(type))
setValue(type, new Vector());
private void setArmorStandFlag(int value, boolean isTrue)
{ return getValue(type);
byte b1 = (byte) getValue(FlagType.ARMORSTAND_META); }
if (isTrue) public Vector getRightArm()
{ {
b1 = (byte) (b1 | value); return getPose(FlagType.ARMORSTAND_RIGHT_ARM);
} }
else
{ public Vector getRightLeg()
b1 = (byte) (b1 & value); {
} return getPose(FlagType.ARMORSTAND_RIGHT_LEG);
}
setValue(FlagType.ARMORSTAND_META, b1);
sendData(FlagType.ARMORSTAND_META); public boolean isMarker()
} {
return getArmorStandFlag(10);
public void setNoBasePlate(boolean noBasePlate) }
{
setArmorStandFlag(8, noBasePlate); public boolean isNoBasePlate()
sendData(FlagType.ARMORSTAND_META); {
} return getArmorStandFlag(8);
}
public void setNoGravity(boolean noGravity)
{ public boolean isNoGravity()
setArmorStandFlag(2, noGravity); {
sendData(FlagType.ARMORSTAND_META); return getArmorStandFlag(2);
} }
public void setShowArms(boolean showArms) public boolean isShowArms()
{ {
setArmorStandFlag(4, showArms); return getArmorStandFlag(4);
sendData(FlagType.ARMORSTAND_META); }
}
public boolean isSmall()
public void setSmall(boolean isSmall) {
{ return getArmorStandFlag(1);
setArmorStandFlag(1, isSmall); }
sendData(FlagType.ARMORSTAND_META);
} private void setArmorStandFlag(int value, boolean isTrue)
{
public void setMarker(boolean isMarker) byte b1 = (byte) getValue(FlagType.ARMORSTAND_META);
{
setArmorStandFlag(10, isMarker); if (isTrue)
sendData(FlagType.ARMORSTAND_META); {
} b1 = (byte) (b1 | value);
}
} else
{
b1 = (byte) (b1 & value);
}
setValue(FlagType.ARMORSTAND_META, b1);
sendData(FlagType.ARMORSTAND_META);
}
public void setBody(Vector vector)
{
setPose(FlagType.ARMORSTAND_BODY, vector);
}
public void setHead(Vector vector)
{
setPose(FlagType.ARMORSTAND_HEAD, vector);
}
public void setLeftArm(Vector vector)
{
setPose(FlagType.ARMORSTAND_LEFT_ARM, vector);
}
public void setLeftLeg(Vector vector)
{
setPose(FlagType.ARMORSTAND_LEFT_LEG, vector);
}
public void setMarker(boolean isMarker)
{
setArmorStandFlag(10, isMarker);
sendData(FlagType.ARMORSTAND_META);
}
public void setNoBasePlate(boolean noBasePlate)
{
setArmorStandFlag(8, noBasePlate);
sendData(FlagType.ARMORSTAND_META);
}
public void setNoGravity(boolean noGravity)
{
setArmorStandFlag(2, noGravity);
sendData(FlagType.ARMORSTAND_META);
}
private void setPose(FlagType type, Vector vector)
{
setValue(type, vector);
sendData(type);
}
public void setRightArm(Vector vector)
{
setPose(FlagType.ARMORSTAND_RIGHT_ARM, vector);
}
public void setRightLeg(Vector vector)
{
setPose(FlagType.ARMORSTAND_RIGHT_LEG, vector);
}
public void setShowArms(boolean showArms)
{
setArmorStandFlag(4, showArms);
sendData(FlagType.ARMORSTAND_META);
}
public void setSmall(boolean isSmall)
{
setArmorStandFlag(1, isSmall);
sendData(FlagType.ARMORSTAND_META);
}
}

View File

@ -1,26 +1,24 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
public class ArrowWatcher extends FlagWatcher public class ArrowWatcher extends FlagWatcher
{ {
public ArrowWatcher(Disguise disguise)
public ArrowWatcher(Disguise disguise) {
{ super(disguise);
super(disguise); }
}
public boolean isCritical()
public boolean isCritical() {
{ return (byte) getValue(FlagType.ARROW_CRITICAL) == 1;
return (byte) getValue(FlagType.ARROW_CRITICAL) == 1; }
}
public void setCritical(boolean critical)
public void setCritical(boolean critical) {
{ setValue(FlagType.ARROW_CRITICAL, (byte) (critical ? 1 : 0));
setValue(FlagType.ARROW_CRITICAL, (byte) (critical ? 1 : 0)); sendData(FlagType.ARROW_CRITICAL);
sendData(FlagType.ARROW_CRITICAL); }
} }
}

View File

@ -1,26 +1,26 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
public class BatWatcher extends LivingWatcher public class BatWatcher extends InsentientWatcher
{ {
public BatWatcher(Disguise disguise) public BatWatcher(Disguise disguise)
{ {
super(disguise); super(disguise);
setHanging(false); setHanging(false);
} }
public boolean isHanging() public boolean isHanging()
{ {
return ((byte) getValue(FlagType.BAT_HANGING)) == 1; return ((byte) getValue(FlagType.BAT_HANGING)) == 1;
} }
public void setHanging(boolean hanging) public void setHanging(boolean hanging)
{ {
setValue(FlagType.BAT_HANGING, hanging ? (byte) 1 : (byte) 0); setValue(FlagType.BAT_HANGING, hanging ? (byte) 1 : (byte) 0);
sendData(FlagType.BAT_HANGING); sendData(FlagType.BAT_HANGING);
} }
} }

View File

@ -1,24 +1,24 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
public class BlazeWatcher extends LivingWatcher public class BlazeWatcher extends InsentientWatcher
{ {
public BlazeWatcher(Disguise disguise) public BlazeWatcher(Disguise disguise)
{ {
super(disguise); super(disguise);
} }
public boolean isBlazing() public boolean isBlazing()
{ {
return getValue(FlagType.BLAZE_BLAZING); return getValue(FlagType.BLAZE_BLAZING);
} }
public void setBlazing(boolean isBlazing) public void setBlazing(boolean isBlazing)
{ {
setValue(FlagType.BLAZE_BLAZING, isBlazing); setValue(FlagType.BLAZE_BLAZING, isBlazing);
sendData(FlagType.BLAZE_BLAZING); sendData(FlagType.BLAZE_BLAZING);
} }
} }

View File

@ -1,28 +1,64 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import java.util.Random;
import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import org.bukkit.TreeSpecies;
public class BoatWatcher extends FlagWatcher import me.libraryaddict.disguise.disguisetypes.Disguise;
{ import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
// TODO: Add stuff for new boat values
public class BoatWatcher extends FlagWatcher
public BoatWatcher(Disguise disguise) {
{ public BoatWatcher(Disguise disguise)
super(disguise); {
} super(disguise);
public float getDamage() setBoatType(TreeSpecies.values()[new Random().nextInt(6)]);
{ }
return getValue(FlagType.BOAT_DAMAGE);
} public float getDamage()
{
public void setDamage(float dmg) return getValue(FlagType.BOAT_DAMAGE);
{ }
setValue(FlagType.BOAT_DAMAGE, dmg);
sendData(FlagType.BOAT_DAMAGE); public void setDamage(float dmg)
} {
setValue(FlagType.BOAT_DAMAGE, dmg);
} sendData(FlagType.BOAT_DAMAGE);
}
public void setRightPaddling(boolean rightPaddling)
{
setValue(FlagType.BOAT_RIGHT_PADDLING, rightPaddling);
sendData(FlagType.BOAT_RIGHT_PADDLING);
}
public void setLeftPaddling(boolean leftPaddling)
{
setValue(FlagType.BOAT_LEFT_PADDLING, leftPaddling);
sendData(FlagType.BOAT_LEFT_PADDLING);
}
public boolean isRightPaddling()
{
return getValue(FlagType.BOAT_RIGHT_PADDLING);
}
public boolean isLeftPaddling()
{
return getValue(FlagType.BOAT_LEFT_PADDLING);
}
public void setBoatType(TreeSpecies boatType)
{
setValue(FlagType.BOAT_TYPE, (int) boatType.getData());
sendData(FlagType.BOAT_TYPE);
}
public TreeSpecies getBoatType()
{
return TreeSpecies.getByData(getValue(FlagType.BOAT_TYPE).byteValue());
}
}

View File

@ -1,36 +1,36 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
public class CreeperWatcher extends LivingWatcher public class CreeperWatcher extends InsentientWatcher
{ {
public CreeperWatcher(Disguise disguise) public CreeperWatcher(Disguise disguise)
{ {
super(disguise); super(disguise);
} }
public boolean isIgnited() public boolean isIgnited()
{ {
return (boolean) getValue(FlagType.CREEPER_IGNITED); return (boolean) getValue(FlagType.CREEPER_IGNITED);
} }
public boolean isPowered() public boolean isPowered()
{ {
return (boolean) getValue(FlagType.CREEPER_POWERED); return (boolean) getValue(FlagType.CREEPER_POWERED);
} }
public void setIgnited(boolean ignited) public void setIgnited(boolean ignited)
{ {
setValue(FlagType.CREEPER_IGNITED, ignited); setValue(FlagType.CREEPER_IGNITED, ignited);
sendData(FlagType.CREEPER_IGNITED); sendData(FlagType.CREEPER_IGNITED);
} }
public void setPowered(boolean powered) public void setPowered(boolean powered)
{ {
setValue(FlagType.CREEPER_POWERED, powered); setValue(FlagType.CREEPER_POWERED, powered);
sendData(FlagType.CREEPER_POWERED); sendData(FlagType.CREEPER_POWERED);
} }
} }

View File

@ -1,29 +1,28 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.Material; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ItemStack;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
//TODO: Add support for custom items instead of just stone
//TODO: Add support for custom items instead of just stone public class DroppedItemWatcher extends FlagWatcher
public class DroppedItemWatcher extends FlagWatcher {
{
public DroppedItemWatcher(Disguise disguise)
public DroppedItemWatcher(Disguise disguise) {
{ super(disguise);
super(disguise); }
}
public ItemStack getItemStack()
public ItemStack getItemStack() {
{ return getValue(FlagType.DROPPED_ITEM);
return getValue(FlagType.DROPPED_ITEM); }
}
public void setItemStack(ItemStack item)
public void setItemStack(ItemStack item) {
{ setValue(FlagType.DROPPED_ITEM, item);
setValue(FlagType.DROPPED_ITEM, item); sendData(FlagType.DROPPED_ITEM);
sendData(FlagType.DROPPED_ITEM); }
} }
}

View File

@ -1,27 +1,27 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
/** /**
* @author Navid * @author Navid
*/ */
public class EnderDragonWatcher extends LivingWatcher public class EnderDragonWatcher extends InsentientWatcher
{ {
public EnderDragonWatcher(Disguise disguise) public EnderDragonWatcher(Disguise disguise)
{ {
super(disguise); super(disguise);
} }
public int getPhase() public int getPhase()
{ {
return getValue(FlagType.ENDERDRAGON_PHASE); return getValue(FlagType.ENDERDRAGON_PHASE);
} }
public void setPhase(int phase) public void setPhase(int phase)
{ {
setValue(FlagType.ENDERDRAGON_PHASE, phase); setValue(FlagType.ENDERDRAGON_PHASE, phase);
sendData(FlagType.ENDERDRAGON_PHASE); sendData(FlagType.ENDERDRAGON_PHASE);
} }
} }

View File

@ -1,68 +1,68 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.utilities.ReflectionManager; import me.libraryaddict.disguise.utilities.ReflectionManager;
public class EndermanWatcher extends LivingWatcher public class EndermanWatcher extends InsentientWatcher
{ {
public EndermanWatcher(Disguise disguise) public EndermanWatcher(Disguise disguise)
{ {
super(disguise); super(disguise);
} }
@Override @Override
public ItemStack getItemInMainHand() public ItemStack getItemInMainHand()
{ {
Optional<Integer> value = getValue(FlagType.ENDERMAN_ITEM); Optional<Integer> value = getValue(FlagType.ENDERMAN_ITEM);
if (value.isPresent()) if (value.isPresent())
{ {
Pair<Integer, Integer> pair = ReflectionManager.getFromCombinedId(value.get()); Pair<Integer, Integer> pair = ReflectionManager.getFromCombinedId(value.get());
int id = pair.getLeft(); int id = pair.getLeft();
int data = pair.getRight(); int data = pair.getRight();
return new ItemStack(id, 1, (short) data); return new ItemStack(id, 1, (short) data);
} }
else else
{ {
return null; return null;
} }
} }
@Override @Override
public void setItemInMainHand(ItemStack itemstack) public void setItemInMainHand(ItemStack itemstack)
{ {
setItemInMainHand(itemstack.getTypeId(), itemstack.getDurability()); setItemInMainHand(itemstack.getTypeId(), itemstack.getDurability());
} }
public void setItemInMainHand(int typeId) public void setItemInMainHand(int typeId)
{ {
setItemInMainHand(typeId, 0); setItemInMainHand(typeId, 0);
} }
public void setItemInMainHand(int typeId, int data) public void setItemInMainHand(int typeId, int data)
{ {
int combined = ReflectionManager.getCombinedId(typeId, data); int combined = ReflectionManager.getCombinedId(typeId, data);
setValue(FlagType.ENDERMAN_ITEM, Optional.of(combined)); setValue(FlagType.ENDERMAN_ITEM, Optional.of(combined));
} }
public boolean isAggressive() public boolean isAggressive()
{ {
return getValue(FlagType.ENDERMAN_AGRESSIVE); return getValue(FlagType.ENDERMAN_AGRESSIVE);
} }
public void setAggressive(boolean isAggressive) public void setAggressive(boolean isAggressive)
{ {
setValue(FlagType.ENDERMAN_AGRESSIVE, isAggressive); setValue(FlagType.ENDERMAN_AGRESSIVE, isAggressive);
sendData(FlagType.ENDERMAN_AGRESSIVE); sendData(FlagType.ENDERMAN_AGRESSIVE);
} }
} }

View File

@ -0,0 +1,43 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import com.google.common.base.Optional;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
public class FireworkWatcher extends FlagWatcher
{
public FireworkWatcher(Disguise disguise)
{
super(disguise);
}
public ItemStack getFirework()
{
if (getValue(FlagType.FIREWORK_ITEM) == null)
{
return new ItemStack(Material.AIR);
}
return (ItemStack) getValue(FlagType.FIREWORK_ITEM).get();
}
public void setFirework(ItemStack newItem)
{
if (newItem == null)
{
newItem = new ItemStack(Material.AIR);
}
newItem = newItem.clone();
newItem.setAmount(1);
setValue(FlagType.FIREWORK_ITEM, Optional.<ItemStack> of(newItem));
sendData(FlagType.FIREWORK_ITEM);
}
}

View File

@ -0,0 +1,29 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
public class FishingHookWatcher extends FlagWatcher
{
public FishingHookWatcher(Disguise disguise)
{
super(disguise);
}
public void setHooked(int hookedId)
{
setValue(FlagType.FISHING_HOOK, hookedId + 1);
sendData(FlagType.FISHING_HOOK);
}
public int getHooked()
{
int hooked = getValue(FlagType.FISHING_HOOK);
if (hooked > 0)
hooked--;
return hooked;
}
}

View File

@ -1,25 +1,25 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
public class GhastWatcher extends LivingWatcher public class GhastWatcher extends InsentientWatcher
{ {
public GhastWatcher(Disguise disguise) public GhastWatcher(Disguise disguise)
{ {
super(disguise); super(disguise);
} }
public boolean isAggressive() public boolean isAggressive()
{ {
return getValue(FlagType.GHAST_AGRESSIVE); return getValue(FlagType.GHAST_AGRESSIVE);
} }
public void setAggressive(boolean isAggressive) public void setAggressive(boolean isAggressive)
{ {
setValue(FlagType.GHAST_AGRESSIVE, isAggressive); setValue(FlagType.GHAST_AGRESSIVE, isAggressive);
sendData(FlagType.GHAST_AGRESSIVE); sendData(FlagType.GHAST_AGRESSIVE);
} }
} }

View File

@ -1,101 +1,101 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
public class GuardianWatcher extends LivingWatcher public class GuardianWatcher extends InsentientWatcher
{ {
public GuardianWatcher(Disguise disguise) public GuardianWatcher(Disguise disguise)
{ {
super(disguise); super(disguise);
} }
/** /**
* Is this guardian targetting someone? * Is this guardian targetting someone?
* *
* @return * @return
*/ */
public boolean isTarget() public boolean isTarget()
{ {
return ((int) getValue(FlagType.GUARDIAN_TARGET)) != 0; return ((int) getValue(FlagType.GUARDIAN_TARGET)) != 0;
} }
/** /**
* Shoot a beam at the given entityId. * Shoot a beam at the given entityId.
* *
* @param entityId * @param entityId
*/ */
public void setTarget(int entityId) public void setTarget(int entityId)
{ {
setValue(FlagType.GUARDIAN_TARGET, entityId); setValue(FlagType.GUARDIAN_TARGET, entityId);
sendData(FlagType.GUARDIAN_TARGET); sendData(FlagType.GUARDIAN_TARGET);
} }
public void setTarget(Entity entity) public void setTarget(Entity entity)
{ {
setTarget(entity == null ? 0 : entity.getEntityId()); setTarget(entity == null ? 0 : entity.getEntityId());
} }
/** /**
* Shoot a beam at the given player name. * Shoot a beam at the given player name.
* *
* @param playername * @param playername
*/ */
public void setTarget(String playername) public void setTarget(String playername)
{ {
Player player = Bukkit.getPlayer(playername); Player player = Bukkit.getPlayer(playername);
if (player == null) if (player == null)
return; return;
setValue(FlagType.GUARDIAN_TARGET, player.getEntityId()); setValue(FlagType.GUARDIAN_TARGET, player.getEntityId());
sendData(FlagType.GUARDIAN_TARGET); sendData(FlagType.GUARDIAN_TARGET);
} }
public boolean isRetractingSpikes() public boolean isRetractingSpikes()
{ {
return isGuardianFlag(2); return isGuardianFlag(2);
} }
public void setRetractingSpikes(boolean isRetracting) public void setRetractingSpikes(boolean isRetracting)
{ {
setGuardianFlag(2, isRetracting); setGuardianFlag(2, isRetracting);
} }
public boolean isElder() public boolean isElder()
{ {
return isGuardianFlag(4); return isGuardianFlag(4);
} }
public void setElder(boolean isGuardian) public void setElder(boolean isGuardian)
{ {
setGuardianFlag(4, isGuardian); setGuardianFlag(4, isGuardian);
} }
protected boolean isGuardianFlag(int no) protected boolean isGuardianFlag(int no)
{ {
return (getValue(FlagType.GUARDIAN_FLAG) & no) != 0; return (getValue(FlagType.GUARDIAN_FLAG) & no) != 0;
} }
protected void setGuardianFlag(int no, boolean flag) protected void setGuardianFlag(int no, boolean flag)
{ {
byte b0 = getValue(FlagType.GUARDIAN_FLAG); byte b0 = getValue(FlagType.GUARDIAN_FLAG);
if (flag) if (flag)
{ {
setValue(FlagType.GUARDIAN_FLAG, (byte) (b0 | no)); setValue(FlagType.GUARDIAN_FLAG, (byte) (b0 | no));
} }
else else
{ {
setValue(FlagType.GUARDIAN_FLAG, (byte) (b0 & -(no + 1))); setValue(FlagType.GUARDIAN_FLAG, (byte) (b0 & -(no + 1)));
} }
sendData(FlagType.GUARDIAN_FLAG); sendData(FlagType.GUARDIAN_FLAG);
} }
} }

View File

@ -1,233 +1,232 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Horse.Color; import org.bukkit.entity.Horse.Color;
import org.bukkit.entity.Horse.Style; import org.bukkit.entity.Horse.Style;
import org.bukkit.entity.Horse.Variant; import org.bukkit.entity.Horse.Variant;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
public class HorseWatcher extends AgeableWatcher public class HorseWatcher extends AgeableWatcher
{ {
public HorseWatcher(Disguise disguise)
public HorseWatcher(Disguise disguise) {
{ super(disguise);
super(disguise);
setStyle(Style.values()[DisguiseUtilities.random.nextInt(Style.values().length)]);
setStyle(Style.values()[DisguiseUtilities.random.nextInt(Style.values().length)]); setColor(Color.values()[DisguiseUtilities.random.nextInt(Color.values().length)]);
setColor(Color.values()[DisguiseUtilities.random.nextInt(Color.values().length)]); }
}
public Variant getVariant()
public Variant getVariant() {
{ return Variant.values()[getValue(FlagType.HORSE_VARIANT)];
return Variant.values()[getValue(FlagType.HORSE_VARIANT)]; }
}
public void setVariant(Variant variant)
public void setVariant(Variant variant) {
{ setVariant(variant.ordinal());
setVariant(variant.ordinal()); }
}
public void setVariant(int variant)
public void setVariant(int variant) {
{ if (variant < 0 || variant > 4)
if (variant < 0 || variant > 4) {
{ variant = 0; // Crashing people is mean
variant = 0; // Crashing people is mean }
}
setValue(FlagType.HORSE_VARIANT, variant);
setValue(FlagType.HORSE_VARIANT, variant); sendData(FlagType.HORSE_VARIANT);
sendData(FlagType.HORSE_VARIANT); }
}
public Color getColor()
public Color getColor() {
{ return Color.values()[((Integer) getValue(FlagType.HORSE_COLOR) & 0xFF)];
return Color.values()[((Integer) getValue(FlagType.HORSE_COLOR) & 0xFF)]; }
}
public ItemStack getHorseArmor()
public ItemStack getHorseArmor() {
{ int horseValue = getHorseArmorAsInt();
int horseValue = getHorseArmorAsInt();
switch (horseValue)
switch (horseValue) {
{ case 1:
case 1: return new ItemStack(Material.IRON_BARDING);
return new ItemStack(Material.IRON_BARDING); case 2:
case 2: return new ItemStack(Material.GOLD_BARDING);
return new ItemStack(Material.GOLD_BARDING); case 3:
case 3: return new ItemStack(Material.DIAMOND_BARDING);
return new ItemStack(Material.DIAMOND_BARDING); default:
default: break;
break; }
}
return null;
return null; }
}
protected int getHorseArmorAsInt()
protected int getHorseArmorAsInt() {
{ return getValue(FlagType.HORSE_ARMOR);
return getValue(FlagType.HORSE_ARMOR); }
}
public Optional<UUID> getOwner()
public Optional<UUID> getOwner() {
{ return getValue(FlagType.HORSE_OWNER);
return getValue(FlagType.HORSE_OWNER); }
}
public Style getStyle()
public Style getStyle() {
{ return Style.values()[(getValue(FlagType.HORSE_COLOR) >>> 8)];
return Style.values()[(getValue(FlagType.HORSE_STYLE) >>> 8)]; }
}
public boolean hasChest()
public boolean hasChest() {
{ return isHorseFlag(8);
return isHorseFlag(8); }
}
public boolean isBreedable()
public boolean isBreedable() {
{ return isHorseFlag(16);
return isHorseFlag(16); }
}
public boolean isGrazing()
public boolean isGrazing() {
{ return isHorseFlag(32);
return isHorseFlag(32); }
}
public boolean isMouthOpen()
public boolean isMouthOpen() {
{ return isHorseFlag(128);
return isHorseFlag(128); }
}
public boolean isRearing()
public boolean isRearing() {
{ return isHorseFlag(64);
return isHorseFlag(64); }
}
public boolean isSaddled()
public boolean isSaddled() {
{ return isHorseFlag(4);
return isHorseFlag(4); }
}
public boolean isTamed()
public boolean isTamed() {
{ return isHorseFlag(2);
return isHorseFlag(2); }
}
private boolean isHorseFlag(int i)
private boolean isHorseFlag(int i) {
{ return (getHorseFlag() & i) != 0;
return (getHorseFlag() & i) != 0; }
}
private byte getHorseFlag()
private byte getHorseFlag() {
{ return getValue(FlagType.HORSE_META);
return getValue(FlagType.HORSE_META); }
}
public void setCanBreed(boolean breed)
public void setCanBreed(boolean breed) {
{ setHorseFlag(16, breed);
setHorseFlag(16, breed); }
}
public void setCarryingChest(boolean chest)
public void setCarryingChest(boolean chest) {
{ setHorseFlag(8, chest);
setHorseFlag(8, chest); }
}
public void setColor(Color color)
public void setColor(Color color) {
{ setValue(FlagType.HORSE_COLOR, color.ordinal() & 0xFF | getStyle().ordinal() << 8);
setValue(FlagType.HORSE_COLOR, color.ordinal() & 0xFF | getStyle().ordinal() << 8); sendData(FlagType.HORSE_COLOR);
sendData(FlagType.HORSE_COLOR); }
}
private void setHorseFlag(int i, boolean flag)
private void setHorseFlag(int i, boolean flag) {
{ byte j = getValue(FlagType.HORSE_META);
byte j = getValue(FlagType.HORSE_META);
if (flag)
if (flag) {
{ setValue(FlagType.HORSE_META, (byte) (j | i));
setValue(FlagType.HORSE_META, (byte) (j | i)); }
} else
else {
{ setValue(FlagType.HORSE_META, (byte) (j & ~i));
setValue(FlagType.HORSE_META, (byte) (j & ~i)); }
}
sendData(FlagType.HORSE_META);
sendData(FlagType.HORSE_META); }
}
public void setGrazing(boolean grazing)
public void setGrazing(boolean grazing) {
{ setHorseFlag(32, grazing);
setHorseFlag(32, grazing); }
}
protected void setHorseArmor(int armor)
protected void setHorseArmor(int armor) {
{ setValue(FlagType.HORSE_ARMOR, armor);
setValue(FlagType.HORSE_ARMOR, armor); sendData(FlagType.HORSE_ARMOR);
sendData(FlagType.HORSE_ARMOR); }
}
public void setHorseArmor(ItemStack item)
public void setHorseArmor(ItemStack item) {
{ int value = 0;
int value = 0;
if (item != null)
if (item != null) {
{ Material mat = item.getType();
Material mat = item.getType();
if (mat == Material.IRON_BARDING)
if (mat == Material.IRON_BARDING) {
{ value = 1;
value = 1; }
} else if (mat == Material.GOLD_BARDING)
else if (mat == Material.GOLD_BARDING) {
{ value = 2;
value = 2; }
} else if (mat == Material.DIAMOND_BARDING)
else if (mat == Material.DIAMOND_BARDING) {
{ value = 3;
value = 3; }
} }
}
setHorseArmor(value);
setHorseArmor(value); }
}
public void setMouthOpen(boolean mouthOpen)
public void setMouthOpen(boolean mouthOpen) {
{ setHorseFlag(128, mouthOpen);
setHorseFlag(128, mouthOpen); }
}
public void setOwner(UUID uuid)
public void setOwner(UUID uuid) {
{ setValue(FlagType.HORSE_OWNER, Optional.of(uuid));
setValue(FlagType.HORSE_OWNER, Optional.of(uuid)); sendData(FlagType.HORSE_OWNER);
sendData(FlagType.HORSE_OWNER); }
}
public void setRearing(boolean rear)
public void setRearing(boolean rear) {
{ setHorseFlag(64, rear);
setHorseFlag(64, rear); }
}
public void setSaddled(boolean saddled)
public void setSaddled(boolean saddled) {
{ setHorseFlag(4, saddled);
setHorseFlag(4, saddled); }
}
public void setStyle(Style style)
public void setStyle(Style style) {
{ setValue(FlagType.HORSE_COLOR, getColor().ordinal() & 0xFF | style.ordinal() << 8);
setValue(FlagType.HORSE_STYLE, getColor().ordinal() & 0xFF | style.ordinal() << 8); sendData(FlagType.HORSE_COLOR);
sendData(FlagType.HORSE_STYLE); }
}
public void setTamed(boolean tamed)
public void setTamed(boolean tamed) {
{ setHorseFlag(2, tamed);
setHorseFlag(2, tamed); }
}
}
}

View File

@ -1,63 +1,55 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import org.bukkit.inventory.MainHand;
import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class InsentientWatcher extends LivingWatcher import me.libraryaddict.disguise.disguisetypes.FlagType;
{
public InsentientWatcher(Disguise disguise) public class InsentientWatcher extends LivingWatcher
{ {
super(disguise); public InsentientWatcher(Disguise disguise)
} {
super(disguise);
public void setLeftHanded(boolean leftHanded) }
{
setRightHanded(!leftHanded); public void setMainHand(MainHand mainHand)
} {
setInsentientFlag(2, mainHand == MainHand.RIGHT);
public void setRightHanded(boolean rightHanded) sendData(FlagType.INSENTIENT_META);
{ }
setInsentientFlag(2, rightHanded);
sendData(FlagType.INSENTIENT_META); public MainHand getMainHand()
} {
return getInsentientFlag(2) ? MainHand.RIGHT : MainHand.LEFT;
public boolean isRightHanded() }
{
return getInsentientFlag(2); public boolean isAI()
} {
return getInsentientFlag(1);
public boolean isLeftHanded() }
{
return !isRightHanded(); public void setAI(boolean ai)
} {
setInsentientFlag(1, ai);
public boolean isAI() sendData(FlagType.INSENTIENT_META);
{ }
return getInsentientFlag(1);
} private void setInsentientFlag(int i, boolean flag)
{
public void setAI(boolean ai) byte b0 = (byte) getValue(FlagType.INSENTIENT_META);
{
setInsentientFlag(1, ai); if (flag)
sendData(FlagType.INSENTIENT_META); {
} setValue(FlagType.INSENTIENT_META, (byte) (b0 | 1 << i));
}
private void setInsentientFlag(int i, boolean flag) else
{ {
byte b0 = (byte) getValue(FlagType.INSENTIENT_META); setValue(FlagType.INSENTIENT_META, (byte) (b0 & (~1 << i)));
}
if (flag) }
{
setValue(FlagType.INSENTIENT_META, (byte) (b0 | 1 << i)); private boolean getInsentientFlag(int i)
} {
else return ((byte) getValue(FlagType.PLAYER_SKIN) & 1 << i) != 0;
{ }
setValue(FlagType.INSENTIENT_META, (byte) (b0 & (~1 << i))); }
}
}
private boolean getInsentientFlag(int i)
{
return ((byte) getValue(FlagType.PLAYER_SKIN) & 1 << i) != 0;
}
}

View File

@ -0,0 +1,12 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class IronGolemWatcher extends InsentientWatcher
{
public IronGolemWatcher(Disguise disguise)
{
super(disguise);
}
}

View File

@ -1,53 +1,54 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import me.libraryaddict.disguise.disguisetypes.Disguise; import com.google.common.base.Optional;
import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class ItemFrameWatcher extends FlagWatcher import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
{
public class ItemFrameWatcher extends FlagWatcher
public ItemFrameWatcher(Disguise disguise) {
{ public ItemFrameWatcher(Disguise disguise)
super(disguise); {
} super(disguise);
}
public ItemStack getItem()
{ public ItemStack getItem()
if (getValue(FlagType.ITEMFRAME_ITEM) == null) {
{ if (getValue(FlagType.ITEMFRAME_ITEM) == null)
return new ItemStack(Material.AIR); {
} return new ItemStack(Material.AIR);
}
return (ItemStack) getValue(FlagType.ITEMFRAME_ITEM);
} return (ItemStack) getValue(FlagType.ITEMFRAME_ITEM).get();
}
public int getRotation()
{ public int getRotation()
return getValue(FlagType.ITEMFRAME_ROTATION); {
} return getValue(FlagType.ITEMFRAME_ROTATION);
}
public void setItem(ItemStack newItem)
{ public void setItem(ItemStack newItem)
if (newItem == null) {
{ if (newItem == null)
newItem = new ItemStack(Material.AIR); {
} newItem = new ItemStack(Material.AIR);
}
newItem = newItem.clone();
newItem.setAmount(1); newItem = newItem.clone();
newItem.setAmount(1);
setValue(FlagType.ITEMFRAME_ITEM, newItem);
sendData(FlagType.ITEMFRAME_ITEM); setValue(FlagType.ITEMFRAME_ITEM, Optional.<ItemStack> of(newItem));
} sendData(FlagType.ITEMFRAME_ITEM);
}
public void setRotation(int rotation)
{ public void setRotation(int rotation)
setValue(FlagType.ITEMFRAME_ROTATION, (byte) (rotation % 4)); {
sendData(FlagType.ITEMFRAME_ROTATION); setValue(FlagType.ITEMFRAME_ROTATION, rotation % 4);
} sendData(FlagType.ITEMFRAME_ROTATION);
}
}
}

View File

@ -2,6 +2,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.MainHand;
import com.comphenix.protocol.PacketType.Play.Server; import com.comphenix.protocol.PacketType.Play.Server;
import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolLibrary;
@ -34,6 +35,17 @@ public class PlayerWatcher extends LivingWatcher
return watcher; return watcher;
} }
public void setMainHand(MainHand mainHand)
{
setValue(FlagType.PLAYER_HAND, (byte) mainHand.ordinal());
sendData(FlagType.PLAYER_HAND);
}
public MainHand getMainHand()
{
return MainHand.values()[getValue(FlagType.PLAYER_HAND)];
}
public BlockFace getSleepingDirection() public BlockFace getSleepingDirection()
{ {
if (sleepingDirection == null) if (sleepingDirection == null)

View File

@ -1,52 +1,61 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import com.comphenix.protocol.wrappers.BlockPosition; import com.comphenix.protocol.wrappers.BlockPosition;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
/**
* @author Navid /**
*/ * @author Navid
// TODO: Add the appropriate data values to this class */
public class ShulkerWatcher extends LivingWatcher public class ShulkerWatcher extends InsentientWatcher
{ {
public ShulkerWatcher(Disguise disguise) public ShulkerWatcher(Disguise disguise)
{ {
super(disguise); super(disguise);
} }
public BlockFace getFacingDirection() public BlockFace getFacingDirection()
{ {
return BlockFace.UP; return getValue(FlagType.SHULKER_FACING);
} }
public void setFacingDirection() public void setFacingDirection(BlockFace face)
{ {
setValue(FlagType.SHULKER_FACING, face);
} sendData(FlagType.SHULKER_FACING);
}
public Optional<BlockPosition> getAttachmentPosition()
{ public BlockPosition getAttachmentPosition()
return Optional.absent(); {
} return getValue(FlagType.SHULKER_ATTACHED).get();
}
public void setAttachmentPosition(BlockPosition pos)
{ public void setAttachmentPosition(BlockPosition pos)
{
} setValue(FlagType.SHULKER_ATTACHED, Optional.of(pos));
sendData(FlagType.SHULKER_ATTACHED);
public byte getShieldHeight() }
{
return 0x00; public int getShieldHeight()
} {
return getValue(FlagType.SHULKER_PEEKING);
public void setShieldHeight() }
{
public void setShieldHeight(int newHeight)
} {
if (newHeight < 0)
} newHeight = 0;
if (newHeight > 127)
newHeight = 127;
setValue(FlagType.SHULKER_PEEKING, (byte) newHeight);
sendData(FlagType.SHULKER_PEEKING);
}
}

View File

@ -1,28 +1,39 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.entity.Skeleton.SkeletonType; import org.bukkit.entity.Skeleton.SkeletonType;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
/** /**
* @author Navid * @author Navid
*/ */
public class SkeletonWatcher extends LivingWatcher public class SkeletonWatcher extends InsentientWatcher
{ {
public SkeletonWatcher(Disguise disguise) public SkeletonWatcher(Disguise disguise)
{ {
super(disguise); super(disguise);
} }
public void setType(SkeletonType type) public void setSwingArms(boolean swingingArms)
{ {
setValue(FlagType.SKELETON_TYPE, type.ordinal()); setValue(FlagType.SKELETON_SWING_ARMS, swingingArms);
sendData(FlagType.SKELETON_TYPE); sendData(FlagType.SKELETON_SWING_ARMS);
} }
public SkeletonType getType() public boolean isSwingArms()
{ {
return SkeletonType.values()[getValue(FlagType.SKELETON_TYPE)]; return getValue(FlagType.SKELETON_SWING_ARMS);
} }
}
public void setType(SkeletonType type)
{
setValue(FlagType.SKELETON_TYPE, type.ordinal());
sendData(FlagType.SKELETON_TYPE);
}
public SkeletonType getType()
{
return SkeletonType.values()[getValue(FlagType.SKELETON_TYPE)];
}
}

View File

@ -1,32 +1,32 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
public class SlimeWatcher extends LivingWatcher public class SlimeWatcher extends InsentientWatcher
{ {
public SlimeWatcher(Disguise disguise) public SlimeWatcher(Disguise disguise)
{ {
super(disguise); super(disguise);
setSize(DisguiseUtilities.random.nextInt(4) + 1); setSize(DisguiseUtilities.random.nextInt(4) + 1);
} }
public int getSize() public int getSize()
{ {
return (int) getValue(FlagType.SLIME_SIZE); return (int) getValue(FlagType.SLIME_SIZE);
} }
public void setSize(int size) public void setSize(int size)
{ {
if (size <= 0 || size >= 128) if (size <= 0 || size >= 128)
{ {
size = 1; size = 1;
} }
setValue(FlagType.SLIME_SIZE, size); setValue(FlagType.SLIME_SIZE, size);
sendData(FlagType.SLIME_SIZE); sendData(FlagType.SLIME_SIZE);
} }
} }

View File

@ -0,0 +1,23 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class SnowmanWatcher extends InsentientWatcher
{
public SnowmanWatcher(Disguise disguise)
{
super(disguise);
}
public void setHat(boolean hat)
{
setValue(FlagType.SNOWMAN_HAT, (byte) (hat ? 1 : 0));
sendData(FlagType.SNOWMAN_HAT);
}
public boolean isHat()
{
return getValue(FlagType.SNOWMAN_HAT) == 1;
}
}

View File

@ -0,0 +1,23 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class SpiderWatcher extends InsentientWatcher
{
public SpiderWatcher(Disguise disguise)
{
super(disguise);
}
public void setClimbing(boolean climbing)
{
setValue(FlagType.SPIDER_CLIMB, (byte) (climbing ? 1 : 0));
sendData(FlagType.SPIDER_CLIMB);
}
public boolean isClimbing()
{
return getValue(FlagType.SPIDER_CLIMB) == (byte) 1;
}
}

View File

@ -1,40 +1,56 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import org.bukkit.inventory.ItemStack;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import com.google.common.base.Optional;
public class SplashPotionWatcher extends FlagWatcher import me.libraryaddict.disguise.disguisetypes.Disguise;
{ import me.libraryaddict.disguise.disguisetypes.FlagType;
private int potionId; import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
public SplashPotionWatcher(Disguise disguise)
{ public class SplashPotionWatcher extends FlagWatcher
super(disguise); {
} private int potionId;
@Override public SplashPotionWatcher(Disguise disguise)
public SplashPotionWatcher clone(Disguise disguise) {
{ super(disguise);
SplashPotionWatcher watcher = (SplashPotionWatcher) super.clone(disguise); }
watcher.setPotionId(getPotionId());
@Override
return watcher; public SplashPotionWatcher clone(Disguise disguise)
} {
SplashPotionWatcher watcher = (SplashPotionWatcher) super.clone(disguise);
public int getPotionId() watcher.setPotionId(getPotionId());
{
return potionId; return watcher;
} }
public void setPotionId(int newPotionId) public int getPotionId()
{ {
this.potionId = newPotionId; return potionId;
}
if (getDisguise().getEntity() != null && getDisguise().getWatcher() == this)
{ public void setSplashPotion(ItemStack item)
DisguiseUtilities.refreshTrackers(getDisguise()); {
} setValue(FlagType.SPLASH_POTION_ITEM, Optional.of(item));
} sendData(FlagType.SPLASH_POTION_ITEM);
}
}
public ItemStack getSplashPotion()
{
return getValue(FlagType.SPLASH_POTION_ITEM).get();
}
public void setPotionId(int newPotionId)
{
this.potionId = newPotionId;
if (getDisguise().getEntity() != null && getDisguise().getWatcher() == this)
{
DisguiseUtilities.refreshTrackers(getDisguise());
}
}
}

View File

@ -0,0 +1,11 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class SquidWatcher extends InsentientWatcher
{
public SquidWatcher(Disguise disguise)
{
super(disguise);
}
}

View File

@ -0,0 +1,12 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
public class TNTWatcher extends FlagWatcher
{
public TNTWatcher(Disguise disguise)
{
super(disguise);
}
}

View File

@ -1,37 +1,37 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.Color; import org.bukkit.Color;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
/** /**
* @author Navid * @author Navid
*/ */
public class TippedArrowWatcher extends ArrowWatcher public class TippedArrowWatcher extends ArrowWatcher
{ {
public TippedArrowWatcher(Disguise disguise) public TippedArrowWatcher(Disguise disguise)
{ {
super(disguise); super(disguise);
int r = DisguiseUtilities.random.nextInt(256); int r = DisguiseUtilities.random.nextInt(256);
int g = DisguiseUtilities.random.nextInt(256); int g = DisguiseUtilities.random.nextInt(256);
int b = DisguiseUtilities.random.nextInt(256); int b = DisguiseUtilities.random.nextInt(256);
setColor(Color.fromRGB(r, g, b)); setColor(Color.fromRGB(r, g, b));
} }
public Color getColor() public Color getColor()
{ {
int color = (int) getValue(FlagType.TIPPED_ARROW_COLOR); int color = (int) getValue(FlagType.TIPPED_ARROW_COLOR);
return Color.fromRGB(color); return Color.fromRGB(color);
} }
public void setColor(Color color) public void setColor(Color color)
{ {
setValue(FlagType.TIPPED_ARROW_COLOR, color.asRGB()); setValue(FlagType.TIPPED_ARROW_COLOR, color.asRGB());
sendData(FlagType.TIPPED_ARROW_COLOR); sendData(FlagType.TIPPED_ARROW_COLOR);
} }
} }

View File

@ -1,28 +1,28 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
/** /**
* @author Navid * @author Navid
*/ */
public class WitchWatcher extends LivingWatcher public class WitchWatcher extends InsentientWatcher
{ {
public WitchWatcher(Disguise disguise) public WitchWatcher(Disguise disguise)
{ {
super(disguise); super(disguise);
} }
public boolean isAggressive() public boolean isAggressive()
{ {
return (boolean) getValue(FlagType.WITCH_AGGRESSIVE); return (boolean) getValue(FlagType.WITCH_AGGRESSIVE);
} }
public void setAggressive(boolean aggressive) public void setAggressive(boolean aggressive)
{ {
setValue(FlagType.WITCH_AGGRESSIVE, aggressive); setValue(FlagType.WITCH_AGGRESSIVE, aggressive);
sendData(FlagType.WITCH_AGGRESSIVE); sendData(FlagType.WITCH_AGGRESSIVE);
} }
} }

View File

@ -1,58 +1,58 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import java.security.InvalidParameterException; import java.security.InvalidParameterException;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
public class WitherWatcher extends LivingWatcher public class WitherWatcher extends InsentientWatcher
{ {
public WitherWatcher(Disguise disguise) public WitherWatcher(Disguise disguise)
{ {
super(disguise); super(disguise);
} }
/** /**
* Returns the amount of time this Wither is invulnerable for * Returns the amount of time this Wither is invulnerable for
* *
* @return * @return
*/ */
public int getInvulnerability() public int getInvulnerability()
{ {
return (int) getValue(FlagType.WITHER_INVUL); return (int) getValue(FlagType.WITHER_INVUL);
} }
public int[] getTargets() public int[] getTargets()
{ {
return new int[] return new int[]
{ {
getValue(FlagType.WITHER_TARGET_1), getValue(FlagType.WITHER_TARGET_2), getValue(FlagType.WITHER_TARGET_3) getValue(FlagType.WITHER_TARGET_1), getValue(FlagType.WITHER_TARGET_2), getValue(FlagType.WITHER_TARGET_3)
}; };
} }
/** /**
* Sets the amount of time this Wither is invulnerable for * Sets the amount of time this Wither is invulnerable for
*/ */
public void setInvulnerability(int invulnerability) public void setInvulnerability(int invulnerability)
{ {
setValue(FlagType.WITHER_INVUL, invulnerability); setValue(FlagType.WITHER_INVUL, invulnerability);
sendData(FlagType.WITHER_INVUL); sendData(FlagType.WITHER_INVUL);
} }
public void setTargets(int... targets) public void setTargets(int... targets)
{ {
if (targets.length != 3) if (targets.length != 3)
{ {
throw new InvalidParameterException( throw new InvalidParameterException(
ChatColor.RED + "Expected 3 numbers for wither setTargets. Received " + targets.length); ChatColor.RED + "Expected 3 numbers for wither setTargets. Received " + targets.length);
} }
setValue(FlagType.WITHER_TARGET_1, targets[0]); setValue(FlagType.WITHER_TARGET_1, targets[0]);
setValue(FlagType.WITHER_TARGET_2, targets[1]); setValue(FlagType.WITHER_TARGET_2, targets[1]);
setValue(FlagType.WITHER_TARGET_3, targets[2]); setValue(FlagType.WITHER_TARGET_3, targets[2]);
sendData(FlagType.WITHER_TARGET_1, FlagType.WITHER_TARGET_2, FlagType.WITHER_TARGET_3); sendData(FlagType.WITHER_TARGET_1, FlagType.WITHER_TARGET_2, FlagType.WITHER_TARGET_3);
} }
} }

View File

@ -1,106 +1,106 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.entity.Villager.Profession; import org.bukkit.entity.Villager.Profession;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
public class ZombieWatcher extends LivingWatcher public class ZombieWatcher extends InsentientWatcher
{ {
public ZombieWatcher(Disguise disguise) public ZombieWatcher(Disguise disguise)
{ {
super(disguise); super(disguise);
} }
public boolean isAdult() public boolean isAdult()
{ {
return !isBaby(); return !isBaby();
} }
public boolean isBaby() public boolean isBaby()
{ {
return getValue(FlagType.ZOMBIE_BABY); return getValue(FlagType.ZOMBIE_BABY);
} }
public boolean isShaking() public boolean isShaking()
{ {
return getValue(FlagType.ZOMBIE_SHAKING); return getValue(FlagType.ZOMBIE_SHAKING);
} }
/** /**
* Is this zombie a villager? * Is this zombie a villager?
* *
* @return * @return
*/ */
public boolean isVillager() public boolean isVillager()
{ {
return ((int) getValue(FlagType.ZOMBIE_PROFESSION)) != 0; return ((int) getValue(FlagType.ZOMBIE_PROFESSION)) != 0;
} }
public boolean isAggressive() public boolean isAggressive()
{ {
return (boolean) getValue(FlagType.ZOMBIE_AGGRESSIVE); return (boolean) getValue(FlagType.ZOMBIE_AGGRESSIVE);
} }
/** /**
* Only returns a valid value if this zombie is a villager. * Only returns a valid value if this zombie is a villager.
* *
* @return * @return
*/ */
public Profession getProfession() public Profession getProfession()
{ {
return Profession.values()[getValue(FlagType.ZOMBIE_PROFESSION)]; return Profession.values()[getValue(FlagType.ZOMBIE_PROFESSION)];
} }
public void setAdult() public void setAdult()
{ {
setBaby(false); setBaby(false);
} }
public void setBaby() public void setBaby()
{ {
setBaby(true); setBaby(true);
} }
public void setBaby(boolean baby) public void setBaby(boolean baby)
{ {
setValue(FlagType.ZOMBIE_BABY, baby); setValue(FlagType.ZOMBIE_BABY, baby);
sendData(FlagType.ZOMBIE_BABY); sendData(FlagType.ZOMBIE_BABY);
} }
public void setShaking(boolean shaking) public void setShaking(boolean shaking)
{ {
setValue(FlagType.ZOMBIE_SHAKING, shaking); setValue(FlagType.ZOMBIE_SHAKING, shaking);
sendData(FlagType.ZOMBIE_SHAKING); sendData(FlagType.ZOMBIE_SHAKING);
} }
/** /**
* Sets the profession of this zombie, in turn turning it into a Zombie Villager * Sets the profession of this zombie, in turn turning it into a Zombie Villager
* *
* @param id * @param id
*/ */
public void setProfession(int id) public void setProfession(int id)
{ {
setValue(FlagType.ZOMBIE_PROFESSION, id); setValue(FlagType.ZOMBIE_PROFESSION, id);
sendData(FlagType.ZOMBIE_PROFESSION); sendData(FlagType.ZOMBIE_PROFESSION);
} }
/** /**
* Sets the profession of this zombie, in turn turning it into a Zombie Villager * Sets the profession of this zombie, in turn turning it into a Zombie Villager
* *
* @param profession * @param profession
*/ */
public void setProfession(Profession profession) public void setProfession(Profession profession)
{ {
setValue(FlagType.ZOMBIE_PROFESSION, profession.ordinal()); setValue(FlagType.ZOMBIE_PROFESSION, profession.ordinal());
sendData(FlagType.ZOMBIE_PROFESSION); sendData(FlagType.ZOMBIE_PROFESSION);
} }
public void setAggressive(boolean handsup) public void setAggressive(boolean handsup)
{ {
setValue(FlagType.ZOMBIE_AGGRESSIVE, handsup); setValue(FlagType.ZOMBIE_AGGRESSIVE, handsup);
sendData(FlagType.ZOMBIE_AGGRESSIVE); sendData(FlagType.ZOMBIE_AGGRESSIVE);
} }
} }

View File

@ -3,7 +3,6 @@ package me.libraryaddict.disguise.utilities;
import java.util.HashMap; import java.util.HashMap;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class DisguiseValues public class DisguiseValues
{ {
@ -40,11 +39,6 @@ public class DisguiseValues
return values.get(type); return values.get(type);
} }
public static HashMap<FlagType, Object> getMetaValues(DisguiseType type)
{
return getDisguiseValues(type).getMetaValues();
}
public static Class getNmsEntityClass(DisguiseType type) public static Class getNmsEntityClass(DisguiseType type)
{ {
return getDisguiseValues(type).getNmsEntityClass(); return getDisguiseValues(type).getNmsEntityClass();
@ -54,7 +48,6 @@ public class DisguiseValues
private FakeBoundingBox babyBox; private FakeBoundingBox babyBox;
private float[] entitySize; private float[] entitySize;
private double maxHealth; private double maxHealth;
private HashMap<FlagType, Object> metaValues = new HashMap<>();
private Class nmsEntityClass; private Class nmsEntityClass;
public DisguiseValues(DisguiseType type, Class classType, int entitySize, double maxHealth) public DisguiseValues(DisguiseType type, Class classType, int entitySize, double maxHealth)
@ -84,11 +77,6 @@ public class DisguiseValues
return maxHealth; return maxHealth;
} }
public HashMap<FlagType, Object> getMetaValues()
{
return metaValues;
}
public Class getNmsEntityClass() public Class getNmsEntityClass()
{ {
return nmsEntityClass; return nmsEntityClass;
@ -108,9 +96,4 @@ public class DisguiseValues
{ {
this.entitySize = size; this.entitySize = size;
} }
public void setMetaValue(FlagType id, Object value)
{
metaValues.put(id, value);
}
} }

View File

@ -16,6 +16,7 @@ import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.reflect.StructureModifier;
import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;