Add support for disguiseNextEntity

This commit is contained in:
libraryaddict 2014-04-03 02:02:58 +13:00
parent 07bf03f154
commit 167f14bfe8
2 changed files with 17 additions and 3 deletions

View File

@ -78,7 +78,7 @@ public class DisguiseAPI {
Field field = ReflectionManager.getNmsClass("Entity").getDeclaredField("entityCount"); Field field = ReflectionManager.getNmsClass("Entity").getDeclaredField("entityCount");
field.setAccessible(true); field.setAccessible(true);
int id = field.getInt(null); int id = field.getInt(null);
DisguiseUtilities.addDisguise(id, (TargetedDisguise) disguise); DisguiseUtilities.addFutureDisguise(id, (TargetedDisguise) disguise);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
@ -128,7 +128,7 @@ public class DisguiseAPI {
public static Disguise getDisguise(Player observer, Entity disguised) { public static Disguise getDisguise(Player observer, Entity disguised) {
if (disguised == null || observer == null) if (disguised == null || observer == null)
return null; return null;
return DisguiseUtilities.getDisguise(observer, disguised.getUniqueId()); return DisguiseUtilities.getDisguise(observer, disguised);
} }
/** /**

View File

@ -43,6 +43,14 @@ public class DisguiseUtilities {
private static HashMap<UUID, Integer> selfDisguisesIds = new HashMap<UUID, 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 // Store the entity IDs instead of entitys because then I can disguise entitys even before they exist
private static HashMap<UUID, HashSet<TargetedDisguise>> targetedDisguises = new HashMap<UUID, HashSet<TargetedDisguise>>(); private static HashMap<UUID, HashSet<TargetedDisguise>> targetedDisguises = new HashMap<UUID, HashSet<TargetedDisguise>>();
private static HashMap<Integer, HashSet<TargetedDisguise>> futureDisguises = new HashMap<Integer, HashSet<TargetedDisguise>>();
public static void addFutureDisguise(int entityId, TargetedDisguise disguise) {
if (!futureDisguises.containsKey(entityId)) {
futureDisguises.put(entityId, new HashSet<TargetedDisguise>());
}
futureDisguises.get(entityId).add(disguise);
}
public static void addDisguise(UUID entityId, TargetedDisguise disguise) { public static void addDisguise(UUID entityId, TargetedDisguise disguise) {
if (!getDisguises().containsKey(entityId)) { if (!getDisguises().containsKey(entityId)) {
@ -163,7 +171,13 @@ public class DisguiseUtilities {
} }
} }
public static TargetedDisguise getDisguise(Player observer, UUID 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)) { if (getDisguises().containsKey(entityId)) {
for (TargetedDisguise disguise : getDisguises().get(entityId)) { for (TargetedDisguise disguise : getDisguises().get(entityId)) {
if (disguise.canSee(observer)) { if (disguise.canSee(observer)) {