Browse Source

Updated the library.

master
Jitse Boonstra 3 years ago
parent
commit
e0752c5d7e
68 changed files with 1115 additions and 695 deletions
  1. +53
    -0
      api/pom.xml
  2. +4
    -0
      api/src/main/java/com/comphenix/tinyprotocol/Reflection.java
  3. +24
    -23
      api/src/main/java/com/comphenix/tinyprotocol/TinyProtocol.java
  4. +113
    -0
      api/src/main/java/net/jitse/npclib/NPCLib.java
  5. +83
    -0
      api/src/main/java/net/jitse/npclib/api/NPC.java
  6. +11
    -8
      api/src/main/java/net/jitse/npclib/api/events/NPCHideEvent.java
  7. +5
    -2
      api/src/main/java/net/jitse/npclib/api/events/NPCInteractEvent.java
  8. +10
    -9
      api/src/main/java/net/jitse/npclib/api/events/NPCShowEvent.java
  9. +1
    -1
      api/src/main/java/net/jitse/npclib/api/skin/MineSkinFetcher.java
  10. +1
    -4
      api/src/main/java/net/jitse/npclib/api/skin/Skin.java
  11. +46
    -0
      api/src/main/java/net/jitse/npclib/api/utilities/Logger.java
  12. +26
    -20
      api/src/main/java/net/jitse/npclib/hologram/Hologram.java
  13. +15
    -0
      api/src/main/java/net/jitse/npclib/internal/MinecraftVersion.java
  14. +5
    -7
      api/src/main/java/net/jitse/npclib/internal/NPCManager.java
  15. +1
    -1
      api/src/main/java/net/jitse/npclib/internal/PacketHandler.java
  16. +59
    -42
      api/src/main/java/net/jitse/npclib/internal/SimpleNPC.java
  17. +12
    -5
      api/src/main/java/net/jitse/npclib/listeners/ChunkListener.java
  18. +13
    -12
      api/src/main/java/net/jitse/npclib/listeners/PacketListener.java
  19. +13
    -6
      api/src/main/java/net/jitse/npclib/listeners/PlayerListener.java
  20. +0
    -51
      commons/pom.xml
  21. +0
    -120
      commons/src/main/java/net/jitse/npclib/NPCLib.java
  22. +0
    -17
      commons/src/main/java/net/jitse/npclib/api/ActionHandler.java
  23. +0
    -21
      commons/src/main/java/net/jitse/npclib/api/packet/NPCPacket.java
  24. +0
    -56
      commons/src/main/java/net/jitse/npclib/api/wrapper/GameProfileWrapper.java
  25. +0
    -13
      commons/src/main/java/net/jitse/npclib/events/click/ClickType.java
  26. +0
    -13
      commons/src/main/java/net/jitse/npclib/events/trigger/TriggerType.java
  27. +0
    -26
      commons/src/main/java/net/jitse/npclib/logging/NPCLibLogger.java
  28. +38
    -0
      nms/pom.xml
  29. +2
    -1
      nms/v1_10_R1/pom.xml
  30. +10
    -11
      nms/v1_10_R1/src/main/java/net/jitse/npclib/nms/v1_10_R1/NPC_v1_10_R1.java
  31. +1
    -4
      nms/v1_10_R1/src/main/java/net/jitse/npclib/nms/v1_10_R1/packets/PacketPlayOutPlayerInfoWrapper.java
  32. +2
    -1
      nms/v1_11_R1/pom.xml
  33. +10
    -11
      nms/v1_11_R1/src/main/java/net/jitse/npclib/nms/v1_11_R1/NPC_v1_11_R1.java
  34. +1
    -4
      nms/v1_11_R1/src/main/java/net/jitse/npclib/nms/v1_11_R1/packets/PacketPlayOutPlayerInfoWrapper.java
  35. +2
    -1
      nms/v1_12_R1/pom.xml
  36. +10
    -12
      nms/v1_12_R1/src/main/java/net/jitse/npclib/nms/v1_12_R1/NPC_v1_12_R1.java
  37. +1
    -4
      nms/v1_12_R1/src/main/java/net/jitse/npclib/nms/v1_12_R1/packets/PacketPlayOutPlayerInfoWrapper.java
  38. +2
    -1
      nms/v1_13_R1/pom.xml
  39. +10
    -12
      nms/v1_13_R1/src/main/java/net/jitse/npclib/nms/v1_13_R1/NPC_v1_13_R1.java
  40. +1
    -4
      nms/v1_13_R1/src/main/java/net/jitse/npclib/nms/v1_13_R1/packets/PacketPlayOutPlayerInfoWrapper.java
  41. +2
    -1
      nms/v1_13_R2/pom.xml
  42. +10
    -11
      nms/v1_13_R2/src/main/java/net/jitse/npclib/nms/v1_13_R2/NPC_v1_13_R2.java
  43. +1
    -4
      nms/v1_13_R2/src/main/java/net/jitse/npclib/nms/v1_13_R2/packets/PacketPlayOutPlayerInfoWrapper.java
  44. +24
    -0
      nms/v1_14_R1/pom.xml
  45. +99
    -0
      nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/NPC_v1_14_R1.java
  46. +26
    -0
      nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutEntityHeadRotationWrapper.java
  47. +47
    -0
      nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutNamedEntitySpawnWrapper.java
  48. +43
    -0
      nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutPlayerInfoWrapper.java
  49. +53
    -0
      nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutScoreboardTeamWrapper.java
  50. +20
    -1
      nms/v1_8_R1/pom.xml
  51. +10
    -11
      nms/v1_8_R1/src/main/java/net/jitse/npclib/nms/v1_8_R1/NPC_v1_8_R1.java
  52. +1
    -4
      nms/v1_8_R1/src/main/java/net/jitse/npclib/nms/v1_8_R1/packets/PacketPlayOutPlayerInfoWrapper.java
  53. +2
    -1
      nms/v1_8_R2/pom.xml
  54. +10
    -11
      nms/v1_8_R2/src/main/java/net/jitse/npclib/nms/v1_8_R2/NPC_v1_8_R2.java
  55. +1
    -4
      nms/v1_8_R2/src/main/java/net/jitse/npclib/nms/v1_8_R2/packets/PacketPlayOutPlayerInfoWrapper.java
  56. +2
    -1
      nms/v1_8_R3/pom.xml
  57. +10
    -11
      nms/v1_8_R3/src/main/java/net/jitse/npclib/nms/v1_8_R3/NPC_v1_8_R3.java
  58. +1
    -4
      nms/v1_8_R3/src/main/java/net/jitse/npclib/nms/v1_8_R3/packets/PacketPlayOutPlayerInfoWrapper.java
  59. +2
    -1
      nms/v1_9_R1/pom.xml
  60. +10
    -11
      nms/v1_9_R1/src/main/java/net/jitse/npclib/nms/v1_9_R1/NPC_v1_9_R1.java
  61. +1
    -4
      nms/v1_9_R1/src/main/java/net/jitse/npclib/nms/v1_9_R1/packets/PacketPlayOutPlayerInfoWrapper.java
  62. +2
    -1
      nms/v1_9_R2/pom.xml
  63. +10
    -11
      nms/v1_9_R2/src/main/java/net/jitse/npclib/nms/v1_9_R2/NPC_v1_9_R2.java
  64. +1
    -4
      nms/v1_9_R2/src/main/java/net/jitse/npclib/nms/v1_9_R2/packets/PacketPlayOutPlayerInfoWrapper.java
  65. +99
    -11
      plugin/pom.xml
  66. +0
    -8
      plugin/src/main/java/net/jitse/npclib/plugin/NPCLibPlugin.java
  67. +3
    -3
      plugin/src/main/resources/plugin.yml
  68. +40
    -54
      pom.xml

+ 53
- 0
api/pom.xml View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<parent>
<artifactId>npclib</artifactId>
<groupId>net.jitse</groupId>
<version>2.0-SNAPSHOT</version>
</parent>
<artifactId>npclib-api</artifactId>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>minecraft-repo</id>
<url>https://libraries.minecraft.net</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.14.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.14.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
<version>1.5.21</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.33.Final</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

commons/src/main/java/com/comphenix/tinyprotocol/Reflection.java → api/src/main/java/com/comphenix/tinyprotocol/Reflection.java View File


commons/src/main/java/com/comphenix/tinyprotocol/TinyProtocol.java → api/src/main/java/com/comphenix/tinyprotocol/TinyProtocol.java View File


+ 113
- 0
api/src/main/java/net/jitse/npclib/NPCLib.java View File

@ -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<String> 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);
}
}

+ 83
- 0
api/src/main/java/net/jitse/npclib/api/NPC.java View File

@ -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();
}

commons/src/main/java/net/jitse/npclib/events/NPCSpawnEvent.java → api/src/main/java/net/jitse/npclib/api/events/NPCHideEvent.java View File


commons/src/main/java/net/jitse/npclib/events/NPCInteractEvent.java → api/src/main/java/net/jitse/npclib/api/events/NPCInteractEvent.java View File


commons/src/main/java/net/jitse/npclib/events/NPCDestroyEvent.java → api/src/main/java/net/jitse/npclib/api/events/NPCShowEvent.java View File


commons/src/main/java/net/jitse/npclib/skin/MineSkinFetcher.java → api/src/main/java/net/jitse/npclib/api/skin/MineSkinFetcher.java View File


commons/src/main/java/net/jitse/npclib/skin/Skin.java → api/src/main/java/net/jitse/npclib/api/skin/Skin.java View File


+ 46
- 0
api/src/main/java/net/jitse/npclib/api/utilities/Logger.java View File

@ -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);
}
}

commons/src/main/java/net/jitse/npclib/nms/holograms/Hologram.java → api/src/main/java/net/jitse/npclib/hologram/Hologram.java View File


+ 15
- 0
api/src/main/java/net/jitse/npclib/internal/MinecraftVersion.java View File

@ -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();
}
}

commons/src/main/java/net/jitse/npclib/NPCManager.java → api/src/main/java/net/jitse/npclib/internal/NPCManager.java View File


commons/src/main/java/net/jitse/npclib/api/PacketHandler.java → api/src/main/java/net/jitse/npclib/internal/PacketHandler.java View File


commons/src/main/java/net/jitse/npclib/api/NPC.java → api/src/main/java/net/jitse/npclib/internal/SimpleNPC.java View File


commons/src/main/java/net/jitse/npclib/listeners/ChunkListener.java → api/src/main/java/net/jitse/npclib/listeners/ChunkListener.java View File


commons/src/main/java/net/jitse/npclib/listeners/PacketListener.java → api/src/main/java/net/jitse/npclib/listeners/PacketListener.java View File


commons/src/main/java/net/jitse/npclib/listeners/PlayerListener.java → api/src/main/java/net/jitse/npclib/listeners/PlayerListener.java View File


+ 0
- 51
commons/pom.xml View File

@ -1,51 +0,0 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib</artifactId>
<version>1.5-SNAPSHOT</version>
</parent>
<artifactId>npclib-commons</artifactId>
<!--
<build>
<resources>
<resource>
<targetPath>.</targetPath>
<directory>${basedir}/src/main/java/net/jitse/npclib</directory>
<filtering>true</filtering>
<includes>
<include>NPCLib.java</include>
</includes>
</resource>
</resources>
</build>
-->
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.33.Final</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

+ 0
- 120
commons/src/main/java/net/jitse/npclib/NPCLib.java View File

@ -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<String> 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<String> 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);
}
}

+ 0
- 17
commons/src/main/java/net/jitse/npclib/api/ActionHandler.java View File

@ -1,17 +0,0 @@
/*
* Copyright (c) 2018 Jitse Boonstra
*/
package net.jitse.npclib.api;
/**
* @author Jitse Boonstra
*/
public interface ActionHandler {
// void toggleSleep(Supplier<Set<Player>> visible);
//
// void toggleShift(Supplier<Set<Player>> visible);
//
// void toggleWatching(Player player, Supplier<Set<Player>> visible);
}

+ 0
- 21
commons/src/main/java/net/jitse/npclib/api/packet/NPCPacket.java View File

@ -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();
}

+ 0
- 56
commons/src/main/java/net/jitse/npclib/api/wrapper/GameProfileWrapper.java View File

@ -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;
}
}

+ 0
- 13
commons/src/main/java/net/jitse/npclib/events/click/ClickType.java View File

@ -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
}

+ 0
- 13
commons/src/main/java/net/jitse/npclib/events/trigger/TriggerType.java View File

@ -1,13 +0,0 @@
/*
* Copyright (c) 2018 Jitse Boonstra
*/
package net.jitse.npclib.events.trigger;
/**
* @author Jitse Boonstra
*/
public enum TriggerType {
MANUAL, AUTOMATIC
}

+ 0
- 26
commons/src/main/java/net/jitse/npclib/logging/NPCLibLogger.java View File

@ -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);
}
}

+ 38
- 0
nms/pom.xml View File

@ -0,0 +1,38 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib</artifactId>
<version>2.0-SNAPSHOT</version>
</parent>
<artifactId>npclib-nms</artifactId>
<modules>
<module>v1_8_R1</module>
<module>v1_8_R2</module>
<module>v1_8_R3</module>
<module>v1_9_R1</module>
<module>v1_9_R2</module>
<module>v1_10_R1</module>
<module>v1_11_R1</module>
<module>v1_12_R1</module>
<module>v1_13_R1</module>
<module>v1_13_R2</module>
<module>v1_14_R1</module>
</modules>
<dependencies>
<dependency>
<groupId>net.jitse</groupId>
<artifactId>npclib-api</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

+ 2
- 1
nms/v1_10_R1/pom.xml View File

@ -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">
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>1.5-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
</parent>
<artifactId>npclib-nms-v1_10_R1</artifactId>


+ 10
- 11
nms/v1_10_R1/src/main/java/net/jitse/npclib/nms/v1_10_R1/NPC_v1_10_R1.java View File

@ -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<String> lines) {
super(plugin, skin, autoHideDistance, lines);
public NPC_v1_10_R1(NPCLib instance, List<String> 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);


+ 1
- 4
nms/v1_10_R1/src/main/java/net/jitse/npclib/nms/v1_10_R1/packets/PacketPlayOutPlayerInfoWrapper.java View File

@ -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);


+ 2
- 1
nms/v1_11_R1/pom.xml View File

@ -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">
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>1.5-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
</parent>
<artifactId>npclib-nms-v1_11_R1</artifactId>


+ 10
- 11
nms/v1_11_R1/src/main/java/net/jitse/npclib/nms/v1_11_R1/NPC_v1_11_R1.java View File

@ -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<String> lines) {
super(plugin, skin, autoHideDistance, lines);
public NPC_v1_11_R1(NPCLib instance, List<String> 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);


+ 1
- 4
nms/v1_11_R1/src/main/java/net/jitse/npclib/nms/v1_11_R1/packets/PacketPlayOutPlayerInfoWrapper.java View File

@ -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);


+ 2
- 1
nms/v1_12_R1/pom.xml View File

@ -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">
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>1.5-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
</parent>
<artifactId>npclib-nms-v1_12_R1</artifactId>


+ 10
- 12
nms/v1_12_R1/src/main/java/net/jitse/npclib/nms/v1_12_R1/NPC_v1_12_R1.java View File

@ -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<String> lines) {
super(plugin, skin, autoHideDistance, lines);
public NPC_v1_12_R1(NPCLib instance, List<String> 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);


+ 1
- 4
nms/v1_12_R1/src/main/java/net/jitse/npclib/nms/v1_12_R1/packets/PacketPlayOutPlayerInfoWrapper.java View File

@ -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);


+ 2
- 1
nms/v1_13_R1/pom.xml View File

@ -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">
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>1.5-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
</parent>
<artifactId>npclib-nms-v1_13_R1</artifactId>


+ 10
- 12
nms/v1_13_R1/src/main/java/net/jitse/npclib/nms/v1_13_R1/NPC_v1_13_R1.java View File

@ -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<String> lines) {
super(plugin, skin, autoHideDistance, lines);
public NPC_v1_13_R1(NPCLib instance, List<String> 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);


+ 1
- 4
nms/v1_13_R1/src/main/java/net/jitse/npclib/nms/v1_13_R1/packets/PacketPlayOutPlayerInfoWrapper.java View File

@ -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);


+ 2
- 1
nms/v1_13_R2/pom.xml View File

@ -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">
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>1.5-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
</parent>
<artifactId>npclib-nms-v1_13_R2</artifactId>


+ 10
- 11
nms/v1_13_R2/src/main/java/net/jitse/npclib/nms/v1_13_R2/NPC_v1_13_R2.java View File

@ -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<String> lines) {
super(plugin, skin, autoHideDistance, lines);
public NPC_v1_13_R2(NPCLib instance, List<String> 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);


+ 1
- 4
nms/v1_13_R2/src/main/java/net/jitse/npclib/nms/v1_13_R2/packets/PacketPlayOutPlayerInfoWrapper.java View File

@ -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);


+ 24
- 0
nms/v1_14_R1/pom.xml View File

@ -0,0 +1,24 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>2.0-SNAPSHOT</version>
</parent>
<artifactId>npclib-nms-v1_14_R1</artifactId>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.14.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

+ 99
- 0
nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/NPC_v1_14_R1.java View File

@ -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<String> 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);
}
}
}

+ 26
- 0
nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutEntityHeadRotationWrapper.java View File

@ -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;
}
}

+ 47
- 0
nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutNamedEntitySpawnWrapper.java View File

@ -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;
}
}

+ 43
- 0
nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutPlayerInfoWrapper.java View File

@ -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
<