commit
1143398b2a
|
@ -14,4 +14,5 @@ out
|
|||
|
||||
# Maven
|
||||
log/
|
||||
target/
|
||||
target/
|
||||
dependency-reduced-pom.xml
|
|
@ -0,0 +1,71 @@
|
|||
<?xml version="1.0"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>net.jitse</groupId>
|
||||
<artifactId>npclib</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>npclib-api</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>npclib-commons</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>npclib-nms-v1_8_R1</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>npclib-nms-v1_8_R2</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>npclib-nms-v1_8_R3</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>npclib-nms-v1_9_R1</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>npclib-nms-v1_9_R2</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>npclib-nms-v1_10_R1</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>npclib-nms-v1_11_R1</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>npclib-nms-v1_12_R1</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>net.jitse</groupId>
|
||||
<artifactId>npclib</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>npclib-commons</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -5,20 +5,15 @@
|
|||
package net.jitse.npclib;
|
||||
|
||||
import net.jitse.npclib.api.NPC;
|
||||
import net.jitse.npclib.listeners.packet.PacketListener;
|
||||
import net.jitse.npclib.listeners.player.PlayerChangedWorldListener;
|
||||
import net.jitse.npclib.listeners.player.PlayerMoveOrTeleportListener;
|
||||
import net.jitse.npclib.listeners.player.PlayerQuitListener;
|
||||
import net.jitse.npclib.listeners.world.ChunkLoadListener;
|
||||
import net.jitse.npclib.listeners.world.ChunkUnloadListener;
|
||||
import net.jitse.npclib.listeners.ChunkListener;
|
||||
import net.jitse.npclib.listeners.PacketListener;
|
||||
import net.jitse.npclib.listeners.PlayerListener;
|
||||
import net.jitse.npclib.skin.Skin;
|
||||
import net.jitse.npclib.version.Version;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -28,21 +23,31 @@ public class NPCLib {
|
|||
|
||||
private final Server server;
|
||||
private final JavaPlugin plugin;
|
||||
private final Version version;
|
||||
private final Class<?> npcClass;
|
||||
|
||||
public NPCLib(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.server = plugin.getServer();
|
||||
|
||||
String versionName = server.getClass().getPackage().getName().split("\\.")[3];
|
||||
version = Version.getByName(versionName).orElse(null);
|
||||
|
||||
if (version == null) {
|
||||
server.getConsoleSender().sendMessage(ChatColor.RED + "NPCLib failed to initiate. Your server's version ("
|
||||
+ versionName + ") is not supported.");
|
||||
Class<?> npcClass = null;
|
||||
|
||||
try {
|
||||
npcClass = Class.forName("net.jitse.npclib.nms." + versionName + ".NPC_" + versionName);
|
||||
} catch (ClassNotFoundException e) {
|
||||
// Version not supported, error below
|
||||
}
|
||||
|
||||
server.getConsoleSender().sendMessage(ChatColor.BLUE + "[NPCLib] " + ChatColor.WHITE + "Enabled for version " + version.toString() + ".");
|
||||
this.npcClass = npcClass;
|
||||
|
||||
if (npcClass == null) {
|
||||
server.getConsoleSender().sendMessage(ChatColor.RED + "NPCLib failed to initiate. Your server's version ("
|
||||
+ versionName + ") is not supported.");
|
||||
return;
|
||||
}
|
||||
|
||||
server.getConsoleSender().sendMessage(ChatColor.BLUE + "[NPCLib] " + ChatColor.WHITE + "Enabled for version " + versionName + ".");
|
||||
|
||||
registerInternal();
|
||||
}
|
||||
|
@ -50,11 +55,8 @@ public class NPCLib {
|
|||
private void registerInternal() {
|
||||
PluginManager pluginManager = server.getPluginManager();
|
||||
|
||||
pluginManager.registerEvents(new PlayerChangedWorldListener(), plugin);
|
||||
pluginManager.registerEvents(new PlayerQuitListener(), plugin);
|
||||
pluginManager.registerEvents(new PlayerMoveOrTeleportListener(), plugin);
|
||||
pluginManager.registerEvents(new ChunkLoadListener(), plugin);
|
||||
pluginManager.registerEvents(new ChunkUnloadListener(), plugin);
|
||||
pluginManager.registerEvents(new PlayerListener(), plugin);
|
||||
pluginManager.registerEvents(new ChunkListener(), plugin);
|
||||
|
||||
new PacketListener().start(plugin);
|
||||
}
|
||||
|
@ -69,8 +71,8 @@ public class NPCLib {
|
|||
*/
|
||||
public NPC createNPC(Skin skin, double autoHideDistance, List<String> lines) {
|
||||
try {
|
||||
return version.createNPC(plugin, skin, autoHideDistance, lines);
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException exception) {
|
||||
return (NPC) npcClass.getConstructors()[0].newInstance(plugin, skin, autoHideDistance, lines);
|
||||
} catch (Exception exception) {
|
||||
server.getConsoleSender().sendMessage(ChatColor.RED + "NPCLib failed to create NPC. Please report this stacktrace:");
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
@ -109,4 +111,5 @@ public class NPCLib {
|
|||
public NPC createNPC() {
|
||||
return createNPC(null, 50, null);
|
||||
}
|
||||
|
||||
}
|
|
@ -162,13 +162,4 @@ public abstract class NPC {
|
|||
|
||||
// Internal method.
|
||||
protected abstract void sendHidePackets(Player player);
|
||||
|
||||
public void teleport(Player player, Location location) {
|
||||
this.location = location;
|
||||
|
||||
sendTeleportationPackets(player);
|
||||
}
|
||||
|
||||
// Internal method.
|
||||
public abstract void sendTeleportationPackets(Player player);
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (c) 2018 Jitse Boonstra
|
||||
*/
|
||||
|
||||
package net.jitse.npclib.listeners.world;
|
||||
package net.jitse.npclib.listeners;
|
||||
|
||||
import net.jitse.npclib.NPCManager;
|
||||
import net.jitse.npclib.api.NPC;
|
||||
|
@ -12,13 +12,37 @@ import org.bukkit.entity.Player;
|
|||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Jitse Boonstra
|
||||
* @author Jitse Boonstras
|
||||
*/
|
||||
public class ChunkLoadListener implements Listener {
|
||||
public class ChunkListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onChunkUnload(ChunkUnloadEvent event) {
|
||||
Chunk chunk = event.getChunk();
|
||||
|
||||
for (NPC npc : NPCManager.getAllNPCs()) {
|
||||
Chunk npcChunk = npc.getLocation().getChunk();
|
||||
|
||||
if (chunk.equals(npcChunk)) {
|
||||
// Unloaded chunk with NPC in it. Hiding it from all players currently shown to.
|
||||
|
||||
for (UUID uuid : npc.getShown()) {
|
||||
// Safety check so it doesn't send packets if the NPC has already
|
||||
// been automatically despawned by the system.
|
||||
if (npc.getAutoHidden().contains(uuid)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
npc.hide(Bukkit.getPlayer(uuid), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChunkLoad(ChunkLoadEvent event) {
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (c) 2018 Jitse Boonstra
|
||||
*/
|
||||
|
||||
package net.jitse.npclib.listeners.packet;
|
||||
package net.jitse.npclib.listeners;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
|
@ -39,6 +39,7 @@ public class PacketListener {
|
|||
|
||||
@Override
|
||||
public Object onPacketInAsync(Player player, Channel channel, Object packet) {
|
||||
|
||||
if (packetPlayInUseEntityClazz.isInstance(packet)) {
|
||||
NPC npc = NPCManager.getAllNPCs().stream().filter(
|
||||
check -> check.isActuallyShown(player) && check.getEntityId() == (int) entityIdField.get(packet))
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (c) 2018 Jitse Boonstra
|
||||
*/
|
||||
|
||||
package net.jitse.npclib.listeners.player;
|
||||
package net.jitse.npclib.listeners;
|
||||
|
||||
import net.jitse.npclib.NPCManager;
|
||||
import net.jitse.npclib.api.NPC;
|
||||
|
@ -12,13 +12,46 @@ import org.bukkit.World;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
/**
|
||||
* @author Jitse Boonstra
|
||||
*/
|
||||
public class PlayerMoveOrTeleportListener implements Listener {
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
for (NPC npc : NPCManager.getAllNPCs()) {
|
||||
if (npc.getAutoHidden().contains(player.getUniqueId())) {
|
||||
npc.getAutoHidden().remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
// Don't need to use NPC#hide since the entity is not registered in the NMS server.
|
||||
if (npc.getShown().contains(player.getUniqueId())) {
|
||||
npc.getShown().remove(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
World from = event.getFrom();
|
||||
|
||||
// The PlayerTeleportEvent is call, and will handle visibility in the new world.
|
||||
for (NPC npc : NPCManager.getAllNPCs()) {
|
||||
if (npc.getLocation().getWorld().equals(from)) {
|
||||
if (!npc.getAutoHidden().contains(player.getUniqueId())) {
|
||||
npc.getAutoHidden().add(player.getUniqueId());
|
||||
npc.hide(player, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>pom</packaging>
|
||||
<parent>
|
||||
<groupId>net.jitse</groupId>
|
||||
<artifactId>npclib</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>npclib-nms</artifactId>
|
||||
|
||||
<modules>
|
||||
<module>v1_8_R1</module>
|
||||
<module>v1_8_R2</module>
|
||||
<module>v1_8_R3</module>
|
||||
<module>v1_9_R1</module>
|
||||
<module>v1_9_R2</module>
|
||||
<module>v1_10_R1</module>
|
||||
<module>v1_11_R1</module>
|
||||
<module>v1_12_R1</module>
|
||||
</modules>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>npclib-commons</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>net.jitse</groupId>
|
||||
<artifactId>npclib-nms</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>npclib-nms-v1_10_R1</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.10.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -23,7 +23,7 @@ import java.util.List;
|
|||
/**
|
||||
* @author Jitse Boonstra
|
||||
*/
|
||||
public class NPC_V1_10_R1 extends NPC {
|
||||
public class NPC_v1_10_R1 extends NPC {
|
||||
|
||||
private Hologram hologram;
|
||||
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
||||
|
@ -32,7 +32,7 @@ public class NPC_V1_10_R1 extends NPC {
|
|||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||
|
||||
public NPC_V1_10_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||
public NPC_v1_10_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||
super(plugin, skin, autoHideDistance, lines);
|
||||
}
|
||||
|
||||
|
@ -100,9 +100,4 @@ public class NPC_V1_10_R1 extends NPC {
|
|||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
||||
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTeleportationPackets(Player player) {
|
||||
// Todo create this method.
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>net.jitse</groupId>
|
||||
<artifactId>npclib-nms</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>npclib-nms-v1_11_R1</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.11.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -23,7 +23,7 @@ import java.util.List;
|
|||
/**
|
||||
* @author Jitse Boonstra
|
||||
*/
|
||||
public class NPC_V1_11_R1 extends NPC {
|
||||
public class NPC_v1_11_R1 extends NPC {
|
||||
|
||||
private Hologram hologram;
|
||||
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
||||
|
@ -32,7 +32,7 @@ public class NPC_V1_11_R1 extends NPC {
|
|||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||
|
||||
public NPC_V1_11_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||
public NPC_v1_11_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||
super(plugin, skin, autoHideDistance, lines);
|
||||
}
|
||||
|
||||
|
@ -100,9 +100,4 @@ public class NPC_V1_11_R1 extends NPC {
|
|||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
||||
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTeleportationPackets(Player player) {
|
||||
// Todo create this method.
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>net.jitse</groupId>
|
||||
<artifactId>npclib-nms</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>npclib-nms-v1_12_R1</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -6,7 +6,10 @@ package net.jitse.npclib.nms.v1_12_R1;
|
|||
|
||||
import net.jitse.npclib.api.NPC;
|
||||
import net.jitse.npclib.nms.holograms.Hologram;
|
||||
import net.jitse.npclib.nms.v1_12_R1.packets.*;
|
||||
import net.jitse.npclib.nms.v1_12_R1.packets.PacketPlayOutEntityHeadRotationWrapper;
|
||||
import net.jitse.npclib.nms.v1_12_R1.packets.PacketPlayOutNamedEntitySpawnWrapper;
|
||||
import net.jitse.npclib.nms.v1_12_R1.packets.PacketPlayOutPlayerInfoWrapper;
|
||||
import net.jitse.npclib.nms.v1_12_R1.packets.PacketPlayOutScoreboardTeamWrapper;
|
||||
import net.jitse.npclib.skin.Skin;
|
||||
import net.minecraft.server.v1_12_R1.*;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -20,7 +23,7 @@ import java.util.List;
|
|||
/**
|
||||
* @author Jitse Boonstra
|
||||
*/
|
||||
public class NPC_V1_12_R1 extends NPC {
|
||||
public class NPC_v1_12_R1 extends NPC {
|
||||
|
||||
private Hologram hologram;
|
||||
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
||||
|
@ -29,7 +32,7 @@ public class NPC_V1_12_R1 extends NPC {
|
|||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||
|
||||
public NPC_V1_12_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||
public NPC_v1_12_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||
super(plugin, skin, autoHideDistance, lines);
|
||||
}
|
||||
|
||||
|
@ -79,9 +82,9 @@ public class NPC_V1_12_R1 extends NPC {
|
|||
|
||||
hologram.spawn(player);
|
||||
|
||||
// Todo: Test this new delay speed (custom skin render issue).
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
||||
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 10);
|
||||
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -97,13 +100,4 @@ public class NPC_V1_12_R1 extends NPC {
|
|||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
||||
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTeleportationPackets(Player player) {
|
||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||
|
||||
PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleportWrapper().create(entityId, location);
|
||||
|
||||
playerConnection.sendPacket(packetPlayOutEntityTeleport);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>net.jitse</groupId>
|
||||
<artifactId>npclib-nms</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>npclib-nms-v1_8_R1</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.8-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -23,7 +23,7 @@ import java.util.List;
|
|||
/**
|
||||
* @author Jitse Boonstra
|
||||
*/
|
||||
public class NPC_V1_8_R1 extends NPC {
|
||||
public class NPC_v1_8_R1 extends NPC {
|
||||
|
||||
private Hologram hologram;
|
||||
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
||||
|
@ -32,7 +32,7 @@ public class NPC_V1_8_R1 extends NPC {
|
|||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||
|
||||
public NPC_V1_8_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||
public NPC_v1_8_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||
super(plugin, skin, autoHideDistance, lines);
|
||||
}
|
||||
|
||||
|
@ -99,9 +99,4 @@ public class NPC_V1_8_R1 extends NPC {
|
|||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
||||
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTeleportationPackets(Player player) {
|
||||
// Todo create this method.
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>net.jitse</groupId>
|
||||
<artifactId>npclib-nms</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>npclib-nms-v1_8_R2</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.8.3-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -23,7 +23,7 @@ import java.util.List;
|
|||
/**
|
||||
* @author Jitse Boonstra
|
||||
*/
|
||||
public class NPC_V1_8_R2 extends NPC {
|
||||
public class NPC_v1_8_R2 extends NPC {
|
||||
|
||||
private Hologram hologram;
|
||||
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
||||
|
@ -32,7 +32,7 @@ public class NPC_V1_8_R2 extends NPC {
|
|||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||
|
||||
public NPC_V1_8_R2(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||
public NPC_v1_8_R2(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||
super(plugin, skin, autoHideDistance, lines);
|
||||
}
|
||||
|
||||
|
@ -100,9 +100,4 @@ public class NPC_V1_8_R2 extends NPC {
|
|||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
||||
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTeleportationPackets(Player player) {
|
||||
// Todo create this method.
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>net.jitse</groupId>
|
||||
<artifactId>npclib-nms</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>npclib-nms-v1_8_R3</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.8.8-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -23,7 +23,7 @@ import java.util.List;
|
|||
/**
|
||||
* @author Jitse Boonstra
|
||||
*/
|
||||
public class NPC_V1_8_R3 extends NPC {
|
||||
public class NPC_v1_8_R3 extends NPC {
|
||||
|
||||
private Hologram hologram;
|
||||
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
||||
|
@ -32,7 +32,7 @@ public class NPC_V1_8_R3 extends NPC {
|
|||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||
|
||||
public NPC_V1_8_R3(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||
public NPC_v1_8_R3(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||
super(plugin, skin, autoHideDistance, lines);
|
||||
}
|
||||
|
||||
|
@ -100,9 +100,4 @@ public class NPC_V1_8_R3 extends NPC {
|
|||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
||||
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTeleportationPackets(Player player) {
|
||||
// Todo create this method.
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>net.jitse</groupId>
|
||||
<artifactId>npclib-nms</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>npclib-nms-v1_9_R1</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.9-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -23,7 +23,7 @@ import java.util.List;
|
|||
/**
|
||||
* @author Jitse Boonstra
|
||||
*/
|
||||
public class NPC_V1_9_R1 extends NPC {
|
||||
public class NPC_v1_9_R1 extends NPC {
|
||||
|
||||
private Hologram hologram;
|
||||
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
||||
|
@ -32,7 +32,7 @@ public class NPC_V1_9_R1 extends NPC {
|
|||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||
|
||||
public NPC_V1_9_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||
public NPC_v1_9_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||
super(plugin, skin, autoHideDistance, lines);
|
||||
}
|
||||
|
||||
|
@ -100,9 +100,4 @@ public class NPC_V1_9_R1 extends NPC {
|
|||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
||||
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTeleportationPackets(Player player) {
|
||||
// Todo create this method.
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>net.jitse</groupId>
|
||||
<artifactId>npclib-nms</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>npclib-nms-v1_9_R2</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.9.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -23,7 +23,7 @@ import java.util.List;
|
|||
/**
|
||||
* @author Jitse Boonstra
|
||||
*/
|
||||
public class NPC_V1_9_R2 extends NPC {
|
||||
public class NPC_v1_9_R2 extends NPC {
|
||||
|
||||
private Hologram hologram;
|
||||
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
||||
|
@ -32,7 +32,7 @@ public class NPC_V1_9_R2 extends NPC {
|
|||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||
|
||||
public NPC_V1_9_R2(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||
public NPC_v1_9_R2(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||
super(plugin, skin, autoHideDistance, lines);
|
||||
}
|
||||
|
||||
|
@ -100,9 +100,4 @@ public class NPC_V1_9_R2 extends NPC {
|
|||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
||||
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTeleportationPackets(Player player) {
|
||||
// Todo create this method.
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>net.jitse</groupId>
|
||||
<artifactId>npclib</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>npclib-plugin</artifactId>
|
||||
|
||||
<build>
|
||||
<directory>../target</directory>
|
||||
<finalName>NPCLib-v${project.parent.version}</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>npclib-api</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -23,7 +23,6 @@ import java.util.Arrays;
|
|||
public class NPCLibPlugin extends JavaPlugin implements Listener {
|
||||
|
||||
private NPCLib npcLib;
|
||||
private NPC npc;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
@ -33,6 +32,7 @@ public class NPCLibPlugin extends JavaPlugin implements Listener {
|
|||
ChatColor.GRAY + "This is a test plugin usually used for development reasons. " +
|
||||
"You can spawn NPCs by pressing [shift] in game.");
|
||||
|
||||
|
||||
getServer().getPluginManager().registerEvents(this, this);
|
||||
getServer().getPluginManager().registerEvents(new NPCListener(), this);
|
||||
}
|
||||
|
@ -48,21 +48,17 @@ public class NPCLibPlugin extends JavaPlugin implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
if (npc != null) {
|
||||
npc.teleport(event.getPlayer(), event.getPlayer().getLocation());
|
||||
} else {
|
||||
MineSkinFetcher.fetchSkinFromIdAsync(168841, skin -> {
|
||||
npc = npcLib.createNPC(skin, Arrays.asList(
|
||||
ChatColor.BOLD + "NPC Library", "",
|
||||
"Create your own", "non-player characters",
|
||||
"with the simplistic", "API of NPCLib!"
|
||||
));
|
||||
npc.create(event.getPlayer().getLocation());
|
||||
MineSkinFetcher.fetchSkinFromIdAsync(168841, skin -> {
|
||||
NPC npc = npcLib.createNPC(skin, Arrays.asList(
|
||||
ChatColor.BOLD + "NPC Library", "",
|
||||
"Create your own", "non-player characters",
|
||||
"with the simplistic", "API of NPCLib!"
|
||||
));
|
||||
npc.create(event.getPlayer().getLocation());
|
||||
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
npc.show(player);
|
||||
}
|
||||
});
|
||||
}
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
npc.show(player);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<groupId>net.jitse</groupId>
|
||||
<artifactId>npclib</artifactId>
|
||||
<version>1.0.4</version>
|
||||
|
||||
<name>NPCLib</name>
|
||||
<url>https://github.com/JitseB/npclib</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>MIT</name>
|
||||
<url>https://opensource.org/licenses/MIT</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.6.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<!--Spigot API-->
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<modules>
|
||||
<module>commons</module>
|
||||
<module>nms</module>
|
||||
<module>api</module>
|
||||
<module>plugin</module>
|
||||
</modules>
|
||||
</project>
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Jitse Boonstra
|
||||
*/
|
||||
|
||||
package net.jitse.npclib.listeners.player;
|
||||
|
||||
import net.jitse.npclib.NPCManager;
|
||||
import net.jitse.npclib.api.NPC;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
|
||||
/**
|
||||
* @author Jitse Boonstra
|
||||
*/
|
||||
public class PlayerChangedWorldListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
World from = event.getFrom();
|
||||
|
||||
// The PlayerTeleportEvent is call, and will handle visibility in the new world.
|
||||
for (NPC npc : NPCManager.getAllNPCs()) {
|
||||
if (npc.getLocation().getWorld().equals(from)) {
|
||||
if (!npc.getAutoHidden().contains(player.getUniqueId())) {
|
||||
npc.getAutoHidden().add(player.getUniqueId());
|
||||
npc.hide(player, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Jitse Boonstra
|
||||
*/
|
||||
|
||||
package net.jitse.npclib.listeners.player;
|
||||
|
||||
import net.jitse.npclib.NPCManager;
|
||||
import net.jitse.npclib.api.NPC;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
/**
|
||||
* @author Jitse Boonstra
|
||||
*/
|
||||
public class PlayerQuitListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
for (NPC npc : NPCManager.getAllNPCs()) {
|
||||
if (npc.getAutoHidden().contains(player.getUniqueId())) {
|
||||
npc.getAutoHidden().remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
if (npc.isActuallyShown(player)) {
|
||||
npc.hide(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Jitse Boonstra
|
||||
*/
|
||||
|
||||
package net.jitse.npclib.listeners.world;
|
||||
|
||||
import net.jitse.npclib.NPCManager;
|
||||
import net.jitse.npclib.api.NPC;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Jitse Boonstra
|
||||
*/
|
||||
public class ChunkUnloadListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onChunkUnload(ChunkUnloadEvent event) {
|
||||
Chunk chunk = event.getChunk();
|
||||
|
||||
for (NPC npc : NPCManager.getAllNPCs()) {
|
||||
Chunk npcChunk = npc.getLocation().getChunk();
|
||||
|
||||
if (chunk.equals(npcChunk)) {
|
||||
// Unloaded chunk with NPC in it. Hiding it from all players currently shown to.
|
||||
|
||||
for (UUID uuid : npc.getShown()) {
|
||||
// Safety check so it doesn't send packets if the NPC has already
|
||||
// been automatically despawned by the system.
|
||||
if (npc.getAutoHidden().contains(uuid)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
npc.hide(Bukkit.getPlayer(uuid), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Jitse Boonstra
|
||||
*/
|
||||
|
||||
package net.jitse.npclib.nms.v1_12_R1.packets;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import net.minecraft.server.v1_12_R1.PacketPlayOutEntityTeleport;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
/**
|
||||
* @author Jitse Boonstra
|
||||
*/
|
||||
public class PacketPlayOutEntityTeleportWrapper {
|
||||
|
||||
public PacketPlayOutEntityTeleport create(int entityId, Location location) {
|
||||
PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport();
|
||||
|
||||
Reflection.getField(packetPlayOutEntityTeleport.getClass(), "a", int.class)
|
||||
.set(packetPlayOutEntityTeleport, entityId);
|
||||
Reflection.getField(packetPlayOutEntityTeleport.getClass(), "b", double.class)
|
||||
.set(packetPlayOutEntityTeleport, location.getX());
|
||||
Reflection.getField(packetPlayOutEntityTeleport.getClass(), "c", double.class)
|
||||
.set(packetPlayOutEntityTeleport, location.getY());
|
||||
Reflection.getField(packetPlayOutEntityTeleport.getClass(), "d", double.class)
|
||||
.set(packetPlayOutEntityTeleport, location.getZ());
|
||||
Reflection.getField(packetPlayOutEntityTeleport.getClass(), "e", byte.class)
|
||||
.set(packetPlayOutEntityTeleport, (byte) ((int) (location.getYaw() * 256.0F / 360.0F)));
|
||||
Reflection.getField(packetPlayOutEntityTeleport.getClass(), "f", byte.class)
|
||||
.set(packetPlayOutEntityTeleport, (byte) ((int) (location.getPitch() * 256.0F / 360.0F)));
|
||||
Reflection.getField(packetPlayOutEntityTeleport.getClass(), "g", boolean.class)
|
||||
.set(packetPlayOutEntityTeleport, location.getBlock().getRelative(BlockFace.DOWN).getType() != Material.AIR);
|
||||
|
||||
return packetPlayOutEntityTeleport;
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Jitse Boonstra
|
||||
*/
|
||||
|
||||
package net.jitse.npclib.version;
|
||||
|
||||
import net.jitse.npclib.api.NPC;
|
||||
import net.jitse.npclib.nms.v1_10_R1.NPC_V1_10_R1;
|
||||
import net.jitse.npclib.nms.v1_11_R1.NPC_V1_11_R1;
|
||||
import net.jitse.npclib.nms.v1_12_R1.NPC_V1_12_R1;
|
||||
import net.jitse.npclib.nms.v1_8_R1.NPC_V1_8_R1;
|
||||
import net.jitse.npclib.nms.v1_8_R2.NPC_V1_8_R2;
|
||||
import net.jitse.npclib.nms.v1_8_R3.NPC_V1_8_R3;
|
||||
import net.jitse.npclib.nms.v1_9_R1.NPC_V1_9_R1;
|
||||
import net.jitse.npclib.nms.v1_9_R2.NPC_V1_9_R2;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author Jitse Boonstra
|
||||
*/
|
||||
public enum Version {
|
||||
|
||||
V1_8_R1("v1_8_R1", NPC_V1_8_R1.class),
|
||||
V1_8_R2("v1_8_R2", NPC_V1_8_R2.class),
|
||||
V1_8_R3("v1_8_R3", NPC_V1_8_R3.class),
|
||||
V1_9_R1("v1_9_R1", NPC_V1_9_R1.class),
|
||||
V1_9_R2("v1_9_R2", NPC_V1_9_R2.class),
|
||||
V1_10_R1("v1_10_R1", NPC_V1_10_R1.class),
|
||||
V1_11_R1("v1_11_R1", NPC_V1_11_R1.class),
|
||||
V1_12_R1("v1_12_R1", NPC_V1_12_R1.class);
|
||||
|
||||
private String version;
|
||||
private Class<?> clazz;
|
||||
|
||||
Version(String version, Class<?> clazz) {
|
||||
this.version = version;
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public NPC createNPC(Object... params) throws InstantiationException, IllegalAccessException, InvocationTargetException {
|
||||
return (NPC) clazz.getConstructors()[0].newInstance(params);
|
||||
}
|
||||
|
||||
public static Optional<Version> getByName(String version) {
|
||||
return Arrays.stream(values()).filter(value -> value.version.equals(version)).findFirst();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue