Merge pull request #52 from MrMicky-FR/master
Add 1.15 support and cleanup some code
This commit is contained in:
@@ -17,5 +17,6 @@ install:
|
|||||||
- ls $HOME/.m2/repository/org/spigotmc/spigot/1.13-R0.1-SNAPSHOT >> /dev/null 2>&1 || java -jar BuildTools.jar --rev 1.13 >> /dev/null 2>&1
|
- ls $HOME/.m2/repository/org/spigotmc/spigot/1.13-R0.1-SNAPSHOT >> /dev/null 2>&1 || java -jar BuildTools.jar --rev 1.13 >> /dev/null 2>&1
|
||||||
- ls $HOME/.m2/repository/org/spigotmc/spigot/1.13.2-R0.1-SNAPSHOT >> /dev/null 2>&1 || java -jar BuildTools.jar --rev 1.13.2 >> /dev/null 2>&1
|
- ls $HOME/.m2/repository/org/spigotmc/spigot/1.13.2-R0.1-SNAPSHOT >> /dev/null 2>&1 || java -jar BuildTools.jar --rev 1.13.2 >> /dev/null 2>&1
|
||||||
- ls $HOME/.m2/repository/org/spigotmc/spigot/1.14.4-R0.1-SNAPSHOT >> /dev/null 2>&1 || java -jar BuildTools.jar --rev 1.14.4 >> /dev/null 2>&1
|
- ls $HOME/.m2/repository/org/spigotmc/spigot/1.14.4-R0.1-SNAPSHOT >> /dev/null 2>&1 || java -jar BuildTools.jar --rev 1.14.4 >> /dev/null 2>&1
|
||||||
|
- ls $HOME/.m2/repository/org/spigotmc/spigot/1.15.2-R0.1-SNAPSHOT >> /dev/null 2>&1 || java -jar BuildTools.jar --rev 1.15.2 >> /dev/null 2>&1
|
||||||
script:
|
script:
|
||||||
- mvn clean install
|
- mvn clean install
|
||||||
Executable → Regular
+12
-18
@@ -6,6 +6,7 @@ package com.comphenix.tinyprotocol;
|
|||||||
|
|
||||||
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 com.mojang.authlib.GameProfile;
|
||||||
import io.netty.channel.*;
|
import io.netty.channel.*;
|
||||||
import net.jitse.npclib.NPCLib;
|
import net.jitse.npclib.NPCLib;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -26,7 +27,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
* Minimized version of TinyProtocol by Kristian suited for NPCLib.
|
* Minimized version of TinyProtocol by Kristian suited for NPCLib.
|
||||||
*/
|
*/
|
||||||
public abstract class TinyProtocol {
|
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
|
||||||
@@ -44,8 +44,7 @@ public abstract class TinyProtocol {
|
|||||||
|
|
||||||
// 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 Reflection.FieldAccessor getGameProfile = Reflection.getField(PACKET_LOGIN_IN_START,
|
private static final Reflection.FieldAccessor<GameProfile> getGameProfile = Reflection.getField(PACKET_LOGIN_IN_START, GameProfile.class, 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();
|
||||||
@@ -85,7 +84,7 @@ public abstract class TinyProtocol {
|
|||||||
instance.getLogger().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 ex) {
|
||||||
// Damn you, late bind
|
// Damn you, late bind
|
||||||
instance.getLogger().warning("Attempting to delay injection");
|
instance.getLogger().warning("Attempting to delay injection");
|
||||||
|
|
||||||
@@ -115,9 +114,8 @@ public abstract class TinyProtocol {
|
|||||||
channel.eventLoop().submit(() -> injectChannelInternal(channel));
|
channel.eventLoop().submit(() -> injectChannelInternal(channel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception exception) {
|
} catch (Exception e) {
|
||||||
instance.getLogger().severe("Cannot inject incomming channel " + channel + ". Message: "
|
instance.getLogger().severe("Cannot inject incomming channel " + channel, e);
|
||||||
+ exception.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,9 +124,8 @@ public abstract class TinyProtocol {
|
|||||||
// This is executed before Minecraft's channel handler
|
// This is executed before Minecraft's channel handler
|
||||||
beginInitProtocol = new ChannelInitializer<Channel>() {
|
beginInitProtocol = new ChannelInitializer<Channel>() {
|
||||||
|
|
||||||
@SuppressWarnings("all")
|
|
||||||
@Override
|
@Override
|
||||||
protected void initChannel(Channel channel) throws Exception {
|
protected void initChannel(Channel channel) {
|
||||||
channel.pipeline().addLast(endInitProtocol);
|
channel.pipeline().addLast(endInitProtocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,9 +133,8 @@ public abstract class TinyProtocol {
|
|||||||
|
|
||||||
serverChannelHandler = new ChannelInboundHandlerAdapter() {
|
serverChannelHandler = new ChannelInboundHandlerAdapter() {
|
||||||
|
|
||||||
@SuppressWarnings("all")
|
|
||||||
@Override
|
@Override
|
||||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
public void channelRead(ChannelHandlerContext ctx, Object msg) {
|
||||||
Channel channel = (Channel) msg;
|
Channel channel = (Channel) msg;
|
||||||
|
|
||||||
// Prepare to initialize ths channel
|
// Prepare to initialize ths channel
|
||||||
@@ -152,7 +148,6 @@ public abstract class TinyProtocol {
|
|||||||
private void registerBukkitEvents() {
|
private void registerBukkitEvents() {
|
||||||
listener = new Listener() {
|
listener = new Listener() {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public final void onPlayerLogin(PlayerLoginEvent e) {
|
public final void onPlayerLogin(PlayerLoginEvent e) {
|
||||||
if (closed)
|
if (closed)
|
||||||
@@ -166,7 +161,6 @@ public abstract class TinyProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public final void onPluginDisable(PluginDisableEvent e) {
|
public final void onPluginDisable(PluginDisableEvent e) {
|
||||||
if (e.getPlugin().equals(plugin)) {
|
if (e.getPlugin().equals(plugin)) {
|
||||||
@@ -251,7 +245,7 @@ public abstract class TinyProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return interceptor;
|
return interceptor;
|
||||||
} catch (IllegalArgumentException exception) {
|
} catch (IllegalArgumentException e) {
|
||||||
// Try again
|
// Try again
|
||||||
return (PacketInterceptor) channel.pipeline().get(handlerName);
|
return (PacketInterceptor) channel.pipeline().get(handlerName);
|
||||||
}
|
}
|
||||||
@@ -305,8 +299,8 @@ public abstract class TinyProtocol {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
msg = onPacketInAsync(player, msg);
|
msg = onPacketInAsync(player, msg);
|
||||||
} catch (Exception exception) {
|
} catch (Exception e) {
|
||||||
instance.getLogger().severe("Error in onPacketInAsync(). Message: " + exception.getMessage());
|
instance.getLogger().severe("Error in onPacketInAsync().", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
@@ -316,8 +310,8 @@ public abstract class TinyProtocol {
|
|||||||
|
|
||||||
private void handleLoginStart(Channel channel, Object packet) {
|
private void handleLoginStart(Channel channel, Object packet) {
|
||||||
if (PACKET_LOGIN_IN_START.isInstance(packet)) {
|
if (PACKET_LOGIN_IN_START.isInstance(packet)) {
|
||||||
Object profile = getGameProfile.get(packet);
|
GameProfile profile = getGameProfile.get(packet);
|
||||||
channelLookup.put((String) Reflection.getMethod(profile.getClass(), "getName").invoke(profile), channel);
|
channelLookup.put(profile.getName(), channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,8 +39,7 @@ public final class NPCLib {
|
|||||||
this.npcClass = npcClass;
|
this.npcClass = npcClass;
|
||||||
|
|
||||||
if (npcClass == null) {
|
if (npcClass == null) {
|
||||||
logger.severe("Failed to initiate. Your server's version ("
|
logger.severe("Failed to initiate. Your server's version (" + versionName + ") is not supported");
|
||||||
+ versionName + ") is not supported");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +95,7 @@ public final class NPCLib {
|
|||||||
try {
|
try {
|
||||||
return (NPC) npcClass.getConstructors()[0].newInstance(this, text);
|
return (NPC) npcClass.getConstructors()[0].newInstance(this, text);
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
logger.warning("Failed to create NPC. Please report the following stacktrace message: " + exception.getMessage());
|
logger.warning("Failed to create NPC. Please report the following stacktrace message", exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ public class NPCHideEvent extends Event implements Cancellable {
|
|||||||
return cancelled;
|
return cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ public class NPCInteractEvent extends Event {
|
|||||||
return this.npc;
|
return this.npc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ public class NPCShowEvent extends Event implements Cancellable {
|
|||||||
return cancelled;
|
return cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,13 @@ 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;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
@@ -20,10 +21,10 @@ import java.util.Scanner;
|
|||||||
public class MineSkinFetcher {
|
public class MineSkinFetcher {
|
||||||
|
|
||||||
private static final String MINESKIN_API = "https://api.mineskin.org/get/id/";
|
private static final String MINESKIN_API = "https://api.mineskin.org/get/id/";
|
||||||
private static final ExecutorService threadPool = Executors.newSingleThreadExecutor();
|
private static final ExecutorService EXECUTOR = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
public static void fetchSkinFromIdAsync(int id, Callback callback) {
|
public static void fetchSkinFromIdAsync(int id, Callback callback) {
|
||||||
threadPool.execute(() -> {
|
EXECUTOR.execute(() -> {
|
||||||
try {
|
try {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(MINESKIN_API + id).openConnection();
|
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(MINESKIN_API + id).openConnection();
|
||||||
@@ -47,7 +48,7 @@ public class MineSkinFetcher {
|
|||||||
|
|
||||||
callback.call(new Skin(value, signature));
|
callback.call(new Skin(value, signature));
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Could not fetch skin! (Id: " + id + "). Message: " + exception.getMessage());
|
Bukkit.getLogger().severe("Could not fetch skin! (Id: " + id + "). Message: " + exception.getMessage());
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
callback.failed();
|
callback.failed();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,20 +2,30 @@ package net.jitse.npclib.api.state;
|
|||||||
|
|
||||||
public enum NPCSlot {
|
public enum NPCSlot {
|
||||||
|
|
||||||
HELMET(4),
|
HELMET(4, "HEAD"),
|
||||||
CHESTPLATE(3),
|
CHESTPLATE(3, "CHEST"),
|
||||||
LEGGINGS(2),
|
LEGGINGS(2, "LEGS"),
|
||||||
BOOTS(1),
|
BOOTS(1, "FEET"),
|
||||||
MAINHAND(0),
|
MAINHAND(0, "MAINHAND"),
|
||||||
OFFHAND(5);
|
OFFHAND(5, "OFFHAND");
|
||||||
|
|
||||||
int slot;
|
private final int slot;
|
||||||
|
private final String nmsName;
|
||||||
|
|
||||||
NPCSlot(int slot) {
|
NPCSlot(int slot, String nmsName) {
|
||||||
this.slot = slot;
|
this.slot = slot;
|
||||||
|
this.nmsName = nmsName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSlot() {
|
public int getSlot() {
|
||||||
return slot;
|
return slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getNmsName() {
|
||||||
|
return nmsName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <E extends Enum<E>> E getNmsEnum(Class<E> nmsEnumClass) {
|
||||||
|
return Enum.valueOf(nmsEnumClass, this.nmsName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
package net.jitse.npclib.api.state;
|
package net.jitse.npclib.api.state;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public enum NPCState {
|
public enum NPCState {
|
||||||
|
|
||||||
ON_FIRE((byte) 1),
|
ON_FIRE((byte) 1),
|
||||||
CROUCHED((byte) 2),
|
CROUCHED((byte) 2),
|
||||||
INVISIBLE((byte) 32);
|
INVISIBLE((byte) 32);
|
||||||
|
|
||||||
private byte b;
|
private final byte b;
|
||||||
|
|
||||||
NPCState(byte b) {
|
NPCState(byte b) {
|
||||||
this.b = b;
|
this.b = b;
|
||||||
@@ -16,10 +18,15 @@ public enum NPCState {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte getMasked(final NPCState... status) {
|
public static byte getMasked(NPCState... states) {
|
||||||
byte b = 0;
|
byte mask = 0;
|
||||||
for (NPCState s : status) b |= s.getByte();
|
for (NPCState state : states) mask |= state.getByte();
|
||||||
return b;
|
return mask;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static byte getMasked(Collection<NPCState> states) {
|
||||||
|
byte mask = 0;
|
||||||
|
for (NPCState state : states) mask |= state.getByte();
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ package net.jitse.npclib.api.utilities;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class Logger {
|
public class Logger {
|
||||||
|
|
||||||
private final String prefix;
|
private final String prefix;
|
||||||
@@ -21,26 +23,34 @@ public class Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void info(String info) {
|
public void info(String info) {
|
||||||
if (!enabled) {
|
log(Level.INFO, info);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Bukkit.getLogger().info(prefix + info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void warning(String warning) {
|
public void warning(String warning) {
|
||||||
if (!enabled) {
|
log(Level.WARNING, warning);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getLogger().warning(prefix + warning);
|
public void warning(String warning, Throwable throwable) {
|
||||||
|
log(Level.WARNING, warning, throwable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void severe(String severe) {
|
public void severe(String severe) {
|
||||||
if (!enabled) {
|
log(Level.SEVERE, severe);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getLogger().severe(prefix + severe);
|
public void severe(String severe, Throwable throwable) {
|
||||||
|
log(Level.SEVERE, severe, throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void log(Level level, String message) {
|
||||||
|
if (enabled) {
|
||||||
|
Bukkit.getLogger().log(level, prefix + message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void log(Level level, String message, Throwable throwable) {
|
||||||
|
if (enabled) {
|
||||||
|
Bukkit.getLogger().log(level, prefix + message, throwable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class Hologram {
|
|||||||
.getConstructor(PACKET_PLAY_OUT_ENTITY_METADATA_CLAZZ, int.class, DATAWATCHER_CLAZZ, boolean.class);
|
.getConstructor(PACKET_PLAY_OUT_ENTITY_METADATA_CLAZZ, int.class, DATAWATCHER_CLAZZ, boolean.class);
|
||||||
|
|
||||||
// Fields:
|
// Fields:
|
||||||
private static final Reflection.FieldAccessor playerConnectionField = Reflection.getField(ENTITY_PLAYER_CLAZZ,
|
private static final Reflection.FieldAccessor<?> playerConnectionField = Reflection.getField(ENTITY_PLAYER_CLAZZ,
|
||||||
"playerConnection", PLAYER_CONNECTION_CLAZZ);
|
"playerConnection", PLAYER_CONNECTION_CLAZZ);
|
||||||
|
|
||||||
// Methods:
|
// Methods:
|
||||||
@@ -92,8 +92,7 @@ public class Hologram {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createPackets() {
|
private void createPackets() {
|
||||||
// TODO: Check when this method was changed (1.9 R2 is giving an exception...)
|
Reflection.MethodInvoker gravityMethod = (version.isAboveOrEqual(MinecraftVersion.V1_10_R1) ?
|
||||||
Reflection.MethodInvoker gravityMethod = (version.isAboveOrEqual(MinecraftVersion.V1_9_R2) ?
|
|
||||||
Reflection.getMethod(ENTITY_CLAZZ, "setNoGravity", boolean.class) :
|
Reflection.getMethod(ENTITY_CLAZZ, "setNoGravity", boolean.class) :
|
||||||
Reflection.getMethod(ENTITY_ARMOR_STAND_CLAZZ, "setGravity", boolean.class));
|
Reflection.getMethod(ENTITY_ARMOR_STAND_CLAZZ, "setGravity", boolean.class));
|
||||||
|
|
||||||
@@ -213,4 +212,3 @@ public class Hologram {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,17 @@ package net.jitse.npclib.internal;
|
|||||||
|
|
||||||
public enum MinecraftVersion {
|
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;
|
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,
|
||||||
|
V1_15_R1;
|
||||||
|
|
||||||
public boolean isAboveOrEqual(MinecraftVersion compare) {
|
public boolean isAboveOrEqual(MinecraftVersion compare) {
|
||||||
return ordinal() >= compare.ordinal();
|
return ordinal() >= compare.ordinal();
|
||||||
|
|||||||
@@ -29,12 +29,13 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
|
|||||||
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 String name = uuid.toString().replace("-", "").substring(0, 10);
|
||||||
protected final GameProfile gameProfile = new GameProfile(uuid, name);
|
protected final GameProfile gameProfile = new GameProfile(uuid, name);
|
||||||
|
protected final Set<UUID> hasTeamRegistered = new HashSet<>();
|
||||||
|
protected final Set<NPCState> activeStates = EnumSet.noneOf(NPCState.class);
|
||||||
|
|
||||||
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 double cosFOV = Math.cos(Math.toRadians(60));
|
protected double cosFOV = Math.cos(Math.toRadians(60));
|
||||||
protected NPCState[] activeStates = new NPCState[]{};
|
|
||||||
|
|
||||||
protected NPCLib instance;
|
protected NPCLib instance;
|
||||||
protected List<String> text;
|
protected List<String> text;
|
||||||
@@ -42,8 +43,7 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
|
|||||||
protected Skin skin;
|
protected Skin skin;
|
||||||
protected Hologram hologram;
|
protected Hologram hologram;
|
||||||
|
|
||||||
// offHand support in 1.9 R1 and later.
|
protected final Map<NPCSlot, ItemStack> items = new EnumMap<>(NPCSlot.class);
|
||||||
protected ItemStack helmet, chestplate, leggings, boots, inHand, offHand;
|
|
||||||
|
|
||||||
public NPCBase(NPCLib instance, List<String> text) {
|
public NPCBase(NPCLib instance, List<String> text) {
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
@@ -136,6 +136,7 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
|
|||||||
public void onLogout(Player player) {
|
public void onLogout(Player player) {
|
||||||
getAutoHidden().remove(player.getUniqueId());
|
getAutoHidden().remove(player.getUniqueId());
|
||||||
getShown().remove(player.getUniqueId()); // Don't need to use NPC#hide since the entity is not registered in the NMS server.
|
getShown().remove(player.getUniqueId()); // Don't need to use NPC#hide since the entity is not registered in the NMS server.
|
||||||
|
hasTeamRegistered.remove(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -165,7 +166,7 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
|
|||||||
sendEquipmentPackets(player);
|
sendEquipmentPackets(player);
|
||||||
} else {
|
} else {
|
||||||
if (isShown(player)) {
|
if (isShown(player)) {
|
||||||
throw new RuntimeException("Cannot call show method twice.");
|
throw new IllegalStateException("Cannot call show method twice.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shown.contains(player.getUniqueId())) {
|
if (shown.contains(player.getUniqueId())) {
|
||||||
@@ -206,7 +207,7 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
|
|||||||
sendHidePackets(player);
|
sendHidePackets(player);
|
||||||
} else {
|
} else {
|
||||||
if (!shown.contains(player.getUniqueId())) {
|
if (!shown.contains(player.getUniqueId())) {
|
||||||
throw new RuntimeException("Cannot call hide method without calling NPC#show.");
|
throw new IllegalStateException("Cannot call hide method without calling NPC#show.");
|
||||||
}
|
}
|
||||||
|
|
||||||
shown.remove(player.getUniqueId());
|
shown.remove(player.getUniqueId());
|
||||||
@@ -222,47 +223,15 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getState(NPCState state) {
|
public boolean getState(NPCState state) {
|
||||||
if (activeStates.length != 0) {
|
return activeStates.contains(state);
|
||||||
for (int i = 0; i < activeStates.length; i++) {
|
|
||||||
if (activeStates[i] == state) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NPC toggleState(NPCState state) {
|
public NPC toggleState(NPCState state) {
|
||||||
int inActiveStatesIndex = -1;
|
if (activeStates.contains(state)) {
|
||||||
if (activeStates.length == 0) { // If there're no active states, this is the first to be toggled (on).
|
activeStates.remove(state);
|
||||||
activeStates = new NPCState[]{state};
|
|
||||||
} else { // Otherwise, there have been states that were toggled, check if we need to toggle something off.
|
|
||||||
for (int i = 0; i < activeStates.length; i++) {
|
|
||||||
if (activeStates[i] == state) { // If the state is to be toggled off, save the index so we can remove it.
|
|
||||||
inActiveStatesIndex = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inActiveStatesIndex > -1) { // If there's a state to be toggled of, create a new array with all items but the one to be toggled off.
|
|
||||||
NPCState[] newArr = new NPCState[activeStates.length - 1];
|
|
||||||
for (int i = 0; i < newArr.length; i++) {
|
|
||||||
if (inActiveStatesIndex == i) {
|
|
||||||
continue;
|
|
||||||
} else if (i < inActiveStatesIndex) {
|
|
||||||
newArr[i] = activeStates[i];
|
|
||||||
} else {
|
} else {
|
||||||
newArr[i] = activeStates[i + 1];
|
activeStates.add(state);
|
||||||
}
|
|
||||||
}
|
|
||||||
activeStates = newArr;
|
|
||||||
} else { // Else, we need to add a state by appending our state to the array.
|
|
||||||
NPCState[] newArr = new NPCState[activeStates.length + 1];
|
|
||||||
System.arraycopy(activeStates, 0, newArr, 0, activeStates.length);
|
|
||||||
newArr[activeStates.length] = state;
|
|
||||||
activeStates = newArr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send a new metadata packet to all players that can see the NPC.
|
// Send a new metadata packet to all players that can see the NPC.
|
||||||
@@ -277,55 +246,16 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getItem(NPCSlot slot) {
|
public ItemStack getItem(NPCSlot slot) {
|
||||||
if (slot == null) {
|
Objects.requireNonNull(slot, "Slot cannot be null");
|
||||||
throw new NullPointerException("Slot cannot be null");
|
|
||||||
}
|
return items.get(slot);
|
||||||
switch (slot) {
|
|
||||||
case HELMET:
|
|
||||||
return this.helmet;
|
|
||||||
case CHESTPLATE:
|
|
||||||
return this.chestplate;
|
|
||||||
case LEGGINGS:
|
|
||||||
return this.leggings;
|
|
||||||
case BOOTS:
|
|
||||||
return this.boots;
|
|
||||||
case MAINHAND:
|
|
||||||
return this.inHand;
|
|
||||||
case OFFHAND:
|
|
||||||
return this.offHand;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("Entered an invalid inventory slot");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NPC setItem(NPCSlot slot, ItemStack item) {
|
public NPC setItem(NPCSlot slot, ItemStack item) {
|
||||||
if (slot == null) {
|
Objects.requireNonNull(slot, "Slot cannot be null");
|
||||||
throw new NullPointerException("Slot cannot be null");
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (slot) {
|
items.put(slot, item);
|
||||||
case HELMET:
|
|
||||||
this.helmet = item;
|
|
||||||
break;
|
|
||||||
case CHESTPLATE:
|
|
||||||
this.chestplate = item;
|
|
||||||
break;
|
|
||||||
case LEGGINGS:
|
|
||||||
this.leggings = item;
|
|
||||||
break;
|
|
||||||
case BOOTS:
|
|
||||||
this.boots = item;
|
|
||||||
break;
|
|
||||||
case MAINHAND:
|
|
||||||
this.inHand = item;
|
|
||||||
break;
|
|
||||||
case OFFHAND:
|
|
||||||
this.offHand = item;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("Entered an invalid inventory slot");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (UUID shownUuid : shown) {
|
for (UUID shownUuid : shown) {
|
||||||
Player player = Bukkit.getPlayer(shownUuid);
|
Player player = Bukkit.getPlayer(shownUuid);
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class ChunkListener implements Listener {
|
|||||||
Chunk chunk = event.getChunk();
|
Chunk chunk = event.getChunk();
|
||||||
|
|
||||||
for (NPCBase npc : NPCManager.getAllNPCs()) {
|
for (NPCBase npc : NPCManager.getAllNPCs()) {
|
||||||
if (!isSameChunk(npc.getLocation(), chunk))
|
if (npc.getLocation() == null || !isSameChunk(npc.getLocation(), chunk))
|
||||||
continue; // The NPC is not in the loaded chunk.
|
continue; // The NPC is not in the loaded chunk.
|
||||||
|
|
||||||
// The chunk being loaded has this NPC in it. Showing it to all the players again.
|
// The chunk being loaded has this NPC in it. Showing it to all the players again.
|
||||||
@@ -90,7 +90,6 @@ public class ChunkListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static int getChunkCoordinate(int coordinate) {
|
private static int getChunkCoordinate(int coordinate) {
|
||||||
return coordinate >> 4;
|
return coordinate >> 4;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -29,8 +28,8 @@ public class PacketListener {
|
|||||||
private final Class<?> packetPlayInUseEntityClazz = Reflection.getMinecraftClass("PacketPlayInUseEntity");
|
private final Class<?> packetPlayInUseEntityClazz = Reflection.getMinecraftClass("PacketPlayInUseEntity");
|
||||||
|
|
||||||
// Fields:
|
// Fields:
|
||||||
private final Reflection.FieldAccessor entityIdField = Reflection.getField(packetPlayInUseEntityClazz, "a", int.class);
|
private final Reflection.FieldAccessor<Integer> entityIdField = Reflection.getField(packetPlayInUseEntityClazz, "a", int.class);
|
||||||
private final Reflection.FieldAccessor actionField = Reflection.getField(packetPlayInUseEntityClazz, "action", Object.class);
|
private final Reflection.FieldAccessor<?> actionField = Reflection.getField(packetPlayInUseEntityClazz, "action", Object.class);
|
||||||
|
|
||||||
// Prevent players from clicking at very high speeds.
|
// Prevent players from clicking at very high speeds.
|
||||||
private final Set<UUID> delay = new HashSet<>();
|
private final Set<UUID> delay = new HashSet<>();
|
||||||
@@ -54,7 +53,7 @@ public class PacketListener {
|
|||||||
return true; // We aren't handling the packet.
|
return true; // We aren't handling the packet.
|
||||||
|
|
||||||
NPCBase npc = null;
|
NPCBase npc = null;
|
||||||
int packetEntityId = (int) entityIdField.get(packet);
|
int packetEntityId = entityIdField.get(packet);
|
||||||
|
|
||||||
// Not using streams here is an intentional choice.
|
// Not using streams here is an intentional choice.
|
||||||
// Packet listeners is one of the few places where it is important to write optimized code.
|
// Packet listeners is one of the few places where it is important to write optimized code.
|
||||||
@@ -102,7 +101,7 @@ public class PacketListener {
|
|||||||
public void run() {
|
public void run() {
|
||||||
Player player = eventToCall.getWhoClicked();
|
Player player = eventToCall.getWhoClicked();
|
||||||
this.listener.delay.remove(player.getUniqueId()); // Remove the NPC from the interact cooldown.
|
this.listener.delay.remove(player.getUniqueId()); // Remove the NPC from the interact cooldown.
|
||||||
if (!Objects.equals(player.getWorld(), eventToCall.getNPC().getWorld()))
|
if (!player.getWorld().equals(eventToCall.getNPC().getWorld()))
|
||||||
return; // If the NPC and player are not in the same world, abort!
|
return; // If the NPC and player are not in the same world, abort!
|
||||||
|
|
||||||
double distance = player.getLocation(playerLocation).distanceSquared(eventToCall.getNPC().getLocation());
|
double distance = player.getLocation(playerLocation).distanceSquared(eventToCall.getNPC().getLocation());
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
<module>v1_13_R1</module>
|
<module>v1_13_R1</module>
|
||||||
<module>v1_13_R2</module>
|
<module>v1_13_R2</module>
|
||||||
<module>v1_14_R1</module>
|
<module>v1_14_R1</module>
|
||||||
|
<module>v1_15_R1</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -17,10 +17,7 @@ import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
@@ -32,7 +29,6 @@ public class NPC_v1_10_R1 extends NPCBase {
|
|||||||
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
private Set<UUID> hasTeamRegistered = new HashSet<>();
|
|
||||||
|
|
||||||
public NPC_v1_10_R1(NPCLib instance, List<String> lines) {
|
public NPC_v1_10_R1(NPCLib instance, List<String> lines) {
|
||||||
super(instance, lines);
|
super(instance, lines);
|
||||||
@@ -64,12 +60,6 @@ public class NPC_v1_10_R1 extends NPCBase {
|
|||||||
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
|
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLogout(Player player) {
|
|
||||||
super.onLogout(player);
|
|
||||||
hasTeamRegistered.remove(player.getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendShowPackets(Player player) {
|
public void sendShowPackets(Player player) {
|
||||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
@@ -108,39 +98,8 @@ public class NPC_v1_10_R1 extends NPCBase {
|
|||||||
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
|
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
|
||||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
|
|
||||||
EnumItemSlot nmsSlot;
|
EnumItemSlot nmsSlot = slot.getNmsEnum(EnumItemSlot.class);
|
||||||
ItemStack item;
|
ItemStack item = getItem(slot);
|
||||||
switch (slot) {
|
|
||||||
case HELMET:
|
|
||||||
item = helmet;
|
|
||||||
nmsSlot = EnumItemSlot.HEAD;
|
|
||||||
break;
|
|
||||||
case CHESTPLATE:
|
|
||||||
item = chestplate;
|
|
||||||
nmsSlot = EnumItemSlot.CHEST;
|
|
||||||
break;
|
|
||||||
case LEGGINGS:
|
|
||||||
item = leggings;
|
|
||||||
nmsSlot = EnumItemSlot.LEGS;
|
|
||||||
break;
|
|
||||||
case BOOTS:
|
|
||||||
item = boots;
|
|
||||||
nmsSlot = EnumItemSlot.FEET;
|
|
||||||
break;
|
|
||||||
case MAINHAND:
|
|
||||||
item = inHand;
|
|
||||||
nmsSlot = EnumItemSlot.MAINHAND;
|
|
||||||
break;
|
|
||||||
case OFFHAND:
|
|
||||||
item = offHand;
|
|
||||||
nmsSlot = EnumItemSlot.OFFHAND;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (!auto) {
|
|
||||||
throw new IllegalArgumentException(slot.toString() + " is not a supported slot for the version of your server");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item));
|
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item));
|
||||||
playerConnection.sendPacket(packet);
|
playerConnection.sendPacket(packet);
|
||||||
|
|||||||
+3
-1
@@ -6,9 +6,11 @@ import net.minecraft.server.v1_10_R1.DataWatcherObject;
|
|||||||
import net.minecraft.server.v1_10_R1.DataWatcherRegistry;
|
import net.minecraft.server.v1_10_R1.DataWatcherRegistry;
|
||||||
import net.minecraft.server.v1_10_R1.PacketPlayOutEntityMetadata;
|
import net.minecraft.server.v1_10_R1.PacketPlayOutEntityMetadata;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public class PacketPlayOutEntityMetadataWrapper {
|
public class PacketPlayOutEntityMetadataWrapper {
|
||||||
|
|
||||||
public PacketPlayOutEntityMetadata create(NPCState[] activateStates, int entityId) {
|
public PacketPlayOutEntityMetadata create(Collection<NPCState> activateStates, int entityId) {
|
||||||
DataWatcher dataWatcher = new DataWatcher(null);
|
DataWatcher dataWatcher = new DataWatcher(null);
|
||||||
byte masked = NPCState.getMasked(activateStates);
|
byte masked = NPCState.getMasked(activateStates);
|
||||||
dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), masked);
|
dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), masked);
|
||||||
|
|||||||
@@ -17,10 +17,7 @@ import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
@@ -32,7 +29,6 @@ public class NPC_v1_11_R1 extends NPCBase {
|
|||||||
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
private Set<UUID> hasTeamRegistered = new HashSet<>();
|
|
||||||
|
|
||||||
public NPC_v1_11_R1(NPCLib instance, List<String> lines) {
|
public NPC_v1_11_R1(NPCLib instance, List<String> lines) {
|
||||||
super(instance, lines);
|
super(instance, lines);
|
||||||
@@ -64,12 +60,6 @@ public class NPC_v1_11_R1 extends NPCBase {
|
|||||||
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
|
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLogout(Player player) {
|
|
||||||
super.onLogout(player);
|
|
||||||
hasTeamRegistered.remove(player.getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendShowPackets(Player player) {
|
public void sendShowPackets(Player player) {
|
||||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
@@ -108,39 +98,8 @@ public class NPC_v1_11_R1 extends NPCBase {
|
|||||||
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
|
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
|
||||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
|
|
||||||
EnumItemSlot nmsSlot;
|
EnumItemSlot nmsSlot = slot.getNmsEnum(EnumItemSlot.class);
|
||||||
ItemStack item;
|
ItemStack item = getItem(slot);
|
||||||
switch (slot) {
|
|
||||||
case HELMET:
|
|
||||||
item = helmet;
|
|
||||||
nmsSlot = EnumItemSlot.HEAD;
|
|
||||||
break;
|
|
||||||
case CHESTPLATE:
|
|
||||||
item = chestplate;
|
|
||||||
nmsSlot = EnumItemSlot.CHEST;
|
|
||||||
break;
|
|
||||||
case LEGGINGS:
|
|
||||||
item = leggings;
|
|
||||||
nmsSlot = EnumItemSlot.LEGS;
|
|
||||||
break;
|
|
||||||
case BOOTS:
|
|
||||||
item = boots;
|
|
||||||
nmsSlot = EnumItemSlot.FEET;
|
|
||||||
break;
|
|
||||||
case MAINHAND:
|
|
||||||
item = inHand;
|
|
||||||
nmsSlot = EnumItemSlot.MAINHAND;
|
|
||||||
break;
|
|
||||||
case OFFHAND:
|
|
||||||
item = offHand;
|
|
||||||
nmsSlot = EnumItemSlot.OFFHAND;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (!auto) {
|
|
||||||
throw new IllegalArgumentException(slot.toString() + " is not a supported slot for the version of your server");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item));
|
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item));
|
||||||
playerConnection.sendPacket(packet);
|
playerConnection.sendPacket(packet);
|
||||||
|
|||||||
+3
-1
@@ -6,9 +6,11 @@ import net.minecraft.server.v1_11_R1.DataWatcherObject;
|
|||||||
import net.minecraft.server.v1_11_R1.DataWatcherRegistry;
|
import net.minecraft.server.v1_11_R1.DataWatcherRegistry;
|
||||||
import net.minecraft.server.v1_11_R1.PacketPlayOutEntityMetadata;
|
import net.minecraft.server.v1_11_R1.PacketPlayOutEntityMetadata;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public class PacketPlayOutEntityMetadataWrapper {
|
public class PacketPlayOutEntityMetadataWrapper {
|
||||||
|
|
||||||
public PacketPlayOutEntityMetadata create(NPCState[] activateStates, int entityId) {
|
public PacketPlayOutEntityMetadata create(Collection<NPCState> activateStates, int entityId) {
|
||||||
DataWatcher dataWatcher = new DataWatcher(null);
|
DataWatcher dataWatcher = new DataWatcher(null);
|
||||||
byte masked = NPCState.getMasked(activateStates);
|
byte masked = NPCState.getMasked(activateStates);
|
||||||
dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), masked);
|
dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), masked);
|
||||||
|
|||||||
@@ -17,10 +17,7 @@ import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
@@ -32,7 +29,6 @@ public class NPC_v1_12_R1 extends NPCBase {
|
|||||||
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
private Set<UUID> hasTeamRegistered = new HashSet<>();
|
|
||||||
|
|
||||||
public NPC_v1_12_R1(NPCLib instance, List<String> lines) {
|
public NPC_v1_12_R1(NPCLib instance, List<String> lines) {
|
||||||
super(instance, lines);
|
super(instance, lines);
|
||||||
@@ -64,12 +60,6 @@ public class NPC_v1_12_R1 extends NPCBase {
|
|||||||
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
|
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLogout(Player player) {
|
|
||||||
super.onLogout(player);
|
|
||||||
hasTeamRegistered.remove(player.getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendShowPackets(Player player) {
|
public void sendShowPackets(Player player) {
|
||||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
@@ -108,39 +98,8 @@ public class NPC_v1_12_R1 extends NPCBase {
|
|||||||
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
|
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
|
||||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
|
|
||||||
EnumItemSlot nmsSlot;
|
EnumItemSlot nmsSlot = slot.getNmsEnum(EnumItemSlot.class);
|
||||||
ItemStack item;
|
ItemStack item = getItem(slot);
|
||||||
switch (slot) {
|
|
||||||
case HELMET:
|
|
||||||
item = helmet;
|
|
||||||
nmsSlot = EnumItemSlot.HEAD;
|
|
||||||
break;
|
|
||||||
case CHESTPLATE:
|
|
||||||
item = chestplate;
|
|
||||||
nmsSlot = EnumItemSlot.CHEST;
|
|
||||||
break;
|
|
||||||
case LEGGINGS:
|
|
||||||
item = leggings;
|
|
||||||
nmsSlot = EnumItemSlot.LEGS;
|
|
||||||
break;
|
|
||||||
case BOOTS:
|
|
||||||
item = boots;
|
|
||||||
nmsSlot = EnumItemSlot.FEET;
|
|
||||||
break;
|
|
||||||
case MAINHAND:
|
|
||||||
item = inHand;
|
|
||||||
nmsSlot = EnumItemSlot.MAINHAND;
|
|
||||||
break;
|
|
||||||
case OFFHAND:
|
|
||||||
item = offHand;
|
|
||||||
nmsSlot = EnumItemSlot.OFFHAND;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (!auto) {
|
|
||||||
throw new IllegalArgumentException(slot.toString() + " is not a supported slot for the version of your server");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item));
|
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item));
|
||||||
playerConnection.sendPacket(packet);
|
playerConnection.sendPacket(packet);
|
||||||
|
|||||||
+3
-1
@@ -6,9 +6,11 @@ import net.minecraft.server.v1_12_R1.DataWatcherObject;
|
|||||||
import net.minecraft.server.v1_12_R1.DataWatcherRegistry;
|
import net.minecraft.server.v1_12_R1.DataWatcherRegistry;
|
||||||
import net.minecraft.server.v1_12_R1.PacketPlayOutEntityMetadata;
|
import net.minecraft.server.v1_12_R1.PacketPlayOutEntityMetadata;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public class PacketPlayOutEntityMetadataWrapper {
|
public class PacketPlayOutEntityMetadataWrapper {
|
||||||
|
|
||||||
public PacketPlayOutEntityMetadata create(NPCState[] activateStates, int entityId) {
|
public PacketPlayOutEntityMetadata create(Collection<NPCState> activateStates, int entityId) {
|
||||||
DataWatcher dataWatcher = new DataWatcher(null);
|
DataWatcher dataWatcher = new DataWatcher(null);
|
||||||
byte masked = NPCState.getMasked(activateStates);
|
byte masked = NPCState.getMasked(activateStates);
|
||||||
dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), masked);
|
dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), masked);
|
||||||
|
|||||||
@@ -17,10 +17,7 @@ import org.bukkit.craftbukkit.v1_13_R1.inventory.CraftItemStack;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
@@ -32,7 +29,6 @@ public class NPC_v1_13_R1 extends NPCBase {
|
|||||||
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
private Set<UUID> hasTeamRegistered = new HashSet<>();
|
|
||||||
|
|
||||||
public NPC_v1_13_R1(NPCLib instance, List<String> lines) {
|
public NPC_v1_13_R1(NPCLib instance, List<String> lines) {
|
||||||
super(instance, lines);
|
super(instance, lines);
|
||||||
@@ -64,12 +60,6 @@ public class NPC_v1_13_R1 extends NPCBase {
|
|||||||
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
|
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLogout(Player player) {
|
|
||||||
super.onLogout(player);
|
|
||||||
hasTeamRegistered.remove(player.getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendShowPackets(Player player) {
|
public void sendShowPackets(Player player) {
|
||||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
@@ -108,39 +98,8 @@ public class NPC_v1_13_R1 extends NPCBase {
|
|||||||
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
|
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
|
||||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
|
|
||||||
EnumItemSlot nmsSlot;
|
EnumItemSlot nmsSlot = slot.getNmsEnum(EnumItemSlot.class);
|
||||||
ItemStack item;
|
ItemStack item = getItem(slot);
|
||||||
switch (slot) {
|
|
||||||
case HELMET:
|
|
||||||
item = helmet;
|
|
||||||
nmsSlot = EnumItemSlot.HEAD;
|
|
||||||
break;
|
|
||||||
case CHESTPLATE:
|
|
||||||
item = chestplate;
|
|
||||||
nmsSlot = EnumItemSlot.CHEST;
|
|
||||||
break;
|
|
||||||
case LEGGINGS:
|
|
||||||
item = leggings;
|
|
||||||
nmsSlot = EnumItemSlot.LEGS;
|
|
||||||
break;
|
|
||||||
case BOOTS:
|
|
||||||
item = boots;
|
|
||||||
nmsSlot = EnumItemSlot.FEET;
|
|
||||||
break;
|
|
||||||
case MAINHAND:
|
|
||||||
item = inHand;
|
|
||||||
nmsSlot = EnumItemSlot.MAINHAND;
|
|
||||||
break;
|
|
||||||
case OFFHAND:
|
|
||||||
item = offHand;
|
|
||||||
nmsSlot = EnumItemSlot.OFFHAND;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (!auto) {
|
|
||||||
throw new IllegalArgumentException(slot.toString() + " is not a supported slot for the version of your server");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item));
|
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item));
|
||||||
playerConnection.sendPacket(packet);
|
playerConnection.sendPacket(packet);
|
||||||
|
|||||||
+3
-1
@@ -6,9 +6,11 @@ import net.minecraft.server.v1_13_R1.DataWatcherObject;
|
|||||||
import net.minecraft.server.v1_13_R1.DataWatcherRegistry;
|
import net.minecraft.server.v1_13_R1.DataWatcherRegistry;
|
||||||
import net.minecraft.server.v1_13_R1.PacketPlayOutEntityMetadata;
|
import net.minecraft.server.v1_13_R1.PacketPlayOutEntityMetadata;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public class PacketPlayOutEntityMetadataWrapper {
|
public class PacketPlayOutEntityMetadataWrapper {
|
||||||
|
|
||||||
public PacketPlayOutEntityMetadata create(NPCState[] activateStates, int entityId) {
|
public PacketPlayOutEntityMetadata create(Collection<NPCState> activateStates, int entityId) {
|
||||||
DataWatcher dataWatcher = new DataWatcher(null);
|
DataWatcher dataWatcher = new DataWatcher(null);
|
||||||
byte masked = NPCState.getMasked(activateStates);
|
byte masked = NPCState.getMasked(activateStates);
|
||||||
dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), masked);
|
dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), masked);
|
||||||
|
|||||||
@@ -17,10 +17,7 @@ import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
@@ -32,7 +29,6 @@ public class NPC_v1_13_R2 extends NPCBase {
|
|||||||
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
private Set<UUID> hasTeamRegistered = new HashSet<>();
|
|
||||||
|
|
||||||
public NPC_v1_13_R2(NPCLib instance, List<String> lines) {
|
public NPC_v1_13_R2(NPCLib instance, List<String> lines) {
|
||||||
super(instance, lines);
|
super(instance, lines);
|
||||||
@@ -64,12 +60,6 @@ public class NPC_v1_13_R2 extends NPCBase {
|
|||||||
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
|
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLogout(Player player) {
|
|
||||||
super.onLogout(player);
|
|
||||||
hasTeamRegistered.remove(player.getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendShowPackets(Player player) {
|
public void sendShowPackets(Player player) {
|
||||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
@@ -108,39 +98,8 @@ public class NPC_v1_13_R2 extends NPCBase {
|
|||||||
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
|
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
|
||||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
|
|
||||||
EnumItemSlot nmsSlot;
|
EnumItemSlot nmsSlot = slot.getNmsEnum(EnumItemSlot.class);
|
||||||
ItemStack item;
|
ItemStack item = getItem(slot);
|
||||||
switch (slot) {
|
|
||||||
case HELMET:
|
|
||||||
item = helmet;
|
|
||||||
nmsSlot = EnumItemSlot.HEAD;
|
|
||||||
break;
|
|
||||||
case CHESTPLATE:
|
|
||||||
item = chestplate;
|
|
||||||
nmsSlot = EnumItemSlot.CHEST;
|
|
||||||
break;
|
|
||||||
case LEGGINGS:
|
|
||||||
item = leggings;
|
|
||||||
nmsSlot = EnumItemSlot.LEGS;
|
|
||||||
break;
|
|
||||||
case BOOTS:
|
|
||||||
item = boots;
|
|
||||||
nmsSlot = EnumItemSlot.FEET;
|
|
||||||
break;
|
|
||||||
case MAINHAND:
|
|
||||||
item = inHand;
|
|
||||||
nmsSlot = EnumItemSlot.MAINHAND;
|
|
||||||
break;
|
|
||||||
case OFFHAND:
|
|
||||||
item = offHand;
|
|
||||||
nmsSlot = EnumItemSlot.OFFHAND;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (!auto) {
|
|
||||||
throw new IllegalArgumentException(slot.toString() + " is not a supported slot for the version of your server");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item));
|
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item));
|
||||||
playerConnection.sendPacket(packet);
|
playerConnection.sendPacket(packet);
|
||||||
|
|||||||
+3
-1
@@ -6,9 +6,11 @@ import net.minecraft.server.v1_13_R2.DataWatcherObject;
|
|||||||
import net.minecraft.server.v1_13_R2.DataWatcherRegistry;
|
import net.minecraft.server.v1_13_R2.DataWatcherRegistry;
|
||||||
import net.minecraft.server.v1_13_R2.PacketPlayOutEntityMetadata;
|
import net.minecraft.server.v1_13_R2.PacketPlayOutEntityMetadata;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public class PacketPlayOutEntityMetadataWrapper {
|
public class PacketPlayOutEntityMetadataWrapper {
|
||||||
|
|
||||||
public PacketPlayOutEntityMetadata create(NPCState[] activateStates, int entityId) {
|
public PacketPlayOutEntityMetadata create(Collection<NPCState> activateStates, int entityId) {
|
||||||
DataWatcher dataWatcher = new DataWatcher(null);
|
DataWatcher dataWatcher = new DataWatcher(null);
|
||||||
byte masked = NPCState.getMasked(activateStates);
|
byte masked = NPCState.getMasked(activateStates);
|
||||||
dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), masked);
|
dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), masked);
|
||||||
|
|||||||
@@ -13,10 +13,7 @@ import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
@@ -28,7 +25,6 @@ public class NPC_v1_14_R1 extends NPCBase {
|
|||||||
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
private Set<UUID> hasTeamRegistered = new HashSet<>();
|
|
||||||
|
|
||||||
public NPC_v1_14_R1(NPCLib instance, List<String> lines) {
|
public NPC_v1_14_R1(NPCLib instance, List<String> lines) {
|
||||||
super(instance, lines);
|
super(instance, lines);
|
||||||
@@ -60,12 +56,6 @@ public class NPC_v1_14_R1 extends NPCBase {
|
|||||||
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
|
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLogout(Player player) {
|
|
||||||
super.onLogout(player);
|
|
||||||
hasTeamRegistered.remove(player.getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendShowPackets(Player player) {
|
public void sendShowPackets(Player player) {
|
||||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
@@ -104,39 +94,8 @@ public class NPC_v1_14_R1 extends NPCBase {
|
|||||||
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
|
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
|
||||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
|
|
||||||
EnumItemSlot nmsSlot;
|
EnumItemSlot nmsSlot = slot.getNmsEnum(EnumItemSlot.class);
|
||||||
ItemStack item;
|
ItemStack item = getItem(slot);
|
||||||
switch (slot) {
|
|
||||||
case HELMET:
|
|
||||||
item = helmet;
|
|
||||||
nmsSlot = EnumItemSlot.HEAD;
|
|
||||||
break;
|
|
||||||
case CHESTPLATE:
|
|
||||||
item = chestplate;
|
|
||||||
nmsSlot = EnumItemSlot.CHEST;
|
|
||||||
break;
|
|
||||||
case LEGGINGS:
|
|
||||||
item = leggings;
|
|
||||||
nmsSlot = EnumItemSlot.LEGS;
|
|
||||||
break;
|
|
||||||
case BOOTS:
|
|
||||||
item = boots;
|
|
||||||
nmsSlot = EnumItemSlot.FEET;
|
|
||||||
break;
|
|
||||||
case MAINHAND:
|
|
||||||
item = inHand;
|
|
||||||
nmsSlot = EnumItemSlot.MAINHAND;
|
|
||||||
break;
|
|
||||||
case OFFHAND:
|
|
||||||
item = offHand;
|
|
||||||
nmsSlot = EnumItemSlot.OFFHAND;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (!auto) {
|
|
||||||
throw new IllegalArgumentException(slot.toString() + " is not a supported slot for the version of your server");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item));
|
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item));
|
||||||
playerConnection.sendPacket(packet);
|
playerConnection.sendPacket(packet);
|
||||||
|
|||||||
+3
-1
@@ -6,9 +6,11 @@ import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
|||||||
import net.minecraft.server.v1_14_R1.DataWatcherRegistry;
|
import net.minecraft.server.v1_14_R1.DataWatcherRegistry;
|
||||||
import net.minecraft.server.v1_14_R1.PacketPlayOutEntityMetadata;
|
import net.minecraft.server.v1_14_R1.PacketPlayOutEntityMetadata;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public class PacketPlayOutEntityMetadataWrapper {
|
public class PacketPlayOutEntityMetadataWrapper {
|
||||||
|
|
||||||
public PacketPlayOutEntityMetadata create(NPCState[] activateStates, int entityId) {
|
public PacketPlayOutEntityMetadata create(Collection<NPCState> activateStates, int entityId) {
|
||||||
DataWatcher dataWatcher = new DataWatcher(null);
|
DataWatcher dataWatcher = new DataWatcher(null);
|
||||||
byte masked = NPCState.getMasked(activateStates);
|
byte masked = NPCState.getMasked(activateStates);
|
||||||
// TODO: Find out why NPCState#CROUCHED doesn't work.
|
// TODO: Find out why NPCState#CROUCHED doesn't work.
|
||||||
|
|||||||
@@ -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.3.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>npclib-nms-v1_15_R1</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot</artifactId>
|
||||||
|
<version>1.15.2-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
package net.jitse.npclib.nms.v1_15_R1;
|
||||||
|
|
||||||
|
import net.jitse.npclib.NPCLib;
|
||||||
|
import net.jitse.npclib.api.state.NPCSlot;
|
||||||
|
import net.jitse.npclib.hologram.Hologram;
|
||||||
|
import net.jitse.npclib.internal.MinecraftVersion;
|
||||||
|
import net.jitse.npclib.internal.NPCBase;
|
||||||
|
import net.jitse.npclib.nms.v1_15_R1.packets.*;
|
||||||
|
import net.minecraft.server.v1_15_R1.*;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||||
|
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Jitse Boonstra
|
||||||
|
*/
|
||||||
|
public class NPC_v1_15_R1 extends NPCBase {
|
||||||
|
|
||||||
|
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
||||||
|
private PacketPlayOutScoreboardTeam packetPlayOutScoreboardTeamRegister;
|
||||||
|
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
||||||
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
|
|
||||||
|
public NPC_v1_15_R1(NPCLib instance, List<String> lines) {
|
||||||
|
super(instance, lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createPackets() {
|
||||||
|
this.hologram = new Hologram(MinecraftVersion.V1_15_R1, location.clone().add(0, 0.5, 0), text);
|
||||||
|
|
||||||
|
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.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendShowPackets(Player player) {
|
||||||
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
|
|
||||||
|
if (hasTeamRegistered.add(player.getUniqueId()))
|
||||||
|
playerConnection.sendPacket(packetPlayOutScoreboardTeamRegister);
|
||||||
|
playerConnection.sendPacket(packetPlayOutPlayerInfoAdd);
|
||||||
|
playerConnection.sendPacket(packetPlayOutNamedEntitySpawn);
|
||||||
|
playerConnection.sendPacket(packetPlayOutEntityHeadRotation);
|
||||||
|
sendMetadataPacket(player);
|
||||||
|
|
||||||
|
hologram.show(player);
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () ->
|
||||||
|
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendHidePackets(Player player) {
|
||||||
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
|
|
||||||
|
playerConnection.sendPacket(packetPlayOutEntityDestroy);
|
||||||
|
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove);
|
||||||
|
|
||||||
|
hologram.hide(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMetadataPacket(Player player) {
|
||||||
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
|
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadataWrapper().create(activeStates, entityId);
|
||||||
|
|
||||||
|
playerConnection.sendPacket(packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
|
||||||
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
|
|
||||||
|
EnumItemSlot nmsSlot = slot.getNmsEnum(EnumItemSlot.class);
|
||||||
|
ItemStack item = getItem(slot);
|
||||||
|
|
||||||
|
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item));
|
||||||
|
playerConnection.sendPacket(packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 Jitse Boonstra
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.jitse.npclib.nms.v1_15_R1.packets;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import net.minecraft.server.v1_15_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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
package net.jitse.npclib.nms.v1_15_R1.packets;
|
||||||
|
|
||||||
|
import net.jitse.npclib.api.state.NPCState;
|
||||||
|
import net.minecraft.server.v1_15_R1.DataWatcher;
|
||||||
|
import net.minecraft.server.v1_15_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_15_R1.DataWatcherRegistry;
|
||||||
|
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityMetadata;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public class PacketPlayOutEntityMetadataWrapper {
|
||||||
|
|
||||||
|
public PacketPlayOutEntityMetadata create(Collection<NPCState> activateStates, int entityId) {
|
||||||
|
DataWatcher dataWatcher = new DataWatcher(null);
|
||||||
|
dataWatcher.register(new DataWatcherObject<>(16, DataWatcherRegistry.a), (byte) 127);
|
||||||
|
|
||||||
|
byte masked = NPCState.getMasked(activateStates);
|
||||||
|
// TODO: Find out why NPCState#CROUCHED doesn't work.
|
||||||
|
dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), masked);
|
||||||
|
|
||||||
|
// for (Player online : Bukkit.getOnlinePlayers()) {
|
||||||
|
// DataWatcher watcher = ((CraftPlayer) online).getHandle().getDataWatcher();
|
||||||
|
// try {
|
||||||
|
// Field entriesField = watcher.getClass().getDeclaredField("entries");
|
||||||
|
// entriesField.setAccessible(true);
|
||||||
|
//
|
||||||
|
// Int2ObjectOpenHashMap<DataWatcher.Item<?>> entries = (Int2ObjectOpenHashMap<DataWatcher.Item<?>>) entriesField.get(watcher);
|
||||||
|
// entries.forEach((integer, item) -> {
|
||||||
|
// if (item.b() instanceof Boolean || item.b() instanceof Byte)
|
||||||
|
// online.sendMessage(integer + ": " + item.b() + " type = " + item.b().getClass().toString());
|
||||||
|
// });
|
||||||
|
// } catch (NoSuchFieldException | IllegalAccessException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
return new PacketPlayOutEntityMetadata(entityId, dataWatcher, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 Jitse Boonstra
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.jitse.npclib.nms.v1_15_R1.packets;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import net.minecraft.server.v1_15_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)));
|
||||||
|
|
||||||
|
return packetPlayOutNamedEntitySpawn;
|
||||||
|
}
|
||||||
|
}
|
||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 Jitse Boonstra
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.jitse.npclib.nms.v1_15_R1.packets;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import net.minecraft.server.v1_15_R1.EnumGamemode;
|
||||||
|
import net.minecraft.server.v1_15_R1.IChatBaseComponent;
|
||||||
|
import net.minecraft.server.v1_15_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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+53
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 Jitse Boonstra
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.jitse.npclib.nms.v1_15_R1.packets;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import net.minecraft.server.v1_15_R1.ChatComponentText;
|
||||||
|
import net.minecraft.server.v1_15_R1.IChatBaseComponent;
|
||||||
|
import net.minecraft.server.v1_15_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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,10 +17,7 @@ import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
@@ -32,7 +29,6 @@ public class NPC_v1_8_R2 extends NPCBase {
|
|||||||
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
private Set<UUID> hasTeamRegistered = new HashSet<>();
|
|
||||||
|
|
||||||
public NPC_v1_8_R2(NPCLib instance, List<String> lines) {
|
public NPC_v1_8_R2(NPCLib instance, List<String> lines) {
|
||||||
super(instance, lines);
|
super(instance, lines);
|
||||||
@@ -64,12 +60,6 @@ public class NPC_v1_8_R2 extends NPCBase {
|
|||||||
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
|
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLogout(Player player) {
|
|
||||||
super.onLogout(player);
|
|
||||||
hasTeamRegistered.remove(player.getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendShowPackets(Player player) {
|
public void sendShowPackets(Player player) {
|
||||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
@@ -107,30 +97,12 @@ public class NPC_v1_8_R2 extends NPCBase {
|
|||||||
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
|
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
|
||||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
|
|
||||||
ItemStack item;
|
if (slot == NPCSlot.OFFHAND && !auto) {
|
||||||
switch (slot) {
|
throw new UnsupportedOperationException("Offhand is not supported on servers below 1.9");
|
||||||
case HELMET:
|
|
||||||
item = helmet;
|
|
||||||
break;
|
|
||||||
case CHESTPLATE:
|
|
||||||
item = chestplate;
|
|
||||||
break;
|
|
||||||
case LEGGINGS:
|
|
||||||
item = leggings;
|
|
||||||
break;
|
|
||||||
case BOOTS:
|
|
||||||
item = boots;
|
|
||||||
break;
|
|
||||||
case MAINHAND:
|
|
||||||
item = inHand;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (!auto) {
|
|
||||||
throw new IllegalArgumentException(slot.toString() + " is not a supported slot for the version of your server");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ItemStack item = getItem(slot);
|
||||||
|
|
||||||
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, slot.getSlot(), CraftItemStack.asNMSCopy(item));
|
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, slot.getSlot(), CraftItemStack.asNMSCopy(item));
|
||||||
playerConnection.sendPacket(packet);
|
playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -4,9 +4,11 @@ import net.jitse.npclib.api.state.NPCState;
|
|||||||
import net.minecraft.server.v1_8_R2.DataWatcher;
|
import net.minecraft.server.v1_8_R2.DataWatcher;
|
||||||
import net.minecraft.server.v1_8_R2.PacketPlayOutEntityMetadata;
|
import net.minecraft.server.v1_8_R2.PacketPlayOutEntityMetadata;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public class PacketPlayOutEntityMetadataWrapper {
|
public class PacketPlayOutEntityMetadataWrapper {
|
||||||
|
|
||||||
public PacketPlayOutEntityMetadata create(NPCState[] activateStates, int entityId) {
|
public PacketPlayOutEntityMetadata create(Collection<NPCState> activateStates, int entityId) {
|
||||||
DataWatcher dataWatcher = new DataWatcher(null);
|
DataWatcher dataWatcher = new DataWatcher(null);
|
||||||
byte masked = NPCState.getMasked(activateStates);
|
byte masked = NPCState.getMasked(activateStates);
|
||||||
dataWatcher.a(0, masked);
|
dataWatcher.a(0, masked);
|
||||||
|
|||||||
@@ -17,10 +17,7 @@ import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
@@ -32,7 +29,6 @@ public class NPC_v1_8_R3 extends NPCBase {
|
|||||||
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
private Set<UUID> hasTeamRegistered = new HashSet<>();
|
|
||||||
|
|
||||||
public NPC_v1_8_R3(NPCLib instance, List<String> lines) {
|
public NPC_v1_8_R3(NPCLib instance, List<String> lines) {
|
||||||
super(instance, lines);
|
super(instance, lines);
|
||||||
@@ -64,12 +60,6 @@ public class NPC_v1_8_R3 extends NPCBase {
|
|||||||
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
|
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLogout(Player player) {
|
|
||||||
super.onLogout(player);
|
|
||||||
hasTeamRegistered.remove(player.getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendShowPackets(Player player) {
|
public void sendShowPackets(Player player) {
|
||||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
@@ -108,30 +98,12 @@ public class NPC_v1_8_R3 extends NPCBase {
|
|||||||
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
|
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
|
||||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
|
|
||||||
ItemStack item;
|
if (slot == NPCSlot.OFFHAND && !auto) {
|
||||||
switch (slot) {
|
throw new UnsupportedOperationException("Offhand is not supported on servers below 1.9");
|
||||||
case HELMET:
|
|
||||||
item = helmet;
|
|
||||||
break;
|
|
||||||
case CHESTPLATE:
|
|
||||||
item = chestplate;
|
|
||||||
break;
|
|
||||||
case LEGGINGS:
|
|
||||||
item = leggings;
|
|
||||||
break;
|
|
||||||
case BOOTS:
|
|
||||||
item = boots;
|
|
||||||
break;
|
|
||||||
case MAINHAND:
|
|
||||||
item = inHand;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (!auto) {
|
|
||||||
throw new IllegalArgumentException(slot.toString() + " is not a supported slot for the version of your server");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ItemStack item = getItem(slot);
|
||||||
|
|
||||||
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, slot.getSlot(), CraftItemStack.asNMSCopy(item));
|
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, slot.getSlot(), CraftItemStack.asNMSCopy(item));
|
||||||
playerConnection.sendPacket(packet);
|
playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -4,9 +4,11 @@ import net.jitse.npclib.api.state.NPCState;
|
|||||||
import net.minecraft.server.v1_8_R3.DataWatcher;
|
import net.minecraft.server.v1_8_R3.DataWatcher;
|
||||||
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata;
|
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public class PacketPlayOutEntityMetadataWrapper {
|
public class PacketPlayOutEntityMetadataWrapper {
|
||||||
|
|
||||||
public PacketPlayOutEntityMetadata create(NPCState[] activateStates, int entityId) {
|
public PacketPlayOutEntityMetadata create(Collection<NPCState> activateStates, int entityId) {
|
||||||
DataWatcher dataWatcher = new DataWatcher(null);
|
DataWatcher dataWatcher = new DataWatcher(null);
|
||||||
byte masked = NPCState.getMasked(activateStates);
|
byte masked = NPCState.getMasked(activateStates);
|
||||||
dataWatcher.a(0, masked);
|
dataWatcher.a(0, masked);
|
||||||
|
|||||||
@@ -17,10 +17,7 @@ import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
@@ -32,7 +29,6 @@ public class NPC_v1_9_R1 extends NPCBase {
|
|||||||
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
private Set<UUID> hasTeamRegistered = new HashSet<>();
|
|
||||||
|
|
||||||
public NPC_v1_9_R1(NPCLib instance, List<String> lines) {
|
public NPC_v1_9_R1(NPCLib instance, List<String> lines) {
|
||||||
super(instance, lines);
|
super(instance, lines);
|
||||||
@@ -64,12 +60,6 @@ public class NPC_v1_9_R1 extends NPCBase {
|
|||||||
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
|
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLogout(Player player) {
|
|
||||||
super.onLogout(player);
|
|
||||||
hasTeamRegistered.remove(player.getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendShowPackets(Player player) {
|
public void sendShowPackets(Player player) {
|
||||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
@@ -108,39 +98,8 @@ public class NPC_v1_9_R1 extends NPCBase {
|
|||||||
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
|
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
|
||||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
|
|
||||||
EnumItemSlot nmsSlot;
|
EnumItemSlot nmsSlot = slot.getNmsEnum(EnumItemSlot.class);
|
||||||
ItemStack item;
|
ItemStack item = getItem(slot);
|
||||||
switch (slot) {
|
|
||||||
case HELMET:
|
|
||||||
item = helmet;
|
|
||||||
nmsSlot = EnumItemSlot.HEAD;
|
|
||||||
break;
|
|
||||||
case CHESTPLATE:
|
|
||||||
item = chestplate;
|
|
||||||
nmsSlot = EnumItemSlot.CHEST;
|
|
||||||
break;
|
|
||||||
case LEGGINGS:
|
|
||||||
item = leggings;
|
|
||||||
nmsSlot = EnumItemSlot.LEGS;
|
|
||||||
break;
|
|
||||||
case BOOTS:
|
|
||||||
item = boots;
|
|
||||||
nmsSlot = EnumItemSlot.FEET;
|
|
||||||
break;
|
|
||||||
case MAINHAND:
|
|
||||||
item = inHand;
|
|
||||||
nmsSlot = EnumItemSlot.MAINHAND;
|
|
||||||
break;
|
|
||||||
case OFFHAND:
|
|
||||||
item = offHand;
|
|
||||||
nmsSlot = EnumItemSlot.OFFHAND;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (!auto) {
|
|
||||||
throw new IllegalArgumentException(slot.toString() + " is not a supported slot for the version of your server");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item));
|
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item));
|
||||||
playerConnection.sendPacket(packet);
|
playerConnection.sendPacket(packet);
|
||||||
|
|||||||
+3
-1
@@ -6,9 +6,11 @@ import net.minecraft.server.v1_9_R1.DataWatcherObject;
|
|||||||
import net.minecraft.server.v1_9_R1.DataWatcherRegistry;
|
import net.minecraft.server.v1_9_R1.DataWatcherRegistry;
|
||||||
import net.minecraft.server.v1_9_R1.PacketPlayOutEntityMetadata;
|
import net.minecraft.server.v1_9_R1.PacketPlayOutEntityMetadata;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public class PacketPlayOutEntityMetadataWrapper {
|
public class PacketPlayOutEntityMetadataWrapper {
|
||||||
|
|
||||||
public PacketPlayOutEntityMetadata create(NPCState[] activateStates, int entityId) {
|
public PacketPlayOutEntityMetadata create(Collection<NPCState> activateStates, int entityId) {
|
||||||
DataWatcher dataWatcher = new DataWatcher(null);
|
DataWatcher dataWatcher = new DataWatcher(null);
|
||||||
byte masked = NPCState.getMasked(activateStates);
|
byte masked = NPCState.getMasked(activateStates);
|
||||||
dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), masked);
|
dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), masked);
|
||||||
|
|||||||
@@ -17,10 +17,7 @@ import org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
@@ -32,7 +29,6 @@ public class NPC_v1_9_R2 extends NPCBase {
|
|||||||
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
private Set<UUID> hasTeamRegistered = new HashSet<>();
|
|
||||||
|
|
||||||
public NPC_v1_9_R2(NPCLib instance, List<String> lines) {
|
public NPC_v1_9_R2(NPCLib instance, List<String> lines) {
|
||||||
super(instance, lines);
|
super(instance, lines);
|
||||||
@@ -64,12 +60,6 @@ public class NPC_v1_9_R2 extends NPCBase {
|
|||||||
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
|
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLogout(Player player) {
|
|
||||||
super.onLogout(player);
|
|
||||||
hasTeamRegistered.remove(player.getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendShowPackets(Player player) {
|
public void sendShowPackets(Player player) {
|
||||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
@@ -108,39 +98,8 @@ public class NPC_v1_9_R2 extends NPCBase {
|
|||||||
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
|
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
|
||||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
|
|
||||||
EnumItemSlot nmsSlot;
|
EnumItemSlot nmsSlot = slot.getNmsEnum(EnumItemSlot.class);
|
||||||
ItemStack item;
|
ItemStack item = getItem(slot);
|
||||||
switch (slot) {
|
|
||||||
case HELMET:
|
|
||||||
item = helmet;
|
|
||||||
nmsSlot = EnumItemSlot.HEAD;
|
|
||||||
break;
|
|
||||||
case CHESTPLATE:
|
|
||||||
item = chestplate;
|
|
||||||
nmsSlot = EnumItemSlot.CHEST;
|
|
||||||
break;
|
|
||||||
case LEGGINGS:
|
|
||||||
item = leggings;
|
|
||||||
nmsSlot = EnumItemSlot.LEGS;
|
|
||||||
break;
|
|
||||||
case BOOTS:
|
|
||||||
item = boots;
|
|
||||||
nmsSlot = EnumItemSlot.FEET;
|
|
||||||
break;
|
|
||||||
case MAINHAND:
|
|
||||||
item = inHand;
|
|
||||||
nmsSlot = EnumItemSlot.MAINHAND;
|
|
||||||
break;
|
|
||||||
case OFFHAND:
|
|
||||||
item = offHand;
|
|
||||||
nmsSlot = EnumItemSlot.OFFHAND;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (!auto) {
|
|
||||||
throw new IllegalArgumentException(slot.toString() + " is not a supported slot for the version of your server");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item));
|
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item));
|
||||||
playerConnection.sendPacket(packet);
|
playerConnection.sendPacket(packet);
|
||||||
|
|||||||
+3
-1
@@ -6,9 +6,11 @@ import net.minecraft.server.v1_9_R2.DataWatcherObject;
|
|||||||
import net.minecraft.server.v1_9_R2.DataWatcherRegistry;
|
import net.minecraft.server.v1_9_R2.DataWatcherRegistry;
|
||||||
import net.minecraft.server.v1_9_R2.PacketPlayOutEntityMetadata;
|
import net.minecraft.server.v1_9_R2.PacketPlayOutEntityMetadata;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public class PacketPlayOutEntityMetadataWrapper {
|
public class PacketPlayOutEntityMetadataWrapper {
|
||||||
|
|
||||||
public PacketPlayOutEntityMetadata create(NPCState[] activateStates, int entityId) {
|
public PacketPlayOutEntityMetadata create(Collection<NPCState> activateStates, int entityId) {
|
||||||
DataWatcher dataWatcher = new DataWatcher(null);
|
DataWatcher dataWatcher = new DataWatcher(null);
|
||||||
byte masked = NPCState.getMasked(activateStates);
|
byte masked = NPCState.getMasked(activateStates);
|
||||||
dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), masked);
|
dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), masked);
|
||||||
|
|||||||
@@ -86,6 +86,12 @@
|
|||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.jitse</groupId>
|
||||||
|
<artifactId>npclib-nms-v1_15_R1</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
Reference in New Issue
Block a user