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;
import java.io.IOException;
import java.lang.reflect.Field;
import org.bukkit.Bukkit;
import org.bukkit.entity.Ageable;
import org.bukkit.entity.Damageable;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Zombie;
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.wrappers.WrappedWatchableObject;
import me.libraryaddict.disguise.commands.CloneDisguiseCommand;
import me.libraryaddict.disguise.commands.DisguiseCommand;
import me.libraryaddict.disguise.commands.DisguiseViewSelf;
import me.libraryaddict.disguise.commands.EntityDisguiseCommand;
import me.libraryaddict.disguise.commands.HelpDisguiseCommand;
import me.libraryaddict.disguise.commands.LibsDisguisesCommand;
import me.libraryaddict.disguise.commands.PlayerDisguiseCommand;
import me.libraryaddict.disguise.commands.RadiusDisguiseCommand;
import me.libraryaddict.disguise.commands.UndisguiseCommand;
import me.libraryaddict.disguise.commands.UndisguiseEntityCommand;
import me.libraryaddict.disguise.commands.UndisguisePlayerCommand;
import me.libraryaddict.disguise.commands.UndisguiseRadiusCommand;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SkeletonWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SlimeWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.TameableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import me.libraryaddict.disguise.utilities.DisguiseSound;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.DisguiseValues;
import me.libraryaddict.disguise.utilities.FakeBoundingBox;
import me.libraryaddict.disguise.utilities.Metrics;
import me.libraryaddict.disguise.utilities.PacketsManager;
import me.libraryaddict.disguise.utilities.ReflectionManager;
public class LibsDisguises extends JavaPlugin
{
private static LibsDisguises instance;
private DisguiseListener listener;
@Override
public void onEnable()
{
getLogger().info("Discovered MC version: " + ReflectionManager.getBukkitVersion());
saveDefaultConfig();
PacketsManager.init(this);
DisguiseUtilities.init(this);
DisguiseConfig.initConfig(getConfig());
PacketsManager.addPacketListeners();
listener = new DisguiseListener(this);
Bukkit.getPluginManager().registerEvents(listener, this);
getCommand("disguise").setExecutor(new DisguiseCommand());
getCommand("undisguise").setExecutor(new UndisguiseCommand());
getCommand("disguiseplayer").setExecutor(new PlayerDisguiseCommand());
getCommand("undisguiseplayer").setExecutor(new UndisguisePlayerCommand());
getCommand("undisguiseentity").setExecutor(new UndisguiseEntityCommand());
getCommand("disguiseentity").setExecutor(new EntityDisguiseCommand());
getCommand("disguiseradius").setExecutor(new RadiusDisguiseCommand(getConfig().getInt("DisguiseRadiusMax")));
getCommand("undisguiseradius").setExecutor(new UndisguiseRadiusCommand(getConfig().getInt("UndisguiseRadiusMax")));
getCommand("disguisehelp").setExecutor(new HelpDisguiseCommand());
getCommand("disguiseclone").setExecutor(new CloneDisguiseCommand());
getCommand("libsdisguises").setExecutor(new LibsDisguisesCommand());
getCommand("disguiseviewself").setExecutor(new DisguiseViewSelf());
registerValues();
instance = this;
try
{
Metrics metrics = new Metrics(this);
metrics.start();
}
catch (IOException e)
{
}
}
/**
* Reloads the config with new config options.
*/
public void reload()
{
HandlerList.unregisterAll(listener);
reloadConfig();
DisguiseConfig.initConfig(getConfig());
}
/**
* 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.
*/
private void registerValues()
{
for (DisguiseType disguiseType : DisguiseType.values())
{
if (disguiseType.getEntityType() == null)
{
continue;
}
Class watcherClass = null;
try
{
switch (disguiseType)
{
case ITEM_FRAME: // Not really supported...
break;
case MINECART_CHEST:
case MINECART_COMMAND:
case MINECART_FURNACE:
case MINECART_HOPPER:
case MINECART_MOB_SPAWNER:
case MINECART_TNT:
watcherClass = MinecartWatcher.class;
break;
case DONKEY:
case MULE:
case UNDEAD_HORSE:
case SKELETON_HORSE:
watcherClass = HorseWatcher.class;
break;
case ZOMBIE_VILLAGER:
case PIG_ZOMBIE:
watcherClass = ZombieWatcher.class;
break;
case MAGMA_CUBE:
watcherClass = SlimeWatcher.class;
break;
case ELDER_GUARDIAN:
watcherClass = GuardianWatcher.class;
break;
case ENDERMITE:
watcherClass = LivingWatcher.class;
break;
case WITHER_SKELETON:
watcherClass = SkeletonWatcher.class;
break;
default:
watcherClass = Class.forName(
"me.libraryaddict.disguise.disguisetypes.watchers." + toReadable(disguiseType.name()) + "Watcher");
break;
}
}
catch (ClassNotFoundException ex)
{
// There is no explicit watcher for this entity.
Class entityClass = disguiseType.getEntityType().getEntityClass();
if (entityClass != null)
{
if (Tameable.class.isAssignableFrom(entityClass))
{
watcherClass = TameableWatcher.class;
}
else if (Ageable.class.isAssignableFrom(entityClass))
{
watcherClass = AgeableWatcher.class;
}
else if (LivingEntity.class.isAssignableFrom(entityClass))
{
watcherClass = LivingWatcher.class;
}
else
{
watcherClass = FlagWatcher.class;
}
}
else
{
watcherClass = FlagWatcher.class; // Disguise is unknown type
}
}
disguiseType.setWatcherClass(watcherClass);
if (DisguiseValues.getDisguiseValues(disguiseType) != null)
{
continue;
}
String nmsEntityName = toReadable(disguiseType.name());
switch (disguiseType)
{
case WITHER_SKELETON:
case ZOMBIE_VILLAGER:
case DONKEY:
case MULE:
case UNDEAD_HORSE:
case SKELETON_HORSE:
continue;
case PRIMED_TNT:
nmsEntityName = "TNTPrimed";
break;
case MINECART_TNT:
nmsEntityName = "MinecartTNT";
break;
case MINECART:
nmsEntityName = "MinecartRideable";
break;
case FIREWORK:
nmsEntityName = "Fireworks";
break;
case SPLASH_POTION:
nmsEntityName = "Potion";
break;
case GIANT:
nmsEntityName = "GiantZombie";
break;
case DROPPED_ITEM:
nmsEntityName = "Item";
break;
case FIREBALL:
nmsEntityName = "LargeFireball";
break;
case LEASH_HITCH:
nmsEntityName = "Leash";
break;
case ELDER_GUARDIAN:
nmsEntityName = "Guardian";
break;
case ARROW:
nmsEntityName = "TippedArrow";
default:
break;
}
try
{
if (nmsEntityName.equalsIgnoreCase("Unknown"))
{
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, null, 0, 0);
disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0));
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
if (sound != null)
{
sound.setDamageAndIdleSoundVolume(1f);
}
continue;
}
Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName);
if (nmsEntity == null)
{
getLogger().warning("Entity not found! (" + nmsEntityName + ")");
continue;
}
Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity);
int entitySize = 0;
for (Field field : ReflectionManager.getNmsClass("Entity").getFields())
{
if (field.getType().getName().equals("EnumEntitySize"))
{
Enum enumEntitySize = (Enum) field.get(nmsEntity);
entitySize = enumEntitySize.ordinal();
break;
}
}
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, nmsEntity.getClass(), entitySize,
bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0);
WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity);
for (WrappedWatchableObject watch : watcher.getWatchableObjects())
{
FlagType flagType = FlagType.getFlag(watcherClass, watch.getIndex());
if (flagType == null)
{
System.err.println("Error finding the FlagType for " + disguiseType.name() + "! " + watch.getIndex()
+ " cannot be found!");
System.err.println("Lib's Disguises will continue to load, but this will not work properly!");
continue;
}
disguiseValues.setMetaValue(flagType, watch.getValue());
// Uncomment when I need to find the new datawatcher values for a class..
// int id = watch.getIndex();
// Object val = watch.getValue();
// Class<?> valClazz = val != null ? watch.getValue().getClass() : null;
// try {
// val = val.toString();
// } catch (Exception e) {
// val = val != null ? val.getClass() : "null";
// }
// System.out.println("Disguise: " + disguiseType + ", ID: " + id + ", Class: " + (val == null ? "null" :
// valClazz) + ", Value: " + val);
}
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
if (sound != null)
{
Float soundStrength = ReflectionManager.getSoundModifier(nmsEntity);
if (soundStrength != null)
{
sound.setDamageAndIdleSoundVolume(soundStrength);
}
}
// Get the bounding box
disguiseValues.setAdultBox(ReflectionManager.getBoundingBox(bukkitEntity));
if (bukkitEntity instanceof Ageable)
{
((Ageable) bukkitEntity).setBaby();
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
}
else if (bukkitEntity instanceof Zombie)
{
((Zombie) bukkitEntity).setBaby(true);
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
}
disguiseValues.setEntitySize(ReflectionManager.getSize(bukkitEntity));
}
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, "
+ "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+/");
ex.printStackTrace(System.out);
}
}
}
private String toReadable(String string)
{
StringBuilder builder = new StringBuilder();
for (String s : string.split("_"))
{
builder.append(s.substring(0, 1)).append(s.substring(1).toLowerCase());
}
return builder.toString();
}
public DisguiseListener getListener()
{
return listener;
}
/**
* 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;
}
}
package me.libraryaddict.disguise;
import java.io.IOException;
import java.lang.reflect.Field;
import org.bukkit.Bukkit;
import org.bukkit.entity.Ageable;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Damageable;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Zombie;
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.wrappers.WrappedWatchableObject;
import me.libraryaddict.disguise.commands.CloneDisguiseCommand;
import me.libraryaddict.disguise.commands.DisguiseCommand;
import me.libraryaddict.disguise.commands.DisguiseViewSelf;
import me.libraryaddict.disguise.commands.EntityDisguiseCommand;
import me.libraryaddict.disguise.commands.HelpDisguiseCommand;
import me.libraryaddict.disguise.commands.LibsDisguisesCommand;
import me.libraryaddict.disguise.commands.PlayerDisguiseCommand;
import me.libraryaddict.disguise.commands.RadiusDisguiseCommand;
import me.libraryaddict.disguise.commands.UndisguiseCommand;
import me.libraryaddict.disguise.commands.UndisguiseEntityCommand;
import me.libraryaddict.disguise.commands.UndisguisePlayerCommand;
import me.libraryaddict.disguise.commands.UndisguiseRadiusCommand;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ArrowWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.InsentientWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SkeletonWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SlimeWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SpiderWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.TNTWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.TameableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import me.libraryaddict.disguise.utilities.DisguiseSound;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.DisguiseValues;
import me.libraryaddict.disguise.utilities.FakeBoundingBox;
import me.libraryaddict.disguise.utilities.Metrics;
import me.libraryaddict.disguise.utilities.PacketsManager;
import me.libraryaddict.disguise.utilities.ReflectionManager;
public class LibsDisguises extends JavaPlugin
{
private static LibsDisguises instance;
private DisguiseListener listener;
@Override
public void onEnable()
{
getLogger().info("Discovered MC version: " + ReflectionManager.getBukkitVersion());
saveDefaultConfig();
PacketsManager.init(this);
DisguiseUtilities.init(this);
DisguiseConfig.initConfig(getConfig());
PacketsManager.addPacketListeners();
listener = new DisguiseListener(this);
Bukkit.getPluginManager().registerEvents(listener, this);
getCommand("disguise").setExecutor(new DisguiseCommand());
getCommand("undisguise").setExecutor(new UndisguiseCommand());
getCommand("disguiseplayer").setExecutor(new PlayerDisguiseCommand());
getCommand("undisguiseplayer").setExecutor(new UndisguisePlayerCommand());
getCommand("undisguiseentity").setExecutor(new UndisguiseEntityCommand());
getCommand("disguiseentity").setExecutor(new EntityDisguiseCommand());
getCommand("disguiseradius").setExecutor(new RadiusDisguiseCommand(getConfig().getInt("DisguiseRadiusMax")));
getCommand("undisguiseradius").setExecutor(new UndisguiseRadiusCommand(getConfig().getInt("UndisguiseRadiusMax")));
getCommand("disguisehelp").setExecutor(new HelpDisguiseCommand());
getCommand("disguiseclone").setExecutor(new CloneDisguiseCommand());
getCommand("libsdisguises").setExecutor(new LibsDisguisesCommand());
getCommand("disguiseviewself").setExecutor(new DisguiseViewSelf());
registerValues();
instance = this;
try
{
Metrics metrics = new Metrics(this);
metrics.start();
}
catch (IOException e)
{
}
}
/**
* Reloads the config with new config options.
*/
public void reload()
{
HandlerList.unregisterAll(listener);
reloadConfig();
DisguiseConfig.initConfig(getConfig());
}
/**
* 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.
*/
private void registerValues()
{
for (DisguiseType disguiseType : DisguiseType.values())
{
if (disguiseType.getEntityType() == null)
{
continue;
}
Class watcherClass = null;
try
{
switch (disguiseType)
{
case SPECTRAL_ARROW:
watcherClass = ArrowWatcher.class;
break;
case PRIMED_TNT:
watcherClass = TNTWatcher.class;
break;
case MINECART_CHEST:
case MINECART_COMMAND:
case MINECART_FURNACE:
case MINECART_HOPPER:
case MINECART_MOB_SPAWNER:
case MINECART_TNT:
watcherClass = MinecartWatcher.class;
break;
case SPIDER:
case CAVE_SPIDER:
watcherClass = SpiderWatcher.class;
break;
case DONKEY:
case MULE:
case UNDEAD_HORSE:
case SKELETON_HORSE:
watcherClass = HorseWatcher.class;
break;
case ZOMBIE_VILLAGER:
case PIG_ZOMBIE:
watcherClass = ZombieWatcher.class;
break;
case MAGMA_CUBE:
watcherClass = SlimeWatcher.class;
break;
case ELDER_GUARDIAN:
watcherClass = GuardianWatcher.class;
break;
case WITHER_SKELETON:
watcherClass = SkeletonWatcher.class;
break;
default:
watcherClass = Class.forName(
"me.libraryaddict.disguise.disguisetypes.watchers." + toReadable(disguiseType.name()) + "Watcher");
break;
}
}
catch (ClassNotFoundException ex)
{
// There is no explicit watcher for this entity.
Class entityClass = disguiseType.getEntityType().getEntityClass();
if (entityClass != null)
{
if (Tameable.class.isAssignableFrom(entityClass))
{
watcherClass = TameableWatcher.class;
}
else if (Ageable.class.isAssignableFrom(entityClass))
{
watcherClass = AgeableWatcher.class;
}
else if (Creature.class.isAssignableFrom(entityClass))
{
watcherClass = InsentientWatcher.class;
}
else if (LivingEntity.class.isAssignableFrom(entityClass))
{
watcherClass = LivingWatcher.class;
}
else
{
watcherClass = FlagWatcher.class;
}
}
else
{
watcherClass = FlagWatcher.class; // Disguise is unknown type
}
}
if (watcherClass == null)
{
System.err.println("Error loading " + disguiseType.name() + ", FlagWatcher not assigned");
continue;
}
disguiseType.setWatcherClass(watcherClass);
if (DisguiseValues.getDisguiseValues(disguiseType) != null)
{
continue;
}
String nmsEntityName = toReadable(disguiseType.name());
switch (disguiseType)
{
case WITHER_SKELETON:
case ZOMBIE_VILLAGER:
case DONKEY:
case MULE:
case UNDEAD_HORSE:
case SKELETON_HORSE:
continue;
case PRIMED_TNT:
nmsEntityName = "TNTPrimed";
break;
case MINECART_TNT:
nmsEntityName = "MinecartTNT";
break;
case MINECART:
nmsEntityName = "MinecartRideable";
break;
case FIREWORK:
nmsEntityName = "Fireworks";
break;
case SPLASH_POTION:
nmsEntityName = "Potion";
break;
case GIANT:
nmsEntityName = "GiantZombie";
break;
case DROPPED_ITEM:
nmsEntityName = "Item";
break;
case FIREBALL:
nmsEntityName = "LargeFireball";
break;
case LEASH_HITCH:
nmsEntityName = "Leash";
break;
case ELDER_GUARDIAN:
nmsEntityName = "Guardian";
break;
case ARROW:
case SPECTRAL_ARROW:
nmsEntityName = "TippedArrow";
default:
break;
}
try
{
if (nmsEntityName.equalsIgnoreCase("Unknown"))
{
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, null, 0, 0);
disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0));
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
if (sound != null)
{
sound.setDamageAndIdleSoundVolume(1f);
}
continue;
}
Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName);
if (nmsEntity == null)
{
getLogger().warning("Entity not found! (" + nmsEntityName + ")");
continue;
}
Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity);
int entitySize = 0;
for (Field field : ReflectionManager.getNmsClass("Entity").getFields())
{
if (field.getType().getName().equals("EnumEntitySize"))
{
Enum enumEntitySize = (Enum) field.get(nmsEntity);
entitySize = enumEntitySize.ordinal();
break;
}
}
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, nmsEntity.getClass(), entitySize,
bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0);
WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity);
for (WrappedWatchableObject watch : watcher.getWatchableObjects())
{
FlagType flagType = FlagType.getFlag(watcherClass, watch.getIndex());
if (flagType == null)
{
System.err.println("Error finding the FlagType for " + disguiseType.name() + "! Index " + watch.getIndex()
+ " can't be found!");
System.err.println("Value is " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") ("
+ nmsEntity.getClass() + ") & " + watcherClass.getSimpleName());
System.err.println("Lib's Disguises will continue to load, but this will not work properly!");
continue;
}
}
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
if (sound != null)
{
Float soundStrength = ReflectionManager.getSoundModifier(nmsEntity);
if (soundStrength != null)
{
sound.setDamageAndIdleSoundVolume(soundStrength);
}
}
// Get the bounding box
disguiseValues.setAdultBox(ReflectionManager.getBoundingBox(bukkitEntity));
if (bukkitEntity instanceof Ageable)
{
((Ageable) bukkitEntity).setBaby();
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
}
else if (bukkitEntity instanceof Zombie)
{
((Zombie) bukkitEntity).setBaby(true);
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
}
disguiseValues.setEntitySize(ReflectionManager.getSize(bukkitEntity));
}
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, "
+ "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+/");
ex.printStackTrace(System.out);
}
}
}
private String toReadable(String string)
{
StringBuilder builder = new StringBuilder();
for (String s : string.split("_"))
{
builder.append(s.substring(0, 1)).append(s.substring(1).toLowerCase());
}
return builder.toString();
}
public DisguiseListener getListener()
{
return listener;
}
/**
* 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.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
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.UndisguiseEvent;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.DisguiseValues;
import me.libraryaddict.disguise.utilities.PacketsManager;
import me.libraryaddict.disguise.utilities.ReflectionManager;
@ -260,7 +258,7 @@ public abstract class Disguise
deadTicks = 0;
// 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++;
@ -783,15 +781,23 @@ public abstract class Disguise
*/
private void setupWatcher()
{
HashMap<FlagType, Object> disguiseValues = DisguiseValues.getMetaValues(getType());
HashMap<FlagType, Object> entityValues = DisguiseValues.getMetaValues(DisguiseType.getType(getEntity().getType()));
ArrayList<FlagType> disguiseFlags = FlagType.getFlags(getType().getWatcherClass());
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;
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;
import java.util.Arrays;
import java.util.HashMap;
import java.util.UUID;
import java.util.Map.Entry;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import com.google.common.base.Optional;
import me.libraryaddict.disguise.disguisetypes.watchers.*;
public class FlagType<Y>
{
private static FlagType[] _values = new FlagType[0];
public static FlagType<Boolean> AGEABLE_BABY = new FlagType<Boolean>(AgeableWatcher.class, 11, false);
public static FlagType<Integer> AREA_EFFECT_COLOR = new FlagType<Integer>(AreaEffectCloudWatcher.class, 6,
Color.BLACK.asRGB());
public static FlagType<Boolean> AREA_EFFECT_IGNORE_RADIUS = new FlagType<Boolean>(AreaEffectCloudWatcher.class, 7, false);
public static FlagType<Integer> AREA_EFFECT_PARTICLE = new FlagType<Integer>(AreaEffectCloudWatcher.class, 8, 0);
public static FlagType<Float> AREA_EFFECT_RADIUS = new FlagType<Float>(AreaEffectCloudWatcher.class, 6, 0F);
public static FlagType<Byte> ARMORSTAND_META = new FlagType<Byte>(ArmorStandWatcher.class, 10, (byte) 0);
public static FlagType<Byte> ARROW_CRITICAL = new FlagType<Byte>(ArrowWatcher.class, 6, (byte) 0);
public static FlagType<Byte> BAT_HANGING = new FlagType<Byte>(BatWatcher.class, 11, (byte) 1);
public static FlagType<Boolean> BLAZE_BLAZING = new FlagType<Boolean>(BlazeWatcher.class, 11, false);
public static FlagType<Float> BOAT_DAMAGE = new FlagType<Float>(BoatWatcher.class, 7, 40F);
public static FlagType<Boolean> CREEPER_IGNITED = new FlagType<Boolean>(CreeperWatcher.class, 13, false);
public static FlagType<Boolean> CREEPER_POWERED = new FlagType<Boolean>(CreeperWatcher.class, 12, false);
public static FlagType<ItemStack> DROPPED_ITEM = new FlagType<ItemStack>(DroppedItemWatcher.class, 6,
new ItemStack(Material.AIR));
public static FlagType<Optional> ENDER_CRYSTAL_BEAM = new FlagType<Optional>(EnderCrystalWatcher.class, 6, Optional.absent());
public static FlagType<Boolean> ENDER_CRYSTAL_PLATE = new FlagType<Boolean>(EnderCrystalWatcher.class, 6, false);
public static FlagType<Integer> ENDERDRAGON_PHASE = new FlagType<Integer>(EnderDragonWatcher.class, 6, 0);
public static FlagType<Boolean> ENDERMAN_AGRESSIVE = new FlagType<Boolean>(EndermanWatcher.class, 12, false);
public static FlagType<Optional<Integer>> ENDERMAN_ITEM = new FlagType<Optional<Integer>>(EndermanWatcher.class, 11,
Optional.of(1));
public static FlagType<Integer> ENTITY_AIR_TICKS = new FlagType<Integer>(FlagWatcher.class, 1, 0);
public static FlagType<String> ENTITY_CUSTOM_NAME = new FlagType<String>(FlagWatcher.class, 2, null);
public static FlagType<Boolean> ENTITY_CUSTOM_NAME_VISIBLE = new FlagType<Boolean>(FlagWatcher.class, 3, false);
public static FlagType<Byte> ENTITY_META = new FlagType<Byte>(FlagWatcher.class, 0, (byte) 0);
public static FlagType<Boolean> ENTITY_NO_GRAVITY = new FlagType<Boolean>(FlagWatcher.class, 5, false);
public static FlagType<Integer> ENTITY_SILENT = new FlagType<Integer>(FlagWatcher.class, 4, 0);
public static FlagType<Boolean> GHAST_AGRESSIVE = new FlagType<Boolean>(GhastWatcher.class, 11, false);
public static FlagType<Byte> GUARDIAN_FLAG = new FlagType<Byte>(GuardianWatcher.class, 11, (byte) 0);
public static FlagType<Integer> GUARDIAN_TARGET = new FlagType<Integer>(GuardianWatcher.class, 12, 0);
public static FlagType<Integer> HORSE_ARMOR = new FlagType<Integer>(HorseWatcher.class, 16, 0);
public static FlagType<Integer> HORSE_COLOR = new FlagType<Integer>(HorseWatcher.class, 14, 0);
public static FlagType<Byte> HORSE_META = new FlagType<Byte>(HorseWatcher.class, 12, (byte) 0);
public static FlagType<Optional<UUID>> HORSE_OWNER = new FlagType<Optional<UUID>>(HorseWatcher.class, 15,
Optional.<UUID> absent());
public static FlagType<Integer> HORSE_STYLE = new FlagType<Integer>(HorseWatcher.class, 14, 0);
public static FlagType<Integer> HORSE_VARIANT = new FlagType<Integer>(HorseWatcher.class, 13, 0);
public static FlagType<Byte> INSENTIENT_META = new FlagType<Byte>(LivingWatcher.class, 10, (byte) 0);
public static FlagType<ItemStack> ITEMFRAME_ITEM = new FlagType<ItemStack>(ItemFrameWatcher.class, 6, null);
public static FlagType<Byte> ITEMFRAME_ROTATION = new FlagType<Byte>(ItemFrameWatcher.class, 6, (byte) 0);
public static FlagType<Integer> LIVING_ARROWS = new FlagType<Integer>(LivingWatcher.class, 9, 0);
public static FlagType<Float> LIVING_HEALTH = new FlagType<Float>(LivingWatcher.class, 6, 0F);
public static FlagType<Boolean> LIVING_POTION_AMBIENT = new FlagType<Boolean>(LivingWatcher.class, 8, false);
public static FlagType<Integer> LIVING_POTIONS = new FlagType<Integer>(LivingWatcher.class, 7, 0);
public static FlagType<Integer> MINECART_BLOCK = new FlagType<Integer>(MinecartWatcher.class, 8, 0);
public static FlagType<Boolean> MINECART_BLOCK_VISIBLE = new FlagType<Boolean>(MinecartWatcher.class, 10, false);
public static FlagType<Integer> MINECART_BLOCK_Y = new FlagType<Integer>(MinecartWatcher.class, 9, 0);
public static FlagType<Integer> OCELOT_TYPE = new FlagType<Integer>(OcelotWatcher.class, 14, 0);
public static FlagType<Boolean> PIG_SADDLED = new FlagType<Boolean>(PigWatcher.class, 12, false);
public static FlagType<Byte> PLAYER_SKIN = new FlagType<Byte>(PlayerWatcher.class, 12, (byte) 0);
public static FlagType<Integer> RABBIT_TYPE = new FlagType<Integer>(RabbitWatcher.class, 12, 0);
public static FlagType<Byte> SHEEP_WOOL = new FlagType<Byte>(SheepWatcher.class, 12, (byte) 0);
public static FlagType<Integer> SKELETON_TYPE = new FlagType<Integer>(SkeletonWatcher.class, 11, 0);
public static FlagType<Integer> SLIME_SIZE = new FlagType<Integer>(SlimeWatcher.class, 11, 0);
public static FlagType<Byte> TAMEABLE_META = new FlagType<Byte>(TameableWatcher.class, 12, (byte) 0);
public static FlagType<Optional<UUID>> TAMEABLE_OWNER = new FlagType<Optional<UUID>>(TameableWatcher.class, 13,
Optional.<UUID> absent());
public static FlagType<Integer> TIPPED_ARROW_COLOR = new FlagType<Integer>(TippedArrowWatcher.class, 6, Color.WHITE.asRGB());
public static FlagType<Integer> VILLAGER_PROFESSION = new FlagType<Integer>(VillagerWatcher.class, 12, 0);
public static FlagType<Boolean> WITCH_AGGRESSIVE = new FlagType<Boolean>(WitchWatcher.class, 11, false);
public static FlagType<Integer> WITHER_INVUL = new FlagType<Integer>(WitchWatcher.class, 14, 0);
public static FlagType<Integer> WITHER_TARGET_1 = new FlagType<Integer>(WitherWatcher.class, 11, 0);
public static FlagType<Integer> WITHER_TARGET_2 = new FlagType<Integer>(WitherWatcher.class, 12, 0);
public static FlagType<Integer> WITHER_TARGET_3 = new FlagType<Integer>(WitherWatcher.class, 13, 0);
public static FlagType<Boolean> WITHERSKULL_BLUE = new FlagType<Boolean>(WitherSkullWatcher.class, 6, false);
public static FlagType<Boolean> WOLF_BEGGING = new FlagType<Boolean>(WolfWatcher.class, 15, false);
public static FlagType<Integer> WOLF_COLLAR = new FlagType<Integer>(WolfWatcher.class, 16, 14);
public static FlagType<Float> WOLF_DAMAGE = new FlagType<Float>(WolfWatcher.class, 14, 0F);
public static FlagType<Boolean> ZOMBIE_AGGRESSIVE = new FlagType<Boolean>(ZombieWatcher.class, 14, false);
public static FlagType<Boolean> ZOMBIE_BABY = new FlagType<Boolean>(ZombieWatcher.class, 11, false);
public static FlagType<Integer> ZOMBIE_PROFESSION = new FlagType<Integer>(ZombieWatcher.class, 12, 0);
public static FlagType<Boolean> ZOMBIE_SHAKING = new FlagType<Boolean>(ZombieWatcher.class, 13, false);
static
{
// 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 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;
_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;
}
}
package me.libraryaddict.disguise.disguisetypes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import com.comphenix.protocol.wrappers.BlockPosition;
import com.google.common.base.Optional;
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.AreaEffectCloudWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ArmorStandWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ArrowWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.BatWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.BlazeWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.BoatWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.CreeperWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.DroppedItemWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.EnderCrystalWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.EnderDragonWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.EndermanWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.FireworkWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.FishingHookWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.GhastWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.InsentientWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.IronGolemWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ItemFrameWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.OcelotWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.PigWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.RabbitWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SheepWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ShulkerWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SkeletonWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SlimeWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SnowmanWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SpiderWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SplashPotionWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.TNTWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.TameableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.VillagerWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.WitchWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.WitherSkullWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.WitherWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
public class FlagType<Y>
{
private static FlagType[] _values = new FlagType[0];
public static FlagType<Boolean> AGEABLE_BABY = new FlagType<Boolean>(AgeableWatcher.class, 0, false);
public static FlagType<Integer> AREA_EFFECT_COLOR = new FlagType<Integer>(AreaEffectCloudWatcher.class, 1,
Color.BLACK.asRGB());
public static FlagType<Boolean> AREA_EFFECT_IGNORE_RADIUS = new FlagType<Boolean>(AreaEffectCloudWatcher.class, 2, false);
public static FlagType<Integer> AREA_EFFECT_PARTICLE = new FlagType<Integer>(AreaEffectCloudWatcher.class, 3, 0);
public static FlagType<Integer> AREA_EFFECT_PARTICLE_PARAM_1 = new FlagType<Integer>(AreaEffectCloudWatcher.class, 4, 0);
public static FlagType<Integer> AREA_EFFECT_PARTICLE_PARAM_2 = new FlagType<Integer>(AreaEffectCloudWatcher.class, 5, 0);
public static FlagType<Float> AREA_EFFECT_RADIUS = new FlagType<Float>(AreaEffectCloudWatcher.class, 0, 0F);
public static FlagType<Vector> ARMORSTAND_BODY = new FlagType<Vector>(ArmorStandWatcher.class, 2, new Vector());
public static FlagType<Vector> ARMORSTAND_HEAD = new FlagType<Vector>(ArmorStandWatcher.class, 1, new Vector());
public static FlagType<Vector> ARMORSTAND_LEFT_ARM = new FlagType<Vector>(ArmorStandWatcher.class, 3, new Vector());
public static FlagType<Vector> ARMORSTAND_LEFT_LEG = new FlagType<Vector>(ArmorStandWatcher.class, 5, new Vector());
public static FlagType<Byte> ARMORSTAND_META = new FlagType<Byte>(ArmorStandWatcher.class, 0, (byte) 0);
public static FlagType<Vector> ARMORSTAND_RIGHT_ARM = new FlagType<Vector>(ArmorStandWatcher.class, 4, new Vector());
public static FlagType<Vector> ARMORSTAND_RIGHT_LEG = new FlagType<Vector>(ArmorStandWatcher.class, 6, new Vector());
public static FlagType<Byte> ARROW_CRITICAL = new FlagType<Byte>(ArrowWatcher.class, 0, (byte) 0);
public static FlagType<Byte> BAT_HANGING = new FlagType<Byte>(BatWatcher.class, 0, (byte) 1);
public static FlagType<Boolean> BLAZE_BLAZING = new FlagType<Boolean>(BlazeWatcher.class, 0, false);
public static FlagType<Float> BOAT_DAMAGE = new FlagType<Float>(BoatWatcher.class, 2, 40F);
public static FlagType<Integer> BOAT_DIRECTION = new FlagType<Integer>(BoatWatcher.class, 1, 0);
public static FlagType<Integer> BOAT_LAST_HIT = new FlagType<Integer>(BoatWatcher.class, 0, 0);
public static FlagType<Boolean> BOAT_LEFT_PADDLING = new FlagType<Boolean>(BoatWatcher.class, 5, false);
public static FlagType<Boolean> BOAT_RIGHT_PADDLING = new FlagType<Boolean>(BoatWatcher.class, 4, false);
public static FlagType<Integer> BOAT_TYPE = new FlagType<Integer>(BoatWatcher.class, 3, 0);
public static FlagType<Boolean> CREEPER_IGNITED = new FlagType<Boolean>(CreeperWatcher.class, 2, false);
public static FlagType<Boolean> CREEPER_POWERED = new FlagType<Boolean>(CreeperWatcher.class, 1, false);
public static FlagType<Integer> CREEPER_STATE = new FlagType<Integer>(CreeperWatcher.class, 0, -1);
public static FlagType<ItemStack> DROPPED_ITEM = new FlagType<ItemStack>(DroppedItemWatcher.class, 0,
new ItemStack(Material.AIR));
public static FlagType<Optional> ENDER_CRYSTAL_BEAM = new FlagType<Optional>(EnderCrystalWatcher.class, 0, Optional.absent());
public static FlagType<Boolean> ENDER_CRYSTAL_PLATE = new FlagType<Boolean>(EnderCrystalWatcher.class, 1, false);
public static FlagType<Integer> ENDERDRAGON_PHASE = new FlagType<Integer>(EnderDragonWatcher.class, 0, 0);
public static FlagType<Boolean> ENDERMAN_AGRESSIVE = new FlagType<Boolean>(EndermanWatcher.class, 1, false);
public static FlagType<Optional<Integer>> ENDERMAN_ITEM = new FlagType<Optional<Integer>>(EndermanWatcher.class, 0,
Optional.of(1));
public static FlagType<Integer> ENTITY_AIR_TICKS = new FlagType<Integer>(FlagWatcher.class, 1, 0);
public static FlagType<String> ENTITY_CUSTOM_NAME = new FlagType<String>(FlagWatcher.class, 2, "");
public static FlagType<Boolean> ENTITY_CUSTOM_NAME_VISIBLE = new FlagType<Boolean>(FlagWatcher.class, 3, false);
public static FlagType<Byte> ENTITY_META = new FlagType<Byte>(FlagWatcher.class, 0, (byte) 0);
public static FlagType<Boolean> ENTITY_NO_GRAVITY = new FlagType<Boolean>(FlagWatcher.class, 5, false);
public static FlagType<Boolean> ENTITY_SILENT = new FlagType<Boolean>(FlagWatcher.class, 4, false);
public static FlagType<BlockPosition> FALLING_BLOCK_POSITION = new FlagType<BlockPosition>(FallingBlockWatcher.class, 0,
BlockPosition.ORIGIN);
public static FlagType<Optional<ItemStack>> FIREWORK_ITEM = new FlagType<Optional<ItemStack>>(FireworkWatcher.class, 0,
Optional.<ItemStack> absent());
public static FlagType<Integer> FISHING_HOOK = new FlagType<Integer>(FishingHookWatcher.class, 0, 0);
public static FlagType<Boolean> GHAST_AGRESSIVE = new FlagType<Boolean>(GhastWatcher.class, 0, false);
public static FlagType<Byte> GUARDIAN_FLAG = new FlagType<Byte>(GuardianWatcher.class, 0, (byte) 0);
public static FlagType<Integer> GUARDIAN_TARGET = new FlagType<Integer>(GuardianWatcher.class, 1, 0);
public static FlagType<Integer> HORSE_ARMOR = new FlagType<Integer>(HorseWatcher.class, 4, 0);
public static FlagType<Integer> HORSE_COLOR = new FlagType<Integer>(HorseWatcher.class, 2, 0);
public static FlagType<Byte> HORSE_META = new FlagType<Byte>(HorseWatcher.class, 0, (byte) 0);
public static FlagType<Optional<UUID>> HORSE_OWNER = new FlagType<Optional<UUID>>(HorseWatcher.class, 3,
Optional.<UUID> absent());
public static FlagType<Integer> HORSE_VARIANT = new FlagType<Integer>(HorseWatcher.class, 1, 0);
public static FlagType<Byte> INSENTIENT_META = new FlagType<Byte>(InsentientWatcher.class, 0, (byte) 0);
public static FlagType<Byte> IRON_GOLEM_PLAYER_CREATED = new FlagType<Byte>(IronGolemWatcher.class, 0, (byte) 0);
public static FlagType<Optional<ItemStack>> ITEMFRAME_ITEM = new FlagType<Optional<ItemStack>>(ItemFrameWatcher.class, 0,
Optional.<ItemStack> absent());
public static FlagType<Integer> ITEMFRAME_ROTATION = new FlagType<Integer>(ItemFrameWatcher.class, 1, 0);
public static FlagType<Integer> LIVING_ARROWS = new FlagType<Integer>(LivingWatcher.class, 4, 0);
public static FlagType<Byte> LIVING_HAND = new FlagType<Byte>(LivingWatcher.class, 0, (byte) 0);
public static FlagType<Float> LIVING_HEALTH = new FlagType<Float>(LivingWatcher.class, 1, 0F);
public static FlagType<Boolean> LIVING_POTION_AMBIENT = new FlagType<Boolean>(LivingWatcher.class, 3, false);
public static FlagType<Integer> LIVING_POTIONS = new FlagType<Integer>(LivingWatcher.class, 2, 0);
public static FlagType<Integer> MINECART_BLOCK = new FlagType<Integer>(MinecartWatcher.class, 3, 0);
public static FlagType<Boolean> MINECART_BLOCK_VISIBLE = new FlagType<Boolean>(MinecartWatcher.class, 5, false);
public static FlagType<Integer> MINECART_BLOCK_Y = new FlagType<Integer>(MinecartWatcher.class, 4, 0);
public static FlagType<Integer> MINECART_SHAKING_DIRECTION = new FlagType<Integer>(MinecartWatcher.class, 1, 1);
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);
public static FlagType<Integer> OCELOT_TYPE = new FlagType<Integer>(OcelotWatcher.class, 0, 0);
public static FlagType<Boolean> PIG_SADDLED = new FlagType<Boolean>(PigWatcher.class, 0, false);
public static FlagType<Float> PLAYER_ABSORPTION = new FlagType<Float>(PlayerWatcher.class, 0, 0F);
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<Byte> PLAYER_SKIN = new FlagType<Byte>(PlayerWatcher.class, 2, (byte) 0);
public static FlagType<Integer> RABBIT_TYPE = new FlagType<Integer>(RabbitWatcher.class, 0, 0);
public static FlagType<Byte> SHEEP_WOOL = new FlagType<Byte>(SheepWatcher.class, 0, (byte) 0);
public static FlagType<Optional<BlockPosition>> SHULKER_ATTACHED = new FlagType<Optional<BlockPosition>>(ShulkerWatcher.class,
1, Optional.<BlockPosition> absent());
public static FlagType<BlockFace> SHULKER_FACING = new FlagType<BlockFace>(ShulkerWatcher.class, 0, BlockFace.DOWN);
public static FlagType<Byte> SHULKER_PEEKING = new FlagType<Byte>(ShulkerWatcher.class, 2, (byte) 0);
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<Integer> SLIME_SIZE = new FlagType<Integer>(SlimeWatcher.class, 0, 0);
public static FlagType<Byte> SNOWMAN_HAT = new FlagType<Byte>(SnowmanWatcher.class, 0, (byte) 1);
public static FlagType<Byte> SPIDER_CLIMB = new FlagType<Byte>(SpiderWatcher.class, 0, (byte) 0);
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
// there's a '0' already.
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
// idea why but MC thinks there's a
// '0' already.
public static FlagType<Byte> TAMEABLE_META = new FlagType<Byte>(TameableWatcher.class, 0, (byte) 0);
public static FlagType<Optional<UUID>> TAMEABLE_OWNER = new FlagType<Optional<UUID>>(TameableWatcher.class, 1,
Optional.<UUID> absent());
public static FlagType<Integer> TIPPED_ARROW_COLOR = new FlagType<Integer>(ArrowWatcher.class, 1, Color.WHITE.asRGB());
public static FlagType<Integer> TNT_FUSE_TICKS = new FlagType<Integer>(TNTWatcher.class, 0, Integer.MAX_VALUE);
public static FlagType<Integer> VILLAGER_PROFESSION = new FlagType<Integer>(VillagerWatcher.class, 0, 0);
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 static FlagType<Integer> WITHER_TARGET_1 = new FlagType<Integer>(WitherWatcher.class, 0, 0);
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..
*/
private HashMap<FlagType, Object> backupEntityValues = new HashMap<>();
private HashMap<Integer, Object> backupEntityValues = new HashMap<>();
private TargetedDisguise disguise;
private HashMap<FlagType, Object> entityValues = new HashMap<>();
private HashMap<Integer, Object> entityValues = new HashMap<>();
private EntityEquipment equipment;
private boolean hasDied;
private HashSet<Integer> modifiedEntityAnimations = new HashSet<>();
@ -77,7 +77,7 @@ public class FlagWatcher
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.modifiedEntityAnimations = (HashSet<Integer>) modifiedEntityAnimations.clone();
cloned.addEntityAnimations = addEntityAnimations;
@ -158,7 +158,7 @@ public class FlagWatcher
if (sendAllCustom)
{
// 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))
{
@ -172,8 +172,7 @@ public class FlagWatcher
continue;
}
WrappedWatchableObject watch = new WrappedWatchableObject(
ReflectionManager.createDataWatcherItem(id.getIndex(), value));
WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(id, value));
newList.add(watch);
}
@ -245,7 +244,7 @@ public class FlagWatcher
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()
@ -293,14 +292,14 @@ public class FlagWatcher
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()
@ -318,9 +317,9 @@ public class FlagWatcher
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()
@ -377,7 +376,7 @@ public class FlagWatcher
{
watchableObjects = new ArrayList<>();
for (int i = 0; i <= 31; i++)
for (int i = 0; i <= 31; i++)// TODO
{
WrappedWatchableObject watchable = null;
@ -468,7 +467,7 @@ public class FlagWatcher
protected void setBackupValue(FlagType no, Object value)
{
backupEntityValues.put(no, value);
backupEntityValues.put(no.getIndex(), value);
}
public void setBurning(boolean setBurning)
@ -653,7 +652,7 @@ public class FlagWatcher
protected <Y> void setValue(FlagType<Y> id, Y value)
{
entityValues.put(id, value);
entityValues.put(id.getIndex(), value);
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.FlagType;
public class AgeableWatcher extends LivingWatcher
public class AgeableWatcher extends InsentientWatcher
{
public AgeableWatcher(Disguise disguise)

View File

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

View File

@ -1,91 +1,166 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class ArmorStandWatcher extends LivingWatcher
{
public ArmorStandWatcher(Disguise disguise)
{
super(disguise);
}
private boolean getArmorStandFlag(int value)
{
return (getValue(FlagType.ARMORSTAND_META) & value) != 0;
}
public boolean isNoBasePlate()
{
return getArmorStandFlag(8);
}
public boolean isNoGravity()
{
return getArmorStandFlag(2);
}
public boolean isShowArms()
{
return getArmorStandFlag(4);
}
public boolean isSmall()
{
return getArmorStandFlag(1);
}
public boolean isMarker()
{
return getArmorStandFlag(10);
}
private void setArmorStandFlag(int value, boolean isTrue)
{
byte b1 = (byte) getValue(FlagType.ARMORSTAND_META);
if (isTrue)
{
b1 = (byte) (b1 | value);
}
else
{
b1 = (byte) (b1 & value);
}
setValue(FlagType.ARMORSTAND_META, b1);
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);
}
public void setShowArms(boolean showArms)
{
setArmorStandFlag(4, showArms);
sendData(FlagType.ARMORSTAND_META);
}
public void setSmall(boolean isSmall)
{
setArmorStandFlag(1, isSmall);
sendData(FlagType.ARMORSTAND_META);
}
public void setMarker(boolean isMarker)
{
setArmorStandFlag(10, isMarker);
sendData(FlagType.ARMORSTAND_META);
}
}
package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.util.Vector;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class ArmorStandWatcher extends LivingWatcher
{
public ArmorStandWatcher(Disguise disguise)
{
super(disguise);
}
private boolean getArmorStandFlag(int value)
{
return (getValue(FlagType.ARMORSTAND_META) & value) != 0;
}
public Vector getBody()
{
return getPose(FlagType.ARMORSTAND_BODY);
}
public Vector getHead()
{
return getPose(FlagType.ARMORSTAND_HEAD);
}
public Vector getLeftArm()
{
return getPose(FlagType.ARMORSTAND_LEFT_ARM);
}
public Vector getLeftLeg()
{
return getPose(FlagType.ARMORSTAND_LEFT_LEG);
}
private Vector getPose(FlagType<Vector> type)
{
if (!hasValue(type))
setValue(type, new Vector());
return getValue(type);
}
public Vector getRightArm()
{
return getPose(FlagType.ARMORSTAND_RIGHT_ARM);
}
public Vector getRightLeg()
{
return getPose(FlagType.ARMORSTAND_RIGHT_LEG);
}
public boolean isMarker()
{
return getArmorStandFlag(10);
}
public boolean isNoBasePlate()
{
return getArmorStandFlag(8);
}
public boolean isNoGravity()
{
return getArmorStandFlag(2);
}
public boolean isShowArms()
{
return getArmorStandFlag(4);
}
public boolean isSmall()
{
return getArmorStandFlag(1);
}
private void setArmorStandFlag(int value, boolean isTrue)
{
byte b1 = (byte) getValue(FlagType.ARMORSTAND_META);
if (isTrue)
{
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;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
public class ArrowWatcher extends FlagWatcher
{
public ArrowWatcher(Disguise disguise)
{
super(disguise);
}
public boolean isCritical()
{
return (byte) getValue(FlagType.ARROW_CRITICAL) == 1;
}
public void setCritical(boolean critical)
{
setValue(FlagType.ARROW_CRITICAL, (byte) (critical ? 1 : 0));
sendData(FlagType.ARROW_CRITICAL);
}
}
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 ArrowWatcher extends FlagWatcher
{
public ArrowWatcher(Disguise disguise)
{
super(disguise);
}
public boolean isCritical()
{
return (byte) getValue(FlagType.ARROW_CRITICAL) == 1;
}
public void setCritical(boolean critical)
{
setValue(FlagType.ARROW_CRITICAL, (byte) (critical ? 1 : 0));
sendData(FlagType.ARROW_CRITICAL);
}
}

View File

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

View File

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

View File

@ -1,28 +1,64 @@
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 BoatWatcher extends FlagWatcher
{
// TODO: Add stuff for new boat values
public BoatWatcher(Disguise disguise)
{
super(disguise);
}
public float getDamage()
{
return getValue(FlagType.BOAT_DAMAGE);
}
public void setDamage(float dmg)
{
setValue(FlagType.BOAT_DAMAGE, dmg);
sendData(FlagType.BOAT_DAMAGE);
}
}
package me.libraryaddict.disguise.disguisetypes.watchers;
import java.util.Random;
import org.bukkit.TreeSpecies;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
public class BoatWatcher extends FlagWatcher
{
public BoatWatcher(Disguise disguise)
{
super(disguise);
setBoatType(TreeSpecies.values()[new Random().nextInt(6)]);
}
public float getDamage()
{
return getValue(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;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class CreeperWatcher extends LivingWatcher
{
public CreeperWatcher(Disguise disguise)
{
super(disguise);
}
public boolean isIgnited()
{
return (boolean) getValue(FlagType.CREEPER_IGNITED);
}
public boolean isPowered()
{
return (boolean) getValue(FlagType.CREEPER_POWERED);
}
public void setIgnited(boolean ignited)
{
setValue(FlagType.CREEPER_IGNITED, ignited);
sendData(FlagType.CREEPER_IGNITED);
}
public void setPowered(boolean powered)
{
setValue(FlagType.CREEPER_POWERED, powered);
sendData(FlagType.CREEPER_POWERED);
}
}
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class CreeperWatcher extends InsentientWatcher
{
public CreeperWatcher(Disguise disguise)
{
super(disguise);
}
public boolean isIgnited()
{
return (boolean) getValue(FlagType.CREEPER_IGNITED);
}
public boolean isPowered()
{
return (boolean) getValue(FlagType.CREEPER_POWERED);
}
public void setIgnited(boolean ignited)
{
setValue(FlagType.CREEPER_IGNITED, ignited);
sendData(FlagType.CREEPER_IGNITED);
}
public void setPowered(boolean powered)
{
setValue(FlagType.CREEPER_POWERED, powered);
sendData(FlagType.CREEPER_POWERED);
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,63 +1,55 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class InsentientWatcher extends LivingWatcher
{
public InsentientWatcher(Disguise disguise)
{
super(disguise);
}
public void setLeftHanded(boolean leftHanded)
{
setRightHanded(!leftHanded);
}
public void setRightHanded(boolean rightHanded)
{
setInsentientFlag(2, rightHanded);
sendData(FlagType.INSENTIENT_META);
}
public boolean isRightHanded()
{
return getInsentientFlag(2);
}
public boolean isLeftHanded()
{
return !isRightHanded();
}
public boolean isAI()
{
return getInsentientFlag(1);
}
public void setAI(boolean ai)
{
setInsentientFlag(1, ai);
sendData(FlagType.INSENTIENT_META);
}
private void setInsentientFlag(int i, boolean flag)
{
byte b0 = (byte) getValue(FlagType.INSENTIENT_META);
if (flag)
{
setValue(FlagType.INSENTIENT_META, (byte) (b0 | 1 << i));
}
else
{
setValue(FlagType.INSENTIENT_META, (byte) (b0 & (~1 << i)));
}
}
private boolean getInsentientFlag(int i)
{
return ((byte) getValue(FlagType.PLAYER_SKIN) & 1 << i) != 0;
}
}
package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.inventory.MainHand;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class InsentientWatcher extends LivingWatcher
{
public InsentientWatcher(Disguise disguise)
{
super(disguise);
}
public void setMainHand(MainHand mainHand)
{
setInsentientFlag(2, mainHand == MainHand.RIGHT);
sendData(FlagType.INSENTIENT_META);
}
public MainHand getMainHand()
{
return getInsentientFlag(2) ? MainHand.RIGHT : MainHand.LEFT;
}
public boolean isAI()
{
return getInsentientFlag(1);
}
public void setAI(boolean ai)
{
setInsentientFlag(1, ai);
sendData(FlagType.INSENTIENT_META);
}
private void setInsentientFlag(int i, boolean flag)
{
byte b0 = (byte) getValue(FlagType.INSENTIENT_META);
if (flag)
{
setValue(FlagType.INSENTIENT_META, (byte) (b0 | 1 << i));
}
else
{
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;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
public class ItemFrameWatcher extends FlagWatcher
{
public ItemFrameWatcher(Disguise disguise)
{
super(disguise);
}
public ItemStack getItem()
{
if (getValue(FlagType.ITEMFRAME_ITEM) == null)
{
return new ItemStack(Material.AIR);
}
return (ItemStack) getValue(FlagType.ITEMFRAME_ITEM);
}
public int getRotation()
{
return getValue(FlagType.ITEMFRAME_ROTATION);
}
public void setItem(ItemStack newItem)
{
if (newItem == null)
{
newItem = new ItemStack(Material.AIR);
}
newItem = newItem.clone();
newItem.setAmount(1);
setValue(FlagType.ITEMFRAME_ITEM, newItem);
sendData(FlagType.ITEMFRAME_ITEM);
}
public void setRotation(int rotation)
{
setValue(FlagType.ITEMFRAME_ROTATION, (byte) (rotation % 4));
sendData(FlagType.ITEMFRAME_ROTATION);
}
}
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 ItemFrameWatcher extends FlagWatcher
{
public ItemFrameWatcher(Disguise disguise)
{
super(disguise);
}
public ItemStack getItem()
{
if (getValue(FlagType.ITEMFRAME_ITEM) == null)
{
return new ItemStack(Material.AIR);
}
return (ItemStack) getValue(FlagType.ITEMFRAME_ITEM).get();
}
public int getRotation()
{
return getValue(FlagType.ITEMFRAME_ROTATION);
}
public void setItem(ItemStack newItem)
{
if (newItem == null)
{
newItem = new ItemStack(Material.AIR);
}
newItem = newItem.clone();
newItem.setAmount(1);
setValue(FlagType.ITEMFRAME_ITEM, Optional.<ItemStack> of(newItem));
sendData(FlagType.ITEMFRAME_ITEM);
}
public void setRotation(int 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.entity.Player;
import org.bukkit.inventory.MainHand;
import com.comphenix.protocol.PacketType.Play.Server;
import com.comphenix.protocol.ProtocolLibrary;
@ -34,6 +35,17 @@ public class PlayerWatcher extends LivingWatcher
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()
{
if (sleepingDirection == null)

View File

@ -1,52 +1,61 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.block.BlockFace;
import com.comphenix.protocol.wrappers.BlockPosition;
import com.google.common.base.Optional;
import me.libraryaddict.disguise.disguisetypes.Disguise;
/**
* @author Navid
*/
// TODO: Add the appropriate data values to this class
public class ShulkerWatcher extends LivingWatcher
{
public ShulkerWatcher(Disguise disguise)
{
super(disguise);
}
public BlockFace getFacingDirection()
{
return BlockFace.UP;
}
public void setFacingDirection()
{
}
public Optional<BlockPosition> getAttachmentPosition()
{
return Optional.absent();
}
public void setAttachmentPosition(BlockPosition pos)
{
}
public byte getShieldHeight()
{
return 0x00;
}
public void setShieldHeight()
{
}
}
package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.block.BlockFace;
import com.comphenix.protocol.wrappers.BlockPosition;
import com.google.common.base.Optional;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
/**
* @author Navid
*/
public class ShulkerWatcher extends InsentientWatcher
{
public ShulkerWatcher(Disguise disguise)
{
super(disguise);
}
public BlockFace getFacingDirection()
{
return getValue(FlagType.SHULKER_FACING);
}
public void setFacingDirection(BlockFace face)
{
setValue(FlagType.SHULKER_FACING, face);
sendData(FlagType.SHULKER_FACING);
}
public BlockPosition getAttachmentPosition()
{
return getValue(FlagType.SHULKER_ATTACHED).get();
}
public void setAttachmentPosition(BlockPosition pos)
{
setValue(FlagType.SHULKER_ATTACHED, Optional.of(pos));
sendData(FlagType.SHULKER_ATTACHED);
}
public int getShieldHeight()
{
return getValue(FlagType.SHULKER_PEEKING);
}
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;
import org.bukkit.entity.Skeleton.SkeletonType;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
/**
* @author Navid
*/
public class SkeletonWatcher extends LivingWatcher
{
public SkeletonWatcher(Disguise disguise)
{
super(disguise);
}
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)];
}
}
package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.entity.Skeleton.SkeletonType;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
/**
* @author Navid
*/
public class SkeletonWatcher extends InsentientWatcher
{
public SkeletonWatcher(Disguise disguise)
{
super(disguise);
}
public void setSwingArms(boolean swingingArms)
{
setValue(FlagType.SKELETON_SWING_ARMS, swingingArms);
sendData(FlagType.SKELETON_SWING_ARMS);
}
public boolean isSwingArms()
{
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;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
public class SlimeWatcher extends LivingWatcher
{
public SlimeWatcher(Disguise disguise)
{
super(disguise);
setSize(DisguiseUtilities.random.nextInt(4) + 1);
}
public int getSize()
{
return (int) getValue(FlagType.SLIME_SIZE);
}
public void setSize(int size)
{
if (size <= 0 || size >= 128)
{
size = 1;
}
setValue(FlagType.SLIME_SIZE, size);
sendData(FlagType.SLIME_SIZE);
}
}
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
public class SlimeWatcher extends InsentientWatcher
{
public SlimeWatcher(Disguise disguise)
{
super(disguise);
setSize(DisguiseUtilities.random.nextInt(4) + 1);
}
public int getSize()
{
return (int) getValue(FlagType.SLIME_SIZE);
}
public void setSize(int size)
{
if (size <= 0 || size >= 128)
{
size = 1;
}
setValue(FlagType.SLIME_SIZE, 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;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
public class SplashPotionWatcher extends FlagWatcher
{
private int potionId;
public SplashPotionWatcher(Disguise disguise)
{
super(disguise);
}
@Override
public SplashPotionWatcher clone(Disguise disguise)
{
SplashPotionWatcher watcher = (SplashPotionWatcher) super.clone(disguise);
watcher.setPotionId(getPotionId());
return watcher;
}
public int getPotionId()
{
return potionId;
}
public void setPotionId(int newPotionId)
{
this.potionId = newPotionId;
if (getDisguise().getEntity() != null && getDisguise().getWatcher() == this)
{
DisguiseUtilities.refreshTrackers(getDisguise());
}
}
}
package me.libraryaddict.disguise.disguisetypes.watchers;
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;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
public class SplashPotionWatcher extends FlagWatcher
{
private int potionId;
public SplashPotionWatcher(Disguise disguise)
{
super(disguise);
}
@Override
public SplashPotionWatcher clone(Disguise disguise)
{
SplashPotionWatcher watcher = (SplashPotionWatcher) super.clone(disguise);
watcher.setPotionId(getPotionId());
return watcher;
}
public int getPotionId()
{
return potionId;
}
public void setSplashPotion(ItemStack item)
{
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;
import org.bukkit.Color;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
/**
* @author Navid
*/
public class TippedArrowWatcher extends ArrowWatcher
{
public TippedArrowWatcher(Disguise disguise)
{
super(disguise);
int r = DisguiseUtilities.random.nextInt(256);
int g = DisguiseUtilities.random.nextInt(256);
int b = DisguiseUtilities.random.nextInt(256);
setColor(Color.fromRGB(r, g, b));
}
public Color getColor()
{
int color = (int) getValue(FlagType.TIPPED_ARROW_COLOR);
return Color.fromRGB(color);
}
public void setColor(Color color)
{
setValue(FlagType.TIPPED_ARROW_COLOR, color.asRGB());
sendData(FlagType.TIPPED_ARROW_COLOR);
}
}
package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.Color;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
/**
* @author Navid
*/
public class TippedArrowWatcher extends ArrowWatcher
{
public TippedArrowWatcher(Disguise disguise)
{
super(disguise);
int r = DisguiseUtilities.random.nextInt(256);
int g = DisguiseUtilities.random.nextInt(256);
int b = DisguiseUtilities.random.nextInt(256);
setColor(Color.fromRGB(r, g, b));
}
public Color getColor()
{
int color = (int) getValue(FlagType.TIPPED_ARROW_COLOR);
return Color.fromRGB(color);
}
public void setColor(Color color)
{
setValue(FlagType.TIPPED_ARROW_COLOR, color.asRGB());
sendData(FlagType.TIPPED_ARROW_COLOR);
}
}

View File

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

View File

@ -1,58 +1,58 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import java.security.InvalidParameterException;
import org.bukkit.ChatColor;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class WitherWatcher extends LivingWatcher
{
public WitherWatcher(Disguise disguise)
{
super(disguise);
}
/**
* Returns the amount of time this Wither is invulnerable for
*
* @return
*/
public int getInvulnerability()
{
return (int) getValue(FlagType.WITHER_INVUL);
}
public int[] getTargets()
{
return new int[]
{
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
*/
public void setInvulnerability(int invulnerability)
{
setValue(FlagType.WITHER_INVUL, invulnerability);
sendData(FlagType.WITHER_INVUL);
}
public void setTargets(int... targets)
{
if (targets.length != 3)
{
throw new InvalidParameterException(
ChatColor.RED + "Expected 3 numbers for wither setTargets. Received " + targets.length);
}
setValue(FlagType.WITHER_TARGET_1, targets[0]);
setValue(FlagType.WITHER_TARGET_2, targets[1]);
setValue(FlagType.WITHER_TARGET_3, targets[2]);
sendData(FlagType.WITHER_TARGET_1, FlagType.WITHER_TARGET_2, FlagType.WITHER_TARGET_3);
}
}
package me.libraryaddict.disguise.disguisetypes.watchers;
import java.security.InvalidParameterException;
import org.bukkit.ChatColor;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class WitherWatcher extends InsentientWatcher
{
public WitherWatcher(Disguise disguise)
{
super(disguise);
}
/**
* Returns the amount of time this Wither is invulnerable for
*
* @return
*/
public int getInvulnerability()
{
return (int) getValue(FlagType.WITHER_INVUL);
}
public int[] getTargets()
{
return new int[]
{
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
*/
public void setInvulnerability(int invulnerability)
{
setValue(FlagType.WITHER_INVUL, invulnerability);
sendData(FlagType.WITHER_INVUL);
}
public void setTargets(int... targets)
{
if (targets.length != 3)
{
throw new InvalidParameterException(
ChatColor.RED + "Expected 3 numbers for wither setTargets. Received " + targets.length);
}
setValue(FlagType.WITHER_TARGET_1, targets[0]);
setValue(FlagType.WITHER_TARGET_2, targets[1]);
setValue(FlagType.WITHER_TARGET_3, targets[2]);
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;
import org.bukkit.entity.Villager.Profession;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class ZombieWatcher extends LivingWatcher
{
public ZombieWatcher(Disguise disguise)
{
super(disguise);
}
public boolean isAdult()
{
return !isBaby();
}
public boolean isBaby()
{
return getValue(FlagType.ZOMBIE_BABY);
}
public boolean isShaking()
{
return getValue(FlagType.ZOMBIE_SHAKING);
}
/**
* Is this zombie a villager?
*
* @return
*/
public boolean isVillager()
{
return ((int) getValue(FlagType.ZOMBIE_PROFESSION)) != 0;
}
public boolean isAggressive()
{
return (boolean) getValue(FlagType.ZOMBIE_AGGRESSIVE);
}
/**
* Only returns a valid value if this zombie is a villager.
*
* @return
*/
public Profession getProfession()
{
return Profession.values()[getValue(FlagType.ZOMBIE_PROFESSION)];
}
public void setAdult()
{
setBaby(false);
}
public void setBaby()
{
setBaby(true);
}
public void setBaby(boolean baby)
{
setValue(FlagType.ZOMBIE_BABY, baby);
sendData(FlagType.ZOMBIE_BABY);
}
public void setShaking(boolean shaking)
{
setValue(FlagType.ZOMBIE_SHAKING, shaking);
sendData(FlagType.ZOMBIE_SHAKING);
}
/**
* Sets the profession of this zombie, in turn turning it into a Zombie Villager
*
* @param id
*/
public void setProfession(int id)
{
setValue(FlagType.ZOMBIE_PROFESSION, id);
sendData(FlagType.ZOMBIE_PROFESSION);
}
/**
* Sets the profession of this zombie, in turn turning it into a Zombie Villager
*
* @param profession
*/
public void setProfession(Profession profession)
{
setValue(FlagType.ZOMBIE_PROFESSION, profession.ordinal());
sendData(FlagType.ZOMBIE_PROFESSION);
}
public void setAggressive(boolean handsup)
{
setValue(FlagType.ZOMBIE_AGGRESSIVE, handsup);
sendData(FlagType.ZOMBIE_AGGRESSIVE);
}
}
package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.entity.Villager.Profession;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class ZombieWatcher extends InsentientWatcher
{
public ZombieWatcher(Disguise disguise)
{
super(disguise);
}
public boolean isAdult()
{
return !isBaby();
}
public boolean isBaby()
{
return getValue(FlagType.ZOMBIE_BABY);
}
public boolean isShaking()
{
return getValue(FlagType.ZOMBIE_SHAKING);
}
/**
* Is this zombie a villager?
*
* @return
*/
public boolean isVillager()
{
return ((int) getValue(FlagType.ZOMBIE_PROFESSION)) != 0;
}
public boolean isAggressive()
{
return (boolean) getValue(FlagType.ZOMBIE_AGGRESSIVE);
}
/**
* Only returns a valid value if this zombie is a villager.
*
* @return
*/
public Profession getProfession()
{
return Profession.values()[getValue(FlagType.ZOMBIE_PROFESSION)];
}
public void setAdult()
{
setBaby(false);
}
public void setBaby()
{
setBaby(true);
}
public void setBaby(boolean baby)
{
setValue(FlagType.ZOMBIE_BABY, baby);
sendData(FlagType.ZOMBIE_BABY);
}
public void setShaking(boolean shaking)
{
setValue(FlagType.ZOMBIE_SHAKING, shaking);
sendData(FlagType.ZOMBIE_SHAKING);
}
/**
* Sets the profession of this zombie, in turn turning it into a Zombie Villager
*
* @param id
*/
public void setProfession(int id)
{
setValue(FlagType.ZOMBIE_PROFESSION, id);
sendData(FlagType.ZOMBIE_PROFESSION);
}
/**
* Sets the profession of this zombie, in turn turning it into a Zombie Villager
*
* @param profession
*/
public void setProfession(Profession profession)
{
setValue(FlagType.ZOMBIE_PROFESSION, profession.ordinal());
sendData(FlagType.ZOMBIE_PROFESSION);
}
public void setAggressive(boolean handsup)
{
setValue(FlagType.ZOMBIE_AGGRESSIVE, handsup);
sendData(FlagType.ZOMBIE_AGGRESSIVE);
}
}

View File

@ -3,7 +3,6 @@ package me.libraryaddict.disguise.utilities;
import java.util.HashMap;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class DisguiseValues
{
@ -40,11 +39,6 @@ public class DisguiseValues
return values.get(type);
}
public static HashMap<FlagType, Object> getMetaValues(DisguiseType type)
{
return getDisguiseValues(type).getMetaValues();
}
public static Class getNmsEntityClass(DisguiseType type)
{
return getDisguiseValues(type).getNmsEntityClass();
@ -54,7 +48,6 @@ public class DisguiseValues
private FakeBoundingBox babyBox;
private float[] entitySize;
private double maxHealth;
private HashMap<FlagType, Object> metaValues = new HashMap<>();
private Class nmsEntityClass;
public DisguiseValues(DisguiseType type, Class classType, int entitySize, double maxHealth)
@ -84,11 +77,6 @@ public class DisguiseValues
return maxHealth;
}
public HashMap<FlagType, Object> getMetaValues()
{
return metaValues;
}
public Class getNmsEntityClass()
{
return nmsEntityClass;
@ -108,9 +96,4 @@ public class DisguiseValues
{
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.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.Disguise;