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

@ -5,6 +5,7 @@ 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;
@ -33,12 +34,16 @@ 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;
@ -129,7 +134,11 @@ public class LibsDisguises extends JavaPlugin
{
switch (disguiseType)
{
case ITEM_FRAME: // Not really supported...
case SPECTRAL_ARROW:
watcherClass = ArrowWatcher.class;
break;
case PRIMED_TNT:
watcherClass = TNTWatcher.class;
break;
case MINECART_CHEST:
case MINECART_COMMAND:
@ -139,6 +148,10 @@ public class LibsDisguises extends JavaPlugin
case MINECART_TNT:
watcherClass = MinecartWatcher.class;
break;
case SPIDER:
case CAVE_SPIDER:
watcherClass = SpiderWatcher.class;
break;
case DONKEY:
case MULE:
case UNDEAD_HORSE:
@ -155,9 +168,6 @@ public class LibsDisguises extends JavaPlugin
case ELDER_GUARDIAN:
watcherClass = GuardianWatcher.class;
break;
case ENDERMITE:
watcherClass = LivingWatcher.class;
break;
case WITHER_SKELETON:
watcherClass = SkeletonWatcher.class;
break;
@ -182,6 +192,10 @@ public class LibsDisguises extends JavaPlugin
{
watcherClass = AgeableWatcher.class;
}
else if (Creature.class.isAssignableFrom(entityClass))
{
watcherClass = InsentientWatcher.class;
}
else if (LivingEntity.class.isAssignableFrom(entityClass))
{
watcherClass = LivingWatcher.class;
@ -197,6 +211,12 @@ public class LibsDisguises extends JavaPlugin
}
}
if (watcherClass == null)
{
System.err.println("Error loading " + disguiseType.name() + ", FlagWatcher not assigned");
continue;
}
disguiseType.setWatcherClass(watcherClass);
if (DisguiseValues.getDisguiseValues(disguiseType) != null)
@ -246,6 +266,7 @@ public class LibsDisguises extends JavaPlugin
nmsEntityName = "Guardian";
break;
case ARROW:
case SPECTRAL_ARROW:
nmsEntityName = "TippedArrow";
default:
break;
@ -304,25 +325,13 @@ public class LibsDisguises extends JavaPlugin
if (flagType == null)
{
System.err.println("Error finding the FlagType for " + disguiseType.name() + "! " + watch.getIndex()
+ " cannot be found!");
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;
}
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());

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,64 +1,137 @@
package me.libraryaddict.disguise.disguisetypes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.UUID;
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.*;
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, 11, false);
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, 6,
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, 7, false);
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, 8, 0);
public static FlagType<Integer> AREA_EFFECT_PARTICLE = new FlagType<Integer>(AreaEffectCloudWatcher.class, 3, 0);
public static FlagType<Float> AREA_EFFECT_RADIUS = new FlagType<Float>(AreaEffectCloudWatcher.class, 6, 0F);
public static FlagType<Integer> AREA_EFFECT_PARTICLE_PARAM_1 = new FlagType<Integer>(AreaEffectCloudWatcher.class, 4, 0);
public static FlagType<Byte> ARMORSTAND_META = new FlagType<Byte>(ArmorStandWatcher.class, 10, (byte) 0);
public static FlagType<Integer> AREA_EFFECT_PARTICLE_PARAM_2 = new FlagType<Integer>(AreaEffectCloudWatcher.class, 5, 0);
public static FlagType<Byte> ARROW_CRITICAL = new FlagType<Byte>(ArrowWatcher.class, 6, (byte) 0);
public static FlagType<Float> AREA_EFFECT_RADIUS = new FlagType<Float>(AreaEffectCloudWatcher.class, 0, 0F);
public static FlagType<Byte> BAT_HANGING = new FlagType<Byte>(BatWatcher.class, 11, (byte) 1);
public static FlagType<Vector> ARMORSTAND_BODY = new FlagType<Vector>(ArmorStandWatcher.class, 2, new Vector());
public static FlagType<Boolean> BLAZE_BLAZING = new FlagType<Boolean>(BlazeWatcher.class, 11, false);
public static FlagType<Vector> ARMORSTAND_HEAD = new FlagType<Vector>(ArmorStandWatcher.class, 1, new Vector());
public static FlagType<Float> BOAT_DAMAGE = new FlagType<Float>(BoatWatcher.class, 7, 40F);
public static FlagType<Vector> ARMORSTAND_LEFT_ARM = new FlagType<Vector>(ArmorStandWatcher.class, 3, new Vector());
public static FlagType<Boolean> CREEPER_IGNITED = new FlagType<Boolean>(CreeperWatcher.class, 13, false);
public static FlagType<Vector> ARMORSTAND_LEFT_LEG = new FlagType<Vector>(ArmorStandWatcher.class, 5, new Vector());
public static FlagType<Boolean> CREEPER_POWERED = new FlagType<Boolean>(CreeperWatcher.class, 12, false);
public static FlagType<Byte> ARMORSTAND_META = new FlagType<Byte>(ArmorStandWatcher.class, 0, (byte) 0);
public static FlagType<ItemStack> DROPPED_ITEM = new FlagType<ItemStack>(DroppedItemWatcher.class, 6,
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, 6, Optional.absent());
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, 6, false);
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, 6, 0);
public static FlagType<Integer> ENDERDRAGON_PHASE = new FlagType<Integer>(EnderDragonWatcher.class, 0, 0);
public static FlagType<Boolean> ENDERMAN_AGRESSIVE = new FlagType<Boolean>(EndermanWatcher.class, 12, false);
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, 11,
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, null);
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);
@ -66,98 +139,154 @@ public class FlagType<Y>
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> ENTITY_SILENT = new FlagType<Boolean>(FlagWatcher.class, 4, false);
public static FlagType<Boolean> GHAST_AGRESSIVE = new FlagType<Boolean>(GhastWatcher.class, 11, false);
public static FlagType<BlockPosition> FALLING_BLOCK_POSITION = new FlagType<BlockPosition>(FallingBlockWatcher.class, 0,
BlockPosition.ORIGIN);
public static FlagType<Byte> GUARDIAN_FLAG = new FlagType<Byte>(GuardianWatcher.class, 11, (byte) 0);
public static FlagType<Optional<ItemStack>> FIREWORK_ITEM = new FlagType<Optional<ItemStack>>(FireworkWatcher.class, 0,
Optional.<ItemStack> absent());
public static FlagType<Integer> GUARDIAN_TARGET = new FlagType<Integer>(GuardianWatcher.class, 12, 0);
public static FlagType<Integer> FISHING_HOOK = new FlagType<Integer>(FishingHookWatcher.class, 0, 0);
public static FlagType<Integer> HORSE_ARMOR = new FlagType<Integer>(HorseWatcher.class, 16, 0);
public static FlagType<Boolean> GHAST_AGRESSIVE = new FlagType<Boolean>(GhastWatcher.class, 0, false);
public static FlagType<Integer> HORSE_COLOR = new FlagType<Integer>(HorseWatcher.class, 14, 0);
public static FlagType<Byte> GUARDIAN_FLAG = new FlagType<Byte>(GuardianWatcher.class, 0, (byte) 0);
public static FlagType<Byte> HORSE_META = new FlagType<Byte>(HorseWatcher.class, 12, (byte) 0);
public static FlagType<Integer> GUARDIAN_TARGET = new FlagType<Integer>(GuardianWatcher.class, 1, 0);
public static FlagType<Optional<UUID>> HORSE_OWNER = new FlagType<Optional<UUID>>(HorseWatcher.class, 15,
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_STYLE = new FlagType<Integer>(HorseWatcher.class, 14, 0);
public static FlagType<Integer> HORSE_VARIANT = new FlagType<Integer>(HorseWatcher.class, 1, 0);
public static FlagType<Integer> HORSE_VARIANT = new FlagType<Integer>(HorseWatcher.class, 13, 0);
public static FlagType<Byte> INSENTIENT_META = new FlagType<Byte>(InsentientWatcher.class, 0, (byte) 0);
public static FlagType<Byte> INSENTIENT_META = new FlagType<Byte>(LivingWatcher.class, 10, (byte) 0);
public static FlagType<Byte> IRON_GOLEM_PLAYER_CREATED = new FlagType<Byte>(IronGolemWatcher.class, 0, (byte) 0);
public static FlagType<ItemStack> ITEMFRAME_ITEM = new FlagType<ItemStack>(ItemFrameWatcher.class, 6, null);
public static FlagType<Optional<ItemStack>> ITEMFRAME_ITEM = new FlagType<Optional<ItemStack>>(ItemFrameWatcher.class, 0,
Optional.<ItemStack> absent());
public static FlagType<Byte> ITEMFRAME_ROTATION = new FlagType<Byte>(ItemFrameWatcher.class, 6, (byte) 0);
public static FlagType<Integer> ITEMFRAME_ROTATION = new FlagType<Integer>(ItemFrameWatcher.class, 1, 0);
public static FlagType<Integer> LIVING_ARROWS = new FlagType<Integer>(LivingWatcher.class, 9, 0);
public static FlagType<Integer> LIVING_ARROWS = new FlagType<Integer>(LivingWatcher.class, 4, 0);
public static FlagType<Float> LIVING_HEALTH = new FlagType<Float>(LivingWatcher.class, 6, 0F);
public static FlagType<Byte> LIVING_HAND = new FlagType<Byte>(LivingWatcher.class, 0, (byte) 0);
public static FlagType<Boolean> LIVING_POTION_AMBIENT = new FlagType<Boolean>(LivingWatcher.class, 8, false);
public static FlagType<Float> LIVING_HEALTH = new FlagType<Float>(LivingWatcher.class, 1, 0F);
public static FlagType<Integer> LIVING_POTIONS = new FlagType<Integer>(LivingWatcher.class, 7, 0);
public static FlagType<Boolean> LIVING_POTION_AMBIENT = new FlagType<Boolean>(LivingWatcher.class, 3, false);
public static FlagType<Integer> MINECART_BLOCK = new FlagType<Integer>(MinecartWatcher.class, 8, 0);
public static FlagType<Integer> LIVING_POTIONS = new FlagType<Integer>(LivingWatcher.class, 2, 0);
public static FlagType<Boolean> MINECART_BLOCK_VISIBLE = new FlagType<Boolean>(MinecartWatcher.class, 10, false);
public static FlagType<Integer> MINECART_BLOCK = new FlagType<Integer>(MinecartWatcher.class, 3, 0);
public static FlagType<Integer> MINECART_BLOCK_Y = new FlagType<Integer>(MinecartWatcher.class, 9, 0);
public static FlagType<Boolean> MINECART_BLOCK_VISIBLE = new FlagType<Boolean>(MinecartWatcher.class, 5, false);
public static FlagType<Integer> OCELOT_TYPE = new FlagType<Integer>(OcelotWatcher.class, 14, 0);
public static FlagType<Integer> MINECART_BLOCK_Y = new FlagType<Integer>(MinecartWatcher.class, 4, 0);
public static FlagType<Boolean> PIG_SADDLED = new FlagType<Boolean>(PigWatcher.class, 12, false);
public static FlagType<Integer> MINECART_SHAKING_DIRECTION = new FlagType<Integer>(MinecartWatcher.class, 1, 1);
public static FlagType<Byte> PLAYER_SKIN = new FlagType<Byte>(PlayerWatcher.class, 12, (byte) 0);
public static FlagType<Float> MINECART_SHAKING_MULITPLIER = new FlagType<Float>(MinecartWatcher.class, 2, 0F);
public static FlagType<Integer> RABBIT_TYPE = new FlagType<Integer>(RabbitWatcher.class, 12, 0);
public static FlagType<Integer> MINECART_SHAKING_POWER = new FlagType<Integer>(MinecartWatcher.class, 0, 0);
public static FlagType<Byte> SHEEP_WOOL = new FlagType<Byte>(SheepWatcher.class, 12, (byte) 0);
public static FlagType<Integer> OCELOT_TYPE = new FlagType<Integer>(OcelotWatcher.class, 0, 0);
public static FlagType<Integer> SKELETON_TYPE = new FlagType<Integer>(SkeletonWatcher.class, 11, 0);
public static FlagType<Boolean> PIG_SADDLED = new FlagType<Boolean>(PigWatcher.class, 0, false);
public static FlagType<Integer> SLIME_SIZE = new FlagType<Integer>(SlimeWatcher.class, 11, 0);
public static FlagType<Float> PLAYER_ABSORPTION = new FlagType<Float>(PlayerWatcher.class, 0, 0F);
public static FlagType<Byte> TAMEABLE_META = new FlagType<Byte>(TameableWatcher.class, 12, (byte) 0);
public static FlagType<Byte> PLAYER_HAND = new FlagType<Byte>(PlayerWatcher.class, 3, (byte) 0);
public static FlagType<Optional<UUID>> TAMEABLE_OWNER = new FlagType<Optional<UUID>>(TameableWatcher.class, 13,
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>(TippedArrowWatcher.class, 6, Color.WHITE.asRGB());
public static FlagType<Integer> TIPPED_ARROW_COLOR = new FlagType<Integer>(ArrowWatcher.class, 1, Color.WHITE.asRGB());
public static FlagType<Integer> VILLAGER_PROFESSION = new FlagType<Integer>(VillagerWatcher.class, 12, 0);
public static FlagType<Integer> TNT_FUSE_TICKS = new FlagType<Integer>(TNTWatcher.class, 0, Integer.MAX_VALUE);
public static FlagType<Boolean> WITCH_AGGRESSIVE = new FlagType<Boolean>(WitchWatcher.class, 11, false);
public static FlagType<Integer> VILLAGER_PROFESSION = new FlagType<Integer>(VillagerWatcher.class, 0, 0);
public static FlagType<Integer> WITHER_INVUL = new FlagType<Integer>(WitchWatcher.class, 14, 0);
public static FlagType<Boolean> WITCH_AGGRESSIVE = new FlagType<Boolean>(WitchWatcher.class, 0, false);
public static FlagType<Integer> WITHER_TARGET_1 = new FlagType<Integer>(WitherWatcher.class, 11, 0);
public static FlagType<Integer> WITHER_INVUL = new FlagType<Integer>(WitherWatcher.class, 3, 0);
public static FlagType<Integer> WITHER_TARGET_2 = new FlagType<Integer>(WitherWatcher.class, 12, 0);
public static FlagType<Integer> WITHER_TARGET_1 = new FlagType<Integer>(WitherWatcher.class, 0, 0);
public static FlagType<Integer> WITHER_TARGET_3 = new FlagType<Integer>(WitherWatcher.class, 13, 0);
public static FlagType<Integer> WITHER_TARGET_2 = new FlagType<Integer>(WitherWatcher.class, 1, 0);
public static FlagType<Boolean> WITHERSKULL_BLUE = new FlagType<Boolean>(WitherSkullWatcher.class, 6, false);
public static FlagType<Integer> WITHER_TARGET_3 = new FlagType<Integer>(WitherWatcher.class, 2, 0);
public static FlagType<Boolean> WOLF_BEGGING = new FlagType<Boolean>(WolfWatcher.class, 15, false);
public static FlagType<Boolean> WITHERSKULL_BLUE = new FlagType<Boolean>(WitherSkullWatcher.class, 0, false);
public static FlagType<Integer> WOLF_COLLAR = new FlagType<Integer>(WolfWatcher.class, 16, 14);
public static FlagType<Boolean> WOLF_BEGGING = new FlagType<Boolean>(WolfWatcher.class, 1, false);
public static FlagType<Float> WOLF_DAMAGE = new FlagType<Float>(WolfWatcher.class, 14, 0F);
public static FlagType<Integer> WOLF_COLLAR = new FlagType<Integer>(WolfWatcher.class, 2, 14);
public static FlagType<Boolean> ZOMBIE_AGGRESSIVE = new FlagType<Boolean>(ZombieWatcher.class, 14, false);
public static FlagType<Float> WOLF_DAMAGE = new FlagType<Float>(WolfWatcher.class, 0, 0F);
public static FlagType<Boolean> ZOMBIE_BABY = new FlagType<Boolean>(ZombieWatcher.class, 11, false);
public static FlagType<Boolean> ZOMBIE_AGGRESSIVE = new FlagType<Boolean>(ZombieWatcher.class, 3, false);
public static FlagType<Integer> ZOMBIE_PROFESSION = new FlagType<Integer>(ZombieWatcher.class, 12, 0);
public static FlagType<Boolean> ZOMBIE_BABY = new FlagType<Boolean>(ZombieWatcher.class, 0, false);
public static FlagType<Boolean> ZOMBIE_SHAKING = new FlagType<Boolean>(ZombieWatcher.class, 13, 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.
@ -223,21 +352,55 @@ public class FlagType<Y>
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;

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,7 +1,5 @@
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;

View File

@ -1,11 +1,12 @@
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);
@ -16,6 +17,49 @@ public class ArmorStandWatcher extends LivingWatcher
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);
@ -36,11 +80,6 @@ public class ArmorStandWatcher extends LivingWatcher
return getArmorStandFlag(1);
}
public boolean isMarker()
{
return getArmorStandFlag(10);
}
private void setArmorStandFlag(int value, boolean isTrue)
{
byte b1 = (byte) getValue(FlagType.ARMORSTAND_META);
@ -58,6 +97,32 @@ public class ArmorStandWatcher extends LivingWatcher
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);
@ -70,6 +135,22 @@ public class ArmorStandWatcher extends LivingWatcher
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);
@ -82,10 +163,4 @@ public class ArmorStandWatcher extends LivingWatcher
sendData(FlagType.ARMORSTAND_META);
}
public void setMarker(boolean isMarker)
{
setArmorStandFlag(10, isMarker);
sendData(FlagType.ARMORSTAND_META);
}
}

View File

@ -6,7 +6,6 @@ import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
public class ArrowWatcher extends FlagWatcher
{
public ArrowWatcher(Disguise disguise)
{
super(disguise);
@ -22,5 +21,4 @@ public class ArrowWatcher extends FlagWatcher
setValue(FlagType.ARROW_CRITICAL, (byte) (critical ? 1 : 0));
sendData(FlagType.ARROW_CRITICAL);
}
}

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 BatWatcher extends LivingWatcher
public class BatWatcher extends InsentientWatcher
{
public BatWatcher(Disguise disguise)

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 BlazeWatcher extends LivingWatcher
public class BlazeWatcher extends InsentientWatcher
{
public BlazeWatcher(Disguise disguise)
{

View File

@ -1,17 +1,20 @@
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
{
// TODO: Add stuff for new boat values
public BoatWatcher(Disguise disguise)
{
super(disguise);
setBoatType(TreeSpecies.values()[new Random().nextInt(6)]);
}
public float getDamage()
@ -25,4 +28,37 @@ public class BoatWatcher extends FlagWatcher
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

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

View File

@ -1,6 +1,5 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import me.libraryaddict.disguise.disguisetypes.Disguise;

View File

@ -6,7 +6,7 @@ import me.libraryaddict.disguise.disguisetypes.FlagType;
/**
* @author Navid
*/
public class EnderDragonWatcher extends LivingWatcher
public class EnderDragonWatcher extends InsentientWatcher
{
public EnderDragonWatcher(Disguise disguise)

View File

@ -9,7 +9,7 @@ import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.utilities.ReflectionManager;
public class EndermanWatcher extends LivingWatcher
public class EndermanWatcher extends InsentientWatcher
{
public EndermanWatcher(Disguise disguise)

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

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

View File

@ -7,7 +7,7 @@ import org.bukkit.entity.Player;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class GuardianWatcher extends LivingWatcher
public class GuardianWatcher extends InsentientWatcher
{
public GuardianWatcher(Disguise disguise)

View File

@ -16,7 +16,6 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities;
public class HorseWatcher extends AgeableWatcher
{
public HorseWatcher(Disguise disguise)
{
super(disguise);
@ -82,7 +81,7 @@ public class HorseWatcher extends AgeableWatcher
public Style getStyle()
{
return Style.values()[(getValue(FlagType.HORSE_STYLE) >>> 8)];
return Style.values()[(getValue(FlagType.HORSE_COLOR) >>> 8)];
}
public boolean hasChest()
@ -221,8 +220,8 @@ public class HorseWatcher extends AgeableWatcher
public void setStyle(Style style)
{
setValue(FlagType.HORSE_STYLE, getColor().ordinal() & 0xFF | style.ordinal() << 8);
sendData(FlagType.HORSE_STYLE);
setValue(FlagType.HORSE_COLOR, getColor().ordinal() & 0xFF | style.ordinal() << 8);
sendData(FlagType.HORSE_COLOR);
}
public void setTamed(boolean tamed)

View File

@ -1,5 +1,7 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.inventory.MainHand;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
@ -10,25 +12,15 @@ public class InsentientWatcher extends LivingWatcher
super(disguise);
}
public void setLeftHanded(boolean leftHanded)
public void setMainHand(MainHand mainHand)
{
setRightHanded(!leftHanded);
}
public void setRightHanded(boolean rightHanded)
{
setInsentientFlag(2, rightHanded);
setInsentientFlag(2, mainHand == MainHand.RIGHT);
sendData(FlagType.INSENTIENT_META);
}
public boolean isRightHanded()
public MainHand getMainHand()
{
return getInsentientFlag(2);
}
public boolean isLeftHanded()
{
return !isRightHanded();
return getInsentientFlag(2) ? MainHand.RIGHT : MainHand.LEFT;
}
public boolean isAI()

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

@ -3,13 +3,14 @@ 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);
@ -22,7 +23,7 @@ public class ItemFrameWatcher extends FlagWatcher
return new ItemStack(Material.AIR);
}
return (ItemStack) getValue(FlagType.ITEMFRAME_ITEM);
return (ItemStack) getValue(FlagType.ITEMFRAME_ITEM).get();
}
public int getRotation()
@ -40,13 +41,13 @@ public class ItemFrameWatcher extends FlagWatcher
newItem = newItem.clone();
newItem.setAmount(1);
setValue(FlagType.ITEMFRAME_ITEM, newItem);
setValue(FlagType.ITEMFRAME_ITEM, Optional.<ItemStack> of(newItem));
sendData(FlagType.ITEMFRAME_ITEM);
}
public void setRotation(int rotation)
{
setValue(FlagType.ITEMFRAME_ROTATION, (byte) (rotation % 4));
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

@ -6,12 +6,12 @@ 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
*/
// TODO: Add the appropriate data values to this class
public class ShulkerWatcher extends LivingWatcher
public class ShulkerWatcher extends InsentientWatcher
{
public ShulkerWatcher(Disguise disguise)
@ -21,32 +21,41 @@ public class ShulkerWatcher extends LivingWatcher
public BlockFace getFacingDirection()
{
return BlockFace.UP;
return getValue(FlagType.SHULKER_FACING);
}
public void setFacingDirection()
public void setFacingDirection(BlockFace face)
{
setValue(FlagType.SHULKER_FACING, face);
sendData(FlagType.SHULKER_FACING);
}
public Optional<BlockPosition> getAttachmentPosition()
public BlockPosition getAttachmentPosition()
{
return Optional.absent();
return getValue(FlagType.SHULKER_ATTACHED).get();
}
public void setAttachmentPosition(BlockPosition pos)
{
setValue(FlagType.SHULKER_ATTACHED, Optional.of(pos));
sendData(FlagType.SHULKER_ATTACHED);
}
public byte getShieldHeight()
public int getShieldHeight()
{
return 0x00;
return getValue(FlagType.SHULKER_PEEKING);
}
public void setShieldHeight()
public void setShieldHeight(int newHeight)
{
if (newHeight < 0)
newHeight = 0;
if (newHeight > 127)
newHeight = 127;
setValue(FlagType.SHULKER_PEEKING, (byte) newHeight);
sendData(FlagType.SHULKER_PEEKING);
}
}

View File

@ -8,13 +8,24 @@ import me.libraryaddict.disguise.disguisetypes.FlagType;
/**
* @author Navid
*/
public class SkeletonWatcher extends LivingWatcher
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());

View File

@ -4,7 +4,7 @@ import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
public class SlimeWatcher extends LivingWatcher
public class SlimeWatcher extends InsentientWatcher
{
public SlimeWatcher(Disguise disguise)

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,6 +1,11 @@
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;
@ -27,6 +32,17 @@ public class SplashPotionWatcher extends FlagWatcher
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;

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

@ -6,7 +6,7 @@ import me.libraryaddict.disguise.disguisetypes.FlagType;
/**
* @author Navid
*/
public class WitchWatcher extends LivingWatcher
public class WitchWatcher extends InsentientWatcher
{
public WitchWatcher(Disguise disguise)

View File

@ -7,7 +7,7 @@ import org.bukkit.ChatColor;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class WitherWatcher extends LivingWatcher
public class WitherWatcher extends InsentientWatcher
{
public WitherWatcher(Disguise disguise)

View File

@ -5,7 +5,7 @@ import org.bukkit.entity.Villager.Profession;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class ZombieWatcher extends LivingWatcher
public class ZombieWatcher extends InsentientWatcher
{
public ZombieWatcher(Disguise disguise)

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;