Started on a major rework of the way NPCLib handles packets.
This commit is contained in:
parent
1a5a3bc490
commit
f8325dcf27
|
@ -22,11 +22,12 @@ import java.util.*;
|
|||
/**
|
||||
* @author Jitse Boonstra
|
||||
*/
|
||||
public abstract class NPC {
|
||||
public abstract class NPC implements PacketHandler {
|
||||
|
||||
protected final UUID uuid = UUID.randomUUID();
|
||||
protected final String name = uuid.toString().replace("-", "").substring(0, 10);
|
||||
protected final int entityId = (int) Math.ceil(Math.random() * 100000) + 100000;
|
||||
// Below was previously = (int) Math.ceil(Math.random() * 100000) + 100000 (new is experimental).
|
||||
protected final int entityId = Integer.MAX_VALUE - NPCManager.getAllNPCs().size();
|
||||
|
||||
protected double cosFOV = Math.cos(Math.toRadians(60));
|
||||
|
||||
|
@ -45,7 +46,7 @@ public abstract class NPC {
|
|||
this.plugin = plugin;
|
||||
this.skin = skin;
|
||||
this.autoHideDistance = autoHideDistance;
|
||||
this.lines = (lines == null ? Collections.emptyList() : lines);
|
||||
this.lines = lines == null ? Collections.emptyList() : lines;
|
||||
|
||||
NPCManager.add(this);
|
||||
}
|
||||
|
@ -110,8 +111,11 @@ public abstract class NPC {
|
|||
return shown.contains(player.getUniqueId()) && !autoHidden.contains(player.getUniqueId());
|
||||
}
|
||||
|
||||
// Generate packets.
|
||||
public abstract void create(Location location);
|
||||
public void create(Location location) {
|
||||
this.location = location;
|
||||
|
||||
createPackets();
|
||||
}
|
||||
|
||||
public void show(Player player) {
|
||||
show(player, false);
|
||||
|
@ -160,13 +164,9 @@ public abstract class NPC {
|
|||
|
||||
private boolean canSeeNPC(Player player) {
|
||||
Vector dir = location.toVector().subtract(player.getEyeLocation().toVector()).normalize();
|
||||
double dot = dir.dot(player.getLocation().getDirection());
|
||||
return dot >= cosFOV;
|
||||
return dir.dot(player.getLocation().getDirection()) >= cosFOV;
|
||||
}
|
||||
|
||||
// Internal method.
|
||||
protected abstract void sendShowPackets(Player player);
|
||||
|
||||
public void hide(Player player) {
|
||||
hide(player, false, true);
|
||||
}
|
||||
|
@ -196,7 +196,4 @@ public abstract class NPC {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Internal method.
|
||||
protected abstract void sendHidePackets(Player player, boolean scheduler);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Jitse Boonstra
|
||||
*/
|
||||
|
||||
package net.jitse.npclib.api;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Jitse Boonstra
|
||||
*/
|
||||
interface PacketHandler {
|
||||
|
||||
void createPackets();
|
||||
|
||||
void sendShowPackets(Player player);
|
||||
|
||||
void sendHidePackets(Player player, boolean scheduler);
|
||||
}
|
|
@ -13,7 +13,6 @@ import net.jitse.npclib.nms.v1_8_R1.packets.PacketPlayOutScoreboardTeamWrapper;
|
|||
import net.jitse.npclib.skin.Skin;
|
||||
import net.minecraft.server.v1_8_R1.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
@ -37,9 +36,7 @@ public class NPC_v1_8_R1 extends NPC {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void create(Location location) {
|
||||
this.location = location;
|
||||
|
||||
public void createPackets() {
|
||||
this.hologram = new Hologram(location.clone().add(0, 0.5, 0), lines);
|
||||
hologram.generatePackets(false);
|
||||
|
||||
|
|
Loading…
Reference in New Issue