From e8112dba0e0bf4d495605749f07ea916d4a055e4 Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Tue, 5 Feb 2013 01:37:41 +0100 Subject: [PATCH] Made IntegerSet accessible. Encapsulating the injection handler. --- .../main/java/com/comphenix/protocol/Packets.java | 5 +++++ .../player => concurrency}/IntegerSet.java | 4 ++-- .../injector/player/NetworkFieldInjector.java | 1 + .../injector/player/NetworkObjectInjector.java | 1 + .../injector/player/NetworkServerInjector.java | 1 + .../injector/player/PlayerInjectionHandler.java | 15 --------------- .../player/ProxyPlayerInjectionHandler.java | 13 ++++--------- 7 files changed, 14 insertions(+), 26 deletions(-) rename ProtocolLib/src/main/java/com/comphenix/protocol/{injector/player => concurrency}/IntegerSet.java (97%) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/Packets.java b/ProtocolLib/src/main/java/com/comphenix/protocol/Packets.java index 1d364779..ada35964 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/Packets.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/Packets.java @@ -30,6 +30,11 @@ import com.comphenix.protocol.reflect.IntEnum; */ public final class Packets { + /** + * The highest possible packet ID. It's unlikely that this value will ever change. + */ + public static final int MAXIMUM_PACKET_ID = 255; + /** * List of packets sent only by the server. * @author Kristian diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/IntegerSet.java b/ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/IntegerSet.java similarity index 97% rename from ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/IntegerSet.java rename to ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/IntegerSet.java index 3deea142..2393fced 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/IntegerSet.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/IntegerSet.java @@ -15,7 +15,7 @@ * 02111-1307 USA */ -package com.comphenix.protocol.injector.player; +package com.comphenix.protocol.concurrency; import java.util.Arrays; import java.util.HashSet; @@ -27,7 +27,7 @@ import java.util.Set; * This class is intentionally missing a size method. * @author Kristian */ -class IntegerSet { +public class IntegerSet { private final boolean[] array; /** diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/NetworkFieldInjector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/NetworkFieldInjector.java index ffb6ca3d..88d9beec 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/NetworkFieldInjector.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/NetworkFieldInjector.java @@ -28,6 +28,7 @@ import java.util.concurrent.ConcurrentHashMap; import org.bukkit.entity.Player; import com.comphenix.protocol.Packets; +import com.comphenix.protocol.concurrency.IntegerSet; import com.comphenix.protocol.error.ErrorReporter; import com.comphenix.protocol.events.ListeningWhitelist; import com.comphenix.protocol.events.PacketListener; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/NetworkObjectInjector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/NetworkObjectInjector.java index 951c4b23..8b9f44f8 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/NetworkObjectInjector.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/NetworkObjectInjector.java @@ -31,6 +31,7 @@ import java.lang.reflect.Method; import org.bukkit.entity.Player; import com.comphenix.protocol.Packets; +import com.comphenix.protocol.concurrency.IntegerSet; import com.comphenix.protocol.error.ErrorReporter; import com.comphenix.protocol.events.ListeningWhitelist; import com.comphenix.protocol.events.PacketListener; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/NetworkServerInjector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/NetworkServerInjector.java index 7261547b..da328bd2 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/NetworkServerInjector.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/NetworkServerInjector.java @@ -32,6 +32,7 @@ import net.sf.cglib.proxy.NoOp; import org.bukkit.entity.Player; +import com.comphenix.protocol.concurrency.IntegerSet; import com.comphenix.protocol.error.ErrorReporter; import com.comphenix.protocol.events.PacketListener; import com.comphenix.protocol.injector.GamePhase; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/PlayerInjectionHandler.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/PlayerInjectionHandler.java index dd23e6fd..a1fe1b44 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/PlayerInjectionHandler.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/PlayerInjectionHandler.java @@ -79,13 +79,6 @@ public interface PlayerInjectionHandler { */ public abstract void injectPlayer(Player player); - /** - * Determine if it's truly necessary to perform the given player injection. - * @param phase - current game phase. - * @return TRUE if we should perform the injection, FALSE otherwise. - */ - public abstract boolean isInjectionNecessary(GamePhase phase); - /** * Invoke special routines for handling disconnect before a player is uninjected. * @param player - player to process. @@ -99,14 +92,6 @@ public interface PlayerInjectionHandler { */ public abstract boolean uninjectPlayer(Player player); - /** - * Unregisters the given player. - * @param player - player to unregister. - * @param removeAuxiliary - TRUE to remove auxiliary information, such as input stream and address. - * @return TRUE if a player has been uninjected, FALSE otherwise. - */ - public abstract boolean uninjectPlayer(Player player, boolean removeAuxiliary); - /** * Unregisters a player by the given address. *

diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/ProxyPlayerInjectionHandler.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/ProxyPlayerInjectionHandler.java index dea74009..053fe0ef 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/ProxyPlayerInjectionHandler.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/ProxyPlayerInjectionHandler.java @@ -29,7 +29,9 @@ import java.util.concurrent.TimeUnit; import org.bukkit.Server; import org.bukkit.entity.Player; +import com.comphenix.protocol.Packets; import com.comphenix.protocol.concurrency.BlockingHashMap; +import com.comphenix.protocol.concurrency.IntegerSet; import com.comphenix.protocol.error.ErrorReporter; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; @@ -52,12 +54,7 @@ class ProxyPlayerInjectionHandler implements PlayerInjectionHandler { * The maximum number of milliseconds to wait until a player can be looked up by connection. */ private static final long TIMEOUT_PLAYER_LOOKUP = 2000; // ms - - /** - * The highest possible packet ID. It's unlikely that this value will ever change. - */ - private static final int MAXIMUM_PACKET_ID = 255; - + // Server connection injection private InjectedServerConnection serverInjection; @@ -88,7 +85,7 @@ class ProxyPlayerInjectionHandler implements PlayerInjectionHandler { private ListenerInvoker invoker; // Enabled packet filters - private IntegerSet sendingFilters = new IntegerSet(MAXIMUM_PACKET_ID + 1); + private IntegerSet sendingFilters = new IntegerSet(Packets.MAXIMUM_PACKET_ID + 1); // List of packet listeners private Set packetListeners; @@ -262,7 +259,6 @@ class ProxyPlayerInjectionHandler implements PlayerInjectionHandler { * @param phase - current game phase. * @return TRUE if we should perform the injection, FALSE otherwise. */ - @Override public boolean isInjectionNecessary(GamePhase phase) { return injectionFilter.apply(phase); } @@ -417,7 +413,6 @@ class ProxyPlayerInjectionHandler implements PlayerInjectionHandler { * @param removeAuxiliary - TRUE to remove auxiliary information, such as input stream and address. * @return TRUE if a player has been uninjected, FALSE otherwise. */ - @Override public boolean uninjectPlayer(Player player, boolean removeAuxiliary) { return uninjectPlayer(player, removeAuxiliary, false); }