Change the disguises to store UUID's. Not ints.
This commit is contained in:
parent
b6fca92817
commit
07bf03f154
@ -43,7 +43,7 @@ public class DisguiseAPI {
|
|||||||
disguise.setEntity(entity);
|
disguise.setEntity(entity);
|
||||||
}
|
}
|
||||||
// Stick the disguise in the disguises bin
|
// 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
|
// Resend the disguised entity's packet
|
||||||
DisguiseUtilities.refreshTrackers((TargetedDisguise) disguise);
|
DisguiseUtilities.refreshTrackers((TargetedDisguise) disguise);
|
||||||
// If he is a player, then self disguise himself
|
// If he is a player, then self disguise himself
|
||||||
@ -119,7 +119,7 @@ public class DisguiseAPI {
|
|||||||
public static Disguise getDisguise(Entity disguised) {
|
public static Disguise getDisguise(Entity disguised) {
|
||||||
if (disguised == null)
|
if (disguised == null)
|
||||||
return 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) {
|
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.getEntityId());
|
return DisguiseUtilities.getDisguise(observer, disguised.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -137,7 +137,7 @@ public class DisguiseAPI {
|
|||||||
public static Disguise[] getDisguises(Entity disguised) {
|
public static Disguise[] getDisguises(Entity disguised) {
|
||||||
if (disguised == null)
|
if (disguised == null)
|
||||||
return null;
|
return null;
|
||||||
return DisguiseUtilities.getDisguises(disguised.getEntityId());
|
return DisguiseUtilities.getDisguises(disguised.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +34,6 @@ public abstract class Disguise {
|
|||||||
private static JavaPlugin plugin;
|
private static JavaPlugin plugin;
|
||||||
private DisguiseType disguiseType;
|
private DisguiseType disguiseType;
|
||||||
private Entity entity;
|
private Entity entity;
|
||||||
private UUID disguiseUUID;
|
|
||||||
private boolean hearSelfDisguise = DisguiseConfig.isSelfDisguisesSoundsReplaced();
|
private boolean hearSelfDisguise = DisguiseConfig.isSelfDisguisesSoundsReplaced();
|
||||||
private boolean hideArmorFromSelf = DisguiseConfig.isHidingArmorFromSelf();
|
private boolean hideArmorFromSelf = DisguiseConfig.isHidingArmorFromSelf();
|
||||||
private boolean hideHeldItemFromSelf = DisguiseConfig.isHidingHeldItemFromSelf();
|
private boolean hideHeldItemFromSelf = DisguiseConfig.isHidingHeldItemFromSelf();
|
||||||
@ -375,7 +374,7 @@ public abstract class Disguise {
|
|||||||
velocityRunnable.cancel();
|
velocityRunnable.cancel();
|
||||||
} catch (Exception ex) {
|
} 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 this disguise has a entity set
|
||||||
if (getEntity() != null) {
|
if (getEntity() != null) {
|
||||||
// If this disguise is active
|
// If this disguise is active
|
||||||
@ -393,9 +392,9 @@ public abstract class Disguise {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Loop through the disguises because it could be used with a unknown entity id.
|
// 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()) {
|
while (itel.hasNext()) {
|
||||||
int id = itel.next();
|
UUID id = itel.next();
|
||||||
if (disguises.get(id).remove(this) && disguises.get(id).isEmpty()) {
|
if (disguises.get(id).remove(this) && disguises.get(id).isEmpty()) {
|
||||||
itel.remove();
|
itel.remove();
|
||||||
}
|
}
|
||||||
|
@ -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
|
// 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>();
|
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<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)) {
|
if (!getDisguises().containsKey(entityId)) {
|
||||||
getDisguises().put(entityId, new HashSet<TargetedDisguise>());
|
getDisguises().put(entityId, new HashSet<TargetedDisguise>());
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ public class DisguiseUtilities {
|
|||||||
public static void checkConflicts(TargetedDisguise disguise, String name) {
|
public static void checkConflicts(TargetedDisguise disguise, String name) {
|
||||||
// If the disguise is being used.. Else we may accidentally undisguise something else
|
// If the disguise is being used.. Else we may accidentally undisguise something else
|
||||||
if (DisguiseAPI.isDisguiseInUse(disguise)) {
|
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
|
// Iterate through the disguises
|
||||||
while (disguiseItel.hasNext()) {
|
while (disguiseItel.hasNext()) {
|
||||||
TargetedDisguise d = disguiseItel.next();
|
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)) {
|
if (getDisguises().containsKey(entityId)) {
|
||||||
for (TargetedDisguise disguise : getDisguises().get(entityId)) {
|
for (TargetedDisguise disguise : getDisguises().get(entityId)) {
|
||||||
if (disguise.canSee(observer)) {
|
if (disguise.canSee(observer)) {
|
||||||
@ -174,18 +174,18 @@ public class DisguiseUtilities {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<Integer, HashSet<TargetedDisguise>> getDisguises() {
|
public static HashMap<UUID, HashSet<TargetedDisguise>> getDisguises() {
|
||||||
return targetedDisguises;
|
return targetedDisguises;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TargetedDisguise[] getDisguises(int entityId) {
|
public static TargetedDisguise[] getDisguises(UUID entityId) {
|
||||||
if (getDisguises().containsKey(entityId)) {
|
if (getDisguises().containsKey(entityId)) {
|
||||||
return getDisguises().get(entityId).toArray(new TargetedDisguise[getDisguises().get(entityId).size()]);
|
return getDisguises().get(entityId).toArray(new TargetedDisguise[getDisguises().get(entityId).size()]);
|
||||||
}
|
}
|
||||||
return new TargetedDisguise[0];
|
return new TargetedDisguise[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TargetedDisguise getMainDisguise(int entityId) {
|
public static TargetedDisguise getMainDisguise(UUID entityId) {
|
||||||
TargetedDisguise toReturn = null;
|
TargetedDisguise toReturn = null;
|
||||||
if (getDisguises().containsKey(entityId)) {
|
if (getDisguises().containsKey(entityId)) {
|
||||||
for (TargetedDisguise disguise : getDisguises().get(entityId)) {
|
for (TargetedDisguise disguise : getDisguises().get(entityId)) {
|
||||||
@ -257,8 +257,8 @@ public class DisguiseUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isDisguiseInUse(Disguise disguise) {
|
public static boolean isDisguiseInUse(Disguise disguise) {
|
||||||
if (disguise.getEntity() != null && getDisguises().containsKey(disguise.getEntity().getEntityId())
|
if (disguise.getEntity() != null && getDisguises().containsKey(disguise.getEntity().getUniqueId())
|
||||||
&& getDisguises().get(disguise.getEntity().getEntityId()).contains(disguise)) {
|
&& getDisguises().get(disguise.getEntity().getUniqueId()).contains(disguise)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -364,7 +364,7 @@ public class DisguiseUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean removeDisguise(TargetedDisguise disguise) {
|
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().containsKey(entityId) && getDisguises().get(entityId).remove(disguise)) {
|
||||||
if (getDisguises().get(entityId).isEmpty()) {
|
if (getDisguises().get(entityId).isEmpty()) {
|
||||||
getDisguises().remove(entityId);
|
getDisguises().remove(entityId);
|
||||||
@ -551,8 +551,8 @@ public class DisguiseUtilities {
|
|||||||
public static void setupFakeDisguise(final Disguise disguise) {
|
public static void setupFakeDisguise(final Disguise disguise) {
|
||||||
Entity e = disguise.getEntity();
|
Entity e = disguise.getEntity();
|
||||||
// If the disguises entity is null, or the disguised entity isn't a player return
|
// 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())
|
if (e == null || !(e instanceof Player) || !getDisguises().containsKey(e.getUniqueId())
|
||||||
|| !getDisguises().get(e.getEntityId()).contains(disguise)) {
|
|| !getDisguises().get(e.getUniqueId()).contains(disguise)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Player player = (Player) e;
|
Player player = (Player) e;
|
||||||
|
Loading…
Reference in New Issue
Block a user