Change the disguises to store UUID's. Not ints.

This commit is contained in:
libraryaddict 2014-04-03 01:54:36 +13:00
parent b6fca92817
commit 07bf03f154
3 changed files with 19 additions and 20 deletions

View File

@ -43,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
@ -119,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());
}
/**
@ -128,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.getUniqueId());
}
/**
@ -137,7 +137,7 @@ public class DisguiseAPI {
public static Disguise[] getDisguises(Entity disguised) {
if (disguised == null)
return null;
return DisguiseUtilities.getDisguises(disguised.getEntityId());
return DisguiseUtilities.getDisguises(disguised.getUniqueId());
}
/**

View File

@ -34,7 +34,6 @@ public abstract class Disguise {
private static JavaPlugin plugin;
private DisguiseType disguiseType;
private Entity entity;
private UUID disguiseUUID;
private boolean hearSelfDisguise = DisguiseConfig.isSelfDisguisesSoundsReplaced();
private boolean hideArmorFromSelf = DisguiseConfig.isHidingArmorFromSelf();
private boolean hideHeldItemFromSelf = DisguiseConfig.isHidingHeldItemFromSelf();
@ -375,7 +374,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
@ -393,9 +392,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();
}

View File

@ -42,9 +42,9 @@ public class DisguiseUtilities {
// Realistically I could probably use a ID like "4" for everyone, seeing as no one shares the ID
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>());
}
@ -62,7 +62,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();
@ -163,7 +163,7 @@ public class DisguiseUtilities {
}
}
public static TargetedDisguise getDisguise(Player observer, int entityId) {
public static TargetedDisguise getDisguise(Player observer, UUID entityId) {
if (getDisguises().containsKey(entityId)) {
for (TargetedDisguise disguise : getDisguises().get(entityId)) {
if (disguise.canSee(observer)) {
@ -174,18 +174,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)) {
@ -257,8 +257,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;
@ -364,7 +364,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);
@ -551,8 +551,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;