mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2024-09-12 01:48:07 +02:00
Change self disguises to use UUID's instead of integers as the key
This commit is contained in:
parent
04f6b18fff
commit
b6fca92817
@ -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;
|
||||
@ -142,7 +143,7 @@ public class DisguiseAPI {
|
||||
/**
|
||||
* 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;
|
||||
|
@ -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;
|
||||
@ -33,6 +34,7 @@ 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();
|
||||
@ -229,7 +231,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 +250,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 +276,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);
|
||||
|
@ -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;
|
||||
@ -39,7 +40,7 @@ public class DisguiseUtilities {
|
||||
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>>();
|
||||
|
||||
@ -247,7 +248,7 @@ public class DisguiseUtilities {
|
||||
return dis;
|
||||
}
|
||||
|
||||
public static HashMap<Integer, Integer> getSelfDisguisesIds() {
|
||||
public static HashMap<UUID, Integer> getSelfDisguisesIds() {
|
||||
return selfDisguisesIds;
|
||||
}
|
||||
|
||||
@ -377,17 +378,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 +445,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));
|
||||
@ -572,7 +573,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();
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user