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.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -151,11 +150,7 @@ public class DisguiseAPI
|
|||||||
{
|
{
|
||||||
if (toCast == float.class)
|
if (toCast == float.class)
|
||||||
{
|
{
|
||||||
if (value instanceof Float)
|
if (!(value instanceof Float))
|
||||||
{
|
|
||||||
value = value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
double d = (Double) value;
|
double d = (Double) value;
|
||||||
value = (float) d;
|
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
|
* @param disguise
|
||||||
* @return
|
* @return
|
||||||
@ -288,6 +283,7 @@ public class DisguiseAPI
|
|||||||
{
|
{
|
||||||
int id = ReflectionManager.getNmsField("Entity", "entityCount").getInt(null);
|
int id = ReflectionManager.getNmsField("Entity", "entityCount").getInt(null);
|
||||||
DisguiseUtilities.addFutureDisguise(id, (TargetedDisguise) disguise);
|
DisguiseUtilities.addFutureDisguise(id, (TargetedDisguise) disguise);
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
catch (IllegalAccessException e)
|
catch (IllegalAccessException e)
|
||||||
@ -423,18 +419,6 @@ public class DisguiseAPI
|
|||||||
return DisguiseUtilities.getDisguises(disguised.getUniqueId());
|
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()
|
public static int getSelfDisguiseId()
|
||||||
{
|
{
|
||||||
return -10;
|
return -10;
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -82,7 +82,7 @@ public abstract class Disguise
|
|||||||
if (newType.getEntityType() == null)
|
if (newType.getEntityType() == null)
|
||||||
{
|
{
|
||||||
throw new RuntimeException("DisguiseType " + newType
|
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
|
// Set the disguise type
|
||||||
|
@ -1,389 +1,387 @@
|
|||||||
package me.libraryaddict.disguise.disguisetypes;
|
package me.libraryaddict.disguise.disguisetypes;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Guardian;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.Horse;
|
||||||
import org.bukkit.entity.Guardian;
|
import org.bukkit.entity.Skeleton;
|
||||||
import org.bukkit.entity.Horse;
|
import org.bukkit.entity.Skeleton.SkeletonType;
|
||||||
import org.bukkit.entity.Skeleton;
|
import org.bukkit.entity.Zombie;
|
||||||
import org.bukkit.entity.Skeleton.SkeletonType;
|
|
||||||
import org.bukkit.entity.Zombie;
|
public enum DisguiseType
|
||||||
|
{
|
||||||
public enum DisguiseType
|
|
||||||
{
|
AREA_EFFECT_CLOUD(3, 0),
|
||||||
|
|
||||||
AREA_EFFECT_CLOUD(3, 0),
|
ARMOR_STAND(78),
|
||||||
|
|
||||||
ARMOR_STAND(78),
|
ARROW(60, 0),
|
||||||
|
|
||||||
ARROW(60, 0),
|
BAT,
|
||||||
|
|
||||||
BAT,
|
BLAZE,
|
||||||
|
|
||||||
BLAZE,
|
BOAT(1),
|
||||||
|
|
||||||
BOAT(1),
|
CAVE_SPIDER,
|
||||||
|
|
||||||
CAVE_SPIDER,
|
CHICKEN,
|
||||||
|
|
||||||
CHICKEN,
|
COW,
|
||||||
|
|
||||||
COW,
|
CREEPER,
|
||||||
|
|
||||||
CREEPER,
|
DONKEY,
|
||||||
|
|
||||||
DONKEY,
|
DRAGON_FIREBALL(93),
|
||||||
|
|
||||||
DRAGON_FIREBALL(93),
|
DROPPED_ITEM(2, 1),
|
||||||
|
|
||||||
DROPPED_ITEM(2, 1),
|
EGG(62),
|
||||||
|
|
||||||
EGG(62),
|
ELDER_GUARDIAN,
|
||||||
|
|
||||||
ELDER_GUARDIAN,
|
ENDER_CRYSTAL(51),
|
||||||
|
|
||||||
ENDER_CRYSTAL(51),
|
ENDER_DRAGON,
|
||||||
|
|
||||||
ENDER_DRAGON,
|
ENDER_PEARL(65),
|
||||||
|
|
||||||
ENDER_PEARL(65),
|
ENDER_SIGNAL(72),
|
||||||
|
|
||||||
ENDER_SIGNAL(72),
|
ENDERMAN,
|
||||||
|
|
||||||
ENDERMAN,
|
ENDERMITE,
|
||||||
|
|
||||||
ENDERMITE,
|
EXPERIENCE_ORB,
|
||||||
|
|
||||||
EXPERIENCE_ORB,
|
FALLING_BLOCK(70, 1),
|
||||||
|
|
||||||
FALLING_BLOCK(70, 1),
|
FIREBALL(63),
|
||||||
|
|
||||||
FIREBALL(63),
|
FIREWORK(76),
|
||||||
|
|
||||||
FIREWORK(76),
|
FISHING_HOOK(90),
|
||||||
|
|
||||||
FISHING_HOOK(90),
|
GHAST,
|
||||||
|
|
||||||
GHAST,
|
GIANT,
|
||||||
|
|
||||||
GIANT,
|
GUARDIAN,
|
||||||
|
|
||||||
GUARDIAN,
|
HORSE,
|
||||||
|
|
||||||
HORSE,
|
IRON_GOLEM,
|
||||||
|
|
||||||
IRON_GOLEM,
|
ITEM_FRAME(71),
|
||||||
|
|
||||||
ITEM_FRAME(71),
|
LEASH_HITCH(77),
|
||||||
|
|
||||||
LEASH_HITCH(77),
|
MAGMA_CUBE,
|
||||||
|
|
||||||
MAGMA_CUBE,
|
MINECART(10),
|
||||||
|
|
||||||
MINECART(10),
|
MINECART_CHEST(10, 1),
|
||||||
|
|
||||||
MINECART_CHEST(10, 1),
|
MINECART_COMMAND(10, 6),
|
||||||
|
|
||||||
MINECART_COMMAND(10, 6),
|
MINECART_FURNACE(10, 2),
|
||||||
|
|
||||||
MINECART_FURNACE(10, 2),
|
MINECART_HOPPER(10, 5),
|
||||||
|
|
||||||
MINECART_HOPPER(10, 5),
|
MINECART_MOB_SPAWNER(10, 4),
|
||||||
|
|
||||||
MINECART_MOB_SPAWNER(10, 4),
|
MINECART_TNT(10, 3),
|
||||||
|
|
||||||
MINECART_TNT(10, 3),
|
MULE,
|
||||||
|
|
||||||
MULE,
|
MUSHROOM_COW,
|
||||||
|
|
||||||
MUSHROOM_COW,
|
OCELOT,
|
||||||
|
|
||||||
OCELOT,
|
PAINTING,
|
||||||
|
|
||||||
PAINTING,
|
PIG,
|
||||||
|
|
||||||
PIG,
|
PIG_ZOMBIE,
|
||||||
|
|
||||||
PIG_ZOMBIE,
|
PLAYER,
|
||||||
|
|
||||||
PLAYER,
|
PRIMED_TNT(50),
|
||||||
|
|
||||||
PRIMED_TNT(50),
|
RABBIT,
|
||||||
|
|
||||||
RABBIT,
|
SHEEP,
|
||||||
|
|
||||||
SHEEP,
|
SHULKER,
|
||||||
|
|
||||||
SHULKER,
|
SHULKER_BULLET(67),
|
||||||
|
|
||||||
SHULKER_BULLET(67),
|
SILVERFISH,
|
||||||
|
|
||||||
SILVERFISH,
|
SKELETON,
|
||||||
|
|
||||||
SKELETON,
|
SKELETON_HORSE,
|
||||||
|
|
||||||
SKELETON_HORSE,
|
SLIME,
|
||||||
|
|
||||||
SLIME,
|
SMALL_FIREBALL(63),
|
||||||
|
|
||||||
SMALL_FIREBALL(63),
|
SNOWBALL(61),
|
||||||
|
|
||||||
SNOWBALL(61),
|
SNOWMAN,
|
||||||
|
|
||||||
SNOWMAN,
|
SPECTRAL_ARROW(91),
|
||||||
|
|
||||||
SPECTRAL_ARROW(91),
|
SPIDER,
|
||||||
|
|
||||||
SPIDER,
|
SPLASH_POTION(73, 0),
|
||||||
|
|
||||||
SPLASH_POTION(73, 0),
|
SQUID,
|
||||||
|
|
||||||
SQUID,
|
TIPPED_ARROW(92),
|
||||||
|
|
||||||
TIPPED_ARROW(92),
|
THROWN_EXP_BOTTLE(75),
|
||||||
|
|
||||||
THROWN_EXP_BOTTLE(75),
|
UNDEAD_HORSE,
|
||||||
|
|
||||||
UNDEAD_HORSE,
|
VILLAGER,
|
||||||
|
|
||||||
VILLAGER,
|
WITCH,
|
||||||
|
|
||||||
WITCH,
|
WITHER,
|
||||||
|
|
||||||
WITHER,
|
WITHER_SKELETON,
|
||||||
|
|
||||||
WITHER_SKELETON,
|
WITHER_SKULL(66),
|
||||||
|
|
||||||
WITHER_SKULL(66),
|
WOLF,
|
||||||
|
|
||||||
WOLF,
|
ZOMBIE,
|
||||||
|
|
||||||
ZOMBIE,
|
ZOMBIE_VILLAGER,
|
||||||
|
|
||||||
ZOMBIE_VILLAGER,
|
UNKNOWN;
|
||||||
|
|
||||||
UNKNOWN;
|
static
|
||||||
|
{
|
||||||
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.
|
||||||
// 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())
|
||||||
|
{
|
||||||
for (DisguiseType type : values())
|
|
||||||
{
|
try
|
||||||
|
{
|
||||||
try
|
DisguiseType toUse = type;
|
||||||
{
|
String name;
|
||||||
DisguiseType toUse = type;
|
|
||||||
String name;
|
switch (type)
|
||||||
|
{
|
||||||
switch (type)
|
// Disguise item frame isn't supported. So we don't give it a entity type which should prevent it from being..
|
||||||
{
|
// Usable.
|
||||||
// Disguise item frame isn't supported. So we don't give it a entity type which should prevent it from being..
|
case ITEM_FRAME:
|
||||||
// Usable.
|
break;
|
||||||
case ITEM_FRAME:
|
case DONKEY:
|
||||||
break;
|
case MULE:
|
||||||
case DONKEY:
|
case UNDEAD_HORSE:
|
||||||
case MULE:
|
case SKELETON_HORSE:
|
||||||
case UNDEAD_HORSE:
|
toUse = DisguiseType.HORSE;
|
||||||
case SKELETON_HORSE:
|
break;
|
||||||
toUse = DisguiseType.HORSE;
|
case ZOMBIE_VILLAGER:
|
||||||
break;
|
toUse = DisguiseType.ZOMBIE;
|
||||||
case ZOMBIE_VILLAGER:
|
break;
|
||||||
toUse = DisguiseType.ZOMBIE;
|
case WITHER_SKELETON:
|
||||||
break;
|
toUse = DisguiseType.SKELETON;
|
||||||
case WITHER_SKELETON:
|
break;
|
||||||
toUse = DisguiseType.SKELETON;
|
case ELDER_GUARDIAN:
|
||||||
break;
|
toUse = DisguiseType.GUARDIAN;
|
||||||
case ELDER_GUARDIAN:
|
break;
|
||||||
toUse = DisguiseType.GUARDIAN;
|
default:
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
break;
|
|
||||||
}
|
name = toUse.name();
|
||||||
|
|
||||||
name = toUse.name();
|
type.setEntityType(EntityType.valueOf(name));
|
||||||
|
}
|
||||||
type.setEntityType(EntityType.valueOf(name));
|
catch (Throwable ex)
|
||||||
}
|
{
|
||||||
catch (Throwable ex)
|
// This version of Spigot doesn't have the disguise.
|
||||||
{
|
}
|
||||||
// This version of Spigot doesn't have the disguise.
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
public static DisguiseType getType(Entity entity)
|
||||||
|
{
|
||||||
public static DisguiseType getType(Entity entity)
|
DisguiseType disguiseType = getType(entity.getType());
|
||||||
{
|
|
||||||
DisguiseType disguiseType = getType(entity.getType());
|
switch (disguiseType)
|
||||||
|
{
|
||||||
switch (disguiseType)
|
case ZOMBIE:
|
||||||
{
|
|
||||||
case ZOMBIE:
|
if (((Zombie) entity).isVillager())
|
||||||
|
{
|
||||||
if (((Zombie) entity).isVillager())
|
disguiseType = DisguiseType.ZOMBIE_VILLAGER;
|
||||||
{
|
}
|
||||||
disguiseType = DisguiseType.ZOMBIE_VILLAGER;
|
|
||||||
}
|
break;
|
||||||
|
|
||||||
break;
|
case HORSE:
|
||||||
|
|
||||||
case HORSE:
|
disguiseType = DisguiseType.valueOf(((Horse) entity).getVariant().name());
|
||||||
|
|
||||||
disguiseType = DisguiseType.valueOf(((Horse) entity).getVariant().name());
|
break;
|
||||||
|
|
||||||
break;
|
case SKELETON:
|
||||||
|
|
||||||
case SKELETON:
|
if (((Skeleton) entity).getSkeletonType() == SkeletonType.WITHER)
|
||||||
|
{
|
||||||
if (((Skeleton) entity).getSkeletonType() == SkeletonType.WITHER)
|
disguiseType = DisguiseType.WITHER_SKELETON;
|
||||||
{
|
}
|
||||||
disguiseType = DisguiseType.WITHER_SKELETON;
|
|
||||||
}
|
break;
|
||||||
|
case GUARDIAN:
|
||||||
break;
|
|
||||||
case GUARDIAN:
|
if (((Guardian) entity).isElder())
|
||||||
|
{
|
||||||
if (((Guardian) entity).isElder())
|
disguiseType = DisguiseType.ELDER_GUARDIAN;
|
||||||
{
|
}
|
||||||
disguiseType = DisguiseType.ELDER_GUARDIAN;
|
|
||||||
}
|
break;
|
||||||
|
default:
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
break;
|
|
||||||
}
|
return disguiseType;
|
||||||
|
|
||||||
return disguiseType;
|
}
|
||||||
|
|
||||||
}
|
public static DisguiseType getType(EntityType entityType)
|
||||||
|
{
|
||||||
public static DisguiseType getType(EntityType entityType)
|
try
|
||||||
{
|
{
|
||||||
try
|
return valueOf(entityType.name().toUpperCase());
|
||||||
{
|
}
|
||||||
return valueOf(entityType.name().toUpperCase());
|
catch (Throwable ex)
|
||||||
}
|
{
|
||||||
catch (Throwable ex)
|
return DisguiseType.UNKNOWN;
|
||||||
{
|
}
|
||||||
return DisguiseType.UNKNOWN;
|
}
|
||||||
}
|
|
||||||
}
|
private int objectId = -1, defaultData = 0;
|
||||||
|
|
||||||
private int objectId = -1, defaultData = 0;
|
private EntityType entityType;
|
||||||
|
|
||||||
private EntityType entityType;
|
private Class<? extends FlagWatcher> watcherClass;
|
||||||
|
|
||||||
private Class<? extends FlagWatcher> watcherClass;
|
DisguiseType(int... ints)
|
||||||
|
{
|
||||||
DisguiseType(int... ints)
|
for (int i = 0; i < ints.length; i++)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < ints.length; i++)
|
int value = ints[i];
|
||||||
{
|
|
||||||
int value = ints[i];
|
switch (i)
|
||||||
|
{
|
||||||
switch (i)
|
case 0:
|
||||||
{
|
objectId = value;
|
||||||
case 0:
|
|
||||||
objectId = value;
|
break;
|
||||||
|
case 1:
|
||||||
break;
|
defaultData = value;
|
||||||
case 1:
|
|
||||||
defaultData = value;
|
break;
|
||||||
|
default:
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
public int getDefaultData()
|
||||||
|
{
|
||||||
public int getDefaultData()
|
return defaultData;
|
||||||
{
|
}
|
||||||
return defaultData;
|
|
||||||
}
|
public Class<? extends Entity> getEntityClass()
|
||||||
|
{
|
||||||
public Class<? extends Entity> getEntityClass()
|
if (entityType != null)
|
||||||
{
|
{
|
||||||
if (entityType != null)
|
return getEntityType().getEntityClass();
|
||||||
{
|
}
|
||||||
return getEntityType().getEntityClass();
|
|
||||||
}
|
return Entity.class;
|
||||||
|
}
|
||||||
return Entity.class;
|
|
||||||
}
|
public EntityType getEntityType()
|
||||||
|
{
|
||||||
public EntityType getEntityType()
|
return entityType;
|
||||||
{
|
}
|
||||||
return entityType;
|
|
||||||
}
|
/**
|
||||||
|
* The TYPE id of this entity. Different from the Object Id send in spawn packets when spawning miscs.
|
||||||
/**
|
*
|
||||||
* The TYPE id of this entity. Different from the Object Id send in spawn packets when spawning miscs.
|
* @return
|
||||||
*
|
*/
|
||||||
* @return
|
public int getTypeId()
|
||||||
*/
|
{
|
||||||
public int getTypeId()
|
return (int) getEntityType().getTypeId();
|
||||||
{
|
}
|
||||||
return (int) getEntityType().getTypeId();
|
|
||||||
}
|
/**
|
||||||
|
* The object type send in packets when spawning a misc entity. Otherwise, -1.
|
||||||
/**
|
*
|
||||||
* The object type send in packets when spawning a misc entity. Otherwise, -1.
|
* @return
|
||||||
*
|
*/
|
||||||
* @return
|
public int getObjectId()
|
||||||
*/
|
{
|
||||||
public int getObjectId()
|
return objectId;
|
||||||
{
|
}
|
||||||
return objectId;
|
|
||||||
}
|
public Class getWatcherClass()
|
||||||
|
{
|
||||||
public Class getWatcherClass()
|
return watcherClass;
|
||||||
{
|
}
|
||||||
return watcherClass;
|
|
||||||
}
|
public boolean isMisc()
|
||||||
|
{
|
||||||
public boolean isMisc()
|
return getEntityType() != null && !getEntityType().isAlive();
|
||||||
{
|
}
|
||||||
return getEntityType() != null && !getEntityType().isAlive();
|
|
||||||
}
|
public boolean isMob()
|
||||||
|
{
|
||||||
public boolean isMob()
|
return getEntityType() != null && getEntityType().isAlive() && !isPlayer();
|
||||||
{
|
}
|
||||||
return getEntityType() != null && getEntityType().isAlive() && !isPlayer();
|
|
||||||
}
|
public boolean isPlayer()
|
||||||
|
{
|
||||||
public boolean isPlayer()
|
return this == DisguiseType.PLAYER;
|
||||||
{
|
}
|
||||||
return this == DisguiseType.PLAYER;
|
|
||||||
}
|
public boolean isUnknown()
|
||||||
|
{
|
||||||
public boolean isUnknown()
|
return this == DisguiseType.UNKNOWN;
|
||||||
{
|
}
|
||||||
return this == DisguiseType.UNKNOWN;
|
|
||||||
}
|
private void setEntityType(EntityType entityType)
|
||||||
|
{
|
||||||
private void setEntityType(EntityType entityType)
|
this.entityType = entityType;
|
||||||
{
|
}
|
||||||
this.entityType = entityType;
|
|
||||||
}
|
public void setWatcherClass(Class<? extends FlagWatcher> c)
|
||||||
|
{
|
||||||
public void setWatcherClass(Class<? extends FlagWatcher> c)
|
watcherClass = c;
|
||||||
{
|
}
|
||||||
watcherClass = c;
|
|
||||||
}
|
public String toReadable()
|
||||||
|
{
|
||||||
public String toReadable()
|
String[] split = name().split("_");
|
||||||
{
|
|
||||||
String[] split = name().split("_");
|
for (int i = 0; i < split.length; i++)
|
||||||
|
{
|
||||||
for (int i = 0; i < split.length; i++)
|
split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase();
|
||||||
{
|
}
|
||||||
split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase();
|
|
||||||
}
|
return StringUtils.join(split, " ");
|
||||||
|
}
|
||||||
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 java.security.InvalidParameterException;
|
||||||
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
||||||
|
|
||||||
public class MobDisguise extends TargetedDisguise {
|
public class MobDisguise extends TargetedDisguise
|
||||||
|
{
|
||||||
|
|
||||||
private boolean isAdult;
|
private boolean isAdult;
|
||||||
|
|
||||||
public MobDisguise(DisguiseType disguiseType) {
|
public MobDisguise(DisguiseType disguiseType)
|
||||||
|
{
|
||||||
this(disguiseType, true);
|
this(disguiseType, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MobDisguise(DisguiseType disguiseType, boolean isAdult) {
|
public MobDisguise(DisguiseType disguiseType, boolean isAdult)
|
||||||
if (!disguiseType.isMob()) {
|
{
|
||||||
|
if (!disguiseType.isMob())
|
||||||
|
{
|
||||||
throw new InvalidParameterException("Expected a living DisguiseType while constructing MobDisguise. Received "
|
throw new InvalidParameterException("Expected a living DisguiseType while constructing MobDisguise. Received "
|
||||||
+ disguiseType + " instead. Please use " + (disguiseType.isPlayer() ? "PlayerDisguise" : "MiscDisguise")
|
+ disguiseType + " instead. Please use " + (disguiseType.isPlayer() ? "PlayerDisguise" : "MiscDisguise")
|
||||||
+ " instead");
|
+ " instead");
|
||||||
@ -28,40 +31,21 @@ public class MobDisguise extends TargetedDisguise {
|
|||||||
createDisguise(disguiseType);
|
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
|
@Override
|
||||||
public MobDisguise addPlayer(Player player) {
|
public MobDisguise addPlayer(Player player)
|
||||||
|
{
|
||||||
return (MobDisguise) super.addPlayer(player);
|
return (MobDisguise) super.addPlayer(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobDisguise addPlayer(String playername) {
|
public MobDisguise addPlayer(String playername)
|
||||||
|
{
|
||||||
return (MobDisguise) super.addPlayer(playername);
|
return (MobDisguise) super.addPlayer(playername);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobDisguise clone() {
|
public MobDisguise clone()
|
||||||
|
{
|
||||||
MobDisguise disguise = new MobDisguise(getType(), isAdult());
|
MobDisguise disguise = new MobDisguise(getType(), isAdult());
|
||||||
disguise.setReplaceSounds(isSoundsReplaced());
|
disguise.setReplaceSounds(isSoundsReplaced());
|
||||||
disguise.setViewSelfDisguise(isSelfDisguiseVisible());
|
disguise.setViewSelfDisguise(isSelfDisguiseVisible());
|
||||||
@ -74,20 +58,27 @@ public class MobDisguise extends TargetedDisguise {
|
|||||||
return disguise;
|
return disguise;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean doesDisguiseAge() {
|
public boolean doesDisguiseAge()
|
||||||
|
{
|
||||||
return getWatcher() != null && (getWatcher() instanceof AgeableWatcher || getWatcher() instanceof ZombieWatcher);
|
return getWatcher() != null && (getWatcher() instanceof AgeableWatcher || getWatcher() instanceof ZombieWatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LivingWatcher getWatcher() {
|
public LivingWatcher getWatcher()
|
||||||
|
{
|
||||||
return (LivingWatcher) super.getWatcher();
|
return (LivingWatcher) super.getWatcher();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAdult() {
|
public boolean isAdult()
|
||||||
if (getWatcher() != null) {
|
{
|
||||||
if (getWatcher() instanceof AgeableWatcher) {
|
if (getWatcher() != null)
|
||||||
|
{
|
||||||
|
if (getWatcher() instanceof AgeableWatcher)
|
||||||
|
{
|
||||||
return ((AgeableWatcher) getWatcher()).isAdult();
|
return ((AgeableWatcher) getWatcher()).isAdult();
|
||||||
} else if (getWatcher() instanceof ZombieWatcher) {
|
}
|
||||||
|
else if (getWatcher() instanceof ZombieWatcher)
|
||||||
|
{
|
||||||
return ((ZombieWatcher) getWatcher()).isAdult();
|
return ((ZombieWatcher) getWatcher()).isAdult();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -96,92 +87,110 @@ public class MobDisguise extends TargetedDisguise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMobDisguise() {
|
public boolean isMobDisguise()
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobDisguise removePlayer(Player player) {
|
public MobDisguise removePlayer(Player player)
|
||||||
|
{
|
||||||
return (MobDisguise) super.removePlayer(player);
|
return (MobDisguise) super.removePlayer(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobDisguise removePlayer(String playername) {
|
public MobDisguise removePlayer(String playername)
|
||||||
|
{
|
||||||
return (MobDisguise) super.removePlayer(playername);
|
return (MobDisguise) super.removePlayer(playername);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobDisguise setDisguiseTarget(TargetType newTargetType) {
|
public MobDisguise setDisguiseTarget(TargetType newTargetType)
|
||||||
|
{
|
||||||
return (MobDisguise) super.setDisguiseTarget(newTargetType);
|
return (MobDisguise) super.setDisguiseTarget(newTargetType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobDisguise setEntity(Entity entity) {
|
public MobDisguise setEntity(Entity entity)
|
||||||
|
{
|
||||||
return (MobDisguise) super.setEntity(entity);
|
return (MobDisguise) super.setEntity(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobDisguise setHearSelfDisguise(boolean hearSelfDisguise) {
|
public MobDisguise setHearSelfDisguise(boolean hearSelfDisguise)
|
||||||
|
{
|
||||||
return (MobDisguise) super.setHearSelfDisguise(hearSelfDisguise);
|
return (MobDisguise) super.setHearSelfDisguise(hearSelfDisguise);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobDisguise setHideArmorFromSelf(boolean hideArmor) {
|
public MobDisguise setHideArmorFromSelf(boolean hideArmor)
|
||||||
|
{
|
||||||
return (MobDisguise) super.setHideArmorFromSelf(hideArmor);
|
return (MobDisguise) super.setHideArmorFromSelf(hideArmor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobDisguise setHideHeldItemFromSelf(boolean hideHeldItem) {
|
public MobDisguise setHideHeldItemFromSelf(boolean hideHeldItem)
|
||||||
|
{
|
||||||
return (MobDisguise) super.setHideHeldItemFromSelf(hideHeldItem);
|
return (MobDisguise) super.setHideHeldItemFromSelf(hideHeldItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobDisguise setKeepDisguiseOnEntityDespawn(boolean keepDisguise) {
|
public MobDisguise setKeepDisguiseOnEntityDespawn(boolean keepDisguise)
|
||||||
|
{
|
||||||
return (MobDisguise) super.setKeepDisguiseOnEntityDespawn(keepDisguise);
|
return (MobDisguise) super.setKeepDisguiseOnEntityDespawn(keepDisguise);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobDisguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
|
public MobDisguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise)
|
||||||
|
{
|
||||||
return (MobDisguise) super.setKeepDisguiseOnPlayerDeath(keepDisguise);
|
return (MobDisguise) super.setKeepDisguiseOnPlayerDeath(keepDisguise);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobDisguise setKeepDisguiseOnPlayerLogout(boolean keepDisguise) {
|
public MobDisguise setKeepDisguiseOnPlayerLogout(boolean keepDisguise)
|
||||||
|
{
|
||||||
return (MobDisguise) super.setKeepDisguiseOnPlayerLogout(keepDisguise);
|
return (MobDisguise) super.setKeepDisguiseOnPlayerLogout(keepDisguise);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobDisguise setModifyBoundingBox(boolean modifyBox) {
|
public MobDisguise setModifyBoundingBox(boolean modifyBox)
|
||||||
|
{
|
||||||
return (MobDisguise) super.setModifyBoundingBox(modifyBox);
|
return (MobDisguise) super.setModifyBoundingBox(modifyBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobDisguise setReplaceSounds(boolean areSoundsReplaced) {
|
public MobDisguise setReplaceSounds(boolean areSoundsReplaced)
|
||||||
|
{
|
||||||
return (MobDisguise) super.setReplaceSounds(areSoundsReplaced);
|
return (MobDisguise) super.setReplaceSounds(areSoundsReplaced);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobDisguise setVelocitySent(boolean sendVelocity) {
|
public MobDisguise setVelocitySent(boolean sendVelocity)
|
||||||
|
{
|
||||||
return (MobDisguise) super.setVelocitySent(sendVelocity);
|
return (MobDisguise) super.setVelocitySent(sendVelocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobDisguise setViewSelfDisguise(boolean viewSelfDisguise) {
|
public MobDisguise setViewSelfDisguise(boolean viewSelfDisguise)
|
||||||
|
{
|
||||||
return (MobDisguise) super.setViewSelfDisguise(viewSelfDisguise);
|
return (MobDisguise) super.setViewSelfDisguise(viewSelfDisguise);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobDisguise setWatcher(FlagWatcher newWatcher) {
|
public MobDisguise setWatcher(FlagWatcher newWatcher)
|
||||||
|
{
|
||||||
return (MobDisguise) super.setWatcher(newWatcher);
|
return (MobDisguise) super.setWatcher(newWatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobDisguise silentlyAddPlayer(String playername) {
|
public MobDisguise silentlyAddPlayer(String playername)
|
||||||
|
{
|
||||||
return (MobDisguise) super.silentlyAddPlayer(playername);
|
return (MobDisguise) super.silentlyAddPlayer(playername);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobDisguise silentlyRemovePlayer(String playername) {
|
public MobDisguise silentlyRemovePlayer(String playername)
|
||||||
|
{
|
||||||
return (MobDisguise) super.silentlyRemovePlayer(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.LibsProfileLookup;
|
||||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||||
|
|
||||||
public class PlayerDisguise extends TargetedDisguise {
|
public class PlayerDisguise extends TargetedDisguise
|
||||||
|
{
|
||||||
|
|
||||||
private LibsProfileLookup currentLookup;
|
private LibsProfileLookup currentLookup;
|
||||||
private WrappedGameProfile gameProfile;
|
private WrappedGameProfile gameProfile;
|
||||||
private String playerName;
|
private String playerName;
|
||||||
private String skinToUse;
|
private String skinToUse;
|
||||||
|
|
||||||
public PlayerDisguise(String name) {
|
public PlayerDisguise(String name)
|
||||||
if (name.length() > 16) {
|
{
|
||||||
|
if (name.length() > 16)
|
||||||
|
{
|
||||||
name = name.substring(0, 16);
|
name = name.substring(0, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
playerName = name;
|
playerName = name;
|
||||||
createDisguise(DisguiseType.PLAYER);
|
createDisguise(DisguiseType.PLAYER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
public PlayerDisguise(String name, String skinToUse)
|
||||||
public PlayerDisguise(String name, boolean replaceSounds) {
|
{
|
||||||
this(name);
|
|
||||||
this.setReplaceSounds(replaceSounds);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlayerDisguise(String name, String skinToUse) {
|
|
||||||
this(name);
|
this(name);
|
||||||
setSkin(skinToUse);
|
setSkin(skinToUse);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerDisguise(WrappedGameProfile gameProfile) {
|
public PlayerDisguise(Player player)
|
||||||
|
{
|
||||||
|
this(ReflectionManager.getGameProfile(player));
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerDisguise(WrappedGameProfile gameProfile)
|
||||||
|
{
|
||||||
this(gameProfile.getName());
|
this(gameProfile.getName());
|
||||||
|
|
||||||
this.gameProfile = gameProfile;
|
this.gameProfile = gameProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDisguise addPlayer(Player player) {
|
public PlayerDisguise addPlayer(Player player)
|
||||||
|
{
|
||||||
return (PlayerDisguise) super.addPlayer(player);
|
return (PlayerDisguise) super.addPlayer(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDisguise addPlayer(String playername) {
|
public PlayerDisguise addPlayer(String playername)
|
||||||
|
{
|
||||||
return (PlayerDisguise) super.addPlayer(playername);
|
return (PlayerDisguise) super.addPlayer(playername);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDisguise clone() {
|
public PlayerDisguise clone()
|
||||||
|
{
|
||||||
PlayerDisguise disguise = new PlayerDisguise(getName());
|
PlayerDisguise disguise = new PlayerDisguise(getName());
|
||||||
if (disguise.currentLookup == null && disguise.gameProfile != null) {
|
|
||||||
|
if (disguise.currentLookup == null && disguise.gameProfile != null)
|
||||||
|
{
|
||||||
disguise.skinToUse = getSkin();
|
disguise.skinToUse = getSkin();
|
||||||
disguise.gameProfile = gameProfile;
|
disguise.gameProfile = gameProfile;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
disguise.setSkin(getSkin());
|
disguise.setSkin(getSkin());
|
||||||
}
|
}
|
||||||
|
|
||||||
disguise.setReplaceSounds(isSoundsReplaced());
|
disguise.setReplaceSounds(isSoundsReplaced());
|
||||||
disguise.setViewSelfDisguise(isSelfDisguiseVisible());
|
disguise.setViewSelfDisguise(isSelfDisguiseVisible());
|
||||||
disguise.setHearSelfDisguise(isSelfDisguiseSoundsReplaced());
|
disguise.setHearSelfDisguise(isSelfDisguiseSoundsReplaced());
|
||||||
@ -70,175 +84,229 @@ public class PlayerDisguise extends TargetedDisguise {
|
|||||||
disguise.setVelocitySent(isVelocitySent());
|
disguise.setVelocitySent(isVelocitySent());
|
||||||
disguise.setModifyBoundingBox(isModifyBoundingBox());
|
disguise.setModifyBoundingBox(isModifyBoundingBox());
|
||||||
disguise.setWatcher(getWatcher().clone(disguise));
|
disguise.setWatcher(getWatcher().clone(disguise));
|
||||||
|
|
||||||
return disguise;
|
return disguise;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGameProfile(WrappedGameProfile gameProfile) {
|
public void setGameProfile(WrappedGameProfile gameProfile)
|
||||||
|
{
|
||||||
this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, gameProfile.getName(), gameProfile);
|
this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, gameProfile.getName(), gameProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WrappedGameProfile getGameProfile() {
|
public WrappedGameProfile getGameProfile()
|
||||||
if (gameProfile == null) {
|
{
|
||||||
if (getSkin() != null) {
|
if (gameProfile == null)
|
||||||
|
{
|
||||||
|
if (getSkin() != null)
|
||||||
|
{
|
||||||
gameProfile = ReflectionManager.getGameProfile(null, getName());
|
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;
|
return gameProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName()
|
||||||
|
{
|
||||||
return playerName;
|
return playerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSkin() {
|
public String getSkin()
|
||||||
|
{
|
||||||
return skinToUse;
|
return skinToUse;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerWatcher getWatcher() {
|
public PlayerWatcher getWatcher()
|
||||||
|
{
|
||||||
return (PlayerWatcher) super.getWatcher();
|
return (PlayerWatcher) super.getWatcher();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPlayerDisguise() {
|
public boolean isPlayerDisguise()
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDisguise removePlayer(Player player) {
|
public PlayerDisguise removePlayer(Player player)
|
||||||
|
{
|
||||||
return (PlayerDisguise) super.removePlayer(player);
|
return (PlayerDisguise) super.removePlayer(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDisguise removePlayer(String playername) {
|
public PlayerDisguise removePlayer(String playername)
|
||||||
|
{
|
||||||
return (PlayerDisguise) super.removePlayer(playername);
|
return (PlayerDisguise) super.removePlayer(playername);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDisguise setDisguiseTarget(TargetType newTargetType) {
|
public PlayerDisguise setDisguiseTarget(TargetType newTargetType)
|
||||||
|
{
|
||||||
return (PlayerDisguise) super.setDisguiseTarget(newTargetType);
|
return (PlayerDisguise) super.setDisguiseTarget(newTargetType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDisguise setEntity(Entity entity) {
|
public PlayerDisguise setEntity(Entity entity)
|
||||||
|
{
|
||||||
return (PlayerDisguise) super.setEntity(entity);
|
return (PlayerDisguise) super.setEntity(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDisguise setHearSelfDisguise(boolean hearSelfDisguise) {
|
public PlayerDisguise setHearSelfDisguise(boolean hearSelfDisguise)
|
||||||
|
{
|
||||||
return (PlayerDisguise) super.setHearSelfDisguise(hearSelfDisguise);
|
return (PlayerDisguise) super.setHearSelfDisguise(hearSelfDisguise);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDisguise setHideArmorFromSelf(boolean hideArmor) {
|
public PlayerDisguise setHideArmorFromSelf(boolean hideArmor)
|
||||||
|
{
|
||||||
return (PlayerDisguise) super.setHideArmorFromSelf(hideArmor);
|
return (PlayerDisguise) super.setHideArmorFromSelf(hideArmor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDisguise setHideHeldItemFromSelf(boolean hideHeldItem) {
|
public PlayerDisguise setHideHeldItemFromSelf(boolean hideHeldItem)
|
||||||
|
{
|
||||||
return (PlayerDisguise) super.setHideHeldItemFromSelf(hideHeldItem);
|
return (PlayerDisguise) super.setHideHeldItemFromSelf(hideHeldItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDisguise setKeepDisguiseOnEntityDespawn(boolean keepDisguise) {
|
public PlayerDisguise setKeepDisguiseOnEntityDespawn(boolean keepDisguise)
|
||||||
|
{
|
||||||
return (PlayerDisguise) super.setKeepDisguiseOnEntityDespawn(keepDisguise);
|
return (PlayerDisguise) super.setKeepDisguiseOnEntityDespawn(keepDisguise);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDisguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
|
public PlayerDisguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise)
|
||||||
|
{
|
||||||
return (PlayerDisguise) super.setKeepDisguiseOnPlayerDeath(keepDisguise);
|
return (PlayerDisguise) super.setKeepDisguiseOnPlayerDeath(keepDisguise);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDisguise setKeepDisguiseOnPlayerLogout(boolean keepDisguise) {
|
public PlayerDisguise setKeepDisguiseOnPlayerLogout(boolean keepDisguise)
|
||||||
|
{
|
||||||
return (PlayerDisguise) super.setKeepDisguiseOnPlayerLogout(keepDisguise);
|
return (PlayerDisguise) super.setKeepDisguiseOnPlayerLogout(keepDisguise);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDisguise setModifyBoundingBox(boolean modifyBox) {
|
public PlayerDisguise setModifyBoundingBox(boolean modifyBox)
|
||||||
|
{
|
||||||
return (PlayerDisguise) super.setModifyBoundingBox(modifyBox);
|
return (PlayerDisguise) super.setModifyBoundingBox(modifyBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDisguise setReplaceSounds(boolean areSoundsReplaced) {
|
public PlayerDisguise setReplaceSounds(boolean areSoundsReplaced)
|
||||||
|
{
|
||||||
return (PlayerDisguise) super.setReplaceSounds(areSoundsReplaced);
|
return (PlayerDisguise) super.setReplaceSounds(areSoundsReplaced);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerDisguise setSkin(String skinToUse) {
|
public PlayerDisguise setSkin(String skinToUse)
|
||||||
|
{
|
||||||
this.skinToUse = skinToUse;
|
this.skinToUse = skinToUse;
|
||||||
if (skinToUse == null) {
|
|
||||||
|
if (skinToUse == null)
|
||||||
|
{
|
||||||
this.currentLookup = null;
|
this.currentLookup = null;
|
||||||
this.gameProfile = null;
|
this.gameProfile = null;
|
||||||
} else {
|
}
|
||||||
if (skinToUse.length() > 16) {
|
else
|
||||||
|
{
|
||||||
|
if (skinToUse.length() > 16)
|
||||||
|
{
|
||||||
this.skinToUse = skinToUse.substring(0, 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
|
@Override
|
||||||
public void onLookup(WrappedGameProfile gameProfile) {
|
public void onLookup(WrappedGameProfile gameProfile)
|
||||||
if (currentLookup == this && gameProfile != null) {
|
{
|
||||||
|
if (currentLookup == this && gameProfile != null)
|
||||||
|
{
|
||||||
setSkin(gameProfile);
|
setSkin(gameProfile);
|
||||||
if (!gameProfile.getProperties().isEmpty() && DisguiseUtilities.isDisguiseInUse(PlayerDisguise.this)) {
|
|
||||||
|
if (!gameProfile.getProperties().isEmpty() && DisguiseUtilities.isDisguiseInUse(PlayerDisguise.this))
|
||||||
|
{
|
||||||
DisguiseUtilities.refreshTrackers(PlayerDisguise.this);
|
DisguiseUtilities.refreshTrackers(PlayerDisguise.this);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentLookup = null;
|
currentLookup = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup);
|
WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup);
|
||||||
if (gameProfile != null) {
|
|
||||||
|
if (gameProfile != null)
|
||||||
|
{
|
||||||
setSkin(gameProfile);
|
setSkin(gameProfile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the GameProfile, without tampering.
|
* Set the GameProfile, without tampering.
|
||||||
*
|
*
|
||||||
* @param gameProfile GameProfile
|
* @param gameProfile
|
||||||
|
* GameProfile
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public PlayerDisguise setSkin(WrappedGameProfile gameProfile) {
|
public PlayerDisguise setSkin(WrappedGameProfile gameProfile)
|
||||||
if (gameProfile == null) {
|
{
|
||||||
|
if (gameProfile == null)
|
||||||
|
{
|
||||||
this.gameProfile = null;
|
this.gameProfile = null;
|
||||||
this.skinToUse = null;
|
this.skinToUse = null;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
if (LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true)) {
|
|
||||||
|
if (LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true))
|
||||||
|
{
|
||||||
Validate.notEmpty(gameProfile.getName(), "Name must be set");
|
Validate.notEmpty(gameProfile.getName(), "Name must be set");
|
||||||
this.skinToUse = gameProfile.getName();
|
this.skinToUse = gameProfile.getName();
|
||||||
this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, getName(), gameProfile);
|
this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, getName(), gameProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDisguise setVelocitySent(boolean sendVelocity) {
|
public PlayerDisguise setVelocitySent(boolean sendVelocity)
|
||||||
|
{
|
||||||
return (PlayerDisguise) super.setVelocitySent(sendVelocity);
|
return (PlayerDisguise) super.setVelocitySent(sendVelocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDisguise setViewSelfDisguise(boolean viewSelfDisguise) {
|
public PlayerDisguise setViewSelfDisguise(boolean viewSelfDisguise)
|
||||||
|
{
|
||||||
return (PlayerDisguise) super.setViewSelfDisguise(viewSelfDisguise);
|
return (PlayerDisguise) super.setViewSelfDisguise(viewSelfDisguise);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDisguise setWatcher(FlagWatcher newWatcher) {
|
public PlayerDisguise setWatcher(FlagWatcher newWatcher)
|
||||||
|
{
|
||||||
return (PlayerDisguise) super.setWatcher(newWatcher);
|
return (PlayerDisguise) super.setWatcher(newWatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDisguise silentlyAddPlayer(String playername) {
|
public PlayerDisguise silentlyAddPlayer(String playername)
|
||||||
|
{
|
||||||
return (PlayerDisguise) super.silentlyAddPlayer(playername);
|
return (PlayerDisguise) super.silentlyAddPlayer(playername);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDisguise silentlyRemovePlayer(String playername) {
|
public PlayerDisguise silentlyRemovePlayer(String playername)
|
||||||
|
{
|
||||||
return (PlayerDisguise) super.silentlyRemovePlayer(playername);
|
return (PlayerDisguise) super.silentlyRemovePlayer(playername);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,36 +1,39 @@
|
|||||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||||
|
|
||||||
import org.bukkit.entity.Entity;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
public class AgeableWatcher extends LivingWatcher
|
||||||
|
{
|
||||||
public class AgeableWatcher extends LivingWatcher {
|
|
||||||
|
public AgeableWatcher(Disguise disguise)
|
||||||
public AgeableWatcher(Disguise disguise) {
|
{
|
||||||
super(disguise);
|
super(disguise);
|
||||||
Entity e;
|
}
|
||||||
|
|
||||||
}
|
public boolean isAdult()
|
||||||
|
{
|
||||||
public boolean isAdult() {
|
return !isBaby();
|
||||||
return !isBaby();
|
}
|
||||||
}
|
|
||||||
|
public boolean isBaby()
|
||||||
public boolean isBaby() {
|
{
|
||||||
return (boolean) getValue(11, false);
|
return (boolean) getValue(11, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAdult() {
|
public void setAdult()
|
||||||
setBaby(false);
|
{
|
||||||
}
|
setBaby(false);
|
||||||
|
}
|
||||||
public void setBaby() {
|
|
||||||
setBaby(true);
|
public void setBaby()
|
||||||
}
|
{
|
||||||
|
setBaby(true);
|
||||||
public void setBaby(boolean isBaby) {
|
}
|
||||||
setValue(11, isBaby);
|
|
||||||
sendData(11);
|
public void setBaby(boolean isBaby)
|
||||||
}
|
{
|
||||||
|
setValue(11, isBaby);
|
||||||
}
|
sendData(11);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -1,50 +1,53 @@
|
|||||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||||
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||||
|
|
||||||
public class MinecartWatcher extends FlagWatcher {
|
public class MinecartWatcher extends FlagWatcher
|
||||||
|
{
|
||||||
public MinecartWatcher(Disguise disguise) {
|
|
||||||
super(disguise);
|
public MinecartWatcher(Disguise disguise)
|
||||||
}
|
{
|
||||||
|
super(disguise);
|
||||||
public ItemStack getBlockInCart() {
|
}
|
||||||
int id = (int) getValue(8, 0) & 0xffff;
|
|
||||||
int data = (int) getValue(8, 0) >> 16;
|
public ItemStack getBlockInCart()
|
||||||
return new ItemStack(id, 1, (short) data);
|
{
|
||||||
}
|
int id = (int) getValue(8, 0) & 0xffff;
|
||||||
|
int data = (int) getValue(8, 0) >> 16;
|
||||||
public int getBlockYOffset() {
|
return new ItemStack(id, 1, (short) data);
|
||||||
return (int) getValue(9, 0);
|
}
|
||||||
}
|
|
||||||
|
public int getBlockYOffset()
|
||||||
public boolean isViewBlockInCart() {
|
{
|
||||||
return (boolean) getValue(10, false);
|
return (int) getValue(9, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBlockInCart(ItemStack item) {
|
public boolean isViewBlockInCart()
|
||||||
int id = item.getTypeId();
|
{
|
||||||
int data = item.getDurability();
|
return (boolean) getValue(10, false);
|
||||||
setValue(8, id & 0xffff | data << 16);
|
}
|
||||||
setValue(10, true); //Show block
|
|
||||||
sendData(8, 10);
|
public void setBlockInCart(ItemStack item)
|
||||||
}
|
{
|
||||||
|
int id = item.getTypeId();
|
||||||
public void setBlockOffset(int i) {
|
int data = item.getDurability();
|
||||||
setValue(9, i);
|
setValue(8, id & 0xffff | data << 16);
|
||||||
sendData(9);
|
setValue(10, true); // Show block
|
||||||
}
|
sendData(8, 10);
|
||||||
|
}
|
||||||
@Deprecated
|
|
||||||
public void setBlockOffSet(int i) {
|
public void setBlockOffset(int i)
|
||||||
setBlockOffset(i);
|
{
|
||||||
}
|
setValue(9, i);
|
||||||
|
sendData(9);
|
||||||
public void setViewBlockInCart(boolean viewBlock) {
|
}
|
||||||
setValue(10, viewBlock);
|
|
||||||
sendData(10);
|
public void setViewBlockInCart(boolean viewBlock)
|
||||||
}
|
{
|
||||||
}
|
setValue(10, viewBlock);
|
||||||
|
sendData(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,89 +1,95 @@
|
|||||||
package me.libraryaddict.disguise.utilities;
|
package me.libraryaddict.disguise.utilities;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.security.CodeSource;
|
import java.security.CodeSource;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: Austin Date: 4/22/13 Time: 11:47 PM (c) lazertester
|
* User: Austin Date: 4/22/13 Time: 11:47 PM (c) lazertester
|
||||||
*/
|
*/
|
||||||
// Code for this taken and slightly modified from
|
// Code for this taken and slightly modified from
|
||||||
// https://github.com/ddopson/java-class-enumerator
|
// https://github.com/ddopson/java-class-enumerator
|
||||||
public class ClassGetter
|
public class ClassGetter
|
||||||
{
|
{
|
||||||
|
|
||||||
public static ArrayList<Class<?>> getClassesForPackage(String pkgname)
|
public static ArrayList<Class<?>> getClassesForPackage(String pkgname)
|
||||||
{
|
{
|
||||||
ArrayList<Class<?>> classes = new ArrayList<>();
|
ArrayList<Class<?>> classes = new ArrayList<>();
|
||||||
// String relPath = pkgname.replace('.', '/');
|
// String relPath = pkgname.replace('.', '/');
|
||||||
|
|
||||||
// Get a File object for the package
|
// Get a File object for the package
|
||||||
CodeSource src = Entity.class.getProtectionDomain().getCodeSource();
|
CodeSource src = Entity.class.getProtectionDomain().getCodeSource();
|
||||||
|
|
||||||
if (src != null)
|
if (src != null)
|
||||||
{
|
{
|
||||||
URL resource = src.getLocation();
|
URL resource = src.getLocation();
|
||||||
resource.getPath();
|
resource.getPath();
|
||||||
processJarfile(resource, pkgname, classes);
|
processJarfile(resource, pkgname, classes);
|
||||||
}
|
}
|
||||||
|
|
||||||
return classes;
|
return classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Class<?> loadClass(String className)
|
private static Class<?> loadClass(String className)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return Class.forName(className);
|
return Class.forName(className);
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException e)
|
catch (ClassNotFoundException e)
|
||||||
{
|
{
|
||||||
throw new RuntimeException("Unexpected ClassNotFoundException loading class '" + className + "'");
|
throw new RuntimeException("Unexpected ClassNotFoundException loading class '" + className + "'");
|
||||||
}
|
}
|
||||||
catch (NoClassDefFoundError e)
|
catch (NoClassDefFoundError e)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void processJarfile(URL resource, String pkgname, ArrayList<Class<?>> classes)
|
private static void processJarfile(URL resource, String pkgname, ArrayList<Class<?>> classes)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String relPath = pkgname.replace('.', '/');
|
String relPath = pkgname.replace('.', '/');
|
||||||
String resPath = URLDecoder.decode(resource.getPath(), "UTF-8");
|
String resPath = URLDecoder.decode(resource.getPath(), "UTF-8");
|
||||||
String jarPath = resPath.replaceFirst("[.]jar[!].*", ".jar").replaceFirst("file:", "");
|
String jarPath = resPath.replaceFirst("[.]jar[!].*", ".jar").replaceFirst("file:", "");
|
||||||
JarFile jarFile = new JarFile(jarPath);
|
|
||||||
Enumeration<JarEntry> entries = jarFile.entries();
|
JarFile jarFile = new JarFile(jarPath);
|
||||||
while (entries.hasMoreElements())
|
|
||||||
{
|
Enumeration<JarEntry> entries = jarFile.entries();
|
||||||
JarEntry entry = entries.nextElement();
|
|
||||||
String entryName = entry.getName();
|
while (entries.hasMoreElements())
|
||||||
String className = null;
|
{
|
||||||
if (entryName.endsWith(".class") && entryName.startsWith(relPath)
|
JarEntry entry = entries.nextElement();
|
||||||
&& entryName.length() > (relPath.length() + "/".length()))
|
String entryName = entry.getName();
|
||||||
{
|
String className = null;
|
||||||
className = entryName.replace('/', '.').replace('\\', '.').replace(".class", "");
|
if (entryName.endsWith(".class") && entryName.startsWith(relPath)
|
||||||
}
|
&& entryName.length() > (relPath.length() + "/".length()))
|
||||||
if (className != null)
|
{
|
||||||
{
|
className = entryName.replace('/', '.').replace('\\', '.').replace(".class", "");
|
||||||
Class<?> c = loadClass(className);
|
}
|
||||||
if (c != null)
|
if (className != null)
|
||||||
{
|
{
|
||||||
classes.add(c);
|
Class<?> c = loadClass(className);
|
||||||
}
|
|
||||||
}
|
if (c != null)
|
||||||
}
|
{
|
||||||
}
|
classes.add(c);
|
||||||
catch (Exception ex)
|
}
|
||||||
{
|
}
|
||||||
ex.printStackTrace(System.out);
|
}
|
||||||
}
|
|
||||||
}
|
jarFile.close();
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ex.printStackTrace(System.out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -521,9 +521,12 @@ public class DisguiseUtilities
|
|||||||
|
|
||||||
StructureModifier<Integer> ints = teleport.getIntegers();
|
StructureModifier<Integer> ints = teleport.getIntegers();
|
||||||
ints.write(0, entity.getEntityId());
|
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));
|
StructureModifier<Double> doubles = teleport.getDoubles();
|
||||||
ints.write(3, (int) Math.floor(loc.getZ() * 32));
|
|
||||||
|
doubles.write(0, loc.getX());
|
||||||
|
doubles.write(1, PacketsManager.getYModifier(disguise.getEntity(), disguise) + loc.getY());
|
||||||
|
doubles.write(2, loc.getZ());
|
||||||
|
|
||||||
return new PacketContainer[]
|
return new PacketContainer[]
|
||||||
{
|
{
|
||||||
|
@ -1,146 +1,115 @@
|
|||||||
package me.libraryaddict.disguise.utilities;
|
package me.libraryaddict.disguise.utilities;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||||
|
|
||||||
public class DisguiseValues {
|
public class DisguiseValues
|
||||||
|
{
|
||||||
private static HashMap<DisguiseType, DisguiseValues> values = new HashMap<>();
|
|
||||||
|
private static HashMap<DisguiseType, DisguiseValues> values = new HashMap<>();
|
||||||
public static DisguiseValues getDisguiseValues(DisguiseType type) {
|
|
||||||
switch (type) {
|
public static DisguiseValues getDisguiseValues(DisguiseType type)
|
||||||
case DONKEY:
|
{
|
||||||
case MULE:
|
switch (type)
|
||||||
case UNDEAD_HORSE:
|
{
|
||||||
case SKELETON_HORSE:
|
case DONKEY:
|
||||||
type = DisguiseType.HORSE;
|
case MULE:
|
||||||
break;
|
case UNDEAD_HORSE:
|
||||||
case MINECART_CHEST:
|
case SKELETON_HORSE:
|
||||||
case MINECART_COMMAND:
|
type = DisguiseType.HORSE;
|
||||||
case MINECART_FURNACE:
|
break;
|
||||||
case MINECART_HOPPER:
|
case MINECART_CHEST:
|
||||||
case MINECART_TNT:
|
case MINECART_COMMAND:
|
||||||
case MINECART_MOB_SPAWNER:
|
case MINECART_FURNACE:
|
||||||
type = DisguiseType.MINECART;
|
case MINECART_HOPPER:
|
||||||
break;
|
case MINECART_TNT:
|
||||||
case WITHER_SKELETON:
|
case MINECART_MOB_SPAWNER:
|
||||||
type = DisguiseType.SKELETON;
|
type = DisguiseType.MINECART;
|
||||||
break;
|
break;
|
||||||
case ZOMBIE_VILLAGER:
|
case WITHER_SKELETON:
|
||||||
type = DisguiseType.ZOMBIE;
|
type = DisguiseType.SKELETON;
|
||||||
break;
|
break;
|
||||||
default:
|
case ZOMBIE_VILLAGER:
|
||||||
break;
|
type = DisguiseType.ZOMBIE;
|
||||||
}
|
break;
|
||||||
return values.get(type);
|
default:
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
public static HashMap<Integer, Object> getMetaValues(DisguiseType type) {
|
return values.get(type);
|
||||||
return getDisguiseValues(type).getMetaValues();
|
}
|
||||||
}
|
|
||||||
|
public static HashMap<Integer, Object> getMetaValues(DisguiseType type)
|
||||||
public static Class getNmsEntityClass(DisguiseType type) {
|
{
|
||||||
return getDisguiseValues(type).getNmsEntityClass();
|
return getDisguiseValues(type).getMetaValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
private FakeBoundingBox adultBox;
|
public static Class getNmsEntityClass(DisguiseType type)
|
||||||
private FakeBoundingBox babyBox;
|
{
|
||||||
private float[] entitySize;
|
return getDisguiseValues(type).getNmsEntityClass();
|
||||||
private int enumEntitySize;
|
}
|
||||||
private double maxHealth;
|
|
||||||
private HashMap<Integer, Object> metaValues = new HashMap<>();
|
private FakeBoundingBox adultBox;
|
||||||
private Class nmsEntityClass;
|
private FakeBoundingBox babyBox;
|
||||||
|
private float[] entitySize;
|
||||||
@SuppressWarnings("LeakingThisInConstructor")
|
private double maxHealth;
|
||||||
public DisguiseValues(DisguiseType type, Class classType, int entitySize, double maxHealth) {
|
private HashMap<Integer, Object> metaValues = new HashMap<>();
|
||||||
values.put(type, this);
|
private Class nmsEntityClass;
|
||||||
enumEntitySize = entitySize;
|
|
||||||
nmsEntityClass = classType;
|
public DisguiseValues(DisguiseType type, Class classType, int entitySize, double maxHealth)
|
||||||
this.maxHealth = maxHealth;
|
{
|
||||||
}
|
values.put(type, this);
|
||||||
|
nmsEntityClass = classType;
|
||||||
public FakeBoundingBox getAdultBox() {
|
this.maxHealth = maxHealth;
|
||||||
return adultBox;
|
}
|
||||||
}
|
|
||||||
|
public FakeBoundingBox getAdultBox()
|
||||||
public FakeBoundingBox getBabyBox() {
|
{
|
||||||
return babyBox;
|
return adultBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float[] getEntitySize() {
|
public FakeBoundingBox getBabyBox()
|
||||||
return entitySize;
|
{
|
||||||
}
|
return babyBox;
|
||||||
|
}
|
||||||
public int getEntitySize(double paramDouble) {
|
|
||||||
double d = paramDouble - (((int) Math.floor(paramDouble)) + 0.5D);
|
public float[] getEntitySize()
|
||||||
|
{
|
||||||
switch (enumEntitySize) {
|
return entitySize;
|
||||||
case 1:
|
}
|
||||||
if (d < 0.0D ? d < -0.3125D : d < 0.3125D) {
|
|
||||||
return (int) Math.ceil(paramDouble * 32.0D);
|
public double getMaxHealth()
|
||||||
}
|
{
|
||||||
|
return maxHealth;
|
||||||
return (int) Math.floor(paramDouble * 32.0D);
|
}
|
||||||
case 2:
|
|
||||||
if (d < 0.0D ? d < -0.3125D : d < 0.3125D) {
|
public HashMap<Integer, Object> getMetaValues()
|
||||||
return (int) Math.floor(paramDouble * 32.0D);
|
{
|
||||||
}
|
return metaValues;
|
||||||
|
}
|
||||||
return (int) Math.ceil(paramDouble * 32.0D);
|
|
||||||
case 3:
|
public Class getNmsEntityClass()
|
||||||
if (d > 0.0D) {
|
{
|
||||||
return (int) Math.floor(paramDouble * 32.0D);
|
return nmsEntityClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int) Math.ceil(paramDouble * 32.0D);
|
public void setAdultBox(FakeBoundingBox newBox)
|
||||||
case 4:
|
{
|
||||||
if (d < 0.0D ? d < -0.1875D : d < 0.1875D) {
|
adultBox = newBox;
|
||||||
return (int) Math.ceil(paramDouble * 32.0D);
|
}
|
||||||
}
|
|
||||||
|
public void setBabyBox(FakeBoundingBox newBox)
|
||||||
return (int) Math.floor(paramDouble * 32.0D);
|
{
|
||||||
case 5:
|
babyBox = newBox;
|
||||||
if (d < 0.0D ? d < -0.1875D : d < 0.1875D) {
|
}
|
||||||
return (int) Math.floor(paramDouble * 32.0D);
|
|
||||||
}
|
public void setEntitySize(float[] size)
|
||||||
|
{
|
||||||
return (int) Math.ceil(paramDouble * 32.0D);
|
this.entitySize = size;
|
||||||
default:
|
}
|
||||||
break;
|
|
||||||
}
|
public void setMetaValue(int id, Object value)
|
||||||
if (d > 0.0D) {
|
{
|
||||||
return (int) Math.ceil(paramDouble * 32.0D);
|
metaValues.put(id, value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
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