protocolLookup = new WeakHashMap<>();
-
- @Override public void addChannel(Player player) {
- io.netty.channel.Channel channel = getChannel(player);
- this.addChannelHandlerExecutor.execute(() -> {
- if (channel != null) {
- if (channel.pipeline().get(this.playerKey) != null) {
- channel.pipeline().remove(this.playerKey);
- }
- channel.pipeline().addBefore(this.handlerKey, this.playerKey, new ChannelHandler(player, this));
- }
- });
- }
-
- @Override public void removeChannel(Player player) {
- io.netty.channel.Channel channel = getChannel(player);
- this.removeChannelHandlerExecutor.execute(() -> {
- if (channel != null && channel.pipeline().get(this.playerKey) != null) {
- channel.pipeline().remove(this.playerKey);
- }
- });
- }
-
- public ProtocolVersion getProtocolVersion(Player player) {
- Channel channel = channelLookup.get(player.getName());
-
- // Lookup channel again
- if (channel == null) {
-
- channelLookup.put(player.getName(), getChannel(player));
- }
-
- return ProtocolVersion.getVersion(protocolLookup.getOrDefault(channel, -1));
- }
-
- private io.netty.channel.Channel getChannel(Player player) {
- return (io.netty.channel.Channel) Reflections.getNMSClass("NetworkManager").getFirstFieldByType(io.netty.channel.Channel.class).get(networkManagerField.get(playerConnectionField.get(ReflectionsUtil.getEntityPlayer(player))));
- }
-
- private class ChannelHandler extends io.netty.channel.ChannelDuplexHandler {
- private final Player player;
- private final ChannelHandlerAbstract channelHandlerAbstract;
-
- ChannelHandler(Player player, ChannelHandlerAbstract channelHandlerAbstract) {
- this.player = player;
- this.channelHandlerAbstract = channelHandlerAbstract;
- }
-
- @Override public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) throws Exception {
- Object packet = Atlas.getInstance().getTinyProtocolHandler().onPacketOutAsync(player, msg);
- if (packet != null) {
- super.write(ctx, packet, promise);
- }
- }
-
- @Override public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) throws Exception {
- 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));
- }
- }
- Object packet = Atlas.getInstance().getTinyProtocolHandler().onPacketInAsync(player, msg);
- if (packet != null) {
- super.channelRead(ctx, packet);
- }
- }
- }
-
- public void sendPacket(Player player, Object packet) {
- getChannel(player).pipeline().writeAndFlush(packet);
- }
-}
diff --git a/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/tinyprotocol/api/packets/channelhandler/ChannelHandlerAbstract.java b/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/tinyprotocol/api/packets/channelhandler/ChannelHandlerAbstract.java
deleted file mode 100644
index 84a5c28b..00000000
--- a/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/tinyprotocol/api/packets/channelhandler/ChannelHandlerAbstract.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Created by Justin Heflin on 4/19/18 8:21 PM
- * Copyright (c) 2018.
- *
- * Can be redistributed non commercially as long as credit is given to original copyright owner.
- *
- * last modified: 4/19/18 7:22 PM
- */
-package cc.funkemunky.api.tinyprotocol.api.packets.channelhandler;
-
-import cc.funkemunky.api.tinyprotocol.api.ProtocolVersion;
-import cc.funkemunky.api.tinyprotocol.api.packets.reflections.Reflections;
-import cc.funkemunky.api.tinyprotocol.api.packets.reflections.types.WrappedField;
-import cc.funkemunky.api.tinyprotocol.reflection.Reflection;
-import org.bukkit.entity.Player;
-
-import java.util.concurrent.Executor;
-import java.util.concurrent.Executors;
-
-public abstract class ChannelHandlerAbstract {
- static final WrappedField networkManagerField = Reflections.getNMSClass("PlayerConnection").getFieldByName("networkManager");
- static final WrappedField playerConnectionField = Reflections.getNMSClass("EntityPlayer").getFieldByName("playerConnection");
- // Packets we have to intercept
- static final Class> PACKET_SET_PROTOCOL = Reflection.getMinecraftClass("PacketHandshakingInSetProtocol");
- static final Class> PACKET_LOGIN_IN_START = Reflection.getMinecraftClass("PacketLoginInStart");
- final Executor addChannelHandlerExecutor;
- final Executor removeChannelHandlerExecutor;
- final String handlerKey;
- final String playerKey;
-
- ChannelHandlerAbstract() {
- this.addChannelHandlerExecutor = Executors.newSingleThreadExecutor();
- this.removeChannelHandlerExecutor = Executors.newSingleThreadExecutor();
- this.handlerKey = "packet_handler";
- this.playerKey = "atlas_player_handler";
- }
-
- public abstract void addChannel(Player player);
-
- public abstract void removeChannel(Player player);
-
- public abstract void sendPacket(Player player, Object packet);
-
- public abstract ProtocolVersion getProtocolVersion(Player player);
-}
diff --git a/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/tinyprotocol/api/packets/channelhandler/TinyProtocol1_7.java b/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/tinyprotocol/api/packets/channelhandler/TinyProtocol1_7.java
new file mode 100644
index 00000000..6676d259
--- /dev/null
+++ b/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/tinyprotocol/api/packets/channelhandler/TinyProtocol1_7.java
@@ -0,0 +1,536 @@
+package cc.funkemunky.api.tinyprotocol.api.packets.channelhandler;
+
+import cc.funkemunky.api.Atlas;
+import cc.funkemunky.api.tinyprotocol.api.packets.AbstractTinyProtocol;
+import cc.funkemunky.api.tinyprotocol.reflection.FieldAccessor;
+import cc.funkemunky.api.tinyprotocol.reflection.MethodInvoker;
+import cc.funkemunky.api.tinyprotocol.reflection.Reflection;
+import com.google.common.collect.MapMaker;
+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.lang.reflect.Method;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
+
+/**
+ * Represents a very tiny alternative to ProtocolLib.
+ *
+ * It now supports intercepting packets during login and status ping (such as OUT_SERVER_PING)!
+ *
+ * @author Kristian
+ */
+
+public abstract class TinyProtocol1_7 implements AbstractTinyProtocol {
+ private static final AtomicInteger ID = new AtomicInteger(0);
+
+ // Used in order to lookup a channel
+ private static final MethodInvoker getPlayerHandle = Reflection.getMethod("{obc}.entity.CraftPlayer", "getHandle");
+ private static final FieldAccessor