From e0752c5d7e84c2880211677bb2b41be522b9d591 Mon Sep 17 00:00:00 2001 From: Jitse Boonstra Date: Sat, 3 Aug 2019 13:47:12 +0200 Subject: [PATCH] Updated the library. --- api/pom.xml | 53 ++++++++ .../comphenix/tinyprotocol/Reflection.java | 4 + .../comphenix/tinyprotocol/TinyProtocol.java | 47 +++---- .../main/java/net/jitse/npclib/NPCLib.java | 113 +++++++++++++++++ .../main/java/net/jitse/npclib/api/NPC.java | 83 ++++++++++++ .../jitse/npclib/api/events/NPCHideEvent.java | 19 +-- .../npclib/api}/events/NPCInteractEvent.java | 7 +- .../jitse/npclib/api/events/NPCShowEvent.java | 19 +-- .../npclib/api}/skin/MineSkinFetcher.java | 2 +- .../java/net/jitse/npclib/api}/skin/Skin.java | 5 +- .../jitse/npclib/api/utilities/Logger.java | 46 +++++++ .../net/jitse/npclib/hologram}/Hologram.java | 46 ++++--- .../npclib/internal/MinecraftVersion.java | 15 +++ .../jitse/npclib/internal}/NPCManager.java | 12 +- .../jitse/npclib/internal}/PacketHandler.java | 2 +- .../net/jitse/npclib/internal/SimpleNPC.java | 101 +++++++++------ .../jitse/npclib/listeners/ChunkListener.java | 17 ++- .../npclib/listeners/PacketListener.java | 25 ++-- .../npclib/listeners/PlayerListener.java | 19 ++- commons/pom.xml | 51 -------- .../main/java/net/jitse/npclib/NPCLib.java | 120 ------------------ .../net/jitse/npclib/api/ActionHandler.java | 17 --- .../jitse/npclib/api/packet/NPCPacket.java | 21 --- .../api/wrapper/GameProfileWrapper.java | 56 -------- .../jitse/npclib/events/click/ClickType.java | 13 -- .../npclib/events/trigger/TriggerType.java | 13 -- .../jitse/npclib/logging/NPCLibLogger.java | 26 ---- nms/pom.xml | 38 ++++++ nms/v1_10_R1/pom.xml | 3 +- .../npclib/nms/v1_10_R1/NPC_v1_10_R1.java | 21 ++- .../PacketPlayOutPlayerInfoWrapper.java | 5 +- nms/v1_11_R1/pom.xml | 3 +- .../npclib/nms/v1_11_R1/NPC_v1_11_R1.java | 21 ++- .../PacketPlayOutPlayerInfoWrapper.java | 5 +- nms/v1_12_R1/pom.xml | 3 +- .../npclib/nms/v1_12_R1/NPC_v1_12_R1.java | 22 ++-- .../PacketPlayOutPlayerInfoWrapper.java | 5 +- nms/v1_13_R1/pom.xml | 3 +- .../npclib/nms/v1_13_R1/NPC_v1_13_R1.java | 22 ++-- .../PacketPlayOutPlayerInfoWrapper.java | 5 +- nms/v1_13_R2/pom.xml | 3 +- .../npclib/nms/v1_13_R2/NPC_v1_13_R2.java | 21 ++- .../PacketPlayOutPlayerInfoWrapper.java | 5 +- nms/v1_14_R1/pom.xml | 24 ++++ .../npclib/nms/v1_14_R1/NPC_v1_14_R1.java | 99 +++++++++++++++ ...acketPlayOutEntityHeadRotationWrapper.java | 26 ++++ .../PacketPlayOutNamedEntitySpawnWrapper.java | 47 +++++++ .../PacketPlayOutPlayerInfoWrapper.java | 43 +++++++ .../PacketPlayOutScoreboardTeamWrapper.java | 53 ++++++++ nms/v1_8_R1/pom.xml | 21 ++- .../jitse/npclib/nms/v1_8_R1/NPC_v1_8_R1.java | 21 ++- .../PacketPlayOutPlayerInfoWrapper.java | 5 +- nms/v1_8_R2/pom.xml | 3 +- .../jitse/npclib/nms/v1_8_R2/NPC_v1_8_R2.java | 21 ++- .../PacketPlayOutPlayerInfoWrapper.java | 5 +- nms/v1_8_R3/pom.xml | 3 +- .../jitse/npclib/nms/v1_8_R3/NPC_v1_8_R3.java | 21 ++- .../PacketPlayOutPlayerInfoWrapper.java | 5 +- nms/v1_9_R1/pom.xml | 3 +- .../jitse/npclib/nms/v1_9_R1/NPC_v1_9_R1.java | 21 ++- .../PacketPlayOutPlayerInfoWrapper.java | 5 +- nms/v1_9_R2/pom.xml | 3 +- .../jitse/npclib/nms/v1_9_R2/NPC_v1_9_R2.java | 21 ++- .../PacketPlayOutPlayerInfoWrapper.java | 5 +- plugin/pom.xml | 110 ++++++++++++++-- .../net/jitse/npclib/plugin/NPCLibPlugin.java | 8 -- plugin/src/main/resources/plugin.yml | 6 +- pom.xml | 94 ++++++-------- 68 files changed, 1115 insertions(+), 695 deletions(-) create mode 100644 api/pom.xml rename {commons => api}/src/main/java/com/comphenix/tinyprotocol/Reflection.java (99%) rename {commons => api}/src/main/java/com/comphenix/tinyprotocol/TinyProtocol.java (84%) create mode 100644 api/src/main/java/net/jitse/npclib/NPCLib.java create mode 100644 api/src/main/java/net/jitse/npclib/api/NPC.java rename commons/src/main/java/net/jitse/npclib/events/NPCSpawnEvent.java => api/src/main/java/net/jitse/npclib/api/events/NPCHideEvent.java (70%) rename {commons/src/main/java/net/jitse/npclib => api/src/main/java/net/jitse/npclib/api}/events/NPCInteractEvent.java (90%) rename commons/src/main/java/net/jitse/npclib/events/NPCDestroyEvent.java => api/src/main/java/net/jitse/npclib/api/events/NPCShowEvent.java (70%) rename {commons/src/main/java/net/jitse/npclib => api/src/main/java/net/jitse/npclib/api}/skin/MineSkinFetcher.java (98%) rename {commons/src/main/java/net/jitse/npclib => api/src/main/java/net/jitse/npclib/api}/skin/Skin.java (85%) mode change 100755 => 100644 create mode 100644 api/src/main/java/net/jitse/npclib/api/utilities/Logger.java rename {commons/src/main/java/net/jitse/npclib/nms/holograms => api/src/main/java/net/jitse/npclib/hologram}/Hologram.java (76%) mode change 100755 => 100644 create mode 100644 api/src/main/java/net/jitse/npclib/internal/MinecraftVersion.java rename {commons/src/main/java/net/jitse/npclib => api/src/main/java/net/jitse/npclib/internal}/NPCManager.java (60%) rename {commons/src/main/java/net/jitse/npclib/api => api/src/main/java/net/jitse/npclib/internal}/PacketHandler.java (88%) rename commons/src/main/java/net/jitse/npclib/api/NPC.java => api/src/main/java/net/jitse/npclib/internal/SimpleNPC.java (64%) mode change 100755 => 100644 rename {commons => api}/src/main/java/net/jitse/npclib/listeners/ChunkListener.java (84%) rename {commons => api}/src/main/java/net/jitse/npclib/listeners/PacketListener.java (68%) rename {commons => api}/src/main/java/net/jitse/npclib/listeners/PlayerListener.java (86%) delete mode 100755 commons/pom.xml delete mode 100755 commons/src/main/java/net/jitse/npclib/NPCLib.java delete mode 100755 commons/src/main/java/net/jitse/npclib/api/ActionHandler.java delete mode 100755 commons/src/main/java/net/jitse/npclib/api/packet/NPCPacket.java delete mode 100644 commons/src/main/java/net/jitse/npclib/api/wrapper/GameProfileWrapper.java delete mode 100755 commons/src/main/java/net/jitse/npclib/events/click/ClickType.java delete mode 100755 commons/src/main/java/net/jitse/npclib/events/trigger/TriggerType.java delete mode 100644 commons/src/main/java/net/jitse/npclib/logging/NPCLibLogger.java create mode 100644 nms/pom.xml create mode 100755 nms/v1_14_R1/pom.xml create mode 100755 nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/NPC_v1_14_R1.java create mode 100755 nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutEntityHeadRotationWrapper.java create mode 100755 nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutNamedEntitySpawnWrapper.java create mode 100755 nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutPlayerInfoWrapper.java create mode 100755 nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutScoreboardTeamWrapper.java mode change 100755 => 100644 plugin/pom.xml mode change 100755 => 100644 plugin/src/main/java/net/jitse/npclib/plugin/NPCLibPlugin.java mode change 100755 => 100644 plugin/src/main/resources/plugin.yml diff --git a/api/pom.xml b/api/pom.xml new file mode 100644 index 0000000..896d09a --- /dev/null +++ b/api/pom.xml @@ -0,0 +1,53 @@ + + + 4.0.0 + jar + + + npclib + net.jitse + 2.0-SNAPSHOT + + + npclib-api + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + minecraft-repo + https://libraries.minecraft.net + + + + + + org.spigotmc + spigot-api + 1.14.4-R0.1-SNAPSHOT + provided + + + org.spigotmc + spigot + 1.14.4-R0.1-SNAPSHOT + provided + + + com.mojang + authlib + 1.5.21 + provided + + + io.netty + netty-all + 4.1.33.Final + provided + + + \ No newline at end of file diff --git a/commons/src/main/java/com/comphenix/tinyprotocol/Reflection.java b/api/src/main/java/com/comphenix/tinyprotocol/Reflection.java similarity index 99% rename from commons/src/main/java/com/comphenix/tinyprotocol/Reflection.java rename to api/src/main/java/com/comphenix/tinyprotocol/Reflection.java index acf0c5f..c2bbbec 100755 --- a/commons/src/main/java/com/comphenix/tinyprotocol/Reflection.java +++ b/api/src/main/java/com/comphenix/tinyprotocol/Reflection.java @@ -1,3 +1,7 @@ +/* + * Copyright (c) 2018 Jitse Boonstra + */ + package com.comphenix.tinyprotocol; import org.bukkit.Bukkit; diff --git a/commons/src/main/java/com/comphenix/tinyprotocol/TinyProtocol.java b/api/src/main/java/com/comphenix/tinyprotocol/TinyProtocol.java similarity index 84% rename from commons/src/main/java/com/comphenix/tinyprotocol/TinyProtocol.java rename to api/src/main/java/com/comphenix/tinyprotocol/TinyProtocol.java index 0cfd2fa..cf67fa8 100755 --- a/commons/src/main/java/com/comphenix/tinyprotocol/TinyProtocol.java +++ b/api/src/main/java/com/comphenix/tinyprotocol/TinyProtocol.java @@ -1,11 +1,13 @@ +/* + * Copyright (c) 2018 Jitse Boonstra + */ + package com.comphenix.tinyprotocol; -import com.comphenix.tinyprotocol.Reflection.FieldAccessor; -import com.comphenix.tinyprotocol.Reflection.MethodInvoker; import com.google.common.collect.Lists; import com.google.common.collect.MapMaker; import io.netty.channel.*; -import net.jitse.npclib.logging.NPCLibLogger; +import net.jitse.npclib.NPCLib; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -19,8 +21,6 @@ import org.bukkit.scheduler.BukkitRunnable; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; -import java.util.logging.Logger; /** * Minimized version of TinyProtocol by Kristian suited for NPCLib. @@ -30,35 +30,35 @@ public abstract class TinyProtocol { private static final AtomicInteger ID = new AtomicInteger(0); // Used in order to lookup a channel - private static final MethodInvoker getPlayerHandle = Reflection.getMethod("{obc}.entity.CraftPlayer", "getHandle"); - private static final FieldAccessor getConnection = Reflection.getField("{nms}.EntityPlayer", "playerConnection", Object.class); - private static final FieldAccessor getManager = Reflection.getField("{nms}.PlayerConnection", "networkManager", Object.class); - private static final FieldAccessor getChannel = Reflection.getField("{nms}.NetworkManager", Channel.class, 0); + private static final Reflection.MethodInvoker getPlayerHandle = Reflection.getMethod("{obc}.entity.CraftPlayer", "getHandle"); + private static final Reflection.FieldAccessor getConnection = Reflection.getField("{nms}.EntityPlayer", "playerConnection", Object.class); + private static final Reflection.FieldAccessor getManager = Reflection.getField("{nms}.PlayerConnection", "networkManager", Object.class); + private static final Reflection.FieldAccessor getChannel = Reflection.getField("{nms}.NetworkManager", Channel.class, 0); // Looking up ServerConnection private static final Class minecraftServerClass = Reflection.getUntypedClass("{nms}.MinecraftServer"); private static final Class serverConnectionClass = Reflection.getUntypedClass("{nms}.ServerConnection"); - private static final FieldAccessor getMinecraftServer = Reflection.getField("{obc}.CraftServer", minecraftServerClass, 0); - private static final FieldAccessor getServerConnection = Reflection.getField(minecraftServerClass, serverConnectionClass, 0); - private static final MethodInvoker getNetworkMarkers = Reflection.getTypedMethod(serverConnectionClass, null, List.class, serverConnectionClass); + private static final Reflection.FieldAccessor getMinecraftServer = Reflection.getField("{obc}.CraftServer", minecraftServerClass, 0); + private static final Reflection.FieldAccessor getServerConnection = Reflection.getField(minecraftServerClass, serverConnectionClass, 0); + private static final Reflection.MethodInvoker getNetworkMarkers = Reflection.getTypedMethod(serverConnectionClass, null, List.class, serverConnectionClass); // Packets we have to intercept private static final Class PACKET_LOGIN_IN_START = Reflection.getMinecraftClass("PacketLoginInStart"); - private static final FieldAccessor getGameProfile = Reflection.getField(PACKET_LOGIN_IN_START, + private static final Reflection.FieldAccessor getGameProfile = Reflection.getField(PACKET_LOGIN_IN_START, Reflection.getClass("com.mojang.authlib.GameProfile"), 0); // Speedup channel lookup private Map channelLookup = new MapMaker().weakValues().makeMap(); private Listener listener; - private Logger logger; - // Channels that have already been removed private Set uninjectedChannels = Collections.newSetFromMap(new MapMaker().weakKeys().makeMap()); // List of network markers private List networkManagers; + private final NPCLib instance; + // Injected channel handlers private List serverChannels = Lists.newArrayList(); private ChannelInboundHandlerAdapter serverChannelHandler; @@ -71,9 +71,9 @@ public abstract class TinyProtocol { private volatile boolean closed; protected Plugin plugin; - protected TinyProtocol(final Plugin plugin) { - this.plugin = plugin; - this.logger = new NPCLibLogger(plugin); + protected TinyProtocol(NPCLib instance) { + this.plugin = instance.getPlugin(); + this.instance = instance; // Compute handler name this.handlerName = "tiny-" + plugin.getName() + "-" + ID.incrementAndGet(); @@ -82,19 +82,19 @@ public abstract class TinyProtocol { registerBukkitEvents(); try { - logger.info("Attempting to inject into netty"); + instance.getLogger().info("Attempting to inject into netty"); registerChannelHandler(); registerPlayers(plugin); } catch (IllegalArgumentException exception) { // Damn you, late bind - logger.log(Level.WARNING, "Attempting to delay injection"); + instance.getLogger().warning("Attempting to delay injection"); new BukkitRunnable() { @Override public void run() { registerChannelHandler(); registerPlayers(plugin); - logger.info("Injection complete"); + instance.getLogger().info("Injection complete"); } }.runTask(plugin); } @@ -116,7 +116,8 @@ public abstract class TinyProtocol { } } } catch (Exception exception) { - logger.log(Level.SEVERE, "Cannot inject incomming channel " + channel, exception); + instance.getLogger().severe("Cannot inject incomming channel " + channel + ". Message: " + + exception.getMessage()); } } @@ -305,7 +306,7 @@ public abstract class TinyProtocol { try { msg = onPacketInAsync(player, msg); } catch (Exception exception) { - logger.log(Level.SEVERE, "Error in onPacketInAsync()", exception); + instance.getLogger().severe("Error in onPacketInAsync(). Message: " + exception.getMessage()); } if (msg != null) { diff --git a/api/src/main/java/net/jitse/npclib/NPCLib.java b/api/src/main/java/net/jitse/npclib/NPCLib.java new file mode 100644 index 0000000..52e7bb8 --- /dev/null +++ b/api/src/main/java/net/jitse/npclib/NPCLib.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018 Jitse Boonstra + */ + +package net.jitse.npclib; + +import net.jitse.npclib.api.NPC; +import net.jitse.npclib.api.utilities.Logger; +import net.jitse.npclib.listeners.ChunkListener; +import net.jitse.npclib.listeners.PacketListener; +import net.jitse.npclib.listeners.PlayerListener; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.List; + +public final class NPCLib { + + private final JavaPlugin plugin; + private final Logger logger; + private final Class npcClass; + + private double autoHideDistance = 50.0; + + public NPCLib(JavaPlugin plugin) { + this.plugin = plugin; + this.logger = new Logger("NPCLib"); + + String versionName = plugin.getServer().getClass().getPackage().getName().split("\\.")[3]; + + Class npcClass = null; + + try { + npcClass = Class.forName("net.jitse.npclib.nms." + versionName + ".NPC_" + versionName); + } catch (ClassNotFoundException exception) { + // Version not supported, error below. + } + + this.npcClass = npcClass; + + if (npcClass == null) { + logger.severe("Failed to initiate. Your server's version (" + + versionName + ") is not supported"); + return; + } + + PluginManager pluginManager = plugin.getServer().getPluginManager(); + + pluginManager.registerEvents(new PlayerListener(this), plugin); + pluginManager.registerEvents(new ChunkListener(this), plugin); + + // Boot the according packet listener. + new PacketListener().start(this); + + logger.info("Enabled for Minecraft " + versionName); + } + + /** + * @return The JavaPlugin instance. + */ + public JavaPlugin getPlugin() { + return plugin; + } + + /** + * Set a new value for the auto-hide distance. + * A recommended value (and default) is 50 blocks. + * + * @param autoHideDistance The new value. + */ + public void setAutoHideDistance(double autoHideDistance) { + this.autoHideDistance = autoHideDistance; + } + + /** + * @return The auto-hide distance. + */ + public double getAutoHideDistance() { + return autoHideDistance; + } + + /** + * @return The logger NPCLib uses. + */ + public Logger getLogger() { + return logger; + } + + /** + * Create a new non-player character (NPC). + * + * @param lines The text you want to sendShowPackets above the NPC (null = no text). + * @return The NPC object you may use to sendShowPackets it to players. + */ + public NPC createNPC(List lines) { + try { + return (NPC) npcClass.getConstructors()[0].newInstance(this, lines); + } catch (Exception exception) { + logger.warning("Failed to create NPC. Please report the following stacktrace message: " + exception.getMessage()); + } + + return null; + } + + /** + * Create a new non-player character (NPC). + * + * @return The NPC object you may use to sendShowPackets it to players. + */ + public NPC createNPC() { + return createNPC(null); + } +} diff --git a/api/src/main/java/net/jitse/npclib/api/NPC.java b/api/src/main/java/net/jitse/npclib/api/NPC.java new file mode 100644 index 0000000..9b4d687 --- /dev/null +++ b/api/src/main/java/net/jitse/npclib/api/NPC.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2018 Jitse Boonstra + */ + +package net.jitse.npclib.api; + +import net.jitse.npclib.api.skin.Skin; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +public interface NPC { + + /** + * Set the NPC's location. + * Use this method before using {@link NPC#create}. + * + * @param location The spawn location for the NPC. + * @return object instance. + */ + NPC setLocation(Location location); + + /** + * Set the NPC's skin. + * Use this method before using {@link NPC#create}. + * + * @param skin The skin(data) you'd like to apply. + * @return object instance. + */ + NPC setSkin(Skin skin); + + /** + * Get the location of the NPC. + * + * @return The location of the NPC. + */ + Location getLocation(); + + /** + * Create all necessary packets for the NPC so it can be shown to players. + * + * @return object instance. + */ + NPC create(); + + /** + * Get the ID of the NPC. + * + * @return the ID of the NPC. + */ + String getId(); + + /** + * Test if a player can see the NPC. + * E.g. is the player is out of range, this method will return false as the NPC is automatically hidden by the library. + * + * @param player The player you'd like to check. + * @return Value on whether the player can see the NPC. + */ + boolean isShown(Player player); + + /** + * Show the NPC to a player. + * Requires {@link NPC#create} to be used first. + * + * @param player the player to show the NPC to. + */ + void show(Player player); + + /** + * Hide the NPC from a player. + * Will not do anything if NPC isn't shown to the player. + * Requires {@link NPC#create} to be used first. + * + * @param player The player to hide the NPC from. + */ + void hide(Player player); + + /** + * Destroy the NPC, i.e. remove it from the registry. + * Requires {@link NPC#create} to be used first. + */ + void destroy(); +} diff --git a/commons/src/main/java/net/jitse/npclib/events/NPCSpawnEvent.java b/api/src/main/java/net/jitse/npclib/api/events/NPCHideEvent.java similarity index 70% rename from commons/src/main/java/net/jitse/npclib/events/NPCSpawnEvent.java rename to api/src/main/java/net/jitse/npclib/api/events/NPCHideEvent.java index 5d4ba73..e210a15 100755 --- a/commons/src/main/java/net/jitse/npclib/events/NPCSpawnEvent.java +++ b/api/src/main/java/net/jitse/npclib/api/events/NPCHideEvent.java @@ -2,10 +2,9 @@ * Copyright (c) 2018 Jitse Boonstra */ -package net.jitse.npclib.events; +package net.jitse.npclib.api.events; import net.jitse.npclib.api.NPC; -import net.jitse.npclib.events.trigger.TriggerType; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; @@ -14,7 +13,7 @@ import org.bukkit.event.HandlerList; /** * @author Jitse Boonstra */ -public class NPCSpawnEvent extends Event implements Cancellable { +public class NPCHideEvent extends Event implements Cancellable { private static final HandlerList handlers = new HandlerList(); @@ -22,12 +21,12 @@ public class NPCSpawnEvent extends Event implements Cancellable { private final NPC npc; private final Player player; - private final TriggerType trigger; + private final boolean automatic; - public NPCSpawnEvent(NPC npc, Player player, TriggerType trigger) { + public NPCHideEvent(NPC npc, Player player, boolean automatic) { this.npc = npc; this.player = player; - this.trigger = trigger; + this.automatic = automatic; } @Override @@ -43,8 +42,11 @@ public class NPCSpawnEvent extends Event implements Cancellable { return player; } - public TriggerType getTrigger() { - return trigger; + /** + * @return Value on whether the hiding was triggered automatically. + */ + public boolean isAutomatic() { + return automatic; } @Override @@ -60,3 +62,4 @@ public class NPCSpawnEvent extends Event implements Cancellable { return handlers; } } + diff --git a/commons/src/main/java/net/jitse/npclib/events/NPCInteractEvent.java b/api/src/main/java/net/jitse/npclib/api/events/NPCInteractEvent.java similarity index 90% rename from commons/src/main/java/net/jitse/npclib/events/NPCInteractEvent.java rename to api/src/main/java/net/jitse/npclib/api/events/NPCInteractEvent.java index ae79a44..c89df01 100755 --- a/commons/src/main/java/net/jitse/npclib/events/NPCInteractEvent.java +++ b/api/src/main/java/net/jitse/npclib/api/events/NPCInteractEvent.java @@ -2,10 +2,9 @@ * Copyright (c) 2018 Jitse Boonstra */ -package net.jitse.npclib.events; +package net.jitse.npclib.api.events; import net.jitse.npclib.api.NPC; -import net.jitse.npclib.events.click.ClickType; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; @@ -46,4 +45,8 @@ public class NPCInteractEvent extends Event { public static HandlerList getHandlerList() { return handlers; } + + public enum ClickType { + LEFT_CLICK, RIGHT_CLICK + } } diff --git a/commons/src/main/java/net/jitse/npclib/events/NPCDestroyEvent.java b/api/src/main/java/net/jitse/npclib/api/events/NPCShowEvent.java similarity index 70% rename from commons/src/main/java/net/jitse/npclib/events/NPCDestroyEvent.java rename to api/src/main/java/net/jitse/npclib/api/events/NPCShowEvent.java index 6fc0c36..7459621 100755 --- a/commons/src/main/java/net/jitse/npclib/events/NPCDestroyEvent.java +++ b/api/src/main/java/net/jitse/npclib/api/events/NPCShowEvent.java @@ -2,10 +2,9 @@ * Copyright (c) 2018 Jitse Boonstra */ -package net.jitse.npclib.events; +package net.jitse.npclib.api.events; import net.jitse.npclib.api.NPC; -import net.jitse.npclib.events.trigger.TriggerType; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; @@ -14,7 +13,7 @@ import org.bukkit.event.HandlerList; /** * @author Jitse Boonstra */ -public class NPCDestroyEvent extends Event implements Cancellable { +public class NPCShowEvent extends Event implements Cancellable { private static final HandlerList handlers = new HandlerList(); @@ -22,12 +21,12 @@ public class NPCDestroyEvent extends Event implements Cancellable { private final NPC npc; private final Player player; - private final TriggerType trigger; + private final boolean automatic; - public NPCDestroyEvent(NPC npc, Player player, TriggerType trigger) { + public NPCShowEvent(NPC npc, Player player, boolean automatic) { this.npc = npc; this.player = player; - this.trigger = trigger; + this.automatic = automatic; } @Override @@ -43,8 +42,11 @@ public class NPCDestroyEvent extends Event implements Cancellable { return player; } - public TriggerType getTrigger() { - return trigger; + /** + * @return Value on whether the spawn was triggered automatically. + */ + public boolean isAutomatic() { + return automatic; } @Override @@ -60,4 +62,3 @@ public class NPCDestroyEvent extends Event implements Cancellable { return handlers; } } - diff --git a/commons/src/main/java/net/jitse/npclib/skin/MineSkinFetcher.java b/api/src/main/java/net/jitse/npclib/api/skin/MineSkinFetcher.java similarity index 98% rename from commons/src/main/java/net/jitse/npclib/skin/MineSkinFetcher.java rename to api/src/main/java/net/jitse/npclib/api/skin/MineSkinFetcher.java index d2dccd9..58316d1 100755 --- a/commons/src/main/java/net/jitse/npclib/skin/MineSkinFetcher.java +++ b/api/src/main/java/net/jitse/npclib/api/skin/MineSkinFetcher.java @@ -2,7 +2,7 @@ * Copyright (c) 2018 Jitse Boonstra */ -package net.jitse.npclib.skin; +package net.jitse.npclib.api.skin; import com.google.gson.JsonObject; import com.google.gson.JsonParser; diff --git a/commons/src/main/java/net/jitse/npclib/skin/Skin.java b/api/src/main/java/net/jitse/npclib/api/skin/Skin.java old mode 100755 new mode 100644 similarity index 85% rename from commons/src/main/java/net/jitse/npclib/skin/Skin.java rename to api/src/main/java/net/jitse/npclib/api/skin/Skin.java index 181a4f0..60733d9 --- a/commons/src/main/java/net/jitse/npclib/skin/Skin.java +++ b/api/src/main/java/net/jitse/npclib/api/skin/Skin.java @@ -2,11 +2,8 @@ * Copyright (c) 2018 Jitse Boonstra */ -package net.jitse.npclib.skin; +package net.jitse.npclib.api.skin; -/** - * @author Jitse Boonstra - */ public class Skin { private final String value, signature; diff --git a/api/src/main/java/net/jitse/npclib/api/utilities/Logger.java b/api/src/main/java/net/jitse/npclib/api/utilities/Logger.java new file mode 100644 index 0000000..c9ef24a --- /dev/null +++ b/api/src/main/java/net/jitse/npclib/api/utilities/Logger.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2018 Jitse Boonstra + */ + +package net.jitse.npclib.api.utilities; + +import org.bukkit.Bukkit; + +public class Logger { + + private final String prefix; + + private boolean enabled = true; + + public Logger(String prefix) { + this.prefix = prefix + " "; + } + + public void disable() { + this.enabled = false; + } + + public void info(String info) { + if (!enabled) { + return; + } + + Bukkit.getLogger().info(prefix + info); + } + + public void warning(String warning) { + if (!enabled) { + return; + } + + Bukkit.getLogger().warning(prefix + warning); + } + + public void severe(String severe) { + if (!enabled) { + return; + } + + Bukkit.getLogger().severe(prefix + severe); + } +} diff --git a/commons/src/main/java/net/jitse/npclib/nms/holograms/Hologram.java b/api/src/main/java/net/jitse/npclib/hologram/Hologram.java old mode 100755 new mode 100644 similarity index 76% rename from commons/src/main/java/net/jitse/npclib/nms/holograms/Hologram.java rename to api/src/main/java/net/jitse/npclib/hologram/Hologram.java index 98fac46..ae464a4 --- a/commons/src/main/java/net/jitse/npclib/nms/holograms/Hologram.java +++ b/api/src/main/java/net/jitse/npclib/hologram/Hologram.java @@ -2,9 +2,10 @@ * Copyright (c) 2018 Jitse Boonstra */ -package net.jitse.npclib.nms.holograms; +package net.jitse.npclib.hologram; import com.comphenix.tinyprotocol.Reflection; +import net.jitse.npclib.internal.MinecraftVersion; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; @@ -14,9 +15,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -/** - * @author Jitse Boonstra - */ public class Hologram { private final double delta = 0.3; @@ -84,18 +82,18 @@ public class Hologram { } - public void generatePackets(boolean above1_9_r2, boolean above_1_12_r1) { - Reflection.MethodInvoker gravityMethod = (above1_9_r2 ? Reflection.getMethod(ENTITY_CLAZZ, - "setNoGravity", boolean.class) : Reflection.getMethod(ENTITY_ARMOR_STAND_CLAZZ, - "setGravity", boolean.class)); + public void generatePackets(MinecraftVersion version) { + Reflection.MethodInvoker gravityMethod = (version.isAboveOrEqual(MinecraftVersion.V1_9_R2) ? + Reflection.getMethod(ENTITY_CLAZZ, "setNoGravity", boolean.class) : + Reflection.getMethod(ENTITY_ARMOR_STAND_CLAZZ, "setGravity", boolean.class)); - Reflection.MethodInvoker customNameMethod = (above_1_12_r1 ? Reflection.getMethod(ENTITY_CLAZZ, - "setCustomName", CHAT_BASE_COMPONENT_CLAZZ) : Reflection.getMethod(ENTITY_ARMOR_STAND_CLAZZ, - "setCustomName", String.class)); + Reflection.MethodInvoker customNameMethod = (version.isAboveOrEqual(MinecraftVersion.V1_12_R1) ? + Reflection.getMethod(ENTITY_CLAZZ, "setCustomName", CHAT_BASE_COMPONENT_CLAZZ) : + Reflection.getMethod(ENTITY_ARMOR_STAND_CLAZZ, "setCustomName", String.class)); - Reflection.MethodInvoker customNameVisibilityMethod = (above_1_12_r1 ? Reflection.getMethod(ENTITY_CLAZZ, - "setCustomNameVisible", boolean.class) : Reflection.getMethod(ENTITY_ARMOR_STAND_CLAZZ, - "setCustomNameVisible", boolean.class)); + Reflection.MethodInvoker customNameVisibilityMethod = (version.isAboveOrEqual(MinecraftVersion.V1_12_R1) ? + Reflection.getMethod(ENTITY_CLAZZ, "setCustomNameVisible", boolean.class) : + Reflection.getMethod(ENTITY_ARMOR_STAND_CLAZZ, "setCustomNameVisible", boolean.class)); Location location = start.clone().add(0, delta * lines.size(), 0); Class worldClass = worldServer.getClass().getSuperclass(); @@ -104,16 +102,23 @@ public class Hologram { worldClass = worldClass.getSuperclass(); } - Reflection.ConstructorInvoker entityArmorStandConstructor = Reflection - .getConstructor(ENTITY_ARMOR_STAND_CLAZZ, worldClass); + Reflection.ConstructorInvoker entityArmorStandConstructor = (version.isAboveOrEqual(MinecraftVersion.V1_14_R1) ? + Reflection.getConstructor(ENTITY_ARMOR_STAND_CLAZZ, worldClass, double.class, double.class, double.class) : + Reflection.getConstructor(ENTITY_ARMOR_STAND_CLAZZ, worldClass)); for (String line : lines) { - Object entityArmorStand = entityArmorStandConstructor.invoke(worldServer); + Object entityArmorStand = (version.isAboveOrEqual(MinecraftVersion.V1_14_R1) ? + entityArmorStandConstructor.invoke(worldServer, location.getX(), location.getY(), location.getZ()) : + entityArmorStandConstructor.invoke(worldServer)); + + if (!version.isAboveOrEqual(MinecraftVersion.V1_14_R1)) { + SET_LOCATION_METHOD.invoke(entityArmorStand, location.getX(), location.getY(), location.getZ(), 0, 0); + } - SET_LOCATION_METHOD.invoke(entityArmorStand, location.getX(), location.getY(), location.getZ(), 0, 0); - customNameMethod.invoke(entityArmorStand, above_1_12_r1 ? CHAT_COMPONENT_TEXT_CONSTRUCTOR.invoke(line) : line); + customNameMethod.invoke(entityArmorStand, version.isAboveOrEqual(MinecraftVersion.V1_12_R1) ? + CHAT_COMPONENT_TEXT_CONSTRUCTOR.invoke(line) : line); customNameVisibilityMethod.invoke(entityArmorStand, true); - gravityMethod.invoke(entityArmorStand, above1_9_r2); + gravityMethod.invoke(entityArmorStand, version.isAboveOrEqual(MinecraftVersion.V1_9_R2)); SET_SMALL_METHOD.invoke(entityArmorStand, true); SET_INVISIBLE_METHOD.invoke(entityArmorStand, true); SET_BASE_PLATE_METHOD.invoke(entityArmorStand, false); @@ -170,3 +175,4 @@ public class Hologram { } } } + diff --git a/api/src/main/java/net/jitse/npclib/internal/MinecraftVersion.java b/api/src/main/java/net/jitse/npclib/internal/MinecraftVersion.java new file mode 100644 index 0000000..591c557 --- /dev/null +++ b/api/src/main/java/net/jitse/npclib/internal/MinecraftVersion.java @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2018 Jitse Boonstra + */ + +package net.jitse.npclib.internal; + +public enum MinecraftVersion { + + V1_8_R1, V1_8_R2, V1_8_R3, V1_9_R1, V1_9_R2, V1_10_R1, V1_11_R1, V1_12_R1, V1_13_R1, V1_13_R2, V1_14_R1; + + + public boolean isAboveOrEqual(MinecraftVersion compare) { + return ordinal() >= compare.ordinal(); + } +} diff --git a/commons/src/main/java/net/jitse/npclib/NPCManager.java b/api/src/main/java/net/jitse/npclib/internal/NPCManager.java similarity index 60% rename from commons/src/main/java/net/jitse/npclib/NPCManager.java rename to api/src/main/java/net/jitse/npclib/internal/NPCManager.java index 476ea46..92fc36e 100755 --- a/commons/src/main/java/net/jitse/npclib/NPCManager.java +++ b/api/src/main/java/net/jitse/npclib/internal/NPCManager.java @@ -2,9 +2,7 @@ * Copyright (c) 2018 Jitse Boonstra */ -package net.jitse.npclib; - -import net.jitse.npclib.api.NPC; +package net.jitse.npclib.internal; import java.util.HashSet; import java.util.Set; @@ -14,17 +12,17 @@ import java.util.Set; */ public final class NPCManager { - private static Set npcs = new HashSet<>(); + private static Set npcs = new HashSet<>(); - public static Set getAllNPCs() { + public static Set getAllNPCs() { return npcs; } - public static void add(NPC npc) { + public static void add(SimpleNPC npc) { npcs.add(npc); } - public static void remove(NPC npc) { + public static void remove(SimpleNPC npc) { npcs.remove(npc); } diff --git a/commons/src/main/java/net/jitse/npclib/api/PacketHandler.java b/api/src/main/java/net/jitse/npclib/internal/PacketHandler.java similarity index 88% rename from commons/src/main/java/net/jitse/npclib/api/PacketHandler.java rename to api/src/main/java/net/jitse/npclib/internal/PacketHandler.java index 7fb2230..5257bd4 100755 --- a/commons/src/main/java/net/jitse/npclib/api/PacketHandler.java +++ b/api/src/main/java/net/jitse/npclib/internal/PacketHandler.java @@ -2,7 +2,7 @@ * Copyright (c) 2018 Jitse Boonstra */ -package net.jitse.npclib.api; +package net.jitse.npclib.internal; import org.bukkit.entity.Player; diff --git a/commons/src/main/java/net/jitse/npclib/api/NPC.java b/api/src/main/java/net/jitse/npclib/internal/SimpleNPC.java old mode 100755 new mode 100644 similarity index 64% rename from commons/src/main/java/net/jitse/npclib/api/NPC.java rename to api/src/main/java/net/jitse/npclib/internal/SimpleNPC.java index 11b2760..8c753d9 --- a/commons/src/main/java/net/jitse/npclib/api/NPC.java +++ b/api/src/main/java/net/jitse/npclib/internal/SimpleNPC.java @@ -2,65 +2,74 @@ * Copyright (c) 2018 Jitse Boonstra */ -package net.jitse.npclib.api; - -import net.jitse.npclib.NPCManager; -import net.jitse.npclib.api.wrapper.GameProfileWrapper; -import net.jitse.npclib.events.NPCDestroyEvent; -import net.jitse.npclib.events.NPCSpawnEvent; -import net.jitse.npclib.events.trigger.TriggerType; -import net.jitse.npclib.skin.Skin; +package net.jitse.npclib.internal; + +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import net.jitse.npclib.NPCLib; +import net.jitse.npclib.api.NPC; +import net.jitse.npclib.api.events.NPCHideEvent; +import net.jitse.npclib.api.events.NPCShowEvent; +import net.jitse.npclib.api.skin.Skin; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; import java.util.*; -/** - * @author Jitse Boonstra - */ -public abstract class NPC implements PacketHandler, ActionHandler { +public abstract class SimpleNPC implements NPC, PacketHandler { protected final UUID uuid = UUID.randomUUID(); - // Below was previously = (int) Math.ceil(Math.random() * 100000) + 100000 (new is experimental). protected final int entityId = Integer.MAX_VALUE - NPCManager.getAllNPCs().size(); + protected final String name = uuid.toString().replace("-", "").substring(0, 10); + protected final GameProfile gameProfile = new GameProfile(uuid, name); - protected double cosFOV = Math.cos(Math.toRadians(60)); - protected String name = uuid.toString().replace("-", "").substring(0, 10); + protected final List lines; private final Set shown = new HashSet<>(); private final Set autoHidden = new HashSet<>(); - protected final double autoHideDistance; - protected final Skin skin; - protected final List lines; + protected double cosFOV = Math.cos(Math.toRadians(60)); - protected JavaPlugin plugin; - protected GameProfileWrapper gameProfile; + protected NPCLib instance; protected Location location; + protected Skin skin; - public NPC(JavaPlugin plugin, Skin skin, double autoHideDistance, List lines) { - this.plugin = plugin; - this.skin = skin; - this.autoHideDistance = autoHideDistance; + public SimpleNPC(NPCLib instance, List lines) { + this.instance = instance; this.lines = lines == null ? Collections.emptyList() : lines; NPCManager.add(this); } - protected GameProfileWrapper generateGameProfile(UUID uuid, String name) { - GameProfileWrapper gameProfile = new GameProfileWrapper(uuid, name); + protected GameProfile generateGameProfile(UUID uuid, String name) { + GameProfile gameProfile = new GameProfile(uuid, name); if (skin != null) { - gameProfile.addSkin(skin); + gameProfile.getProperties().get("textures").clear(); + gameProfile.getProperties().get("textures").add(new Property(skin.getValue(), skin.getSignature())); } return gameProfile; } + public NPCLib getInstance() { + return instance; + } + @Override + public String getId() { + return name; + } + + @Override + public NPC setSkin(Skin skin) { + this.skin = skin; + return this; + } + + @Override public void destroy() { destroy(true); } @@ -83,7 +92,7 @@ public abstract class NPC implements PacketHandler, ActionHandler { } public void setFOV(double fov) { - this.cosFOV = Math.cos(Math.toRadians(60)); + this.cosFOV = Math.cos(Math.toRadians(fov)); } public Set getShown() { @@ -94,35 +103,40 @@ public abstract class NPC implements PacketHandler, ActionHandler { return autoHidden; } + @Override public Location getLocation() { return location; } - public double getAutoHideDistance() { - return autoHideDistance; - } - public int getEntityId() { return entityId; } - public boolean isActuallyShown(Player player) { + @Override + public boolean isShown(Player player) { return shown.contains(player.getUniqueId()) && !autoHidden.contains(player.getUniqueId()); } - public void create(Location location) { + @Override + public NPC setLocation(Location location) { this.location = location; + return this; + } + @Override + public NPC create() { createPackets(); + return this; } + @Override public void show(Player player) { show(player, false); } public void show(Player player, boolean auto) { - NPCSpawnEvent event = new NPCSpawnEvent(this, player, auto ? TriggerType.AUTOMATIC : TriggerType.MANUAL); - plugin.getServer().getPluginManager().callEvent(event); + NPCShowEvent event = new NPCShowEvent(this, player, auto); + Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return; } @@ -139,7 +153,7 @@ public abstract class NPC implements PacketHandler, ActionHandler { if (auto) { sendShowPackets(player); } else { - if (isActuallyShown(player)) { + if (isShown(player)) { throw new RuntimeException("Cannot call show method twice."); } @@ -149,7 +163,8 @@ public abstract class NPC implements PacketHandler, ActionHandler { shown.add(player.getUniqueId()); - if (player.getWorld().equals(location.getWorld()) && player.getLocation().distance(location) <= autoHideDistance) { + if (player.getWorld().equals(location.getWorld()) && player.getLocation().distance(location) + <= instance.getAutoHideDistance()) { sendShowPackets(player); } else { autoHidden.add(player.getUniqueId()); @@ -162,13 +177,14 @@ public abstract class NPC implements PacketHandler, ActionHandler { return dir.dot(player.getLocation().getDirection()) >= cosFOV; } + @Override public void hide(Player player) { hide(player, false, true); } public void hide(Player player, boolean auto, boolean scheduler) { - NPCDestroyEvent event = new NPCDestroyEvent(this, player, auto ? TriggerType.AUTOMATIC : TriggerType.MANUAL); - plugin.getServer().getPluginManager().callEvent(event); + NPCHideEvent event = new NPCHideEvent(this, player, auto); + Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return; } @@ -182,7 +198,8 @@ public abstract class NPC implements PacketHandler, ActionHandler { shown.remove(player.getUniqueId()); - if (player.getWorld().equals(location.getWorld()) && player.getLocation().distance(location) <= autoHideDistance) { + if (player.getWorld().equals(location.getWorld()) && player.getLocation().distance(location) + <= instance.getAutoHideDistance()) { sendHidePackets(player, scheduler); } else { autoHidden.remove(player.getUniqueId()); diff --git a/commons/src/main/java/net/jitse/npclib/listeners/ChunkListener.java b/api/src/main/java/net/jitse/npclib/listeners/ChunkListener.java similarity index 84% rename from commons/src/main/java/net/jitse/npclib/listeners/ChunkListener.java rename to api/src/main/java/net/jitse/npclib/listeners/ChunkListener.java index f72a01b..10d7902 100755 --- a/commons/src/main/java/net/jitse/npclib/listeners/ChunkListener.java +++ b/api/src/main/java/net/jitse/npclib/listeners/ChunkListener.java @@ -4,8 +4,9 @@ package net.jitse.npclib.listeners; -import net.jitse.npclib.NPCManager; -import net.jitse.npclib.api.NPC; +import net.jitse.npclib.NPCLib; +import net.jitse.npclib.internal.NPCManager; +import net.jitse.npclib.internal.SimpleNPC; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.entity.Player; @@ -21,11 +22,17 @@ import java.util.UUID; */ public class ChunkListener implements Listener { + private final NPCLib instance; + + public ChunkListener(NPCLib instance) { + this.instance = instance; + } + @EventHandler public void onChunkUnload(ChunkUnloadEvent event) { Chunk chunk = event.getChunk(); - for (NPC npc : NPCManager.getAllNPCs()) { + for (SimpleNPC npc : NPCManager.getAllNPCs()) { Chunk npcChunk = npc.getLocation().getChunk(); if (chunk.equals(npcChunk)) { @@ -48,7 +55,7 @@ public class ChunkListener implements Listener { public void onChunkLoad(ChunkLoadEvent event) { Chunk chunk = event.getChunk(); - for (NPC npc : NPCManager.getAllNPCs()) { + for (SimpleNPC npc : NPCManager.getAllNPCs()) { Chunk npcChunk = npc.getLocation().getChunk(); if (chunk.equals(npcChunk)) { @@ -66,7 +73,7 @@ public class ChunkListener implements Listener { continue; // Player and NPC are not in the same world. } - double hideDistance = npc.getAutoHideDistance(); + double hideDistance = instance.getAutoHideDistance(); double distanceSquared = player.getLocation().distanceSquared(npc.getLocation()); boolean inRange = distanceSquared <= (hideDistance * hideDistance) || distanceSquared <= (Bukkit.getViewDistance() << 4); diff --git a/commons/src/main/java/net/jitse/npclib/listeners/PacketListener.java b/api/src/main/java/net/jitse/npclib/listeners/PacketListener.java similarity index 68% rename from commons/src/main/java/net/jitse/npclib/listeners/PacketListener.java rename to api/src/main/java/net/jitse/npclib/listeners/PacketListener.java index 3886f47..36a6431 100755 --- a/commons/src/main/java/net/jitse/npclib/listeners/PacketListener.java +++ b/api/src/main/java/net/jitse/npclib/listeners/PacketListener.java @@ -6,10 +6,10 @@ package net.jitse.npclib.listeners; import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; -import net.jitse.npclib.NPCManager; -import net.jitse.npclib.api.NPC; -import net.jitse.npclib.events.NPCInteractEvent; -import net.jitse.npclib.events.click.ClickType; +import net.jitse.npclib.NPCLib; +import net.jitse.npclib.api.events.NPCInteractEvent; +import net.jitse.npclib.internal.NPCManager; +import net.jitse.npclib.internal.SimpleNPC; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -35,10 +35,10 @@ public class PacketListener { private Plugin plugin; - public void start(Plugin plugin) { - this.plugin = plugin; + public void start(NPCLib instance) { + this.plugin = instance.getPlugin(); - new TinyProtocol(plugin) { + new TinyProtocol(instance) { @Override public Object onPacketInAsync(Player player, Object packet) { @@ -49,8 +49,8 @@ public class PacketListener { private boolean handleInteractPacket(Player player, Object packet) { if (packetPlayInUseEntityClazz.isInstance(packet)) { - NPC npc = NPCManager.getAllNPCs().stream().filter( - check -> check.isActuallyShown(player) && check.getEntityId() == (int) entityIdField.get(packet)) + SimpleNPC npc = NPCManager.getAllNPCs().stream().filter( + check -> check.isShown(player) && check.getEntityId() == (int) entityIdField.get(packet)) .findFirst().orElse(null); if (npc == null) { @@ -62,10 +62,11 @@ public class PacketListener { return false; } - ClickType clickType = actionField.get(packet).toString() - .equals("ATTACK") ? ClickType.LEFT_CLICK : ClickType.RIGHT_CLICK; + NPCInteractEvent.ClickType clickType = actionField.get(packet).toString().equals("ATTACK") + ? NPCInteractEvent.ClickType.LEFT_CLICK : NPCInteractEvent.ClickType.RIGHT_CLICK; - Bukkit.getPluginManager().callEvent(new NPCInteractEvent(player, clickType, npc)); + Bukkit.getScheduler().runTask(plugin, () -> + Bukkit.getPluginManager().callEvent(new NPCInteractEvent(player, clickType, npc))); UUID uuid = player.getUniqueId(); delay.add(uuid); diff --git a/commons/src/main/java/net/jitse/npclib/listeners/PlayerListener.java b/api/src/main/java/net/jitse/npclib/listeners/PlayerListener.java similarity index 86% rename from commons/src/main/java/net/jitse/npclib/listeners/PlayerListener.java rename to api/src/main/java/net/jitse/npclib/listeners/PlayerListener.java index 8c4ab62..dcd418b 100755 --- a/commons/src/main/java/net/jitse/npclib/listeners/PlayerListener.java +++ b/api/src/main/java/net/jitse/npclib/listeners/PlayerListener.java @@ -4,8 +4,9 @@ package net.jitse.npclib.listeners; -import net.jitse.npclib.NPCManager; -import net.jitse.npclib.api.NPC; +import net.jitse.npclib.NPCLib; +import net.jitse.npclib.internal.NPCManager; +import net.jitse.npclib.internal.SimpleNPC; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; @@ -21,10 +22,16 @@ import org.bukkit.event.player.PlayerTeleportEvent; */ public class PlayerListener implements Listener { + private final NPCLib instance; + + public PlayerListener(NPCLib instance) { + this.instance = instance; + } + @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { Player player = event.getPlayer(); - for (NPC npc : NPCManager.getAllNPCs()) { + for (SimpleNPC npc : NPCManager.getAllNPCs()) { npc.getAutoHidden().remove(player.getUniqueId()); // Don't need to use NPC#hide since the entity is not registered in the NMS server. @@ -38,7 +45,7 @@ public class PlayerListener implements Listener { World from = event.getFrom(); // The PlayerTeleportEvent is call, and will handle visibility in the new world. - for (NPC npc : NPCManager.getAllNPCs()) { + for (SimpleNPC npc : NPCManager.getAllNPCs()) { if (npc.getLocation().getWorld().equals(from)) { if (!npc.getAutoHidden().contains(player.getUniqueId())) { npc.getAutoHidden().add(player.getUniqueId()); @@ -60,7 +67,7 @@ public class PlayerListener implements Listener { private void handleMove(Player player) { World world = player.getWorld(); - for (NPC npc : NPCManager.getAllNPCs()) { + for (SimpleNPC npc : NPCManager.getAllNPCs()) { if (!npc.getShown().contains(player.getUniqueId())) { continue; // NPC was never supposed to be shown to the player. } @@ -71,7 +78,7 @@ public class PlayerListener implements Listener { // If Bukkit doesn't track the NPC entity anymore, bypass the hiding distance variable. // This will cause issues otherwise (e.g. custom skin disappearing). - double hideDistance = npc.getAutoHideDistance(); + double hideDistance = instance.getAutoHideDistance(); double distanceSquared = player.getLocation().distanceSquared(npc.getLocation()); boolean inRange = distanceSquared <= (Math.pow(hideDistance, 2)) && distanceSquared <= (Math.pow(Bukkit.getViewDistance() << 4, 2)); diff --git a/commons/pom.xml b/commons/pom.xml deleted file mode 100755 index 64e656c..0000000 --- a/commons/pom.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - 4.0.0 - - - net.jitse - npclib - 1.5-SNAPSHOT - - - npclib-commons - - - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - - - - org.spigotmc - spigot-api - 1.13.2-R0.1-SNAPSHOT - provided - - - io.netty - netty-all - 4.1.33.Final - provided - - - diff --git a/commons/src/main/java/net/jitse/npclib/NPCLib.java b/commons/src/main/java/net/jitse/npclib/NPCLib.java deleted file mode 100755 index 6df0fba..0000000 --- a/commons/src/main/java/net/jitse/npclib/NPCLib.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2018 Jitse Boonstra - */ - -package net.jitse.npclib; - -import net.jitse.npclib.api.NPC; -import net.jitse.npclib.listeners.ChunkListener; -import net.jitse.npclib.listeners.PacketListener; -import net.jitse.npclib.listeners.PlayerListener; -import net.jitse.npclib.logging.NPCLibLogger; -import net.jitse.npclib.skin.Skin; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; - -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * @author Jitse Boonstra - */ -public class NPCLib { - - private final JavaPlugin plugin; - private final Class npcClass; - - private Logger logger; - - public NPCLib(JavaPlugin plugin) { - this.plugin = plugin; - this.logger = new NPCLibLogger(plugin); - - // TODO: Change this variable to a dynamic variable (maven file filtering?). - // logger.info("Initiating NPCLib v1.4"); - - String versionName = plugin.getServer().getClass().getPackage().getName().split("\\.")[3]; - - Class npcClass = null; - - try { - npcClass = Class.forName("net.jitse.npclib.nms." + versionName + ".NPC_" + versionName); - } catch (ClassNotFoundException exception) { - // Version not supported, error below. - } - - this.npcClass = npcClass; - - if (npcClass == null) { - logger.log(Level.SEVERE, "Failed to initiate. Your server's version (" - + versionName + ") is not supported"); - return; - } - - logger.info("Enabled for MC " + versionName); - - registerInternal(); - } - - private void registerInternal() { - PluginManager pluginManager = plugin.getServer().getPluginManager(); - - pluginManager.registerEvents(new PlayerListener(), plugin); - pluginManager.registerEvents(new ChunkListener(), plugin); - - // Boot the according packet listener. - new PacketListener().start(plugin); - } - - /** - * Create a new non-player character (NPC). - * - * @param skin The skin you want the NPC to have. - * @param autoHideDistance Distance from where you want to NPC to hide from the player (50 recommended). - * @param lines The text you want to sendShowPackets above the NPC (null = no text). - * @return The NPC object you may use to sendShowPackets it to players. - */ - public NPC createNPC(Skin skin, double autoHideDistance, List lines) { - try { - return (NPC) npcClass.getConstructors()[0].newInstance(plugin, skin, autoHideDistance, lines); - } catch (Exception exception) { - logger.log(Level.SEVERE, "Failed to create NPC. Please report the following stacktrace", exception); - } - - return null; - } - - /** - * Create a new non-player character (NPC). - * - * @param skin The skin you want the NPC to have. - * @param lines The text you want to sendShowPackets above the NPC (null = no text). - * @return The NPC object you may use to sendShowPackets it to players. - */ - public NPC createNPC(Skin skin, List lines) { - return createNPC(skin, 50, lines); - } - - - /** - * Create a new non-player character (NPC). - * - * @param skin The skin you want the NPC to have. - * @return The NPC object you may use to sendShowPackets it to players. - */ - public NPC createNPC(Skin skin) { - return createNPC(skin, 50, null); - } - - - /** - * Create a new non-player character (NPC). - * - * @return The NPC object you may use to sendShowPackets it to players. - */ - public NPC createNPC() { - return createNPC(null, 50, null); - } - -} diff --git a/commons/src/main/java/net/jitse/npclib/api/ActionHandler.java b/commons/src/main/java/net/jitse/npclib/api/ActionHandler.java deleted file mode 100755 index 29db86f..0000000 --- a/commons/src/main/java/net/jitse/npclib/api/ActionHandler.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2018 Jitse Boonstra - */ - -package net.jitse.npclib.api; - -/** - * @author Jitse Boonstra - */ -public interface ActionHandler { - -// void toggleSleep(Supplier> visible); -// -// void toggleShift(Supplier> visible); -// -// void toggleWatching(Player player, Supplier> visible); -} diff --git a/commons/src/main/java/net/jitse/npclib/api/packet/NPCPacket.java b/commons/src/main/java/net/jitse/npclib/api/packet/NPCPacket.java deleted file mode 100755 index 9ebf165..0000000 --- a/commons/src/main/java/net/jitse/npclib/api/packet/NPCPacket.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2018 Jitse Boonstra - */ - -package net.jitse.npclib.api.packet; - -import org.bukkit.entity.Player; - -/** - * @author Jitse Boonstra - */ -public abstract class NPCPacket { - - private Object packet; - - public void send(Player player) { - - } - - public abstract void create(); -} diff --git a/commons/src/main/java/net/jitse/npclib/api/wrapper/GameProfileWrapper.java b/commons/src/main/java/net/jitse/npclib/api/wrapper/GameProfileWrapper.java deleted file mode 100644 index 38c2888..0000000 --- a/commons/src/main/java/net/jitse/npclib/api/wrapper/GameProfileWrapper.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2018 Jitse Boonstra - */ - -package net.jitse.npclib.api.wrapper; - -import com.comphenix.tinyprotocol.Reflection; -import com.google.common.collect.ForwardingMultimap; -import net.jitse.npclib.skin.Skin; -import org.bukkit.Bukkit; - -import java.util.UUID; - -public class GameProfileWrapper { - - // Written because of issue#10 (https://github.com/JitseB/NPCLib/issues/10). - // This class acts as an NMS reflection wrapper for the GameProfileWrapper class. - - // TODO: As of 1.4.2 1.7 support was removed, refactor this class. - - // TODO: This doesn't seem to work well with modified versions of Spigot (see issue #12). - private final boolean is1_7 = Bukkit.getBukkitVersion().contains("1.7"); - private final Class gameProfileClazz = Reflection.getClass((is1_7 ? "net.minecraft.util." : "") + "com.mojang.authlib.GameProfile"); - - Object gameProfile; - - public GameProfileWrapper(UUID uuid, String name) { - // Only need to check if the version is 1.7, as NPCLib doesn't support any version below this version. - this.gameProfile = Reflection.getConstructor(gameProfileClazz, UUID.class, String.class).invoke(uuid, name); - } - - public void addSkin(Skin skin) { - // Create a new property with the skin data. - Class propertyClazz = Reflection.getClass((is1_7 ? "net.minecraft.util." : "") + "com.mojang.authlib.properties.Property"); - Object property = Reflection.getConstructor(propertyClazz, - String.class, String.class, String.class).invoke("textures", skin.getValue(), skin.getSignature()); - - // Get the property map from the GameProfileWrapper object. - Class propertyMapClazz = Reflection.getClass((is1_7 ? "net.minecraft.util." : "") + "com.mojang.authlib.properties.PropertyMap"); - Reflection.FieldAccessor propertyMapGetter = Reflection.getField(gameProfileClazz, "properties", - propertyMapClazz); - Object propertyMap = propertyMapGetter.get(gameProfile); - - // TODO: Won't work on 1.7.10 (as Guava also changed package location). - // Add our new property to the property map. - Reflection.getMethod(ForwardingMultimap.class, "put", Object.class, Object.class) - .invoke(propertyMap, "textures", property); - - // Finally set the property map back in the GameProfileWrapper object. - propertyMapGetter.set(gameProfile, propertyMap); - } - - public Object getGameProfile() { - return gameProfile; - } -} diff --git a/commons/src/main/java/net/jitse/npclib/events/click/ClickType.java b/commons/src/main/java/net/jitse/npclib/events/click/ClickType.java deleted file mode 100755 index f8d84a7..0000000 --- a/commons/src/main/java/net/jitse/npclib/events/click/ClickType.java +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2018 Jitse Boonstra - */ - -package net.jitse.npclib.events.click; - -/** - * @author Jitse Boonstra - */ -public enum ClickType { - - LEFT_CLICK, RIGHT_CLICK -} diff --git a/commons/src/main/java/net/jitse/npclib/events/trigger/TriggerType.java b/commons/src/main/java/net/jitse/npclib/events/trigger/TriggerType.java deleted file mode 100755 index 4310bcc..0000000 --- a/commons/src/main/java/net/jitse/npclib/events/trigger/TriggerType.java +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2018 Jitse Boonstra - */ - -package net.jitse.npclib.events.trigger; - -/** - * @author Jitse Boonstra - */ -public enum TriggerType { - - MANUAL, AUTOMATIC -} diff --git a/commons/src/main/java/net/jitse/npclib/logging/NPCLibLogger.java b/commons/src/main/java/net/jitse/npclib/logging/NPCLibLogger.java deleted file mode 100644 index 32f1e9d..0000000 --- a/commons/src/main/java/net/jitse/npclib/logging/NPCLibLogger.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2018 Jitse Boonstra - */ - -package net.jitse.npclib.logging; - -import org.bukkit.plugin.Plugin; - -import java.util.logging.Level; -import java.util.logging.LogRecord; -import java.util.logging.Logger; - -public class NPCLibLogger extends Logger { - - public NPCLibLogger(Plugin context) { - super(context.getClass().getCanonicalName(), null); - setParent(context.getServer().getLogger()); - setLevel(Level.ALL); - } - - @Override - public void log(LogRecord logRecord) { - logRecord.setMessage("[NPCLib] " + logRecord.getMessage()); - super.log(logRecord); - } -} diff --git a/nms/pom.xml b/nms/pom.xml new file mode 100644 index 0000000..f257a2f --- /dev/null +++ b/nms/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + pom + + + net.jitse + npclib + 2.0-SNAPSHOT + + + npclib-nms + + + v1_8_R1 + v1_8_R2 + v1_8_R3 + v1_9_R1 + v1_9_R2 + v1_10_R1 + v1_11_R1 + v1_12_R1 + v1_13_R1 + v1_13_R2 + v1_14_R1 + + + + + net.jitse + npclib-api + ${project.parent.version} + provided + + + diff --git a/nms/v1_10_R1/pom.xml b/nms/v1_10_R1/pom.xml index 4753407..aba32c5 100755 --- a/nms/v1_10_R1/pom.xml +++ b/nms/v1_10_R1/pom.xml @@ -3,11 +3,12 @@ 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"> 4.0.0 + jar net.jitse npclib-nms - 1.5-SNAPSHOT + 2.0-SNAPSHOT npclib-nms-v1_10_R1 diff --git a/nms/v1_10_R1/src/main/java/net/jitse/npclib/nms/v1_10_R1/NPC_v1_10_R1.java b/nms/v1_10_R1/src/main/java/net/jitse/npclib/nms/v1_10_R1/NPC_v1_10_R1.java index b352b2d..3438a45 100755 --- a/nms/v1_10_R1/src/main/java/net/jitse/npclib/nms/v1_10_R1/NPC_v1_10_R1.java +++ b/nms/v1_10_R1/src/main/java/net/jitse/npclib/nms/v1_10_R1/NPC_v1_10_R1.java @@ -4,25 +4,25 @@ package net.jitse.npclib.nms.v1_10_R1; -import net.jitse.npclib.api.NPC; -import net.jitse.npclib.nms.holograms.Hologram; +import net.jitse.npclib.NPCLib; +import net.jitse.npclib.hologram.Hologram; +import net.jitse.npclib.internal.MinecraftVersion; +import net.jitse.npclib.internal.SimpleNPC; import net.jitse.npclib.nms.v1_10_R1.packets.PacketPlayOutEntityHeadRotationWrapper; import net.jitse.npclib.nms.v1_10_R1.packets.PacketPlayOutNamedEntitySpawnWrapper; import net.jitse.npclib.nms.v1_10_R1.packets.PacketPlayOutPlayerInfoWrapper; import net.jitse.npclib.nms.v1_10_R1.packets.PacketPlayOutScoreboardTeamWrapper; -import net.jitse.npclib.skin.Skin; import net.minecraft.server.v1_10_R1.*; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; import java.util.List; /** * @author Jitse Boonstra */ -public class NPC_v1_10_R1 extends NPC { +public class NPC_v1_10_R1 extends SimpleNPC { private Hologram hologram; private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn; @@ -31,16 +31,15 @@ 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 lines) { - super(plugin, skin, autoHideDistance, lines); + public NPC_v1_10_R1(NPCLib instance, List lines) { + super(instance, lines); } @Override public void createPackets() { this.hologram = new Hologram(location.clone().subtract(0, 0.5, 0), lines); - hologram.generatePackets(true, false); + hologram.generatePackets(MinecraftVersion.V1_10_R1); - this.gameProfile = generateGameProfile(uuid, name); PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper(); // Packets for spawning the NPC: @@ -80,7 +79,7 @@ public class NPC_v1_10_R1 extends NPC { hologram.spawn(player); - Bukkit.getScheduler().runTaskLater(plugin, () -> + Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () -> playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50); } @@ -95,7 +94,7 @@ public class NPC_v1_10_R1 extends NPC { if (scheduler) { // Sending this a bit later so the player doesn't see the name (for that split second). - Bukkit.getScheduler().runTaskLater(plugin, () -> + Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () -> playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5); } else { playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister); diff --git a/nms/v1_10_R1/src/main/java/net/jitse/npclib/nms/v1_10_R1/packets/PacketPlayOutPlayerInfoWrapper.java b/nms/v1_10_R1/src/main/java/net/jitse/npclib/nms/v1_10_R1/packets/PacketPlayOutPlayerInfoWrapper.java index d5a77df..d07e54a 100755 --- a/nms/v1_10_R1/src/main/java/net/jitse/npclib/nms/v1_10_R1/packets/PacketPlayOutPlayerInfoWrapper.java +++ b/nms/v1_10_R1/src/main/java/net/jitse/npclib/nms/v1_10_R1/packets/PacketPlayOutPlayerInfoWrapper.java @@ -6,7 +6,6 @@ package net.jitse.npclib.nms.v1_10_R1.packets; import com.comphenix.tinyprotocol.Reflection; import com.mojang.authlib.GameProfile; -import net.jitse.npclib.api.wrapper.GameProfileWrapper; import net.minecraft.server.v1_10_R1.EnumGamemode; import net.minecraft.server.v1_10_R1.IChatBaseComponent; import net.minecraft.server.v1_10_R1.PacketPlayOutPlayerInfo; @@ -24,9 +23,7 @@ public class PacketPlayOutPlayerInfoWrapper { private final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClazz, packetPlayOutPlayerInfoClazz, GameProfile.class, int.class, EnumGamemode.class, IChatBaseComponent.class); - public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfileWrapper gameProfileWrapper, String name) { - GameProfile gameProfile = (GameProfile) gameProfileWrapper.getGameProfile(); - + public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfile gameProfile, String name) { PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo(); Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class) .set(packetPlayOutPlayerInfo, action); diff --git a/nms/v1_11_R1/pom.xml b/nms/v1_11_R1/pom.xml index eecbf1d..3ee8eb8 100755 --- a/nms/v1_11_R1/pom.xml +++ b/nms/v1_11_R1/pom.xml @@ -3,11 +3,12 @@ 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"> 4.0.0 + jar net.jitse npclib-nms - 1.5-SNAPSHOT + 2.0-SNAPSHOT npclib-nms-v1_11_R1 diff --git a/nms/v1_11_R1/src/main/java/net/jitse/npclib/nms/v1_11_R1/NPC_v1_11_R1.java b/nms/v1_11_R1/src/main/java/net/jitse/npclib/nms/v1_11_R1/NPC_v1_11_R1.java index 9cab2e7..055de27 100755 --- a/nms/v1_11_R1/src/main/java/net/jitse/npclib/nms/v1_11_R1/NPC_v1_11_R1.java +++ b/nms/v1_11_R1/src/main/java/net/jitse/npclib/nms/v1_11_R1/NPC_v1_11_R1.java @@ -4,25 +4,25 @@ package net.jitse.npclib.nms.v1_11_R1; -import net.jitse.npclib.api.NPC; -import net.jitse.npclib.nms.holograms.Hologram; +import net.jitse.npclib.NPCLib; +import net.jitse.npclib.hologram.Hologram; +import net.jitse.npclib.internal.MinecraftVersion; +import net.jitse.npclib.internal.SimpleNPC; import net.jitse.npclib.nms.v1_11_R1.packets.PacketPlayOutEntityHeadRotationWrapper; import net.jitse.npclib.nms.v1_11_R1.packets.PacketPlayOutNamedEntitySpawnWrapper; import net.jitse.npclib.nms.v1_11_R1.packets.PacketPlayOutPlayerInfoWrapper; import net.jitse.npclib.nms.v1_11_R1.packets.PacketPlayOutScoreboardTeamWrapper; -import net.jitse.npclib.skin.Skin; import net.minecraft.server.v1_11_R1.*; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; import java.util.List; /** * @author Jitse Boonstra */ -public class NPC_v1_11_R1 extends NPC { +public class NPC_v1_11_R1 extends SimpleNPC { private Hologram hologram; private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn; @@ -31,16 +31,15 @@ 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 lines) { - super(plugin, skin, autoHideDistance, lines); + public NPC_v1_11_R1(NPCLib instance, List lines) { + super(instance, lines); } @Override public void createPackets() { this.hologram = new Hologram(location.clone().add(0, 0.5, 0), lines); - hologram.generatePackets(true, false); + hologram.generatePackets(MinecraftVersion.V1_11_R1); - this.gameProfile = generateGameProfile(uuid, name); PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper(); // Packets for spawning the NPC: @@ -80,7 +79,7 @@ public class NPC_v1_11_R1 extends NPC { hologram.spawn(player); - Bukkit.getScheduler().runTaskLater(plugin, () -> + Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () -> playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50); } @@ -95,7 +94,7 @@ public class NPC_v1_11_R1 extends NPC { if (scheduler) { // Sending this a bit later so the player doesn't see the name (for that split second). - Bukkit.getScheduler().runTaskLater(plugin, () -> + Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () -> playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5); } else { playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister); diff --git a/nms/v1_11_R1/src/main/java/net/jitse/npclib/nms/v1_11_R1/packets/PacketPlayOutPlayerInfoWrapper.java b/nms/v1_11_R1/src/main/java/net/jitse/npclib/nms/v1_11_R1/packets/PacketPlayOutPlayerInfoWrapper.java index cb2a3de..52413e5 100755 --- a/nms/v1_11_R1/src/main/java/net/jitse/npclib/nms/v1_11_R1/packets/PacketPlayOutPlayerInfoWrapper.java +++ b/nms/v1_11_R1/src/main/java/net/jitse/npclib/nms/v1_11_R1/packets/PacketPlayOutPlayerInfoWrapper.java @@ -6,7 +6,6 @@ package net.jitse.npclib.nms.v1_11_R1.packets; import com.comphenix.tinyprotocol.Reflection; import com.mojang.authlib.GameProfile; -import net.jitse.npclib.api.wrapper.GameProfileWrapper; import net.minecraft.server.v1_11_R1.EnumGamemode; import net.minecraft.server.v1_11_R1.IChatBaseComponent; import net.minecraft.server.v1_11_R1.PacketPlayOutPlayerInfo; @@ -24,9 +23,7 @@ public class PacketPlayOutPlayerInfoWrapper { private final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClazz, packetPlayOutPlayerInfoClazz, GameProfile.class, int.class, EnumGamemode.class, IChatBaseComponent.class); - public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfileWrapper gameProfileWrapper, String name) { - GameProfile gameProfile = (GameProfile) gameProfileWrapper.getGameProfile(); - + public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfile gameProfile, String name) { PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo(); Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class) .set(packetPlayOutPlayerInfo, action); diff --git a/nms/v1_12_R1/pom.xml b/nms/v1_12_R1/pom.xml index 12cc525..e1adee5 100755 --- a/nms/v1_12_R1/pom.xml +++ b/nms/v1_12_R1/pom.xml @@ -3,11 +3,12 @@ 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"> 4.0.0 + jar net.jitse npclib-nms - 1.5-SNAPSHOT + 2.0-SNAPSHOT npclib-nms-v1_12_R1 diff --git a/nms/v1_12_R1/src/main/java/net/jitse/npclib/nms/v1_12_R1/NPC_v1_12_R1.java b/nms/v1_12_R1/src/main/java/net/jitse/npclib/nms/v1_12_R1/NPC_v1_12_R1.java index 348bd9d..ee47131 100755 --- a/nms/v1_12_R1/src/main/java/net/jitse/npclib/nms/v1_12_R1/NPC_v1_12_R1.java +++ b/nms/v1_12_R1/src/main/java/net/jitse/npclib/nms/v1_12_R1/NPC_v1_12_R1.java @@ -4,25 +4,25 @@ 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.NPCLib; +import net.jitse.npclib.hologram.Hologram; +import net.jitse.npclib.internal.MinecraftVersion; +import net.jitse.npclib.internal.SimpleNPC; 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; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; import java.util.List; /** * @author Jitse Boonstra */ -public class NPC_v1_12_R1 extends NPC { +public class NPC_v1_12_R1 extends SimpleNPC { private Hologram hologram; private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn; @@ -31,16 +31,15 @@ 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 lines) { - super(plugin, skin, autoHideDistance, lines); + public NPC_v1_12_R1(NPCLib instance, List lines) { + super(instance, lines); } @Override public void createPackets() { this.hologram = new Hologram(location.clone().add(0, 0.5, 0), lines); - hologram.generatePackets(true, false); + hologram.generatePackets(MinecraftVersion.V1_12_R1); - this.gameProfile = generateGameProfile(uuid, name); PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper(); // Packets for spawning the NPC: @@ -79,8 +78,7 @@ public class NPC_v1_12_R1 extends NPC { hologram.spawn(player); - - Bukkit.getScheduler().runTaskLater(plugin, () -> + Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () -> playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50); } @@ -95,7 +93,7 @@ public class NPC_v1_12_R1 extends NPC { if (scheduler) { // Sending this a bit later so the player doesn't see the name (for that split second). - Bukkit.getScheduler().runTaskLater(plugin, () -> + Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () -> playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5); } else { playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister); diff --git a/nms/v1_12_R1/src/main/java/net/jitse/npclib/nms/v1_12_R1/packets/PacketPlayOutPlayerInfoWrapper.java b/nms/v1_12_R1/src/main/java/net/jitse/npclib/nms/v1_12_R1/packets/PacketPlayOutPlayerInfoWrapper.java index e24f311..f13a0a4 100755 --- a/nms/v1_12_R1/src/main/java/net/jitse/npclib/nms/v1_12_R1/packets/PacketPlayOutPlayerInfoWrapper.java +++ b/nms/v1_12_R1/src/main/java/net/jitse/npclib/nms/v1_12_R1/packets/PacketPlayOutPlayerInfoWrapper.java @@ -6,7 +6,6 @@ package net.jitse.npclib.nms.v1_12_R1.packets; import com.comphenix.tinyprotocol.Reflection; import com.mojang.authlib.GameProfile; -import net.jitse.npclib.api.wrapper.GameProfileWrapper; import net.minecraft.server.v1_12_R1.EnumGamemode; import net.minecraft.server.v1_12_R1.IChatBaseComponent; import net.minecraft.server.v1_12_R1.PacketPlayOutPlayerInfo; @@ -24,9 +23,7 @@ public class PacketPlayOutPlayerInfoWrapper { private final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClazz, packetPlayOutPlayerInfoClazz, GameProfile.class, int.class, EnumGamemode.class, IChatBaseComponent.class); - public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfileWrapper gameProfileWrapper, String name) { - GameProfile gameProfile = (GameProfile) gameProfileWrapper.getGameProfile(); - + public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfile gameProfile, String name) { PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo(); Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class) .set(packetPlayOutPlayerInfo, action); diff --git a/nms/v1_13_R1/pom.xml b/nms/v1_13_R1/pom.xml index 3c46984..97128d8 100755 --- a/nms/v1_13_R1/pom.xml +++ b/nms/v1_13_R1/pom.xml @@ -3,11 +3,12 @@ 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"> 4.0.0 + jar net.jitse npclib-nms - 1.5-SNAPSHOT + 2.0-SNAPSHOT npclib-nms-v1_13_R1 diff --git a/nms/v1_13_R1/src/main/java/net/jitse/npclib/nms/v1_13_R1/NPC_v1_13_R1.java b/nms/v1_13_R1/src/main/java/net/jitse/npclib/nms/v1_13_R1/NPC_v1_13_R1.java index b64b767..db05c74 100755 --- a/nms/v1_13_R1/src/main/java/net/jitse/npclib/nms/v1_13_R1/NPC_v1_13_R1.java +++ b/nms/v1_13_R1/src/main/java/net/jitse/npclib/nms/v1_13_R1/NPC_v1_13_R1.java @@ -4,26 +4,25 @@ package net.jitse.npclib.nms.v1_13_R1; -import net.jitse.npclib.api.NPC; -import net.jitse.npclib.nms.holograms.Hologram; +import net.jitse.npclib.NPCLib; +import net.jitse.npclib.hologram.Hologram; +import net.jitse.npclib.internal.MinecraftVersion; +import net.jitse.npclib.internal.SimpleNPC; import net.jitse.npclib.nms.v1_13_R1.packets.PacketPlayOutEntityHeadRotationWrapper; import net.jitse.npclib.nms.v1_13_R1.packets.PacketPlayOutNamedEntitySpawnWrapper; import net.jitse.npclib.nms.v1_13_R1.packets.PacketPlayOutPlayerInfoWrapper; import net.jitse.npclib.nms.v1_13_R1.packets.PacketPlayOutScoreboardTeamWrapper; -import net.jitse.npclib.skin.Skin; import net.minecraft.server.v1_13_R1.*; import org.bukkit.Bukkit; - import org.bukkit.craftbukkit.v1_13_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; import java.util.List; /** * @author Jitse Boonstra */ -public class NPC_v1_13_R1 extends NPC { +public class NPC_v1_13_R1 extends SimpleNPC { private Hologram hologram; private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn; @@ -32,16 +31,15 @@ public class NPC_v1_13_R1 extends NPC { private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation; private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy; - public NPC_v1_13_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List lines) { - super(plugin, skin, autoHideDistance, lines); + public NPC_v1_13_R1(NPCLib instance, List lines) { + super(instance, lines); } @Override public void createPackets() { this.hologram = new Hologram(location.clone().add(0, 0.5, 0), lines); - hologram.generatePackets(true, true); + hologram.generatePackets(MinecraftVersion.V1_13_R1); - this.gameProfile = generateGameProfile(uuid, name); PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper(); // Packets for spawning the NPC: @@ -81,7 +79,7 @@ public class NPC_v1_13_R1 extends NPC { hologram.spawn(player); - Bukkit.getScheduler().runTaskLater(plugin, () -> + Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () -> playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50); } @@ -96,7 +94,7 @@ public class NPC_v1_13_R1 extends NPC { if (scheduler) { // Sending this a bit later so the player doesn't see the name (for that split second). - Bukkit.getScheduler().runTaskLater(plugin, () -> + Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () -> playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5); } else { playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister); diff --git a/nms/v1_13_R1/src/main/java/net/jitse/npclib/nms/v1_13_R1/packets/PacketPlayOutPlayerInfoWrapper.java b/nms/v1_13_R1/src/main/java/net/jitse/npclib/nms/v1_13_R1/packets/PacketPlayOutPlayerInfoWrapper.java index 24b0d6a..578efb0 100755 --- a/nms/v1_13_R1/src/main/java/net/jitse/npclib/nms/v1_13_R1/packets/PacketPlayOutPlayerInfoWrapper.java +++ b/nms/v1_13_R1/src/main/java/net/jitse/npclib/nms/v1_13_R1/packets/PacketPlayOutPlayerInfoWrapper.java @@ -6,7 +6,6 @@ package net.jitse.npclib.nms.v1_13_R1.packets; import com.comphenix.tinyprotocol.Reflection; import com.mojang.authlib.GameProfile; -import net.jitse.npclib.api.wrapper.GameProfileWrapper; import net.minecraft.server.v1_13_R1.EnumGamemode; import net.minecraft.server.v1_13_R1.IChatBaseComponent; import net.minecraft.server.v1_13_R1.PacketPlayOutPlayerInfo; @@ -24,9 +23,7 @@ public class PacketPlayOutPlayerInfoWrapper { private final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClazz, packetPlayOutPlayerInfoClazz, GameProfile.class, int.class, EnumGamemode.class, IChatBaseComponent.class); - public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfileWrapper gameProfileWrapper, String name) { - GameProfile gameProfile = (GameProfile) gameProfileWrapper.getGameProfile(); - + public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfile gameProfile, String name) { PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo(); Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class) .set(packetPlayOutPlayerInfo, action); diff --git a/nms/v1_13_R2/pom.xml b/nms/v1_13_R2/pom.xml index e7674b8..50684b4 100755 --- a/nms/v1_13_R2/pom.xml +++ b/nms/v1_13_R2/pom.xml @@ -3,11 +3,12 @@ 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"> 4.0.0 + jar net.jitse npclib-nms - 1.5-SNAPSHOT + 2.0-SNAPSHOT npclib-nms-v1_13_R2 diff --git a/nms/v1_13_R2/src/main/java/net/jitse/npclib/nms/v1_13_R2/NPC_v1_13_R2.java b/nms/v1_13_R2/src/main/java/net/jitse/npclib/nms/v1_13_R2/NPC_v1_13_R2.java index 0efa24f..54ac946 100755 --- a/nms/v1_13_R2/src/main/java/net/jitse/npclib/nms/v1_13_R2/NPC_v1_13_R2.java +++ b/nms/v1_13_R2/src/main/java/net/jitse/npclib/nms/v1_13_R2/NPC_v1_13_R2.java @@ -4,25 +4,25 @@ package net.jitse.npclib.nms.v1_13_R2; -import net.jitse.npclib.api.NPC; -import net.jitse.npclib.nms.holograms.Hologram; +import net.jitse.npclib.NPCLib; +import net.jitse.npclib.hologram.Hologram; +import net.jitse.npclib.internal.MinecraftVersion; +import net.jitse.npclib.internal.SimpleNPC; import net.jitse.npclib.nms.v1_13_R2.packets.PacketPlayOutEntityHeadRotationWrapper; import net.jitse.npclib.nms.v1_13_R2.packets.PacketPlayOutNamedEntitySpawnWrapper; import net.jitse.npclib.nms.v1_13_R2.packets.PacketPlayOutPlayerInfoWrapper; import net.jitse.npclib.nms.v1_13_R2.packets.PacketPlayOutScoreboardTeamWrapper; -import net.jitse.npclib.skin.Skin; import net.minecraft.server.v1_13_R2.*; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer; import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; import java.util.List; /** * @author Jitse Boonstra */ -public class NPC_v1_13_R2 extends NPC { +public class NPC_v1_13_R2 extends SimpleNPC { private Hologram hologram; private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn; @@ -31,16 +31,15 @@ public class NPC_v1_13_R2 extends NPC { private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation; private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy; - public NPC_v1_13_R2(JavaPlugin plugin, Skin skin, double autoHideDistance, List lines) { - super(plugin, skin, autoHideDistance, lines); + public NPC_v1_13_R2(NPCLib instance, List lines) { + super(instance, lines); } @Override public void createPackets() { this.hologram = new Hologram(location.clone().add(0, 0.5, 0), lines); - hologram.generatePackets(true, true); + hologram.generatePackets(MinecraftVersion.V1_13_R2); - this.gameProfile = generateGameProfile(uuid, name); PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper(); // Packets for spawning the NPC: @@ -80,7 +79,7 @@ public class NPC_v1_13_R2 extends NPC { hologram.spawn(player); - Bukkit.getScheduler().runTaskLater(plugin, () -> + Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () -> playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50); } @@ -95,7 +94,7 @@ public class NPC_v1_13_R2 extends NPC { if (scheduler) { // Sending this a bit later so the player doesn't see the name (for that split second). - Bukkit.getScheduler().runTaskLater(plugin, () -> + Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () -> playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5); } else { playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister); diff --git a/nms/v1_13_R2/src/main/java/net/jitse/npclib/nms/v1_13_R2/packets/PacketPlayOutPlayerInfoWrapper.java b/nms/v1_13_R2/src/main/java/net/jitse/npclib/nms/v1_13_R2/packets/PacketPlayOutPlayerInfoWrapper.java index bd8103d..79e1fbb 100755 --- a/nms/v1_13_R2/src/main/java/net/jitse/npclib/nms/v1_13_R2/packets/PacketPlayOutPlayerInfoWrapper.java +++ b/nms/v1_13_R2/src/main/java/net/jitse/npclib/nms/v1_13_R2/packets/PacketPlayOutPlayerInfoWrapper.java @@ -6,7 +6,6 @@ package net.jitse.npclib.nms.v1_13_R2.packets; import com.comphenix.tinyprotocol.Reflection; import com.mojang.authlib.GameProfile; -import net.jitse.npclib.api.wrapper.GameProfileWrapper; import net.minecraft.server.v1_13_R2.EnumGamemode; import net.minecraft.server.v1_13_R2.IChatBaseComponent; import net.minecraft.server.v1_13_R2.PacketPlayOutPlayerInfo; @@ -24,9 +23,7 @@ public class PacketPlayOutPlayerInfoWrapper { private final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClazz, packetPlayOutPlayerInfoClazz, GameProfile.class, int.class, EnumGamemode.class, IChatBaseComponent.class); - public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfileWrapper gameProfileWrapper, String name) { - GameProfile gameProfile = (GameProfile) gameProfileWrapper.getGameProfile(); - + public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfile gameProfile, String name) { PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo(); Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class) .set(packetPlayOutPlayerInfo, action); diff --git a/nms/v1_14_R1/pom.xml b/nms/v1_14_R1/pom.xml new file mode 100755 index 0000000..604ac4e --- /dev/null +++ b/nms/v1_14_R1/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + jar + + + net.jitse + npclib-nms + 2.0-SNAPSHOT + + + npclib-nms-v1_14_R1 + + + + org.spigotmc + spigot + 1.14.4-R0.1-SNAPSHOT + provided + + + diff --git a/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/NPC_v1_14_R1.java b/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/NPC_v1_14_R1.java new file mode 100755 index 0000000..bb799d6 --- /dev/null +++ b/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/NPC_v1_14_R1.java @@ -0,0 +1,99 @@ +package net.jitse.npclib.nms.v1_14_R1; + +import net.jitse.npclib.NPCLib; +import net.jitse.npclib.hologram.Hologram; +import net.jitse.npclib.internal.MinecraftVersion; +import net.jitse.npclib.internal.SimpleNPC; +import net.jitse.npclib.nms.v1_14_R1.packets.PacketPlayOutEntityHeadRotationWrapper; +import net.jitse.npclib.nms.v1_14_R1.packets.PacketPlayOutNamedEntitySpawnWrapper; +import net.jitse.npclib.nms.v1_14_R1.packets.PacketPlayOutPlayerInfoWrapper; +import net.jitse.npclib.nms.v1_14_R1.packets.PacketPlayOutScoreboardTeamWrapper; +import net.minecraft.server.v1_14_R1.*; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; + +import java.util.List; + +/** + * @author Jitse Boonstra + */ +public class NPC_v1_14_R1 extends SimpleNPC { + + private Hologram hologram; + private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn; + private PacketPlayOutScoreboardTeam packetPlayOutScoreboardTeamRegister, packetPlayOutScoreboardTeamUnregister; + private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove; + private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation; + private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy; + + public NPC_v1_14_R1(NPCLib instance, List lines) { + super(instance, lines); + } + + @Override + public void createPackets() { + this.hologram = new Hologram(location.clone().add(0, 0.5, 0), lines); + hologram.generatePackets(MinecraftVersion.V1_14_R1); + + PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper(); + + // Packets for spawning the NPC: + this.packetPlayOutScoreboardTeamRegister = new PacketPlayOutScoreboardTeamWrapper() + .createRegisterTeam(name); // First packet to send. + + this.packetPlayOutPlayerInfoAdd = packetPlayOutPlayerInfoWrapper + .create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, gameProfile, name); // Second packet to send. + + this.packetPlayOutNamedEntitySpawn = new PacketPlayOutNamedEntitySpawnWrapper() + .create(uuid, location, entityId); // Third packet to send. + + this.packetPlayOutEntityHeadRotation = new PacketPlayOutEntityHeadRotationWrapper() + .create(location, entityId); // Fourth packet to send. + + this.packetPlayOutPlayerInfoRemove = packetPlayOutPlayerInfoWrapper + .create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, gameProfile, name); // Fifth packet to send (delayed). + + // Packet for destroying the NPC: + this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send. + + // Second packet to send is "packetPlayOutPlayerInfoRemove". + + this.packetPlayOutScoreboardTeamUnregister = new PacketPlayOutScoreboardTeamWrapper() + .createUnregisterTeam(name); // Third packet to send. + } + + @Override + public void sendShowPackets(Player player) { + PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; + + playerConnection.sendPacket(packetPlayOutScoreboardTeamRegister); + playerConnection.sendPacket(packetPlayOutPlayerInfoAdd); + playerConnection.sendPacket(packetPlayOutNamedEntitySpawn); + playerConnection.sendPacket(packetPlayOutEntityHeadRotation); + + hologram.spawn(player); + + + Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () -> + playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50); + } + + @Override + public void sendHidePackets(Player player, boolean scheduler) { + PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; + + playerConnection.sendPacket(packetPlayOutEntityDestroy); + playerConnection.sendPacket(packetPlayOutPlayerInfoRemove); + + hologram.destroy(player); + + if (scheduler) { + // Sending this a bit later so the player doesn't see the name (for that split second). + Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () -> + playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5); + } else { + playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister); + } + } +} diff --git a/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutEntityHeadRotationWrapper.java b/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutEntityHeadRotationWrapper.java new file mode 100755 index 0000000..f0e5d15 --- /dev/null +++ b/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutEntityHeadRotationWrapper.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2018 Jitse Boonstra + */ + +package net.jitse.npclib.nms.v1_14_R1.packets; + +import com.comphenix.tinyprotocol.Reflection; +import net.minecraft.server.v1_14_R1.PacketPlayOutEntityHeadRotation; +import org.bukkit.Location; + +/** + * @author Jitse Boonstra + */ +public class PacketPlayOutEntityHeadRotationWrapper { + + public PacketPlayOutEntityHeadRotation create(Location location, int entityId) { + PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation = new PacketPlayOutEntityHeadRotation(); + + Reflection.getField(packetPlayOutEntityHeadRotation.getClass(), "a", int.class). + set(packetPlayOutEntityHeadRotation, entityId); + Reflection.getField(packetPlayOutEntityHeadRotation.getClass(), "b", byte.class) + .set(packetPlayOutEntityHeadRotation, (byte) ((int) location.getYaw() * 256.0F / 360.0F)); + + return packetPlayOutEntityHeadRotation; + } +} diff --git a/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutNamedEntitySpawnWrapper.java b/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutNamedEntitySpawnWrapper.java new file mode 100755 index 0000000..15e4988 --- /dev/null +++ b/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutNamedEntitySpawnWrapper.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2018 Jitse Boonstra + */ + +package net.jitse.npclib.nms.v1_14_R1.packets; + +import com.comphenix.tinyprotocol.Reflection; +import net.minecraft.server.v1_14_R1.DataWatcher; +import net.minecraft.server.v1_14_R1.DataWatcherObject; +import net.minecraft.server.v1_14_R1.DataWatcherRegistry; +import net.minecraft.server.v1_14_R1.PacketPlayOutNamedEntitySpawn; +import org.bukkit.Location; + +import java.util.UUID; + +/** + * @author Jitse Boonstra + */ +public class PacketPlayOutNamedEntitySpawnWrapper { + + public PacketPlayOutNamedEntitySpawn create(UUID uuid, Location location, int entityId) { + PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn = new PacketPlayOutNamedEntitySpawn(); + + Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "a", int.class) + .set(packetPlayOutNamedEntitySpawn, entityId); + Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "b", UUID.class) + .set(packetPlayOutNamedEntitySpawn, uuid); + Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "c", double.class) + .set(packetPlayOutNamedEntitySpawn, location.getX()); + Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "d", double.class) + .set(packetPlayOutNamedEntitySpawn, location.getY()); + Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "e", double.class) + .set(packetPlayOutNamedEntitySpawn, location.getZ()); + Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "f", byte.class) + .set(packetPlayOutNamedEntitySpawn, (byte) ((int) (location.getYaw() * 256.0F / 360.0F))); + Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "g", byte.class) + .set(packetPlayOutNamedEntitySpawn, (byte) ((int) (location.getPitch() * 256.0F / 360.0F))); + + DataWatcher dataWatcher = new DataWatcher(null); + dataWatcher.register(new DataWatcherObject<>(13, DataWatcherRegistry.a), (byte) 127); + + Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "h", DataWatcher.class) + .set(packetPlayOutNamedEntitySpawn, dataWatcher); + + return packetPlayOutNamedEntitySpawn; + } +} diff --git a/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutPlayerInfoWrapper.java b/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutPlayerInfoWrapper.java new file mode 100755 index 0000000..ad8021b --- /dev/null +++ b/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutPlayerInfoWrapper.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2018 Jitse Boonstra + */ + +package net.jitse.npclib.nms.v1_14_R1.packets; + +import com.comphenix.tinyprotocol.Reflection; +import com.mojang.authlib.GameProfile; +import net.minecraft.server.v1_14_R1.EnumGamemode; +import net.minecraft.server.v1_14_R1.IChatBaseComponent; +import net.minecraft.server.v1_14_R1.PacketPlayOutPlayerInfo; +import org.bukkit.ChatColor; + +import java.util.List; + +/** + * @author Jitse Boonstra + */ +public class PacketPlayOutPlayerInfoWrapper { + + private final Class packetPlayOutPlayerInfoClazz = Reflection.getMinecraftClass("PacketPlayOutPlayerInfo"); + private final Class playerInfoDataClazz = Reflection.getMinecraftClass("PacketPlayOutPlayerInfo$PlayerInfoData"); + private final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClazz, + packetPlayOutPlayerInfoClazz, GameProfile.class, int.class, EnumGamemode.class, IChatBaseComponent.class); + + public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfile gameProfile, String name) { + PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo(); + Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class) + .set(packetPlayOutPlayerInfo, action); + + Object playerInfoData = playerInfoDataConstructor.invoke(packetPlayOutPlayerInfo, + gameProfile, 1, EnumGamemode.NOT_SET, + IChatBaseComponent.ChatSerializer.b("{\"text\":\"" + ChatColor.BLUE + "[NPC] " + name + "\"}") + ); + + Reflection.FieldAccessor fieldAccessor = Reflection.getField(packetPlayOutPlayerInfo.getClass(), "b", List.class); + List list = fieldAccessor.get(packetPlayOutPlayerInfo); + list.add(playerInfoData); + fieldAccessor.set(packetPlayOutPlayerInfo, list); + + return packetPlayOutPlayerInfo; + } +} diff --git a/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutScoreboardTeamWrapper.java b/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutScoreboardTeamWrapper.java new file mode 100755 index 0000000..234071f --- /dev/null +++ b/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutScoreboardTeamWrapper.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2018 Jitse Boonstra + */ + +package net.jitse.npclib.nms.v1_14_R1.packets; + +import com.comphenix.tinyprotocol.Reflection; +import net.minecraft.server.v1_14_R1.ChatComponentText; +import net.minecraft.server.v1_14_R1.IChatBaseComponent; +import net.minecraft.server.v1_14_R1.PacketPlayOutScoreboardTeam; + +import java.util.Collection; + +/** + * @author Jitse Boonstra + */ +public class PacketPlayOutScoreboardTeamWrapper { + + public PacketPlayOutScoreboardTeam createRegisterTeam(String name) { + PacketPlayOutScoreboardTeam packetPlayOutScoreboardTeam = new PacketPlayOutScoreboardTeam(); + + Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "i", int.class) + .set(packetPlayOutScoreboardTeam, 0); + Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "a", String.class) + .set(packetPlayOutScoreboardTeam, name); + Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "b", IChatBaseComponent.class) + .set(packetPlayOutScoreboardTeam, new ChatComponentText(name)); + Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "e", String.class) + .set(packetPlayOutScoreboardTeam, "never"); + Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "f", String.class) + .set(packetPlayOutScoreboardTeam, "never"); + Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "j", int.class) + .set(packetPlayOutScoreboardTeam, 0); + Reflection.FieldAccessor collectionFieldAccessor = Reflection.getField( + packetPlayOutScoreboardTeam.getClass(), "h", Collection.class); + Collection collection = collectionFieldAccessor.get(packetPlayOutScoreboardTeam); + collection.add(name); + collectionFieldAccessor.set(packetPlayOutScoreboardTeam, collection); + + return packetPlayOutScoreboardTeam; + } + + public PacketPlayOutScoreboardTeam createUnregisterTeam(String name) { + PacketPlayOutScoreboardTeam packetPlayOutScoreboardTeam = new PacketPlayOutScoreboardTeam(); + + Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "i", int.class) + .set(packetPlayOutScoreboardTeam, 1); + Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "a", String.class) + .set(packetPlayOutScoreboardTeam, name); + + return packetPlayOutScoreboardTeam; + } +} diff --git a/nms/v1_8_R1/pom.xml b/nms/v1_8_R1/pom.xml index 3ab01af..abf3648 100755 --- a/nms/v1_8_R1/pom.xml +++ b/nms/v1_8_R1/pom.xml @@ -3,11 +3,12 @@ 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"> 4.0.0 + jar net.jitse npclib-nms - 1.5-SNAPSHOT + 2.0-SNAPSHOT npclib-nms-v1_8_R1 @@ -26,4 +27,22 @@ compile + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + + package + + shade + + + + + + diff --git a/nms/v1_8_R1/src/main/java/net/jitse/npclib/nms/v1_8_R1/NPC_v1_8_R1.java b/nms/v1_8_R1/src/main/java/net/jitse/npclib/nms/v1_8_R1/NPC_v1_8_R1.java index 44987ec..5554652 100755 --- a/nms/v1_8_R1/src/main/java/net/jitse/npclib/nms/v1_8_R1/NPC_v1_8_R1.java +++ b/nms/v1_8_R1/src/main/java/net/jitse/npclib/nms/v1_8_R1/NPC_v1_8_R1.java @@ -4,25 +4,25 @@ package net.jitse.npclib.nms.v1_8_R1; -import net.jitse.npclib.api.NPC; -import net.jitse.npclib.nms.holograms.Hologram; +import net.jitse.npclib.NPCLib; +import net.jitse.npclib.hologram.Hologram; +import net.jitse.npclib.internal.MinecraftVersion; +import net.jitse.npclib.internal.SimpleNPC; import net.jitse.npclib.nms.v1_8_R1.packets.PacketPlayOutEntityHeadRotationWrapper; import net.jitse.npclib.nms.v1_8_R1.packets.PacketPlayOutNamedEntitySpawnWrapper; import net.jitse.npclib.nms.v1_8_R1.packets.PacketPlayOutPlayerInfoWrapper; 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.craftbukkit.v1_8_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; import java.util.List; /** * @author Jitse Boonstra */ -public class NPC_v1_8_R1 extends NPC { +public class NPC_v1_8_R1 extends SimpleNPC { private Hologram hologram; private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn; @@ -31,16 +31,15 @@ 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 lines) { - super(plugin, skin, autoHideDistance, lines); + public NPC_v1_8_R1(NPCLib instance, List lines) { + super(instance, lines); } @Override public void createPackets() { this.hologram = new Hologram(location.clone().add(0, 0.5, 0), lines); - hologram.generatePackets(false, false); + hologram.generatePackets(MinecraftVersion.V1_8_R1); - this.gameProfile = generateGameProfile(uuid, name); PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper(); // Packets for spawning the NPC: @@ -79,7 +78,7 @@ public class NPC_v1_8_R1 extends NPC { hologram.spawn(player); - Bukkit.getScheduler().runTaskLater(plugin, () -> + Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () -> playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50); } @@ -94,7 +93,7 @@ public class NPC_v1_8_R1 extends NPC { if (scheduler) { // Sending this a bit later so the player doesn't see the name (for that split second). - Bukkit.getScheduler().runTaskLater(plugin, () -> + Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () -> playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5); } else { playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister); diff --git a/nms/v1_8_R1/src/main/java/net/jitse/npclib/nms/v1_8_R1/packets/PacketPlayOutPlayerInfoWrapper.java b/nms/v1_8_R1/src/main/java/net/jitse/npclib/nms/v1_8_R1/packets/PacketPlayOutPlayerInfoWrapper.java index bab9bfb..283b46e 100755 --- a/nms/v1_8_R1/src/main/java/net/jitse/npclib/nms/v1_8_R1/packets/PacketPlayOutPlayerInfoWrapper.java +++ b/nms/v1_8_R1/src/main/java/net/jitse/npclib/nms/v1_8_R1/packets/PacketPlayOutPlayerInfoWrapper.java @@ -6,7 +6,6 @@ package net.jitse.npclib.nms.v1_8_R1.packets; import com.comphenix.tinyprotocol.Reflection; import com.mojang.authlib.GameProfile; -import net.jitse.npclib.api.wrapper.GameProfileWrapper; import net.minecraft.server.v1_8_R1.*; import java.util.List; @@ -16,9 +15,7 @@ import java.util.List; */ public class PacketPlayOutPlayerInfoWrapper { - public PacketPlayOutPlayerInfo create(EnumPlayerInfoAction action, GameProfileWrapper gameProfileWrapper, String name) { - GameProfile gameProfile = (GameProfile) gameProfileWrapper.getGameProfile(); - + public PacketPlayOutPlayerInfo create(EnumPlayerInfoAction action, GameProfile gameProfile, String name) { PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo(); Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", EnumPlayerInfoAction.class) .set(packetPlayOutPlayerInfo, action); diff --git a/nms/v1_8_R2/pom.xml b/nms/v1_8_R2/pom.xml index a68e0c0..280a8b8 100755 --- a/nms/v1_8_R2/pom.xml +++ b/nms/v1_8_R2/pom.xml @@ -3,11 +3,12 @@ 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"> 4.0.0 + jar net.jitse npclib-nms - 1.5-SNAPSHOT + 2.0-SNAPSHOT npclib-nms-v1_8_R2 diff --git a/nms/v1_8_R2/src/main/java/net/jitse/npclib/nms/v1_8_R2/NPC_v1_8_R2.java b/nms/v1_8_R2/src/main/java/net/jitse/npclib/nms/v1_8_R2/NPC_v1_8_R2.java index 978f409..94e51ca 100755 --- a/nms/v1_8_R2/src/main/java/net/jitse/npclib/nms/v1_8_R2/NPC_v1_8_R2.java +++ b/nms/v1_8_R2/src/main/java/net/jitse/npclib/nms/v1_8_R2/NPC_v1_8_R2.java @@ -4,25 +4,25 @@ package net.jitse.npclib.nms.v1_8_R2; -import net.jitse.npclib.api.NPC; -import net.jitse.npclib.nms.holograms.Hologram; +import net.jitse.npclib.NPCLib; +import net.jitse.npclib.hologram.Hologram; +import net.jitse.npclib.internal.MinecraftVersion; +import net.jitse.npclib.internal.SimpleNPC; import net.jitse.npclib.nms.v1_8_R2.packets.PacketPlayOutEntityHeadRotationWrapper; import net.jitse.npclib.nms.v1_8_R2.packets.PacketPlayOutNamedEntitySpawnWrapper; import net.jitse.npclib.nms.v1_8_R2.packets.PacketPlayOutPlayerInfoWrapper; import net.jitse.npclib.nms.v1_8_R2.packets.PacketPlayOutScoreboardTeamWrapper; -import net.jitse.npclib.skin.Skin; import net.minecraft.server.v1_8_R2.*; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; import java.util.List; /** * @author Jitse Boonstra */ -public class NPC_v1_8_R2 extends NPC { +public class NPC_v1_8_R2 extends SimpleNPC { private Hologram hologram; private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn; @@ -31,16 +31,15 @@ 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 lines) { - super(plugin, skin, autoHideDistance, lines); + public NPC_v1_8_R2(NPCLib instance, List lines) { + super(instance, lines); } @Override public void createPackets() { this.hologram = new Hologram(location.clone().add(0, 0.5, 0), lines); - hologram.generatePackets(false, false); + hologram.generatePackets(MinecraftVersion.V1_8_R2); - this.gameProfile = generateGameProfile(uuid, name); PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper(); // Packets for spawning the NPC: @@ -79,7 +78,7 @@ public class NPC_v1_8_R2 extends NPC { hologram.spawn(player); - Bukkit.getScheduler().runTaskLater(plugin, () -> + Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () -> playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50); } @@ -94,7 +93,7 @@ public class NPC_v1_8_R2 extends NPC { if (scheduler) { // Sending this a bit later so the player doesn't see the name (for that split second). - Bukkit.getScheduler().runTaskLater(plugin, () -> + Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () -> playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5); } else { playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister); diff --git a/nms/v1_8_R2/src/main/java/net/jitse/npclib/nms/v1_8_R2/packets/PacketPlayOutPlayerInfoWrapper.java b/nms/v1_8_R2/src/main/java/net/jitse/npclib/nms/v1_8_R2/packets/PacketPlayOutPlayerInfoWrapper.java index 9afaaca..bca9688 100755 --- a/nms/v1_8_R2/src/main/java/net/jitse/npclib/nms/v1_8_R2/packets/PacketPlayOutPlayerInfoWrapper.java +++ b/nms/v1_8_R2/src/main/java/net/jitse/npclib/nms/v1_8_R2/packets/PacketPlayOutPlayerInfoWrapper.java @@ -6,7 +6,6 @@ package net.jitse.npclib.nms.v1_8_R2.packets; import com.comphenix.tinyprotocol.Reflection; import com.mojang.authlib.GameProfile; -import net.jitse.npclib.api.wrapper.GameProfileWrapper; import net.minecraft.server.v1_8_R2.IChatBaseComponent; import net.minecraft.server.v1_8_R2.PacketPlayOutPlayerInfo; import net.minecraft.server.v1_8_R2.WorldSettings; @@ -18,9 +17,7 @@ import java.util.List; */ public class PacketPlayOutPlayerInfoWrapper { - public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfileWrapper gameProfileWrapper, String name) { - GameProfile gameProfile = (GameProfile) gameProfileWrapper.getGameProfile(); - + public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfile gameProfile, String name) { PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo(); Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class) .set(packetPlayOutPlayerInfo, action); diff --git a/nms/v1_8_R3/pom.xml b/nms/v1_8_R3/pom.xml index 62b9627..16d10da 100755 --- a/nms/v1_8_R3/pom.xml +++ b/nms/v1_8_R3/pom.xml @@ -3,11 +3,12 @@ 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"> 4.0.0 + jar net.jitse npclib-nms - 1.5-SNAPSHOT + 2.0-SNAPSHOT npclib-nms-v1_8_R3 diff --git a/nms/v1_8_R3/src/main/java/net/jitse/npclib/nms/v1_8_R3/NPC_v1_8_R3.java b/nms/v1_8_R3/src/main/java/net/jitse/npclib/nms/v1_8_R3/NPC_v1_8_R3.java index 4a8af07..0b4d990 100755 --- a/nms/v1_8_R3/src/main/java/net/jitse/npclib/nms/v1_8_R3/NPC_v1_8_R3.java +++ b/nms/v1_8_R3/src/main/java/net/jitse/npclib/nms/v1_8_R3/NPC_v1_8_R3.java @@ -4,25 +4,25 @@ package net.jitse.npclib.nms.v1_8_R3; -import net.jitse.npclib.api.NPC; -import net.jitse.npclib.nms.holograms.Hologram; +import net.jitse.npclib.NPCLib; +import net.jitse.npclib.hologram.Hologram; +import net.jitse.npclib.internal.MinecraftVersion; +import net.jitse.npclib.internal.SimpleNPC; import net.jitse.npclib.nms.v1_8_R3.packets.PacketPlayOutEntityHeadRotationWrapper; import net.jitse.npclib.nms.v1_8_R3.packets.PacketPlayOutNamedEntitySpawnWrapper; import net.jitse.npclib.nms.v1_8_R3.packets.PacketPlayOutPlayerInfoWrapper; import net.jitse.npclib.nms.v1_8_R3.packets.PacketPlayOutScoreboardTeamWrapper; -import net.jitse.npclib.skin.Skin; import net.minecraft.server.v1_8_R3.*; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; import java.util.List; /** * @author Jitse Boonstra */ -public class NPC_v1_8_R3 extends NPC { +public class NPC_v1_8_R3 extends SimpleNPC { private Hologram hologram; private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn; @@ -31,16 +31,15 @@ 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 lines) { - super(plugin, skin, autoHideDistance, lines); + public NPC_v1_8_R3(NPCLib instance, List lines) { + super(instance, lines); } @Override public void createPackets() { this.hologram = new Hologram(location.clone().add(0, 0.5, 0), lines); - hologram.generatePackets(false, false); + hologram.generatePackets(MinecraftVersion.V1_8_R3); - this.gameProfile = generateGameProfile(uuid, name); PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper(); // Packets for spawning the NPC: @@ -80,7 +79,7 @@ public class NPC_v1_8_R3 extends NPC { hologram.spawn(player); - Bukkit.getScheduler().runTaskLater(plugin, () -> + Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () -> playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50); } @@ -95,7 +94,7 @@ public class NPC_v1_8_R3 extends NPC { if (scheduler) { // Sending this a bit later so the player doesn't see the name (for that split second). - Bukkit.getScheduler().runTaskLater(plugin, () -> + Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () -> playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5); } else { playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister); diff --git a/nms/v1_8_R3/src/main/java/net/jitse/npclib/nms/v1_8_R3/packets/PacketPlayOutPlayerInfoWrapper.java b/nms/v1_8_R3/src/main/java/net/jitse/npclib/nms/v1_8_R3/packets/PacketPlayOutPlayerInfoWrapper.java index 24a7cc0..3c411df 100755 --- a/nms/v1_8_R3/src/main/java/net/jitse/npclib/nms/v1_8_R3/packets/PacketPlayOutPlayerInfoWrapper.java +++ b/nms/v1_8_R3/src/main/java/net/jitse/npclib/nms/v1_8_R3/packets/PacketPlayOutPlayerInfoWrapper.java @@ -6,7 +6,6 @@ package net.jitse.npclib.nms.v1_8_R3.packets; import com.comphenix.tinyprotocol.Reflection; import com.mojang.authlib.GameProfile; -import net.jitse.npclib.api.wrapper.GameProfileWrapper; import net.minecraft.server.v1_8_R3.IChatBaseComponent; import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo; import net.minecraft.server.v1_8_R3.WorldSettings; @@ -18,9 +17,7 @@ import java.util.List; */ public class PacketPlayOutPlayerInfoWrapper { - public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfileWrapper gameProfileWrapper, String name) { - GameProfile gameProfile = (GameProfile) gameProfileWrapper.getGameProfile(); - + public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfile gameProfile, String name) { PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo(); Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class) .set(packetPlayOutPlayerInfo, action); diff --git a/nms/v1_9_R1/pom.xml b/nms/v1_9_R1/pom.xml index fa28961..0cffcb2 100755 --- a/nms/v1_9_R1/pom.xml +++ b/nms/v1_9_R1/pom.xml @@ -3,11 +3,12 @@ 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"> 4.0.0 + jar net.jitse npclib-nms - 1.5-SNAPSHOT + 2.0-SNAPSHOT npclib-nms-v1_9_R1 diff --git a/nms/v1_9_R1/src/main/java/net/jitse/npclib/nms/v1_9_R1/NPC_v1_9_R1.java b/nms/v1_9_R1/src/main/java/net/jitse/npclib/nms/v1_9_R1/NPC_v1_9_R1.java index dd89e26..1bb2f2e 100755 --- a/nms/v1_9_R1/src/main/java/net/jitse/npclib/nms/v1_9_R1/NPC_v1_9_R1.java +++ b/nms/v1_9_R1/src/main/java/net/jitse/npclib/nms/v1_9_R1/NPC_v1_9_R1.java @@ -4,25 +4,25 @@ package net.jitse.npclib.nms.v1_9_R1; -import net.jitse.npclib.api.NPC; -import net.jitse.npclib.nms.holograms.Hologram; +import net.jitse.npclib.NPCLib; +import net.jitse.npclib.hologram.Hologram; +import net.jitse.npclib.internal.MinecraftVersion; +import net.jitse.npclib.internal.SimpleNPC; import net.jitse.npclib.nms.v1_9_R1.packets.PacketPlayOutEntityHeadRotationWrapper; import net.jitse.npclib.nms.v1_9_R1.packets.PacketPlayOutNamedEntitySpawnWrapper; import net.jitse.npclib.nms.v1_9_R1.packets.PacketPlayOutPlayerInfoWrapper; import net.jitse.npclib.nms.v1_9_R1.packets.PacketPlayOutScoreboardTeamWrapper; -import net.jitse.npclib.skin.Skin; import net.minecraft.server.v1_9_R1.*; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; import java.util.List; /** * @author Jitse Boonstra */ -public class NPC_v1_9_R1 extends NPC { +public class NPC_v1_9_R1 extends SimpleNPC { private Hologram hologram; private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn; @@ -31,16 +31,15 @@ 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 lines) { - super(plugin, skin, autoHideDistance, lines); + public NPC_v1_9_R1(NPCLib instance, List lines) { + super(instance, lines); } @Override public void createPackets() { this.hologram = new Hologram(location.clone().subtract(0, 0.5, 0), lines); - hologram.generatePackets(false, false); + hologram.generatePackets(MinecraftVersion.V1_9_R1); - this.gameProfile = generateGameProfile(uuid, name); PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper(); // Packets for spawning the NPC: @@ -80,7 +79,7 @@ public class NPC_v1_9_R1 extends NPC { hologram.spawn(player); - Bukkit.getScheduler().runTaskLater(plugin, () -> + Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () -> playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50); } @@ -95,7 +94,7 @@ public class NPC_v1_9_R1 extends NPC { if (scheduler) { // Sending this a bit later so the player doesn't see the name (for that split second). - Bukkit.getScheduler().runTaskLater(plugin, () -> + Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () -> playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5); } else { playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister); diff --git a/nms/v1_9_R1/src/main/java/net/jitse/npclib/nms/v1_9_R1/packets/PacketPlayOutPlayerInfoWrapper.java b/nms/v1_9_R1/src/main/java/net/jitse/npclib/nms/v1_9_R1/packets/PacketPlayOutPlayerInfoWrapper.java index 0f9a478..43695c7 100755 --- a/nms/v1_9_R1/src/main/java/net/jitse/npclib/nms/v1_9_R1/packets/PacketPlayOutPlayerInfoWrapper.java +++ b/nms/v1_9_R1/src/main/java/net/jitse/npclib/nms/v1_9_R1/packets/PacketPlayOutPlayerInfoWrapper.java @@ -6,7 +6,6 @@ package net.jitse.npclib.nms.v1_9_R1.packets; import com.comphenix.tinyprotocol.Reflection; import com.mojang.authlib.GameProfile; -import net.jitse.npclib.api.wrapper.GameProfileWrapper; import net.minecraft.server.v1_9_R1.IChatBaseComponent; import net.minecraft.server.v1_9_R1.PacketPlayOutPlayerInfo; import net.minecraft.server.v1_9_R1.WorldSettings; @@ -19,9 +18,7 @@ import java.util.List; */ public class PacketPlayOutPlayerInfoWrapper { - public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfileWrapper gameProfileWrapper, String name) { - GameProfile gameProfile = (GameProfile) gameProfileWrapper.getGameProfile(); - + public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfile gameProfile, String name) { PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo(); Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class) .set(packetPlayOutPlayerInfo, action); diff --git a/nms/v1_9_R2/pom.xml b/nms/v1_9_R2/pom.xml index 715dd5c..67f0adf 100755 --- a/nms/v1_9_R2/pom.xml +++ b/nms/v1_9_R2/pom.xml @@ -3,11 +3,12 @@ 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"> 4.0.0 + jar net.jitse npclib-nms - 1.5-SNAPSHOT + 2.0-SNAPSHOT npclib-nms-v1_9_R2 diff --git a/nms/v1_9_R2/src/main/java/net/jitse/npclib/nms/v1_9_R2/NPC_v1_9_R2.java b/nms/v1_9_R2/src/main/java/net/jitse/npclib/nms/v1_9_R2/NPC_v1_9_R2.java index d254033..550af84 100755 --- a/nms/v1_9_R2/src/main/java/net/jitse/npclib/nms/v1_9_R2/NPC_v1_9_R2.java +++ b/nms/v1_9_R2/src/main/java/net/jitse/npclib/nms/v1_9_R2/NPC_v1_9_R2.java @@ -4,25 +4,25 @@ package net.jitse.npclib.nms.v1_9_R2; -import net.jitse.npclib.api.NPC; -import net.jitse.npclib.nms.holograms.Hologram; +import net.jitse.npclib.NPCLib; +import net.jitse.npclib.hologram.Hologram; +import net.jitse.npclib.internal.MinecraftVersion; +import net.jitse.npclib.internal.SimpleNPC; import net.jitse.npclib.nms.v1_9_R2.packets.PacketPlayOutEntityHeadRotationWrapper; import net.jitse.npclib.nms.v1_9_R2.packets.PacketPlayOutNamedEntitySpawnWrapper; import net.jitse.npclib.nms.v1_9_R2.packets.PacketPlayOutPlayerInfoWrapper; import net.jitse.npclib.nms.v1_9_R2.packets.PacketPlayOutScoreboardTeamWrapper; -import net.jitse.npclib.skin.Skin; import net.minecraft.server.v1_9_R2.*; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; import java.util.List; /** * @author Jitse Boonstra */ -public class NPC_v1_9_R2 extends NPC { +public class NPC_v1_9_R2 extends SimpleNPC { private Hologram hologram; private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn; @@ -31,16 +31,15 @@ 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 lines) { - super(plugin, skin, autoHideDistance, lines); + public NPC_v1_9_R2(NPCLib instance, List lines) { + super(instance, lines); } @Override public void createPackets() { this.hologram = new Hologram(location.clone().subtract(0, 0.5, 0), lines); - hologram.generatePackets(false, false); + hologram.generatePackets(MinecraftVersion.V1_9_R2); - this.gameProfile = generateGameProfile(uuid, name); PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper(); // Packets for spawning the NPC: @@ -80,7 +79,7 @@ public class NPC_v1_9_R2 extends NPC { hologram.spawn(player); - Bukkit.getScheduler().runTaskLater(plugin, () -> + Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () -> playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50); } @@ -95,7 +94,7 @@ public class NPC_v1_9_R2 extends NPC { if (scheduler) { // Sending this a bit later so the player doesn't see the name (for that split second). - Bukkit.getScheduler().runTaskLater(plugin, () -> + Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () -> playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5); } else { playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister); diff --git a/nms/v1_9_R2/src/main/java/net/jitse/npclib/nms/v1_9_R2/packets/PacketPlayOutPlayerInfoWrapper.java b/nms/v1_9_R2/src/main/java/net/jitse/npclib/nms/v1_9_R2/packets/PacketPlayOutPlayerInfoWrapper.java index 6ba09e6..67afd64 100755 --- a/nms/v1_9_R2/src/main/java/net/jitse/npclib/nms/v1_9_R2/packets/PacketPlayOutPlayerInfoWrapper.java +++ b/nms/v1_9_R2/src/main/java/net/jitse/npclib/nms/v1_9_R2/packets/PacketPlayOutPlayerInfoWrapper.java @@ -6,7 +6,6 @@ package net.jitse.npclib.nms.v1_9_R2.packets; import com.comphenix.tinyprotocol.Reflection; import com.mojang.authlib.GameProfile; -import net.jitse.npclib.api.wrapper.GameProfileWrapper; import net.minecraft.server.v1_9_R2.IChatBaseComponent; import net.minecraft.server.v1_9_R2.PacketPlayOutPlayerInfo; import net.minecraft.server.v1_9_R2.WorldSettings; @@ -24,9 +23,7 @@ public class PacketPlayOutPlayerInfoWrapper { private final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClazz, packetPlayOutPlayerInfoClazz, GameProfile.class, int.class, WorldSettings.EnumGamemode.class, IChatBaseComponent.class); - public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfileWrapper gameProfileWrapper, String name) { - GameProfile gameProfile = (GameProfile) gameProfileWrapper.getGameProfile(); - + public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfile gameProfile, String name) { PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo(); Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class) .set(packetPlayOutPlayerInfo, action); diff --git a/plugin/pom.xml b/plugin/pom.xml old mode 100755 new mode 100644 index 4cbace7..e6b20ae --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -3,15 +3,97 @@ 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"> 4.0.0 + jar net.jitse npclib - 1.5-SNAPSHOT + 2.0-SNAPSHOT npclib-plugin + + + org.spigotmc + spigot-api + 1.14.4-R0.1-SNAPSHOT + provided + + + net.jitse + npclib-api + ${project.version} + compile + + + net.jitse + npclib-nms-v1_8_R1 + ${project.version} + compile + + + net.jitse + npclib-nms-v1_8_R2 + ${project.version} + compile + + + net.jitse + npclib-nms-v1_8_R3 + ${project.version} + compile + + + net.jitse + npclib-nms-v1_9_R1 + ${project.version} + compile + + + net.jitse + npclib-nms-v1_9_R2 + ${project.version} + compile + + + net.jitse + npclib-nms-v1_10_R1 + ${project.version} + compile + + + net.jitse + npclib-nms-v1_11_R1 + ${project.version} + compile + + + net.jitse + npclib-nms-v1_12_R1 + ${project.version} + compile + + + net.jitse + npclib-nms-v1_13_R1 + ${project.version} + compile + + + net.jitse + npclib-nms-v1_13_R2 + ${project.version} + compile + + + net.jitse + npclib-nms-v1_14_R1 + ${project.version} + compile + + + @@ -23,14 +105,20 @@ + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + + package + + shade + + + + + - - - - ${project.parent.groupId} - npclib-api - ${project.parent.version} - compile - - - + \ No newline at end of file diff --git a/plugin/src/main/java/net/jitse/npclib/plugin/NPCLibPlugin.java b/plugin/src/main/java/net/jitse/npclib/plugin/NPCLibPlugin.java old mode 100755 new mode 100644 index a7151b8..f7c5c27 --- a/plugin/src/main/java/net/jitse/npclib/plugin/NPCLibPlugin.java +++ b/plugin/src/main/java/net/jitse/npclib/plugin/NPCLibPlugin.java @@ -6,18 +6,10 @@ package net.jitse.npclib.plugin; import org.bukkit.plugin.java.JavaPlugin; -/** - * @author Jitse Boonstra - */ public class NPCLibPlugin extends JavaPlugin { @Override public void onEnable() { getLogger().info("NPCLib classes loaded"); } - - @Override - public void onDisable() { - getLogger().info("NPCLib classes unloaded"); - } } diff --git a/plugin/src/main/resources/plugin.yml b/plugin/src/main/resources/plugin.yml old mode 100755 new mode 100644 index 30f6853..1e9d20c --- a/plugin/src/main/resources/plugin.yml +++ b/plugin/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ -name: NPCLib-Plugin +name: NPCLibPlugin version: ${project.parent.version} author: JitseB -main: net.jitse.npclib.plugin.NPCLibPlugin -description: Basic non-player character library. \ No newline at end of file +description: Dummy plugin for easy class-loading. +main: net.jitse.npclib.plugin.NPCLibPlugin \ No newline at end of file diff --git a/pom.xml b/pom.xml index 51b6546..1638f8f 100755 --- a/pom.xml +++ b/pom.xml @@ -2,19 +2,20 @@ - 4.0.0 pom net.jitse npclib - 1.5-SNAPSHOT + 2.0-SNAPSHOT - - git@github.com:JitseB/NPCLib.git - scm:git:git@github.com:JitseB/NPClib.git - scm:git:git@github.com:JitseB/NPCLib.git - + + UTF-8 + + + NPCLib + https://github.com/JitseB/NPCLib + Basic non-player character library for Minecraft. @@ -23,13 +24,25 @@ - NPCLib - https://github.com/JitseB/NPCLib - Basic non-player character library for Minecraft. + + + MIT + https://opensource.org/licenses/MIT + repo + + - - UTF-8 - + + api + nms + plugin + + + + git@github.com:JitseB/NPCLib.git + scm:git:git@github.com:JitseB/NPClib.git + scm:git:git@github.com:JitseB/NPCLib.git + @@ -42,34 +55,21 @@ - - - MIT - https://opensource.org/licenses/MIT - repo - - - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - - - - - org.spigotmc - spigot-api - 1.13.2-R0.1-SNAPSHOT - provided - - - - clean install + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + org.apache.maven.plugins maven-compiler-plugin @@ -82,6 +82,7 @@ org.apache.maven.plugins maven-gpg-plugin + 1.5 sign-artifacts @@ -105,19 +106,4 @@ - - - commons - nms/v1_8_R1 - nms/v1_8_R2 - nms/v1_8_R3 - nms/v1_9_R1 - nms/v1_9_R2 - nms/v1_10_R1 - nms/v1_11_R1 - nms/v1_12_R1 - nms/v1_13_R1 - nms/v1_13_R2 - plugin - \ No newline at end of file