Fix disguises and stuff
This commit is contained in:
parent
401061bbcd
commit
126a7a4a6a
@ -225,7 +225,7 @@ public class LibsDisguises extends JavaPlugin {
|
||||
case ZOMBIE_VILLAGER:
|
||||
case DONKEY:
|
||||
case MULE:
|
||||
case UNDEAD_HORSE:
|
||||
case ZOMBIE_HORSE:
|
||||
case SKELETON_HORSE:
|
||||
case STRAY:
|
||||
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!");
|
||||
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());
|
||||
|
@ -13,8 +13,6 @@ import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
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.util.Vector;
|
||||
|
||||
@ -29,8 +27,6 @@ import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
||||
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.events.DisguiseEvent;
|
||||
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;
|
||||
|
||||
switch (getType()) {
|
||||
|
@ -3,11 +3,6 @@ package me.libraryaddict.disguise.disguisetypes;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.entity.Entity;
|
||||
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 {
|
||||
AREA_EFFECT_CLOUD(3, 0),
|
||||
@ -154,9 +149,9 @@ public enum DisguiseType {
|
||||
|
||||
THROWN_EXP_BOTTLE(75),
|
||||
|
||||
TIPPED_ARROW(92),
|
||||
TIPPED_ARROW(60),
|
||||
|
||||
UNDEAD_HORSE,
|
||||
ZOMBIE_HORSE,
|
||||
|
||||
UNKNOWN,
|
||||
|
||||
@ -190,7 +185,7 @@ public enum DisguiseType {
|
||||
DisguiseType toUse = type;
|
||||
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..
|
||||
// Usable.
|
||||
case ITEM_FRAME:
|
||||
@ -199,16 +194,9 @@ public enum DisguiseType {
|
||||
case HUSK:
|
||||
toUse = DisguiseType.ZOMBIE;
|
||||
break;
|
||||
case WITHER_SKELETON:
|
||||
case STRAY:
|
||||
toUse = DisguiseType.SKELETON;
|
||||
break;
|
||||
case ELDER_GUARDIAN:
|
||||
toUse = DisguiseType.GUARDIAN;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
|
||||
name = toUse.name();
|
||||
|
||||
@ -223,39 +211,6 @@ public enum DisguiseType {
|
||||
public static DisguiseType getType(Entity entity) {
|
||||
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;
|
||||
|
||||
}
|
||||
|
@ -64,6 +64,7 @@ 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.ZombieVillagerWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
||||
|
||||
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<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());
|
||||
|
||||
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<Optional<ItemStack>> DROPPED_ITEM = new FlagType<Optional<ItemStack>>(DroppedItemWatcher.class, 0,
|
||||
Optional.<ItemStack> of(new ItemStack(Material.STONE)));
|
||||
public static FlagType<ItemStack> DROPPED_ITEM = new FlagType<ItemStack>(DroppedItemWatcher.class, 0,
|
||||
new ItemStack(Material.STONE));
|
||||
|
||||
public static FlagType<Optional<BlockPosition>> ENDER_CRYSTAL_BEAM = new FlagType<Optional<BlockPosition>>(
|
||||
EnderCrystalWatcher.class, 0, Optional.<BlockPosition> absent());
|
||||
|
||||
public static FlagType<Boolean> ENDER_CRYSTAL_PLATE = new FlagType<Boolean>(EnderCrystalWatcher.class, 1, false);
|
||||
|
||||
public static FlagType<Integer> ENDERDRAGON_PHASE = new FlagType<Integer>(EnderDragonWatcher.class, 0, 0);
|
||||
public static FlagType<Integer> ENDERD_RAGON_PHASE = new FlagType<Integer>(EnderDragonWatcher.class, 0, 0);
|
||||
|
||||
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,
|
||||
BlockPosition.ORIGIN);
|
||||
|
||||
public static FlagType<Optional<ItemStack>> FIREWORK_ITEM = new FlagType<Optional<ItemStack>>(FireworkWatcher.class, 0,
|
||||
Optional.<ItemStack> absent());
|
||||
public static FlagType<ItemStack> FIREWORK_ITEM = new FlagType<ItemStack>(FireworkWatcher.class, 0,
|
||||
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<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);
|
||||
|
||||
@ -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<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,
|
||||
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<Optional<ItemStack>> ITEMFRAME_ITEM = new FlagType<Optional<ItemStack>>(ItemFrameWatcher.class, 0,
|
||||
Optional.<ItemStack> absent());
|
||||
public static FlagType<ItemStack> ITEMFRAME_ITEM = new FlagType<ItemStack>(ItemFrameWatcher.class, 0,
|
||||
new ItemStack(Material.AIR));
|
||||
|
||||
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<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<Boolean> SKELETON_SWING_ARMS = new FlagType<Boolean>(SkeletonWatcher.class, 0, false);
|
||||
|
||||
public static FlagType<Integer> SLIME_SIZE = new FlagType<Integer>(SlimeWatcher.class, 0, 0);
|
||||
|
||||
@ -256,12 +255,12 @@ public class FlagType<Y> {
|
||||
|
||||
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
|
||||
public static FlagType<ItemStack> SPLASH_POTION_ITEM = new FlagType<ItemStack>(SplashPotionWatcher.class, 1,
|
||||
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
|
||||
public static FlagType<ItemStack> SPLASH_POTION_ITEM_BAD = new FlagType<ItemStack>(SplashPotionWatcher.class, 0,
|
||||
new ItemStack(Material.SPLASH_POTION)); // Yeah, the '1' isn't a bug. No
|
||||
// idea why but MC thinks there's a
|
||||
// '0' already.
|
||||
|
||||
@ -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<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);
|
||||
|
||||
@ -298,13 +297,13 @@ public class FlagType<Y> {
|
||||
|
||||
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<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 {
|
||||
for (FlagType flagType : values()) {
|
||||
|
@ -26,8 +26,7 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.PacketsManager;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
|
||||
public class FlagWatcher
|
||||
{
|
||||
public class FlagWatcher {
|
||||
private boolean _addEntityAnimations = DisguiseConfig.isEntityAnimationsAdded();
|
||||
/**
|
||||
* 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 List<WrappedWatchableObject> _watchableObjects;
|
||||
|
||||
public FlagWatcher(Disguise disguise)
|
||||
{
|
||||
public FlagWatcher(Disguise disguise) {
|
||||
_disguise = (TargetedDisguise) disguise;
|
||||
_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;
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if ((entityValue & 1 << i) != 0 && !_modifiedEntityAnimations.contains(i))
|
||||
{
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if ((entityValue & 1 << i) != 0 && !_modifiedEntityAnimations.contains(i)) {
|
||||
valueByte = (byte) (valueByte | 1 << i);
|
||||
}
|
||||
}
|
||||
@ -63,16 +60,13 @@ public class FlagWatcher
|
||||
return originalValue;
|
||||
}
|
||||
|
||||
public FlagWatcher clone(Disguise owningDisguise)
|
||||
{
|
||||
public FlagWatcher clone(Disguise owningDisguise) {
|
||||
FlagWatcher cloned;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
cloned = getClass().getConstructor(Disguise.class).newInstance(getDisguise());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
cloned = new FlagWatcher(getDisguise());
|
||||
}
|
||||
@ -85,49 +79,40 @@ public class FlagWatcher
|
||||
return cloned;
|
||||
}
|
||||
|
||||
public List<WrappedWatchableObject> convert(List<WrappedWatchableObject> list)
|
||||
{
|
||||
public List<WrappedWatchableObject> convert(List<WrappedWatchableObject> list) {
|
||||
List<WrappedWatchableObject> newList = new ArrayList<>();
|
||||
HashSet<Integer> sentValues = new HashSet<>();
|
||||
boolean sendAllCustom = false;
|
||||
|
||||
for (WrappedWatchableObject watch : list)
|
||||
{
|
||||
for (WrappedWatchableObject watch : list) {
|
||||
int id = watch.getIndex();
|
||||
sentValues.add(id);
|
||||
|
||||
// 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!
|
||||
if (id == 1)
|
||||
{
|
||||
if (id == 1) {
|
||||
sendAllCustom = true;
|
||||
}
|
||||
|
||||
Object value = null;
|
||||
|
||||
if (_entityValues.containsKey(id))
|
||||
{
|
||||
if (_entityValues.get(id) == null)
|
||||
{
|
||||
if (_entityValues.containsKey(id)) {
|
||||
if (_entityValues.get(id) == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
value = _entityValues.get(id);
|
||||
}
|
||||
else if (_backupEntityValues.containsKey(id))
|
||||
{
|
||||
if (_backupEntityValues.get(id) == null)
|
||||
{
|
||||
else if (_backupEntityValues.containsKey(id)) {
|
||||
if (_backupEntityValues.get(id) == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
value = _backupEntityValues.get(id);
|
||||
}
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
if (isEntityAnimationsAdded() && id == 0)
|
||||
{
|
||||
if (value != null) {
|
||||
if (isEntityAnimationsAdded() && id == 0) {
|
||||
value = addEntityAnimations((byte) value, (byte) watch.getValue());
|
||||
}
|
||||
|
||||
@ -138,13 +123,11 @@ public class FlagWatcher
|
||||
if (watch == null)
|
||||
continue;
|
||||
|
||||
if (!isDirty)
|
||||
{
|
||||
if (!isDirty) {
|
||||
watch.setDirtyState(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
boolean isDirty = watch.getDirtyState();
|
||||
|
||||
watch = ReflectionManager.createWatchable(id, watch.getValue());
|
||||
@ -152,8 +135,7 @@ public class FlagWatcher
|
||||
if (watch == null)
|
||||
continue;
|
||||
|
||||
if (!isDirty)
|
||||
{
|
||||
if (!isDirty) {
|
||||
watch.setDirtyState(false);
|
||||
}
|
||||
}
|
||||
@ -161,20 +143,16 @@ public class FlagWatcher
|
||||
newList.add(watch);
|
||||
}
|
||||
|
||||
if (sendAllCustom)
|
||||
{
|
||||
if (sendAllCustom) {
|
||||
// Its sending the entire meta data. Better add the custom meta
|
||||
for (Integer id : _entityValues.keySet())
|
||||
{
|
||||
if (sentValues.contains(id))
|
||||
{
|
||||
for (Integer id : _entityValues.keySet()) {
|
||||
if (sentValues.contains(id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Object value = _entityValues.get(id);
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -188,41 +166,31 @@ public class FlagWatcher
|
||||
}
|
||||
// Here we check for if there is a health packet that says they died.
|
||||
if (getDisguise().isSelfDisguiseVisible() && getDisguise().getEntity() != null
|
||||
&& getDisguise().getEntity() instanceof Player)
|
||||
{
|
||||
for (WrappedWatchableObject watch : newList)
|
||||
{
|
||||
&& getDisguise().getEntity() instanceof Player) {
|
||||
for (WrappedWatchableObject watch : newList) {
|
||||
// Its a health packet
|
||||
if (watch.getIndex() == 6)
|
||||
{
|
||||
if (watch.getIndex() == 6) {
|
||||
Object value = watch.getValue();
|
||||
|
||||
if (value != null && value instanceof Float)
|
||||
{
|
||||
if (value != null && value instanceof Float) {
|
||||
float newHealth = (Float) value;
|
||||
|
||||
if (newHealth > 0 && _hasDied)
|
||||
{
|
||||
if (newHealth > 0 && _hasDied) {
|
||||
_hasDied = false;
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(DisguiseUtilities.getPlugin(), new Runnable()
|
||||
{
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(DisguiseUtilities.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
public void run() {
|
||||
try {
|
||||
DisguiseUtilities.sendSelfDisguise((Player) getDisguise().getEntity(), _disguise);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, 2);
|
||||
}
|
||||
else if (newHealth <= 0 && !_hasDied)
|
||||
{
|
||||
else if (newHealth <= 0 && !_hasDied) {
|
||||
_hasDied = true;
|
||||
}
|
||||
}
|
||||
@ -233,57 +201,48 @@ public class FlagWatcher
|
||||
return newList;
|
||||
}
|
||||
|
||||
public ItemStack[] getArmor()
|
||||
{
|
||||
public ItemStack[] getArmor() {
|
||||
ItemStack[] armor = new ItemStack[4];
|
||||
System.arraycopy(armor, 0, armor, 0, 4);
|
||||
|
||||
return armor;
|
||||
}
|
||||
|
||||
public String getCustomName()
|
||||
{
|
||||
public String getCustomName() {
|
||||
return (String) getData(FlagType.ENTITY_CUSTOM_NAME);
|
||||
}
|
||||
|
||||
protected TargetedDisguise getDisguise()
|
||||
{
|
||||
protected TargetedDisguise getDisguise() {
|
||||
return _disguise;
|
||||
}
|
||||
|
||||
private boolean getEntityFlag(int byteValue)
|
||||
{
|
||||
private boolean getEntityFlag(int byteValue) {
|
||||
return (getData(FlagType.ENTITY_META) & 1 << byteValue) != 0;
|
||||
}
|
||||
|
||||
public EntityEquipment getEquipment()
|
||||
{
|
||||
public EntityEquipment getEquipment() {
|
||||
return _equipment;
|
||||
}
|
||||
|
||||
public ItemStack getItemInMainHand()
|
||||
{
|
||||
public ItemStack getItemInMainHand() {
|
||||
if (_equipment == null)
|
||||
return null;
|
||||
|
||||
return _equipment.getItemInMainHand();
|
||||
}
|
||||
|
||||
public ItemStack getItemInOffHand()
|
||||
{
|
||||
public ItemStack getItemInOffHand() {
|
||||
if (_equipment == null)
|
||||
return null;
|
||||
|
||||
return _equipment.getItemInOffHand();
|
||||
}
|
||||
|
||||
public ItemStack getItemStack(EquipmentSlot slot)
|
||||
{
|
||||
public ItemStack getItemStack(EquipmentSlot slot) {
|
||||
if (_equipment == null)
|
||||
return null;
|
||||
|
||||
switch (slot)
|
||||
{
|
||||
switch (slot) {
|
||||
case CHEST:
|
||||
return _equipment.getChestplate();
|
||||
case FEET:
|
||||
@ -301,104 +260,83 @@ public class FlagWatcher
|
||||
return null;
|
||||
}
|
||||
|
||||
protected <Y> Y getData(FlagType<Y> flagType)
|
||||
{
|
||||
if (_entityValues.containsKey(flagType.getIndex()))
|
||||
{
|
||||
protected <Y> Y getData(FlagType<Y> flagType) {
|
||||
if (_entityValues.containsKey(flagType.getIndex())) {
|
||||
return (Y) _entityValues.get(flagType.getIndex());
|
||||
}
|
||||
|
||||
return flagType.getDefault();
|
||||
}
|
||||
|
||||
public List<WrappedWatchableObject> getWatchableObjects()
|
||||
{
|
||||
if (_watchableObjects == null)
|
||||
{
|
||||
public List<WrappedWatchableObject> getWatchableObjects() {
|
||||
if (_watchableObjects == null) {
|
||||
rebuildWatchableObjects();
|
||||
}
|
||||
|
||||
return _watchableObjects;
|
||||
}
|
||||
|
||||
public boolean hasCustomName()
|
||||
{
|
||||
public boolean hasCustomName() {
|
||||
return getCustomName() != null;
|
||||
}
|
||||
|
||||
protected boolean hasValue(FlagType no)
|
||||
{
|
||||
protected boolean hasValue(FlagType no) {
|
||||
return _entityValues.containsKey(no.getIndex());
|
||||
}
|
||||
|
||||
public boolean isBurning()
|
||||
{
|
||||
public boolean isBurning() {
|
||||
return getEntityFlag(0);
|
||||
}
|
||||
|
||||
public boolean isCustomNameVisible()
|
||||
{
|
||||
public boolean isCustomNameVisible() {
|
||||
return getData(FlagType.ENTITY_CUSTOM_NAME_VISIBLE);
|
||||
}
|
||||
|
||||
public boolean isEntityAnimationsAdded()
|
||||
{
|
||||
public boolean isEntityAnimationsAdded() {
|
||||
return _addEntityAnimations;
|
||||
}
|
||||
|
||||
public boolean isFlyingWithElytra()
|
||||
{
|
||||
public boolean isFlyingWithElytra() {
|
||||
return getEntityFlag(7);
|
||||
}
|
||||
|
||||
public boolean isGlowing()
|
||||
{
|
||||
public boolean isGlowing() {
|
||||
return getEntityFlag(6);
|
||||
}
|
||||
|
||||
public boolean isInvisible()
|
||||
{
|
||||
public boolean isInvisible() {
|
||||
return getEntityFlag(5);
|
||||
}
|
||||
|
||||
public boolean isNoGravity()
|
||||
{
|
||||
public boolean isNoGravity() {
|
||||
return getData(FlagType.ENTITY_NO_GRAVITY);
|
||||
}
|
||||
|
||||
public boolean isRightClicking()
|
||||
{
|
||||
public boolean isRightClicking() {
|
||||
return getEntityFlag(4);
|
||||
}
|
||||
|
||||
public boolean isSneaking()
|
||||
{
|
||||
public boolean isSneaking() {
|
||||
return getEntityFlag(1);
|
||||
}
|
||||
|
||||
public boolean isSprinting()
|
||||
{
|
||||
public boolean isSprinting() {
|
||||
return getEntityFlag(3);
|
||||
}
|
||||
|
||||
public void rebuildWatchableObjects()
|
||||
{
|
||||
public void rebuildWatchableObjects() {
|
||||
_watchableObjects = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i <= 31; i++)
|
||||
{
|
||||
for (int i = 0; i <= 31; i++) {
|
||||
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));
|
||||
}
|
||||
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));
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -409,28 +347,22 @@ public class FlagWatcher
|
||||
}
|
||||
}
|
||||
|
||||
protected void sendData(FlagType... dataValues)
|
||||
{
|
||||
if (!DisguiseAPI.isDisguiseInUse(getDisguise()) || getDisguise().getWatcher() != this)
|
||||
{
|
||||
protected void sendData(FlagType... dataValues) {
|
||||
if (!DisguiseAPI.isDisguiseInUse(getDisguise()) || getDisguise().getWatcher() != this) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<WrappedWatchableObject> list = new ArrayList<>();
|
||||
|
||||
for (FlagType data : dataValues)
|
||||
{
|
||||
if (!_entityValues.containsKey(data.getIndex()) || _entityValues.get(data.getIndex()) == null)
|
||||
{
|
||||
for (FlagType data : dataValues) {
|
||||
if (!_entityValues.containsKey(data.getIndex()) || _entityValues.get(data.getIndex()) == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Object value = _entityValues.get(data.getIndex());
|
||||
|
||||
if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == FlagType.ENTITY_META)
|
||||
{
|
||||
if (!PacketsManager.isStaticMetadataDisguiseType(_disguise))
|
||||
{
|
||||
if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == FlagType.ENTITY_META) {
|
||||
if (!PacketsManager.isStaticMetadataDisguiseType(_disguise)) {
|
||||
value = addEntityAnimations((byte) value,
|
||||
WrappedDataWatcher.getEntityWatcher(_disguise.getEntity()).getByte(0));
|
||||
}
|
||||
@ -444,8 +376,7 @@ public class FlagWatcher
|
||||
list.add(watch);
|
||||
}
|
||||
|
||||
if (!list.isEmpty())
|
||||
{
|
||||
if (!list.isEmpty()) {
|
||||
PacketContainer packet = new PacketContainer(Server.ENTITY_METADATA);
|
||||
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
@ -453,59 +384,48 @@ public class FlagWatcher
|
||||
|
||||
packet.getWatchableCollectionModifier().write(0, list);
|
||||
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise()))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (player == getDisguise().getEntity())
|
||||
{
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
|
||||
try {
|
||||
if (player == getDisguise().getEntity()) {
|
||||
PacketContainer temp = packet.shallowClone();
|
||||
temp.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, temp);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
}
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setAddEntityAnimations(boolean isEntityAnimationsAdded)
|
||||
{
|
||||
public void setAddEntityAnimations(boolean isEntityAnimationsAdded) {
|
||||
_addEntityAnimations = isEntityAnimationsAdded;
|
||||
}
|
||||
|
||||
public void setArmor(ItemStack[] itemstack)
|
||||
{
|
||||
public void setArmor(ItemStack[] itemstack) {
|
||||
setItemStack(EquipmentSlot.HEAD, itemstack[0]);
|
||||
setItemStack(EquipmentSlot.CHEST, itemstack[1]);
|
||||
setItemStack(EquipmentSlot.LEGS, itemstack[2]);
|
||||
setItemStack(EquipmentSlot.FEET, itemstack[3]);
|
||||
}
|
||||
|
||||
protected void setBackupValue(FlagType no, Object value)
|
||||
{
|
||||
protected void setBackupValue(FlagType no, Object value) {
|
||||
_backupEntityValues.put(no.getIndex(), value);
|
||||
}
|
||||
|
||||
public void setBurning(boolean setBurning)
|
||||
{
|
||||
public void setBurning(boolean setBurning) {
|
||||
setEntityFlag(0, setBurning);
|
||||
|
||||
sendData(FlagType.ENTITY_META);
|
||||
}
|
||||
|
||||
public void setCustomName(String name)
|
||||
{
|
||||
if (name != null && name.length() > 64)
|
||||
{
|
||||
public void setCustomName(String name) {
|
||||
if (name != null && name.length() > 64) {
|
||||
name = name.substring(0, 64);
|
||||
}
|
||||
|
||||
@ -513,42 +433,35 @@ public class FlagWatcher
|
||||
sendData(FlagType.ENTITY_CUSTOM_NAME);
|
||||
}
|
||||
|
||||
public void setCustomNameVisible(boolean display)
|
||||
{
|
||||
public void setCustomNameVisible(boolean display) {
|
||||
setData(FlagType.ENTITY_CUSTOM_NAME_VISIBLE, display);
|
||||
sendData(FlagType.ENTITY_CUSTOM_NAME_VISIBLE);
|
||||
}
|
||||
|
||||
private void setEntityFlag(int byteValue, boolean flag)
|
||||
{
|
||||
private void setEntityFlag(int byteValue, boolean flag) {
|
||||
_modifiedEntityAnimations.add(byteValue);
|
||||
|
||||
byte b0 = (byte) getData(FlagType.ENTITY_META);
|
||||
|
||||
if (flag)
|
||||
{
|
||||
if (flag) {
|
||||
setData(FlagType.ENTITY_META, (byte) (b0 | 1 << byteValue));
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
setData(FlagType.ENTITY_META, (byte) (b0 & ~(1 << byteValue)));
|
||||
}
|
||||
}
|
||||
|
||||
public void setFlyingWithElytra(boolean flying)
|
||||
{
|
||||
public void setFlyingWithElytra(boolean flying) {
|
||||
setEntityFlag(7, flying);
|
||||
sendData(FlagType.ENTITY_META);
|
||||
}
|
||||
|
||||
public void setGlowing(boolean glowing)
|
||||
{
|
||||
public void setGlowing(boolean glowing) {
|
||||
setEntityFlag(6, glowing);
|
||||
sendData(FlagType.ENTITY_META);
|
||||
}
|
||||
|
||||
public void setInvisible(boolean setInvis)
|
||||
{
|
||||
public void setInvisible(boolean setInvis) {
|
||||
setEntityFlag(5, setInvis);
|
||||
sendData(FlagType.ENTITY_META);
|
||||
}
|
||||
@ -559,28 +472,23 @@ public class FlagWatcher
|
||||
* @param itemstack
|
||||
*/
|
||||
@Deprecated
|
||||
public void setItemInHand(ItemStack itemstack)
|
||||
{
|
||||
public void setItemInHand(ItemStack itemstack) {
|
||||
setItemInMainHand(itemstack);
|
||||
}
|
||||
|
||||
public void setItemInMainHand(ItemStack itemstack)
|
||||
{
|
||||
public void setItemInMainHand(ItemStack itemstack) {
|
||||
setItemStack(EquipmentSlot.HAND, itemstack);
|
||||
}
|
||||
|
||||
public void setItemInOffHand(ItemStack itemstack)
|
||||
{
|
||||
public void setItemInOffHand(ItemStack 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)
|
||||
return;
|
||||
|
||||
switch (slot)
|
||||
{
|
||||
switch (slot) {
|
||||
case CHEST:
|
||||
equipment.setChestplate(itemStack);
|
||||
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)
|
||||
return;
|
||||
|
||||
// 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
|
||||
if (getDisguise().getEntity() instanceof LivingEntity)
|
||||
{
|
||||
if (getDisguise().getEntity() instanceof LivingEntity) {
|
||||
EntityEquipment equipment = ((LivingEntity) getDisguise().getEntity()).getEquipment();
|
||||
setItemStack(equipment, slot, itemStack);
|
||||
}
|
||||
@ -620,15 +525,13 @@ public class FlagWatcher
|
||||
|
||||
Object itemToSend = null;
|
||||
|
||||
if (itemStack != null && itemStack.getTypeId() != 0)
|
||||
{
|
||||
if (itemStack != null && itemStack.getTypeId() != 0) {
|
||||
itemToSend = ReflectionManager.getNmsItem(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);
|
||||
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
@ -637,50 +540,44 @@ public class FlagWatcher
|
||||
mods.write(1, ReflectionManager.createEnumItemSlot(slot));
|
||||
mods.write(2, itemToSend);
|
||||
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise()))
|
||||
{
|
||||
try
|
||||
{
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setNoGravity(boolean noGravity)
|
||||
{
|
||||
public void setNoGravity(boolean noGravity) {
|
||||
setData(FlagType.ENTITY_NO_GRAVITY, noGravity);
|
||||
sendData(FlagType.ENTITY_NO_GRAVITY);
|
||||
}
|
||||
|
||||
public void setRightClicking(boolean setRightClicking)
|
||||
{
|
||||
public void setRightClicking(boolean setRightClicking) {
|
||||
setEntityFlag(4, setRightClicking);
|
||||
sendData(FlagType.ENTITY_META);
|
||||
}
|
||||
|
||||
public void setSneaking(boolean setSneaking)
|
||||
{
|
||||
public void setSneaking(boolean setSneaking) {
|
||||
setEntityFlag(1, setSneaking);
|
||||
sendData(FlagType.ENTITY_META);
|
||||
}
|
||||
|
||||
public void setSprinting(boolean setSprinting)
|
||||
{
|
||||
public void setSprinting(boolean setSprinting) {
|
||||
setEntityFlag(3, setSprinting);
|
||||
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);
|
||||
|
||||
if (!DisguiseConfig.isMetadataPacketsEnabled())
|
||||
{
|
||||
if (!DisguiseConfig.isMetadataPacketsEnabled()) {
|
||||
rebuildWatchableObjects();
|
||||
}
|
||||
}
|
||||
|
@ -7,51 +7,43 @@ import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
/**
|
||||
* @author Navid
|
||||
*/
|
||||
public class AreaEffectCloudWatcher extends FlagWatcher
|
||||
{
|
||||
public class AreaEffectCloudWatcher extends FlagWatcher {
|
||||
|
||||
public AreaEffectCloudWatcher(Disguise disguise)
|
||||
{
|
||||
public AreaEffectCloudWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
|
||||
setRadius(1);
|
||||
}
|
||||
|
||||
public float getRadius()
|
||||
{
|
||||
public float getRadius() {
|
||||
return getData(FlagType.AREA_EFFECT_RADIUS);
|
||||
}
|
||||
|
||||
public int getColor()
|
||||
{
|
||||
return getData(FlagType.AREA_EFFECT_COLOR);
|
||||
public int getColor() {
|
||||
return getData(FlagType.AREA_EFFECT_CLOUD_COLOR);
|
||||
}
|
||||
|
||||
public boolean isIgnoreRadius()
|
||||
{
|
||||
public boolean isIgnoreRadius() {
|
||||
return getData(FlagType.AREA_EFFECT_IGNORE_RADIUS);
|
||||
}
|
||||
|
||||
public int getParticleId()
|
||||
{
|
||||
public int getParticleId() {
|
||||
return getData(FlagType.AREA_EFFECT_PARTICLE);
|
||||
}
|
||||
|
||||
public void setRadius(float radius)
|
||||
{
|
||||
public void setRadius(float radius) {
|
||||
setData(FlagType.AREA_EFFECT_RADIUS, radius);
|
||||
}
|
||||
|
||||
public void setColor(int color)
|
||||
{
|
||||
setData(FlagType.AREA_EFFECT_COLOR, color);
|
||||
public void setColor(int color) {
|
||||
setData(FlagType.AREA_EFFECT_CLOUD_COLOR, color);
|
||||
}
|
||||
|
||||
public void setIgnoreRadius(boolean ignore)
|
||||
{
|
||||
public void setIgnoreRadius(boolean ignore) {
|
||||
setData(FlagType.AREA_EFFECT_IGNORE_RADIUS, ignore);
|
||||
}
|
||||
|
||||
public void setParticleId(int particleId)
|
||||
{
|
||||
public void setParticleId(int particleId) {
|
||||
setData(FlagType.AREA_EFFECT_PARTICLE, particleId);
|
||||
}
|
||||
|
||||
|
@ -2,27 +2,21 @@ 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;
|
||||
|
||||
public class DroppedItemWatcher extends FlagWatcher
|
||||
{
|
||||
public DroppedItemWatcher(Disguise disguise)
|
||||
{
|
||||
public class DroppedItemWatcher extends FlagWatcher {
|
||||
public DroppedItemWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return getData(FlagType.DROPPED_ITEM).get();
|
||||
public ItemStack getItemStack() {
|
||||
return getData(FlagType.DROPPED_ITEM);
|
||||
}
|
||||
|
||||
public void setItemStack(ItemStack item)
|
||||
{
|
||||
setData(FlagType.DROPPED_ITEM, Optional.<ItemStack> of(item));
|
||||
public void setItemStack(ItemStack item) {
|
||||
setData(FlagType.DROPPED_ITEM, item);
|
||||
sendData(FlagType.DROPPED_ITEM);
|
||||
}
|
||||
}
|
||||
|
@ -16,12 +16,12 @@ public class EnderDragonWatcher extends InsentientWatcher
|
||||
|
||||
public int getPhase()
|
||||
{
|
||||
return getData(FlagType.ENDERDRAGON_PHASE);
|
||||
return getData(FlagType.ENDERD_RAGON_PHASE);
|
||||
}
|
||||
|
||||
public void setPhase(int phase)
|
||||
{
|
||||
setData(FlagType.ENDERDRAGON_PHASE, phase);
|
||||
sendData(FlagType.ENDERDRAGON_PHASE);
|
||||
setData(FlagType.ENDERD_RAGON_PHASE, phase);
|
||||
sendData(FlagType.ENDERD_RAGON_PHASE);
|
||||
}
|
||||
}
|
||||
|
@ -3,40 +3,32 @@ 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)
|
||||
{
|
||||
public class FireworkWatcher extends FlagWatcher {
|
||||
public FireworkWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public ItemStack getFirework()
|
||||
{
|
||||
if (getData(FlagType.FIREWORK_ITEM) == null)
|
||||
{
|
||||
public ItemStack getFirework() {
|
||||
if (getData(FlagType.FIREWORK_ITEM) == null) {
|
||||
return new ItemStack(Material.AIR);
|
||||
}
|
||||
|
||||
return (ItemStack) getData(FlagType.FIREWORK_ITEM).get();
|
||||
return (ItemStack) getData(FlagType.FIREWORK_ITEM);
|
||||
}
|
||||
|
||||
public void setFirework(ItemStack newItem)
|
||||
{
|
||||
if (newItem == null)
|
||||
{
|
||||
public void setFirework(ItemStack newItem) {
|
||||
if (newItem == null) {
|
||||
newItem = new ItemStack(Material.AIR);
|
||||
}
|
||||
|
||||
newItem = newItem.clone();
|
||||
newItem.setAmount(1);
|
||||
|
||||
setData(FlagType.FIREWORK_ITEM, Optional.<ItemStack> of(newItem));
|
||||
setData(FlagType.FIREWORK_ITEM, newItem);
|
||||
sendData(FlagType.FIREWORK_ITEM);
|
||||
}
|
||||
|
||||
|
@ -13,13 +13,13 @@ public class FishingHookWatcher extends FlagWatcher
|
||||
|
||||
public void setHooked(int hookedId)
|
||||
{
|
||||
setData(FlagType.FISHING_HOOK, hookedId + 1);
|
||||
sendData(FlagType.FISHING_HOOK);
|
||||
setData(FlagType.FISHING_HOOK_HOOKED, hookedId + 1);
|
||||
sendData(FlagType.FISHING_HOOK_HOOKED);
|
||||
}
|
||||
|
||||
public int getHooked()
|
||||
{
|
||||
int hooked = getData(FlagType.FISHING_HOOK);
|
||||
int hooked = getData(FlagType.FISHING_HOOK_HOOKED);
|
||||
|
||||
if (hooked > 0)
|
||||
hooked--;
|
||||
|
@ -7,11 +7,8 @@ import org.bukkit.entity.Player;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagType;
|
||||
|
||||
public class GuardianWatcher extends InsentientWatcher
|
||||
{
|
||||
|
||||
public GuardianWatcher(Disguise disguise)
|
||||
{
|
||||
public class GuardianWatcher extends InsentientWatcher {
|
||||
public GuardianWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
@ -20,8 +17,7 @@ public class GuardianWatcher extends InsentientWatcher
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isTarget()
|
||||
{
|
||||
public boolean isTarget() {
|
||||
return ((int) getData(FlagType.GUARDIAN_TARGET)) != 0;
|
||||
}
|
||||
|
||||
@ -30,14 +26,12 @@ public class GuardianWatcher extends InsentientWatcher
|
||||
*
|
||||
* @param entityId
|
||||
*/
|
||||
public void setTarget(int entityId)
|
||||
{
|
||||
public void setTarget(int entityId) {
|
||||
setData(FlagType.GUARDIAN_TARGET, entityId);
|
||||
sendData(FlagType.GUARDIAN_TARGET);
|
||||
}
|
||||
|
||||
public void setTarget(Entity entity)
|
||||
{
|
||||
public void setTarget(Entity entity) {
|
||||
setTarget(entity == null ? 0 : entity.getEntityId());
|
||||
}
|
||||
|
||||
@ -46,8 +40,7 @@ public class GuardianWatcher extends InsentientWatcher
|
||||
*
|
||||
* @param playername
|
||||
*/
|
||||
public void setTarget(String playername)
|
||||
{
|
||||
public void setTarget(String playername) {
|
||||
Player player = Bukkit.getPlayer(playername);
|
||||
|
||||
if (player == null)
|
||||
@ -57,45 +50,13 @@ public class GuardianWatcher extends InsentientWatcher
|
||||
sendData(FlagType.GUARDIAN_TARGET);
|
||||
}
|
||||
|
||||
public boolean isRetractingSpikes()
|
||||
{
|
||||
return isGuardianFlag(2);
|
||||
public boolean isRetractingSpikes() {
|
||||
return getData(FlagType.GUARDIAN_RETRACT_SPIKES);
|
||||
}
|
||||
|
||||
public void setRetractingSpikes(boolean isRetracting)
|
||||
{
|
||||
setGuardianFlag(2, isRetracting);
|
||||
}
|
||||
|
||||
public boolean isElder()
|
||||
{
|
||||
return isGuardianFlag(4);
|
||||
}
|
||||
|
||||
public void setElder(boolean isGuardian)
|
||||
{
|
||||
setGuardianFlag(4, isGuardian);
|
||||
}
|
||||
|
||||
protected boolean isGuardianFlag(int no)
|
||||
{
|
||||
return (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);
|
||||
public void setRetractingSpikes(boolean isRetracting) {
|
||||
setData(FlagType.GUARDIAN_RETRACT_SPIKES, isRetracting);
|
||||
sendData(FlagType.GUARDIAN_RETRACT_SPIKES);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,11 +10,11 @@ public class HorseChestedWatcher extends HorseAbstractWatcher {
|
||||
}
|
||||
|
||||
public void setCarryingChest(boolean carryingChest) {
|
||||
setData(FlagType.HORSE_CARRYING_CHEST, carryingChest);
|
||||
sendData(FlagType.HORSE_CARRYING_CHEST);
|
||||
setData(FlagType.HORSE_CHESTED_CARRYING_CHEST, carryingChest);
|
||||
sendData(FlagType.HORSE_CHESTED_CARRYING_CHEST);
|
||||
}
|
||||
|
||||
public boolean isCarryingChest() {
|
||||
return getData(FlagType.HORSE_CARRYING_CHEST);
|
||||
return getData(FlagType.HORSE_CHESTED_CARRYING_CHEST);
|
||||
}
|
||||
}
|
||||
|
@ -3,50 +3,40 @@ 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)
|
||||
{
|
||||
public class ItemFrameWatcher extends FlagWatcher {
|
||||
public ItemFrameWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public ItemStack getItem()
|
||||
{
|
||||
if (getData(FlagType.ITEMFRAME_ITEM) == null)
|
||||
{
|
||||
public ItemStack getItem() {
|
||||
if (getData(FlagType.ITEMFRAME_ITEM) == null) {
|
||||
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);
|
||||
}
|
||||
|
||||
public void setItem(ItemStack newItem)
|
||||
{
|
||||
if (newItem == null)
|
||||
{
|
||||
public void setItem(ItemStack newItem) {
|
||||
if (newItem == null) {
|
||||
newItem = new ItemStack(Material.AIR);
|
||||
}
|
||||
|
||||
newItem = newItem.clone();
|
||||
newItem.setAmount(1);
|
||||
|
||||
setData(FlagType.ITEMFRAME_ITEM, Optional.<ItemStack> of(newItem));
|
||||
setData(FlagType.ITEMFRAME_ITEM, newItem);
|
||||
sendData(FlagType.ITEMFRAME_ITEM);
|
||||
}
|
||||
|
||||
public void setRotation(int rotation)
|
||||
{
|
||||
public void setRotation(int rotation) {
|
||||
setData(FlagType.ITEMFRAME_ROTATION, rotation % 4);
|
||||
sendData(FlagType.ITEMFRAME_ROTATION);
|
||||
}
|
||||
|
@ -1,39 +1,22 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import org.bukkit.entity.Skeleton.SkeletonType;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagType;
|
||||
|
||||
/**
|
||||
* @author Navid
|
||||
*/
|
||||
public class SkeletonWatcher extends InsentientWatcher
|
||||
{
|
||||
public SkeletonWatcher(Disguise disguise)
|
||||
{
|
||||
public class SkeletonWatcher extends InsentientWatcher {
|
||||
public SkeletonWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public void setSwingArms(boolean swingingArms)
|
||||
{
|
||||
public void setSwingArms(boolean swingingArms) {
|
||||
setData(FlagType.SKELETON_SWING_ARMS, swingingArms);
|
||||
sendData(FlagType.SKELETON_SWING_ARMS);
|
||||
}
|
||||
|
||||
public boolean isSwingArms()
|
||||
{
|
||||
public boolean isSwingArms() {
|
||||
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)];
|
||||
}
|
||||
}
|
||||
|
@ -2,53 +2,43 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagType;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
|
||||
public class SplashPotionWatcher extends FlagWatcher
|
||||
{
|
||||
public class SplashPotionWatcher extends FlagWatcher {
|
||||
private int potionId;
|
||||
|
||||
public SplashPotionWatcher(Disguise disguise)
|
||||
{
|
||||
public SplashPotionWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SplashPotionWatcher clone(Disguise disguise)
|
||||
{
|
||||
public SplashPotionWatcher clone(Disguise disguise) {
|
||||
SplashPotionWatcher watcher = (SplashPotionWatcher) super.clone(disguise);
|
||||
watcher.setPotionId(getPotionId());
|
||||
|
||||
return watcher;
|
||||
}
|
||||
|
||||
public int getPotionId()
|
||||
{
|
||||
public int getPotionId() {
|
||||
return potionId;
|
||||
}
|
||||
|
||||
public void setSplashPotion(ItemStack item)
|
||||
{
|
||||
setData(FlagType.SPLASH_POTION_ITEM, Optional.of(item));
|
||||
public void setSplashPotion(ItemStack item) {
|
||||
setData(FlagType.SPLASH_POTION_ITEM, item);
|
||||
sendData(FlagType.SPLASH_POTION_ITEM);
|
||||
}
|
||||
|
||||
public ItemStack getSplashPotion()
|
||||
{
|
||||
return getData(FlagType.SPLASH_POTION_ITEM).get();
|
||||
public ItemStack getSplashPotion() {
|
||||
return getData(FlagType.SPLASH_POTION_ITEM);
|
||||
}
|
||||
|
||||
public void setPotionId(int newPotionId)
|
||||
{
|
||||
public void setPotionId(int newPotionId) {
|
||||
this.potionId = newPotionId;
|
||||
|
||||
if (getDisguise().getEntity() != null && getDisguise().getWatcher() == this)
|
||||
{
|
||||
if (getDisguise().getEntity() != null && getDisguise().getWatcher() == this) {
|
||||
DisguiseUtilities.refreshTrackers(getDisguise());
|
||||
}
|
||||
}
|
||||
|
@ -14,13 +14,13 @@ public class WitherSkullWatcher extends FlagWatcher
|
||||
|
||||
public boolean isBlue()
|
||||
{
|
||||
return (boolean) getData(FlagType.WITHERSKULL_BLUE);
|
||||
return (boolean) getData(FlagType.WITHER_SKULL_BLUE);
|
||||
}
|
||||
|
||||
public void setBlue(boolean blue)
|
||||
{
|
||||
setData(FlagType.WITHERSKULL_BLUE, blue);
|
||||
sendData(FlagType.WITHERSKULL_BLUE);
|
||||
setData(FlagType.WITHER_SKULL_BLUE, blue);
|
||||
sendData(FlagType.WITHER_SKULL_BLUE);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -1,104 +1,40 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import org.bukkit.entity.Villager.Profession;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagType;
|
||||
|
||||
public class ZombieWatcher extends InsentientWatcher
|
||||
{
|
||||
public class ZombieWatcher extends InsentientWatcher {
|
||||
|
||||
public ZombieWatcher(Disguise disguise)
|
||||
{
|
||||
public ZombieWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public boolean isAdult()
|
||||
{
|
||||
public boolean isAdult() {
|
||||
return !isBaby();
|
||||
}
|
||||
|
||||
public boolean isBaby()
|
||||
{
|
||||
public boolean isBaby() {
|
||||
return getData(FlagType.ZOMBIE_BABY);
|
||||
}
|
||||
|
||||
public boolean isShaking()
|
||||
{
|
||||
return getData(FlagType.ZOMBIE_SHAKING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this zombie a villager?
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isVillager()
|
||||
{
|
||||
return ((int) getData(FlagType.ZOMBIE_PROFESSION)) != 0;
|
||||
}
|
||||
|
||||
public boolean isAggressive()
|
||||
{
|
||||
public boolean isAggressive() {
|
||||
return (boolean) getData(FlagType.ZOMBIE_AGGRESSIVE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
public void setAdult() {
|
||||
setBaby(false);
|
||||
}
|
||||
|
||||
public void setBaby()
|
||||
{
|
||||
public void setBaby() {
|
||||
setBaby(true);
|
||||
}
|
||||
|
||||
public void setBaby(boolean baby)
|
||||
{
|
||||
public void setBaby(boolean baby) {
|
||||
setData(FlagType.ZOMBIE_BABY, baby);
|
||||
sendData(FlagType.ZOMBIE_BABY);
|
||||
}
|
||||
|
||||
public void setShaking(boolean shaking)
|
||||
{
|
||||
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)
|
||||
{
|
||||
public void setAggressive(boolean handsup) {
|
||||
setData(FlagType.ZOMBIE_AGGRESSIVE, handsup);
|
||||
sendData(FlagType.ZOMBIE_AGGRESSIVE);
|
||||
}
|
||||
|
@ -4,18 +4,15 @@ import java.util.HashMap;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
|
||||
public class DisguiseValues
|
||||
{
|
||||
public class DisguiseValues {
|
||||
|
||||
private static HashMap<DisguiseType, DisguiseValues> values = new HashMap<>();
|
||||
|
||||
public static DisguiseValues getDisguiseValues(DisguiseType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
public static DisguiseValues getDisguiseValues(DisguiseType type) {
|
||||
switch (type) {
|
||||
case DONKEY:
|
||||
case MULE:
|
||||
case UNDEAD_HORSE:
|
||||
case ZOMBIE_HORSE:
|
||||
case SKELETON_HORSE:
|
||||
type = DisguiseType.HORSE;
|
||||
break;
|
||||
@ -28,6 +25,7 @@ public class DisguiseValues
|
||||
type = DisguiseType.MINECART;
|
||||
break;
|
||||
case WITHER_SKELETON:
|
||||
case STRAY:
|
||||
type = DisguiseType.SKELETON;
|
||||
break;
|
||||
case ZOMBIE_VILLAGER:
|
||||
@ -39,8 +37,7 @@ public class DisguiseValues
|
||||
return values.get(type);
|
||||
}
|
||||
|
||||
public static Class getNmsEntityClass(DisguiseType type)
|
||||
{
|
||||
public static Class getNmsEntityClass(DisguiseType type) {
|
||||
return getDisguiseValues(type).getNmsEntityClass();
|
||||
}
|
||||
|
||||
@ -50,50 +47,41 @@ public class DisguiseValues
|
||||
private double maxHealth;
|
||||
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);
|
||||
nmsEntityClass = classType;
|
||||
this.maxHealth = maxHealth;
|
||||
}
|
||||
|
||||
public FakeBoundingBox getAdultBox()
|
||||
{
|
||||
public FakeBoundingBox getAdultBox() {
|
||||
return adultBox;
|
||||
}
|
||||
|
||||
public FakeBoundingBox getBabyBox()
|
||||
{
|
||||
public FakeBoundingBox getBabyBox() {
|
||||
return babyBox;
|
||||
}
|
||||
|
||||
public float[] getEntitySize()
|
||||
{
|
||||
public float[] getEntitySize() {
|
||||
return entitySize;
|
||||
}
|
||||
|
||||
public double getMaxHealth()
|
||||
{
|
||||
public double getMaxHealth() {
|
||||
return maxHealth;
|
||||
}
|
||||
|
||||
public Class getNmsEntityClass()
|
||||
{
|
||||
public Class getNmsEntityClass() {
|
||||
return nmsEntityClass;
|
||||
}
|
||||
|
||||
public void setAdultBox(FakeBoundingBox newBox)
|
||||
{
|
||||
public void setAdultBox(FakeBoundingBox newBox) {
|
||||
adultBox = newBox;
|
||||
}
|
||||
|
||||
public void setBabyBox(FakeBoundingBox newBox)
|
||||
{
|
||||
public void setBabyBox(FakeBoundingBox newBox) {
|
||||
babyBox = newBox;
|
||||
}
|
||||
|
||||
public void setEntitySize(float[] size)
|
||||
{
|
||||
public void setEntitySize(float[] size) {
|
||||
this.entitySize = size;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package me.libraryaddict.disguise.utilities;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
@ -104,6 +105,10 @@ public class PacketsManager {
|
||||
return packets;
|
||||
}
|
||||
|
||||
public Collection<ArrayList<PacketContainer>> getDelayedPackets() {
|
||||
return delayedPackets.values();
|
||||
}
|
||||
|
||||
public void sendDelayed(final Player observer) {
|
||||
for (final Entry<Integer, ArrayList<PacketContainer>> entry : delayedPackets.entrySet()) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
|
||||
@ -494,6 +499,16 @@ public class PacketsManager {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -778,7 +778,7 @@ public class ReflectionManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Object convertInvalidItem(Object value) {
|
||||
public static Object convertInvalidItem(Object value) {
|
||||
if (value instanceof Optional) {
|
||||
Optional opt = (Optional) value;
|
||||
|
||||
@ -787,10 +787,7 @@ public class ReflectionManager {
|
||||
|
||||
Object val = opt.get();
|
||||
|
||||
if (val instanceof ItemStack) {
|
||||
return Optional.of(getNmsItem((ItemStack) val));
|
||||
}
|
||||
else if (val instanceof BlockPosition) {
|
||||
if (val instanceof BlockPosition) {
|
||||
BlockPosition pos = (BlockPosition) val;
|
||||
|
||||
try {
|
||||
@ -840,6 +837,9 @@ public class ReflectionManager {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
else if (value instanceof ItemStack) {
|
||||
return getNmsItem((ItemStack) value);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
@ -871,8 +871,10 @@ public class ReflectionManager {
|
||||
}
|
||||
|
||||
if (serializer == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Unable to find Serializer for " + value + "! Are you running the latest version of ProtocolLib?");
|
||||
throw new IllegalArgumentException("Unable to find Serializer for " + value
|
||||
+ (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);
|
||||
|
@ -22,10 +22,8 @@ import me.libraryaddict.disguise.utilities.PacketsManager;
|
||||
import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
|
||||
public class PacketListenerViewDisguises extends PacketAdapter
|
||||
{
|
||||
public PacketListenerViewDisguises(LibsDisguises plugin)
|
||||
{
|
||||
public class PacketListenerViewDisguises extends PacketAdapter {
|
||||
public PacketListenerViewDisguises(LibsDisguises plugin) {
|
||||
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.ENTITY_METADATA, Server.ENTITY_EQUIPMENT, Server.ANIMATION, Server.BED, Server.ENTITY_EFFECT,
|
||||
@ -33,25 +31,21 @@ public class PacketListenerViewDisguises extends PacketAdapter
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketSending(final PacketEvent event)
|
||||
{
|
||||
public void onPacketSending(final PacketEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
final Player observer = event.getPlayer();
|
||||
|
||||
if (observer.getName().contains("UNKNOWN[")) // If the player is temporary
|
||||
return;
|
||||
|
||||
if (event.getPacket().getIntegers().read(0) != observer.getEntityId())
|
||||
{
|
||||
if (event.getPacket().getIntegers().read(0) != observer.getEntityId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!DisguiseAPI.isSelfDisguised(observer))
|
||||
{
|
||||
if (!DisguiseAPI.isSelfDisguised(observer)) {
|
||||
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.
|
||||
LibsPackets transformed = PacketsManager.transformPacket(event.getPacket(), disguise, observer, observer);
|
||||
|
||||
if (transformed.isUnhandled())
|
||||
{
|
||||
if (transformed.isUnhandled()) {
|
||||
transformed.getPackets().add(event.getPacket());
|
||||
}
|
||||
|
||||
transformed.setPacketType(event.getPacketType());
|
||||
|
||||
for (PacketContainer packet : transformed.getPackets())
|
||||
{
|
||||
if (packet.getType() != Server.PLAYER_INFO)
|
||||
{
|
||||
if (packet.equals(event.getPacket()))
|
||||
{
|
||||
for (PacketContainer packet : transformed.getPackets()) {
|
||||
if (packet.getType() != Server.PLAYER_INFO) {
|
||||
if (packet.equals(event.getPacket())) {
|
||||
packet = packet.shallowClone();
|
||||
}
|
||||
|
||||
packet.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
catch (InvocationTargetException e) {
|
||||
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);
|
||||
|
||||
if (event.getPacketType() == Server.ENTITY_METADATA)
|
||||
{
|
||||
if (event.getPacketType() == Server.ENTITY_METADATA) {
|
||||
event.setPacket(event.getPacket().deepClone());
|
||||
|
||||
for (WrappedWatchableObject watch : event.getPacket().getWatchableCollectionModifier().read(0))
|
||||
{
|
||||
if (watch.getIndex() == 0)
|
||||
{
|
||||
for (WrappedWatchableObject watch : event.getPacket().getWatchableCollectionModifier().read(0)) {
|
||||
if (watch.getIndex() == 0) {
|
||||
byte b = (byte) watch.getValue();
|
||||
|
||||
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);
|
||||
|
||||
PacketContainer packet = new PacketContainer(Server.ENTITY_METADATA);
|
||||
@ -134,40 +130,32 @@ public class PacketListenerViewDisguises extends PacketAdapter
|
||||
watchableList.add(watch);
|
||||
packet.getWatchableCollectionModifier().write(0, watchableList);
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet);
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else if (event.getPacketType() == Server.ANIMATION)
|
||||
{
|
||||
if (event.getPacket().getIntegers().read(1) != 2)
|
||||
{
|
||||
else if (event.getPacketType() == Server.ANIMATION) {
|
||||
if (event.getPacket().getIntegers().read(1) != 2) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
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.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);
|
||||
}
|
||||
else if (event.getPacketType() == Server.ENTITY_STATUS)
|
||||
{
|
||||
else if (event.getPacketType() == Server.ENTITY_STATUS) {
|
||||
if (disguise.isSelfDisguiseSoundsReplaced() && !disguise.getType().isPlayer()
|
||||
&& event.getPacket().getBytes().read(0) == 2)
|
||||
{
|
||||
&& event.getPacket().getBytes().read(0) == 2) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
catch (Exception ex) {
|
||||
event.setCancelled(true);
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user