[TinyProtocol] Update to 1.8

This commit is contained in:
Dan Mulloy 2014-12-08 16:24:27 -05:00
parent 74297da901
commit a60e2522c9
3 changed files with 29 additions and 42 deletions

View File

@ -3,32 +3,18 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.comphenix.tinyprotocol</groupId> <groupId>com.comphenix.tinyprotocol</groupId>
<artifactId>TinyProtocol</artifactId> <artifactId>TinyProtocol</artifactId>
<version>0.1.0</version> <version>0.2.0</version>
<name>TinyProtocol</name> <name>TinyProtocol</name>
<description>Intercept packets without ProtocolLib.</description> <description>Intercept packets without ProtocolLib.</description>
<distributionManagement>
<repository>
<id>comphenix-releases</id>
<name>Comphenix Maven Releases</name>
<url>http://repo.comphenix.net/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>comphenix-snapshots</id>
<name>Comphenix Maven Snapshots</name>
<url>http://repo.comphenix.net/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<repositories> <repositories>
<repository> <repository>
<id>md_5-repo</id> <id>spigot-repo</id>
<url>http://repo.md-5.net/content/repositories/public/</url> <url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository> </repository>
<repository> <repository>
<id>comphenix-rep</id> <id>shadowvolt-repo</id>
<name>Comphenix Maven Releases</name> <url>http://ci.shadowvolt.com/plugin/repository/everything/</url>
<url>http://repo.comphenix.net/content/groups/public</url>
</repository> </repository>
</repositories> </repositories>
@ -56,12 +42,13 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.7.10-R0.1-SNAPSHOT</version> <version>1.8-R0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId> <artifactId>spigot</artifactId>
<version>1.7.10-R0.1-SNAPSHOT</version> <version>1.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -1,5 +1,7 @@
package com.comphenix.tinyprotocol; package com.comphenix.tinyprotocol;
import io.netty.channel.Channel;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -10,8 +12,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import com.comphenix.tinyprotocol.Reflection.ConstructorInvoker; import com.comphenix.tinyprotocol.Reflection.ConstructorInvoker;
import com.comphenix.tinyprotocol.Reflection.FieldAccessor; import com.comphenix.tinyprotocol.Reflection.FieldAccessor;
import net.minecraft.util.io.netty.channel.Channel;
public class ExamplePlugin extends JavaPlugin { public class ExamplePlugin extends JavaPlugin {
// Chat packets // Chat packets
private FieldAccessor<String> CHAT_MESSAGE = Reflection.getField( private FieldAccessor<String> CHAT_MESSAGE = Reflection.getField(
@ -86,7 +86,7 @@ public class ExamplePlugin extends JavaPlugin {
sender.sendMessage(ChatColor.RED + "Can only be invoked by a player."); sender.sendMessage(ChatColor.RED + "Can only be invoked by a player.");
} }
return false; return false;
} }
private void sendExplosion(Player player) { private void sendExplosion(Player player) {
try { try {

View File

@ -1,5 +1,14 @@
package com.comphenix.tinyprotocol; package com.comphenix.tinyprotocol;
import io.netty.channel.Channel;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelPromise;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -8,17 +17,6 @@ import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level; import java.util.logging.Level;
import net.minecraft.util.com.mojang.authlib.GameProfile;
// These are not versioned, but they require CraftBukkit
import net.minecraft.util.io.netty.channel.Channel;
import net.minecraft.util.io.netty.channel.ChannelDuplexHandler;
import net.minecraft.util.io.netty.channel.ChannelFuture;
import net.minecraft.util.io.netty.channel.ChannelHandlerContext;
import net.minecraft.util.io.netty.channel.ChannelInboundHandlerAdapter;
import net.minecraft.util.io.netty.channel.ChannelInitializer;
import net.minecraft.util.io.netty.channel.ChannelPipeline;
import net.minecraft.util.io.netty.channel.ChannelPromise;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -33,6 +31,7 @@ import com.comphenix.tinyprotocol.Reflection.FieldAccessor;
import com.comphenix.tinyprotocol.Reflection.MethodInvoker; import com.comphenix.tinyprotocol.Reflection.MethodInvoker;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.MapMaker; import com.google.common.collect.MapMaker;
import com.mojang.authlib.GameProfile;
/** /**
* Represents a very tiny alternative to ProtocolLib in 1.7.2. * Represents a very tiny alternative to ProtocolLib in 1.7.2.
@ -83,7 +82,7 @@ public abstract class TinyProtocol {
protected Plugin plugin; protected Plugin plugin;
/** /**
* Construct a new instance of TinyProtocol, and start intercepting packets for all connected clients and future clients. * Construct a new instance of TinyProtocol, and start intercepting packets for all connected clients and future clients.
* <p> * <p>
* You can construct multiple instances per plugin. * You can construct multiple instances per plugin.
* @param plugin - the plugin. * @param plugin - the plugin.
@ -146,7 +145,7 @@ public abstract class TinyProtocol {
listener = new Listener() { listener = new Listener() {
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public final void onPlayerLogin(PlayerLoginEvent e) { public final void onPlayerLogin(PlayerLoginEvent e) {
if (closed) if (closed)
return; return;
Channel channel = getChannel(e.getPlayer()); Channel channel = getChannel(e.getPlayer());
@ -182,7 +181,7 @@ public abstract class TinyProtocol {
List<Object> list = Reflection.getField(serverConnection.getClass(), List.class, i).get(serverConnection); List<Object> list = Reflection.getField(serverConnection.getClass(), List.class, i).get(serverConnection);
for (Object item : list) { for (Object item : list) {
if (!ChannelFuture.class.isInstance(item)) if (!ChannelFuture.class.isInstance(item))
break; break;
// Channel future that contains the server connection // Channel future that contains the server connection
@ -204,6 +203,7 @@ public abstract class TinyProtocol {
// Remove channel handler // Remove channel handler
serverChannel.eventLoop().execute(new Runnable() { serverChannel.eventLoop().execute(new Runnable() {
@Override
public void run() { public void run() {
try { try {
pipeline.remove(serverChannelHandler); pipeline.remove(serverChannelHandler);
@ -302,7 +302,7 @@ public abstract class TinyProtocol {
} }
/** /**
* Add a custom channel handler to the given player's channel pipeline, * Add a custom channel handler to the given player's channel pipeline,
* allowing us to intercept sent and received packets. * allowing us to intercept sent and received packets.
* <p> * <p>
* This will automatically be called when a player has logged in. * This will automatically be called when a player has logged in.
@ -336,7 +336,7 @@ public abstract class TinyProtocol {
channel.pipeline().addBefore("packet_handler", handlerName, interceptor); channel.pipeline().addBefore("packet_handler", handlerName, interceptor);
uninjectedChannels.remove(channel); uninjectedChannels.remove(channel);
} }
return interceptor; return interceptor;
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// Try again // Try again
return (PacketInterceptor) channel.pipeline().get(handlerName); return (PacketInterceptor) channel.pipeline().get(handlerName);
@ -429,7 +429,7 @@ public abstract class TinyProtocol {
* Channel handler that is inserted into the player's channel pipeline, allowing us to intercept sent and received packets. * Channel handler that is inserted into the player's channel pipeline, allowing us to intercept sent and received packets.
* @author Kristian * @author Kristian
*/ */
private final class PacketInterceptor extends ChannelDuplexHandler { private final class PacketInterceptor extends ChannelDuplexHandler {
// Updated by the login event // Updated by the login event
public volatile Player player; public volatile Player player;
@ -450,7 +450,7 @@ public abstract class TinyProtocol {
} }
} }
@Override @Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
try { try {
msg = onPacketOutAsync(player, ctx.channel(), msg); msg = onPacketOutAsync(player, ctx.channel(), msg);
} catch (Exception e) { } catch (Exception e) {