Potential packet fix
This commit is contained in:
parent
0a66b9dcef
commit
4eb7c8238d
|
@ -20,15 +20,13 @@ import java.util.UUID;
|
||||||
public interface NPC {
|
public interface NPC {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param player
|
* @param player
|
||||||
* @return unique hologram for that user
|
* @return unique hologram for that user
|
||||||
*/
|
*/
|
||||||
Hologram getPlayerHologram(Player player);
|
Hologram getPlayerHologram(Player player);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @param uniqueLines The text that the targetPlayer will see
|
||||||
* @param uniqueLines The text that the targetPlayer will see
|
|
||||||
* @param targetPlayer The target player
|
* @param targetPlayer The target player
|
||||||
* @return object instance
|
* @return object instance
|
||||||
* @author Gatt
|
* @author Gatt
|
||||||
|
@ -36,17 +34,15 @@ public interface NPC {
|
||||||
NPC setPlayerLines(List<String> uniqueLines, Player targetPlayer);
|
NPC setPlayerLines(List<String> uniqueLines, Player targetPlayer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @param uniqueLines The text that the targetPlayer will see
|
||||||
* @param uniqueLines The text that the targetPlayer will see
|
|
||||||
* @param targetPlayer The target player
|
* @param targetPlayer The target player
|
||||||
* @param update whether or not to send the update packets
|
* @param update whether or not to send the update packets
|
||||||
* @return object instance
|
* @return object instance
|
||||||
* @author Gatt
|
* @author Gatt
|
||||||
*/
|
*/
|
||||||
NPC setPlayerLines(List<String> uniqueLines, Player targetPlayer, boolean update);
|
NPC setPlayerLines(List<String> uniqueLines, Player targetPlayer, boolean update);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param targetPlayer The target player
|
* @param targetPlayer The target player
|
||||||
* @return the lines that the targetPlayer will see, if null; default lines.
|
* @return the lines that the targetPlayer will see, if null; default lines.
|
||||||
*/
|
*/
|
||||||
|
@ -91,6 +87,13 @@ public interface NPC {
|
||||||
*/
|
*/
|
||||||
NPC create();
|
NPC create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the NPCs packets have already been generated.
|
||||||
|
*
|
||||||
|
* @return Whether NPC#create has been called yet.
|
||||||
|
*/
|
||||||
|
boolean isCreated();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the ID of the NPC.
|
* Get the ID of the NPC.
|
||||||
*
|
*
|
||||||
|
|
|
@ -41,6 +41,7 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
|
||||||
protected UUID uuid = new UUID(new Random().nextLong(), 0);
|
protected UUID uuid = new UUID(new Random().nextLong(), 0);
|
||||||
protected String name = uuid.toString().replace("-", "").substring(0, 10);
|
protected String name = uuid.toString().replace("-", "").substring(0, 10);
|
||||||
protected GameProfile gameProfile = new GameProfile(uuid, name);
|
protected GameProfile gameProfile = new GameProfile(uuid, name);
|
||||||
|
protected boolean created = false;
|
||||||
|
|
||||||
protected NPCLib instance;
|
protected NPCLib instance;
|
||||||
protected List<String> text;
|
protected List<String> text;
|
||||||
|
@ -177,7 +178,7 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isShown(Player player) {
|
public boolean isShown(Player player) {
|
||||||
if (player == null) return false;
|
Objects.requireNonNull(player, "Player object cannot be null");
|
||||||
return shown.contains(player.getUniqueId()) && !autoHidden.contains(player.getUniqueId());
|
return shown.contains(player.getUniqueId()) && !autoHidden.contains(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,9 +191,15 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
|
||||||
@Override
|
@Override
|
||||||
public NPC create() {
|
public NPC create() {
|
||||||
createPackets();
|
createPackets();
|
||||||
|
this.created = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCreated() {
|
||||||
|
return created;
|
||||||
|
}
|
||||||
|
|
||||||
public void onLogout(Player player) {
|
public void onLogout(Player player) {
|
||||||
getAutoHidden().remove(player.getUniqueId());
|
getAutoHidden().remove(player.getUniqueId());
|
||||||
getShown().remove(player.getUniqueId()); // Don't need to use NPC#hide since the entity is not registered in the NMS server.
|
getShown().remove(player.getUniqueId()); // Don't need to use NPC#hide since the entity is not registered in the NMS server.
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class PacketListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean handleInteractPacket(Player player, Object packet) {
|
private boolean handleInteractPacket(Player player, Object packet) {
|
||||||
if (!packetPlayInUseEntityClazz.isInstance(packet))
|
if (!packetPlayInUseEntityClazz.isInstance(packet) || player == null)
|
||||||
return true; // We aren't handling the packet.
|
return true; // We aren't handling the packet.
|
||||||
|
|
||||||
NPCBase npc = null;
|
NPCBase npc = null;
|
||||||
|
@ -62,7 +62,7 @@ public class PacketListener {
|
||||||
// ~ Kneesnap, 9 / 20 / 2019.
|
// ~ Kneesnap, 9 / 20 / 2019.
|
||||||
|
|
||||||
for (NPCBase testNPC : NPCManager.getAllNPCs()) {
|
for (NPCBase testNPC : NPCManager.getAllNPCs()) {
|
||||||
if (testNPC.isShown(player) && testNPC.getEntityId() == packetEntityId) {
|
if (testNPC.isCreated() && testNPC.isShown(player) && testNPC.getEntityId() == packetEntityId) {
|
||||||
npc = testNPC;
|
npc = testNPC;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,17 +36,17 @@ public class NPC_v1_16_R1 extends NPCBase {
|
||||||
public NPC_v1_16_R1(NPCLib instance, List<String> lines) {
|
public NPC_v1_16_R1(NPCLib instance, List<String> lines) {
|
||||||
super(instance, lines);
|
super(instance, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Hologram getPlayerHologram(Player player) {
|
public Hologram getPlayerHologram(Player player) {
|
||||||
Hologram holo = super.getPlayerHologram(player);
|
Hologram holo = super.getPlayerHologram(player);
|
||||||
if (holo == null){
|
if (holo == null) {
|
||||||
holo = new Hologram(MinecraftVersion.V1_16_R1, location.clone().add(0, 0.5, 0), getPlayerLines(player));
|
holo = new Hologram(MinecraftVersion.V1_16_R1, location.clone().add(0, 0.5, 0), getPlayerLines(player));
|
||||||
}
|
}
|
||||||
super.textDisplayHolograms.put(player.getUniqueId(), holo);
|
super.textDisplayHolograms.put(player.getUniqueId(), holo);
|
||||||
return holo;
|
return holo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createPackets() {
|
public void createPackets() {
|
||||||
Bukkit.getOnlinePlayers().forEach(this::createPackets);
|
Bukkit.getOnlinePlayers().forEach(this::createPackets);
|
||||||
|
|
Loading…
Reference in New Issue