Fix disguises and stuff

This commit is contained in:
libraryaddict 2016-11-27 04:36:57 +13:00
parent 401061bbcd
commit 126a7a4a6a
22 changed files with 373 additions and 645 deletions

View File

@ -225,7 +225,7 @@ public class LibsDisguises extends JavaPlugin {
case ZOMBIE_VILLAGER: case ZOMBIE_VILLAGER:
case DONKEY: case DONKEY:
case MULE: case MULE:
case UNDEAD_HORSE: case ZOMBIE_HORSE:
case SKELETON_HORSE: case SKELETON_HORSE:
case STRAY: case STRAY:
case HUSK: case HUSK:
@ -319,6 +319,17 @@ public class LibsDisguises extends JavaPlugin {
System.err.println("Lib's Disguises will continue to load, but this will not work properly!"); System.err.println("Lib's Disguises will continue to load, but this will not work properly!");
continue; continue;
} }
if (ReflectionManager.convertInvalidItem(flagType.getDefault()).getClass() != ReflectionManager
.convertInvalidItem(watch.getValue()).getClass()) {
System.err.println("Mismatch of FlagType's for " + disguiseType.name() + "! Index " + watch.getIndex()
+ " has the wrong classtype!");
System.err.println("Value is " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") ("
+ nmsEntity.getClass() + ") & " + watcherClass.getSimpleName() + " which doesn't match up with "
+ flagType.getDefault().getClass());
System.err.println("Lib's Disguises will continue to load, but this will not work properly!");
continue;
}
} }
DisguiseSound sound = DisguiseSound.getType(disguiseType.name()); DisguiseSound sound = DisguiseSound.getType(disguiseType.name());

View File

@ -13,8 +13,6 @@ import org.bukkit.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton.SkeletonType;
import org.bukkit.entity.Villager.Profession;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -29,8 +27,6 @@ import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType; import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.BatWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.BatWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SkeletonWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import me.libraryaddict.disguise.events.DisguiseEvent; import me.libraryaddict.disguise.events.DisguiseEvent;
import me.libraryaddict.disguise.events.UndisguiseEvent; import me.libraryaddict.disguise.events.UndisguiseEvent;
@ -106,28 +102,6 @@ public abstract class Disguise {
} }
} }
// If the disguise type is a wither, set the flagwatcher value for the skeleton to a wither skeleton
if (getType() == DisguiseType.WITHER_SKELETON) {
((SkeletonWatcher) getWatcher()).setType(SkeletonType.WITHER);
}
else if (getType() == DisguiseType.STRAY) {
((SkeletonWatcher) getWatcher()).setType(SkeletonType.STRAY);
} // Else if its a zombie, but the disguise type is a zombie villager. Set the value.
else if (getType() == DisguiseType.ZOMBIE_VILLAGER) {
Profession profession = null;
while (profession == null || profession == Profession.NORMAL || profession == Profession.HUSK)
profession = Profession.values()[DisguiseUtilities.random.nextInt(Profession.values().length)];
((ZombieWatcher) getWatcher()).setProfession(profession);
}
else if (getType() == DisguiseType.HUSK) {
((ZombieWatcher) getWatcher()).setProfession(Profession.HUSK);
}
else if (getType() == DisguiseType.ELDER_GUARDIAN) {
((GuardianWatcher) getWatcher()).setElder(true);
}
final boolean alwaysSendVelocity; final boolean alwaysSendVelocity;
switch (getType()) { switch (getType()) {

View File

@ -3,11 +3,6 @@ package me.libraryaddict.disguise.disguisetypes;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Guardian;
import org.bukkit.entity.Horse;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Skeleton.SkeletonType;
import org.bukkit.entity.Zombie;
public enum DisguiseType { public enum DisguiseType {
AREA_EFFECT_CLOUD(3, 0), AREA_EFFECT_CLOUD(3, 0),
@ -154,9 +149,9 @@ public enum DisguiseType {
THROWN_EXP_BOTTLE(75), THROWN_EXP_BOTTLE(75),
TIPPED_ARROW(92), TIPPED_ARROW(60),
UNDEAD_HORSE, ZOMBIE_HORSE,
UNKNOWN, UNKNOWN,
@ -190,7 +185,7 @@ public enum DisguiseType {
DisguiseType toUse = type; DisguiseType toUse = type;
String name; String name;
switch (type) { /* switch (type) {
// Disguise item frame isn't supported. So we don't give it a entity type which should prevent it from being.. // Disguise item frame isn't supported. So we don't give it a entity type which should prevent it from being..
// Usable. // Usable.
case ITEM_FRAME: case ITEM_FRAME:
@ -199,16 +194,9 @@ public enum DisguiseType {
case HUSK: case HUSK:
toUse = DisguiseType.ZOMBIE; toUse = DisguiseType.ZOMBIE;
break; break;
case WITHER_SKELETON:
case STRAY:
toUse = DisguiseType.SKELETON;
break;
case ELDER_GUARDIAN:
toUse = DisguiseType.GUARDIAN;
break;
default: default:
break; break;
} }*/
name = toUse.name(); name = toUse.name();
@ -223,39 +211,6 @@ public enum DisguiseType {
public static DisguiseType getType(Entity entity) { public static DisguiseType getType(Entity entity) {
DisguiseType disguiseType = getType(entity.getType()); DisguiseType disguiseType = getType(entity.getType());
switch (disguiseType) {
case ZOMBIE:
if (((Zombie) entity).isVillager()) {
disguiseType = DisguiseType.ZOMBIE_VILLAGER;
}
break;
case HORSE:
disguiseType = DisguiseType.valueOf(((Horse) entity).getVariant().name());
break;
case SKELETON:
if (((Skeleton) entity).getSkeletonType() == SkeletonType.WITHER) {
disguiseType = DisguiseType.WITHER_SKELETON;
}
break;
case GUARDIAN:
if (((Guardian) entity).isElder()) {
disguiseType = DisguiseType.ELDER_GUARDIAN;
}
break;
default:
break;
}
return disguiseType; return disguiseType;
} }

View File

@ -64,6 +64,7 @@ import me.libraryaddict.disguise.disguisetypes.watchers.WitchWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.WitherSkullWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.WitherSkullWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.WitherWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.WitherWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieVillagerWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
public class FlagType<Y> { public class FlagType<Y> {
@ -71,7 +72,7 @@ public class FlagType<Y> {
public static FlagType<Boolean> AGEABLE_BABY = new FlagType<Boolean>(AgeableWatcher.class, 0, 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, 1, public static FlagType<Integer> AREA_EFFECT_CLOUD_COLOR = new FlagType<Integer>(AreaEffectCloudWatcher.class, 1,
Color.BLACK.asRGB()); Color.BLACK.asRGB());
public static FlagType<Boolean> AREA_EFFECT_IGNORE_RADIUS = new FlagType<Boolean>(AreaEffectCloudWatcher.class, 2, false); public static FlagType<Boolean> AREA_EFFECT_IGNORE_RADIUS = new FlagType<Boolean>(AreaEffectCloudWatcher.class, 2, false);
@ -126,15 +127,15 @@ public class FlagType<Y> {
public static FlagType<Integer> CREEPER_STATE = new FlagType<Integer>(CreeperWatcher.class, 0, -1); public static FlagType<Integer> CREEPER_STATE = new FlagType<Integer>(CreeperWatcher.class, 0, -1);
public static FlagType<Optional<ItemStack>> DROPPED_ITEM = new FlagType<Optional<ItemStack>>(DroppedItemWatcher.class, 0, public static FlagType<ItemStack> DROPPED_ITEM = new FlagType<ItemStack>(DroppedItemWatcher.class, 0,
Optional.<ItemStack> of(new ItemStack(Material.STONE))); new ItemStack(Material.STONE));
public static FlagType<Optional<BlockPosition>> ENDER_CRYSTAL_BEAM = new FlagType<Optional<BlockPosition>>( public static FlagType<Optional<BlockPosition>> ENDER_CRYSTAL_BEAM = new FlagType<Optional<BlockPosition>>(
EnderCrystalWatcher.class, 0, Optional.<BlockPosition> absent()); EnderCrystalWatcher.class, 0, Optional.<BlockPosition> absent());
public static FlagType<Boolean> ENDER_CRYSTAL_PLATE = new FlagType<Boolean>(EnderCrystalWatcher.class, 1, 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, 0, 0); public static FlagType<Integer> ENDERD_RAGON_PHASE = new FlagType<Integer>(EnderDragonWatcher.class, 0, 0);
public static FlagType<Boolean> ENDERMAN_AGRESSIVE = new FlagType<Boolean>(EndermanWatcher.class, 1, false); public static FlagType<Boolean> ENDERMAN_AGRESSIVE = new FlagType<Boolean>(EndermanWatcher.class, 1, false);
@ -158,14 +159,14 @@ public class FlagType<Y> {
public static FlagType<BlockPosition> FALLING_BLOCK_POSITION = new FlagType<BlockPosition>(FallingBlockWatcher.class, 0, public static FlagType<BlockPosition> FALLING_BLOCK_POSITION = new FlagType<BlockPosition>(FallingBlockWatcher.class, 0,
BlockPosition.ORIGIN); BlockPosition.ORIGIN);
public static FlagType<Optional<ItemStack>> FIREWORK_ITEM = new FlagType<Optional<ItemStack>>(FireworkWatcher.class, 0, public static FlagType<ItemStack> FIREWORK_ITEM = new FlagType<ItemStack>(FireworkWatcher.class, 0,
Optional.<ItemStack> absent()); new ItemStack(Material.AIR));
public static FlagType<Integer> FISHING_HOOK = new FlagType<Integer>(FishingHookWatcher.class, 0, 0); public static FlagType<Integer> FISHING_HOOK_HOOKED = new FlagType<Integer>(FishingHookWatcher.class, 0, 0);
public static FlagType<Boolean> GHAST_AGRESSIVE = new FlagType<Boolean>(GhastWatcher.class, 0, false); 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<Boolean> GUARDIAN_RETRACT_SPIKES = new FlagType<Boolean>(GuardianWatcher.class, 0, false);
public static FlagType<Integer> GUARDIAN_TARGET = new FlagType<Integer>(GuardianWatcher.class, 1, 0); public static FlagType<Integer> GUARDIAN_TARGET = new FlagType<Integer>(GuardianWatcher.class, 1, 0);
@ -175,7 +176,7 @@ public class FlagType<Y> {
public static FlagType<Byte> HORSE_META = new FlagType<Byte>(HorseAbstractWatcher.class, 0, (byte) 0); public static FlagType<Byte> HORSE_META = new FlagType<Byte>(HorseAbstractWatcher.class, 0, (byte) 0);
public static FlagType<Boolean> HORSE_CARRYING_CHEST = new FlagType<Boolean>(HorseChestedWatcher.class, 0, false); public static FlagType<Boolean> HORSE_CHESTED_CARRYING_CHEST = new FlagType<Boolean>(HorseChestedWatcher.class, 0, false);
public static FlagType<Optional<UUID>> HORSE_OWNER = new FlagType<Optional<UUID>>(HorseAbstractWatcher.class, 1, public static FlagType<Optional<UUID>> HORSE_OWNER = new FlagType<Optional<UUID>>(HorseAbstractWatcher.class, 1,
Optional.<UUID> absent()); Optional.<UUID> absent());
@ -186,8 +187,8 @@ public class FlagType<Y> {
public static FlagType<Byte> IRON_GOLEM_PLAYER_CREATED = new FlagType<Byte>(IronGolemWatcher.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, public static FlagType<ItemStack> ITEMFRAME_ITEM = new FlagType<ItemStack>(ItemFrameWatcher.class, 0,
Optional.<ItemStack> absent()); new ItemStack(Material.AIR));
public static FlagType<Integer> ITEMFRAME_ROTATION = new FlagType<Integer>(ItemFrameWatcher.class, 1, 0); public static FlagType<Integer> ITEMFRAME_ROTATION = new FlagType<Integer>(ItemFrameWatcher.class, 1, 0);
@ -246,9 +247,7 @@ public class FlagType<Y> {
public static FlagType<Byte> SHULKER_COLOR = new FlagType<Byte>(ShulkerWatcher.class, 3, (byte) 10); public static FlagType<Byte> SHULKER_COLOR = new FlagType<Byte>(ShulkerWatcher.class, 3, (byte) 10);
public static FlagType<Boolean> SKELETON_SWING_ARMS = new FlagType<Boolean>(SkeletonWatcher.class, 1, false); public static FlagType<Boolean> SKELETON_SWING_ARMS = new FlagType<Boolean>(SkeletonWatcher.class, 0, 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<Integer> SLIME_SIZE = new FlagType<Integer>(SlimeWatcher.class, 0, 0);
@ -256,14 +255,14 @@ public class FlagType<Y> {
public static FlagType<Byte> SPIDER_CLIMB = new FlagType<Byte>(SpiderWatcher.class, 0, (byte) 0); 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, public static FlagType<ItemStack> SPLASH_POTION_ITEM = new FlagType<ItemStack>(SplashPotionWatcher.class, 1,
1, Optional.of(new ItemStack(Material.SPLASH_POTION))); // Yeah, the '1' isn't a bug. No idea why but MC thinks new ItemStack(Material.SPLASH_POTION)); // Yeah, the '1' isn't a bug. No idea why but MC thinks
// there's a '0' already. // there's a '0' already.
public static FlagType<Optional<ItemStack>> SPLASH_POTION_ITEM_BAD = new FlagType<Optional<ItemStack>>( public static FlagType<ItemStack> SPLASH_POTION_ITEM_BAD = new FlagType<ItemStack>(SplashPotionWatcher.class, 0,
SplashPotionWatcher.class, 0, Optional.of(new ItemStack(Material.SPLASH_POTION))); // Yeah, the '1' isn't a bug. No new ItemStack(Material.SPLASH_POTION)); // Yeah, the '1' isn't a bug. No
// idea why but MC thinks there's a // idea why but MC thinks there's a
// '0' already. // '0' already.
public static FlagType<Byte> TAMEABLE_META = new FlagType<Byte>(TameableWatcher.class, 0, (byte) 0); public static FlagType<Byte> TAMEABLE_META = new FlagType<Byte>(TameableWatcher.class, 0, (byte) 0);
@ -290,7 +289,7 @@ public class FlagType<Y> {
public static FlagType<Integer> WITHER_TARGET_3 = new FlagType<Integer>(WitherWatcher.class, 2, 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> WITHER_SKULL_BLUE = new FlagType<Boolean>(WitherSkullWatcher.class, 0, false);
public static FlagType<Boolean> WOLF_BEGGING = new FlagType<Boolean>(WolfWatcher.class, 1, false); public static FlagType<Boolean> WOLF_BEGGING = new FlagType<Boolean>(WolfWatcher.class, 1, false);
@ -298,13 +297,13 @@ public class FlagType<Y> {
public static FlagType<Float> WOLF_DAMAGE = new FlagType<Float>(WolfWatcher.class, 0, 0F); 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_AGGRESSIVE = new FlagType<Boolean>(ZombieWatcher.class, 2, false);
public static FlagType<Boolean> ZOMBIE_BABY = new FlagType<Boolean>(ZombieWatcher.class, 0, 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<Integer> ZOMBIE_VILLAGER_PROFESSION = new FlagType<Integer>(ZombieVillagerWatcher.class, 1, 0);
public static FlagType<Boolean> ZOMBIE_SHAKING = new FlagType<Boolean>(ZombieWatcher.class, 2, false); public static FlagType<Boolean> ZOMBIE_VILLAGER_SHAKING = new FlagType<Boolean>(ZombieVillagerWatcher.class, 0, false);
static { static {
for (FlagType flagType : values()) { for (FlagType flagType : values()) {

View File

@ -26,8 +26,7 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.PacketsManager; import me.libraryaddict.disguise.utilities.PacketsManager;
import me.libraryaddict.disguise.utilities.ReflectionManager; import me.libraryaddict.disguise.utilities.ReflectionManager;
public class FlagWatcher public class FlagWatcher {
{
private boolean _addEntityAnimations = DisguiseConfig.isEntityAnimationsAdded(); private boolean _addEntityAnimations = DisguiseConfig.isEntityAnimationsAdded();
/** /**
* These are the entity values I need to add else it could crash them.. * These are the entity values I need to add else it could crash them..
@ -40,20 +39,18 @@ public class FlagWatcher
private HashSet<Integer> _modifiedEntityAnimations = new HashSet<>(); private HashSet<Integer> _modifiedEntityAnimations = new HashSet<>();
private List<WrappedWatchableObject> _watchableObjects; private List<WrappedWatchableObject> _watchableObjects;
public FlagWatcher(Disguise disguise) public FlagWatcher(Disguise disguise) {
{
_disguise = (TargetedDisguise) disguise; _disguise = (TargetedDisguise) disguise;
_equipment = ReflectionManager.createEntityEquipment(disguise.getEntity()); _equipment = ReflectionManager.createEntityEquipment(disguise.getEntity());
this.setData(FlagType.ENTITY_AIR_TICKS, 0);
} }
private byte addEntityAnimations(byte originalValue, byte entityValue) private byte addEntityAnimations(byte originalValue, byte entityValue) {
{
byte valueByte = originalValue; byte valueByte = originalValue;
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++) {
{ if ((entityValue & 1 << i) != 0 && !_modifiedEntityAnimations.contains(i)) {
if ((entityValue & 1 << i) != 0 && !_modifiedEntityAnimations.contains(i))
{
valueByte = (byte) (valueByte | 1 << i); valueByte = (byte) (valueByte | 1 << i);
} }
} }
@ -63,16 +60,13 @@ public class FlagWatcher
return originalValue; return originalValue;
} }
public FlagWatcher clone(Disguise owningDisguise) public FlagWatcher clone(Disguise owningDisguise) {
{
FlagWatcher cloned; FlagWatcher cloned;
try try {
{
cloned = getClass().getConstructor(Disguise.class).newInstance(getDisguise()); cloned = getClass().getConstructor(Disguise.class).newInstance(getDisguise());
} }
catch (Exception e) catch (Exception e) {
{
e.printStackTrace(); e.printStackTrace();
cloned = new FlagWatcher(getDisguise()); cloned = new FlagWatcher(getDisguise());
} }
@ -85,49 +79,40 @@ public class FlagWatcher
return cloned; return cloned;
} }
public List<WrappedWatchableObject> convert(List<WrappedWatchableObject> list) public List<WrappedWatchableObject> convert(List<WrappedWatchableObject> list) {
{
List<WrappedWatchableObject> newList = new ArrayList<>(); List<WrappedWatchableObject> newList = new ArrayList<>();
HashSet<Integer> sentValues = new HashSet<>(); HashSet<Integer> sentValues = new HashSet<>();
boolean sendAllCustom = false; boolean sendAllCustom = false;
for (WrappedWatchableObject watch : list) for (WrappedWatchableObject watch : list) {
{
int id = watch.getIndex(); int id = watch.getIndex();
sentValues.add(id); sentValues.add(id);
// Its sending the air metadata. This is the least commonly sent metadata which all entitys still share. // Its sending the air metadata. This is the least commonly sent metadata which all entitys still share.
// I send my custom values if I see this! // I send my custom values if I see this!
if (id == 1) if (id == 1) {
{
sendAllCustom = true; sendAllCustom = true;
} }
Object value = null; Object value = null;
if (_entityValues.containsKey(id)) if (_entityValues.containsKey(id)) {
{ if (_entityValues.get(id) == null) {
if (_entityValues.get(id) == null)
{
continue; continue;
} }
value = _entityValues.get(id); value = _entityValues.get(id);
} }
else if (_backupEntityValues.containsKey(id)) else if (_backupEntityValues.containsKey(id)) {
{ if (_backupEntityValues.get(id) == null) {
if (_backupEntityValues.get(id) == null)
{
continue; continue;
} }
value = _backupEntityValues.get(id); value = _backupEntityValues.get(id);
} }
if (value != null) if (value != null) {
{ if (isEntityAnimationsAdded() && id == 0) {
if (isEntityAnimationsAdded() && id == 0)
{
value = addEntityAnimations((byte) value, (byte) watch.getValue()); value = addEntityAnimations((byte) value, (byte) watch.getValue());
} }
@ -138,13 +123,11 @@ public class FlagWatcher
if (watch == null) if (watch == null)
continue; continue;
if (!isDirty) if (!isDirty) {
{
watch.setDirtyState(false); watch.setDirtyState(false);
} }
} }
else else {
{
boolean isDirty = watch.getDirtyState(); boolean isDirty = watch.getDirtyState();
watch = ReflectionManager.createWatchable(id, watch.getValue()); watch = ReflectionManager.createWatchable(id, watch.getValue());
@ -152,8 +135,7 @@ public class FlagWatcher
if (watch == null) if (watch == null)
continue; continue;
if (!isDirty) if (!isDirty) {
{
watch.setDirtyState(false); watch.setDirtyState(false);
} }
} }
@ -161,20 +143,16 @@ public class FlagWatcher
newList.add(watch); newList.add(watch);
} }
if (sendAllCustom) if (sendAllCustom) {
{
// Its sending the entire meta data. Better add the custom meta // Its sending the entire meta data. Better add the custom meta
for (Integer id : _entityValues.keySet()) for (Integer id : _entityValues.keySet()) {
{ if (sentValues.contains(id)) {
if (sentValues.contains(id))
{
continue; continue;
} }
Object value = _entityValues.get(id); Object value = _entityValues.get(id);
if (value == null) if (value == null) {
{
continue; continue;
} }
@ -188,41 +166,31 @@ public class FlagWatcher
} }
// Here we check for if there is a health packet that says they died. // Here we check for if there is a health packet that says they died.
if (getDisguise().isSelfDisguiseVisible() && getDisguise().getEntity() != null if (getDisguise().isSelfDisguiseVisible() && getDisguise().getEntity() != null
&& getDisguise().getEntity() instanceof Player) && getDisguise().getEntity() instanceof Player) {
{ for (WrappedWatchableObject watch : newList) {
for (WrappedWatchableObject watch : newList)
{
// Its a health packet // Its a health packet
if (watch.getIndex() == 6) if (watch.getIndex() == 6) {
{
Object value = watch.getValue(); Object value = watch.getValue();
if (value != null && value instanceof Float) if (value != null && value instanceof Float) {
{
float newHealth = (Float) value; float newHealth = (Float) value;
if (newHealth > 0 && _hasDied) if (newHealth > 0 && _hasDied) {
{
_hasDied = false; _hasDied = false;
Bukkit.getScheduler().scheduleSyncDelayedTask(DisguiseUtilities.getPlugin(), new Runnable() Bukkit.getScheduler().scheduleSyncDelayedTask(DisguiseUtilities.getPlugin(), new Runnable() {
{
@Override @Override
public void run() public void run() {
{ try {
try
{
DisguiseUtilities.sendSelfDisguise((Player) getDisguise().getEntity(), _disguise); DisguiseUtilities.sendSelfDisguise((Player) getDisguise().getEntity(), _disguise);
} }
catch (Exception ex) catch (Exception ex) {
{
ex.printStackTrace(); ex.printStackTrace();
} }
} }
}, 2); }, 2);
} }
else if (newHealth <= 0 && !_hasDied) else if (newHealth <= 0 && !_hasDied) {
{
_hasDied = true; _hasDied = true;
} }
} }
@ -233,57 +201,48 @@ public class FlagWatcher
return newList; return newList;
} }
public ItemStack[] getArmor() public ItemStack[] getArmor() {
{
ItemStack[] armor = new ItemStack[4]; ItemStack[] armor = new ItemStack[4];
System.arraycopy(armor, 0, armor, 0, 4); System.arraycopy(armor, 0, armor, 0, 4);
return armor; return armor;
} }
public String getCustomName() public String getCustomName() {
{
return (String) getData(FlagType.ENTITY_CUSTOM_NAME); return (String) getData(FlagType.ENTITY_CUSTOM_NAME);
} }
protected TargetedDisguise getDisguise() protected TargetedDisguise getDisguise() {
{
return _disguise; return _disguise;
} }
private boolean getEntityFlag(int byteValue) private boolean getEntityFlag(int byteValue) {
{
return (getData(FlagType.ENTITY_META) & 1 << byteValue) != 0; return (getData(FlagType.ENTITY_META) & 1 << byteValue) != 0;
} }
public EntityEquipment getEquipment() public EntityEquipment getEquipment() {
{
return _equipment; return _equipment;
} }
public ItemStack getItemInMainHand() public ItemStack getItemInMainHand() {
{
if (_equipment == null) if (_equipment == null)
return null; return null;
return _equipment.getItemInMainHand(); return _equipment.getItemInMainHand();
} }
public ItemStack getItemInOffHand() public ItemStack getItemInOffHand() {
{
if (_equipment == null) if (_equipment == null)
return null; return null;
return _equipment.getItemInOffHand(); return _equipment.getItemInOffHand();
} }
public ItemStack getItemStack(EquipmentSlot slot) public ItemStack getItemStack(EquipmentSlot slot) {
{
if (_equipment == null) if (_equipment == null)
return null; return null;
switch (slot) switch (slot) {
{
case CHEST: case CHEST:
return _equipment.getChestplate(); return _equipment.getChestplate();
case FEET: case FEET:
@ -301,104 +260,83 @@ public class FlagWatcher
return null; return null;
} }
protected <Y> Y getData(FlagType<Y> flagType) protected <Y> Y getData(FlagType<Y> flagType) {
{ if (_entityValues.containsKey(flagType.getIndex())) {
if (_entityValues.containsKey(flagType.getIndex()))
{
return (Y) _entityValues.get(flagType.getIndex()); return (Y) _entityValues.get(flagType.getIndex());
} }
return flagType.getDefault(); return flagType.getDefault();
} }
public List<WrappedWatchableObject> getWatchableObjects() public List<WrappedWatchableObject> getWatchableObjects() {
{ if (_watchableObjects == null) {
if (_watchableObjects == null)
{
rebuildWatchableObjects(); rebuildWatchableObjects();
} }
return _watchableObjects; return _watchableObjects;
} }
public boolean hasCustomName() public boolean hasCustomName() {
{
return getCustomName() != null; return getCustomName() != null;
} }
protected boolean hasValue(FlagType no) protected boolean hasValue(FlagType no) {
{
return _entityValues.containsKey(no.getIndex()); return _entityValues.containsKey(no.getIndex());
} }
public boolean isBurning() public boolean isBurning() {
{
return getEntityFlag(0); return getEntityFlag(0);
} }
public boolean isCustomNameVisible() public boolean isCustomNameVisible() {
{
return getData(FlagType.ENTITY_CUSTOM_NAME_VISIBLE); return getData(FlagType.ENTITY_CUSTOM_NAME_VISIBLE);
} }
public boolean isEntityAnimationsAdded() public boolean isEntityAnimationsAdded() {
{
return _addEntityAnimations; return _addEntityAnimations;
} }
public boolean isFlyingWithElytra() public boolean isFlyingWithElytra() {
{
return getEntityFlag(7); return getEntityFlag(7);
} }
public boolean isGlowing() public boolean isGlowing() {
{
return getEntityFlag(6); return getEntityFlag(6);
} }
public boolean isInvisible() public boolean isInvisible() {
{
return getEntityFlag(5); return getEntityFlag(5);
} }
public boolean isNoGravity() public boolean isNoGravity() {
{
return getData(FlagType.ENTITY_NO_GRAVITY); return getData(FlagType.ENTITY_NO_GRAVITY);
} }
public boolean isRightClicking() public boolean isRightClicking() {
{
return getEntityFlag(4); return getEntityFlag(4);
} }
public boolean isSneaking() public boolean isSneaking() {
{
return getEntityFlag(1); return getEntityFlag(1);
} }
public boolean isSprinting() public boolean isSprinting() {
{
return getEntityFlag(3); return getEntityFlag(3);
} }
public void rebuildWatchableObjects() public void rebuildWatchableObjects() {
{
_watchableObjects = new ArrayList<>(); _watchableObjects = new ArrayList<>();
for (int i = 0; i <= 31; i++) for (int i = 0; i <= 31; i++) {
{
WrappedWatchableObject watchable = null; WrappedWatchableObject watchable = null;
if (_entityValues.containsKey(i) && _entityValues.get(i) != null) if (_entityValues.containsKey(i) && _entityValues.get(i) != null) {
{
watchable = ReflectionManager.createWatchable(i, _entityValues.get(i)); watchable = ReflectionManager.createWatchable(i, _entityValues.get(i));
} }
else if (_backupEntityValues.containsKey(i) && _backupEntityValues.get(i) != null) else if (_backupEntityValues.containsKey(i) && _backupEntityValues.get(i) != null) {
{
watchable = ReflectionManager.createWatchable(i, _backupEntityValues.get(i)); watchable = ReflectionManager.createWatchable(i, _backupEntityValues.get(i));
} }
else else {
{
continue; continue;
} }
@ -409,28 +347,22 @@ public class FlagWatcher
} }
} }
protected void sendData(FlagType... dataValues) protected void sendData(FlagType... dataValues) {
{ if (!DisguiseAPI.isDisguiseInUse(getDisguise()) || getDisguise().getWatcher() != this) {
if (!DisguiseAPI.isDisguiseInUse(getDisguise()) || getDisguise().getWatcher() != this)
{
return; return;
} }
List<WrappedWatchableObject> list = new ArrayList<>(); List<WrappedWatchableObject> list = new ArrayList<>();
for (FlagType data : dataValues) for (FlagType data : dataValues) {
{ if (!_entityValues.containsKey(data.getIndex()) || _entityValues.get(data.getIndex()) == null) {
if (!_entityValues.containsKey(data.getIndex()) || _entityValues.get(data.getIndex()) == null)
{
continue; continue;
} }
Object value = _entityValues.get(data.getIndex()); Object value = _entityValues.get(data.getIndex());
if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == FlagType.ENTITY_META) if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == FlagType.ENTITY_META) {
{ if (!PacketsManager.isStaticMetadataDisguiseType(_disguise)) {
if (!PacketsManager.isStaticMetadataDisguiseType(_disguise))
{
value = addEntityAnimations((byte) value, value = addEntityAnimations((byte) value,
WrappedDataWatcher.getEntityWatcher(_disguise.getEntity()).getByte(0)); WrappedDataWatcher.getEntityWatcher(_disguise.getEntity()).getByte(0));
} }
@ -444,8 +376,7 @@ public class FlagWatcher
list.add(watch); list.add(watch);
} }
if (!list.isEmpty()) if (!list.isEmpty()) {
{
PacketContainer packet = new PacketContainer(Server.ENTITY_METADATA); PacketContainer packet = new PacketContainer(Server.ENTITY_METADATA);
StructureModifier<Object> mods = packet.getModifier(); StructureModifier<Object> mods = packet.getModifier();
@ -453,59 +384,48 @@ public class FlagWatcher
packet.getWatchableCollectionModifier().write(0, list); packet.getWatchableCollectionModifier().write(0, list);
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
{ try {
try if (player == getDisguise().getEntity()) {
{
if (player == getDisguise().getEntity())
{
PacketContainer temp = packet.shallowClone(); PacketContainer temp = packet.shallowClone();
temp.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId()); temp.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
ProtocolLibrary.getProtocolManager().sendServerPacket(player, temp); ProtocolLibrary.getProtocolManager().sendServerPacket(player, temp);
} }
else else {
{
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
} }
} }
catch (InvocationTargetException e) catch (InvocationTargetException e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
} }
public void setAddEntityAnimations(boolean isEntityAnimationsAdded) public void setAddEntityAnimations(boolean isEntityAnimationsAdded) {
{
_addEntityAnimations = isEntityAnimationsAdded; _addEntityAnimations = isEntityAnimationsAdded;
} }
public void setArmor(ItemStack[] itemstack) public void setArmor(ItemStack[] itemstack) {
{
setItemStack(EquipmentSlot.HEAD, itemstack[0]); setItemStack(EquipmentSlot.HEAD, itemstack[0]);
setItemStack(EquipmentSlot.CHEST, itemstack[1]); setItemStack(EquipmentSlot.CHEST, itemstack[1]);
setItemStack(EquipmentSlot.LEGS, itemstack[2]); setItemStack(EquipmentSlot.LEGS, itemstack[2]);
setItemStack(EquipmentSlot.FEET, itemstack[3]); setItemStack(EquipmentSlot.FEET, itemstack[3]);
} }
protected void setBackupValue(FlagType no, Object value) protected void setBackupValue(FlagType no, Object value) {
{
_backupEntityValues.put(no.getIndex(), value); _backupEntityValues.put(no.getIndex(), value);
} }
public void setBurning(boolean setBurning) public void setBurning(boolean setBurning) {
{
setEntityFlag(0, setBurning); setEntityFlag(0, setBurning);
sendData(FlagType.ENTITY_META); sendData(FlagType.ENTITY_META);
} }
public void setCustomName(String name) public void setCustomName(String name) {
{ if (name != null && name.length() > 64) {
if (name != null && name.length() > 64)
{
name = name.substring(0, 64); name = name.substring(0, 64);
} }
@ -513,42 +433,35 @@ public class FlagWatcher
sendData(FlagType.ENTITY_CUSTOM_NAME); sendData(FlagType.ENTITY_CUSTOM_NAME);
} }
public void setCustomNameVisible(boolean display) public void setCustomNameVisible(boolean display) {
{
setData(FlagType.ENTITY_CUSTOM_NAME_VISIBLE, display); setData(FlagType.ENTITY_CUSTOM_NAME_VISIBLE, display);
sendData(FlagType.ENTITY_CUSTOM_NAME_VISIBLE); sendData(FlagType.ENTITY_CUSTOM_NAME_VISIBLE);
} }
private void setEntityFlag(int byteValue, boolean flag) private void setEntityFlag(int byteValue, boolean flag) {
{
_modifiedEntityAnimations.add(byteValue); _modifiedEntityAnimations.add(byteValue);
byte b0 = (byte) getData(FlagType.ENTITY_META); byte b0 = (byte) getData(FlagType.ENTITY_META);
if (flag) if (flag) {
{
setData(FlagType.ENTITY_META, (byte) (b0 | 1 << byteValue)); setData(FlagType.ENTITY_META, (byte) (b0 | 1 << byteValue));
} }
else else {
{
setData(FlagType.ENTITY_META, (byte) (b0 & ~(1 << byteValue))); setData(FlagType.ENTITY_META, (byte) (b0 & ~(1 << byteValue)));
} }
} }
public void setFlyingWithElytra(boolean flying) public void setFlyingWithElytra(boolean flying) {
{
setEntityFlag(7, flying); setEntityFlag(7, flying);
sendData(FlagType.ENTITY_META); sendData(FlagType.ENTITY_META);
} }
public void setGlowing(boolean glowing) public void setGlowing(boolean glowing) {
{
setEntityFlag(6, glowing); setEntityFlag(6, glowing);
sendData(FlagType.ENTITY_META); sendData(FlagType.ENTITY_META);
} }
public void setInvisible(boolean setInvis) public void setInvisible(boolean setInvis) {
{
setEntityFlag(5, setInvis); setEntityFlag(5, setInvis);
sendData(FlagType.ENTITY_META); sendData(FlagType.ENTITY_META);
} }
@ -559,28 +472,23 @@ public class FlagWatcher
* @param itemstack * @param itemstack
*/ */
@Deprecated @Deprecated
public void setItemInHand(ItemStack itemstack) public void setItemInHand(ItemStack itemstack) {
{
setItemInMainHand(itemstack); setItemInMainHand(itemstack);
} }
public void setItemInMainHand(ItemStack itemstack) public void setItemInMainHand(ItemStack itemstack) {
{
setItemStack(EquipmentSlot.HAND, itemstack); setItemStack(EquipmentSlot.HAND, itemstack);
} }
public void setItemInOffHand(ItemStack itemstack) public void setItemInOffHand(ItemStack itemstack) {
{
setItemStack(EquipmentSlot.OFF_HAND, itemstack); setItemStack(EquipmentSlot.OFF_HAND, itemstack);
} }
private void setItemStack(EntityEquipment equipment, EquipmentSlot slot, ItemStack itemStack) private void setItemStack(EntityEquipment equipment, EquipmentSlot slot, ItemStack itemStack) {
{
if (equipment == null) if (equipment == null)
return; return;
switch (slot) switch (slot) {
{
case CHEST: case CHEST:
equipment.setChestplate(itemStack); equipment.setChestplate(itemStack);
break; break;
@ -602,17 +510,14 @@ public class FlagWatcher
} }
} }
public void setItemStack(EquipmentSlot slot, ItemStack itemStack) public void setItemStack(EquipmentSlot slot, ItemStack itemStack) {
{
if (_equipment == null) if (_equipment == null)
return; return;
// Itemstack which is null means that its not replacing the disguises itemstack. // Itemstack which is null means that its not replacing the disguises itemstack.
if (itemStack == null) if (itemStack == null) {
{
// Find the item to replace it with // Find the item to replace it with
if (getDisguise().getEntity() instanceof LivingEntity) if (getDisguise().getEntity() instanceof LivingEntity) {
{
EntityEquipment equipment = ((LivingEntity) getDisguise().getEntity()).getEquipment(); EntityEquipment equipment = ((LivingEntity) getDisguise().getEntity()).getEquipment();
setItemStack(equipment, slot, itemStack); setItemStack(equipment, slot, itemStack);
} }
@ -620,15 +525,13 @@ public class FlagWatcher
Object itemToSend = null; Object itemToSend = null;
if (itemStack != null && itemStack.getTypeId() != 0) if (itemStack != null && itemStack.getTypeId() != 0) {
{
itemToSend = ReflectionManager.getNmsItem(itemStack); itemToSend = ReflectionManager.getNmsItem(itemStack);
} }
setItemStack(_equipment, slot, itemStack); setItemStack(_equipment, slot, itemStack);
if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) {
{
PacketContainer packet = new PacketContainer(Server.ENTITY_EQUIPMENT); PacketContainer packet = new PacketContainer(Server.ENTITY_EQUIPMENT);
StructureModifier<Object> mods = packet.getModifier(); StructureModifier<Object> mods = packet.getModifier();
@ -637,50 +540,44 @@ public class FlagWatcher
mods.write(1, ReflectionManager.createEnumItemSlot(slot)); mods.write(1, ReflectionManager.createEnumItemSlot(slot));
mods.write(2, itemToSend); mods.write(2, itemToSend);
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
{ try {
try
{
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
} }
catch (InvocationTargetException e) catch (InvocationTargetException e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
} }
public void setNoGravity(boolean noGravity) public void setNoGravity(boolean noGravity) {
{
setData(FlagType.ENTITY_NO_GRAVITY, noGravity); setData(FlagType.ENTITY_NO_GRAVITY, noGravity);
sendData(FlagType.ENTITY_NO_GRAVITY); sendData(FlagType.ENTITY_NO_GRAVITY);
} }
public void setRightClicking(boolean setRightClicking) public void setRightClicking(boolean setRightClicking) {
{
setEntityFlag(4, setRightClicking); setEntityFlag(4, setRightClicking);
sendData(FlagType.ENTITY_META); sendData(FlagType.ENTITY_META);
} }
public void setSneaking(boolean setSneaking) public void setSneaking(boolean setSneaking) {
{
setEntityFlag(1, setSneaking); setEntityFlag(1, setSneaking);
sendData(FlagType.ENTITY_META); sendData(FlagType.ENTITY_META);
} }
public void setSprinting(boolean setSprinting) public void setSprinting(boolean setSprinting) {
{
setEntityFlag(3, setSprinting); setEntityFlag(3, setSprinting);
sendData(FlagType.ENTITY_META); sendData(FlagType.ENTITY_META);
} }
protected <Y> void setData(FlagType<Y> id, Y value) protected <Y> void setData(FlagType<Y> id, Y value) {
{ if (value == null && id.getDefault() instanceof ItemStack)
throw new IllegalArgumentException("Cannot use null ItemStacks");
_entityValues.put(id.getIndex(), value); _entityValues.put(id.getIndex(), value);
if (!DisguiseConfig.isMetadataPacketsEnabled()) if (!DisguiseConfig.isMetadataPacketsEnabled()) {
{
rebuildWatchableObjects(); rebuildWatchableObjects();
} }
} }

View File

@ -7,51 +7,43 @@ import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
/** /**
* @author Navid * @author Navid
*/ */
public class AreaEffectCloudWatcher extends FlagWatcher public class AreaEffectCloudWatcher extends FlagWatcher {
{
public AreaEffectCloudWatcher(Disguise disguise) public AreaEffectCloudWatcher(Disguise disguise) {
{
super(disguise); super(disguise);
setRadius(1);
} }
public float getRadius() public float getRadius() {
{
return getData(FlagType.AREA_EFFECT_RADIUS); return getData(FlagType.AREA_EFFECT_RADIUS);
} }
public int getColor() public int getColor() {
{ return getData(FlagType.AREA_EFFECT_CLOUD_COLOR);
return getData(FlagType.AREA_EFFECT_COLOR);
} }
public boolean isIgnoreRadius() public boolean isIgnoreRadius() {
{
return getData(FlagType.AREA_EFFECT_IGNORE_RADIUS); return getData(FlagType.AREA_EFFECT_IGNORE_RADIUS);
} }
public int getParticleId() public int getParticleId() {
{
return getData(FlagType.AREA_EFFECT_PARTICLE); return getData(FlagType.AREA_EFFECT_PARTICLE);
} }
public void setRadius(float radius) public void setRadius(float radius) {
{
setData(FlagType.AREA_EFFECT_RADIUS, radius); setData(FlagType.AREA_EFFECT_RADIUS, radius);
} }
public void setColor(int color) public void setColor(int color) {
{ setData(FlagType.AREA_EFFECT_CLOUD_COLOR, color);
setData(FlagType.AREA_EFFECT_COLOR, color);
} }
public void setIgnoreRadius(boolean ignore) public void setIgnoreRadius(boolean ignore) {
{
setData(FlagType.AREA_EFFECT_IGNORE_RADIUS, ignore); setData(FlagType.AREA_EFFECT_IGNORE_RADIUS, ignore);
} }
public void setParticleId(int particleId) public void setParticleId(int particleId) {
{
setData(FlagType.AREA_EFFECT_PARTICLE, particleId); setData(FlagType.AREA_EFFECT_PARTICLE, particleId);
} }

View File

@ -2,27 +2,21 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.google.common.base.Optional;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
public class DroppedItemWatcher extends FlagWatcher public class DroppedItemWatcher extends FlagWatcher {
{ public DroppedItemWatcher(Disguise disguise) {
public DroppedItemWatcher(Disguise disguise)
{
super(disguise); super(disguise);
} }
public ItemStack getItemStack() public ItemStack getItemStack() {
{ return getData(FlagType.DROPPED_ITEM);
return getData(FlagType.DROPPED_ITEM).get();
} }
public void setItemStack(ItemStack item) public void setItemStack(ItemStack item) {
{ setData(FlagType.DROPPED_ITEM, item);
setData(FlagType.DROPPED_ITEM, Optional.<ItemStack> of(item));
sendData(FlagType.DROPPED_ITEM); sendData(FlagType.DROPPED_ITEM);
} }
} }

View File

@ -16,12 +16,12 @@ public class EnderDragonWatcher extends InsentientWatcher
public int getPhase() public int getPhase()
{ {
return getData(FlagType.ENDERDRAGON_PHASE); return getData(FlagType.ENDERD_RAGON_PHASE);
} }
public void setPhase(int phase) public void setPhase(int phase)
{ {
setData(FlagType.ENDERDRAGON_PHASE, phase); setData(FlagType.ENDERD_RAGON_PHASE, phase);
sendData(FlagType.ENDERDRAGON_PHASE); sendData(FlagType.ENDERD_RAGON_PHASE);
} }
} }

View File

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

View File

@ -13,13 +13,13 @@ public class FishingHookWatcher extends FlagWatcher
public void setHooked(int hookedId) public void setHooked(int hookedId)
{ {
setData(FlagType.FISHING_HOOK, hookedId + 1); setData(FlagType.FISHING_HOOK_HOOKED, hookedId + 1);
sendData(FlagType.FISHING_HOOK); sendData(FlagType.FISHING_HOOK_HOOKED);
} }
public int getHooked() public int getHooked()
{ {
int hooked = getData(FlagType.FISHING_HOOK); int hooked = getData(FlagType.FISHING_HOOK_HOOKED);
if (hooked > 0) if (hooked > 0)
hooked--; hooked--;

View File

@ -7,11 +7,8 @@ import org.bukkit.entity.Player;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
public class GuardianWatcher extends InsentientWatcher public class GuardianWatcher extends InsentientWatcher {
{ public GuardianWatcher(Disguise disguise) {
public GuardianWatcher(Disguise disguise)
{
super(disguise); super(disguise);
} }
@ -20,8 +17,7 @@ public class GuardianWatcher extends InsentientWatcher
* *
* @return * @return
*/ */
public boolean isTarget() public boolean isTarget() {
{
return ((int) getData(FlagType.GUARDIAN_TARGET)) != 0; return ((int) getData(FlagType.GUARDIAN_TARGET)) != 0;
} }
@ -30,14 +26,12 @@ public class GuardianWatcher extends InsentientWatcher
* *
* @param entityId * @param entityId
*/ */
public void setTarget(int entityId) public void setTarget(int entityId) {
{
setData(FlagType.GUARDIAN_TARGET, entityId); setData(FlagType.GUARDIAN_TARGET, entityId);
sendData(FlagType.GUARDIAN_TARGET); sendData(FlagType.GUARDIAN_TARGET);
} }
public void setTarget(Entity entity) public void setTarget(Entity entity) {
{
setTarget(entity == null ? 0 : entity.getEntityId()); setTarget(entity == null ? 0 : entity.getEntityId());
} }
@ -46,8 +40,7 @@ public class GuardianWatcher extends InsentientWatcher
* *
* @param playername * @param playername
*/ */
public void setTarget(String playername) public void setTarget(String playername) {
{
Player player = Bukkit.getPlayer(playername); Player player = Bukkit.getPlayer(playername);
if (player == null) if (player == null)
@ -57,45 +50,13 @@ public class GuardianWatcher extends InsentientWatcher
sendData(FlagType.GUARDIAN_TARGET); sendData(FlagType.GUARDIAN_TARGET);
} }
public boolean isRetractingSpikes() public boolean isRetractingSpikes() {
{ return getData(FlagType.GUARDIAN_RETRACT_SPIKES);
return isGuardianFlag(2);
} }
public void setRetractingSpikes(boolean isRetracting) public void setRetractingSpikes(boolean isRetracting) {
{ setData(FlagType.GUARDIAN_RETRACT_SPIKES, isRetracting);
setGuardianFlag(2, isRetracting); sendData(FlagType.GUARDIAN_RETRACT_SPIKES);
}
public boolean isElder()
{
return isGuardianFlag(4);
}
public void setElder(boolean isGuardian)
{
setGuardianFlag(4, isGuardian);
}
protected boolean isGuardianFlag(int no)
{
return (getData(FlagType.GUARDIAN_FLAG) & no) != 0;
}
protected void setGuardianFlag(int no, boolean flag)
{
byte b0 = getData(FlagType.GUARDIAN_FLAG);
if (flag)
{
setData(FlagType.GUARDIAN_FLAG, (byte) (b0 | no));
}
else
{
setData(FlagType.GUARDIAN_FLAG, (byte) (b0 & -(no + 1)));
}
sendData(FlagType.GUARDIAN_FLAG);
} }
} }

View File

@ -10,11 +10,11 @@ public class HorseChestedWatcher extends HorseAbstractWatcher {
} }
public void setCarryingChest(boolean carryingChest) { public void setCarryingChest(boolean carryingChest) {
setData(FlagType.HORSE_CARRYING_CHEST, carryingChest); setData(FlagType.HORSE_CHESTED_CARRYING_CHEST, carryingChest);
sendData(FlagType.HORSE_CARRYING_CHEST); sendData(FlagType.HORSE_CHESTED_CARRYING_CHEST);
} }
public boolean isCarryingChest() { public boolean isCarryingChest() {
return getData(FlagType.HORSE_CARRYING_CHEST); return getData(FlagType.HORSE_CHESTED_CARRYING_CHEST);
} }
} }

View File

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

View File

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

View File

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

View File

@ -14,13 +14,13 @@ public class WitherSkullWatcher extends FlagWatcher
public boolean isBlue() public boolean isBlue()
{ {
return (boolean) getData(FlagType.WITHERSKULL_BLUE); return (boolean) getData(FlagType.WITHER_SKULL_BLUE);
} }
public void setBlue(boolean blue) public void setBlue(boolean blue)
{ {
setData(FlagType.WITHERSKULL_BLUE, blue); setData(FlagType.WITHER_SKULL_BLUE, blue);
sendData(FlagType.WITHERSKULL_BLUE); sendData(FlagType.WITHER_SKULL_BLUE);
} }
} }

View File

@ -0,0 +1,61 @@
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 ZombieVillagerWatcher extends ZombieWatcher {
public ZombieVillagerWatcher(Disguise disguise) {
super(disguise);
}
public boolean isShaking() {
return getData(FlagType.ZOMBIE_VILLAGER_SHAKING);
}
/**
* Is this zombie a villager?
*
* @return
*/
public boolean isVillager() {
return ((int) getData(FlagType.ZOMBIE_VILLAGER_PROFESSION)) != 0;
}
public void setShaking(boolean shaking) {
setData(FlagType.ZOMBIE_VILLAGER_SHAKING, shaking);
sendData(FlagType.ZOMBIE_VILLAGER_SHAKING);
}
/**
* Only returns a valid value if this zombie is a villager.
*
* @return
*/
public Profession getProfession() {
return Profession.values()[getData(FlagType.ZOMBIE_VILLAGER_PROFESSION)];
}
/**
* Sets the profession of this zombie, in turn turning it into a Zombie Villager
*
* @param id
*/
public void setProfession(int id) {
setData(FlagType.ZOMBIE_VILLAGER_PROFESSION, id);
sendData(FlagType.ZOMBIE_VILLAGER_PROFESSION);
}
/**
* Sets the profession of this zombie, in turn turning it into a Zombie Villager
*
* @param profession
*/
public void setProfession(Profession profession) {
setData(FlagType.ZOMBIE_VILLAGER_PROFESSION, profession.ordinal());
sendData(FlagType.ZOMBIE_VILLAGER_PROFESSION);
}
}

View File

@ -1,104 +1,40 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.entity.Villager.Profession;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
public class ZombieWatcher extends InsentientWatcher public class ZombieWatcher extends InsentientWatcher {
{
public ZombieWatcher(Disguise disguise) public ZombieWatcher(Disguise disguise) {
{
super(disguise); super(disguise);
} }
public boolean isAdult() public boolean isAdult() {
{
return !isBaby(); return !isBaby();
} }
public boolean isBaby() public boolean isBaby() {
{
return getData(FlagType.ZOMBIE_BABY); return getData(FlagType.ZOMBIE_BABY);
} }
public boolean isShaking() public boolean isAggressive() {
{
return getData(FlagType.ZOMBIE_SHAKING);
}
/**
* Is this zombie a villager?
*
* @return
*/
public boolean isVillager()
{
return ((int) getData(FlagType.ZOMBIE_PROFESSION)) != 0;
}
public boolean isAggressive()
{
return (boolean) getData(FlagType.ZOMBIE_AGGRESSIVE); return (boolean) getData(FlagType.ZOMBIE_AGGRESSIVE);
} }
/** public void setAdult() {
* Only returns a valid value if this zombie is a villager.
*
* @return
*/
public Profession getProfession()
{
return Profession.values()[getData(FlagType.ZOMBIE_PROFESSION)];
}
public void setAdult()
{
setBaby(false); setBaby(false);
} }
public void setBaby() public void setBaby() {
{
setBaby(true); setBaby(true);
} }
public void setBaby(boolean baby) public void setBaby(boolean baby) {
{
setData(FlagType.ZOMBIE_BABY, baby); setData(FlagType.ZOMBIE_BABY, baby);
sendData(FlagType.ZOMBIE_BABY); sendData(FlagType.ZOMBIE_BABY);
} }
public void setShaking(boolean shaking) public void setAggressive(boolean handsup) {
{
setData(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)
{
setData(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)
{
setData(FlagType.ZOMBIE_PROFESSION, profession.ordinal());
sendData(FlagType.ZOMBIE_PROFESSION);
}
public void setAggressive(boolean handsup)
{
setData(FlagType.ZOMBIE_AGGRESSIVE, handsup); setData(FlagType.ZOMBIE_AGGRESSIVE, handsup);
sendData(FlagType.ZOMBIE_AGGRESSIVE); sendData(FlagType.ZOMBIE_AGGRESSIVE);
} }

View File

@ -4,18 +4,15 @@ import java.util.HashMap;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
public class DisguiseValues public class DisguiseValues {
{
private static HashMap<DisguiseType, DisguiseValues> values = new HashMap<>(); private static HashMap<DisguiseType, DisguiseValues> values = new HashMap<>();
public static DisguiseValues getDisguiseValues(DisguiseType type) public static DisguiseValues getDisguiseValues(DisguiseType type) {
{ switch (type) {
switch (type)
{
case DONKEY: case DONKEY:
case MULE: case MULE:
case UNDEAD_HORSE: case ZOMBIE_HORSE:
case SKELETON_HORSE: case SKELETON_HORSE:
type = DisguiseType.HORSE; type = DisguiseType.HORSE;
break; break;
@ -28,6 +25,7 @@ public class DisguiseValues
type = DisguiseType.MINECART; type = DisguiseType.MINECART;
break; break;
case WITHER_SKELETON: case WITHER_SKELETON:
case STRAY:
type = DisguiseType.SKELETON; type = DisguiseType.SKELETON;
break; break;
case ZOMBIE_VILLAGER: case ZOMBIE_VILLAGER:
@ -39,8 +37,7 @@ public class DisguiseValues
return values.get(type); return values.get(type);
} }
public static Class getNmsEntityClass(DisguiseType type) public static Class getNmsEntityClass(DisguiseType type) {
{
return getDisguiseValues(type).getNmsEntityClass(); return getDisguiseValues(type).getNmsEntityClass();
} }
@ -50,50 +47,41 @@ public class DisguiseValues
private double maxHealth; private double maxHealth;
private Class nmsEntityClass; private Class nmsEntityClass;
public DisguiseValues(DisguiseType type, Class classType, int entitySize, double maxHealth) public DisguiseValues(DisguiseType type, Class classType, int entitySize, double maxHealth) {
{
values.put(type, this); values.put(type, this);
nmsEntityClass = classType; nmsEntityClass = classType;
this.maxHealth = maxHealth; this.maxHealth = maxHealth;
} }
public FakeBoundingBox getAdultBox() public FakeBoundingBox getAdultBox() {
{
return adultBox; return adultBox;
} }
public FakeBoundingBox getBabyBox() public FakeBoundingBox getBabyBox() {
{
return babyBox; return babyBox;
} }
public float[] getEntitySize() public float[] getEntitySize() {
{
return entitySize; return entitySize;
} }
public double getMaxHealth() public double getMaxHealth() {
{
return maxHealth; return maxHealth;
} }
public Class getNmsEntityClass() public Class getNmsEntityClass() {
{
return nmsEntityClass; return nmsEntityClass;
} }
public void setAdultBox(FakeBoundingBox newBox) public void setAdultBox(FakeBoundingBox newBox) {
{
adultBox = newBox; adultBox = newBox;
} }
public void setBabyBox(FakeBoundingBox newBox) public void setBabyBox(FakeBoundingBox newBox) {
{
babyBox = newBox; babyBox = newBox;
} }
public void setEntitySize(float[] size) public void setEntitySize(float[] size) {
{
this.entitySize = size; this.entitySize = size;
} }
} }

View File

@ -2,6 +2,7 @@ package me.libraryaddict.disguise.utilities;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -104,6 +105,10 @@ public class PacketsManager {
return packets; return packets;
} }
public Collection<ArrayList<PacketContainer>> getDelayedPackets() {
return delayedPackets.values();
}
public void sendDelayed(final Player observer) { public void sendDelayed(final Player observer) {
for (final Entry<Integer, ArrayList<PacketContainer>> entry : delayedPackets.entrySet()) { for (final Entry<Integer, ArrayList<PacketContainer>> entry : delayedPackets.entrySet()) {
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
@ -494,6 +499,16 @@ public class PacketsManager {
mods.write(1, yaw); mods.write(1, yaw);
} }
if (disguise.getType() == DisguiseType.EVOKER_FANGS) {
PacketContainer newPacket = new PacketContainer(Server.ENTITY_STATUS);
StructureModifier<Object> mods = newPacket.getModifier();
mods.write(0, disguise.getEntity().getEntityId());
mods.write(1, (byte) 4);
packets.addPacket(newPacket);
}
return packets; return packets;
} }

View File

@ -778,7 +778,7 @@ public class ReflectionManager {
return null; return null;
} }
private static Object convertInvalidItem(Object value) { public static Object convertInvalidItem(Object value) {
if (value instanceof Optional) { if (value instanceof Optional) {
Optional opt = (Optional) value; Optional opt = (Optional) value;
@ -787,10 +787,7 @@ public class ReflectionManager {
Object val = opt.get(); Object val = opt.get();
if (val instanceof ItemStack) { if (val instanceof BlockPosition) {
return Optional.of(getNmsItem((ItemStack) val));
}
else if (val instanceof BlockPosition) {
BlockPosition pos = (BlockPosition) val; BlockPosition pos = (BlockPosition) val;
try { try {
@ -840,6 +837,9 @@ public class ReflectionManager {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
else if (value instanceof ItemStack) {
return getNmsItem((ItemStack) value);
}
return value; return value;
} }
@ -871,8 +871,10 @@ public class ReflectionManager {
} }
if (serializer == null) { if (serializer == null) {
throw new IllegalArgumentException( throw new IllegalArgumentException("Unable to find Serializer for " + value
"Unable to find Serializer for " + value + "! Are you running the latest version of ProtocolLib?"); + (value instanceof Optional && ((Optional) value).isPresent()
? " (" + ((Optional) value).get().getClass().getName() + ")" : "")
+ "! Are you running the latest version of ProtocolLib?");
} }
WrappedDataWatcherObject watcherObject = new WrappedDataWatcherObject(id, serializer); WrappedDataWatcherObject watcherObject = new WrappedDataWatcherObject(id, serializer);

View File

@ -22,10 +22,8 @@ import me.libraryaddict.disguise.utilities.PacketsManager;
import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets; import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets;
import me.libraryaddict.disguise.utilities.ReflectionManager; import me.libraryaddict.disguise.utilities.ReflectionManager;
public class PacketListenerViewDisguises extends PacketAdapter public class PacketListenerViewDisguises extends PacketAdapter {
{ public PacketListenerViewDisguises(LibsDisguises plugin) {
public PacketListenerViewDisguises(LibsDisguises plugin)
{
super(plugin, ListenerPriority.HIGH, Server.NAMED_ENTITY_SPAWN, Server.ATTACH_ENTITY, Server.REL_ENTITY_MOVE, super(plugin, ListenerPriority.HIGH, Server.NAMED_ENTITY_SPAWN, Server.ATTACH_ENTITY, Server.REL_ENTITY_MOVE,
Server.REL_ENTITY_MOVE_LOOK, Server.ENTITY_LOOK, Server.ENTITY_TELEPORT, Server.ENTITY_HEAD_ROTATION, Server.REL_ENTITY_MOVE_LOOK, Server.ENTITY_LOOK, Server.ENTITY_TELEPORT, Server.ENTITY_HEAD_ROTATION,
Server.ENTITY_METADATA, Server.ENTITY_EQUIPMENT, Server.ANIMATION, Server.BED, Server.ENTITY_EFFECT, Server.ENTITY_METADATA, Server.ENTITY_EQUIPMENT, Server.ANIMATION, Server.BED, Server.ENTITY_EFFECT,
@ -33,25 +31,21 @@ public class PacketListenerViewDisguises extends PacketAdapter
} }
@Override @Override
public void onPacketSending(final PacketEvent event) public void onPacketSending(final PacketEvent event) {
{
if (event.isCancelled()) if (event.isCancelled())
return; return;
try try {
{
final Player observer = event.getPlayer(); final Player observer = event.getPlayer();
if (observer.getName().contains("UNKNOWN[")) // If the player is temporary if (observer.getName().contains("UNKNOWN[")) // If the player is temporary
return; return;
if (event.getPacket().getIntegers().read(0) != observer.getEntityId()) if (event.getPacket().getIntegers().read(0) != observer.getEntityId()) {
{
return; return;
} }
if (!DisguiseAPI.isSelfDisguised(observer)) if (!DisguiseAPI.isSelfDisguised(observer)) {
{
return; return;
} }
@ -63,45 +57,48 @@ public class PacketListenerViewDisguises extends PacketAdapter
// Here I grab the packets to convert them to, So I can display them as if the disguise sent them. // Here I grab the packets to convert them to, So I can display them as if the disguise sent them.
LibsPackets transformed = PacketsManager.transformPacket(event.getPacket(), disguise, observer, observer); LibsPackets transformed = PacketsManager.transformPacket(event.getPacket(), disguise, observer, observer);
if (transformed.isUnhandled()) if (transformed.isUnhandled()) {
{
transformed.getPackets().add(event.getPacket()); transformed.getPackets().add(event.getPacket());
} }
transformed.setPacketType(event.getPacketType()); transformed.setPacketType(event.getPacketType());
for (PacketContainer packet : transformed.getPackets()) for (PacketContainer packet : transformed.getPackets()) {
{ if (packet.getType() != Server.PLAYER_INFO) {
if (packet.getType() != Server.PLAYER_INFO) if (packet.equals(event.getPacket())) {
{
if (packet.equals(event.getPacket()))
{
packet = packet.shallowClone(); packet = packet.shallowClone();
} }
packet.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId()); packet.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
} }
try try {
{
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false); ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
} }
catch (InvocationTargetException e) catch (InvocationTargetException e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
for (ArrayList<PacketContainer> packets : transformed.getDelayedPackets()) {
for (PacketContainer packet : packets) {
if (packet.getType() != Server.PLAYER_INFO) {
if (packet.equals(event.getPacket())) {
packet = packet.shallowClone();
}
packet.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
}
}
}
transformed.sendDelayed(observer); transformed.sendDelayed(observer);
if (event.getPacketType() == Server.ENTITY_METADATA) if (event.getPacketType() == Server.ENTITY_METADATA) {
{
event.setPacket(event.getPacket().deepClone()); event.setPacket(event.getPacket().deepClone());
for (WrappedWatchableObject watch : event.getPacket().getWatchableCollectionModifier().read(0)) for (WrappedWatchableObject watch : event.getPacket().getWatchableCollectionModifier().read(0)) {
{ if (watch.getIndex() == 0) {
if (watch.getIndex() == 0)
{
byte b = (byte) watch.getValue(); byte b = (byte) watch.getValue();
byte a = (byte) (b | 1 << 5); byte a = (byte) (b | 1 << 5);
@ -113,8 +110,7 @@ public class PacketListenerViewDisguises extends PacketAdapter
} }
} }
} }
else if (event.getPacketType() == Server.NAMED_ENTITY_SPAWN) else if (event.getPacketType() == Server.NAMED_ENTITY_SPAWN) {
{
event.setCancelled(true); event.setCancelled(true);
PacketContainer packet = new PacketContainer(Server.ENTITY_METADATA); PacketContainer packet = new PacketContainer(Server.ENTITY_METADATA);
@ -134,40 +130,32 @@ public class PacketListenerViewDisguises extends PacketAdapter
watchableList.add(watch); watchableList.add(watch);
packet.getWatchableCollectionModifier().write(0, watchableList); packet.getWatchableCollectionModifier().write(0, watchableList);
try try {
{
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet); ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet);
} }
catch (InvocationTargetException e) catch (InvocationTargetException e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
else if (event.getPacketType() == Server.ANIMATION) else if (event.getPacketType() == Server.ANIMATION) {
{ if (event.getPacket().getIntegers().read(1) != 2) {
if (event.getPacket().getIntegers().read(1) != 2)
{
event.setCancelled(true); event.setCancelled(true);
} }
} }
else if (event.getPacketType() == Server.ATTACH_ENTITY || event.getPacketType() == Server.REL_ENTITY_MOVE else if (event.getPacketType() == Server.ATTACH_ENTITY || event.getPacketType() == Server.REL_ENTITY_MOVE
|| event.getPacketType() == Server.REL_ENTITY_MOVE_LOOK || event.getPacketType() == Server.ENTITY_LOOK || event.getPacketType() == Server.REL_ENTITY_MOVE_LOOK || event.getPacketType() == Server.ENTITY_LOOK
|| event.getPacketType() == Server.ENTITY_TELEPORT || event.getPacketType() == Server.ENTITY_HEAD_ROTATION || event.getPacketType() == Server.ENTITY_TELEPORT || event.getPacketType() == Server.ENTITY_HEAD_ROTATION
|| event.getPacketType() == Server.ENTITY_EFFECT || event.getPacketType() == Server.ENTITY_EQUIPMENT) || event.getPacketType() == Server.ENTITY_EFFECT || event.getPacketType() == Server.ENTITY_EQUIPMENT) {
{
event.setCancelled(true); event.setCancelled(true);
} }
else if (event.getPacketType() == Server.ENTITY_STATUS) else if (event.getPacketType() == Server.ENTITY_STATUS) {
{
if (disguise.isSelfDisguiseSoundsReplaced() && !disguise.getType().isPlayer() if (disguise.isSelfDisguiseSoundsReplaced() && !disguise.getType().isPlayer()
&& event.getPacket().getBytes().read(0) == 2) && event.getPacket().getBytes().read(0) == 2) {
{
event.setCancelled(true); event.setCancelled(true);
} }
} }
} }
catch (Exception ex) catch (Exception ex) {
{
event.setCancelled(true); event.setCancelled(true);
ex.printStackTrace(); ex.printStackTrace();
} }