From 1dbe797e013b0ee48525afe64f9398b38f636dda Mon Sep 17 00:00:00 2001 From: Jitse Boonstra Date: Thu, 2 May 2019 18:15:15 +0200 Subject: [PATCH] For 1.4.2. --- api/pom.xml | 8 +- commons/pom.xml | 11 +- .../tinyprotocol/LegacyTinyProtocol.java | 331 ------------------ .../npclib/listeners/PacketListener.java | 33 +- nms/pom.xml | 3 +- nms/v1_10_R1/pom.xml | 2 +- nms/v1_11_R1/pom.xml | 2 +- nms/v1_12_R1/pom.xml | 2 +- nms/v1_13_R1/pom.xml | 2 +- nms/v1_13_R2/pom.xml | 2 +- nms/v1_7_R4/pom.xml | 29 -- .../jitse/npclib/nms/v1_7_R4/NPC_v1_7_R4.java | 111 ------ ...acketPlayOutEntityHeadRotationWrapper.java | 26 -- .../PacketPlayOutNamedEntitySpawnWrapper.java | 44 --- .../PacketPlayOutPlayerInfoWrapper.java | 38 -- .../PacketPlayOutScoreboardTeamWrapper.java | 55 --- nms/v1_8_R1/pom.xml | 2 +- nms/v1_8_R2/pom.xml | 2 +- nms/v1_8_R3/pom.xml | 2 +- nms/v1_9_R1/pom.xml | 2 +- nms/v1_9_R2/pom.xml | 2 +- plugin/pom.xml | 2 +- pom.xml | 2 +- 23 files changed, 22 insertions(+), 691 deletions(-) delete mode 100755 commons/src/main/java/com/comphenix/tinyprotocol/LegacyTinyProtocol.java delete mode 100755 nms/v1_7_R4/pom.xml delete mode 100755 nms/v1_7_R4/src/main/java/net/jitse/npclib/nms/v1_7_R4/NPC_v1_7_R4.java delete mode 100755 nms/v1_7_R4/src/main/java/net/jitse/npclib/nms/v1_7_R4/packets/PacketPlayOutEntityHeadRotationWrapper.java delete mode 100755 nms/v1_7_R4/src/main/java/net/jitse/npclib/nms/v1_7_R4/packets/PacketPlayOutNamedEntitySpawnWrapper.java delete mode 100755 nms/v1_7_R4/src/main/java/net/jitse/npclib/nms/v1_7_R4/packets/PacketPlayOutPlayerInfoWrapper.java delete mode 100755 nms/v1_7_R4/src/main/java/net/jitse/npclib/nms/v1_7_R4/packets/PacketPlayOutScoreboardTeamWrapper.java diff --git a/api/pom.xml b/api/pom.xml index c62b443..96a24a1 100755 --- a/api/pom.xml +++ b/api/pom.xml @@ -7,7 +7,7 @@ net.jitse npclib - 1.4.1 + 1.4.2 npclib-api @@ -19,12 +19,6 @@ ${project.version} compile - - net.jitse - npclib-nms-v1_7_R4 - ${project.version} - compile - net.jitse npclib-nms-v1_8_R1 diff --git a/commons/pom.xml b/commons/pom.xml index 5d745c2..3a1a63c 100755 --- a/commons/pom.xml +++ b/commons/pom.xml @@ -7,7 +7,7 @@ net.jitse npclib - 1.4.1 + 1.4.2 npclib-commons @@ -31,14 +31,7 @@ org.spigotmc spigot - 1.7.10-R0.1-SNAPSHOT - provided - - - - io.netty - netty-all - 4.0.23.Final + 1.13.2-R0.1-SNAPSHOT provided diff --git a/commons/src/main/java/com/comphenix/tinyprotocol/LegacyTinyProtocol.java b/commons/src/main/java/com/comphenix/tinyprotocol/LegacyTinyProtocol.java deleted file mode 100755 index a5e6372..0000000 --- a/commons/src/main/java/com/comphenix/tinyprotocol/LegacyTinyProtocol.java +++ /dev/null @@ -1,331 +0,0 @@ -package com.comphenix.tinyprotocol; - -import com.google.common.collect.Lists; -import com.google.common.collect.MapMaker; -import net.jitse.npclib.logging.NPCLibLogger; -import net.minecraft.util.com.mojang.authlib.GameProfile; -import net.minecraft.util.io.netty.channel.*; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.server.PluginDisableEvent; -import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitRunnable; - -import java.util.*; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Minimized version of TinyProtocol by Kristian suited for NPCLib. - */ -public abstract class LegacyTinyProtocol { - - private static final AtomicInteger ID = new AtomicInteger(0); - - // Used in order to lookup a channel - private static final Reflection.MethodInvoker getPlayerHandle = Reflection.getMethod("{obc}.entity.CraftPlayer", "getHandle"); - private static final Reflection.FieldAccessor getConnection = Reflection.getField("{nms}.EntityPlayer", "playerConnection", Object.class); - private static final Reflection.FieldAccessor getManager = Reflection.getField("{nms}.PlayerConnection", "networkManager", Object.class); - private static final Reflection.FieldAccessor getChannel = Reflection.getField("{nms}.NetworkManager", Channel.class, 0); - - // Looking up ServerConnection - private static final Class minecraftServerClass = Reflection.getUntypedClass("{nms}.MinecraftServer"); - private static final Class serverConnectionClass = Reflection.getUntypedClass("{nms}.ServerConnection"); - private static final Reflection.FieldAccessor getMinecraftServer = Reflection.getField("{obc}.CraftServer", minecraftServerClass, 0); - private static final Reflection.FieldAccessor getServerConnection = Reflection.getField(minecraftServerClass, serverConnectionClass, 0); - private static final Reflection.MethodInvoker getNetworkMarkers = Reflection.getTypedMethod(serverConnectionClass, null, List.class, serverConnectionClass); - - // Packets we have to intercept - private static final Class PACKET_SET_PROTOCOL = Reflection.getMinecraftClass("PacketHandshakingInSetProtocol"); - private static final Class PACKET_LOGIN_IN_START = Reflection.getMinecraftClass("PacketLoginInStart"); - private static final Reflection.FieldAccessor getGameProfile = Reflection.getField(PACKET_LOGIN_IN_START, GameProfile.class, 0); - private static final Reflection.FieldAccessor protocolId = Reflection.getField(PACKET_SET_PROTOCOL, int.class, 0); - private static final Reflection.FieldAccessor protocolType = Reflection.getField(PACKET_SET_PROTOCOL, Enum.class, 0); - - - // Speedup channel lookup - private Map channelLookup = new MapMaker().weakValues().makeMap(); - private Map protocolLookup = new MapMaker().weakKeys().makeMap(); - private Listener listener; - - private Logger logger; - - // Channels that have already been removed - private Set uninjectedChannels = Collections.newSetFromMap(new MapMaker().weakKeys().makeMap()); - - // List of network markers - private List networkManagers; - - // Injected channel handlers - private List serverChannels = Lists.newArrayList(); - private ChannelInboundHandlerAdapter serverChannelHandler; - private ChannelInitializer beginInitProtocol; - private ChannelInitializer endInitProtocol; - - // Current handler name - private String handlerName; - - private volatile boolean closed; - protected Plugin plugin; - - protected LegacyTinyProtocol(final Plugin plugin) { - this.plugin = plugin; - this.logger = new NPCLibLogger(plugin); - - // Compute handler name - this.handlerName = "tiny-" + plugin.getName() + "-" + ID.incrementAndGet(); - - // Prepare existing players - registerBukkitEvents(); - - try { - logger.info("Attempting to inject into netty"); - registerChannelHandler(); - registerPlayers(plugin); - } catch (IllegalArgumentException exceptionx) { - // Damn you, late bind - logger.log(Level.WARNING, "Attempting to delay injection"); - - new BukkitRunnable() { - @Override - public void run() { - registerChannelHandler(); - registerPlayers(plugin); - logger.info("Injection complete"); - } - }.runTask(plugin); - } - } - - private void createServerChannelHandler() { - // Handle connected channels - endInitProtocol = new ChannelInitializer() { - - @SuppressWarnings("all") - @Override - protected void initChannel(Channel channel) throws Exception { - try { - // This can take a while, so we need to stop the main thread from interfering - synchronized (networkManagers) { - // Stop injecting channels - if (!closed) { - channel.eventLoop().submit(() -> injectChannelInternal(channel)); - } - } - } catch (Exception exception) { - logger.log(Level.SEVERE, "Cannot inject incomming channel " + channel, exception); - } - } - - }; - - // This is executed before Minecraft's channel handler - beginInitProtocol = new ChannelInitializer() { - - @SuppressWarnings("all") - @Override - protected void initChannel(Channel channel) throws Exception { - channel.pipeline().addLast(endInitProtocol); - } - - }; - - serverChannelHandler = new ChannelInboundHandlerAdapter() { - - @SuppressWarnings("all") - @Override - public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { - Channel channel = (Channel) msg; - - channel.pipeline().addFirst(beginInitProtocol); - ctx.fireChannelRead(msg); - } - - }; - } - - private void registerBukkitEvents() { - listener = new Listener() { - - @SuppressWarnings("unused") - @EventHandler(priority = EventPriority.LOWEST) - public final void onPlayerLogin(PlayerJoinEvent e) { - if (closed) - return; - - Channel channel = getChannel(e.getPlayer()); - - // Don't inject players that have been explicitly uninjected - if (!uninjectedChannels.contains(channel)) { - injectPlayer(e.getPlayer()); - } - } - - @SuppressWarnings("unused") - @EventHandler - public final void onPluginDisable(PluginDisableEvent e) { - if (e.getPlugin().equals(plugin)) { - close(); - } - } - - }; - - plugin.getServer().getPluginManager().registerEvents(listener, plugin); - } - - @SuppressWarnings("unchecked") - private void registerChannelHandler() { - Object mcServer = getMinecraftServer.get(Bukkit.getServer()); - Object serverConnection = getServerConnection.get(mcServer); - boolean looking = true; - - // We need to synchronize against this list - networkManagers = (List) getNetworkMarkers.invoke(null, serverConnection); - createServerChannelHandler(); - - // Find the correct list, or implicitly throw an exception - for (int i = 0; looking; i++) { - List list = Reflection.getField(serverConnection.getClass(), List.class, i).get(serverConnection); - - for (Object item : list) { - //if (!ChannelFuture.class.isInstance(item)) - // break; - - // Channel future that contains the server connection - Channel serverChannel = ((ChannelFuture) item).channel(); - - serverChannels.add(serverChannel); - - serverChannel.pipeline().addFirst(serverChannelHandler); - logger.info("Server channel handler injected (" + serverChannel + ")"); - looking = false; - } - } - } - - private void unregisterChannelHandler() { - if (serverChannelHandler == null) - return; - - for (Channel serverChannel : serverChannels) { - final ChannelPipeline pipeline = serverChannel.pipeline(); - - // Remove channel handler - serverChannel.eventLoop().execute(() -> { - try { - pipeline.remove(serverChannelHandler); - } catch (NoSuchElementException exception) { - // That's fine - } - }); - } - } - - private void registerPlayers(Plugin plugin) { - for (Player player : plugin.getServer().getOnlinePlayers()) { - injectPlayer(player); - } - } - - public Object onPacketInAsync(Player sender, Object packet) { - return packet; - } - - private void injectPlayer(Player player) { - injectChannelInternal(getChannel(player)).player = player; - } - - private PacketInterceptor injectChannelInternal(Channel channel) { - try { - PacketInterceptor interceptor = (PacketInterceptor) channel.pipeline().get(handlerName); - - // Inject our packet interceptor - if (interceptor == null) { - interceptor = new PacketInterceptor(); - channel.pipeline().addBefore("packet_handler", handlerName, interceptor); - uninjectedChannels.remove(channel); - } - - return interceptor; - } catch (IllegalArgumentException exception) { - // Try again - return (PacketInterceptor) channel.pipeline().get(handlerName); - } - } - - private Channel getChannel(Player player) { - Channel channel = channelLookup.get(player.getName()); - - // Lookup channel again - if (channel == null) { - Object connection = getConnection.get(getPlayerHandle.invoke(player)); - Object manager = getManager.get(connection); - - channelLookup.put(player.getName(), channel = getChannel.get(manager)); - } - - return channel; - } - - private void uninjectChannel(final Channel channel) { - // No need to guard against this if we're closing - if (!closed) { - uninjectedChannels.add(channel); - } - - // See ChannelInjector in ProtocolLib, line 590 - channel.eventLoop().execute(() -> channel.pipeline().remove(handlerName)); - } - - private void close() { - if (!closed) { - closed = true; - - // Remove our handlers - for (Player player : plugin.getServer().getOnlinePlayers()) { - uninjectChannel(getChannel(player)); - } - - // Clean up Bukkit - HandlerList.unregisterAll(listener); - unregisterChannelHandler(); - } - } - - private final class PacketInterceptor extends ChannelDuplexHandler { - // Updated by the login event - public volatile Player player; - - @Override - public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { - // Intercept channel - final Channel channel = ctx.channel(); - if (PACKET_LOGIN_IN_START.isInstance(msg)) { - GameProfile profile = getGameProfile.get(msg); - channelLookup.put(profile.getName(), channel); - } else if (PACKET_SET_PROTOCOL.isInstance(msg)) { - String protocol = protocolType.get(msg).name(); - if (protocol.equalsIgnoreCase("LOGIN")) { - protocolLookup.put(channel, protocolId.get(msg)); - } - } - - try { - msg = onPacketInAsync(player, msg); - } catch (Exception exception) { - logger.log(Level.SEVERE, "Error in onPacketInAsync()", exception); - } - - if (msg != null) { - super.channelRead(ctx, msg); - } - } - } -} \ No newline at end of file diff --git a/commons/src/main/java/net/jitse/npclib/listeners/PacketListener.java b/commons/src/main/java/net/jitse/npclib/listeners/PacketListener.java index a9e7888..3886f47 100755 --- a/commons/src/main/java/net/jitse/npclib/listeners/PacketListener.java +++ b/commons/src/main/java/net/jitse/npclib/listeners/PacketListener.java @@ -4,7 +4,6 @@ package net.jitse.npclib.listeners; -import com.comphenix.tinyprotocol.LegacyTinyProtocol; import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import net.jitse.npclib.NPCManager; @@ -39,33 +38,13 @@ public class PacketListener { public void start(Plugin plugin) { this.plugin = plugin; - boolean legacyProtocol = false; + new TinyProtocol(plugin) { - try { - Class.forName("io.netty.channel.Channel"); - } catch (ClassNotFoundException exception) { - legacyProtocol = true; - } - - if (legacyProtocol) { - // 1.7 R4 packet interaction. - new LegacyTinyProtocol(plugin) { - - @Override - public Object onPacketInAsync(Player player, Object packet) { - return handleInteractPacket(player, packet) ? super.onPacketInAsync(player, packet) : null; - } - }; - } else { - // 1.8 (and above) packet interaction. - new TinyProtocol(plugin) { - - @Override - public Object onPacketInAsync(Player player, Object packet) { - return handleInteractPacket(player, packet) ? super.onPacketInAsync(player, packet) : null; - } - }; - } + @Override + public Object onPacketInAsync(Player player, Object packet) { + return handleInteractPacket(player, packet) ? super.onPacketInAsync(player, packet) : null; + } + }; } private boolean handleInteractPacket(Player player, Object packet) { diff --git a/nms/pom.xml b/nms/pom.xml index fea2c62..048d196 100755 --- a/nms/pom.xml +++ b/nms/pom.xml @@ -7,13 +7,12 @@ net.jitse npclib - 1.4.1 + 1.4.2 npclib-nms - v1_7_R4 v1_8_R1 v1_8_R2 v1_8_R3 diff --git a/nms/v1_10_R1/pom.xml b/nms/v1_10_R1/pom.xml index 297796b..07b3cfe 100755 --- a/nms/v1_10_R1/pom.xml +++ b/nms/v1_10_R1/pom.xml @@ -7,7 +7,7 @@ net.jitse npclib-nms - 1.4.1 + 1.4.2 npclib-nms-v1_10_R1 diff --git a/nms/v1_11_R1/pom.xml b/nms/v1_11_R1/pom.xml index bdf171a..018cdd4 100755 --- a/nms/v1_11_R1/pom.xml +++ b/nms/v1_11_R1/pom.xml @@ -7,7 +7,7 @@ net.jitse npclib-nms - 1.4.1 + 1.4.2 npclib-nms-v1_11_R1 diff --git a/nms/v1_12_R1/pom.xml b/nms/v1_12_R1/pom.xml index c3d5216..b6aa4fa 100755 --- a/nms/v1_12_R1/pom.xml +++ b/nms/v1_12_R1/pom.xml @@ -7,7 +7,7 @@ net.jitse npclib-nms - 1.4.1 + 1.4.2 npclib-nms-v1_12_R1 diff --git a/nms/v1_13_R1/pom.xml b/nms/v1_13_R1/pom.xml index 8a3ba76..9929b47 100755 --- a/nms/v1_13_R1/pom.xml +++ b/nms/v1_13_R1/pom.xml @@ -7,7 +7,7 @@ net.jitse npclib-nms - 1.4.1 + 1.4.2 npclib-nms-v1_13_R1 diff --git a/nms/v1_13_R2/pom.xml b/nms/v1_13_R2/pom.xml index c9e3417..77f29c7 100755 --- a/nms/v1_13_R2/pom.xml +++ b/nms/v1_13_R2/pom.xml @@ -7,7 +7,7 @@ net.jitse npclib-nms - 1.4.1 + 1.4.2 npclib-nms-v1_13_R2 diff --git a/nms/v1_7_R4/pom.xml b/nms/v1_7_R4/pom.xml deleted file mode 100755 index 6570212..0000000 --- a/nms/v1_7_R4/pom.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - 4.0.0 - - - net.jitse - npclib-nms - 1.4.1 - - - npclib-nms-v1_7_R4 - - - - org.spigotmc - spigot - 1.7.10-R0.1-SNAPSHOT - provided - - - com.google.code.gson - gson - 2.8.5 - compile - - - diff --git a/nms/v1_7_R4/src/main/java/net/jitse/npclib/nms/v1_7_R4/NPC_v1_7_R4.java b/nms/v1_7_R4/src/main/java/net/jitse/npclib/nms/v1_7_R4/NPC_v1_7_R4.java deleted file mode 100755 index bb5cd9d..0000000 --- a/nms/v1_7_R4/src/main/java/net/jitse/npclib/nms/v1_7_R4/NPC_v1_7_R4.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2018 Jitse Boonstra - */ - -package net.jitse.npclib.nms.v1_7_R4; - -import net.jitse.npclib.api.NPC; -import net.jitse.npclib.nms.v1_7_R4.packets.PacketPlayOutEntityHeadRotationWrapper; -import net.jitse.npclib.nms.v1_7_R4.packets.PacketPlayOutNamedEntitySpawnWrapper; -import net.jitse.npclib.nms.v1_7_R4.packets.PacketPlayOutPlayerInfoWrapper; -import net.jitse.npclib.nms.v1_7_R4.packets.PacketPlayOutScoreboardTeamWrapper; -import net.jitse.npclib.skin.Skin; -import net.minecraft.server.v1_7_R4.*; -import net.minecraft.util.com.mojang.authlib.GameProfile; -import net.minecraft.util.com.mojang.authlib.properties.Property; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -import java.util.List; -import java.util.UUID; - -/** - * @author Jitse Boonstra - */ -public class NPC_v1_7_R4 extends NPC { - - private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn; - private PacketPlayOutScoreboardTeam packetPlayOutScoreboardTeamRegister, packetPlayOutScoreboardTeamUnregister; - private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove; - private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation; - private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy; - - private GameProfile legacyGameProfile; - - public NPC_v1_7_R4(JavaPlugin plugin, Skin skin, double autoHideDistance, List lines) { - super(plugin, skin, autoHideDistance, lines); - // TODO: Add multi-line text support. - this.name = lines.get(0); - } - - @Override - public void createPackets() { - this.legacyGameProfile = generateLegacyGameProfile(uuid, name.length() < 16 ? name : name.substring(0, 15)); - PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper(); - - // Packets for spawning the NPC: - this.packetPlayOutScoreboardTeamRegister = new PacketPlayOutScoreboardTeamWrapper() - .createRegisterTeam(legacyGameProfile.getId().toString().replace("-", "").substring(0, 10), name); // First packet to send. - - this.packetPlayOutPlayerInfoAdd = packetPlayOutPlayerInfoWrapper - .create(0, legacyGameProfile, name.length() < 16 ? name : name.length() < 16 ? name : name.substring(0, 15)); // Second packet to send. - - this.packetPlayOutNamedEntitySpawn = new PacketPlayOutNamedEntitySpawnWrapper() - .create(legacyGameProfile, location, entityId); // Third packet to send. - - this.packetPlayOutEntityHeadRotation = new PacketPlayOutEntityHeadRotationWrapper() - .create(location, entityId); // Fourth packet to send. - - this.packetPlayOutPlayerInfoRemove = packetPlayOutPlayerInfoWrapper - .create(4, legacyGameProfile, name.length() < 16 ? name : name.substring(0, 15)); // Fifth packet to send (delayed). - - // Packet for destroying the NPC: - this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send. - - // Second packet to send is "packetPlayOutPlayerInfoRemove". - - this.packetPlayOutScoreboardTeamUnregister = new PacketPlayOutScoreboardTeamWrapper() - .createUnregisterTeam(legacyGameProfile.getId().toString().replace("-", "").substring(0, 10)); // Third packet to send. - } - - @Override - public void sendShowPackets(Player player) { - PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; - - playerConnection.sendPacket(packetPlayOutScoreboardTeamRegister); - playerConnection.sendPacket(packetPlayOutPlayerInfoAdd); - playerConnection.sendPacket(packetPlayOutNamedEntitySpawn); - playerConnection.sendPacket(packetPlayOutEntityHeadRotation); - - Bukkit.getScheduler().runTaskLater(plugin, () -> - playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50); - } - - @Override - public void sendHidePackets(Player player, boolean scheduler) { - PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; - - playerConnection.sendPacket(packetPlayOutEntityDestroy); - playerConnection.sendPacket(packetPlayOutPlayerInfoRemove); - - if (scheduler) { - // Sending this a bit later so the player doesn't see the name (for that split second). - Bukkit.getScheduler().runTaskLater(plugin, () -> - playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5); - } else { - playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister); - } - } - - private GameProfile generateLegacyGameProfile(UUID uuid, String name) { - GameProfile gameProfile = new GameProfile(uuid, name); - - if (skin != null) { - gameProfile.getProperties().put("textures", new Property("textures", skin.getValue(), skin.getSignature())); - } - - return gameProfile; - } -} diff --git a/nms/v1_7_R4/src/main/java/net/jitse/npclib/nms/v1_7_R4/packets/PacketPlayOutEntityHeadRotationWrapper.java b/nms/v1_7_R4/src/main/java/net/jitse/npclib/nms/v1_7_R4/packets/PacketPlayOutEntityHeadRotationWrapper.java deleted file mode 100755 index a8af781..0000000 --- a/nms/v1_7_R4/src/main/java/net/jitse/npclib/nms/v1_7_R4/packets/PacketPlayOutEntityHeadRotationWrapper.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2018 Jitse Boonstra - */ - -package net.jitse.npclib.nms.v1_7_R4.packets; - -import com.comphenix.tinyprotocol.Reflection; -import net.minecraft.server.v1_7_R4.PacketPlayOutEntityHeadRotation; -import org.bukkit.Location; - -/** - * @author Jitse Boonstra - */ -public class PacketPlayOutEntityHeadRotationWrapper { - - public PacketPlayOutEntityHeadRotation create(Location location, int entityId) { - PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation = new PacketPlayOutEntityHeadRotation(); - - Reflection.getField(packetPlayOutEntityHeadRotation.getClass(), "a", int.class). - set(packetPlayOutEntityHeadRotation, entityId); - Reflection.getField(packetPlayOutEntityHeadRotation.getClass(), "b", byte.class) - .set(packetPlayOutEntityHeadRotation, (byte) ((int) location.getYaw() * 256.0F / 360.0F)); - - return packetPlayOutEntityHeadRotation; - } -} diff --git a/nms/v1_7_R4/src/main/java/net/jitse/npclib/nms/v1_7_R4/packets/PacketPlayOutNamedEntitySpawnWrapper.java b/nms/v1_7_R4/src/main/java/net/jitse/npclib/nms/v1_7_R4/packets/PacketPlayOutNamedEntitySpawnWrapper.java deleted file mode 100755 index 61b47a5..0000000 --- a/nms/v1_7_R4/src/main/java/net/jitse/npclib/nms/v1_7_R4/packets/PacketPlayOutNamedEntitySpawnWrapper.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2018 Jitse Boonstra - */ - -package net.jitse.npclib.nms.v1_7_R4.packets; - -import com.comphenix.tinyprotocol.Reflection; -import net.minecraft.server.v1_7_R4.DataWatcher; -import net.minecraft.server.v1_7_R4.PacketPlayOutNamedEntitySpawn; -import net.minecraft.util.com.mojang.authlib.GameProfile; -import org.bukkit.Location; - -/** - * @author Jitse Boonstra - */ -public class PacketPlayOutNamedEntitySpawnWrapper { - - public PacketPlayOutNamedEntitySpawn create(GameProfile gameProfile, Location location, int entityId) { - PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn = new PacketPlayOutNamedEntitySpawn(); - - Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "a", int.class) - .set(packetPlayOutNamedEntitySpawn, entityId); - Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "b", GameProfile.class) - .set(packetPlayOutNamedEntitySpawn, gameProfile); - Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "c", int.class) - .set(packetPlayOutNamedEntitySpawn, (int) Math.floor(location.getX() * 32.0D)); - Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "d", int.class) - .set(packetPlayOutNamedEntitySpawn, (int) Math.floor(location.getY() * 32.0D)); - Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "e", int.class) - .set(packetPlayOutNamedEntitySpawn, (int) Math.floor(location.getZ() * 32.0D)); - Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "f", byte.class) - .set(packetPlayOutNamedEntitySpawn, (byte) ((int) (location.getYaw() * 256.0F / 360.0F))); - Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "g", byte.class) - .set(packetPlayOutNamedEntitySpawn, (byte) ((int) (location.getPitch() * 256.0F / 360.0F))); - - DataWatcher dataWatcher = new DataWatcher(null); - dataWatcher.a(10, (byte) 127); - - Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "i", DataWatcher.class) - .set(packetPlayOutNamedEntitySpawn, dataWatcher); - - return packetPlayOutNamedEntitySpawn; - } -} diff --git a/nms/v1_7_R4/src/main/java/net/jitse/npclib/nms/v1_7_R4/packets/PacketPlayOutPlayerInfoWrapper.java b/nms/v1_7_R4/src/main/java/net/jitse/npclib/nms/v1_7_R4/packets/PacketPlayOutPlayerInfoWrapper.java deleted file mode 100755 index 3673d16..0000000 --- a/nms/v1_7_R4/src/main/java/net/jitse/npclib/nms/v1_7_R4/packets/PacketPlayOutPlayerInfoWrapper.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2018 Jitse Boonstra - */ - -package net.jitse.npclib.nms.v1_7_R4.packets; - -import com.comphenix.tinyprotocol.Reflection; -import net.minecraft.server.v1_7_R4.PacketPlayOutPlayerInfo; -import net.minecraft.util.com.mojang.authlib.GameProfile; - -/** - * @author Jitse Boonstra - */ -public class PacketPlayOutPlayerInfoWrapper { - - public PacketPlayOutPlayerInfo create(int action, GameProfile gameProfile, String name) { - PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo(); - - // Action values: - // 0 = Add player - // 1 = Update gamemode - // 2 = Update latency - // 3 = Update display name - // 4 = Remove player - Reflection.getField(packetPlayOutPlayerInfo.getClass(), "action", int.class) - .set(packetPlayOutPlayerInfo, action); - Reflection.getField(packetPlayOutPlayerInfo.getClass(), "player", GameProfile.class) - .set(packetPlayOutPlayerInfo, gameProfile); - Reflection.getField(packetPlayOutPlayerInfo.getClass(), "username", String.class) - .set(packetPlayOutPlayerInfo, name); - Reflection.getField(packetPlayOutPlayerInfo.getClass(), "ping", int.class) - .set(packetPlayOutPlayerInfo, 0); - Reflection.getField(packetPlayOutPlayerInfo.getClass(), "gamemode", int.class) - .set(packetPlayOutPlayerInfo, 1); - - return packetPlayOutPlayerInfo; - } -} diff --git a/nms/v1_7_R4/src/main/java/net/jitse/npclib/nms/v1_7_R4/packets/PacketPlayOutScoreboardTeamWrapper.java b/nms/v1_7_R4/src/main/java/net/jitse/npclib/nms/v1_7_R4/packets/PacketPlayOutScoreboardTeamWrapper.java deleted file mode 100755 index 2547cdc..0000000 --- a/nms/v1_7_R4/src/main/java/net/jitse/npclib/nms/v1_7_R4/packets/PacketPlayOutScoreboardTeamWrapper.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2018 Jitse Boonstra - */ - -package net.jitse.npclib.nms.v1_7_R4.packets; - -import com.comphenix.tinyprotocol.Reflection; -import net.minecraft.server.v1_7_R4.PacketPlayOutScoreboardTeam; - -import java.util.Collection; - -/** - * @author Jitse Boonstra - */ -public class PacketPlayOutScoreboardTeamWrapper { - - public PacketPlayOutScoreboardTeam createRegisterTeam(String uuidName, String name) { - PacketPlayOutScoreboardTeam packetPlayOutScoreboardTeam = new PacketPlayOutScoreboardTeam(); - - Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "f", int.class) - .set(packetPlayOutScoreboardTeam, 0); - Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "b", String.class) - .set(packetPlayOutScoreboardTeam, name.length() < 16 ? name : name.substring(0, 15)); - Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "a", String.class) - .set(packetPlayOutScoreboardTeam, uuidName); - if (name.length() > 16) { - Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "d", String.class) - .set(packetPlayOutScoreboardTeam, name.substring(15)); - } - if (name.length() > 32) { - Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "c", String.class) - .set(packetPlayOutScoreboardTeam, name.substring(31)); - } - Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "g", int.class) - .set(packetPlayOutScoreboardTeam, 1); - Reflection.FieldAccessor collectionFieldAccessor = Reflection.getField( - packetPlayOutScoreboardTeam.getClass(), "e", Collection.class); - Collection collection = collectionFieldAccessor.get(packetPlayOutScoreboardTeam); - collection.add(name.length() < 16 ? name : name.substring(0, 15)); - collectionFieldAccessor.set(packetPlayOutScoreboardTeam, collection); - - return packetPlayOutScoreboardTeam; - } - - public PacketPlayOutScoreboardTeam createUnregisterTeam(String uuidName) { - PacketPlayOutScoreboardTeam packetPlayOutScoreboardTeam = new PacketPlayOutScoreboardTeam(); - - Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "f", int.class) - .set(packetPlayOutScoreboardTeam, 1); - Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "a", String.class) - .set(packetPlayOutScoreboardTeam, uuidName); - - return packetPlayOutScoreboardTeam; - } -} diff --git a/nms/v1_8_R1/pom.xml b/nms/v1_8_R1/pom.xml index 3e77a4a..03dc672 100755 --- a/nms/v1_8_R1/pom.xml +++ b/nms/v1_8_R1/pom.xml @@ -7,7 +7,7 @@ net.jitse npclib-nms - 1.4.1 + 1.4.2 npclib-nms-v1_8_R1 diff --git a/nms/v1_8_R2/pom.xml b/nms/v1_8_R2/pom.xml index 503951d..78bece0 100755 --- a/nms/v1_8_R2/pom.xml +++ b/nms/v1_8_R2/pom.xml @@ -7,7 +7,7 @@ net.jitse npclib-nms - 1.4.1 + 1.4.2 npclib-nms-v1_8_R2 diff --git a/nms/v1_8_R3/pom.xml b/nms/v1_8_R3/pom.xml index dd75c74..d277bc2 100755 --- a/nms/v1_8_R3/pom.xml +++ b/nms/v1_8_R3/pom.xml @@ -7,7 +7,7 @@ net.jitse npclib-nms - 1.4.1 + 1.4.2 npclib-nms-v1_8_R3 diff --git a/nms/v1_9_R1/pom.xml b/nms/v1_9_R1/pom.xml index 5ab5236..8c479ef 100755 --- a/nms/v1_9_R1/pom.xml +++ b/nms/v1_9_R1/pom.xml @@ -7,7 +7,7 @@ net.jitse npclib-nms - 1.4.1 + 1.4.2 npclib-nms-v1_9_R1 diff --git a/nms/v1_9_R2/pom.xml b/nms/v1_9_R2/pom.xml index e03d755..b8aa703 100755 --- a/nms/v1_9_R2/pom.xml +++ b/nms/v1_9_R2/pom.xml @@ -7,7 +7,7 @@ net.jitse npclib-nms - 1.4.1 + 1.4.2 npclib-nms-v1_9_R2 diff --git a/plugin/pom.xml b/plugin/pom.xml index fda91ac..89c4cfa 100755 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -7,7 +7,7 @@ net.jitse npclib - 1.4.1 + 1.4.2 npclib-plugin diff --git a/pom.xml b/pom.xml index 2e63358..984560e 100755 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ net.jitse npclib - 1.4.1 + 1.4.2 NPCLib https://github.com/JitseB/NPCLib