Cleanup code, fix locations in packets being assumed pre-1.9
This commit is contained in:
parent
e0293227dd
commit
986dfe6246
@ -4,7 +4,6 @@ import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
@ -151,11 +150,7 @@ public class DisguiseAPI
|
||||
{
|
||||
if (toCast == float.class)
|
||||
{
|
||||
if (value instanceof Float)
|
||||
{
|
||||
value = value;
|
||||
}
|
||||
else
|
||||
if (!(value instanceof Float))
|
||||
{
|
||||
double d = (Double) value;
|
||||
value = (float) d;
|
||||
@ -267,7 +262,7 @@ public class DisguiseAPI
|
||||
}
|
||||
|
||||
/**
|
||||
* Disguise the next entity to spawn with this disguise. This may not work however if the entity doesn't actually spawn.
|
||||
* Disguise the next entity to spawn, this means you need to spawn an entity immediately after calling this.
|
||||
*
|
||||
* @param disguise
|
||||
* @return
|
||||
@ -288,6 +283,7 @@ public class DisguiseAPI
|
||||
{
|
||||
int id = ReflectionManager.getNmsField("Entity", "entityCount").getInt(null);
|
||||
DisguiseUtilities.addFutureDisguise(id, (TargetedDisguise) disguise);
|
||||
|
||||
return id;
|
||||
}
|
||||
catch (IllegalAccessException e)
|
||||
@ -423,18 +419,6 @@ public class DisguiseAPI
|
||||
return DisguiseUtilities.getDisguises(disguised.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID of a fake disguise for a entityplayer
|
||||
*
|
||||
* @param entityId
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public static int getFakeDisguise(UUID entityId)
|
||||
{
|
||||
return -10;
|
||||
}
|
||||
|
||||
public static int getSelfDisguiseId()
|
||||
{
|
||||
return -10;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -82,7 +82,7 @@ public abstract class Disguise
|
||||
if (newType.getEntityType() == null)
|
||||
{
|
||||
throw new RuntimeException("DisguiseType " + newType
|
||||
+ " was used in a futile attempt to construct a disguise, but this version of Spigot does not have that entity");
|
||||
+ " was used in a futile attempt to construct a disguise, but this Minecraft version does not have that entity");
|
||||
}
|
||||
|
||||
// Set the disguise type
|
||||
|
@ -1,389 +1,387 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
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),
|
||||
|
||||
ARMOR_STAND(78),
|
||||
|
||||
ARROW(60, 0),
|
||||
|
||||
BAT,
|
||||
|
||||
BLAZE,
|
||||
|
||||
BOAT(1),
|
||||
|
||||
CAVE_SPIDER,
|
||||
|
||||
CHICKEN,
|
||||
|
||||
COW,
|
||||
|
||||
CREEPER,
|
||||
|
||||
DONKEY,
|
||||
|
||||
DRAGON_FIREBALL(93),
|
||||
|
||||
DROPPED_ITEM(2, 1),
|
||||
|
||||
EGG(62),
|
||||
|
||||
ELDER_GUARDIAN,
|
||||
|
||||
ENDER_CRYSTAL(51),
|
||||
|
||||
ENDER_DRAGON,
|
||||
|
||||
ENDER_PEARL(65),
|
||||
|
||||
ENDER_SIGNAL(72),
|
||||
|
||||
ENDERMAN,
|
||||
|
||||
ENDERMITE,
|
||||
|
||||
EXPERIENCE_ORB,
|
||||
|
||||
FALLING_BLOCK(70, 1),
|
||||
|
||||
FIREBALL(63),
|
||||
|
||||
FIREWORK(76),
|
||||
|
||||
FISHING_HOOK(90),
|
||||
|
||||
GHAST,
|
||||
|
||||
GIANT,
|
||||
|
||||
GUARDIAN,
|
||||
|
||||
HORSE,
|
||||
|
||||
IRON_GOLEM,
|
||||
|
||||
ITEM_FRAME(71),
|
||||
|
||||
LEASH_HITCH(77),
|
||||
|
||||
MAGMA_CUBE,
|
||||
|
||||
MINECART(10),
|
||||
|
||||
MINECART_CHEST(10, 1),
|
||||
|
||||
MINECART_COMMAND(10, 6),
|
||||
|
||||
MINECART_FURNACE(10, 2),
|
||||
|
||||
MINECART_HOPPER(10, 5),
|
||||
|
||||
MINECART_MOB_SPAWNER(10, 4),
|
||||
|
||||
MINECART_TNT(10, 3),
|
||||
|
||||
MULE,
|
||||
|
||||
MUSHROOM_COW,
|
||||
|
||||
OCELOT,
|
||||
|
||||
PAINTING,
|
||||
|
||||
PIG,
|
||||
|
||||
PIG_ZOMBIE,
|
||||
|
||||
PLAYER,
|
||||
|
||||
PRIMED_TNT(50),
|
||||
|
||||
RABBIT,
|
||||
|
||||
SHEEP,
|
||||
|
||||
SHULKER,
|
||||
|
||||
SHULKER_BULLET(67),
|
||||
|
||||
SILVERFISH,
|
||||
|
||||
SKELETON,
|
||||
|
||||
SKELETON_HORSE,
|
||||
|
||||
SLIME,
|
||||
|
||||
SMALL_FIREBALL(63),
|
||||
|
||||
SNOWBALL(61),
|
||||
|
||||
SNOWMAN,
|
||||
|
||||
SPECTRAL_ARROW(91),
|
||||
|
||||
SPIDER,
|
||||
|
||||
SPLASH_POTION(73, 0),
|
||||
|
||||
SQUID,
|
||||
|
||||
TIPPED_ARROW(92),
|
||||
|
||||
THROWN_EXP_BOTTLE(75),
|
||||
|
||||
UNDEAD_HORSE,
|
||||
|
||||
VILLAGER,
|
||||
|
||||
WITCH,
|
||||
|
||||
WITHER,
|
||||
|
||||
WITHER_SKELETON,
|
||||
|
||||
WITHER_SKULL(66),
|
||||
|
||||
WOLF,
|
||||
|
||||
ZOMBIE,
|
||||
|
||||
ZOMBIE_VILLAGER,
|
||||
|
||||
UNKNOWN;
|
||||
|
||||
static
|
||||
{
|
||||
// We set the entity type in this so that we can safely ignore disguisetypes which don't exist in older versions of MC.
|
||||
// Without erroring up everything.
|
||||
|
||||
for (DisguiseType type : values())
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
DisguiseType toUse = type;
|
||||
String name;
|
||||
|
||||
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:
|
||||
break;
|
||||
case DONKEY:
|
||||
case MULE:
|
||||
case UNDEAD_HORSE:
|
||||
case SKELETON_HORSE:
|
||||
toUse = DisguiseType.HORSE;
|
||||
break;
|
||||
case ZOMBIE_VILLAGER:
|
||||
toUse = DisguiseType.ZOMBIE;
|
||||
break;
|
||||
case WITHER_SKELETON:
|
||||
toUse = DisguiseType.SKELETON;
|
||||
break;
|
||||
case ELDER_GUARDIAN:
|
||||
toUse = DisguiseType.GUARDIAN;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
name = toUse.name();
|
||||
|
||||
type.setEntityType(EntityType.valueOf(name));
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
// This version of Spigot doesn't have the disguise.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
public static DisguiseType getType(EntityType entityType)
|
||||
{
|
||||
try
|
||||
{
|
||||
return valueOf(entityType.name().toUpperCase());
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
return DisguiseType.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
private int objectId = -1, defaultData = 0;
|
||||
|
||||
private EntityType entityType;
|
||||
|
||||
private Class<? extends FlagWatcher> watcherClass;
|
||||
|
||||
DisguiseType(int... ints)
|
||||
{
|
||||
for (int i = 0; i < ints.length; i++)
|
||||
{
|
||||
int value = ints[i];
|
||||
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
objectId = value;
|
||||
|
||||
break;
|
||||
case 1:
|
||||
defaultData = value;
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getDefaultData()
|
||||
{
|
||||
return defaultData;
|
||||
}
|
||||
|
||||
public Class<? extends Entity> getEntityClass()
|
||||
{
|
||||
if (entityType != null)
|
||||
{
|
||||
return getEntityType().getEntityClass();
|
||||
}
|
||||
|
||||
return Entity.class;
|
||||
}
|
||||
|
||||
public EntityType getEntityType()
|
||||
{
|
||||
return entityType;
|
||||
}
|
||||
|
||||
/**
|
||||
* The TYPE id of this entity. Different from the Object Id send in spawn packets when spawning miscs.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getTypeId()
|
||||
{
|
||||
return (int) getEntityType().getTypeId();
|
||||
}
|
||||
|
||||
/**
|
||||
* The object type send in packets when spawning a misc entity. Otherwise, -1.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getObjectId()
|
||||
{
|
||||
return objectId;
|
||||
}
|
||||
|
||||
public Class getWatcherClass()
|
||||
{
|
||||
return watcherClass;
|
||||
}
|
||||
|
||||
public boolean isMisc()
|
||||
{
|
||||
return getEntityType() != null && !getEntityType().isAlive();
|
||||
}
|
||||
|
||||
public boolean isMob()
|
||||
{
|
||||
return getEntityType() != null && getEntityType().isAlive() && !isPlayer();
|
||||
}
|
||||
|
||||
public boolean isPlayer()
|
||||
{
|
||||
return this == DisguiseType.PLAYER;
|
||||
}
|
||||
|
||||
public boolean isUnknown()
|
||||
{
|
||||
return this == DisguiseType.UNKNOWN;
|
||||
}
|
||||
|
||||
private void setEntityType(EntityType entityType)
|
||||
{
|
||||
this.entityType = entityType;
|
||||
}
|
||||
|
||||
public void setWatcherClass(Class<? extends FlagWatcher> c)
|
||||
{
|
||||
watcherClass = c;
|
||||
}
|
||||
|
||||
public String toReadable()
|
||||
{
|
||||
String[] split = name().split("_");
|
||||
|
||||
for (int i = 0; i < split.length; i++)
|
||||
{
|
||||
split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase();
|
||||
}
|
||||
|
||||
return StringUtils.join(split, " ");
|
||||
}
|
||||
}
|
||||
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),
|
||||
|
||||
ARMOR_STAND(78),
|
||||
|
||||
ARROW(60, 0),
|
||||
|
||||
BAT,
|
||||
|
||||
BLAZE,
|
||||
|
||||
BOAT(1),
|
||||
|
||||
CAVE_SPIDER,
|
||||
|
||||
CHICKEN,
|
||||
|
||||
COW,
|
||||
|
||||
CREEPER,
|
||||
|
||||
DONKEY,
|
||||
|
||||
DRAGON_FIREBALL(93),
|
||||
|
||||
DROPPED_ITEM(2, 1),
|
||||
|
||||
EGG(62),
|
||||
|
||||
ELDER_GUARDIAN,
|
||||
|
||||
ENDER_CRYSTAL(51),
|
||||
|
||||
ENDER_DRAGON,
|
||||
|
||||
ENDER_PEARL(65),
|
||||
|
||||
ENDER_SIGNAL(72),
|
||||
|
||||
ENDERMAN,
|
||||
|
||||
ENDERMITE,
|
||||
|
||||
EXPERIENCE_ORB,
|
||||
|
||||
FALLING_BLOCK(70, 1),
|
||||
|
||||
FIREBALL(63),
|
||||
|
||||
FIREWORK(76),
|
||||
|
||||
FISHING_HOOK(90),
|
||||
|
||||
GHAST,
|
||||
|
||||
GIANT,
|
||||
|
||||
GUARDIAN,
|
||||
|
||||
HORSE,
|
||||
|
||||
IRON_GOLEM,
|
||||
|
||||
ITEM_FRAME(71),
|
||||
|
||||
LEASH_HITCH(77),
|
||||
|
||||
MAGMA_CUBE,
|
||||
|
||||
MINECART(10),
|
||||
|
||||
MINECART_CHEST(10, 1),
|
||||
|
||||
MINECART_COMMAND(10, 6),
|
||||
|
||||
MINECART_FURNACE(10, 2),
|
||||
|
||||
MINECART_HOPPER(10, 5),
|
||||
|
||||
MINECART_MOB_SPAWNER(10, 4),
|
||||
|
||||
MINECART_TNT(10, 3),
|
||||
|
||||
MULE,
|
||||
|
||||
MUSHROOM_COW,
|
||||
|
||||
OCELOT,
|
||||
|
||||
PAINTING,
|
||||
|
||||
PIG,
|
||||
|
||||
PIG_ZOMBIE,
|
||||
|
||||
PLAYER,
|
||||
|
||||
PRIMED_TNT(50),
|
||||
|
||||
RABBIT,
|
||||
|
||||
SHEEP,
|
||||
|
||||
SHULKER,
|
||||
|
||||
SHULKER_BULLET(67),
|
||||
|
||||
SILVERFISH,
|
||||
|
||||
SKELETON,
|
||||
|
||||
SKELETON_HORSE,
|
||||
|
||||
SLIME,
|
||||
|
||||
SMALL_FIREBALL(63),
|
||||
|
||||
SNOWBALL(61),
|
||||
|
||||
SNOWMAN,
|
||||
|
||||
SPECTRAL_ARROW(91),
|
||||
|
||||
SPIDER,
|
||||
|
||||
SPLASH_POTION(73, 0),
|
||||
|
||||
SQUID,
|
||||
|
||||
TIPPED_ARROW(92),
|
||||
|
||||
THROWN_EXP_BOTTLE(75),
|
||||
|
||||
UNDEAD_HORSE,
|
||||
|
||||
VILLAGER,
|
||||
|
||||
WITCH,
|
||||
|
||||
WITHER,
|
||||
|
||||
WITHER_SKELETON,
|
||||
|
||||
WITHER_SKULL(66),
|
||||
|
||||
WOLF,
|
||||
|
||||
ZOMBIE,
|
||||
|
||||
ZOMBIE_VILLAGER,
|
||||
|
||||
UNKNOWN;
|
||||
|
||||
static
|
||||
{
|
||||
// We set the entity type in this so that we can safely ignore disguisetypes which don't exist in older versions of MC.
|
||||
// Without erroring up everything.
|
||||
|
||||
for (DisguiseType type : values())
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
DisguiseType toUse = type;
|
||||
String name;
|
||||
|
||||
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:
|
||||
break;
|
||||
case DONKEY:
|
||||
case MULE:
|
||||
case UNDEAD_HORSE:
|
||||
case SKELETON_HORSE:
|
||||
toUse = DisguiseType.HORSE;
|
||||
break;
|
||||
case ZOMBIE_VILLAGER:
|
||||
toUse = DisguiseType.ZOMBIE;
|
||||
break;
|
||||
case WITHER_SKELETON:
|
||||
toUse = DisguiseType.SKELETON;
|
||||
break;
|
||||
case ELDER_GUARDIAN:
|
||||
toUse = DisguiseType.GUARDIAN;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
name = toUse.name();
|
||||
|
||||
type.setEntityType(EntityType.valueOf(name));
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
// This version of Spigot doesn't have the disguise.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
public static DisguiseType getType(EntityType entityType)
|
||||
{
|
||||
try
|
||||
{
|
||||
return valueOf(entityType.name().toUpperCase());
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
return DisguiseType.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
private int objectId = -1, defaultData = 0;
|
||||
|
||||
private EntityType entityType;
|
||||
|
||||
private Class<? extends FlagWatcher> watcherClass;
|
||||
|
||||
DisguiseType(int... ints)
|
||||
{
|
||||
for (int i = 0; i < ints.length; i++)
|
||||
{
|
||||
int value = ints[i];
|
||||
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
objectId = value;
|
||||
|
||||
break;
|
||||
case 1:
|
||||
defaultData = value;
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getDefaultData()
|
||||
{
|
||||
return defaultData;
|
||||
}
|
||||
|
||||
public Class<? extends Entity> getEntityClass()
|
||||
{
|
||||
if (entityType != null)
|
||||
{
|
||||
return getEntityType().getEntityClass();
|
||||
}
|
||||
|
||||
return Entity.class;
|
||||
}
|
||||
|
||||
public EntityType getEntityType()
|
||||
{
|
||||
return entityType;
|
||||
}
|
||||
|
||||
/**
|
||||
* The TYPE id of this entity. Different from the Object Id send in spawn packets when spawning miscs.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getTypeId()
|
||||
{
|
||||
return (int) getEntityType().getTypeId();
|
||||
}
|
||||
|
||||
/**
|
||||
* The object type send in packets when spawning a misc entity. Otherwise, -1.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getObjectId()
|
||||
{
|
||||
return objectId;
|
||||
}
|
||||
|
||||
public Class getWatcherClass()
|
||||
{
|
||||
return watcherClass;
|
||||
}
|
||||
|
||||
public boolean isMisc()
|
||||
{
|
||||
return getEntityType() != null && !getEntityType().isAlive();
|
||||
}
|
||||
|
||||
public boolean isMob()
|
||||
{
|
||||
return getEntityType() != null && getEntityType().isAlive() && !isPlayer();
|
||||
}
|
||||
|
||||
public boolean isPlayer()
|
||||
{
|
||||
return this == DisguiseType.PLAYER;
|
||||
}
|
||||
|
||||
public boolean isUnknown()
|
||||
{
|
||||
return this == DisguiseType.UNKNOWN;
|
||||
}
|
||||
|
||||
private void setEntityType(EntityType entityType)
|
||||
{
|
||||
this.entityType = entityType;
|
||||
}
|
||||
|
||||
public void setWatcherClass(Class<? extends FlagWatcher> c)
|
||||
{
|
||||
watcherClass = c;
|
||||
}
|
||||
|
||||
public String toReadable()
|
||||
{
|
||||
String[] split = name().split("_");
|
||||
|
||||
for (int i = 0; i < split.length; i++)
|
||||
{
|
||||
split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase();
|
||||
}
|
||||
|
||||
return StringUtils.join(split, " ");
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -3,23 +3,26 @@ package me.libraryaddict.disguise.disguisetypes;
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
||||
|
||||
public class MobDisguise extends TargetedDisguise {
|
||||
public class MobDisguise extends TargetedDisguise
|
||||
{
|
||||
|
||||
private boolean isAdult;
|
||||
|
||||
public MobDisguise(DisguiseType disguiseType) {
|
||||
public MobDisguise(DisguiseType disguiseType)
|
||||
{
|
||||
this(disguiseType, true);
|
||||
}
|
||||
|
||||
public MobDisguise(DisguiseType disguiseType, boolean isAdult) {
|
||||
if (!disguiseType.isMob()) {
|
||||
public MobDisguise(DisguiseType disguiseType, boolean isAdult)
|
||||
{
|
||||
if (!disguiseType.isMob())
|
||||
{
|
||||
throw new InvalidParameterException("Expected a living DisguiseType while constructing MobDisguise. Received "
|
||||
+ disguiseType + " instead. Please use " + (disguiseType.isPlayer() ? "PlayerDisguise" : "MiscDisguise")
|
||||
+ " instead");
|
||||
@ -28,40 +31,21 @@ public class MobDisguise extends TargetedDisguise {
|
||||
createDisguise(disguiseType);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public MobDisguise(DisguiseType disguiseType, boolean isAdult, boolean replaceSounds) {
|
||||
this(disguiseType, isAdult);
|
||||
this.setReplaceSounds(replaceSounds);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public MobDisguise(EntityType entityType) {
|
||||
this(entityType, true);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public MobDisguise(EntityType entityType, boolean isAdult) {
|
||||
this(DisguiseType.getType(entityType), isAdult);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public MobDisguise(EntityType entityType, boolean isAdult, boolean replaceSounds) {
|
||||
this(entityType, isAdult);
|
||||
this.setReplaceSounds(replaceSounds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise addPlayer(Player player) {
|
||||
public MobDisguise addPlayer(Player player)
|
||||
{
|
||||
return (MobDisguise) super.addPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise addPlayer(String playername) {
|
||||
public MobDisguise addPlayer(String playername)
|
||||
{
|
||||
return (MobDisguise) super.addPlayer(playername);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise clone() {
|
||||
public MobDisguise clone()
|
||||
{
|
||||
MobDisguise disguise = new MobDisguise(getType(), isAdult());
|
||||
disguise.setReplaceSounds(isSoundsReplaced());
|
||||
disguise.setViewSelfDisguise(isSelfDisguiseVisible());
|
||||
@ -74,20 +58,27 @@ public class MobDisguise extends TargetedDisguise {
|
||||
return disguise;
|
||||
}
|
||||
|
||||
public boolean doesDisguiseAge() {
|
||||
public boolean doesDisguiseAge()
|
||||
{
|
||||
return getWatcher() != null && (getWatcher() instanceof AgeableWatcher || getWatcher() instanceof ZombieWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingWatcher getWatcher() {
|
||||
public LivingWatcher getWatcher()
|
||||
{
|
||||
return (LivingWatcher) super.getWatcher();
|
||||
}
|
||||
|
||||
public boolean isAdult() {
|
||||
if (getWatcher() != null) {
|
||||
if (getWatcher() instanceof AgeableWatcher) {
|
||||
public boolean isAdult()
|
||||
{
|
||||
if (getWatcher() != null)
|
||||
{
|
||||
if (getWatcher() instanceof AgeableWatcher)
|
||||
{
|
||||
return ((AgeableWatcher) getWatcher()).isAdult();
|
||||
} else if (getWatcher() instanceof ZombieWatcher) {
|
||||
}
|
||||
else if (getWatcher() instanceof ZombieWatcher)
|
||||
{
|
||||
return ((ZombieWatcher) getWatcher()).isAdult();
|
||||
}
|
||||
return true;
|
||||
@ -96,92 +87,110 @@ public class MobDisguise extends TargetedDisguise {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMobDisguise() {
|
||||
public boolean isMobDisguise()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise removePlayer(Player player) {
|
||||
public MobDisguise removePlayer(Player player)
|
||||
{
|
||||
return (MobDisguise) super.removePlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise removePlayer(String playername) {
|
||||
public MobDisguise removePlayer(String playername)
|
||||
{
|
||||
return (MobDisguise) super.removePlayer(playername);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setDisguiseTarget(TargetType newTargetType) {
|
||||
public MobDisguise setDisguiseTarget(TargetType newTargetType)
|
||||
{
|
||||
return (MobDisguise) super.setDisguiseTarget(newTargetType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setEntity(Entity entity) {
|
||||
public MobDisguise setEntity(Entity entity)
|
||||
{
|
||||
return (MobDisguise) super.setEntity(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setHearSelfDisguise(boolean hearSelfDisguise) {
|
||||
public MobDisguise setHearSelfDisguise(boolean hearSelfDisguise)
|
||||
{
|
||||
return (MobDisguise) super.setHearSelfDisguise(hearSelfDisguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setHideArmorFromSelf(boolean hideArmor) {
|
||||
public MobDisguise setHideArmorFromSelf(boolean hideArmor)
|
||||
{
|
||||
return (MobDisguise) super.setHideArmorFromSelf(hideArmor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setHideHeldItemFromSelf(boolean hideHeldItem) {
|
||||
public MobDisguise setHideHeldItemFromSelf(boolean hideHeldItem)
|
||||
{
|
||||
return (MobDisguise) super.setHideHeldItemFromSelf(hideHeldItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setKeepDisguiseOnEntityDespawn(boolean keepDisguise) {
|
||||
public MobDisguise setKeepDisguiseOnEntityDespawn(boolean keepDisguise)
|
||||
{
|
||||
return (MobDisguise) super.setKeepDisguiseOnEntityDespawn(keepDisguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
|
||||
public MobDisguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise)
|
||||
{
|
||||
return (MobDisguise) super.setKeepDisguiseOnPlayerDeath(keepDisguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setKeepDisguiseOnPlayerLogout(boolean keepDisguise) {
|
||||
public MobDisguise setKeepDisguiseOnPlayerLogout(boolean keepDisguise)
|
||||
{
|
||||
return (MobDisguise) super.setKeepDisguiseOnPlayerLogout(keepDisguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setModifyBoundingBox(boolean modifyBox) {
|
||||
public MobDisguise setModifyBoundingBox(boolean modifyBox)
|
||||
{
|
||||
return (MobDisguise) super.setModifyBoundingBox(modifyBox);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setReplaceSounds(boolean areSoundsReplaced) {
|
||||
public MobDisguise setReplaceSounds(boolean areSoundsReplaced)
|
||||
{
|
||||
return (MobDisguise) super.setReplaceSounds(areSoundsReplaced);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setVelocitySent(boolean sendVelocity) {
|
||||
public MobDisguise setVelocitySent(boolean sendVelocity)
|
||||
{
|
||||
return (MobDisguise) super.setVelocitySent(sendVelocity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setViewSelfDisguise(boolean viewSelfDisguise) {
|
||||
public MobDisguise setViewSelfDisguise(boolean viewSelfDisguise)
|
||||
{
|
||||
return (MobDisguise) super.setViewSelfDisguise(viewSelfDisguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise setWatcher(FlagWatcher newWatcher) {
|
||||
public MobDisguise setWatcher(FlagWatcher newWatcher)
|
||||
{
|
||||
return (MobDisguise) super.setWatcher(newWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise silentlyAddPlayer(String playername) {
|
||||
public MobDisguise silentlyAddPlayer(String playername)
|
||||
{
|
||||
return (MobDisguise) super.silentlyAddPlayer(playername);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobDisguise silentlyRemovePlayer(String playername) {
|
||||
public MobDisguise silentlyRemovePlayer(String playername)
|
||||
{
|
||||
return (MobDisguise) super.silentlyRemovePlayer(playername);
|
||||
}
|
||||
}
|
||||
|
@ -12,56 +12,70 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.LibsProfileLookup;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
|
||||
public class PlayerDisguise extends TargetedDisguise {
|
||||
public class PlayerDisguise extends TargetedDisguise
|
||||
{
|
||||
|
||||
private LibsProfileLookup currentLookup;
|
||||
private WrappedGameProfile gameProfile;
|
||||
private String playerName;
|
||||
private String skinToUse;
|
||||
|
||||
public PlayerDisguise(String name) {
|
||||
if (name.length() > 16) {
|
||||
public PlayerDisguise(String name)
|
||||
{
|
||||
if (name.length() > 16)
|
||||
{
|
||||
name = name.substring(0, 16);
|
||||
}
|
||||
|
||||
playerName = name;
|
||||
createDisguise(DisguiseType.PLAYER);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public PlayerDisguise(String name, boolean replaceSounds) {
|
||||
this(name);
|
||||
this.setReplaceSounds(replaceSounds);
|
||||
}
|
||||
|
||||
public PlayerDisguise(String name, String skinToUse) {
|
||||
public PlayerDisguise(String name, String skinToUse)
|
||||
{
|
||||
this(name);
|
||||
setSkin(skinToUse);
|
||||
}
|
||||
|
||||
public PlayerDisguise(WrappedGameProfile gameProfile) {
|
||||
public PlayerDisguise(Player player)
|
||||
{
|
||||
this(ReflectionManager.getGameProfile(player));
|
||||
}
|
||||
|
||||
public PlayerDisguise(WrappedGameProfile gameProfile)
|
||||
{
|
||||
this(gameProfile.getName());
|
||||
|
||||
this.gameProfile = gameProfile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise addPlayer(Player player) {
|
||||
public PlayerDisguise addPlayer(Player player)
|
||||
{
|
||||
return (PlayerDisguise) super.addPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise addPlayer(String playername) {
|
||||
public PlayerDisguise addPlayer(String playername)
|
||||
{
|
||||
return (PlayerDisguise) super.addPlayer(playername);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise clone() {
|
||||
public PlayerDisguise clone()
|
||||
{
|
||||
PlayerDisguise disguise = new PlayerDisguise(getName());
|
||||
if (disguise.currentLookup == null && disguise.gameProfile != null) {
|
||||
|
||||
if (disguise.currentLookup == null && disguise.gameProfile != null)
|
||||
{
|
||||
disguise.skinToUse = getSkin();
|
||||
disguise.gameProfile = gameProfile;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
disguise.setSkin(getSkin());
|
||||
}
|
||||
|
||||
disguise.setReplaceSounds(isSoundsReplaced());
|
||||
disguise.setViewSelfDisguise(isSelfDisguiseVisible());
|
||||
disguise.setHearSelfDisguise(isSelfDisguiseSoundsReplaced());
|
||||
@ -70,175 +84,229 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
disguise.setVelocitySent(isVelocitySent());
|
||||
disguise.setModifyBoundingBox(isModifyBoundingBox());
|
||||
disguise.setWatcher(getWatcher().clone(disguise));
|
||||
|
||||
return disguise;
|
||||
}
|
||||
|
||||
public void setGameProfile(WrappedGameProfile gameProfile) {
|
||||
public void setGameProfile(WrappedGameProfile gameProfile)
|
||||
{
|
||||
this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, gameProfile.getName(), gameProfile);
|
||||
}
|
||||
|
||||
public WrappedGameProfile getGameProfile() {
|
||||
if (gameProfile == null) {
|
||||
if (getSkin() != null) {
|
||||
public WrappedGameProfile getGameProfile()
|
||||
{
|
||||
if (gameProfile == null)
|
||||
{
|
||||
if (getSkin() != null)
|
||||
{
|
||||
gameProfile = ReflectionManager.getGameProfile(null, getName());
|
||||
} else {
|
||||
gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, getName(), DisguiseUtilities.getProfileFromMojang(this));
|
||||
}
|
||||
else
|
||||
{
|
||||
gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, getName(),
|
||||
DisguiseUtilities.getProfileFromMojang(this));
|
||||
}
|
||||
}
|
||||
|
||||
return gameProfile;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
public String getName()
|
||||
{
|
||||
return playerName;
|
||||
}
|
||||
|
||||
public String getSkin() {
|
||||
public String getSkin()
|
||||
{
|
||||
return skinToUse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerWatcher getWatcher() {
|
||||
public PlayerWatcher getWatcher()
|
||||
{
|
||||
return (PlayerWatcher) super.getWatcher();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayerDisguise() {
|
||||
public boolean isPlayerDisguise()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise removePlayer(Player player) {
|
||||
public PlayerDisguise removePlayer(Player player)
|
||||
{
|
||||
return (PlayerDisguise) super.removePlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise removePlayer(String playername) {
|
||||
public PlayerDisguise removePlayer(String playername)
|
||||
{
|
||||
return (PlayerDisguise) super.removePlayer(playername);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setDisguiseTarget(TargetType newTargetType) {
|
||||
public PlayerDisguise setDisguiseTarget(TargetType newTargetType)
|
||||
{
|
||||
return (PlayerDisguise) super.setDisguiseTarget(newTargetType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setEntity(Entity entity) {
|
||||
public PlayerDisguise setEntity(Entity entity)
|
||||
{
|
||||
return (PlayerDisguise) super.setEntity(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setHearSelfDisguise(boolean hearSelfDisguise) {
|
||||
public PlayerDisguise setHearSelfDisguise(boolean hearSelfDisguise)
|
||||
{
|
||||
return (PlayerDisguise) super.setHearSelfDisguise(hearSelfDisguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setHideArmorFromSelf(boolean hideArmor) {
|
||||
public PlayerDisguise setHideArmorFromSelf(boolean hideArmor)
|
||||
{
|
||||
return (PlayerDisguise) super.setHideArmorFromSelf(hideArmor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setHideHeldItemFromSelf(boolean hideHeldItem) {
|
||||
public PlayerDisguise setHideHeldItemFromSelf(boolean hideHeldItem)
|
||||
{
|
||||
return (PlayerDisguise) super.setHideHeldItemFromSelf(hideHeldItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setKeepDisguiseOnEntityDespawn(boolean keepDisguise) {
|
||||
public PlayerDisguise setKeepDisguiseOnEntityDespawn(boolean keepDisguise)
|
||||
{
|
||||
return (PlayerDisguise) super.setKeepDisguiseOnEntityDespawn(keepDisguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
|
||||
public PlayerDisguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise)
|
||||
{
|
||||
return (PlayerDisguise) super.setKeepDisguiseOnPlayerDeath(keepDisguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setKeepDisguiseOnPlayerLogout(boolean keepDisguise) {
|
||||
public PlayerDisguise setKeepDisguiseOnPlayerLogout(boolean keepDisguise)
|
||||
{
|
||||
return (PlayerDisguise) super.setKeepDisguiseOnPlayerLogout(keepDisguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setModifyBoundingBox(boolean modifyBox) {
|
||||
public PlayerDisguise setModifyBoundingBox(boolean modifyBox)
|
||||
{
|
||||
return (PlayerDisguise) super.setModifyBoundingBox(modifyBox);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setReplaceSounds(boolean areSoundsReplaced) {
|
||||
public PlayerDisguise setReplaceSounds(boolean areSoundsReplaced)
|
||||
{
|
||||
return (PlayerDisguise) super.setReplaceSounds(areSoundsReplaced);
|
||||
}
|
||||
|
||||
public PlayerDisguise setSkin(String skinToUse) {
|
||||
public PlayerDisguise setSkin(String skinToUse)
|
||||
{
|
||||
this.skinToUse = skinToUse;
|
||||
if (skinToUse == null) {
|
||||
|
||||
if (skinToUse == null)
|
||||
{
|
||||
this.currentLookup = null;
|
||||
this.gameProfile = null;
|
||||
} else {
|
||||
if (skinToUse.length() > 16) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (skinToUse.length() > 16)
|
||||
{
|
||||
this.skinToUse = skinToUse.substring(0, 16);
|
||||
}
|
||||
if (LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true)) {
|
||||
currentLookup = new LibsProfileLookup() {
|
||||
|
||||
if (LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true))
|
||||
{
|
||||
currentLookup = new LibsProfileLookup()
|
||||
{
|
||||
@Override
|
||||
public void onLookup(WrappedGameProfile gameProfile) {
|
||||
if (currentLookup == this && gameProfile != null) {
|
||||
public void onLookup(WrappedGameProfile gameProfile)
|
||||
{
|
||||
if (currentLookup == this && gameProfile != null)
|
||||
{
|
||||
setSkin(gameProfile);
|
||||
if (!gameProfile.getProperties().isEmpty() && DisguiseUtilities.isDisguiseInUse(PlayerDisguise.this)) {
|
||||
|
||||
if (!gameProfile.getProperties().isEmpty() && DisguiseUtilities.isDisguiseInUse(PlayerDisguise.this))
|
||||
{
|
||||
DisguiseUtilities.refreshTrackers(PlayerDisguise.this);
|
||||
}
|
||||
|
||||
currentLookup = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup);
|
||||
if (gameProfile != null) {
|
||||
|
||||
if (gameProfile != null)
|
||||
{
|
||||
setSkin(gameProfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the GameProfile, without tampering.
|
||||
*
|
||||
* @param gameProfile GameProfile
|
||||
* @param gameProfile
|
||||
* GameProfile
|
||||
* @return
|
||||
*/
|
||||
public PlayerDisguise setSkin(WrappedGameProfile gameProfile) {
|
||||
if (gameProfile == null) {
|
||||
public PlayerDisguise setSkin(WrappedGameProfile gameProfile)
|
||||
{
|
||||
if (gameProfile == null)
|
||||
{
|
||||
this.gameProfile = null;
|
||||
this.skinToUse = null;
|
||||
return this;
|
||||
}
|
||||
if (LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true)) {
|
||||
|
||||
if (LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true))
|
||||
{
|
||||
Validate.notEmpty(gameProfile.getName(), "Name must be set");
|
||||
this.skinToUse = gameProfile.getName();
|
||||
this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, getName(), gameProfile);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setVelocitySent(boolean sendVelocity) {
|
||||
public PlayerDisguise setVelocitySent(boolean sendVelocity)
|
||||
{
|
||||
return (PlayerDisguise) super.setVelocitySent(sendVelocity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setViewSelfDisguise(boolean viewSelfDisguise) {
|
||||
public PlayerDisguise setViewSelfDisguise(boolean viewSelfDisguise)
|
||||
{
|
||||
return (PlayerDisguise) super.setViewSelfDisguise(viewSelfDisguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise setWatcher(FlagWatcher newWatcher) {
|
||||
public PlayerDisguise setWatcher(FlagWatcher newWatcher)
|
||||
{
|
||||
return (PlayerDisguise) super.setWatcher(newWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise silentlyAddPlayer(String playername) {
|
||||
public PlayerDisguise silentlyAddPlayer(String playername)
|
||||
{
|
||||
return (PlayerDisguise) super.silentlyAddPlayer(playername);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise silentlyRemovePlayer(String playername) {
|
||||
public PlayerDisguise silentlyRemovePlayer(String playername)
|
||||
{
|
||||
return (PlayerDisguise) super.silentlyRemovePlayer(playername);
|
||||
}
|
||||
}
|
||||
|
@ -1,36 +1,39 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
|
||||
public class AgeableWatcher extends LivingWatcher {
|
||||
|
||||
public AgeableWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
Entity e;
|
||||
|
||||
}
|
||||
|
||||
public boolean isAdult() {
|
||||
return !isBaby();
|
||||
}
|
||||
|
||||
public boolean isBaby() {
|
||||
return (boolean) getValue(11, false);
|
||||
}
|
||||
|
||||
public void setAdult() {
|
||||
setBaby(false);
|
||||
}
|
||||
|
||||
public void setBaby() {
|
||||
setBaby(true);
|
||||
}
|
||||
|
||||
public void setBaby(boolean isBaby) {
|
||||
setValue(11, isBaby);
|
||||
sendData(11);
|
||||
}
|
||||
|
||||
}
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
|
||||
public class AgeableWatcher extends LivingWatcher
|
||||
{
|
||||
|
||||
public AgeableWatcher(Disguise disguise)
|
||||
{
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public boolean isAdult()
|
||||
{
|
||||
return !isBaby();
|
||||
}
|
||||
|
||||
public boolean isBaby()
|
||||
{
|
||||
return (boolean) getValue(11, false);
|
||||
}
|
||||
|
||||
public void setAdult()
|
||||
{
|
||||
setBaby(false);
|
||||
}
|
||||
|
||||
public void setBaby()
|
||||
{
|
||||
setBaby(true);
|
||||
}
|
||||
|
||||
public void setBaby(boolean isBaby)
|
||||
{
|
||||
setValue(11, isBaby);
|
||||
sendData(11);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,50 +1,53 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
|
||||
public class MinecartWatcher extends FlagWatcher {
|
||||
|
||||
public MinecartWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public ItemStack getBlockInCart() {
|
||||
int id = (int) getValue(8, 0) & 0xffff;
|
||||
int data = (int) getValue(8, 0) >> 16;
|
||||
return new ItemStack(id, 1, (short) data);
|
||||
}
|
||||
|
||||
public int getBlockYOffset() {
|
||||
return (int) getValue(9, 0);
|
||||
}
|
||||
|
||||
public boolean isViewBlockInCart() {
|
||||
return (boolean) getValue(10, false);
|
||||
}
|
||||
|
||||
public void setBlockInCart(ItemStack item) {
|
||||
int id = item.getTypeId();
|
||||
int data = item.getDurability();
|
||||
setValue(8, id & 0xffff | data << 16);
|
||||
setValue(10, true); //Show block
|
||||
sendData(8, 10);
|
||||
}
|
||||
|
||||
public void setBlockOffset(int i) {
|
||||
setValue(9, i);
|
||||
sendData(9);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setBlockOffSet(int i) {
|
||||
setBlockOffset(i);
|
||||
}
|
||||
|
||||
public void setViewBlockInCart(boolean viewBlock) {
|
||||
setValue(10, viewBlock);
|
||||
sendData(10);
|
||||
}
|
||||
}
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
|
||||
public class MinecartWatcher extends FlagWatcher
|
||||
{
|
||||
|
||||
public MinecartWatcher(Disguise disguise)
|
||||
{
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public ItemStack getBlockInCart()
|
||||
{
|
||||
int id = (int) getValue(8, 0) & 0xffff;
|
||||
int data = (int) getValue(8, 0) >> 16;
|
||||
return new ItemStack(id, 1, (short) data);
|
||||
}
|
||||
|
||||
public int getBlockYOffset()
|
||||
{
|
||||
return (int) getValue(9, 0);
|
||||
}
|
||||
|
||||
public boolean isViewBlockInCart()
|
||||
{
|
||||
return (boolean) getValue(10, false);
|
||||
}
|
||||
|
||||
public void setBlockInCart(ItemStack item)
|
||||
{
|
||||
int id = item.getTypeId();
|
||||
int data = item.getDurability();
|
||||
setValue(8, id & 0xffff | data << 16);
|
||||
setValue(10, true); // Show block
|
||||
sendData(8, 10);
|
||||
}
|
||||
|
||||
public void setBlockOffset(int i)
|
||||
{
|
||||
setValue(9, i);
|
||||
sendData(9);
|
||||
}
|
||||
|
||||
public void setViewBlockInCart(boolean viewBlock)
|
||||
{
|
||||
setValue(10, viewBlock);
|
||||
sendData(10);
|
||||
}
|
||||
}
|
||||
|
@ -1,89 +1,95 @@
|
||||
package me.libraryaddict.disguise.utilities;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.security.CodeSource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
/**
|
||||
* User: Austin Date: 4/22/13 Time: 11:47 PM (c) lazertester
|
||||
*/
|
||||
// Code for this taken and slightly modified from
|
||||
// https://github.com/ddopson/java-class-enumerator
|
||||
public class ClassGetter
|
||||
{
|
||||
|
||||
public static ArrayList<Class<?>> getClassesForPackage(String pkgname)
|
||||
{
|
||||
ArrayList<Class<?>> classes = new ArrayList<>();
|
||||
// String relPath = pkgname.replace('.', '/');
|
||||
|
||||
// Get a File object for the package
|
||||
CodeSource src = Entity.class.getProtectionDomain().getCodeSource();
|
||||
|
||||
if (src != null)
|
||||
{
|
||||
URL resource = src.getLocation();
|
||||
resource.getPath();
|
||||
processJarfile(resource, pkgname, classes);
|
||||
}
|
||||
|
||||
return classes;
|
||||
}
|
||||
|
||||
private static Class<?> loadClass(String className)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Class.forName(className);
|
||||
}
|
||||
catch (ClassNotFoundException e)
|
||||
{
|
||||
throw new RuntimeException("Unexpected ClassNotFoundException loading class '" + className + "'");
|
||||
}
|
||||
catch (NoClassDefFoundError e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void processJarfile(URL resource, String pkgname, ArrayList<Class<?>> classes)
|
||||
{
|
||||
try
|
||||
{
|
||||
String relPath = pkgname.replace('.', '/');
|
||||
String resPath = URLDecoder.decode(resource.getPath(), "UTF-8");
|
||||
String jarPath = resPath.replaceFirst("[.]jar[!].*", ".jar").replaceFirst("file:", "");
|
||||
JarFile jarFile = new JarFile(jarPath);
|
||||
Enumeration<JarEntry> entries = jarFile.entries();
|
||||
while (entries.hasMoreElements())
|
||||
{
|
||||
JarEntry entry = entries.nextElement();
|
||||
String entryName = entry.getName();
|
||||
String className = null;
|
||||
if (entryName.endsWith(".class") && entryName.startsWith(relPath)
|
||||
&& entryName.length() > (relPath.length() + "/".length()))
|
||||
{
|
||||
className = entryName.replace('/', '.').replace('\\', '.').replace(".class", "");
|
||||
}
|
||||
if (className != null)
|
||||
{
|
||||
Class<?> c = loadClass(className);
|
||||
if (c != null)
|
||||
{
|
||||
classes.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace(System.out);
|
||||
}
|
||||
}
|
||||
}
|
||||
package me.libraryaddict.disguise.utilities;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.security.CodeSource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
/**
|
||||
* User: Austin Date: 4/22/13 Time: 11:47 PM (c) lazertester
|
||||
*/
|
||||
// Code for this taken and slightly modified from
|
||||
// https://github.com/ddopson/java-class-enumerator
|
||||
public class ClassGetter
|
||||
{
|
||||
|
||||
public static ArrayList<Class<?>> getClassesForPackage(String pkgname)
|
||||
{
|
||||
ArrayList<Class<?>> classes = new ArrayList<>();
|
||||
// String relPath = pkgname.replace('.', '/');
|
||||
|
||||
// Get a File object for the package
|
||||
CodeSource src = Entity.class.getProtectionDomain().getCodeSource();
|
||||
|
||||
if (src != null)
|
||||
{
|
||||
URL resource = src.getLocation();
|
||||
resource.getPath();
|
||||
processJarfile(resource, pkgname, classes);
|
||||
}
|
||||
|
||||
return classes;
|
||||
}
|
||||
|
||||
private static Class<?> loadClass(String className)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Class.forName(className);
|
||||
}
|
||||
catch (ClassNotFoundException e)
|
||||
{
|
||||
throw new RuntimeException("Unexpected ClassNotFoundException loading class '" + className + "'");
|
||||
}
|
||||
catch (NoClassDefFoundError e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void processJarfile(URL resource, String pkgname, ArrayList<Class<?>> classes)
|
||||
{
|
||||
try
|
||||
{
|
||||
String relPath = pkgname.replace('.', '/');
|
||||
String resPath = URLDecoder.decode(resource.getPath(), "UTF-8");
|
||||
String jarPath = resPath.replaceFirst("[.]jar[!].*", ".jar").replaceFirst("file:", "");
|
||||
|
||||
JarFile jarFile = new JarFile(jarPath);
|
||||
|
||||
Enumeration<JarEntry> entries = jarFile.entries();
|
||||
|
||||
while (entries.hasMoreElements())
|
||||
{
|
||||
JarEntry entry = entries.nextElement();
|
||||
String entryName = entry.getName();
|
||||
String className = null;
|
||||
if (entryName.endsWith(".class") && entryName.startsWith(relPath)
|
||||
&& entryName.length() > (relPath.length() + "/".length()))
|
||||
{
|
||||
className = entryName.replace('/', '.').replace('\\', '.').replace(".class", "");
|
||||
}
|
||||
if (className != null)
|
||||
{
|
||||
Class<?> c = loadClass(className);
|
||||
|
||||
if (c != null)
|
||||
{
|
||||
classes.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jarFile.close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace(System.out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -521,9 +521,12 @@ public class DisguiseUtilities
|
||||
|
||||
StructureModifier<Integer> ints = teleport.getIntegers();
|
||||
ints.write(0, entity.getEntityId());
|
||||
ints.write(1, (int) Math.floor(loc.getX() * 32));
|
||||
ints.write(2, (int) Math.floor((PacketsManager.getYModifier(disguise.getEntity(), disguise) + loc.getY()) * 32));
|
||||
ints.write(3, (int) Math.floor(loc.getZ() * 32));
|
||||
|
||||
StructureModifier<Double> doubles = teleport.getDoubles();
|
||||
|
||||
doubles.write(0, loc.getX());
|
||||
doubles.write(1, PacketsManager.getYModifier(disguise.getEntity(), disguise) + loc.getY());
|
||||
doubles.write(2, loc.getZ());
|
||||
|
||||
return new PacketContainer[]
|
||||
{
|
||||
|
@ -1,146 +1,115 @@
|
||||
package me.libraryaddict.disguise.utilities;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
|
||||
public class DisguiseValues {
|
||||
|
||||
private static HashMap<DisguiseType, DisguiseValues> values = new HashMap<>();
|
||||
|
||||
public static DisguiseValues getDisguiseValues(DisguiseType type) {
|
||||
switch (type) {
|
||||
case DONKEY:
|
||||
case MULE:
|
||||
case UNDEAD_HORSE:
|
||||
case SKELETON_HORSE:
|
||||
type = DisguiseType.HORSE;
|
||||
break;
|
||||
case MINECART_CHEST:
|
||||
case MINECART_COMMAND:
|
||||
case MINECART_FURNACE:
|
||||
case MINECART_HOPPER:
|
||||
case MINECART_TNT:
|
||||
case MINECART_MOB_SPAWNER:
|
||||
type = DisguiseType.MINECART;
|
||||
break;
|
||||
case WITHER_SKELETON:
|
||||
type = DisguiseType.SKELETON;
|
||||
break;
|
||||
case ZOMBIE_VILLAGER:
|
||||
type = DisguiseType.ZOMBIE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return values.get(type);
|
||||
}
|
||||
|
||||
public static HashMap<Integer, Object> getMetaValues(DisguiseType type) {
|
||||
return getDisguiseValues(type).getMetaValues();
|
||||
}
|
||||
|
||||
public static Class getNmsEntityClass(DisguiseType type) {
|
||||
return getDisguiseValues(type).getNmsEntityClass();
|
||||
}
|
||||
|
||||
private FakeBoundingBox adultBox;
|
||||
private FakeBoundingBox babyBox;
|
||||
private float[] entitySize;
|
||||
private int enumEntitySize;
|
||||
private double maxHealth;
|
||||
private HashMap<Integer, Object> metaValues = new HashMap<>();
|
||||
private Class nmsEntityClass;
|
||||
|
||||
@SuppressWarnings("LeakingThisInConstructor")
|
||||
public DisguiseValues(DisguiseType type, Class classType, int entitySize, double maxHealth) {
|
||||
values.put(type, this);
|
||||
enumEntitySize = entitySize;
|
||||
nmsEntityClass = classType;
|
||||
this.maxHealth = maxHealth;
|
||||
}
|
||||
|
||||
public FakeBoundingBox getAdultBox() {
|
||||
return adultBox;
|
||||
}
|
||||
|
||||
public FakeBoundingBox getBabyBox() {
|
||||
return babyBox;
|
||||
}
|
||||
|
||||
public float[] getEntitySize() {
|
||||
return entitySize;
|
||||
}
|
||||
|
||||
public int getEntitySize(double paramDouble) {
|
||||
double d = paramDouble - (((int) Math.floor(paramDouble)) + 0.5D);
|
||||
|
||||
switch (enumEntitySize) {
|
||||
case 1:
|
||||
if (d < 0.0D ? d < -0.3125D : d < 0.3125D) {
|
||||
return (int) Math.ceil(paramDouble * 32.0D);
|
||||
}
|
||||
|
||||
return (int) Math.floor(paramDouble * 32.0D);
|
||||
case 2:
|
||||
if (d < 0.0D ? d < -0.3125D : d < 0.3125D) {
|
||||
return (int) Math.floor(paramDouble * 32.0D);
|
||||
}
|
||||
|
||||
return (int) Math.ceil(paramDouble * 32.0D);
|
||||
case 3:
|
||||
if (d > 0.0D) {
|
||||
return (int) Math.floor(paramDouble * 32.0D);
|
||||
}
|
||||
|
||||
return (int) Math.ceil(paramDouble * 32.0D);
|
||||
case 4:
|
||||
if (d < 0.0D ? d < -0.1875D : d < 0.1875D) {
|
||||
return (int) Math.ceil(paramDouble * 32.0D);
|
||||
}
|
||||
|
||||
return (int) Math.floor(paramDouble * 32.0D);
|
||||
case 5:
|
||||
if (d < 0.0D ? d < -0.1875D : d < 0.1875D) {
|
||||
return (int) Math.floor(paramDouble * 32.0D);
|
||||
}
|
||||
|
||||
return (int) Math.ceil(paramDouble * 32.0D);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (d > 0.0D) {
|
||||
return (int) Math.ceil(paramDouble * 32.0D);
|
||||
}
|
||||
|
||||
return (int) Math.floor(paramDouble * 32.0D);
|
||||
}
|
||||
|
||||
public double getMaxHealth() {
|
||||
return maxHealth;
|
||||
}
|
||||
|
||||
public HashMap<Integer, Object> getMetaValues() {
|
||||
return metaValues;
|
||||
}
|
||||
|
||||
public Class getNmsEntityClass() {
|
||||
return nmsEntityClass;
|
||||
}
|
||||
|
||||
public void setAdultBox(FakeBoundingBox newBox) {
|
||||
adultBox = newBox;
|
||||
}
|
||||
|
||||
public void setBabyBox(FakeBoundingBox newBox) {
|
||||
babyBox = newBox;
|
||||
}
|
||||
|
||||
public void setEntitySize(float[] size) {
|
||||
this.entitySize = size;
|
||||
}
|
||||
|
||||
public void setMetaValue(int id, Object value) {
|
||||
metaValues.put(id, value);
|
||||
}
|
||||
}
|
||||
package me.libraryaddict.disguise.utilities;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
|
||||
public class DisguiseValues
|
||||
{
|
||||
|
||||
private static HashMap<DisguiseType, DisguiseValues> values = new HashMap<>();
|
||||
|
||||
public static DisguiseValues getDisguiseValues(DisguiseType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case DONKEY:
|
||||
case MULE:
|
||||
case UNDEAD_HORSE:
|
||||
case SKELETON_HORSE:
|
||||
type = DisguiseType.HORSE;
|
||||
break;
|
||||
case MINECART_CHEST:
|
||||
case MINECART_COMMAND:
|
||||
case MINECART_FURNACE:
|
||||
case MINECART_HOPPER:
|
||||
case MINECART_TNT:
|
||||
case MINECART_MOB_SPAWNER:
|
||||
type = DisguiseType.MINECART;
|
||||
break;
|
||||
case WITHER_SKELETON:
|
||||
type = DisguiseType.SKELETON;
|
||||
break;
|
||||
case ZOMBIE_VILLAGER:
|
||||
type = DisguiseType.ZOMBIE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return values.get(type);
|
||||
}
|
||||
|
||||
public static HashMap<Integer, Object> getMetaValues(DisguiseType type)
|
||||
{
|
||||
return getDisguiseValues(type).getMetaValues();
|
||||
}
|
||||
|
||||
public static Class getNmsEntityClass(DisguiseType type)
|
||||
{
|
||||
return getDisguiseValues(type).getNmsEntityClass();
|
||||
}
|
||||
|
||||
private FakeBoundingBox adultBox;
|
||||
private FakeBoundingBox babyBox;
|
||||
private float[] entitySize;
|
||||
private double maxHealth;
|
||||
private HashMap<Integer, Object> metaValues = new HashMap<>();
|
||||
private Class nmsEntityClass;
|
||||
|
||||
public DisguiseValues(DisguiseType type, Class classType, int entitySize, double maxHealth)
|
||||
{
|
||||
values.put(type, this);
|
||||
nmsEntityClass = classType;
|
||||
this.maxHealth = maxHealth;
|
||||
}
|
||||
|
||||
public FakeBoundingBox getAdultBox()
|
||||
{
|
||||
return adultBox;
|
||||
}
|
||||
|
||||
public FakeBoundingBox getBabyBox()
|
||||
{
|
||||
return babyBox;
|
||||
}
|
||||
|
||||
public float[] getEntitySize()
|
||||
{
|
||||
return entitySize;
|
||||
}
|
||||
|
||||
public double getMaxHealth()
|
||||
{
|
||||
return maxHealth;
|
||||
}
|
||||
|
||||
public HashMap<Integer, Object> getMetaValues()
|
||||
{
|
||||
return metaValues;
|
||||
}
|
||||
|
||||
public Class getNmsEntityClass()
|
||||
{
|
||||
return nmsEntityClass;
|
||||
}
|
||||
|
||||
public void setAdultBox(FakeBoundingBox newBox)
|
||||
{
|
||||
adultBox = newBox;
|
||||
}
|
||||
|
||||
public void setBabyBox(FakeBoundingBox newBox)
|
||||
{
|
||||
babyBox = newBox;
|
||||
}
|
||||
|
||||
public void setEntitySize(float[] size)
|
||||
{
|
||||
this.entitySize = size;
|
||||
}
|
||||
|
||||
public void setMetaValue(int id, Object value)
|
||||
{
|
||||
metaValues.put(id, value);
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,86 @@
|
||||
package me.libraryaddict.disguise.utilities.packetlisteners;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ExperienceOrb;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.SheepWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher;
|
||||
|
||||
public class PacketListenerClientInteract extends PacketAdapter
|
||||
{
|
||||
public PacketListenerClientInteract(LibsDisguises plugin)
|
||||
{
|
||||
super(plugin, ListenerPriority.NORMAL, PacketType.Play.Client.USE_ENTITY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event)
|
||||
{
|
||||
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
Player observer = event.getPlayer();
|
||||
|
||||
if (observer.getName().contains("UNKNOWN[")) // If the player is temporary
|
||||
return;
|
||||
|
||||
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld());
|
||||
|
||||
Entity entity = entityModifer.read(0);
|
||||
|
||||
if (entity instanceof ExperienceOrb || entity instanceof Item || entity instanceof Arrow || entity == observer)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
ItemStack item = observer.getItemInHand();
|
||||
|
||||
if (item != null && item.getType() == Material.INK_SACK)
|
||||
{
|
||||
Disguise disguise = DisguiseAPI.getDisguise(observer, entity);
|
||||
|
||||
if (disguise != null && (disguise.getType() == DisguiseType.SHEEP || disguise.getType() == DisguiseType.WOLF))
|
||||
{
|
||||
AnimalColor color = AnimalColor.getColor(item.getDurability());
|
||||
|
||||
if (disguise.getType() == DisguiseType.SHEEP)
|
||||
{
|
||||
SheepWatcher watcher = (SheepWatcher) disguise.getWatcher();
|
||||
|
||||
watcher.setColor(DisguiseConfig.isSheepDyeable() ? color : watcher.getColor());
|
||||
}
|
||||
else
|
||||
{
|
||||
WolfWatcher watcher = (WolfWatcher) disguise.getWatcher();
|
||||
|
||||
watcher.setCollarColor(DisguiseConfig.isWolfDyeable() ? color : watcher.getCollarColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,390 @@
|
||||
package me.libraryaddict.disguise.utilities.packetlisteners;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.PacketType.Play.Server;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
|
||||
public class PacketListenerInventory extends PacketAdapter
|
||||
{
|
||||
private LibsDisguises libsDisguises;
|
||||
|
||||
public PacketListenerInventory(LibsDisguises plugin)
|
||||
{
|
||||
super(plugin, ListenerPriority.HIGH, Server.SET_SLOT, Server.WINDOW_ITEMS, PacketType.Play.Client.HELD_ITEM_SLOT,
|
||||
PacketType.Play.Client.SET_CREATIVE_SLOT, PacketType.Play.Client.WINDOW_CLICK);
|
||||
|
||||
libsDisguises = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceiving(final PacketEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
if (event.getPlayer().getName().contains("UNKNOWN[")) // If the player is temporary
|
||||
return;
|
||||
|
||||
if (!(event.getPlayer() instanceof com.comphenix.net.sf.cglib.proxy.Factory) && event.getPlayer().getVehicle() == null)
|
||||
{
|
||||
Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer());
|
||||
|
||||
// If player is disguised, views self disguises and has a inventory modifier
|
||||
if (disguise != null && disguise.isSelfDisguiseVisible()
|
||||
&& (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf()))
|
||||
{
|
||||
// If they are in creative and clicked on a slot
|
||||
if (event.getPacketType() == PacketType.Play.Client.SET_CREATIVE_SLOT)
|
||||
{
|
||||
int slot = event.getPacket().getIntegers().read(0);
|
||||
|
||||
if (slot >= 5 && slot <= 8)
|
||||
{
|
||||
if (disguise.isHidingArmorFromSelf())
|
||||
{
|
||||
int armorSlot = Math.abs((slot - 5) - 3);
|
||||
|
||||
org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot];
|
||||
|
||||
if (item != null && item.getType() != Material.AIR)
|
||||
{
|
||||
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
|
||||
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
|
||||
mods.write(0, 0);
|
||||
mods.write(1, slot);
|
||||
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
||||
|
||||
try
|
||||
{
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (slot >= 36 && slot <= 44)
|
||||
{
|
||||
if (disguise.isHidingHeldItemFromSelf())
|
||||
{
|
||||
int currentSlot = event.getPlayer().getInventory().getHeldItemSlot();
|
||||
|
||||
if (slot + 36 == currentSlot)
|
||||
{
|
||||
org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand();
|
||||
|
||||
if (item != null && item.getType() != Material.AIR)
|
||||
{
|
||||
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
|
||||
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
mods.write(0, 0);
|
||||
mods.write(1, slot);
|
||||
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
||||
|
||||
try
|
||||
{
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// If the player switched item, aka he moved from slot 1 to slot 2
|
||||
else if (event.getPacketType() == PacketType.Play.Client.HELD_ITEM_SLOT)
|
||||
{
|
||||
if (disguise.isHidingHeldItemFromSelf())
|
||||
{
|
||||
// From logging, it seems that both bukkit and nms uses the same thing for the slot switching.
|
||||
// 0 1 2 3 - 8
|
||||
// If the packet is coming, then I need to replace the item they are switching to
|
||||
// As for the old item, I need to restore it.
|
||||
org.bukkit.inventory.ItemStack currentlyHeld = event.getPlayer().getItemInHand();
|
||||
// If his old weapon isn't air
|
||||
if (currentlyHeld != null && currentlyHeld.getType() != Material.AIR)
|
||||
{
|
||||
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
|
||||
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
|
||||
mods.write(0, 0);
|
||||
mods.write(1, event.getPlayer().getInventory().getHeldItemSlot() + 36);
|
||||
mods.write(2, ReflectionManager.getNmsItem(currentlyHeld));
|
||||
|
||||
try
|
||||
{
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
org.bukkit.inventory.ItemStack newHeld = event.getPlayer().getInventory()
|
||||
.getItem(event.getPacket().getIntegers().read(0));
|
||||
|
||||
// If his new weapon isn't air either!
|
||||
if (newHeld != null && newHeld.getType() != Material.AIR)
|
||||
{
|
||||
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
|
||||
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
|
||||
mods.write(0, 0);
|
||||
mods.write(1, event.getPacket().getIntegers().read(0) + 36);
|
||||
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
||||
|
||||
try
|
||||
{
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (event.getPacketType() == PacketType.Play.Client.WINDOW_CLICK)
|
||||
{
|
||||
int slot = event.getPacket().getIntegers().read(1);
|
||||
|
||||
org.bukkit.inventory.ItemStack clickedItem;
|
||||
|
||||
if (event.getPacket().getShorts().read(0) == 1)
|
||||
{
|
||||
// Its a shift click
|
||||
clickedItem = event.getPacket().getItemModifier().read(0);
|
||||
|
||||
if (clickedItem != null && clickedItem.getType() != Material.AIR)
|
||||
{
|
||||
// Rather than predict the clients actions
|
||||
// Lets just update the entire inventory..
|
||||
Bukkit.getScheduler().runTask(libsDisguises, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
event.getPlayer().updateInventory();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If its not a player inventory click
|
||||
// Shift clicking is exempted for the item in hand..
|
||||
if (event.getPacket().getIntegers().read(0) != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
clickedItem = event.getPlayer().getItemOnCursor();
|
||||
}
|
||||
|
||||
if (clickedItem != null && clickedItem.getType() != Material.AIR)
|
||||
{
|
||||
// If the slot is a armor slot
|
||||
if (slot >= 5 && slot <= 8)
|
||||
{
|
||||
if (disguise.isHidingArmorFromSelf())
|
||||
{
|
||||
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
|
||||
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
|
||||
mods.write(0, 0);
|
||||
mods.write(1, slot);
|
||||
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
||||
|
||||
try
|
||||
{
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// Else if its a hotbar slot
|
||||
}
|
||||
else if (slot >= 36 && slot <= 44)
|
||||
{
|
||||
if (disguise.isHidingHeldItemFromSelf())
|
||||
{
|
||||
int currentSlot = event.getPlayer().getInventory().getHeldItemSlot();
|
||||
|
||||
// Check if the player is on the same slot as the slot that its setting
|
||||
if (slot == currentSlot + 36)
|
||||
{
|
||||
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
|
||||
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
mods.write(0, 0);
|
||||
mods.write(1, slot);
|
||||
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
||||
|
||||
try
|
||||
{
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event)
|
||||
{
|
||||
// If the inventory is the players inventory
|
||||
if (!(event.getPlayer() instanceof com.comphenix.net.sf.cglib.proxy.Factory) && event.getPlayer().getVehicle() == null
|
||||
&& event.getPacket().getIntegers().read(0) == 0)
|
||||
{
|
||||
|
||||
Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer());
|
||||
|
||||
// If the player is disguised, views self disguises and is hiding a item.
|
||||
if (disguise != null && disguise.isSelfDisguiseVisible()
|
||||
&& (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf()))
|
||||
{
|
||||
// If the server is setting the slot
|
||||
// Need to set it to air if its in a place it shouldn't be.
|
||||
// Things such as picking up a item, spawned in item. Plugin sets the item. etc. Will fire this
|
||||
/**
|
||||
* Done
|
||||
*/
|
||||
if (event.getPacketType() == Server.SET_SLOT)
|
||||
{
|
||||
// The raw slot
|
||||
// nms code has the start of the hotbar being 36.
|
||||
int slot = event.getPacket().getIntegers().read(1);
|
||||
|
||||
// If the slot is a armor slot
|
||||
if (slot >= 5 && slot <= 8)
|
||||
{
|
||||
if (disguise.isHidingArmorFromSelf())
|
||||
{
|
||||
// Get the bukkit armor slot!
|
||||
int armorSlot = Math.abs((slot - 5) - 3);
|
||||
|
||||
org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot];
|
||||
|
||||
if (item != null && item.getType() != Material.AIR)
|
||||
{
|
||||
event.setPacket(event.getPacket().shallowClone());
|
||||
|
||||
event.getPacket().getModifier().write(2,
|
||||
ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
||||
}
|
||||
}
|
||||
// Else if its a hotbar slot
|
||||
}
|
||||
else if (slot >= 36 && slot <= 44)
|
||||
{
|
||||
if (disguise.isHidingHeldItemFromSelf())
|
||||
{
|
||||
int currentSlot = event.getPlayer().getInventory().getHeldItemSlot();
|
||||
|
||||
// Check if the player is on the same slot as the slot that its setting
|
||||
if (slot == currentSlot + 36)
|
||||
{
|
||||
org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand();
|
||||
|
||||
if (item != null && item.getType() != Material.AIR)
|
||||
{
|
||||
event.setPacket(event.getPacket().shallowClone());
|
||||
event.getPacket().getModifier().write(2,
|
||||
ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (event.getPacketType() == Server.WINDOW_ITEMS)
|
||||
{
|
||||
event.setPacket(event.getPacket().deepClone());
|
||||
|
||||
StructureModifier<ItemStack[]> mods = event.getPacket().getItemArrayModifier();
|
||||
ItemStack[] items = mods.read(0);
|
||||
|
||||
for (int slot = 0; slot < items.length; slot++)
|
||||
{
|
||||
if (slot >= 5 && slot <= 8)
|
||||
{
|
||||
if (disguise.isHidingArmorFromSelf())
|
||||
{
|
||||
// Get the bukkit armor slot!
|
||||
int armorSlot = Math.abs((slot - 5) - 3);
|
||||
|
||||
org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory()
|
||||
.getArmorContents()[armorSlot];
|
||||
|
||||
if (item != null && item.getType() != Material.AIR)
|
||||
{
|
||||
items[slot] = new org.bukkit.inventory.ItemStack(0);
|
||||
}
|
||||
}
|
||||
// Else if its a hotbar slot
|
||||
}
|
||||
else if (slot >= 36 && slot <= 44)
|
||||
{
|
||||
if (disguise.isHidingHeldItemFromSelf())
|
||||
{
|
||||
int currentSlot = event.getPlayer().getInventory().getHeldItemSlot();
|
||||
|
||||
// Check if the player is on the same slot as the slot that its setting
|
||||
if (slot == currentSlot + 36)
|
||||
{
|
||||
org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand();
|
||||
|
||||
if (item != null && item.getType() != Material.AIR)
|
||||
{
|
||||
items[slot] = new org.bukkit.inventory.ItemStack(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mods.write(0, items);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package me.libraryaddict.disguise.utilities.packetlisteners;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.PacketType.Play.Server;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.utilities.PacketsManager;
|
||||
|
||||
public class PacketListenerMain extends PacketAdapter
|
||||
{
|
||||
private LibsDisguises libsDisguises;
|
||||
|
||||
public PacketListenerMain(LibsDisguises plugin, ArrayList<PacketType> packetsToListen)
|
||||
{
|
||||
super(plugin, ListenerPriority.HIGH, packetsToListen);
|
||||
|
||||
libsDisguises = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
if (event.getPlayer().getName().contains("UNKNOWN[")) // If the player is temporary
|
||||
return;
|
||||
|
||||
final Player observer = event.getPlayer();
|
||||
|
||||
// First get the entity, the one sending this packet
|
||||
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld());
|
||||
|
||||
org.bukkit.entity.Entity entity = entityModifer.read((Server.COLLECT == event.getPacketType() ? 1 : 0));
|
||||
|
||||
// If the entity is the same as the sender. Don't disguise!
|
||||
// Prevents problems and there is no advantage to be gained.
|
||||
if (entity == observer)
|
||||
return;
|
||||
|
||||
PacketContainer[][] packets = PacketsManager.transformPacket(event.getPacket(), event.getPlayer(), entity);
|
||||
|
||||
if (packets != null)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
|
||||
try
|
||||
{
|
||||
for (PacketContainer packet : packets[0])
|
||||
{
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
||||
}
|
||||
|
||||
final PacketContainer[] delayed = packets[1];
|
||||
|
||||
if (delayed.length > 0)
|
||||
{
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
for (PacketContainer packet : delayed)
|
||||
{
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
||||
}
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, 2);
|
||||
}
|
||||
}
|
||||
catch (InvocationTargetException ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,406 @@
|
||||
package me.libraryaddict.disguise.utilities.packetlisteners;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Zombie;
|
||||
|
||||
import com.comphenix.protocol.PacketType.Play.Server;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.MobDisguise;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseSound;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseSound.SoundType;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
|
||||
public class PacketListenerSounds extends PacketAdapter
|
||||
{
|
||||
/**
|
||||
* This is a fix for the stupidity that is
|
||||
* "I can't separate the sounds from the sounds the player heard, and the sounds of the entity tracker heard"
|
||||
*/
|
||||
private static boolean cancelSound;
|
||||
|
||||
public PacketListenerSounds(LibsDisguises plugin)
|
||||
{
|
||||
super(plugin, ListenerPriority.NORMAL, Server.NAMED_SOUND_EFFECT, Server.ENTITY_STATUS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (event.isAsync())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getPlayer().getName().contains("UNKNOWN[")) // If the player is temporary
|
||||
return;
|
||||
|
||||
event.setPacket(event.getPacket().deepClone());
|
||||
|
||||
StructureModifier<Object> mods = event.getPacket().getModifier();
|
||||
|
||||
Player observer = event.getPlayer();
|
||||
|
||||
if (event.getPacketType() == Server.NAMED_SOUND_EFFECT)
|
||||
{
|
||||
Object soundEffect = mods.read(0);
|
||||
|
||||
SoundType soundType = null;
|
||||
|
||||
Location soundLoc = new Location(observer.getWorld(), ((Integer) mods.read(2)) / 8D, ((Integer) mods.read(3)) / 8D,
|
||||
((Integer) mods.read(4)) / 8D);
|
||||
|
||||
Entity disguisedEntity = null;
|
||||
DisguiseSound entitySound = null;
|
||||
|
||||
Disguise disguise = null;
|
||||
|
||||
Entity[] entities = soundLoc.getChunk().getEntities();
|
||||
|
||||
for (Entity entity : entities)
|
||||
{
|
||||
Disguise entityDisguise = DisguiseAPI.getDisguise(observer, entity);
|
||||
|
||||
if (entityDisguise != null)
|
||||
{
|
||||
Location loc = entity.getLocation();
|
||||
|
||||
loc = new Location(observer.getWorld(), ((int) (loc.getX() * 8)) / 8D, ((int) (loc.getY() * 8)) / 8D,
|
||||
((int) (loc.getZ() * 8)) / 8D);
|
||||
|
||||
if (loc.equals(soundLoc))
|
||||
{
|
||||
entitySound = DisguiseSound.getType(entity.getType().name());
|
||||
|
||||
if (entitySound != null)
|
||||
{
|
||||
Object obj = null;
|
||||
|
||||
if (entity instanceof LivingEntity)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Use reflection so that this works for either int or double methods
|
||||
obj = LivingEntity.class.getMethod("getHealth").invoke(entity);
|
||||
|
||||
if (obj instanceof Double ? (Double) obj == 0 : (Integer) obj == 0)
|
||||
{
|
||||
soundType = SoundType.DEATH;
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = null;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (obj == null)
|
||||
{
|
||||
boolean hasInvun = false;
|
||||
|
||||
Object nmsEntity = ReflectionManager.getNmsEntity(entity);
|
||||
|
||||
try
|
||||
{
|
||||
if (entity instanceof LivingEntity)
|
||||
{
|
||||
hasInvun = ReflectionManager.getNmsField("Entity", "noDamageTicks")
|
||||
.getInt(nmsEntity) == ReflectionManager
|
||||
.getNmsField("EntityLiving", "maxNoDamageTicks").getInt(nmsEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
Class clazz = ReflectionManager.getNmsClass("DamageSource");
|
||||
|
||||
hasInvun = (Boolean) ReflectionManager.getNmsMethod("Entity", "isInvulnerable", clazz)
|
||||
.invoke(nmsEntity, ReflectionManager.getNmsField(clazz, "GENERIC"));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
soundType = entitySound.getType(ReflectionManager.convertSoundEffectToString(soundEffect),
|
||||
!hasInvun);
|
||||
}
|
||||
|
||||
if (soundType != null)
|
||||
{
|
||||
disguise = entityDisguise;
|
||||
disguisedEntity = entity;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (disguise != null)
|
||||
{
|
||||
if (disguise.isSelfDisguiseSoundsReplaced() || disguisedEntity != event.getPlayer())
|
||||
{
|
||||
if (disguise.isSoundsReplaced())
|
||||
{
|
||||
String sound = null;
|
||||
|
||||
DisguiseSound dSound = DisguiseSound.getType(disguise.getType().name());
|
||||
|
||||
if (dSound != null)
|
||||
sound = dSound.getSound(soundType);
|
||||
|
||||
if (sound == null)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sound.equals("step.grass"))
|
||||
{
|
||||
try
|
||||
{
|
||||
int typeId = soundLoc.getWorld().getBlockTypeIdAt(soundLoc.getBlockX(),
|
||||
soundLoc.getBlockY() - 1, soundLoc.getBlockZ());
|
||||
|
||||
Object block = ReflectionManager.getNmsMethod("RegistryMaterials", "a", int.class)
|
||||
.invoke(ReflectionManager.getNmsField("Block", "REGISTRY").get(null), typeId);
|
||||
|
||||
if (block != null)
|
||||
{
|
||||
Object step = ReflectionManager.getNmsField("Block", "stepSound").get(block);
|
||||
|
||||
mods.write(0,
|
||||
ReflectionManager.getNmsMethod(step.getClass(), "getStepSound").invoke(step));
|
||||
mods.write(1, ReflectionManager.getSoundCategory(disguise.getType()));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
// There is no else statement. Because seriously. This should never be null. Unless
|
||||
// someone is
|
||||
// sending fake sounds. In which case. Why cancel it.
|
||||
}
|
||||
else
|
||||
{
|
||||
mods.write(0, ReflectionManager.getCraftSoundEffect(sound));
|
||||
mods.write(1, ReflectionManager.getSoundCategory(disguise.getType()));
|
||||
|
||||
// Time to change the pitch and volume
|
||||
if (soundType == SoundType.HURT || soundType == SoundType.DEATH || soundType == SoundType.IDLE)
|
||||
{
|
||||
// If the volume is the default
|
||||
if (mods.read(5).equals(entitySound.getDamageAndIdleSoundVolume()))
|
||||
{
|
||||
mods.write(5, dSound.getDamageAndIdleSoundVolume());
|
||||
}
|
||||
|
||||
// Here I assume its the default pitch as I can't calculate if its real.
|
||||
if (disguise instanceof MobDisguise && disguisedEntity instanceof LivingEntity
|
||||
&& ((MobDisguise) disguise).doesDisguiseAge())
|
||||
{
|
||||
boolean baby = false;
|
||||
|
||||
if (disguisedEntity instanceof Zombie)
|
||||
{
|
||||
baby = ((Zombie) disguisedEntity).isBaby();
|
||||
}
|
||||
else if (disguisedEntity instanceof Ageable)
|
||||
{
|
||||
baby = !((Ageable) disguisedEntity).isAdult();
|
||||
}
|
||||
|
||||
if (((MobDisguise) disguise).isAdult() == baby)
|
||||
{
|
||||
float pitch = (Integer) mods.read(5);
|
||||
|
||||
if (baby)
|
||||
{
|
||||
// If the pitch is not the expected
|
||||
if (pitch > 97 || pitch < 111)
|
||||
return;
|
||||
|
||||
pitch = (DisguiseUtilities.random.nextFloat()
|
||||
- DisguiseUtilities.random.nextFloat()) * 0.2F + 1.5F;
|
||||
// Min = 1.5
|
||||
// Cap = 97.5
|
||||
// Max = 1.7
|
||||
// Cap = 110.5
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the pitch is not the expected
|
||||
if (pitch >= 63 || pitch <= 76)
|
||||
return;
|
||||
|
||||
pitch = (DisguiseUtilities.random.nextFloat()
|
||||
- DisguiseUtilities.random.nextFloat()) * 0.2F + 1.0F;
|
||||
// Min = 1
|
||||
// Cap = 63
|
||||
// Max = 1.2
|
||||
// Cap = 75.6
|
||||
}
|
||||
|
||||
pitch *= 63;
|
||||
|
||||
if (pitch < 0)
|
||||
pitch = 0;
|
||||
|
||||
if (pitch > 255)
|
||||
pitch = 255;
|
||||
|
||||
mods.write(6, (int) pitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (event.getPacketType() == Server.ENTITY_STATUS)
|
||||
{
|
||||
if ((byte) mods.read(1) == 2)
|
||||
{
|
||||
// It made a damage animation
|
||||
Entity entity = event.getPacket().getEntityModifier(observer.getWorld()).read(0);
|
||||
|
||||
Disguise disguise = DisguiseAPI.getDisguise(observer, entity);
|
||||
|
||||
if (disguise != null && !disguise.getType().isPlayer()
|
||||
&& (disguise.isSelfDisguiseSoundsReplaced() || entity != event.getPlayer()))
|
||||
{
|
||||
DisguiseSound disSound = DisguiseSound.getType(entity.getType().name());
|
||||
|
||||
if (disSound == null)
|
||||
return;
|
||||
|
||||
SoundType soundType = null;
|
||||
Object obj = null;
|
||||
|
||||
if (entity instanceof LivingEntity)
|
||||
{
|
||||
try
|
||||
{
|
||||
obj = LivingEntity.class.getMethod("getHealth").invoke(entity);
|
||||
|
||||
if (obj instanceof Double ? (Double) obj == 0 : (Integer) obj == 0)
|
||||
{
|
||||
soundType = SoundType.DEATH;
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = null;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (obj == null)
|
||||
{
|
||||
soundType = SoundType.HURT;
|
||||
}
|
||||
|
||||
if (disSound.getSound(soundType) == null
|
||||
|| (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer()))
|
||||
{
|
||||
if (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer())
|
||||
{
|
||||
cancelSound = !cancelSound;
|
||||
|
||||
if (cancelSound)
|
||||
return;
|
||||
}
|
||||
|
||||
disSound = DisguiseSound.getType(disguise.getType().name());
|
||||
|
||||
if (disSound != null)
|
||||
{
|
||||
String sound = disSound.getSound(soundType);
|
||||
|
||||
if (sound != null)
|
||||
{
|
||||
Location loc = entity.getLocation();
|
||||
|
||||
PacketContainer packet = new PacketContainer(Server.NAMED_SOUND_EFFECT);
|
||||
|
||||
mods = packet.getModifier();
|
||||
|
||||
Object craftSoundEffect = ReflectionManager.getCraftSoundEffect(sound);
|
||||
|
||||
mods.write(0, craftSoundEffect);
|
||||
mods.write(1, ReflectionManager.getSoundCategory(disguise.getType())); // Meh
|
||||
mods.write(2, (int) (loc.getX() * 8D));
|
||||
mods.write(3, (int) (loc.getY() * 8D));
|
||||
mods.write(4, (int) (loc.getZ() * 8D));
|
||||
mods.write(5, disSound.getDamageAndIdleSoundVolume());
|
||||
|
||||
float pitch;
|
||||
|
||||
if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult())
|
||||
{
|
||||
pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F
|
||||
+ 1.5F;
|
||||
}
|
||||
else
|
||||
pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F
|
||||
+ 1.0F;
|
||||
|
||||
if (disguise.getType() == DisguiseType.BAT)
|
||||
pitch *= 95F;
|
||||
|
||||
pitch *= 63;
|
||||
|
||||
if (pitch < 0)
|
||||
pitch = 0;
|
||||
|
||||
if (pitch > 255)
|
||||
pitch = 255;
|
||||
|
||||
mods.write(6, (int) pitch);
|
||||
|
||||
try
|
||||
{
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,188 @@
|
||||
package me.libraryaddict.disguise.utilities.packetlisteners;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.comphenix.protocol.PacketType.Play.Server;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utilities.PacketsManager;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
|
||||
public class PacketListenerViewDisguises extends PacketAdapter
|
||||
{
|
||||
private LibsDisguises libsDisguises;
|
||||
|
||||
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,
|
||||
Server.ENTITY_VELOCITY, Server.UPDATE_ATTRIBUTES, Server.ENTITY_STATUS);
|
||||
|
||||
libsDisguises = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
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 (DisguiseAPI.isSelfDisguised(observer))
|
||||
{
|
||||
// Here I grab the packets to convert them to, So I can display them as if the disguise sent them.
|
||||
PacketContainer[][] transformed = PacketsManager.transformPacket(event.getPacket(), observer, observer);
|
||||
|
||||
PacketContainer[] packets = transformed == null ? null : transformed[0];
|
||||
|
||||
final PacketContainer[] delayedPackets = transformed == null ? null : transformed[1];
|
||||
|
||||
if (packets == null)
|
||||
{
|
||||
packets = new PacketContainer[]
|
||||
{
|
||||
event.getPacket()
|
||||
};
|
||||
}
|
||||
|
||||
for (PacketContainer packet : packets)
|
||||
{
|
||||
if (packet.getType() != Server.PLAYER_INFO)
|
||||
{
|
||||
if (packet.equals(event.getPacket()))
|
||||
{
|
||||
packet = packet.shallowClone();
|
||||
}
|
||||
|
||||
packet.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (delayedPackets != null && delayedPackets.length > 0)
|
||||
{
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
for (PacketContainer packet : delayedPackets)
|
||||
{
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
||||
}
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, 2);
|
||||
}
|
||||
|
||||
if (event.getPacketType() == Server.ENTITY_METADATA)
|
||||
{
|
||||
event.setPacket(event.getPacket().deepClone());
|
||||
|
||||
for (WrappedWatchableObject watch : event.getPacket().getWatchableCollectionModifier().read(0))
|
||||
{
|
||||
if (watch.getIndex() == 0)
|
||||
{
|
||||
byte b = (byte) watch.getValue();
|
||||
|
||||
byte a = (byte) (b | 1 << 5);
|
||||
|
||||
if ((b & 1 << 3) != 0)
|
||||
a = (byte) (a | 1 << 3);
|
||||
|
||||
watch.setValue(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (event.getPacketType() == Server.NAMED_ENTITY_SPAWN)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
|
||||
PacketContainer packet = new PacketContainer(Server.ENTITY_METADATA);
|
||||
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
|
||||
mods.write(0, observer.getEntityId());
|
||||
|
||||
List<WrappedWatchableObject> watchableList = new ArrayList<>();
|
||||
Byte b = 1 << 5;
|
||||
|
||||
if (observer.isSprinting())
|
||||
b = (byte) (b | 1 << 3);
|
||||
|
||||
WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(0, b));
|
||||
|
||||
watchableList.add(watch);
|
||||
packet.getWatchableCollectionModifier().write(0, watchableList);
|
||||
|
||||
try
|
||||
{
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet);
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
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.setCancelled(true);
|
||||
}
|
||||
else if (event.getPacketType() == Server.ENTITY_STATUS)
|
||||
{
|
||||
Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer());
|
||||
|
||||
if (disguise.isSelfDisguiseSoundsReplaced() && !disguise.getType().isPlayer()
|
||||
&& event.getPacket().getBytes().read(0) == 2)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user