Updated the library.
This commit is contained in:
parent
b8a7dcaddb
commit
e0752c5d7e
|
@ -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>
|
|
@ -1,3 +1,7 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018 Jitse Boonstra
|
||||||
|
*/
|
||||||
|
|
||||||
package com.comphenix.tinyprotocol;
|
package com.comphenix.tinyprotocol;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
|
@ -1,11 +1,13 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018 Jitse Boonstra
|
||||||
|
*/
|
||||||
|
|
||||||
package com.comphenix.tinyprotocol;
|
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.Lists;
|
||||||
import com.google.common.collect.MapMaker;
|
import com.google.common.collect.MapMaker;
|
||||||
import io.netty.channel.*;
|
import io.netty.channel.*;
|
||||||
import net.jitse.npclib.logging.NPCLibLogger;
|
import net.jitse.npclib.NPCLib;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
@ -19,8 +21,6 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
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.
|
* 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);
|
private static final AtomicInteger ID = new AtomicInteger(0);
|
||||||
|
|
||||||
// Used in order to lookup a channel
|
// Used in order to lookup a channel
|
||||||
private static final MethodInvoker getPlayerHandle = Reflection.getMethod("{obc}.entity.CraftPlayer", "getHandle");
|
private static final Reflection.MethodInvoker getPlayerHandle = Reflection.getMethod("{obc}.entity.CraftPlayer", "getHandle");
|
||||||
private static final FieldAccessor<Object> getConnection = Reflection.getField("{nms}.EntityPlayer", "playerConnection", Object.class);
|
private static final Reflection.FieldAccessor<Object> getConnection = Reflection.getField("{nms}.EntityPlayer", "playerConnection", Object.class);
|
||||||
private static final FieldAccessor<Object> getManager = Reflection.getField("{nms}.PlayerConnection", "networkManager", Object.class);
|
private static final Reflection.FieldAccessor<Object> getManager = Reflection.getField("{nms}.PlayerConnection", "networkManager", Object.class);
|
||||||
private static final FieldAccessor<Channel> getChannel = Reflection.getField("{nms}.NetworkManager", Channel.class, 0);
|
private static final Reflection.FieldAccessor<Channel> getChannel = Reflection.getField("{nms}.NetworkManager", Channel.class, 0);
|
||||||
|
|
||||||
// Looking up ServerConnection
|
// Looking up ServerConnection
|
||||||
private static final Class<Object> minecraftServerClass = Reflection.getUntypedClass("{nms}.MinecraftServer");
|
private static final Class<Object> minecraftServerClass = Reflection.getUntypedClass("{nms}.MinecraftServer");
|
||||||
private static final Class<Object> serverConnectionClass = Reflection.getUntypedClass("{nms}.ServerConnection");
|
private static final Class<Object> serverConnectionClass = Reflection.getUntypedClass("{nms}.ServerConnection");
|
||||||
private static final FieldAccessor<Object> getMinecraftServer = Reflection.getField("{obc}.CraftServer", minecraftServerClass, 0);
|
private static final Reflection.FieldAccessor<Object> getMinecraftServer = Reflection.getField("{obc}.CraftServer", minecraftServerClass, 0);
|
||||||
private static final FieldAccessor<Object> getServerConnection = Reflection.getField(minecraftServerClass, serverConnectionClass, 0);
|
private static final Reflection.FieldAccessor<Object> getServerConnection = Reflection.getField(minecraftServerClass, serverConnectionClass, 0);
|
||||||
private static final MethodInvoker getNetworkMarkers = Reflection.getTypedMethod(serverConnectionClass, null, List.class, serverConnectionClass);
|
private static final Reflection.MethodInvoker getNetworkMarkers = Reflection.getTypedMethod(serverConnectionClass, null, List.class, serverConnectionClass);
|
||||||
|
|
||||||
// Packets we have to intercept
|
// Packets we have to intercept
|
||||||
private static final Class<?> PACKET_LOGIN_IN_START = Reflection.getMinecraftClass("PacketLoginInStart");
|
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);
|
Reflection.getClass("com.mojang.authlib.GameProfile"), 0);
|
||||||
|
|
||||||
// Speedup channel lookup
|
// Speedup channel lookup
|
||||||
private Map<String, Channel> channelLookup = new MapMaker().weakValues().makeMap();
|
private Map<String, Channel> channelLookup = new MapMaker().weakValues().makeMap();
|
||||||
private Listener listener;
|
private Listener listener;
|
||||||
|
|
||||||
private Logger logger;
|
|
||||||
|
|
||||||
// Channels that have already been removed
|
// Channels that have already been removed
|
||||||
private Set<Channel> uninjectedChannels = Collections.newSetFromMap(new MapMaker().weakKeys().makeMap());
|
private Set<Channel> uninjectedChannels = Collections.newSetFromMap(new MapMaker().weakKeys().makeMap());
|
||||||
|
|
||||||
// List of network markers
|
// List of network markers
|
||||||
private List<Object> networkManagers;
|
private List<Object> networkManagers;
|
||||||
|
|
||||||
|
private final NPCLib instance;
|
||||||
|
|
||||||
// Injected channel handlers
|
// Injected channel handlers
|
||||||
private List<Channel> serverChannels = Lists.newArrayList();
|
private List<Channel> serverChannels = Lists.newArrayList();
|
||||||
private ChannelInboundHandlerAdapter serverChannelHandler;
|
private ChannelInboundHandlerAdapter serverChannelHandler;
|
||||||
|
@ -71,9 +71,9 @@ public abstract class TinyProtocol {
|
||||||
private volatile boolean closed;
|
private volatile boolean closed;
|
||||||
protected Plugin plugin;
|
protected Plugin plugin;
|
||||||
|
|
||||||
protected TinyProtocol(final Plugin plugin) {
|
protected TinyProtocol(NPCLib instance) {
|
||||||
this.plugin = plugin;
|
this.plugin = instance.getPlugin();
|
||||||
this.logger = new NPCLibLogger(plugin);
|
this.instance = instance;
|
||||||
|
|
||||||
// Compute handler name
|
// Compute handler name
|
||||||
this.handlerName = "tiny-" + plugin.getName() + "-" + ID.incrementAndGet();
|
this.handlerName = "tiny-" + plugin.getName() + "-" + ID.incrementAndGet();
|
||||||
|
@ -82,19 +82,19 @@ public abstract class TinyProtocol {
|
||||||
registerBukkitEvents();
|
registerBukkitEvents();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.info("Attempting to inject into netty");
|
instance.getLogger().info("Attempting to inject into netty");
|
||||||
registerChannelHandler();
|
registerChannelHandler();
|
||||||
registerPlayers(plugin);
|
registerPlayers(plugin);
|
||||||
} catch (IllegalArgumentException exception) {
|
} catch (IllegalArgumentException exception) {
|
||||||
// Damn you, late bind
|
// Damn you, late bind
|
||||||
logger.log(Level.WARNING, "Attempting to delay injection");
|
instance.getLogger().warning("Attempting to delay injection");
|
||||||
|
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
registerChannelHandler();
|
registerChannelHandler();
|
||||||
registerPlayers(plugin);
|
registerPlayers(plugin);
|
||||||
logger.info("Injection complete");
|
instance.getLogger().info("Injection complete");
|
||||||
}
|
}
|
||||||
}.runTask(plugin);
|
}.runTask(plugin);
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,8 @@ public abstract class TinyProtocol {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception exception) {
|
} 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 {
|
try {
|
||||||
msg = onPacketInAsync(player, msg);
|
msg = onPacketInAsync(player, msg);
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
logger.log(Level.SEVERE, "Error in onPacketInAsync()", exception);
|
instance.getLogger().severe("Error in onPacketInAsync(). Message: " + exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg != null) {
|
if (msg != null) {
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
|
@ -2,10 +2,9 @@
|
||||||
* Copyright (c) 2018 Jitse Boonstra
|
* 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.api.NPC;
|
||||||
import net.jitse.npclib.events.trigger.TriggerType;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
|
@ -14,7 +13,7 @@ import org.bukkit.event.HandlerList;
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
*/
|
*/
|
||||||
public class NPCSpawnEvent extends Event implements Cancellable {
|
public class NPCHideEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
@ -22,12 +21,12 @@ public class NPCSpawnEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
private final NPC npc;
|
private final NPC npc;
|
||||||
private final Player player;
|
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.npc = npc;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.trigger = trigger;
|
this.automatic = automatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -43,8 +42,11 @@ public class NPCSpawnEvent extends Event implements Cancellable {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TriggerType getTrigger() {
|
/**
|
||||||
return trigger;
|
* @return Value on whether the hiding was triggered automatically.
|
||||||
|
*/
|
||||||
|
public boolean isAutomatic() {
|
||||||
|
return automatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -60,3 +62,4 @@ public class NPCSpawnEvent extends Event implements Cancellable {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,9 @@
|
||||||
* Copyright (c) 2018 Jitse Boonstra
|
* 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.api.NPC;
|
||||||
import net.jitse.npclib.events.click.ClickType;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
@ -46,4 +45,8 @@ public class NPCInteractEvent extends Event {
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum ClickType {
|
||||||
|
LEFT_CLICK, RIGHT_CLICK
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -2,10 +2,9 @@
|
||||||
* Copyright (c) 2018 Jitse Boonstra
|
* 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.api.NPC;
|
||||||
import net.jitse.npclib.events.trigger.TriggerType;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
|
@ -14,7 +13,7 @@ import org.bukkit.event.HandlerList;
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
*/
|
*/
|
||||||
public class NPCDestroyEvent extends Event implements Cancellable {
|
public class NPCShowEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
@ -22,12 +21,12 @@ public class NPCDestroyEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
private final NPC npc;
|
private final NPC npc;
|
||||||
private final Player player;
|
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.npc = npc;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.trigger = trigger;
|
this.automatic = automatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -43,8 +42,11 @@ public class NPCDestroyEvent extends Event implements Cancellable {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TriggerType getTrigger() {
|
/**
|
||||||
return trigger;
|
* @return Value on whether the spawn was triggered automatically.
|
||||||
|
*/
|
||||||
|
public boolean isAutomatic() {
|
||||||
|
return automatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -60,4 +62,3 @@ public class NPCDestroyEvent extends Event implements Cancellable {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Copyright (c) 2018 Jitse Boonstra
|
* 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.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
5
commons/src/main/java/net/jitse/npclib/skin/Skin.java → api/src/main/java/net/jitse/npclib/api/skin/Skin.java
Executable file → Normal file
5
commons/src/main/java/net/jitse/npclib/skin/Skin.java → api/src/main/java/net/jitse/npclib/api/skin/Skin.java
Executable file → Normal file
|
@ -2,11 +2,8 @@
|
||||||
* Copyright (c) 2018 Jitse Boonstra
|
* Copyright (c) 2018 Jitse Boonstra
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.jitse.npclib.skin;
|
package net.jitse.npclib.api.skin;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Jitse Boonstra
|
|
||||||
*/
|
|
||||||
public class Skin {
|
public class Skin {
|
||||||
|
|
||||||
private final String value, signature;
|
private final String value, signature;
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
46
commons/src/main/java/net/jitse/npclib/nms/holograms/Hologram.java → api/src/main/java/net/jitse/npclib/hologram/Hologram.java
Executable file → Normal file
46
commons/src/main/java/net/jitse/npclib/nms/holograms/Hologram.java → api/src/main/java/net/jitse/npclib/hologram/Hologram.java
Executable file → Normal file
|
@ -2,9 +2,10 @@
|
||||||
* Copyright (c) 2018 Jitse Boonstra
|
* Copyright (c) 2018 Jitse Boonstra
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.jitse.npclib.nms.holograms;
|
package net.jitse.npclib.hologram;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import net.jitse.npclib.internal.MinecraftVersion;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -14,9 +15,6 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Jitse Boonstra
|
|
||||||
*/
|
|
||||||
public class Hologram {
|
public class Hologram {
|
||||||
|
|
||||||
private final double delta = 0.3;
|
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) {
|
public void generatePackets(MinecraftVersion version) {
|
||||||
Reflection.MethodInvoker gravityMethod = (above1_9_r2 ? Reflection.getMethod(ENTITY_CLAZZ,
|
Reflection.MethodInvoker gravityMethod = (version.isAboveOrEqual(MinecraftVersion.V1_9_R2) ?
|
||||||
"setNoGravity", boolean.class) : Reflection.getMethod(ENTITY_ARMOR_STAND_CLAZZ,
|
Reflection.getMethod(ENTITY_CLAZZ, "setNoGravity", boolean.class) :
|
||||||
"setGravity", boolean.class));
|
Reflection.getMethod(ENTITY_ARMOR_STAND_CLAZZ, "setGravity", boolean.class));
|
||||||
|
|
||||||
Reflection.MethodInvoker customNameMethod = (above_1_12_r1 ? Reflection.getMethod(ENTITY_CLAZZ,
|
Reflection.MethodInvoker customNameMethod = (version.isAboveOrEqual(MinecraftVersion.V1_12_R1) ?
|
||||||
"setCustomName", CHAT_BASE_COMPONENT_CLAZZ) : Reflection.getMethod(ENTITY_ARMOR_STAND_CLAZZ,
|
Reflection.getMethod(ENTITY_CLAZZ, "setCustomName", CHAT_BASE_COMPONENT_CLAZZ) :
|
||||||
"setCustomName", String.class));
|
Reflection.getMethod(ENTITY_ARMOR_STAND_CLAZZ, "setCustomName", String.class));
|
||||||
|
|
||||||
Reflection.MethodInvoker customNameVisibilityMethod = (above_1_12_r1 ? Reflection.getMethod(ENTITY_CLAZZ,
|
Reflection.MethodInvoker customNameVisibilityMethod = (version.isAboveOrEqual(MinecraftVersion.V1_12_R1) ?
|
||||||
"setCustomNameVisible", boolean.class) : Reflection.getMethod(ENTITY_ARMOR_STAND_CLAZZ,
|
Reflection.getMethod(ENTITY_CLAZZ, "setCustomNameVisible", boolean.class) :
|
||||||
"setCustomNameVisible", boolean.class));
|
Reflection.getMethod(ENTITY_ARMOR_STAND_CLAZZ, "setCustomNameVisible", boolean.class));
|
||||||
|
|
||||||
Location location = start.clone().add(0, delta * lines.size(), 0);
|
Location location = start.clone().add(0, delta * lines.size(), 0);
|
||||||
Class<?> worldClass = worldServer.getClass().getSuperclass();
|
Class<?> worldClass = worldServer.getClass().getSuperclass();
|
||||||
|
@ -104,16 +102,23 @@ public class Hologram {
|
||||||
worldClass = worldClass.getSuperclass();
|
worldClass = worldClass.getSuperclass();
|
||||||
}
|
}
|
||||||
|
|
||||||
Reflection.ConstructorInvoker entityArmorStandConstructor = Reflection
|
Reflection.ConstructorInvoker entityArmorStandConstructor = (version.isAboveOrEqual(MinecraftVersion.V1_14_R1) ?
|
||||||
.getConstructor(ENTITY_ARMOR_STAND_CLAZZ, worldClass);
|
Reflection.getConstructor(ENTITY_ARMOR_STAND_CLAZZ, worldClass, double.class, double.class, double.class) :
|
||||||
|
Reflection.getConstructor(ENTITY_ARMOR_STAND_CLAZZ, worldClass));
|
||||||
|
|
||||||
for (String line : lines) {
|
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));
|
||||||
|
|
||||||
SET_LOCATION_METHOD.invoke(entityArmorStand, location.getX(), location.getY(), location.getZ(), 0, 0);
|
if (!version.isAboveOrEqual(MinecraftVersion.V1_14_R1)) {
|
||||||
customNameMethod.invoke(entityArmorStand, above_1_12_r1 ? CHAT_COMPONENT_TEXT_CONSTRUCTOR.invoke(line) : line);
|
SET_LOCATION_METHOD.invoke(entityArmorStand, location.getX(), location.getY(), location.getZ(), 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
customNameMethod.invoke(entityArmorStand, version.isAboveOrEqual(MinecraftVersion.V1_12_R1) ?
|
||||||
|
CHAT_COMPONENT_TEXT_CONSTRUCTOR.invoke(line) : line);
|
||||||
customNameVisibilityMethod.invoke(entityArmorStand, true);
|
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_SMALL_METHOD.invoke(entityArmorStand, true);
|
||||||
SET_INVISIBLE_METHOD.invoke(entityArmorStand, true);
|
SET_INVISIBLE_METHOD.invoke(entityArmorStand, true);
|
||||||
SET_BASE_PLATE_METHOD.invoke(entityArmorStand, false);
|
SET_BASE_PLATE_METHOD.invoke(entityArmorStand, false);
|
||||||
|
@ -170,3 +175,4 @@ public class Hologram {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,9 +2,7 @@
|
||||||
* Copyright (c) 2018 Jitse Boonstra
|
* Copyright (c) 2018 Jitse Boonstra
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.jitse.npclib;
|
package net.jitse.npclib.internal;
|
||||||
|
|
||||||
import net.jitse.npclib.api.NPC;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -14,17 +12,17 @@ import java.util.Set;
|
||||||
*/
|
*/
|
||||||
public final class NPCManager {
|
public final class NPCManager {
|
||||||
|
|
||||||
private static Set<NPC> npcs = new HashSet<>();
|
private static Set<SimpleNPC> npcs = new HashSet<>();
|
||||||
|
|
||||||
public static Set<NPC> getAllNPCs() {
|
public static Set<SimpleNPC> getAllNPCs() {
|
||||||
return npcs;
|
return npcs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void add(NPC npc) {
|
public static void add(SimpleNPC npc) {
|
||||||
npcs.add(npc);
|
npcs.add(npc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void remove(NPC npc) {
|
public static void remove(SimpleNPC npc) {
|
||||||
npcs.remove(npc);
|
npcs.remove(npc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Copyright (c) 2018 Jitse Boonstra
|
* Copyright (c) 2018 Jitse Boonstra
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.jitse.npclib.api;
|
package net.jitse.npclib.internal;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
103
commons/src/main/java/net/jitse/npclib/api/NPC.java → api/src/main/java/net/jitse/npclib/internal/SimpleNPC.java
Executable file → Normal file
103
commons/src/main/java/net/jitse/npclib/api/NPC.java → api/src/main/java/net/jitse/npclib/internal/SimpleNPC.java
Executable file → Normal file
|
@ -2,65 +2,74 @@
|
||||||
* Copyright (c) 2018 Jitse Boonstra
|
* Copyright (c) 2018 Jitse Boonstra
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.jitse.npclib.api;
|
package net.jitse.npclib.internal;
|
||||||
|
|
||||||
import net.jitse.npclib.NPCManager;
|
import com.mojang.authlib.GameProfile;
|
||||||
import net.jitse.npclib.api.wrapper.GameProfileWrapper;
|
import com.mojang.authlib.properties.Property;
|
||||||
import net.jitse.npclib.events.NPCDestroyEvent;
|
import net.jitse.npclib.NPCLib;
|
||||||
import net.jitse.npclib.events.NPCSpawnEvent;
|
import net.jitse.npclib.api.NPC;
|
||||||
import net.jitse.npclib.events.trigger.TriggerType;
|
import net.jitse.npclib.api.events.NPCHideEvent;
|
||||||
import net.jitse.npclib.skin.Skin;
|
import net.jitse.npclib.api.events.NPCShowEvent;
|
||||||
|
import net.jitse.npclib.api.skin.Skin;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
public abstract class SimpleNPC implements NPC, PacketHandler {
|
||||||
* @author Jitse Boonstra
|
|
||||||
*/
|
|
||||||
public abstract class NPC implements PacketHandler, ActionHandler {
|
|
||||||
|
|
||||||
protected final UUID uuid = UUID.randomUUID();
|
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 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 final List<String> lines;
|
||||||
protected String name = uuid.toString().replace("-", "").substring(0, 10);
|
|
||||||
|
|
||||||
private final Set<UUID> shown = new HashSet<>();
|
private final Set<UUID> shown = new HashSet<>();
|
||||||
private final Set<UUID> autoHidden = new HashSet<>();
|
private final Set<UUID> autoHidden = new HashSet<>();
|
||||||
|
|
||||||
protected final double autoHideDistance;
|
protected double cosFOV = Math.cos(Math.toRadians(60));
|
||||||
protected final Skin skin;
|
|
||||||
protected final List<String> lines;
|
|
||||||
|
|
||||||
protected JavaPlugin plugin;
|
protected NPCLib instance;
|
||||||
protected GameProfileWrapper gameProfile;
|
|
||||||
protected Location location;
|
protected Location location;
|
||||||
|
protected Skin skin;
|
||||||
|
|
||||||
public NPC(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
public SimpleNPC(NPCLib instance, List<String> lines) {
|
||||||
this.plugin = plugin;
|
this.instance = instance;
|
||||||
this.skin = skin;
|
|
||||||
this.autoHideDistance = autoHideDistance;
|
|
||||||
this.lines = lines == null ? Collections.emptyList() : lines;
|
this.lines = lines == null ? Collections.emptyList() : lines;
|
||||||
|
|
||||||
NPCManager.add(this);
|
NPCManager.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected GameProfileWrapper generateGameProfile(UUID uuid, String name) {
|
protected GameProfile generateGameProfile(UUID uuid, String name) {
|
||||||
GameProfileWrapper gameProfile = new GameProfileWrapper(uuid, name);
|
GameProfile gameProfile = new GameProfile(uuid, name);
|
||||||
|
|
||||||
if (skin != null) {
|
if (skin != null) {
|
||||||
gameProfile.addSkin(skin);
|
gameProfile.getProperties().get("textures").clear();
|
||||||
|
gameProfile.getProperties().get("textures").add(new Property(skin.getValue(), skin.getSignature()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return gameProfile;
|
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() {
|
public void destroy() {
|
||||||
destroy(true);
|
destroy(true);
|
||||||
}
|
}
|
||||||
|
@ -83,7 +92,7 @@ public abstract class NPC implements PacketHandler, ActionHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFOV(double fov) {
|
public void setFOV(double fov) {
|
||||||
this.cosFOV = Math.cos(Math.toRadians(60));
|
this.cosFOV = Math.cos(Math.toRadians(fov));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<UUID> getShown() {
|
public Set<UUID> getShown() {
|
||||||
|
@ -94,35 +103,40 @@ public abstract class NPC implements PacketHandler, ActionHandler {
|
||||||
return autoHidden;
|
return autoHidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Location getLocation() {
|
public Location getLocation() {
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getAutoHideDistance() {
|
|
||||||
return autoHideDistance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getEntityId() {
|
public int getEntityId() {
|
||||||
return entityId;
|
return entityId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isActuallyShown(Player player) {
|
@Override
|
||||||
|
public boolean isShown(Player player) {
|
||||||
return shown.contains(player.getUniqueId()) && !autoHidden.contains(player.getUniqueId());
|
return shown.contains(player.getUniqueId()) && !autoHidden.contains(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void create(Location location) {
|
@Override
|
||||||
|
public NPC setLocation(Location location) {
|
||||||
this.location = location;
|
this.location = location;
|
||||||
|
return this;
|
||||||
createPackets();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC create() {
|
||||||
|
createPackets();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void show(Player player) {
|
public void show(Player player) {
|
||||||
show(player, false);
|
show(player, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void show(Player player, boolean auto) {
|
public void show(Player player, boolean auto) {
|
||||||
NPCSpawnEvent event = new NPCSpawnEvent(this, player, auto ? TriggerType.AUTOMATIC : TriggerType.MANUAL);
|
NPCShowEvent event = new NPCShowEvent(this, player, auto);
|
||||||
plugin.getServer().getPluginManager().callEvent(event);
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -139,7 +153,7 @@ public abstract class NPC implements PacketHandler, ActionHandler {
|
||||||
if (auto) {
|
if (auto) {
|
||||||
sendShowPackets(player);
|
sendShowPackets(player);
|
||||||
} else {
|
} else {
|
||||||
if (isActuallyShown(player)) {
|
if (isShown(player)) {
|
||||||
throw new RuntimeException("Cannot call show method twice.");
|
throw new RuntimeException("Cannot call show method twice.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +163,8 @@ public abstract class NPC implements PacketHandler, ActionHandler {
|
||||||
|
|
||||||
shown.add(player.getUniqueId());
|
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);
|
sendShowPackets(player);
|
||||||
} else {
|
} else {
|
||||||
autoHidden.add(player.getUniqueId());
|
autoHidden.add(player.getUniqueId());
|
||||||
|
@ -162,13 +177,14 @@ public abstract class NPC implements PacketHandler, ActionHandler {
|
||||||
return dir.dot(player.getLocation().getDirection()) >= cosFOV;
|
return dir.dot(player.getLocation().getDirection()) >= cosFOV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void hide(Player player) {
|
public void hide(Player player) {
|
||||||
hide(player, false, true);
|
hide(player, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hide(Player player, boolean auto, boolean scheduler) {
|
public void hide(Player player, boolean auto, boolean scheduler) {
|
||||||
NPCDestroyEvent event = new NPCDestroyEvent(this, player, auto ? TriggerType.AUTOMATIC : TriggerType.MANUAL);
|
NPCHideEvent event = new NPCHideEvent(this, player, auto);
|
||||||
plugin.getServer().getPluginManager().callEvent(event);
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -182,7 +198,8 @@ public abstract class NPC implements PacketHandler, ActionHandler {
|
||||||
|
|
||||||
shown.remove(player.getUniqueId());
|
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);
|
sendHidePackets(player, scheduler);
|
||||||
} else {
|
} else {
|
||||||
autoHidden.remove(player.getUniqueId());
|
autoHidden.remove(player.getUniqueId());
|
|
@ -4,8 +4,9 @@
|
||||||
|
|
||||||
package net.jitse.npclib.listeners;
|
package net.jitse.npclib.listeners;
|
||||||
|
|
||||||
import net.jitse.npclib.NPCManager;
|
import net.jitse.npclib.NPCLib;
|
||||||
import net.jitse.npclib.api.NPC;
|
import net.jitse.npclib.internal.NPCManager;
|
||||||
|
import net.jitse.npclib.internal.SimpleNPC;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -21,11 +22,17 @@ import java.util.UUID;
|
||||||
*/
|
*/
|
||||||
public class ChunkListener implements Listener {
|
public class ChunkListener implements Listener {
|
||||||
|
|
||||||
|
private final NPCLib instance;
|
||||||
|
|
||||||
|
public ChunkListener(NPCLib instance) {
|
||||||
|
this.instance = instance;
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onChunkUnload(ChunkUnloadEvent event) {
|
public void onChunkUnload(ChunkUnloadEvent event) {
|
||||||
Chunk chunk = event.getChunk();
|
Chunk chunk = event.getChunk();
|
||||||
|
|
||||||
for (NPC npc : NPCManager.getAllNPCs()) {
|
for (SimpleNPC npc : NPCManager.getAllNPCs()) {
|
||||||
Chunk npcChunk = npc.getLocation().getChunk();
|
Chunk npcChunk = npc.getLocation().getChunk();
|
||||||
|
|
||||||
if (chunk.equals(npcChunk)) {
|
if (chunk.equals(npcChunk)) {
|
||||||
|
@ -48,7 +55,7 @@ public class ChunkListener implements Listener {
|
||||||
public void onChunkLoad(ChunkLoadEvent event) {
|
public void onChunkLoad(ChunkLoadEvent event) {
|
||||||
Chunk chunk = event.getChunk();
|
Chunk chunk = event.getChunk();
|
||||||
|
|
||||||
for (NPC npc : NPCManager.getAllNPCs()) {
|
for (SimpleNPC npc : NPCManager.getAllNPCs()) {
|
||||||
Chunk npcChunk = npc.getLocation().getChunk();
|
Chunk npcChunk = npc.getLocation().getChunk();
|
||||||
|
|
||||||
if (chunk.equals(npcChunk)) {
|
if (chunk.equals(npcChunk)) {
|
||||||
|
@ -66,7 +73,7 @@ public class ChunkListener implements Listener {
|
||||||
continue; // Player and NPC are not in the same world.
|
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());
|
double distanceSquared = player.getLocation().distanceSquared(npc.getLocation());
|
||||||
boolean inRange = distanceSquared <= (hideDistance * hideDistance) || distanceSquared <= (Bukkit.getViewDistance() << 4);
|
boolean inRange = distanceSquared <= (hideDistance * hideDistance) || distanceSquared <= (Bukkit.getViewDistance() << 4);
|
||||||
|
|
|
@ -6,10 +6,10 @@ package net.jitse.npclib.listeners;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
import net.jitse.npclib.NPCManager;
|
import net.jitse.npclib.NPCLib;
|
||||||
import net.jitse.npclib.api.NPC;
|
import net.jitse.npclib.api.events.NPCInteractEvent;
|
||||||
import net.jitse.npclib.events.NPCInteractEvent;
|
import net.jitse.npclib.internal.NPCManager;
|
||||||
import net.jitse.npclib.events.click.ClickType;
|
import net.jitse.npclib.internal.SimpleNPC;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
@ -35,10 +35,10 @@ public class PacketListener {
|
||||||
|
|
||||||
private Plugin plugin;
|
private Plugin plugin;
|
||||||
|
|
||||||
public void start(Plugin plugin) {
|
public void start(NPCLib instance) {
|
||||||
this.plugin = plugin;
|
this.plugin = instance.getPlugin();
|
||||||
|
|
||||||
new TinyProtocol(plugin) {
|
new TinyProtocol(instance) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object onPacketInAsync(Player player, Object packet) {
|
public Object onPacketInAsync(Player player, Object packet) {
|
||||||
|
@ -49,8 +49,8 @@ public class PacketListener {
|
||||||
|
|
||||||
private boolean handleInteractPacket(Player player, Object packet) {
|
private boolean handleInteractPacket(Player player, Object packet) {
|
||||||
if (packetPlayInUseEntityClazz.isInstance(packet)) {
|
if (packetPlayInUseEntityClazz.isInstance(packet)) {
|
||||||
NPC npc = NPCManager.getAllNPCs().stream().filter(
|
SimpleNPC npc = NPCManager.getAllNPCs().stream().filter(
|
||||||
check -> check.isActuallyShown(player) && check.getEntityId() == (int) entityIdField.get(packet))
|
check -> check.isShown(player) && check.getEntityId() == (int) entityIdField.get(packet))
|
||||||
.findFirst().orElse(null);
|
.findFirst().orElse(null);
|
||||||
|
|
||||||
if (npc == null) {
|
if (npc == null) {
|
||||||
|
@ -62,10 +62,11 @@ public class PacketListener {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClickType clickType = actionField.get(packet).toString()
|
NPCInteractEvent.ClickType clickType = actionField.get(packet).toString().equals("ATTACK")
|
||||||
.equals("ATTACK") ? ClickType.LEFT_CLICK : ClickType.RIGHT_CLICK;
|
? 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();
|
UUID uuid = player.getUniqueId();
|
||||||
delay.add(uuid);
|
delay.add(uuid);
|
|
@ -4,8 +4,9 @@
|
||||||
|
|
||||||
package net.jitse.npclib.listeners;
|
package net.jitse.npclib.listeners;
|
||||||
|
|
||||||
import net.jitse.npclib.NPCManager;
|
import net.jitse.npclib.NPCLib;
|
||||||
import net.jitse.npclib.api.NPC;
|
import net.jitse.npclib.internal.NPCManager;
|
||||||
|
import net.jitse.npclib.internal.SimpleNPC;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -21,10 +22,16 @@ import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
*/
|
*/
|
||||||
public class PlayerListener implements Listener {
|
public class PlayerListener implements Listener {
|
||||||
|
|
||||||
|
private final NPCLib instance;
|
||||||
|
|
||||||
|
public PlayerListener(NPCLib instance) {
|
||||||
|
this.instance = instance;
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
for (NPC npc : NPCManager.getAllNPCs()) {
|
for (SimpleNPC npc : NPCManager.getAllNPCs()) {
|
||||||
npc.getAutoHidden().remove(player.getUniqueId());
|
npc.getAutoHidden().remove(player.getUniqueId());
|
||||||
|
|
||||||
// Don't need to use NPC#hide since the entity is not registered in the NMS server.
|
// 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();
|
World from = event.getFrom();
|
||||||
|
|
||||||
// The PlayerTeleportEvent is call, and will handle visibility in the new world.
|
// 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.getLocation().getWorld().equals(from)) {
|
||||||
if (!npc.getAutoHidden().contains(player.getUniqueId())) {
|
if (!npc.getAutoHidden().contains(player.getUniqueId())) {
|
||||||
npc.getAutoHidden().add(player.getUniqueId());
|
npc.getAutoHidden().add(player.getUniqueId());
|
||||||
|
@ -60,7 +67,7 @@ public class PlayerListener implements Listener {
|
||||||
|
|
||||||
private void handleMove(Player player) {
|
private void handleMove(Player player) {
|
||||||
World world = player.getWorld();
|
World world = player.getWorld();
|
||||||
for (NPC npc : NPCManager.getAllNPCs()) {
|
for (SimpleNPC npc : NPCManager.getAllNPCs()) {
|
||||||
if (!npc.getShown().contains(player.getUniqueId())) {
|
if (!npc.getShown().contains(player.getUniqueId())) {
|
||||||
continue; // NPC was never supposed to be shown to the player.
|
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.
|
// If Bukkit doesn't track the NPC entity anymore, bypass the hiding distance variable.
|
||||||
// This will cause issues otherwise (e.g. custom skin disappearing).
|
// 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());
|
double distanceSquared = player.getLocation().distanceSquared(npc.getLocation());
|
||||||
boolean inRange = distanceSquared <= (Math.pow(hideDistance, 2))
|
boolean inRange = distanceSquared <= (Math.pow(hideDistance, 2))
|
||||||
&& distanceSquared <= (Math.pow(Bukkit.getViewDistance() << 4, 2));
|
&& distanceSquared <= (Math.pow(Bukkit.getViewDistance() << 4, 2));
|
|
@ -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>
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -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();
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2018 Jitse Boonstra
|
|
||||||
*/
|
|
||||||
|
|
||||||
package net.jitse.npclib.events.trigger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Jitse Boonstra
|
|
||||||
*/
|
|
||||||
public enum TriggerType {
|
|
||||||
|
|
||||||
MANUAL, AUTOMATIC
|
|
||||||
}
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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>
|
|
@ -3,11 +3,12 @@
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
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">
|
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib-nms</artifactId>
|
<artifactId>npclib-nms</artifactId>
|
||||||
<version>1.5-SNAPSHOT</version>
|
<version>2.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-nms-v1_10_R1</artifactId>
|
<artifactId>npclib-nms-v1_10_R1</artifactId>
|
||||||
|
|
|
@ -4,25 +4,25 @@
|
||||||
|
|
||||||
package net.jitse.npclib.nms.v1_10_R1;
|
package net.jitse.npclib.nms.v1_10_R1;
|
||||||
|
|
||||||
import net.jitse.npclib.api.NPC;
|
import net.jitse.npclib.NPCLib;
|
||||||
import net.jitse.npclib.nms.holograms.Hologram;
|
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.PacketPlayOutEntityHeadRotationWrapper;
|
||||||
import net.jitse.npclib.nms.v1_10_R1.packets.PacketPlayOutNamedEntitySpawnWrapper;
|
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.PacketPlayOutPlayerInfoWrapper;
|
||||||
import net.jitse.npclib.nms.v1_10_R1.packets.PacketPlayOutScoreboardTeamWrapper;
|
import net.jitse.npclib.nms.v1_10_R1.packets.PacketPlayOutScoreboardTeamWrapper;
|
||||||
import net.jitse.npclib.skin.Skin;
|
|
||||||
import net.minecraft.server.v1_10_R1.*;
|
import net.minecraft.server.v1_10_R1.*;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
*/
|
*/
|
||||||
public class NPC_v1_10_R1 extends NPC {
|
public class NPC_v1_10_R1 extends SimpleNPC {
|
||||||
|
|
||||||
private Hologram hologram;
|
private Hologram hologram;
|
||||||
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
||||||
|
@ -31,16 +31,15 @@ public class NPC_v1_10_R1 extends NPC {
|
||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
|
|
||||||
public NPC_v1_10_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
public NPC_v1_10_R1(NPCLib instance, List<String> lines) {
|
||||||
super(plugin, skin, autoHideDistance, lines);
|
super(instance, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createPackets() {
|
public void createPackets() {
|
||||||
this.hologram = new Hologram(location.clone().subtract(0, 0.5, 0), lines);
|
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();
|
PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper();
|
||||||
|
|
||||||
// Packets for spawning the NPC:
|
// Packets for spawning the NPC:
|
||||||
|
@ -80,7 +79,7 @@ public class NPC_v1_10_R1 extends NPC {
|
||||||
hologram.spawn(player);
|
hologram.spawn(player);
|
||||||
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () ->
|
||||||
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
|
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +94,7 @@ public class NPC_v1_10_R1 extends NPC {
|
||||||
|
|
||||||
if (scheduler) {
|
if (scheduler) {
|
||||||
// Sending this a bit later so the player doesn't see the name (for that split second).
|
// 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);
|
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
|
||||||
} else {
|
} else {
|
||||||
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
|
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
|
||||||
|
|
|
@ -6,7 +6,6 @@ package net.jitse.npclib.nms.v1_10_R1.packets;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
import com.mojang.authlib.GameProfile;
|
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.EnumGamemode;
|
||||||
import net.minecraft.server.v1_10_R1.IChatBaseComponent;
|
import net.minecraft.server.v1_10_R1.IChatBaseComponent;
|
||||||
import net.minecraft.server.v1_10_R1.PacketPlayOutPlayerInfo;
|
import net.minecraft.server.v1_10_R1.PacketPlayOutPlayerInfo;
|
||||||
|
@ -24,9 +23,7 @@ public class PacketPlayOutPlayerInfoWrapper {
|
||||||
private final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClazz,
|
private final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClazz,
|
||||||
packetPlayOutPlayerInfoClazz, GameProfile.class, int.class, EnumGamemode.class, IChatBaseComponent.class);
|
packetPlayOutPlayerInfoClazz, GameProfile.class, int.class, EnumGamemode.class, IChatBaseComponent.class);
|
||||||
|
|
||||||
public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfileWrapper gameProfileWrapper, String name) {
|
public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfile gameProfile, String name) {
|
||||||
GameProfile gameProfile = (GameProfile) gameProfileWrapper.getGameProfile();
|
|
||||||
|
|
||||||
PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
|
PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
|
||||||
Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class)
|
Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class)
|
||||||
.set(packetPlayOutPlayerInfo, action);
|
.set(packetPlayOutPlayerInfo, action);
|
||||||
|
|
|
@ -3,11 +3,12 @@
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
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">
|
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib-nms</artifactId>
|
<artifactId>npclib-nms</artifactId>
|
||||||
<version>1.5-SNAPSHOT</version>
|
<version>2.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-nms-v1_11_R1</artifactId>
|
<artifactId>npclib-nms-v1_11_R1</artifactId>
|
||||||
|
|
|
@ -4,25 +4,25 @@
|
||||||
|
|
||||||
package net.jitse.npclib.nms.v1_11_R1;
|
package net.jitse.npclib.nms.v1_11_R1;
|
||||||
|
|
||||||
import net.jitse.npclib.api.NPC;
|
import net.jitse.npclib.NPCLib;
|
||||||
import net.jitse.npclib.nms.holograms.Hologram;
|
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.PacketPlayOutEntityHeadRotationWrapper;
|
||||||
import net.jitse.npclib.nms.v1_11_R1.packets.PacketPlayOutNamedEntitySpawnWrapper;
|
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.PacketPlayOutPlayerInfoWrapper;
|
||||||
import net.jitse.npclib.nms.v1_11_R1.packets.PacketPlayOutScoreboardTeamWrapper;
|
import net.jitse.npclib.nms.v1_11_R1.packets.PacketPlayOutScoreboardTeamWrapper;
|
||||||
import net.jitse.npclib.skin.Skin;
|
|
||||||
import net.minecraft.server.v1_11_R1.*;
|
import net.minecraft.server.v1_11_R1.*;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
*/
|
*/
|
||||||
public class NPC_v1_11_R1 extends NPC {
|
public class NPC_v1_11_R1 extends SimpleNPC {
|
||||||
|
|
||||||
private Hologram hologram;
|
private Hologram hologram;
|
||||||
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
||||||
|
@ -31,16 +31,15 @@ public class NPC_v1_11_R1 extends NPC {
|
||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
|
|
||||||
public NPC_v1_11_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
public NPC_v1_11_R1(NPCLib instance, List<String> lines) {
|
||||||
super(plugin, skin, autoHideDistance, lines);
|
super(instance, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createPackets() {
|
public void createPackets() {
|
||||||
this.hologram = new Hologram(location.clone().add(0, 0.5, 0), lines);
|
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();
|
PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper();
|
||||||
|
|
||||||
// Packets for spawning the NPC:
|
// Packets for spawning the NPC:
|
||||||
|
@ -80,7 +79,7 @@ public class NPC_v1_11_R1 extends NPC {
|
||||||
hologram.spawn(player);
|
hologram.spawn(player);
|
||||||
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () ->
|
||||||
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
|
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +94,7 @@ public class NPC_v1_11_R1 extends NPC {
|
||||||
|
|
||||||
if (scheduler) {
|
if (scheduler) {
|
||||||
// Sending this a bit later so the player doesn't see the name (for that split second).
|
// 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);
|
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
|
||||||
} else {
|
} else {
|
||||||
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
|
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
|
||||||
|
|
|
@ -6,7 +6,6 @@ package net.jitse.npclib.nms.v1_11_R1.packets;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
import com.mojang.authlib.GameProfile;
|
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.EnumGamemode;
|
||||||
import net.minecraft.server.v1_11_R1.IChatBaseComponent;
|
import net.minecraft.server.v1_11_R1.IChatBaseComponent;
|
||||||
import net.minecraft.server.v1_11_R1.PacketPlayOutPlayerInfo;
|
import net.minecraft.server.v1_11_R1.PacketPlayOutPlayerInfo;
|
||||||
|
@ -24,9 +23,7 @@ public class PacketPlayOutPlayerInfoWrapper {
|
||||||
private final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClazz,
|
private final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClazz,
|
||||||
packetPlayOutPlayerInfoClazz, GameProfile.class, int.class, EnumGamemode.class, IChatBaseComponent.class);
|
packetPlayOutPlayerInfoClazz, GameProfile.class, int.class, EnumGamemode.class, IChatBaseComponent.class);
|
||||||
|
|
||||||
public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfileWrapper gameProfileWrapper, String name) {
|
public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfile gameProfile, String name) {
|
||||||
GameProfile gameProfile = (GameProfile) gameProfileWrapper.getGameProfile();
|
|
||||||
|
|
||||||
PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
|
PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
|
||||||
Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class)
|
Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class)
|
||||||
.set(packetPlayOutPlayerInfo, action);
|
.set(packetPlayOutPlayerInfo, action);
|
||||||
|
|
|
@ -3,11 +3,12 @@
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
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">
|
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib-nms</artifactId>
|
<artifactId>npclib-nms</artifactId>
|
||||||
<version>1.5-SNAPSHOT</version>
|
<version>2.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-nms-v1_12_R1</artifactId>
|
<artifactId>npclib-nms-v1_12_R1</artifactId>
|
||||||
|
|
|
@ -4,25 +4,25 @@
|
||||||
|
|
||||||
package net.jitse.npclib.nms.v1_12_R1;
|
package net.jitse.npclib.nms.v1_12_R1;
|
||||||
|
|
||||||
import net.jitse.npclib.api.NPC;
|
import net.jitse.npclib.NPCLib;
|
||||||
import net.jitse.npclib.nms.holograms.Hologram;
|
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.PacketPlayOutEntityHeadRotationWrapper;
|
||||||
import net.jitse.npclib.nms.v1_12_R1.packets.PacketPlayOutNamedEntitySpawnWrapper;
|
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.PacketPlayOutPlayerInfoWrapper;
|
||||||
import net.jitse.npclib.nms.v1_12_R1.packets.PacketPlayOutScoreboardTeamWrapper;
|
import net.jitse.npclib.nms.v1_12_R1.packets.PacketPlayOutScoreboardTeamWrapper;
|
||||||
import net.jitse.npclib.skin.Skin;
|
|
||||||
import net.minecraft.server.v1_12_R1.*;
|
import net.minecraft.server.v1_12_R1.*;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
*/
|
*/
|
||||||
public class NPC_v1_12_R1 extends NPC {
|
public class NPC_v1_12_R1 extends SimpleNPC {
|
||||||
|
|
||||||
private Hologram hologram;
|
private Hologram hologram;
|
||||||
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
||||||
|
@ -31,16 +31,15 @@ public class NPC_v1_12_R1 extends NPC {
|
||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
|
|
||||||
public NPC_v1_12_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
public NPC_v1_12_R1(NPCLib instance, List<String> lines) {
|
||||||
super(plugin, skin, autoHideDistance, lines);
|
super(instance, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createPackets() {
|
public void createPackets() {
|
||||||
this.hologram = new Hologram(location.clone().add(0, 0.5, 0), lines);
|
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();
|
PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper();
|
||||||
|
|
||||||
// Packets for spawning the NPC:
|
// Packets for spawning the NPC:
|
||||||
|
@ -79,8 +78,7 @@ public class NPC_v1_12_R1 extends NPC {
|
||||||
|
|
||||||
hologram.spawn(player);
|
hologram.spawn(player);
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () ->
|
||||||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
|
||||||
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
|
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +93,7 @@ public class NPC_v1_12_R1 extends NPC {
|
||||||
|
|
||||||
if (scheduler) {
|
if (scheduler) {
|
||||||
// Sending this a bit later so the player doesn't see the name (for that split second).
|
// 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);
|
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
|
||||||
} else {
|
} else {
|
||||||
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
|
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
|
||||||
|
|
|
@ -6,7 +6,6 @@ package net.jitse.npclib.nms.v1_12_R1.packets;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
import com.mojang.authlib.GameProfile;
|
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.EnumGamemode;
|
||||||
import net.minecraft.server.v1_12_R1.IChatBaseComponent;
|
import net.minecraft.server.v1_12_R1.IChatBaseComponent;
|
||||||
import net.minecraft.server.v1_12_R1.PacketPlayOutPlayerInfo;
|
import net.minecraft.server.v1_12_R1.PacketPlayOutPlayerInfo;
|
||||||
|
@ -24,9 +23,7 @@ public class PacketPlayOutPlayerInfoWrapper {
|
||||||
private final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClazz,
|
private final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClazz,
|
||||||
packetPlayOutPlayerInfoClazz, GameProfile.class, int.class, EnumGamemode.class, IChatBaseComponent.class);
|
packetPlayOutPlayerInfoClazz, GameProfile.class, int.class, EnumGamemode.class, IChatBaseComponent.class);
|
||||||
|
|
||||||
public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfileWrapper gameProfileWrapper, String name) {
|
public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfile gameProfile, String name) {
|
||||||
GameProfile gameProfile = (GameProfile) gameProfileWrapper.getGameProfile();
|
|
||||||
|
|
||||||
PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
|
PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
|
||||||
Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class)
|
Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class)
|
||||||
.set(packetPlayOutPlayerInfo, action);
|
.set(packetPlayOutPlayerInfo, action);
|
||||||
|
|
|
@ -3,11 +3,12 @@
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
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">
|
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib-nms</artifactId>
|
<artifactId>npclib-nms</artifactId>
|
||||||
<version>1.5-SNAPSHOT</version>
|
<version>2.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-nms-v1_13_R1</artifactId>
|
<artifactId>npclib-nms-v1_13_R1</artifactId>
|
||||||
|
|
|
@ -4,26 +4,25 @@
|
||||||
|
|
||||||
package net.jitse.npclib.nms.v1_13_R1;
|
package net.jitse.npclib.nms.v1_13_R1;
|
||||||
|
|
||||||
import net.jitse.npclib.api.NPC;
|
import net.jitse.npclib.NPCLib;
|
||||||
import net.jitse.npclib.nms.holograms.Hologram;
|
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.PacketPlayOutEntityHeadRotationWrapper;
|
||||||
import net.jitse.npclib.nms.v1_13_R1.packets.PacketPlayOutNamedEntitySpawnWrapper;
|
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.PacketPlayOutPlayerInfoWrapper;
|
||||||
import net.jitse.npclib.nms.v1_13_R1.packets.PacketPlayOutScoreboardTeamWrapper;
|
import net.jitse.npclib.nms.v1_13_R1.packets.PacketPlayOutScoreboardTeamWrapper;
|
||||||
import net.jitse.npclib.skin.Skin;
|
|
||||||
import net.minecraft.server.v1_13_R1.*;
|
import net.minecraft.server.v1_13_R1.*;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_13_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_13_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
*/
|
*/
|
||||||
public class NPC_v1_13_R1 extends NPC {
|
public class NPC_v1_13_R1 extends SimpleNPC {
|
||||||
|
|
||||||
private Hologram hologram;
|
private Hologram hologram;
|
||||||
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
||||||
|
@ -32,16 +31,15 @@ public class NPC_v1_13_R1 extends NPC {
|
||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
|
|
||||||
public NPC_v1_13_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
public NPC_v1_13_R1(NPCLib instance, List<String> lines) {
|
||||||
super(plugin, skin, autoHideDistance, lines);
|
super(instance, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createPackets() {
|
public void createPackets() {
|
||||||
this.hologram = new Hologram(location.clone().add(0, 0.5, 0), lines);
|
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();
|
PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper();
|
||||||
|
|
||||||
// Packets for spawning the NPC:
|
// Packets for spawning the NPC:
|
||||||
|
@ -81,7 +79,7 @@ public class NPC_v1_13_R1 extends NPC {
|
||||||
hologram.spawn(player);
|
hologram.spawn(player);
|
||||||
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () ->
|
||||||
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
|
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +94,7 @@ public class NPC_v1_13_R1 extends NPC {
|
||||||
|
|
||||||
if (scheduler) {
|
if (scheduler) {
|
||||||
// Sending this a bit later so the player doesn't see the name (for that split second).
|
// 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);
|
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
|
||||||
} else {
|
} else {
|
||||||
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
|
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
|
||||||
|
|
|
@ -6,7 +6,6 @@ package net.jitse.npclib.nms.v1_13_R1.packets;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
import com.mojang.authlib.GameProfile;
|
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.EnumGamemode;
|
||||||
import net.minecraft.server.v1_13_R1.IChatBaseComponent;
|
import net.minecraft.server.v1_13_R1.IChatBaseComponent;
|
||||||
import net.minecraft.server.v1_13_R1.PacketPlayOutPlayerInfo;
|
import net.minecraft.server.v1_13_R1.PacketPlayOutPlayerInfo;
|
||||||
|
@ -24,9 +23,7 @@ public class PacketPlayOutPlayerInfoWrapper {
|
||||||
private final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClazz,
|
private final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClazz,
|
||||||
packetPlayOutPlayerInfoClazz, GameProfile.class, int.class, EnumGamemode.class, IChatBaseComponent.class);
|
packetPlayOutPlayerInfoClazz, GameProfile.class, int.class, EnumGamemode.class, IChatBaseComponent.class);
|
||||||
|
|
||||||
public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfileWrapper gameProfileWrapper, String name) {
|
public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfile gameProfile, String name) {
|
||||||
GameProfile gameProfile = (GameProfile) gameProfileWrapper.getGameProfile();
|
|
||||||
|
|
||||||
PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
|
PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
|
||||||
Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class)
|
Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class)
|
||||||
.set(packetPlayOutPlayerInfo, action);
|
.set(packetPlayOutPlayerInfo, action);
|
||||||
|
|
|
@ -3,11 +3,12 @@
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
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">
|
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib-nms</artifactId>
|
<artifactId>npclib-nms</artifactId>
|
||||||
<version>1.5-SNAPSHOT</version>
|
<version>2.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-nms-v1_13_R2</artifactId>
|
<artifactId>npclib-nms-v1_13_R2</artifactId>
|
||||||
|
|
|
@ -4,25 +4,25 @@
|
||||||
|
|
||||||
package net.jitse.npclib.nms.v1_13_R2;
|
package net.jitse.npclib.nms.v1_13_R2;
|
||||||
|
|
||||||
import net.jitse.npclib.api.NPC;
|
import net.jitse.npclib.NPCLib;
|
||||||
import net.jitse.npclib.nms.holograms.Hologram;
|
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.PacketPlayOutEntityHeadRotationWrapper;
|
||||||
import net.jitse.npclib.nms.v1_13_R2.packets.PacketPlayOutNamedEntitySpawnWrapper;
|
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.PacketPlayOutPlayerInfoWrapper;
|
||||||
import net.jitse.npclib.nms.v1_13_R2.packets.PacketPlayOutScoreboardTeamWrapper;
|
import net.jitse.npclib.nms.v1_13_R2.packets.PacketPlayOutScoreboardTeamWrapper;
|
||||||
import net.jitse.npclib.skin.Skin;
|
|
||||||
import net.minecraft.server.v1_13_R2.*;
|
import net.minecraft.server.v1_13_R2.*;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
*/
|
*/
|
||||||
public class NPC_v1_13_R2 extends NPC {
|
public class NPC_v1_13_R2 extends SimpleNPC {
|
||||||
|
|
||||||
private Hologram hologram;
|
private Hologram hologram;
|
||||||
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
||||||
|
@ -31,16 +31,15 @@ public class NPC_v1_13_R2 extends NPC {
|
||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
|
|
||||||
public NPC_v1_13_R2(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
public NPC_v1_13_R2(NPCLib instance, List<String> lines) {
|
||||||
super(plugin, skin, autoHideDistance, lines);
|
super(instance, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createPackets() {
|
public void createPackets() {
|
||||||
this.hologram = new Hologram(location.clone().add(0, 0.5, 0), lines);
|
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();
|
PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper();
|
||||||
|
|
||||||
// Packets for spawning the NPC:
|
// Packets for spawning the NPC:
|
||||||
|
@ -80,7 +79,7 @@ public class NPC_v1_13_R2 extends NPC {
|
||||||
hologram.spawn(player);
|
hologram.spawn(player);
|
||||||
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () ->
|
||||||
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
|
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +94,7 @@ public class NPC_v1_13_R2 extends NPC {
|
||||||
|
|
||||||
if (scheduler) {
|
if (scheduler) {
|
||||||
// Sending this a bit later so the player doesn't see the name (for that split second).
|
// 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);
|
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
|
||||||
} else {
|
} else {
|
||||||
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
|
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
|
||||||
|
|
|
@ -6,7 +6,6 @@ package net.jitse.npclib.nms.v1_13_R2.packets;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
import com.mojang.authlib.GameProfile;
|
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.EnumGamemode;
|
||||||
import net.minecraft.server.v1_13_R2.IChatBaseComponent;
|
import net.minecraft.server.v1_13_R2.IChatBaseComponent;
|
||||||
import net.minecraft.server.v1_13_R2.PacketPlayOutPlayerInfo;
|
import net.minecraft.server.v1_13_R2.PacketPlayOutPlayerInfo;
|
||||||
|
@ -24,9 +23,7 @@ public class PacketPlayOutPlayerInfoWrapper {
|
||||||
private final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClazz,
|
private final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClazz,
|
||||||
packetPlayOutPlayerInfoClazz, GameProfile.class, int.class, EnumGamemode.class, IChatBaseComponent.class);
|
packetPlayOutPlayerInfoClazz, GameProfile.class, int.class, EnumGamemode.class, IChatBaseComponent.class);
|
||||||
|
|
||||||
public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfileWrapper gameProfileWrapper, String name) {
|
public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfile gameProfile, String name) {
|
||||||
GameProfile gameProfile = (GameProfile) gameProfileWrapper.getGameProfile();
|
|
||||||
|
|
||||||
PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
|
PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
|
||||||
Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class)
|
Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class)
|
||||||
.set(packetPlayOutPlayerInfo, action);
|
.set(packetPlayOutPlayerInfo, action);
|
||||||
|
|
|
@ -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>
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<List> fieldAccessor = Reflection.getField(packetPlayOutPlayerInfo.getClass(), "b", List.class);
|
||||||
|
List list = fieldAccessor.get(packetPlayOutPlayerInfo);
|
||||||
|
list.add(playerInfoData);
|
||||||
|
fieldAccessor.set(packetPlayOutPlayerInfo, list);
|
||||||
|
|
||||||
|
return packetPlayOutPlayerInfo;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<Collection> 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,11 +3,12 @@
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
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">
|
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib-nms</artifactId>
|
<artifactId>npclib-nms</artifactId>
|
||||||
<version>1.5-SNAPSHOT</version>
|
<version>2.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-nms-v1_8_R1</artifactId>
|
<artifactId>npclib-nms-v1_8_R1</artifactId>
|
||||||
|
@ -26,4 +27,22 @@
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -4,25 +4,25 @@
|
||||||
|
|
||||||
package net.jitse.npclib.nms.v1_8_R1;
|
package net.jitse.npclib.nms.v1_8_R1;
|
||||||
|
|
||||||
import net.jitse.npclib.api.NPC;
|
import net.jitse.npclib.NPCLib;
|
||||||
import net.jitse.npclib.nms.holograms.Hologram;
|
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.PacketPlayOutEntityHeadRotationWrapper;
|
||||||
import net.jitse.npclib.nms.v1_8_R1.packets.PacketPlayOutNamedEntitySpawnWrapper;
|
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.PacketPlayOutPlayerInfoWrapper;
|
||||||
import net.jitse.npclib.nms.v1_8_R1.packets.PacketPlayOutScoreboardTeamWrapper;
|
import net.jitse.npclib.nms.v1_8_R1.packets.PacketPlayOutScoreboardTeamWrapper;
|
||||||
import net.jitse.npclib.skin.Skin;
|
|
||||||
import net.minecraft.server.v1_8_R1.*;
|
import net.minecraft.server.v1_8_R1.*;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
*/
|
*/
|
||||||
public class NPC_v1_8_R1 extends NPC {
|
public class NPC_v1_8_R1 extends SimpleNPC {
|
||||||
|
|
||||||
private Hologram hologram;
|
private Hologram hologram;
|
||||||
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
||||||
|
@ -31,16 +31,15 @@ public class NPC_v1_8_R1 extends NPC {
|
||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
|
|
||||||
public NPC_v1_8_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
public NPC_v1_8_R1(NPCLib instance, List<String> lines) {
|
||||||
super(plugin, skin, autoHideDistance, lines);
|
super(instance, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createPackets() {
|
public void createPackets() {
|
||||||
this.hologram = new Hologram(location.clone().add(0, 0.5, 0), lines);
|
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();
|
PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper();
|
||||||
|
|
||||||
// Packets for spawning the NPC:
|
// Packets for spawning the NPC:
|
||||||
|
@ -79,7 +78,7 @@ public class NPC_v1_8_R1 extends NPC {
|
||||||
|
|
||||||
hologram.spawn(player);
|
hologram.spawn(player);
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () ->
|
||||||
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
|
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +93,7 @@ public class NPC_v1_8_R1 extends NPC {
|
||||||
|
|
||||||
if (scheduler) {
|
if (scheduler) {
|
||||||
// Sending this a bit later so the player doesn't see the name (for that split second).
|
// 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);
|
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
|
||||||
} else {
|
} else {
|
||||||
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
|
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
|
||||||
|
|
|
@ -6,7 +6,6 @@ package net.jitse.npclib.nms.v1_8_R1.packets;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import net.jitse.npclib.api.wrapper.GameProfileWrapper;
|
|
||||||
import net.minecraft.server.v1_8_R1.*;
|
import net.minecraft.server.v1_8_R1.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -16,9 +15,7 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class PacketPlayOutPlayerInfoWrapper {
|
public class PacketPlayOutPlayerInfoWrapper {
|
||||||
|
|
||||||
public PacketPlayOutPlayerInfo create(EnumPlayerInfoAction action, GameProfileWrapper gameProfileWrapper, String name) {
|
public PacketPlayOutPlayerInfo create(EnumPlayerInfoAction action, GameProfile gameProfile, String name) {
|
||||||
GameProfile gameProfile = (GameProfile) gameProfileWrapper.getGameProfile();
|
|
||||||
|
|
||||||
PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
|
PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
|
||||||
Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", EnumPlayerInfoAction.class)
|
Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", EnumPlayerInfoAction.class)
|
||||||
.set(packetPlayOutPlayerInfo, action);
|
.set(packetPlayOutPlayerInfo, action);
|
||||||
|
|
|
@ -3,11 +3,12 @@
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
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">
|
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib-nms</artifactId>
|
<artifactId>npclib-nms</artifactId>
|
||||||
<version>1.5-SNAPSHOT</version>
|
<version>2.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-nms-v1_8_R2</artifactId>
|
<artifactId>npclib-nms-v1_8_R2</artifactId>
|
||||||
|
|
|
@ -4,25 +4,25 @@
|
||||||
|
|
||||||
package net.jitse.npclib.nms.v1_8_R2;
|
package net.jitse.npclib.nms.v1_8_R2;
|
||||||
|
|
||||||
import net.jitse.npclib.api.NPC;
|
import net.jitse.npclib.NPCLib;
|
||||||
import net.jitse.npclib.nms.holograms.Hologram;
|
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.PacketPlayOutEntityHeadRotationWrapper;
|
||||||
import net.jitse.npclib.nms.v1_8_R2.packets.PacketPlayOutNamedEntitySpawnWrapper;
|
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.PacketPlayOutPlayerInfoWrapper;
|
||||||
import net.jitse.npclib.nms.v1_8_R2.packets.PacketPlayOutScoreboardTeamWrapper;
|
import net.jitse.npclib.nms.v1_8_R2.packets.PacketPlayOutScoreboardTeamWrapper;
|
||||||
import net.jitse.npclib.skin.Skin;
|
|
||||||
import net.minecraft.server.v1_8_R2.*;
|
import net.minecraft.server.v1_8_R2.*;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
*/
|
*/
|
||||||
public class NPC_v1_8_R2 extends NPC {
|
public class NPC_v1_8_R2 extends SimpleNPC {
|
||||||
|
|
||||||
private Hologram hologram;
|
private Hologram hologram;
|
||||||
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
||||||
|
@ -31,16 +31,15 @@ public class NPC_v1_8_R2 extends NPC {
|
||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
|
|
||||||
public NPC_v1_8_R2(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
public NPC_v1_8_R2(NPCLib instance, List<String> lines) {
|
||||||
super(plugin, skin, autoHideDistance, lines);
|
super(instance, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createPackets() {
|
public void createPackets() {
|
||||||
this.hologram = new Hologram(location.clone().add(0, 0.5, 0), lines);
|
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();
|
PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper();
|
||||||
|
|
||||||
// Packets for spawning the NPC:
|
// Packets for spawning the NPC:
|
||||||
|
@ -79,7 +78,7 @@ public class NPC_v1_8_R2 extends NPC {
|
||||||
|
|
||||||
hologram.spawn(player);
|
hologram.spawn(player);
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () ->
|
||||||
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
|
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +93,7 @@ public class NPC_v1_8_R2 extends NPC {
|
||||||
|
|
||||||
if (scheduler) {
|
if (scheduler) {
|
||||||
// Sending this a bit later so the player doesn't see the name (for that split second).
|
// 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);
|
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
|
||||||
} else {
|
} else {
|
||||||
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
|
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
|
||||||
|
|
|
@ -6,7 +6,6 @@ package net.jitse.npclib.nms.v1_8_R2.packets;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
import com.mojang.authlib.GameProfile;
|
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.IChatBaseComponent;
|
||||||
import net.minecraft.server.v1_8_R2.PacketPlayOutPlayerInfo;
|
import net.minecraft.server.v1_8_R2.PacketPlayOutPlayerInfo;
|
||||||
import net.minecraft.server.v1_8_R2.WorldSettings;
|
import net.minecraft.server.v1_8_R2.WorldSettings;
|
||||||
|
@ -18,9 +17,7 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class PacketPlayOutPlayerInfoWrapper {
|
public class PacketPlayOutPlayerInfoWrapper {
|
||||||
|
|
||||||
public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfileWrapper gameProfileWrapper, String name) {
|
public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfile gameProfile, String name) {
|
||||||
GameProfile gameProfile = (GameProfile) gameProfileWrapper.getGameProfile();
|
|
||||||
|
|
||||||
PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
|
PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
|
||||||
Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class)
|
Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class)
|
||||||
.set(packetPlayOutPlayerInfo, action);
|
.set(packetPlayOutPlayerInfo, action);
|
||||||
|
|
|
@ -3,11 +3,12 @@
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
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">
|
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib-nms</artifactId>
|
<artifactId>npclib-nms</artifactId>
|
||||||
<version>1.5-SNAPSHOT</version>
|
<version>2.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-nms-v1_8_R3</artifactId>
|
<artifactId>npclib-nms-v1_8_R3</artifactId>
|
||||||
|
|
|
@ -4,25 +4,25 @@
|
||||||
|
|
||||||
package net.jitse.npclib.nms.v1_8_R3;
|
package net.jitse.npclib.nms.v1_8_R3;
|
||||||
|
|
||||||
import net.jitse.npclib.api.NPC;
|
import net.jitse.npclib.NPCLib;
|
||||||
import net.jitse.npclib.nms.holograms.Hologram;
|
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.PacketPlayOutEntityHeadRotationWrapper;
|
||||||
import net.jitse.npclib.nms.v1_8_R3.packets.PacketPlayOutNamedEntitySpawnWrapper;
|
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.PacketPlayOutPlayerInfoWrapper;
|
||||||
import net.jitse.npclib.nms.v1_8_R3.packets.PacketPlayOutScoreboardTeamWrapper;
|
import net.jitse.npclib.nms.v1_8_R3.packets.PacketPlayOutScoreboardTeamWrapper;
|
||||||
import net.jitse.npclib.skin.Skin;
|
|
||||||
import net.minecraft.server.v1_8_R3.*;
|
import net.minecraft.server.v1_8_R3.*;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
*/
|
*/
|
||||||
public class NPC_v1_8_R3 extends NPC {
|
public class NPC_v1_8_R3 extends SimpleNPC {
|
||||||
|
|
||||||
private Hologram hologram;
|
private Hologram hologram;
|
||||||
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
||||||
|
@ -31,16 +31,15 @@ public class NPC_v1_8_R3 extends NPC {
|
||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
|
|
||||||
public NPC_v1_8_R3(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
public NPC_v1_8_R3(NPCLib instance, List<String> lines) {
|
||||||
super(plugin, skin, autoHideDistance, lines);
|
super(instance, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createPackets() {
|
public void createPackets() {
|
||||||
this.hologram = new Hologram(location.clone().add(0, 0.5, 0), lines);
|
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();
|
PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper();
|
||||||
|
|
||||||
// Packets for spawning the NPC:
|
// Packets for spawning the NPC:
|
||||||
|
@ -80,7 +79,7 @@ public class NPC_v1_8_R3 extends NPC {
|
||||||
hologram.spawn(player);
|
hologram.spawn(player);
|
||||||
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () ->
|
||||||
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
|
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +94,7 @@ public class NPC_v1_8_R3 extends NPC {
|
||||||
|
|
||||||
if (scheduler) {
|
if (scheduler) {
|
||||||
// Sending this a bit later so the player doesn't see the name (for that split second).
|
// 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);
|
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
|
||||||
} else {
|
} else {
|
||||||
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
|
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
|
||||||
|
|
|
@ -6,7 +6,6 @@ package net.jitse.npclib.nms.v1_8_R3.packets;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
import com.mojang.authlib.GameProfile;
|
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.IChatBaseComponent;
|
||||||
import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo;
|
import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo;
|
||||||
import net.minecraft.server.v1_8_R3.WorldSettings;
|
import net.minecraft.server.v1_8_R3.WorldSettings;
|
||||||
|
@ -18,9 +17,7 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class PacketPlayOutPlayerInfoWrapper {
|
public class PacketPlayOutPlayerInfoWrapper {
|
||||||
|
|
||||||
public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfileWrapper gameProfileWrapper, String name) {
|
public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfile gameProfile, String name) {
|
||||||
GameProfile gameProfile = (GameProfile) gameProfileWrapper.getGameProfile();
|
|
||||||
|
|
||||||
PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
|
PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
|
||||||
Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class)
|
Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class)
|
||||||
.set(packetPlayOutPlayerInfo, action);
|
.set(packetPlayOutPlayerInfo, action);
|
||||||
|
|
|
@ -3,11 +3,12 @@
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
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">
|
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib-nms</artifactId>
|
<artifactId>npclib-nms</artifactId>
|
||||||
<version>1.5-SNAPSHOT</version>
|
<version>2.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-nms-v1_9_R1</artifactId>
|
<artifactId>npclib-nms-v1_9_R1</artifactId>
|
||||||
|
|
|
@ -4,25 +4,25 @@
|
||||||
|
|
||||||
package net.jitse.npclib.nms.v1_9_R1;
|
package net.jitse.npclib.nms.v1_9_R1;
|
||||||
|
|
||||||
import net.jitse.npclib.api.NPC;
|
import net.jitse.npclib.NPCLib;
|
||||||
import net.jitse.npclib.nms.holograms.Hologram;
|
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.PacketPlayOutEntityHeadRotationWrapper;
|
||||||
import net.jitse.npclib.nms.v1_9_R1.packets.PacketPlayOutNamedEntitySpawnWrapper;
|
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.PacketPlayOutPlayerInfoWrapper;
|
||||||
import net.jitse.npclib.nms.v1_9_R1.packets.PacketPlayOutScoreboardTeamWrapper;
|
import net.jitse.npclib.nms.v1_9_R1.packets.PacketPlayOutScoreboardTeamWrapper;
|
||||||
import net.jitse.npclib.skin.Skin;
|
|
||||||
import net.minecraft.server.v1_9_R1.*;
|
import net.minecraft.server.v1_9_R1.*;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
*/
|
*/
|
||||||
public class NPC_v1_9_R1 extends NPC {
|
public class NPC_v1_9_R1 extends SimpleNPC {
|
||||||
|
|
||||||
private Hologram hologram;
|
private Hologram hologram;
|
||||||
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
||||||
|
@ -31,16 +31,15 @@ public class NPC_v1_9_R1 extends NPC {
|
||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
|
|
||||||
public NPC_v1_9_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
public NPC_v1_9_R1(NPCLib instance, List<String> lines) {
|
||||||
super(plugin, skin, autoHideDistance, lines);
|
super(instance, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createPackets() {
|
public void createPackets() {
|
||||||
this.hologram = new Hologram(location.clone().subtract(0, 0.5, 0), lines);
|
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();
|
PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper();
|
||||||
|
|
||||||
// Packets for spawning the NPC:
|
// Packets for spawning the NPC:
|
||||||
|
@ -80,7 +79,7 @@ public class NPC_v1_9_R1 extends NPC {
|
||||||
hologram.spawn(player);
|
hologram.spawn(player);
|
||||||
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () ->
|
||||||
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
|
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +94,7 @@ public class NPC_v1_9_R1 extends NPC {
|
||||||
|
|
||||||
if (scheduler) {
|
if (scheduler) {
|
||||||
// Sending this a bit later so the player doesn't see the name (for that split second).
|
// 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);
|
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
|
||||||
} else {
|
} else {
|
||||||
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
|
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
|
||||||
|
|
|
@ -6,7 +6,6 @@ package net.jitse.npclib.nms.v1_9_R1.packets;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
import com.mojang.authlib.GameProfile;
|
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.IChatBaseComponent;
|
||||||
import net.minecraft.server.v1_9_R1.PacketPlayOutPlayerInfo;
|
import net.minecraft.server.v1_9_R1.PacketPlayOutPlayerInfo;
|
||||||
import net.minecraft.server.v1_9_R1.WorldSettings;
|
import net.minecraft.server.v1_9_R1.WorldSettings;
|
||||||
|
@ -19,9 +18,7 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class PacketPlayOutPlayerInfoWrapper {
|
public class PacketPlayOutPlayerInfoWrapper {
|
||||||
|
|
||||||
public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfileWrapper gameProfileWrapper, String name) {
|
public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfile gameProfile, String name) {
|
||||||
GameProfile gameProfile = (GameProfile) gameProfileWrapper.getGameProfile();
|
|
||||||
|
|
||||||
PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
|
PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
|
||||||
Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class)
|
Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class)
|
||||||
.set(packetPlayOutPlayerInfo, action);
|
.set(packetPlayOutPlayerInfo, action);
|
||||||
|
|
|
@ -3,11 +3,12 @@
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
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">
|
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib-nms</artifactId>
|
<artifactId>npclib-nms</artifactId>
|
||||||
<version>1.5-SNAPSHOT</version>
|
<version>2.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-nms-v1_9_R2</artifactId>
|
<artifactId>npclib-nms-v1_9_R2</artifactId>
|
||||||
|
|
|
@ -4,25 +4,25 @@
|
||||||
|
|
||||||
package net.jitse.npclib.nms.v1_9_R2;
|
package net.jitse.npclib.nms.v1_9_R2;
|
||||||
|
|
||||||
import net.jitse.npclib.api.NPC;
|
import net.jitse.npclib.NPCLib;
|
||||||
import net.jitse.npclib.nms.holograms.Hologram;
|
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.PacketPlayOutEntityHeadRotationWrapper;
|
||||||
import net.jitse.npclib.nms.v1_9_R2.packets.PacketPlayOutNamedEntitySpawnWrapper;
|
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.PacketPlayOutPlayerInfoWrapper;
|
||||||
import net.jitse.npclib.nms.v1_9_R2.packets.PacketPlayOutScoreboardTeamWrapper;
|
import net.jitse.npclib.nms.v1_9_R2.packets.PacketPlayOutScoreboardTeamWrapper;
|
||||||
import net.jitse.npclib.skin.Skin;
|
|
||||||
import net.minecraft.server.v1_9_R2.*;
|
import net.minecraft.server.v1_9_R2.*;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
*/
|
*/
|
||||||
public class NPC_v1_9_R2 extends NPC {
|
public class NPC_v1_9_R2 extends SimpleNPC {
|
||||||
|
|
||||||
private Hologram hologram;
|
private Hologram hologram;
|
||||||
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
||||||
|
@ -31,16 +31,15 @@ public class NPC_v1_9_R2 extends NPC {
|
||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
|
|
||||||
public NPC_v1_9_R2(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
public NPC_v1_9_R2(NPCLib instance, List<String> lines) {
|
||||||
super(plugin, skin, autoHideDistance, lines);
|
super(instance, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createPackets() {
|
public void createPackets() {
|
||||||
this.hologram = new Hologram(location.clone().subtract(0, 0.5, 0), lines);
|
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();
|
PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper();
|
||||||
|
|
||||||
// Packets for spawning the NPC:
|
// Packets for spawning the NPC:
|
||||||
|
@ -80,7 +79,7 @@ public class NPC_v1_9_R2 extends NPC {
|
||||||
hologram.spawn(player);
|
hologram.spawn(player);
|
||||||
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () ->
|
||||||
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
|
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +94,7 @@ public class NPC_v1_9_R2 extends NPC {
|
||||||
|
|
||||||
if (scheduler) {
|
if (scheduler) {
|
||||||
// Sending this a bit later so the player doesn't see the name (for that split second).
|
// 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);
|
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
|
||||||
} else {
|
} else {
|
||||||
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
|
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
|
||||||
|
|
|
@ -6,7 +6,6 @@ package net.jitse.npclib.nms.v1_9_R2.packets;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
import com.mojang.authlib.GameProfile;
|
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.IChatBaseComponent;
|
||||||
import net.minecraft.server.v1_9_R2.PacketPlayOutPlayerInfo;
|
import net.minecraft.server.v1_9_R2.PacketPlayOutPlayerInfo;
|
||||||
import net.minecraft.server.v1_9_R2.WorldSettings;
|
import net.minecraft.server.v1_9_R2.WorldSettings;
|
||||||
|
@ -24,9 +23,7 @@ public class PacketPlayOutPlayerInfoWrapper {
|
||||||
private final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClazz,
|
private final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClazz,
|
||||||
packetPlayOutPlayerInfoClazz, GameProfile.class, int.class, WorldSettings.EnumGamemode.class, IChatBaseComponent.class);
|
packetPlayOutPlayerInfoClazz, GameProfile.class, int.class, WorldSettings.EnumGamemode.class, IChatBaseComponent.class);
|
||||||
|
|
||||||
public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfileWrapper gameProfileWrapper, String name) {
|
public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfile gameProfile, String name) {
|
||||||
GameProfile gameProfile = (GameProfile) gameProfileWrapper.getGameProfile();
|
|
||||||
|
|
||||||
PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
|
PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
|
||||||
Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class)
|
Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class)
|
||||||
.set(packetPlayOutPlayerInfo, action);
|
.set(packetPlayOutPlayerInfo, action);
|
||||||
|
|
|
@ -3,15 +3,97 @@
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
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">
|
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib</artifactId>
|
<artifactId>npclib</artifactId>
|
||||||
<version>1.5-SNAPSHOT</version>
|
<version>2.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-plugin</artifactId>
|
<artifactId>npclib-plugin</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.14.4-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.jitse</groupId>
|
||||||
|
<artifactId>npclib-api</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.jitse</groupId>
|
||||||
|
<artifactId>npclib-nms-v1_8_R1</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.jitse</groupId>
|
||||||
|
<artifactId>npclib-nms-v1_8_R2</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.jitse</groupId>
|
||||||
|
<artifactId>npclib-nms-v1_8_R3</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.jitse</groupId>
|
||||||
|
<artifactId>npclib-nms-v1_9_R1</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.jitse</groupId>
|
||||||
|
<artifactId>npclib-nms-v1_9_R2</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.jitse</groupId>
|
||||||
|
<artifactId>npclib-nms-v1_10_R1</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.jitse</groupId>
|
||||||
|
<artifactId>npclib-nms-v1_11_R1</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.jitse</groupId>
|
||||||
|
<artifactId>npclib-nms-v1_12_R1</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.jitse</groupId>
|
||||||
|
<artifactId>npclib-nms-v1_13_R1</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.jitse</groupId>
|
||||||
|
<artifactId>npclib-nms-v1_13_R2</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.jitse</groupId>
|
||||||
|
<artifactId>npclib-nms-v1_14_R1</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
|
@ -23,14 +105,20 @@
|
||||||
</includes>
|
</includes>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
</project>
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
|
||||||
<artifactId>npclib-api</artifactId>
|
|
||||||
<version>${project.parent.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</project>
|
|
|
@ -6,18 +6,10 @@ package net.jitse.npclib.plugin;
|
||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Jitse Boonstra
|
|
||||||
*/
|
|
||||||
public class NPCLibPlugin extends JavaPlugin {
|
public class NPCLibPlugin extends JavaPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
getLogger().info("NPCLib classes loaded");
|
getLogger().info("NPCLib classes loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDisable() {
|
|
||||||
getLogger().info("NPCLib classes unloaded");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: NPCLib-Plugin
|
name: NPCLibPlugin
|
||||||
version: ${project.parent.version}
|
version: ${project.parent.version}
|
||||||
author: JitseB
|
author: JitseB
|
||||||
main: net.jitse.npclib.plugin.NPCLibPlugin
|
description: Dummy plugin for easy class-loading.
|
||||||
description: Basic non-player character library.
|
main: net.jitse.npclib.plugin.NPCLibPlugin
|
94
pom.xml
94
pom.xml
|
@ -2,19 +2,20 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib</artifactId>
|
<artifactId>npclib</artifactId>
|
||||||
<version>1.5-SNAPSHOT</version>
|
<version>2.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<scm>
|
<properties>
|
||||||
<url>git@github.com:JitseB/NPCLib.git</url>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<connection>scm:git:git@github.com:JitseB/NPClib.git</connection>
|
</properties>
|
||||||
<developerConnection>scm:git:git@github.com:JitseB/NPCLib.git</developerConnection>
|
|
||||||
</scm>
|
<name>NPCLib</name>
|
||||||
|
<url>https://github.com/JitseB/NPCLib</url>
|
||||||
|
<description>Basic non-player character library for Minecraft.</description>
|
||||||
|
|
||||||
<developers>
|
<developers>
|
||||||
<developer>
|
<developer>
|
||||||
|
@ -23,13 +24,25 @@
|
||||||
</developer>
|
</developer>
|
||||||
</developers>
|
</developers>
|
||||||
|
|
||||||
<name>NPCLib</name>
|
<licenses>
|
||||||
<url>https://github.com/JitseB/NPCLib</url>
|
<license>
|
||||||
<description>Basic non-player character library for Minecraft.</description>
|
<name>MIT</name>
|
||||||
|
<url>https://opensource.org/licenses/MIT</url>
|
||||||
|
<distribution>repo</distribution>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
|
||||||
<properties>
|
<modules>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<module>api</module>
|
||||||
</properties>
|
<module>nms</module>
|
||||||
|
<module>plugin</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
<scm>
|
||||||
|
<url>git@github.com:JitseB/NPCLib.git</url>
|
||||||
|
<connection>scm:git:git@github.com:JitseB/NPClib.git</connection>
|
||||||
|
<developerConnection>scm:git:git@github.com:JitseB/NPCLib.git</developerConnection>
|
||||||
|
</scm>
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<snapshotRepository>
|
<snapshotRepository>
|
||||||
|
@ -42,34 +55,21 @@
|
||||||
</repository>
|
</repository>
|
||||||
</distributionManagement>
|
</distributionManagement>
|
||||||
|
|
||||||
<licenses>
|
|
||||||
<license>
|
|
||||||
<name>MIT</name>
|
|
||||||
<url>https://opensource.org/licenses/MIT</url>
|
|
||||||
<distribution>repo</distribution>
|
|
||||||
</license>
|
|
||||||
</licenses>
|
|
||||||
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>spigot-repo</id>
|
|
||||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<!--Spigot API-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.spigotmc</groupId>
|
|
||||||
<artifactId>spigot-api</artifactId>
|
|
||||||
<version>1.13.2-R0.1-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<defaultGoal>clean install</defaultGoal>
|
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
<version>2.2.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>attach-sources</id>
|
||||||
|
<goals>
|
||||||
|
<goal>jar-no-fork</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
@ -82,6 +82,7 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-gpg-plugin</artifactId>
|
<artifactId>maven-gpg-plugin</artifactId>
|
||||||
|
<version>1.5</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>sign-artifacts</id>
|
<id>sign-artifacts</id>
|
||||||
|
@ -105,19 +106,4 @@
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<modules>
|
|
||||||
<module>commons</module>
|
|
||||||
<module>nms/v1_8_R1</module>
|
|
||||||
<module>nms/v1_8_R2</module>
|
|
||||||
<module>nms/v1_8_R3</module>
|
|
||||||
<module>nms/v1_9_R1</module>
|
|
||||||
<module>nms/v1_9_R2</module>
|
|
||||||
<module>nms/v1_10_R1</module>
|
|
||||||
<module>nms/v1_11_R1</module>
|
|
||||||
<module>nms/v1_12_R1</module>
|
|
||||||
<module>nms/v1_13_R1</module>
|
|
||||||
<module>nms/v1_13_R2</module>
|
|
||||||
<module>plugin</module>
|
|
||||||
</modules>
|
|
||||||
</project>
|
</project>
|
Loading…
Reference in New Issue