Merge pull request #22 from libraryaddict/UUID-Disguises

Uuid disguises - I hope you guys like untested features
This commit is contained in:
libraryaddict 2014-04-03 02:58:12 +13:00
commit 3e4438d7bb
21 changed files with 151 additions and 249 deletions

View File

@ -23,7 +23,7 @@ SendVelocity: true
# However! This doesn't actually remove the armor!
# It just makes the client think the armor was removed so that it doesn't render it!
RemoveArmor: true
RemoveHeldItem: true
RemoveHeldItem: false
# If you set a disguise to burning, it will no longer be able to be shown as sneaking or invisible.
# Set this to true if you want the disguise to get the animations of the disguised entity. Such as invisible, on fire, sprinting, sneaking, blocking
# This is only valid if you set a animation on the disguise itself. Because the entitys animations are applied otherwise.
@ -55,4 +55,12 @@ MonstersIgnoreDisguises: false
# Works only for disguised players when attacked by a entity (arrow, monster. etc)
# This will blow all disguises he has on him
BlowDisguises: false
BlownDisguiseMessage: '&cYour disguise was blown!'
BlownDisguiseMessage: '&cYour disguise was blown!'
# This I don't really recommend turning on as it can make a memory leak..
# These disguises, as normal will not persist after a server restart.
# There is also no EntityDeath option as entities do not revive after death.
KeepDisguises:
PlayerDeath: false
PlayerLogout: false
EntityDespawn: false

View File

@ -3,6 +3,7 @@ package me.libraryaddict.disguise;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
@ -42,7 +43,7 @@ public class DisguiseAPI {
disguise.setEntity(entity);
}
// Stick the disguise in the disguises bin
DisguiseUtilities.addDisguise(entity.getEntityId(), (TargetedDisguise) disguise);
DisguiseUtilities.addDisguise(entity.getUniqueId(), (TargetedDisguise) disguise);
// Resend the disguised entity's packet
DisguiseUtilities.refreshTrackers((TargetedDisguise) disguise);
// If he is a player, then self disguise himself
@ -77,7 +78,7 @@ public class DisguiseAPI {
Field field = ReflectionManager.getNmsClass("Entity").getDeclaredField("entityCount");
field.setAccessible(true);
int id = field.getInt(null);
DisguiseUtilities.addDisguise(id, (TargetedDisguise) disguise);
DisguiseUtilities.addFutureDisguise(id, (TargetedDisguise) disguise);
} catch (Exception ex) {
ex.printStackTrace();
}
@ -118,7 +119,7 @@ public class DisguiseAPI {
public static Disguise getDisguise(Entity disguised) {
if (disguised == null)
return null;
return DisguiseUtilities.getMainDisguise(disguised.getEntityId());
return DisguiseUtilities.getMainDisguise(disguised.getUniqueId());
}
/**
@ -127,7 +128,7 @@ public class DisguiseAPI {
public static Disguise getDisguise(Player observer, Entity disguised) {
if (disguised == null || observer == null)
return null;
return DisguiseUtilities.getDisguise(observer, disguised.getEntityId());
return DisguiseUtilities.getDisguise(observer, disguised);
}
/**
@ -136,13 +137,13 @@ public class DisguiseAPI {
public static Disguise[] getDisguises(Entity disguised) {
if (disguised == null)
return null;
return DisguiseUtilities.getDisguises(disguised.getEntityId());
return DisguiseUtilities.getDisguises(disguised.getUniqueId());
}
/**
* Get the ID of a fake disguise for a entityplayer
*/
public static int getFakeDisguise(int entityId) {
public static int getFakeDisguise(UUID entityId) {
if (DisguiseUtilities.getSelfDisguisesIds().containsKey(entityId))
return DisguiseUtilities.getSelfDisguisesIds().get(entityId);
return -1;

View File

@ -9,6 +9,9 @@ public class DisguiseConfig {
private static boolean hearSelfDisguise;
private static boolean hidingArmor;
private static boolean hidingHeldItem;
private static boolean keepDisguiseEntityDespawn;
private static boolean keepDisguisePlayerDeath;
private static boolean keepDisguisePlayerLogout;
private static boolean modifyBoundingBox;
private static boolean removeUnseenDisguises;
private static boolean sendVelocity;
@ -16,11 +19,6 @@ public class DisguiseConfig {
private static boolean showNameAboveHeadAlwaysVisible;
private static boolean targetDisguises;
@Deprecated
public static boolean canHearSelfDisguise() {
return hearSelfDisguise;
}
public static String getDisguiseBlownMessage() {
return disguiseBlownMessage;
}
@ -47,6 +45,18 @@ public class DisguiseConfig {
return hidingHeldItem;
}
public static boolean isKeepDisguiseOnEntityDespawn() {
return keepDisguiseEntityDespawn;
}
public static boolean isKeepDisguiseOnPlayerDeath() {
return keepDisguisePlayerDeath;
}
public static boolean isKeepDisguiseOnPlayerLogout() {
return keepDisguisePlayerLogout;
}
public static boolean isModifyBoundingBox() {
return modifyBoundingBox;
}
@ -133,6 +143,18 @@ public class DisguiseConfig {
}
}
public static void setKeepDisguiseOnEntityDespawn(boolean keepDisguise) {
keepDisguiseEntityDespawn = keepDisguise;
}
public static void setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
keepDisguisePlayerDeath = keepDisguise;
}
public static void setKeepDisguiseOnPlayerLogout(boolean keepDisguise) {
keepDisguisePlayerLogout = keepDisguise;
}
public static void setModifyBoundingBox(boolean modifyBounding) {
modifyBoundingBox = modifyBounding;
}

View File

@ -74,6 +74,9 @@ public class LibsDisguises extends JavaPlugin {
DisguiseConfig.setDisguiseBlownOnAttack(getConfig().getBoolean("BlowDisguises"));
DisguiseConfig.setDisguiseBlownMessage(ChatColor.translateAlternateColorCodes('&',
getConfig().getString("BlownDisguiseMessage")));
DisguiseConfig.setKeepDisguiseOnPlayerDeath(getConfig().getBoolean("KeepDisguises.PlayerDeath"));
DisguiseConfig.setKeepDisguiseOnPlayerLogout(getConfig().getBoolean("KeepDisguises.PlayerLogout"));
DisguiseConfig.setKeepDisguiseOnEntityDespawn(getConfig().getBoolean("KeepDisguises.EntityDespawn"));
try {
// Here I use reflection to set the plugin for Disguise..
// Kind of stupid but I don't want open API calls for a commonly used object.

View File

@ -4,6 +4,7 @@ import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.UUID;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
@ -16,6 +17,7 @@ import me.libraryaddict.disguise.utilities.PacketsManager;
import me.libraryaddict.disguise.utilities.ReflectionManager;
import me.libraryaddict.disguise.utilities.DisguiseValues;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Horse.Variant;
@ -36,19 +38,16 @@ public abstract class Disguise {
private boolean hearSelfDisguise = DisguiseConfig.isSelfDisguisesSoundsReplaced();
private boolean hideArmorFromSelf = DisguiseConfig.isHidingArmorFromSelf();
private boolean hideHeldItemFromSelf = DisguiseConfig.isHidingHeldItemFromSelf();
private boolean keepDisguiseEntityDespawn = DisguiseConfig.isKeepDisguiseOnEntityDespawn();
private boolean keepDisguisePlayerDeath = DisguiseConfig.isKeepDisguiseOnPlayerDeath();
private boolean keepDisguisePlayerLogout = DisguiseConfig.isKeepDisguiseOnPlayerLogout();
private boolean modifyBoundingBox = DisguiseConfig.isModifyBoundingBox();
private boolean removeWhenInvalid = true;
private boolean replaceSounds = DisguiseConfig.isSoundEnabled();
private BukkitRunnable velocityRunnable;
private boolean velocitySent = DisguiseConfig.isVelocitySent();
private boolean viewSelfDisguise = DisguiseConfig.isViewDisguises();
private FlagWatcher watcher;
@Deprecated
public boolean canHearSelfDisguise() {
return hearSelfDisguise;
}
@Override
public abstract Disguise clone();
@ -82,9 +81,9 @@ public abstract class Disguise {
// Set the disguise if its a baby or not
if (!isAdult) {
if (getWatcher() instanceof AgeableWatcher) {
((AgeableWatcher) getWatcher()).setAdult(false);
((AgeableWatcher) getWatcher()).setBaby(true);
} else if (getWatcher() instanceof ZombieWatcher) {
((ZombieWatcher) getWatcher()).setAdult(false);
((ZombieWatcher) getWatcher()).setBaby(true);
}
}
// If the disguise type is a wither, set the flagwatcher value for the skeleton to a wither skeleton
@ -185,8 +184,20 @@ public abstract class Disguise {
public void run() {
// If entity is no longer valid. Remove it.
if (!getEntity().isValid()) {
if (isRemoveWhenInvalid()) {
if (getEntity() instanceof Player ?
(Bukkit.getPlayerExact(((Player) getEntity()).getName()) == null ? !isKeepDisguiseOnPlayerLogout()
: !isKeepDisguiseOnPlayerDeath())
:
(!isKeepDisguiseOnEntityDespawn() || getEntity().isDead())) {
removeDisguise();
} else {
entity = null;
watcher = getWatcher().clone(disguise);
cancel();
}
} else {
// If the disguise type is tnt, we need to resend the entity packet else it will turn invisible
@ -229,7 +240,7 @@ public abstract class Disguise {
(byte) Math.floor(loc.getPitch() * 256.0F / 360.0F)));
if (isSelfDisguiseVisible() && getEntity() instanceof Player) {
PacketContainer selfLookPacket = lookPacket.shallowClone();
selfLookPacket.getModifier().write(0, DisguiseAPI.getFakeDisguise(getEntity().getEntityId()));
selfLookPacket.getModifier().write(0, DisguiseAPI.getFakeDisguise(getEntity().getUniqueId()));
try {
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) getEntity(),
selfLookPacket, false);
@ -248,7 +259,7 @@ public abstract class Disguise {
if (!isSelfDisguiseVisible()) {
continue;
}
mods.write(0, DisguiseAPI.getFakeDisguise(getEntity().getEntityId()));
mods.write(0, DisguiseAPI.getFakeDisguise(getEntity().getUniqueId()));
} else {
mods.write(0, getEntity().getEntityId());
}
@ -274,7 +285,7 @@ public abstract class Disguise {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
} else if (isSelfDisguiseVisible()) {
PacketContainer selfPacket = packet.shallowClone();
selfPacket.getModifier().write(0, DisguiseAPI.getFakeDisguise(getEntity().getEntityId()));
selfPacket.getModifier().write(0, DisguiseAPI.getFakeDisguise(getEntity().getUniqueId()));
try {
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) getEntity(),
selfPacket, false);
@ -322,6 +333,18 @@ public abstract class Disguise {
return hideHeldItemFromSelf;
}
public boolean isKeepDisguiseOnEntityDespawn() {
return this.keepDisguiseEntityDespawn;
}
public boolean isKeepDisguiseOnPlayerDeath() {
return this.keepDisguisePlayerDeath;
}
public boolean isKeepDisguiseOnPlayerLogout() {
return this.keepDisguisePlayerLogout;
}
public boolean isMiscDisguise() {
return false;
}
@ -338,13 +361,6 @@ public abstract class Disguise {
return false;
}
/**
* Is the disguise removed when the disguised entity is invalid?
*/
public boolean isRemoveWhenInvalid() {
return removeWhenInvalid;
}
public boolean isSelfDisguiseSoundsReplaced() {
return hearSelfDisguise;
}
@ -373,7 +389,7 @@ public abstract class Disguise {
velocityRunnable.cancel();
} catch (Exception ex) {
}
HashMap<Integer, HashSet<TargetedDisguise>> disguises = DisguiseUtilities.getDisguises();
HashMap<UUID, HashSet<TargetedDisguise>> disguises = DisguiseUtilities.getDisguises();
// If this disguise has a entity set
if (getEntity() != null) {
// If this disguise is active
@ -391,9 +407,9 @@ public abstract class Disguise {
}
} else {
// Loop through the disguises because it could be used with a unknown entity id.
Iterator<Integer> itel = disguises.keySet().iterator();
Iterator<UUID> itel = disguises.keySet().iterator();
while (itel.hasNext()) {
int id = itel.next();
UUID id = itel.next();
if (disguises.get(id).remove(this) && disguises.get(id).isEmpty()) {
itel.remove();
}
@ -401,11 +417,6 @@ public abstract class Disguise {
}
}
@Deprecated
public boolean replaceSounds() {
return replaceSounds;
}
/**
* Set the entity of the disguise. Only used for internal things.
*/
@ -438,6 +449,18 @@ public abstract class Disguise {
}
}
public void setKeepDisguiseOnEntityDespawn(boolean keepDisguise) {
this.keepDisguiseEntityDespawn = keepDisguise;
}
public void setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
this.keepDisguisePlayerDeath = keepDisguise;
}
public void setKeepDisguiseOnPlayerLogout(boolean keepDisguise) {
this.keepDisguisePlayerLogout = keepDisguise;
}
public void setModifyBoundingBox(boolean modifyBox) {
if (((TargetedDisguise) this).getDisguiseTarget() != TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
throw new RuntimeException(
@ -451,10 +474,6 @@ public abstract class Disguise {
}
}
public void setRemoveDisguiseWhenInvalid(boolean removeWhenInvalid) {
this.removeWhenInvalid = removeWhenInvalid;
}
public void setReplaceSounds(boolean areSoundsReplaced) {
replaceSounds = areSoundsReplaced;
}
@ -585,9 +604,4 @@ public abstract class Disguise {
public void setWatcher(FlagWatcher newWatcher) {
watcher = newWatcher;
}
@Deprecated
public boolean viewSelfDisguise() {
return viewSelfDisguise;
}
}

View File

@ -161,11 +161,6 @@ public class FlagWatcher {
return ((Byte) getValue(0, (byte) 0) & 1 << byteValue) != 0;
}
@Deprecated
public ItemStack getHeldItem() {
return getItemInHand();
}
public ItemStack getItemInHand() {
return getItemStack(SlotType.HELD_ITEM);
}
@ -200,11 +195,6 @@ public class FlagWatcher {
return getFlag(5);
}
@Deprecated
public boolean isRiding() {
return getFlag(2);
}
public boolean isRightClicking() {
return getFlag(4);
}
@ -269,11 +259,6 @@ public class FlagWatcher {
}
}
@Deprecated
public void setHeldItem(ItemStack itemstack) {
setItemInHand(itemstack);
}
public void setInvisible(boolean setInvis) {
setFlag(5, setInvis);
sendData(0);
@ -328,12 +313,6 @@ public class FlagWatcher {
setItemStack(slot.getSlot(), itemStack);
}
@Deprecated
public void setRiding(boolean setRiding) {
setFlag(2, setRiding);
sendData(0);
}
public void setRightClicking(boolean setRightClicking) {
setFlag(4, setRightClicking);
sendData(0);

View File

@ -69,7 +69,7 @@ public class MiscDisguise extends TargetedDisguise {
((FallingBlockWatcher) getWatcher()).setBlock(new ItemStack(this.id, 1, (short) this.data));
break;
case PAINTING:
((PaintingWatcher) getWatcher()).setArtId(this.data);
((PaintingWatcher) getWatcher()).setArt(Art.values()[this.data % Art.values().length]);
break;
case SPLASH_POTION:
((SplashPotionWatcher) getWatcher()).setPotionId(this.data);

View File

@ -62,9 +62,9 @@ public class MobDisguise extends TargetedDisguise {
public boolean isAdult() {
if (getWatcher() != null) {
if (getWatcher() instanceof AgeableWatcher)
return ((AgeableWatcher) getWatcher()).isAdult();
return ((AgeableWatcher) getWatcher()).isBaby();
else if (getWatcher() instanceof ZombieWatcher)
return ((ZombieWatcher) getWatcher()).isAdult();
return ((ZombieWatcher) getWatcher()).isBaby();
return false;
}
return isAdult;

View File

@ -12,7 +12,6 @@ public class AgeableWatcher extends LivingWatcher {
return (Integer) getValue(12, 0);
}
@Deprecated
public boolean isAdult() {
return !isBaby();
}
@ -21,9 +20,8 @@ public class AgeableWatcher extends LivingWatcher {
return (Integer) getValue(12, 0) < 0;
}
@Deprecated
public void setAdult(boolean isAdult) {
setBaby(!isAdult);
public void setAdult() {
setBaby(false);
}
public void setAge(int newAge) {
@ -31,6 +29,10 @@ public class AgeableWatcher extends LivingWatcher {
sendData(12);
}
public void setBaby() {
setBaby(true);
}
public void setBaby(boolean isBaby) {
setValue(12, isBaby ? -24000 : 0);
sendData(12);

View File

@ -8,11 +8,6 @@ public class CreeperWatcher extends LivingWatcher {
super(disguise);
}
@Deprecated
public boolean isFused() {
return (Byte) getValue(16, (byte) 0) == 1;
}
public boolean isIgnited() {
return (Byte) getValue(18, (byte) 0) == 1;
}
@ -21,18 +16,6 @@ public class CreeperWatcher extends LivingWatcher {
return (Byte) getValue(17, (byte) 0) == 1;
}
@Deprecated
public void setFuse(boolean isFused) {
setValue(16, (byte) (isFused ? 1 : -1));
sendData(16);
}
@Deprecated
public void setFused(boolean isFused) {
setValue(16, (byte) (isFused ? 1 : -1));
sendData(16);
}
public void setIgnited(boolean ignited) {
setValue(18, (byte) (ignited ? 1 : 0));
sendData(18);

View File

@ -10,22 +10,6 @@ public class EndermanWatcher extends LivingWatcher {
super(disguise);
}
@Deprecated
public int getCarriedData() {
return ((Byte) getValue(17, (byte) 0));
}
@Deprecated
public int getCarriedId() {
return ((Byte) getValue(16, (byte) 0));
}
@Override
@Deprecated
public ItemStack getHeldItem() {
return getItemInHand();
}
@Override
public ItemStack getItemInHand() {
return new ItemStack((Byte) getValue(16, (byte) 0), 1, ((Byte) getValue(17, (byte) 0)));
@ -40,26 +24,6 @@ public class EndermanWatcher extends LivingWatcher {
sendData(18);
}
@Deprecated
public void setCarriedItem(int id, int dataValue) {
setValue(16, (byte) (id & 255));
setValue(17, (byte) (dataValue & 255));
sendData(16);
sendData(17);
}
@Deprecated
public void setCarriedItem(ItemStack itemstack) {
setValue(16, (byte) (itemstack.getTypeId() & 255));
setValue(17, (byte) (itemstack.getDurability() & 255));
}
@Override
@Deprecated
public void setHeldItem(ItemStack itemstack) {
setItemInHand(itemstack);
}
@Override
public void setItemInHand(ItemStack itemstack) {
setValue(16, (byte) (itemstack.getTypeId() & 255));

View File

@ -12,20 +12,9 @@ public class GhastWatcher extends LivingWatcher {
return (Byte) getValue(16, (byte) 0) == 1;
}
@Deprecated
public boolean isAgressive() {
return (Byte) getValue(16, (byte) 0) == 1;
}
public void setAggressive(boolean isAgressive) {
setValue(16, (byte) (isAgressive ? 1 : 0));
sendData(16);
}
@Deprecated
public void setAgressive(boolean isAgressive) {
setValue(16, (byte) (isAgressive ? 1 : 0));
sendData(16);
}
}

View File

@ -11,7 +11,7 @@ public class HorseWatcher extends AgeableWatcher {
public HorseWatcher(Disguise disguise) {
super(disguise);
setColorId(new Random().nextInt(Color.values().length));
setColor(Color.values()[new Random().nextInt(Color.values().length)]);
}
public Color getColor() {
@ -34,11 +34,6 @@ public class HorseWatcher extends AgeableWatcher {
return isTrue(8);
}
@Deprecated
public boolean isBredable() {
return isTrue(16);
}
public boolean isBreedable() {
return isTrue(16);
}
@ -67,11 +62,6 @@ public class HorseWatcher extends AgeableWatcher {
return ((Integer) getValue(16, (byte) 0) & i) != 0;
}
@Deprecated
public void setCanBred(boolean breed) {
setFlag(16, breed);
}
public void setCanBreed(boolean breed) {
setFlag(16, breed);
}
@ -85,12 +75,6 @@ public class HorseWatcher extends AgeableWatcher {
sendData(20);
}
@Deprecated
public void setColorId(int color) {
setValue(20, (color % Color.values().length) & 0xFF | getStyle().ordinal() << 8);
sendData(20);
}
private void setFlag(int i, boolean flag) {
int j = (Byte) getValue(16, (byte) 0);
if (flag) {
@ -132,12 +116,6 @@ public class HorseWatcher extends AgeableWatcher {
sendData(20);
}
@Deprecated
public void setStyleId(int style) {
setValue(20, getColor().ordinal() & 0xFF | (style % Style.values().length) << 8);
sendData(20);
}
public void setTamed(boolean tamed) {
setFlag(2, tamed);
}

View File

@ -6,7 +6,6 @@ import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.utilities.ReflectionManager;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public class LivingWatcher extends FlagWatcher {
@ -38,14 +37,6 @@ public class LivingWatcher extends FlagWatcher {
super(disguise);
}
@Deprecated
public void addPotionEffect(PotionEffect potionEffect) {
if (hasPotionEffect(potionEffect.getType()))
removePotionEffect(potionEffect.getType());
potionEffects.add(potionEffect.getType().getId());
sendPotionEffects();
}
public void addPotionEffect(PotionEffectType potionEffect) {
if (hasPotionEffect(potionEffect))
removePotionEffect(potionEffect);

View File

@ -58,10 +58,4 @@ public class OcelotWatcher extends AgeableWatcher {
setValue(18, (byte) newType.getId());
sendData(18);
}
@Deprecated
public void setTypeId(int type) {
setValue(18, (byte) (type % Type.values().length));
sendData(18);
}
}

View File

@ -30,9 +30,4 @@ public class PaintingWatcher extends FlagWatcher {
}
}
@Deprecated
public void setArtId(int paintingNo) {
painting = Art.values()[paintingNo % Art.values().length];
}
}

View File

@ -10,25 +10,15 @@ public class VillagerWatcher extends AgeableWatcher {
public VillagerWatcher(Disguise disguise) {
super(disguise);
setProfessionId(new Random().nextInt(Profession.values().length));
setProfession(Profession.values()[new Random().nextInt(Profession.values().length)]);
}
public Profession getProfession() {
return Profession.values()[(Integer) getValue(16, 0)];
}
@Deprecated
public int getProfessionId() {
return (Integer) getValue(16, 0);
}
public void setProfession(Profession newProfession) {
setProfessionId(newProfession.getId());
}
@Deprecated
public void setProfessionId(int profession) {
setValue(16, profession % 6);
setValue(16, newProfession.getId() % 6);
sendData(16);
}

View File

@ -8,9 +8,8 @@ public class ZombieWatcher extends LivingWatcher {
super(disguise);
}
@Deprecated
public boolean isAdult() {
return (Byte) getValue(12, (byte) 0) == 0;
return !isBaby();
}
public boolean isBaby() {
@ -21,9 +20,12 @@ public class ZombieWatcher extends LivingWatcher {
return (Byte) getValue(13, (byte) 0) == 1;
}
@Deprecated
public void setAdult(boolean adult) {
setBaby(!adult);
public void setAdult() {
setBaby(false);
}
public void setBaby() {
setBaby(true);
}
public void setBaby(boolean baby) {

View File

@ -372,34 +372,6 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
return disguise;
}
/* private ArrayList<Method> getUsableMethods(DisguiseType disguiseType, CommandSender commandSender) {
ArrayList<Method> methods = getSettableMethods(disguiseType);
ArrayList<String> allowedDisguises = this.getAllowedDisguises(commandSender);
}
private ArrayList<Method> getSettableMethods(DisguiseType disguiseType) {
ArrayList<Method> methods = new ArrayList<Method>();
String[] acceptableParams = new String[] { "String", "boolean", "int", "float", "double", "AnimalColor", "ItemStack",
"ItemStack[]", "Style", "Color", "Type", "Profession", "PotionEffectType" };
try {
for (Method method : disguiseType.getWatcherClass().getMethods()) {
if (!method.getName().startsWith("get") && method.getParameterTypes().length == 1
&& method.getAnnotation(Deprecated.class) == null) {
Class c = method.getParameterTypes()[0];
for (String acceptable : acceptableParams) {
if (c.getSimpleName().equals(acceptable)) {
methods.add(method);
break;
}
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
return methods;
}*/// //
private void doCheck(HashSet<HashSet<String>> optionPermissions, HashSet<String> usedOptions) throws Exception {
if (!optionPermissions.isEmpty()) {
for (HashSet<String> perms : optionPermissions) {

View File

@ -8,6 +8,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.LibsDisguises;
@ -36,14 +37,15 @@ import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
public class DisguiseUtilities {
private static HashMap<Integer, HashSet<TargetedDisguise>> futureDisguises = new HashMap<Integer, HashSet<TargetedDisguise>>();
private static LibsDisguises libsDisguises;
// A internal storage of fake entity ID's I can use.
// Realistically I could probably use a ID like "4" for everyone, seeing as no one shares the ID
private static HashMap<Integer, Integer> selfDisguisesIds = new HashMap<Integer, Integer>();
private static HashMap<UUID, Integer> selfDisguisesIds = new HashMap<UUID, Integer>();
// Store the entity IDs instead of entitys because then I can disguise entitys even before they exist
private static HashMap<Integer, HashSet<TargetedDisguise>> targetedDisguises = new HashMap<Integer, HashSet<TargetedDisguise>>();
private static HashMap<UUID, HashSet<TargetedDisguise>> targetedDisguises = new HashMap<UUID, HashSet<TargetedDisguise>>();
public static void addDisguise(int entityId, TargetedDisguise disguise) {
public static void addDisguise(UUID entityId, TargetedDisguise disguise) {
if (!getDisguises().containsKey(entityId)) {
getDisguises().put(entityId, new HashSet<TargetedDisguise>());
}
@ -54,6 +56,13 @@ public class DisguiseUtilities {
}
}
public static void addFutureDisguise(int entityId, TargetedDisguise disguise) {
if (!futureDisguises.containsKey(entityId)) {
futureDisguises.put(entityId, new HashSet<TargetedDisguise>());
}
futureDisguises.get(entityId).add(disguise);
}
/**
* If name isn't null. Make sure that the name doesn't see any other disguise. Else if name is null. Make sure that the
* observers in the disguise don't see any other disguise.
@ -61,7 +70,7 @@ public class DisguiseUtilities {
public static void checkConflicts(TargetedDisguise disguise, String name) {
// If the disguise is being used.. Else we may accidentally undisguise something else
if (DisguiseAPI.isDisguiseInUse(disguise)) {
Iterator<TargetedDisguise> disguiseItel = getDisguises().get(disguise.getEntity().getEntityId()).iterator();
Iterator<TargetedDisguise> disguiseItel = getDisguises().get(disguise.getEntity().getUniqueId()).iterator();
// Iterate through the disguises
while (disguiseItel.hasNext()) {
TargetedDisguise d = disguiseItel.next();
@ -162,7 +171,13 @@ public class DisguiseUtilities {
}
}
public static TargetedDisguise getDisguise(Player observer, int entityId) {
public static TargetedDisguise getDisguise(Player observer, Entity entity) {
UUID entityId = entity.getUniqueId();
if (futureDisguises.containsKey(entity.getEntityId())) {
for (TargetedDisguise disguise : futureDisguises.remove(entity.getEntityId())) {
addDisguise(entityId, disguise);
}
}
if (getDisguises().containsKey(entityId)) {
for (TargetedDisguise disguise : getDisguises().get(entityId)) {
if (disguise.canSee(observer)) {
@ -173,18 +188,18 @@ public class DisguiseUtilities {
return null;
}
public static HashMap<Integer, HashSet<TargetedDisguise>> getDisguises() {
public static HashMap<UUID, HashSet<TargetedDisguise>> getDisguises() {
return targetedDisguises;
}
public static TargetedDisguise[] getDisguises(int entityId) {
public static TargetedDisguise[] getDisguises(UUID entityId) {
if (getDisguises().containsKey(entityId)) {
return getDisguises().get(entityId).toArray(new TargetedDisguise[getDisguises().get(entityId).size()]);
}
return new TargetedDisguise[0];
}
public static TargetedDisguise getMainDisguise(int entityId) {
public static TargetedDisguise getMainDisguise(UUID entityId) {
TargetedDisguise toReturn = null;
if (getDisguises().containsKey(entityId)) {
for (TargetedDisguise disguise : getDisguises().get(entityId)) {
@ -247,7 +262,7 @@ public class DisguiseUtilities {
return dis;
}
public static HashMap<Integer, Integer> getSelfDisguisesIds() {
public static HashMap<UUID, Integer> getSelfDisguisesIds() {
return selfDisguisesIds;
}
@ -256,8 +271,8 @@ public class DisguiseUtilities {
}
public static boolean isDisguiseInUse(Disguise disguise) {
if (disguise.getEntity() != null && getDisguises().containsKey(disguise.getEntity().getEntityId())
&& getDisguises().get(disguise.getEntity().getEntityId()).contains(disguise)) {
if (disguise.getEntity() != null && getDisguises().containsKey(disguise.getEntity().getUniqueId())
&& getDisguises().get(disguise.getEntity().getUniqueId()).contains(disguise)) {
return true;
}
return false;
@ -363,7 +378,7 @@ public class DisguiseUtilities {
}
public static boolean removeDisguise(TargetedDisguise disguise) {
int entityId = disguise.getEntity().getEntityId();
UUID entityId = disguise.getEntity().getUniqueId();
if (getDisguises().containsKey(entityId) && getDisguises().get(entityId).remove(disguise)) {
if (getDisguises().get(entityId).isEmpty()) {
getDisguises().remove(entityId);
@ -377,17 +392,17 @@ public class DisguiseUtilities {
}
public static void removeSelfDisguise(Player player) {
if (selfDisguisesIds.containsKey(player.getEntityId())) {
if (selfDisguisesIds.containsKey(player.getUniqueId())) {
// Send a packet to destroy the fake entity
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
packet.getModifier().write(0, new int[] { selfDisguisesIds.get(player.getEntityId()) });
packet.getModifier().write(0, new int[] { selfDisguisesIds.get(player.getUniqueId()) });
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
} catch (Exception ex) {
ex.printStackTrace();
}
// Remove the fake entity ID from the disguise bin
selfDisguisesIds.remove(player.getEntityId());
selfDisguisesIds.remove(player.getUniqueId());
// Get the entity tracker
try {
Object world = ReflectionManager.getWorld(player.getWorld());
@ -444,7 +459,7 @@ public class DisguiseUtilities {
});
return;
}
int fakeId = selfDisguisesIds.get(player.getEntityId());
int fakeId = selfDisguisesIds.get(player.getUniqueId());
// Add himself to his own entity tracker
((HashSet) entityTrackerEntry.getClass().getField("trackedPlayers").get(entityTrackerEntry)).add(ReflectionManager
.getNmsEntity(player));
@ -550,8 +565,8 @@ public class DisguiseUtilities {
public static void setupFakeDisguise(final Disguise disguise) {
Entity e = disguise.getEntity();
// If the disguises entity is null, or the disguised entity isn't a player return
if (e == null || !(e instanceof Player) || !getDisguises().containsKey(e.getEntityId())
|| !getDisguises().get(e.getEntityId()).contains(disguise)) {
if (e == null || !(e instanceof Player) || !getDisguises().containsKey(e.getUniqueId())
|| !getDisguises().get(e.getUniqueId()).contains(disguise)) {
return;
}
Player player = (Player) e;
@ -572,7 +587,7 @@ public class DisguiseUtilities {
int id = field.getInt(null);
// Set the entitycount plus one so we don't have the id being reused
field.set(null, id + 1);
selfDisguisesIds.put(player.getEntityId(), id);
selfDisguisesIds.put(player.getUniqueId(), id);
} catch (Exception ex) {
ex.printStackTrace();
}

View File

@ -707,7 +707,7 @@ public class PacketsManager {
public void onPacketSending(PacketEvent event) {
final Player observer = event.getPlayer();
if (event.getPacket().getIntegers().read(0) == observer.getEntityId()) {
int fakeId = DisguiseAPI.getFakeDisguise(observer.getEntityId());
int fakeId = DisguiseAPI.getFakeDisguise(observer.getUniqueId());
if (fakeId > 0) {
// Here I grab the packets to convert them to, So I can display them as if the disguise sent them.
PacketContainer[] packets = transformPacket(event.getPacket(), observer, observer);