diff --git a/pom.xml b/pom.xml
index 5c8c024f..671ad797 100644
--- a/pom.xml
+++ b/pom.xml
@@ -16,7 +16,7 @@
${project.version}
- 2.0.4
+ 2.0.71.15.2-R0.1-SNAPSHOT
@@ -302,13 +302,13 @@
junitjunit
- 4.12
+ 4.13testorg.mockitomockito-core
- 3.2.0
+ 3.3.3test
diff --git a/src/main/java/com/comphenix/protocol/AsynchronousManager.java b/src/main/java/com/comphenix/protocol/AsynchronousManager.java
index 3d3cc260..88657548 100644
--- a/src/main/java/com/comphenix/protocol/AsynchronousManager.java
+++ b/src/main/java/com/comphenix/protocol/AsynchronousManager.java
@@ -42,83 +42,63 @@ public interface AsynchronousManager {
* @param listener - the packet listener that will receive these asynchronous events.
* @return An asynchronous handler.
*/
- public abstract AsyncListenerHandler registerAsyncHandler(PacketListener listener);
+ AsyncListenerHandler registerAsyncHandler(PacketListener listener);
/**
* Unregisters and closes the given asynchronous handler.
* @param handler - asynchronous handler.
*/
- public abstract void unregisterAsyncHandler(AsyncListenerHandler handler);
+ void unregisterAsyncHandler(AsyncListenerHandler handler);
/**
* Unregisters and closes the first asynchronous handler associated with the given listener.
* @param listener - asynchronous listener
*/
- public abstract void unregisterAsyncHandler(PacketListener listener);
+ void unregisterAsyncHandler(PacketListener listener);
/**
* Unregisters every asynchronous handler associated with this plugin.
* @param plugin - the original plugin.
*/
- public void unregisterAsyncHandlers(Plugin plugin);
-
- /**
- * Retrieves a immutable set containing the ID of the sent server packets that will be
- * observed by the asynchronous listeners.
- *
- * Deprecated: Use {@link #getSendingTypes()} instead.
- * @return Every filtered server packet.
- */
- @Deprecated
- public abstract Set getSendingFilters();
+ void unregisterAsyncHandlers(Plugin plugin);
/**
* Retrieves a immutable set containing the types of the sent server packets that will be
* observed by the asynchronous listeners.
* @return Every filtered server packet.
*/
- public abstract Set getSendingTypes();
-
- /**
- * Retrieves a immutable set containing the ID of the recieved client packets that will be
- *
- * Deprecated: Use {@link #getReceivingTypes()} instead.
- * observed by the asynchronous listeners.
- * @return Every filtered client packet.
- */
- @Deprecated
- public abstract Set getReceivingFilters();
-
+ Set getSendingTypes();
+
/**
* Retrieves a immutable set containing the types of the received client packets that will be
* observed by the asynchronous listeners.
* @return Every filtered client packet.
*/
- public abstract Set getReceivingTypes();
+ Set getReceivingTypes();
/**
* Determine if a given synchronous packet has asynchronous listeners.
* @param packet - packet to test.
* @return TRUE if it does, FALSE otherwise.
*/
- public abstract boolean hasAsynchronousListeners(PacketEvent packet);
+ boolean hasAsynchronousListeners(PacketEvent packet);
/**
* Retrieve the default packet stream.
* @return Default packet stream.
*/
- public abstract PacketStream getPacketStream();
+ PacketStream getPacketStream();
/**
* Retrieve the default error reporter.
* @return Default reporter.
*/
- public abstract ErrorReporter getErrorReporter();
+ ErrorReporter getErrorReporter();
/**
* Remove listeners, close threads and transmit every delayed packet.
*/
- public abstract void cleanupAll();
+ void cleanupAll();
/**
* Signal that a packet is ready to be transmitted.
@@ -127,29 +107,29 @@ public interface AsynchronousManager {
* has been called previously.
* @param packet - packet to signal.
*/
- public abstract void signalPacketTransmission(PacketEvent packet);
+ void signalPacketTransmission(PacketEvent packet);
/**
* Register a synchronous listener that handles packets when they time out.
* @param listener - synchronous listener that will handle timed out packets.
*/
- public abstract void registerTimeoutHandler(PacketListener listener);
+ void registerTimeoutHandler(PacketListener listener);
/**
* Unregisters a given timeout listener.
* @param listener - the timeout listener to unregister.
*/
- public abstract void unregisterTimeoutHandler(PacketListener listener);
+ void unregisterTimeoutHandler(PacketListener listener);
/**
* Get a immutable set of every registered timeout handler.
* @return Set of every registered timeout handler.
*/
- public abstract Set getTimeoutHandlers();
+ Set getTimeoutHandlers();
/**
* Get an immutable set of every registered asynchronous packet listener.
* @return Set of every asynchronous packet listener.
*/
- public abstract Set getAsyncHandlers();
+ Set getAsyncHandlers();
}
diff --git a/src/main/java/com/comphenix/protocol/CleanupStaticMembers.java b/src/main/java/com/comphenix/protocol/CleanupStaticMembers.java
deleted file mode 100644
index b8f46183..00000000
--- a/src/main/java/com/comphenix/protocol/CleanupStaticMembers.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
- * Copyright (C) 2012 Kristian S. Stangeland
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- * 02111-1307 USA
- */
-
-package com.comphenix.protocol;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.List;
-
-import com.comphenix.protocol.async.AsyncListenerHandler;
-import com.comphenix.protocol.error.ErrorReporter;
-import com.comphenix.protocol.error.Report;
-import com.comphenix.protocol.error.ReportType;
-import com.comphenix.protocol.events.ListeningWhitelist;
-import com.comphenix.protocol.events.PacketContainer;
-import com.comphenix.protocol.injector.BukkitUnwrapper;
-import com.comphenix.protocol.injector.server.AbstractInputStreamLookup;
-import com.comphenix.protocol.injector.server.TemporaryPlayerFactory;
-import com.comphenix.protocol.injector.spigot.SpigotPacketInjector;
-import com.comphenix.protocol.reflect.FieldUtils;
-import com.comphenix.protocol.reflect.FuzzyReflection;
-import com.comphenix.protocol.reflect.MethodUtils;
-import com.comphenix.protocol.reflect.ObjectWriter;
-import com.comphenix.protocol.reflect.compiler.BackgroundCompiler;
-import com.comphenix.protocol.reflect.compiler.StructureCompiler;
-import com.comphenix.protocol.reflect.instances.CollectionGenerator;
-import com.comphenix.protocol.reflect.instances.DefaultInstances;
-import com.comphenix.protocol.reflect.instances.PrimitiveGenerator;
-import com.comphenix.protocol.utility.MinecraftReflection;
-import com.comphenix.protocol.wrappers.ChunkPosition;
-import com.comphenix.protocol.wrappers.WrappedDataWatcher;
-import com.comphenix.protocol.wrappers.WrappedWatchableObject;
-import com.comphenix.protocol.wrappers.nbt.io.NbtBinarySerializer;
-
-/**
- * Used to fix ClassLoader leaks that may lead to filling up the permanent generation.
- *
- * @author Kristian
- */
-class CleanupStaticMembers {
- // Reports
- public final static ReportType REPORT_CANNOT_RESET_FIELD = new ReportType("Unable to reset field %s: %s");
- public final static ReportType REPORT_CANNOT_UNLOAD_CLASS = new ReportType("Unable to unload class %s.");
-
- private ClassLoader loader;
- private ErrorReporter reporter;
-
- public CleanupStaticMembers(ClassLoader loader, ErrorReporter reporter) {
- this.loader = loader;
- this.reporter = reporter;
- }
-
- /**
- * Ensure that the previous ClassLoader is not leaking.
- */
- public void resetAll() {
- // This list must always be updated
- @SuppressWarnings("deprecation")
- Class>[] publicClasses = {
- AsyncListenerHandler.class, ListeningWhitelist.class, PacketContainer.class,
- BukkitUnwrapper.class, DefaultInstances.class, CollectionGenerator.class,
- PrimitiveGenerator.class, FuzzyReflection.class, MethodUtils.class,
- BackgroundCompiler.class, StructureCompiler.class,
- ObjectWriter.class, Packets.Server.class, Packets.Client.class,
- ChunkPosition.class, WrappedDataWatcher.class, WrappedWatchableObject.class,
- AbstractInputStreamLookup.class, TemporaryPlayerFactory.class, SpigotPacketInjector.class,
- MinecraftReflection.class, NbtBinarySerializer.class
- };
-
- String[] internalClasses = {
- "com.comphenix.protocol.events.SerializedOfflinePlayer",
- "com.comphenix.protocol.injector.player.InjectedServerConnection",
- "com.comphenix.protocol.injector.player.NetworkFieldInjector",
- "com.comphenix.protocol.injector.player.NetworkObjectInjector",
- "com.comphenix.protocol.injector.player.NetworkServerInjector",
- "com.comphenix.protocol.injector.player.PlayerInjector",
- "com.comphenix.protocol.injector.EntityUtilities",
- "com.comphenix.protocol.injector.packet.PacketRegistry",
- "com.comphenix.protocol.injector.packet.PacketInjector",
- "com.comphenix.protocol.injector.packet.ReadPacketModifier",
- "com.comphenix.protocol.injector.StructureCache",
- "com.comphenix.protocol.reflect.compiler.BoxingHelper",
- "com.comphenix.protocol.reflect.compiler.MethodDescriptor",
- "com.comphenix.protocol.wrappers.nbt.WrappedElement",
- };
-
- resetClasses(publicClasses);
- resetClasses(getClasses(loader, internalClasses));
- }
-
- private void resetClasses(Class>[] classes) {
- // Reset each class one by one
- for (Class> clazz : classes) {
- resetClass(clazz);
- }
- }
-
- private void resetClass(Class> clazz) {
- for (Field field : clazz.getFields()) {
- Class> type = field.getType();
-
- // Only check static non-primitive fields. We also skip strings.
- if (Modifier.isStatic(field.getModifiers()) &&
- !type.isPrimitive() && !type.equals(String.class) &&
- !type.equals(ReportType.class)) {
-
- try {
- setFinalStatic(field, null);
- } catch (IllegalAccessException e) {
- // Just inform the player
- reporter.reportWarning(this,
- Report.newBuilder(REPORT_CANNOT_RESET_FIELD).error(e).messageParam(field.getName(), e.getMessage())
- );
- e.printStackTrace();
- }
- }
- }
- }
-
- // HACK! HAACK!
- private static void setFinalStatic(Field field, Object newValue) throws IllegalAccessException {
- int modifier = field.getModifiers();
- boolean isFinal = Modifier.isFinal(modifier);
-
- Field modifiersField = isFinal ? FieldUtils.getField(Field.class, "modifiers", true) : null;
-
- // We have to remove the final field first
- if (isFinal) {
- FieldUtils.writeField(modifiersField, field, modifier & ~Modifier.FINAL, true);
- }
-
- // Now we can safely modify the field
- FieldUtils.writeStaticField(field, newValue, true);
-
- // Revert modifier
- if (isFinal) {
- FieldUtils.writeField(modifiersField, field, modifier, true);
- }
- }
-
- private Class>[] getClasses(ClassLoader loader, String[] names) {
- List> output = new ArrayList>();
-
- for (String name : names) {
- try {
- output.add(loader.loadClass(name));
- } catch (ClassNotFoundException e) {
- // Warn the user
- reporter.reportWarning(this, Report.newBuilder(REPORT_CANNOT_UNLOAD_CLASS).error(e).messageParam(name));
- }
- }
-
- return output.toArray(new Class>[0]);
- }
-}
diff --git a/src/main/java/com/comphenix/protocol/PacketType.java b/src/main/java/com/comphenix/protocol/PacketType.java
index 4d9c9175..d59e3656 100644
--- a/src/main/java/com/comphenix/protocol/PacketType.java
+++ b/src/main/java/com/comphenix/protocol/PacketType.java
@@ -6,8 +6,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.*;
-import java.util.concurrent.Callable;
-import java.util.concurrent.Future;
import java.util.function.Consumer;
import com.comphenix.protocol.PacketTypeLookup.ClassLookup;
@@ -15,15 +13,14 @@ import com.comphenix.protocol.events.ConnectionSide;
import com.comphenix.protocol.injector.packet.PacketRegistry;
import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.utility.MinecraftVersion;
-import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
-import com.google.common.util.concurrent.Futures;
import org.apache.commons.lang.WordUtils;
import org.bukkit.Bukkit;
+import org.bukkit.scheduler.BukkitRunnable;
/**
* Represents the type of a packet in a specific protocol.
@@ -953,34 +950,29 @@ public class PacketType implements Serializable, Cloneable, Comparable scheduleRegister(final PacketType type, final String name) {
- Callable callable = new Callable() {
+ public static void scheduleRegister(final PacketType type, final String name) {
+ BukkitRunnable runnable = new BukkitRunnable() {
@Override
- public Boolean call() throws Exception {
+ public void run() {
PacketTypeEnum objEnum;
// A bit ugly, but performance is critical
objEnum = getObjectEnum(type);
if (objEnum.registerMember(type, name)) {
- getLookup().addPacketTypes(Arrays.asList(type));
- return true;
+ getLookup().addPacketTypes(Collections.singletonList(type));
}
- return false;
}
};
- // Execute in the main thread if possible
if (Bukkit.getServer() == null || Bukkit.isPrimaryThread()) {
try {
- return Futures.immediateFuture(callable.call());
- } catch (Exception e) {
- return Futures.immediateFailedFuture(e);
- }
+ runnable.run();
+ } catch (Exception ignored) { }
+ } else {
+ runnable.runTaskLater(ProtocolLibrary.getPlugin(), 0);
}
- return ProtocolLibrary.getExecutorSync().submit(callable);
}
/**
diff --git a/src/main/java/com/comphenix/protocol/Packets.java b/src/main/java/com/comphenix/protocol/Packets.java
deleted file mode 100644
index 8610979d..00000000
--- a/src/main/java/com/comphenix/protocol/Packets.java
+++ /dev/null
@@ -1,300 +0,0 @@
-/*
- * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
- * Copyright (C) 2012 Kristian S. Stangeland
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- * 02111-1307 USA
- */
-
-package com.comphenix.protocol;
-
-import com.comphenix.protocol.reflect.IntEnum;
-
-/**
- * List of known packet IDs since 1.3.2.
- *
- * Deprecated: Use {@link PacketType} instead.
- * @author Kristian
- */
-@Deprecated
-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;
-
- /**
- * The maximum number of unique packet IDs. It's unlikely this will ever change.
- */
- public static final int PACKET_COUNT = 256;
-
- /**
- * List of packets sent only by the server.
- *
- * Deprecated: Use {@link PacketType} instead.
- * @author Kristian
- */
- @Deprecated
- public static final class Server extends IntEnum {
- /**
- * The singleton instance. Can also be retrieved from the parent class.
- */
- private static Server INSTANCE = new Server();
-
- public static final int KEEP_ALIVE = 0;
- public static final int LOGIN = 1;
- public static final int CHAT = 3;
- public static final int UPDATE_TIME = 4;
- public static final int ENTITY_EQUIPMENT = 5;
- public static final int SPAWN_POSITION = 6;
- public static final int UPDATE_HEALTH = 8;
- public static final int RESPAWN = 9;
- public static final int FLYING = 10;
- public static final int PLAYER_POSITION = 11;
- public static final int PLAYER_LOOK = 12;
- public static final int PLAYER_LOOK_MOVE = 13;
- /**
- * Made bi-directional in 1.4.6.
- */
- public static final int BLOCK_ITEM_SWITCH = 16;
- public static final int ENTITY_LOCATION_ACTION = 17;
- public static final int ARM_ANIMATION = 18;
- public static final int NAMED_ENTITY_SPAWN = 20;
- /**
- * Removed in 1.4.6 and replaced with VEHICLE_SPAWN.
- * @see Protocol History - MinecraftCoalition
- */
- @Deprecated()
- public static final int PICKUP_SPAWN = 21;
- public static final int COLLECT = 22;
- public static final int VEHICLE_SPAWN = 23;
- public static final int MOB_SPAWN = 24;
- public static final int ENTITY_PAINTING = 25;
- public static final int ADD_EXP_ORB = 26;
- public static final int ENTITY_VELOCITY = 28;
- public static final int DESTROY_ENTITY = 29;
- public static final int ENTITY = 30;
- public static final int REL_ENTITY_MOVE = 31;
- public static final int ENTITY_LOOK = 32;
- public static final int REL_ENTITY_MOVE_LOOK = 33;
- public static final int ENTITY_TELEPORT = 34;
- public static final int ENTITY_HEAD_ROTATION = 35;
- public static final int ENTITY_STATUS = 38;
- public static final int ATTACH_ENTITY = 39;
-
- /**
- * Sent when an entities DataWatcher is updated.
- *
- * Remember to clone the packet if you are modifying it.
- */
- public static final int ENTITY_METADATA = 40;
- public static final int MOB_EFFECT = 41;
- public static final int REMOVE_MOB_EFFECT = 42;
- public static final int SET_EXPERIENCE = 43;
- public static final int UPDATE_ATTRIBUTES = 44;
- public static final int MAP_CHUNK = 51;
- public static final int MULTI_BLOCK_CHANGE = 52;
- public static final int BLOCK_CHANGE = 53;
- public static final int PLAY_NOTE_BLOCK = 54;
- public static final int BLOCK_BREAK_ANIMATION = 55;
- public static final int MAP_CHUNK_BULK = 56;
- public static final int EXPLOSION = 60;
- public static final int WORLD_EVENT = 61;
- public static final int NAMED_SOUND_EFFECT = 62;
- public static final int WORLD_PARTICLES = 63;
- public static final int BED = 70;
- public static final int WEATHER = 71;
- public static final int OPEN_WINDOW = 100;
- public static final int CLOSE_WINDOW = 101;
- public static final int SET_SLOT = 103;
- public static final int WINDOW_ITEMS = 104;
- public static final int CRAFT_PROGRESS_BAR = 105;
- public static final int TRANSACTION = 106;
- public static final int SET_CREATIVE_SLOT = 107;
- public static final int UPDATE_SIGN = 130;
- public static final int ITEM_DATA = 131;
-
- /**
- * Sent the first time a tile entity (chest inventory, etc.) is withing range of the player, or has been updated.
- *
- * Remember to clone the packet if you are modifying it.
- */
- public static final int TILE_ENTITY_DATA = 132;
- public static final int OPEN_TILE_ENTITY = 133;
- public static final int STATISTIC = 200;
- public static final int PLAYER_INFO = 201;
- public static final int ABILITIES = 202;
- public static final int TAB_COMPLETE = 203;
- public static final int SCOREBOARD_OBJECTIVE = 206;
- public static final int UPDATE_SCORE = 207;
- public static final int DISPLAY_SCOREBOARD = 208;
- public static final int TEAMS = 209;
- public static final int CUSTOM_PAYLOAD = 250;
- public static final int KEY_RESPONSE = 252;
- public static final int KEY_REQUEST = 253;
- public static final int KICK_DISCONNECT = 255;
-
- /**
- * This packet was introduced in 1.7.2.
- */
- public static final int PING_TIME = 230;
-
- /**
- * This packet was introduced in 1.7.2.
- */
- public static final int LOGIN_SUCCESS = 232;
-
- /**
- * A registry that parses between names and packet IDs.
- * @return The current server registry.
- */
- public static Server getRegistry() {
- return INSTANCE;
- }
-
- // We only allow a single instance of this class
- private Server() {
- super();
- }
- }
-
- /**
- * List of packets sent by the client.
- *
- * Deprecated: Use {@link PacketType} instead.
- * @author Kristian
- */
- @Deprecated
- public static class Client extends IntEnum {
- /**
- * The singleton instance. Can also be retrieved from the parent class.
- */
- private static Client INSTANCE = new Client();
-
- public static final int KEEP_ALIVE = 0;
- public static final int LOGIN = 1;
- public static final int HANDSHAKE = 2;
- public static final int CHAT = 3;
- public static final int USE_ENTITY = 7;
-
- /**
- * Since 1.3.1, the client no longer sends a respawn packet. Moved to CLIENT_COMMAND.
- */
- @Deprecated
- public static final int RESPAWN = 9;
-
- public static final int FLYING = 10;
- public static final int PLAYER_POSITION = 11;
- public static final int PLAYER_LOOK = 12;
- public static final int PLAYER_LOOK_MOVE = 13;
- public static final int BLOCK_DIG = 14;
- public static final int PLACE = 15;
- public static final int BLOCK_ITEM_SWITCH = 16;
- public static final int ARM_ANIMATION = 18;
- public static final int ENTITY_ACTION = 19;
- public static final int PLAYER_INPUT = 27;
- public static final int CLOSE_WINDOW = 101;
- public static final int WINDOW_CLICK = 102;
- public static final int TRANSACTION = 106;
- public static final int SET_CREATIVE_SLOT = 107;
- public static final int BUTTON_CLICK = 108;
- public static final int UPDATE_SIGN = 130;
- public static final int ABILITIES = 202;
- public static final int TAB_COMPLETE = 203;
- public static final int LOCALE_AND_VIEW_DISTANCE = 204;
- public static final int CLIENT_COMMAND = 205;
- public static final int CUSTOM_PAYLOAD = 250;
- public static final int KEY_RESPONSE = 252;
- public static final int GET_INFO = 254;
- public static final int KICK_DISCONNECT = 255;
-
- /**
- * This packet was introduced in 1.7.2.
- */
- public static final int PING_TIME = 230;
-
- /**
- * This packet was introduced in 1.7.2.
- */
- public static final int LOGIN_START = 231;
-
- /**
- * A registry that parses between names and packet IDs.
- * @return The current client registry.
- */
- public static Client getRegistry() {
- return INSTANCE;
- }
-
- // Like above
- private Client() {
- super();
- }
- }
-
- /**
- * A registry that parses between names and packet IDs.
- *
- * Deprecated: Use {@link PacketType} instead.
- * @return The current client registry.
- */
- @Deprecated
- public static Server getServerRegistry() {
- return Server.getRegistry();
- }
-
- /**
- * A registry that parses between names and packet IDs.
- *
- * Deprecated: Use {@link PacketType} instead.
- * @return The current server registry.
- */
- @Deprecated
- public static Client getClientRegistry() {
- return Client.INSTANCE;
- }
-
- /**
- * Find a packet by name. Must be capitalized and use underscores.
- *
- * Deprecated: Use {@link PacketType} instead.
- * @param name - name of packet to find.
- * @return The packet ID found.
- */
- @Deprecated
- public static int valueOf(String name) {
- Integer serverAttempt = Server.INSTANCE.valueOf(name);
-
- if (serverAttempt != null)
- return serverAttempt;
- else
- return Client.INSTANCE.valueOf(name);
- }
-
- /**
- * Retrieves the name of a packet.
- *
- * Deprecated: Use {@link PacketType} instead.
- * @param packetID - packet to retrieve name.
- * @return The name, or NULL if unable to find such a packet.
- */
- @Deprecated
- public static String getDeclaredName(int packetID) {
- String serverAttempt = Server.INSTANCE.getDeclaredName(packetID);
-
- if (serverAttempt != null)
- return serverAttempt;
- else
- return Client.INSTANCE.getDeclaredName(packetID);
- }
-}
diff --git a/src/main/java/com/comphenix/protocol/ProtocolLib.java b/src/main/java/com/comphenix/protocol/ProtocolLib.java
index e6b6781b..42ce511b 100644
--- a/src/main/java/com/comphenix/protocol/ProtocolLib.java
+++ b/src/main/java/com/comphenix/protocol/ProtocolLib.java
@@ -26,21 +26,8 @@ import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.bukkit.Server;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.PluginCommand;
-import org.bukkit.plugin.Plugin;
-import org.bukkit.plugin.PluginManager;
-import org.bukkit.plugin.java.JavaPlugin;
-
-import com.comphenix.protocol.executors.BukkitExecutors;
import com.comphenix.protocol.async.AsyncFilterManager;
-import com.comphenix.protocol.error.BasicErrorReporter;
-import com.comphenix.protocol.error.DelegatedErrorReporter;
-import com.comphenix.protocol.error.DetailedErrorReporter;
-import com.comphenix.protocol.error.ErrorReporter;
-import com.comphenix.protocol.error.Report;
-import com.comphenix.protocol.error.ReportType;
+import com.comphenix.protocol.error.*;
import com.comphenix.protocol.injector.DelayedSingleTask;
import com.comphenix.protocol.injector.InternalManager;
import com.comphenix.protocol.injector.PacketFilterManager;
@@ -55,7 +42,13 @@ import com.comphenix.protocol.utility.MinecraftVersion;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
-import com.google.common.util.concurrent.ListeningScheduledExecutorService;
+
+import org.bukkit.Server;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.PluginCommand;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.PluginManager;
+import org.bukkit.plugin.java.JavaPlugin;
/**
* The main entry point for ProtocolLib.
@@ -112,10 +105,6 @@ public class ProtocolLib extends JavaPlugin {
// Metrics and statistics
private Statistics statistics;
- // Executors
- private static ListeningScheduledExecutorService executorAsync;
- private static ListeningScheduledExecutorService executorSync;
-
// Structure compiler
private BackgroundCompiler backgroundCompiler;
@@ -157,10 +146,6 @@ public class ProtocolLib extends JavaPlugin {
// Initialize enhancer factory
EnhancerFactory.getInstance().setClassLoader(getClassLoader());
- // Initialize executors
- executorAsync = BukkitExecutors.newAsynchronous(this);
- executorSync = BukkitExecutors.newSynchronous(this);
-
// Add global parameters
DetailedErrorReporter detailedReporter = new DetailedErrorReporter(this);
reporter = getFilteredReporter(detailedReporter);
@@ -213,7 +198,7 @@ public class ProtocolLib extends JavaPlugin {
.build();
// Initialize the API
- ProtocolLibrary.init(this, config, protocolManager, reporter, executorAsync, executorSync);
+ ProtocolLibrary.init(this, config, protocolManager, reporter);
// Setup error reporter
detailedReporter.addGlobalParameter("manager", protocolManager);
diff --git a/src/main/java/com/comphenix/protocol/ProtocolLibrary.java b/src/main/java/com/comphenix/protocol/ProtocolLibrary.java
index 5a456545..3c0d3430 100644
--- a/src/main/java/com/comphenix/protocol/ProtocolLibrary.java
+++ b/src/main/java/com/comphenix/protocol/ProtocolLibrary.java
@@ -19,12 +19,11 @@ package com.comphenix.protocol;
import java.util.Arrays;
import java.util.List;
-import org.apache.commons.lang.Validate;
-import org.bukkit.plugin.Plugin;
-
import com.comphenix.protocol.error.BasicErrorReporter;
import com.comphenix.protocol.error.ErrorReporter;
-import com.google.common.util.concurrent.ListeningScheduledExecutorService;
+
+import org.apache.commons.lang.Validate;
+import org.bukkit.plugin.Plugin;
/**
* The main entry point for ProtocolLib.
@@ -56,21 +55,15 @@ public class ProtocolLibrary {
private static ProtocolManager manager;
private static ErrorReporter reporter = new BasicErrorReporter();
- private static ListeningScheduledExecutorService executorAsync;
- private static ListeningScheduledExecutorService executorSync;
-
private static boolean updatesDisabled;
private static boolean initialized;
- protected static void init(Plugin plugin, ProtocolConfig config, ProtocolManager manager, ErrorReporter reporter,
- ListeningScheduledExecutorService executorAsync, ListeningScheduledExecutorService executorSync) {
+ protected static void init(Plugin plugin, ProtocolConfig config, ProtocolManager manager, ErrorReporter reporter) {
Validate.isTrue(!initialized, "ProtocolLib has already been initialized.");
ProtocolLibrary.plugin = plugin;
ProtocolLibrary.config = config;
ProtocolLibrary.manager = manager;
ProtocolLibrary.reporter = reporter;
- ProtocolLibrary.executorAsync = executorAsync;
- ProtocolLibrary.executorSync = executorSync;
initialized = true;
}
@@ -106,26 +99,6 @@ public class ProtocolLibrary {
return reporter;
}
- /**
- * Retrieve an executor service for performing asynchronous tasks on the behalf of ProtocolLib.
- *
- * Note that this service is NULL if ProtocolLib has not been initialized yet.
- * @return The executor service, or NULL.
- */
- public static ListeningScheduledExecutorService getExecutorAsync() {
- return executorAsync;
- }
-
- /**
- * Retrieve an executor service for performing synchronous tasks (main thread) on the behalf of ProtocolLib.
- *
- * Note that this service is NULL if ProtocolLib has not been initialized yet.
- * @return The executor service, or NULL.
- */
- public static ListeningScheduledExecutorService getExecutorSync() {
- return executorSync;
- }
-
/**
* Disables the ProtocolLib update checker.
*/
diff --git a/src/main/java/com/comphenix/protocol/ProtocolManager.java b/src/main/java/com/comphenix/protocol/ProtocolManager.java
index 1ff9c6bd..b73942dc 100644
--- a/src/main/java/com/comphenix/protocol/ProtocolManager.java
+++ b/src/main/java/com/comphenix/protocol/ProtocolManager.java
@@ -49,7 +49,7 @@ public interface ProtocolManager extends PacketStream {
* @param player - the player.
* @return The associated protocol version, or {@link Integer#MIN_VALUE} if unknown.
*/
- public int getProtocolVersion(Player player);
+ int getProtocolVersion(Player player);
/**
* Send a packet to the given player.
@@ -63,7 +63,7 @@ public interface ProtocolManager extends PacketStream {
* @throws InvocationTargetException - if an error occurred when sending the packet.
*/
@Override
- public void sendServerPacket(Player receiver, PacketContainer packet, boolean filters)
+ void sendServerPacket(Player receiver, PacketContainer packet, boolean filters)
throws InvocationTargetException;
/**
@@ -79,7 +79,7 @@ public interface ProtocolManager extends PacketStream {
* @throws IllegalAccessException If the underlying method caused an error.
*/
@Override
- public void recieveClientPacket(Player sender, PacketContainer packet, boolean filters)
+ void recieveClientPacket(Player sender, PacketContainer packet, boolean filters)
throws IllegalAccessException, InvocationTargetException;
/**
@@ -87,7 +87,7 @@ public interface ProtocolManager extends PacketStream {
* @param packet - the packet to broadcast.
* @throws FieldAccessException If we were unable to send the packet due to reflection problems.
*/
- public void broadcastServerPacket(PacketContainer packet);
+ void broadcastServerPacket(PacketContainer packet);
/**
* Broadcast a packet to every player that is receiving information about a given entity.
@@ -99,7 +99,7 @@ public interface ProtocolManager extends PacketStream {
* @param includeTracker - whether or not to also transmit the packet to the entity, if it is a tracker.
* @throws FieldAccessException If we were unable to send the packet due to reflection problems.
*/
- public void broadcastServerPacket(PacketContainer packet, Entity entity, boolean includeTracker);
+ void broadcastServerPacket(PacketContainer packet, Entity entity, boolean includeTracker);
/**
* Broadcast a packet to every player within the given maximum observer distance.
@@ -107,13 +107,13 @@ public interface ProtocolManager extends PacketStream {
* @param origin - the origin to consider when calculating the distance to each observer.
* @param maxObserverDistance - the maximum distance to the origin.
*/
- public void broadcastServerPacket(PacketContainer packet, Location origin, int maxObserverDistance);
+ void broadcastServerPacket(PacketContainer packet, Location origin, int maxObserverDistance);
/**
* Retrieves a list of every registered packet listener.
* @return Every registered packet listener.
*/
- public ImmutableSet getPacketListeners();
+ ImmutableSet getPacketListeners();
/**
* Adds a packet listener.
@@ -123,7 +123,7 @@ public interface ProtocolManager extends PacketStream {
* can register it again.
* @param listener - new packet listener.
*/
- public void addPacketListener(PacketListener listener);
+ void addPacketListener(PacketListener listener);
/**
* Removes a given packet listener.
@@ -131,47 +131,20 @@ public interface ProtocolManager extends PacketStream {
* Attempting to remove a listener that doesn't exist has no effect.
* @param listener - the packet listener to remove.
*/
- public void removePacketListener(PacketListener listener);
+ void removePacketListener(PacketListener listener);
/**
* Removes every listener associated with the given plugin.
* @param plugin - the plugin to unload.
*/
- public void removePacketListeners(Plugin plugin);
+ void removePacketListeners(Plugin plugin);
- /**
- * Constructs a new encapsulated Minecraft packet with the given ID.
- *
- * Deprecated: Use {@link #createPacket(PacketType)} instead.
- * @param id - packet ID.
- * @return New encapsulated Minecraft packet.
- */
- @Deprecated
- public PacketContainer createPacket(int id);
-
/**
* Constructs a new encapsulated Minecraft packet with the given ID.
* @param type - packet type.
* @return New encapsulated Minecraft packet.
*/
- public PacketContainer createPacket(PacketType type);
-
- /**
- * Constructs a new encapsulated Minecraft packet with the given ID.
- *
- * If set to true, the forceDefaults option will force the system to automatically
- * give non-primitive fields in the packet sensible default values. For instance, certain
- * packets - like Packet60Explosion - require a List or Set to be non-null. If the
- * forceDefaults option is true, the List or Set will be automatically created.
- *
- * Deprecated: Use {@link #createPacket(PacketType, boolean)} instead.
- *
- * @param id - packet ID.
- * @param forceDefaults - TRUE to use sensible defaults in most fields, FALSE otherwise.
- * @return New encapsulated Minecraft packet.
- */
- @Deprecated
- public PacketContainer createPacket(int id, boolean forceDefaults);
+ PacketContainer createPacket(PacketType type);
/**
* Constructs a new encapsulated Minecraft packet with the given ID.
@@ -185,18 +158,7 @@ public interface ProtocolManager extends PacketStream {
* @param forceDefaults - TRUE to use sensible defaults in most fields, FALSE otherwise.
* @return New encapsulated Minecraft packet.
*/
- public PacketContainer createPacket(PacketType type, boolean forceDefaults);
-
- /**
- * Construct a packet using the special builtin Minecraft constructors.
- *
- * Deprecated: Use {@link #createPacketConstructor(PacketType, Object...)} instead.
- * @param id - the packet ID.
- * @param arguments - arguments that will be passed to the constructor.
- * @return The packet constructor.
- */
- @Deprecated
- public PacketConstructor createPacketConstructor(int id, Object... arguments);
+ PacketContainer createPacket(PacketType type, boolean forceDefaults);
/**
* Construct a packet using the special builtin Minecraft constructors.
@@ -204,7 +166,7 @@ public interface ProtocolManager extends PacketStream {
* @param arguments - arguments that will be passed to the constructor.
* @return The packet constructor.
*/
- public PacketConstructor createPacketConstructor(PacketType type, Object... arguments);
+ PacketConstructor createPacketConstructor(PacketType type, Object... arguments);
/**
* Completely resend an entity to a list of clients.
@@ -214,7 +176,7 @@ public interface ProtocolManager extends PacketStream {
* @param entity - entity to refresh.
* @param observers - the clients to update.
*/
- public void updateEntity(Entity entity, List observers) throws FieldAccessException;
+ void updateEntity(Entity entity, List observers) throws FieldAccessException;
/**
* Retrieve the associated entity.
@@ -223,7 +185,7 @@ public interface ProtocolManager extends PacketStream {
* @return The associated entity.
* @throws FieldAccessException Reflection failed.
*/
- public Entity getEntityFromID(World container, int id) throws FieldAccessException;
+ Entity getEntityFromID(World container, int id) throws FieldAccessException;
/**
* Retrieve every client that is receiving information about a given entity.
@@ -231,55 +193,37 @@ public interface ProtocolManager extends PacketStream {
* @return Every client/player that is tracking the given entity.
* @throws FieldAccessException If reflection failed.
*/
- public List getEntityTrackers(Entity entity) throws FieldAccessException;
-
- /**
- * Retrieves a immutable set containing the ID of the sent server packets that will be observed by listeners.
- *
- * Deprecated: Use {@link #getSendingFilterTypes()} instead.
- * @return Every filtered server packet.
- */
- @Deprecated
- public Set getSendingFilters();
-
+ List getEntityTrackers(Entity entity) throws FieldAccessException;
+
/**
* Retrieves a immutable set containing the type of the sent server packets that will be observed by listeners.
* @return Every filtered server packet.
*/
- public Set getSendingFilterTypes();
-
- /**
- * Retrieves a immutable set containing the ID of the received client packets that will be observed by listeners.
- *
- * Deprecated: Use {@link #getReceivingFilterTypes()} instead.
- * @return Every filtered client packet.
- */
- @Deprecated
- public Set getReceivingFilters();
-
+ Set getSendingFilterTypes();
+
/**
* Retrieves a immutable set containing the type of the received client packets that will be observed by listeners.
* @return Every filtered client packet.
*/
- public Set getReceivingFilterTypes();
+ Set getReceivingFilterTypes();
/**
* Retrieve the current Minecraft version.
* @return The current version.
*/
- public MinecraftVersion getMinecraftVersion();
+ MinecraftVersion getMinecraftVersion();
/**
* Determines whether or not this protocol manager has been disabled.
* @return TRUE if it has, FALSE otherwise.
*/
- public boolean isClosed();
+ boolean isClosed();
/**
* Retrieve the current asynchronous packet manager.
* @return Asynchronous packet manager.
*/
- public AsynchronousManager getAsynchronousManager();
+ AsynchronousManager getAsynchronousManager();
- public void verifyWhitelist(PacketListener listener, ListeningWhitelist whitelist);
+ void verifyWhitelist(PacketListener listener, ListeningWhitelist whitelist);
}
diff --git a/src/main/java/com/comphenix/protocol/async/AsyncFilterManager.java b/src/main/java/com/comphenix/protocol/async/AsyncFilterManager.java
index abc21532..74cc1149 100644
--- a/src/main/java/com/comphenix/protocol/async/AsyncFilterManager.java
+++ b/src/main/java/com/comphenix/protocol/async/AsyncFilterManager.java
@@ -23,10 +23,6 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
-import org.bukkit.entity.Player;
-import org.bukkit.plugin.Plugin;
-import org.bukkit.scheduler.BukkitScheduler;
-
import com.comphenix.protocol.AsynchronousManager;
import com.comphenix.protocol.PacketStream;
import com.comphenix.protocol.PacketType;
@@ -37,12 +33,15 @@ import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.events.PacketListener;
import com.comphenix.protocol.injector.PrioritizedListener;
import com.comphenix.protocol.injector.SortedPacketListenerList;
-import com.comphenix.protocol.injector.packet.PacketRegistry;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.scheduler.BukkitScheduler;
+
/**
* Represents a filter manager for asynchronous packets.
*
@@ -88,7 +87,7 @@ public class AsyncFilterManager implements AsynchronousManager {
// Initialize timeout listeners
this.serverTimeoutListeners = new SortedPacketListenerList();
this.clientTimeoutListeners = new SortedPacketListenerList();
- this.timeoutListeners = Sets.newSetFromMap(new ConcurrentHashMap());
+ this.timeoutListeners = Sets.newSetFromMap(new ConcurrentHashMap<>());
this.playerSendingHandler = new PlayerSendingHandler(reporter, serverTimeoutListeners, clientTimeoutListeners);
this.serverProcessingQueue = new PacketProcessingQueue(playerSendingHandler);
@@ -327,22 +326,12 @@ public class AsyncFilterManager implements AsynchronousManager {
getProcessingQueue(syncPacket).enqueue(newEvent, true);
}
}
-
- @Override
- public Set getSendingFilters() {
- return PacketRegistry.toLegacy(serverProcessingQueue.keySet());
- }
-
+
@Override
public Set getReceivingTypes() {
return serverProcessingQueue.keySet();
}
-
- @Override
- public Set getReceivingFilters() {
- return PacketRegistry.toLegacy(clientProcessingQueue.keySet());
- }
-
+
@Override
public Set getSendingTypes() {
return clientProcessingQueue.keySet();
diff --git a/src/main/java/com/comphenix/protocol/events/ListeningWhitelist.java b/src/main/java/com/comphenix/protocol/events/ListeningWhitelist.java
index e2d30292..01a5c974 100644
--- a/src/main/java/com/comphenix/protocol/events/ListeningWhitelist.java
+++ b/src/main/java/com/comphenix/protocol/events/ListeningWhitelist.java
@@ -17,11 +17,7 @@
package com.comphenix.protocol.events;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.EnumSet;
-import java.util.Set;
+import java.util.*;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.injector.GamePhase;
@@ -44,93 +40,21 @@ public class ListeningWhitelist {
private final GamePhase gamePhase;
private final Set options;
private final Set types;
-
- // Cache whitelist
- private transient Set intWhitelist;
-
+
private ListeningWhitelist(Builder builder) {
this.priority = builder.priority;
this.types = builder.types;
this.gamePhase = builder.gamePhase;
this.options = builder.options;
}
-
- /**
- * Creates a packet whitelist for a given priority with a set of packet IDs.
- *
- * Deprecated: Use {@link #newBuilder()} instead.
- * @param priority - the listener priority.
- * @param whitelist - set of IDs to observe/enable.
- */
- @Deprecated
- public ListeningWhitelist(ListenerPriority priority, Set whitelist) {
- this(priority, whitelist, GamePhase.PLAYING);
- }
- /**
- * Creates a packet whitelist for a given priority with a set of packet IDs.
- *
- * Deprecated: Use {@link #newBuilder()} instead.
- * @param priority - the listener priority.
- * @param whitelist - set of IDs to observe/enable.
- * @param gamePhase - which game phase to receieve notifications on.
- */
- @Deprecated
- public ListeningWhitelist(ListenerPriority priority, Set whitelist, GamePhase gamePhase) {
+ private ListeningWhitelist(ListenerPriority priority) {
this.priority = priority;
- this.types = PacketRegistry.toPacketTypes(safeSet(whitelist));
- this.gamePhase = gamePhase;
- this.options = EnumSet.noneOf(ListenerOptions.class);
- }
-
- /**
- * Creates a packet whitelist of a given priority for a list of packets.
- *
- * Deprecated: Use {@link #newBuilder()} instead.
- * @param priority - the listener priority.
- * @param whitelist - list of packet IDs to observe/enable.
- */
- @Deprecated
- public ListeningWhitelist(ListenerPriority priority, Integer... whitelist) {
- this.priority = priority;
- this.types = PacketRegistry.toPacketTypes(Sets.newHashSet(whitelist));
+ this.types = new HashSet<>();
this.gamePhase = GamePhase.PLAYING;
this.options = EnumSet.noneOf(ListenerOptions.class);
}
- /**
- * Creates a packet whitelist for a given priority with a set of packet IDs.
- *
- * Deprecated: Use {@link #newBuilder()} instead.
- * @param priority - the listener priority.
- * @param whitelist - list of packet IDs to observe/enable.
- * @param gamePhase - which game phase to receieve notifications on.
- */
- @Deprecated
- public ListeningWhitelist(ListenerPriority priority, Integer[] whitelist, GamePhase gamePhase) {
- this.priority = priority;
- this.types = PacketRegistry.toPacketTypes(Sets.newHashSet(whitelist));
- this.gamePhase = gamePhase;
- this.options = EnumSet.noneOf(ListenerOptions.class);
- }
-
- /**
- * Creates a packet whitelist for a given priority with a set of packet IDs and options.
- *
- * Deprecated: Use {@link #newBuilder()} instead.
- * @param priority - the listener priority.
- * @param whitelist - list of packet IDs to observe/enable.
- * @param gamePhase - which game phase to receieve notifications on.
- * @param options - every special option associated with this whitelist.
- */
- @Deprecated
- public ListeningWhitelist(ListenerPriority priority, Integer[] whitelist, GamePhase gamePhase, ListenerOptions... options) {
- this.priority = priority;
- this.types = PacketRegistry.toPacketTypes(Sets.newHashSet(whitelist));
- this.gamePhase = gamePhase;
- this.options = safeEnumSet(Arrays.asList(options), ListenerOptions.class);
- }
-
/**
* Whether or not this whitelist has any enabled packets.
* @return TRUE if there are any packets, FALSE otherwise.
@@ -147,19 +71,6 @@ public class ListeningWhitelist {
return priority;
}
- /**
- * Retrieves the list of packets that will be observed by the listeners.
- *
- * Deprecated: Use {@link #getTypes()} instead.
- * @return Packet whitelist.
- */
- @Deprecated
- public Set getWhitelist() {
- if (intWhitelist == null)
- intWhitelist = PacketRegistry.toLegacy(types);
- return intWhitelist;
- }
-
/**
* Retrieves a set of the packets that will be observed by the listeners.
* @return Packet whitelist.
@@ -189,23 +100,6 @@ public class ListeningWhitelist {
return Objects.hashCode(priority, types, gamePhase, options);
}
- /**
- * Determine if any of the given IDs can be found in the whitelist.
- * @param whitelist - whitelist to test.
- * @param idList - list of packet IDs to find.
- * @return TRUE if any of the packets in the list can be found in the whitelist, FALSE otherwise.
- */
- public static boolean containsAny(ListeningWhitelist whitelist, int... idList) {
- if (whitelist != null) {
- for (int i = 0; i < idList.length; i++) {
- if (whitelist.getWhitelist().contains(idList[i]))
- return true;
- }
- }
-
- return false;
- }
-
/**
* Determine if the given whitelist is empty or not.
* @param whitelist - the whitelist to test.
@@ -273,7 +167,7 @@ public class ListeningWhitelist {
/**
* Construct a copy of a given set.
- * @param list - the set to copy.
+ * @param set - the set to copy.
* @return The copied set.
*/
private static Set safeSet(Collection set) {
@@ -364,20 +258,7 @@ public class ListeningWhitelist {
public Builder high() {
return priority(ListenerPriority.HIGH);
}
-
- /**
- * Set the whitelist of packet IDs to copy when constructing new whitelists.
- *
- * Deprecated: Use {@link #types(Collection)} instead.
- * @param whitelist - the whitelist of packets.
- * @return This builder, for chaining.
- */
- @Deprecated
- public Builder whitelist(Collection whitelist) {
- this.types = PacketRegistry.toPacketTypes(safeSet(whitelist));
- return this;
- }
-
+
/**
* Set the whitelist of packet types to copy when constructing new whitelists.
* @param types - the whitelist of packets.
diff --git a/src/main/java/com/comphenix/protocol/events/MonitorAdapter.java b/src/main/java/com/comphenix/protocol/events/MonitorAdapter.java
index dd58dd8e..83fb07ae 100644
--- a/src/main/java/com/comphenix/protocol/events/MonitorAdapter.java
+++ b/src/main/java/com/comphenix/protocol/events/MonitorAdapter.java
@@ -17,15 +17,11 @@
package com.comphenix.protocol.events;
-import java.util.logging.Level;
import java.util.logging.Logger;
-import org.bukkit.plugin.Plugin;
-
-import com.comphenix.protocol.Packets;
-import com.comphenix.protocol.injector.GamePhase;
import com.comphenix.protocol.injector.packet.PacketRegistry;
-import com.comphenix.protocol.reflect.FieldAccessException;
+
+import org.bukkit.plugin.Plugin;
/**
* Represents a listener that is notified of every sent and received packet.
@@ -45,26 +41,17 @@ public abstract class MonitorAdapter implements PacketListener {
public MonitorAdapter(Plugin plugin, ConnectionSide side, Logger logger) {
initialize(plugin, side, logger);
}
-
- @SuppressWarnings("deprecation")
+
private void initialize(Plugin plugin, ConnectionSide side, Logger logger) {
this.plugin = plugin;
// Recover in case something goes wrong
- try {
- if (side.isForServer())
- this.sending = ListeningWhitelist.newBuilder().monitor().types(PacketRegistry.getServerPacketTypes()).gamePhaseBoth().build();
- if (side.isForClient())
- this.receiving = ListeningWhitelist.newBuilder().monitor().types(PacketRegistry.getClientPacketTypes()).gamePhaseBoth().build();
- } catch (FieldAccessException e) {
- if (side.isForServer())
- this.sending = new ListeningWhitelist(ListenerPriority.MONITOR, Packets.Server.getRegistry().values(), GamePhase.BOTH);
- if (side.isForClient())
- this.receiving = new ListeningWhitelist(ListenerPriority.MONITOR, Packets.Client.getRegistry().values(), GamePhase.BOTH);
- logger.log(Level.WARNING, "Defaulting to 1.3 packets.", e);
- }
+ if (side.isForServer())
+ this.sending = ListeningWhitelist.newBuilder().monitor().types(PacketRegistry.getServerPacketTypes()).gamePhaseBoth().build();
+ if (side.isForClient())
+ this.receiving = ListeningWhitelist.newBuilder().monitor().types(PacketRegistry.getClientPacketTypes()).gamePhaseBoth().build();
}
-
+
/**
* Retrieve a logger, even if we're running in a CraftBukkit version that doesn't support it.
* @param plugin - the plugin to retrieve.
diff --git a/src/main/java/com/comphenix/protocol/events/PacketAdapter.java b/src/main/java/com/comphenix/protocol/events/PacketAdapter.java
index a5204268..29cd316e 100644
--- a/src/main/java/com/comphenix/protocol/events/PacketAdapter.java
+++ b/src/main/java/com/comphenix/protocol/events/PacketAdapter.java
@@ -19,19 +19,17 @@ package com.comphenix.protocol.events;
import java.util.List;
import java.util.Set;
-
import javax.annotation.Nonnull;
-import org.bukkit.plugin.Plugin;
-
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.injector.GamePhase;
-import com.comphenix.protocol.injector.packet.PacketRegistry;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
+import org.bukkit.plugin.Plugin;
+
/**
* Represents a packet listener with useful constructors.
*
@@ -103,151 +101,7 @@ public abstract class PacketAdapter implements PacketListener {
public PacketAdapter(Plugin plugin, ListenerPriority listenerPriority, PacketType... types) {
this(params(plugin, types).listenerPriority(listenerPriority));
}
-
- /**
- * Initialize a packet listener with default priority.
- *
- * Deprecated: Use {@link #params()} instead.
- * @param plugin - the plugin that spawned this listener.
- * @param connectionSide - the packet type the listener is looking for.
- * @param packets - the packet IDs the listener is looking for.
- */
- @Deprecated
- public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, Integer... packets) {
- this(plugin, connectionSide, ListenerPriority.NORMAL, packets);
- }
-
- /**
- * Initialize a packet listener for a single connection side.
- *
- * Deprecated: Use {@link #params()} instead.
- * @param plugin - the plugin that spawned this listener.
- * @param connectionSide - the packet type the listener is looking for.
- * @param listenerPriority - the event priority.
- * @param packets - the packet IDs the listener is looking for.
- */
- @Deprecated
- public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority, Set packets) {
- this(plugin, connectionSide, listenerPriority, GamePhase.PLAYING, packets.toArray(new Integer[0]));
- }
-
- /**
- * Initialize a packet listener for a single connection side.
- *
- * The game phase is used to optimize performance. A listener should only choose BOTH or LOGIN if it's absolutely necessary.
- *
- * Deprecated: Use {@link #params()} instead.
- * @param plugin - the plugin that spawned this listener.
- * @param connectionSide - the packet type the listener is looking for.
- * @param gamePhase - which game phase this listener is active under.
- * @param packets - the packet IDs the listener is looking for.
- */
- @Deprecated
- public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, GamePhase gamePhase, Set packets) {
- this(plugin, connectionSide, ListenerPriority.NORMAL, gamePhase, packets.toArray(new Integer[0]));
- }
-
- /**
- * Initialize a packet listener for a single connection side.
- *
- * The game phase is used to optimize performance. A listener should only choose BOTH or LOGIN if it's absolutely necessary.
- *
- * Deprecated: Use {@link #params()} instead.
- * @param plugin - the plugin that spawned this listener.
- * @param connectionSide - the packet type the listener is looking for.
- * @param listenerPriority - the event priority.
- * @param gamePhase - which game phase this listener is active under.
- * @param packets - the packet IDs the listener is looking for.
- */
- @Deprecated
- public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority, GamePhase gamePhase, Set packets) {
- this(plugin, connectionSide, listenerPriority, gamePhase, packets.toArray(new Integer[0]));
- }
-
- /**
- * Initialize a packet listener for a single connection side.
- *
- * Deprecated: Use {@link #params()} instead.
- * @param plugin - the plugin that spawned this listener.
- * @param connectionSide - the packet type the listener is looking for.
- * @param listenerPriority - the event priority.
- * @param packets - the packet IDs the listener is looking for.
- */
- @Deprecated
- public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority, Integer... packets) {
- this(plugin, connectionSide, listenerPriority, GamePhase.PLAYING, packets);
- }
-
- /**
- * Initialize a packet listener for a single connection side.
- *
- * Deprecated: Use {@link #params()} instead.
- * @param plugin - the plugin that spawned this listener.
- * @param connectionSide - the packet type the listener is looking for.
- * @param options - which listener options to use.
- * @param packets - the packet IDs the listener is looking for.
- */
- @Deprecated
- public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, ListenerOptions[] options, Integer... packets) {
- this(plugin, connectionSide, ListenerPriority.NORMAL, GamePhase.PLAYING, options, packets);
- }
-
- /**
- * Initialize a packet listener for a single connection side.
- *
- * Deprecated: Use {@link #params()} instead.
- * @param plugin - the plugin that spawned this listener.
- * @param connectionSide - the packet type the listener is looking for.
- * @param gamePhase - which game phase this listener is active under.
- * @param packets - the packet IDs the listener is looking for.
- */
- @Deprecated
- public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, GamePhase gamePhase, Integer... packets) {
- this(plugin, connectionSide, ListenerPriority.NORMAL, gamePhase, packets);
- }
-
- /**
- * Initialize a packet listener for a single connection side.
- *
- * The game phase is used to optimize performance. A listener should only choose BOTH or LOGIN if it's absolutely necessary.
- *
- * Deprecated: Use {@link #params()} instead.
- * @param plugin - the plugin that spawned this listener.
- * @param connectionSide - the packet type the listener is looking for.
- * @param listenerPriority - the event priority.
- * @param gamePhase - which game phase this listener is active under.
- * @param packets - the packet IDs the listener is looking for.
- */
- @Deprecated
- public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority, GamePhase gamePhase, Integer... packets) {
- this(plugin, connectionSide, listenerPriority, gamePhase, new ListenerOptions[0], packets);
- }
-
- /**
- * Initialize a packet listener for a single connection side.
- *
- * The game phase is used to optimize performance. A listener should only choose BOTH or LOGIN if it's absolutely necessary.
- *
- * Listener options must be specified in order for {@link NetworkMarker#getInputBuffer()} to function correctly.
- *
- * Deprecated: Use {@link #params()} instead.
- * @param plugin - the plugin that spawned this listener.
- * @param connectionSide - the packet type the listener is looking for.
- * @param listenerPriority - the event priority.
- * @param gamePhase - which game phase this listener is active under.
- * @param options - which listener options to use.
- * @param packets - the packet IDs the listener is looking for.
- */
- @Deprecated
- public PacketAdapter(
- Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority,
- GamePhase gamePhase, ListenerOptions[] options, Integer... packets) {
-
- this(plugin, connectionSide, listenerPriority, gamePhase, options,
- PacketRegistry.toPacketTypes(Sets.newHashSet(packets), connectionSide.getSender()).toArray(new PacketType[0])
- );
- }
-
+
// For internal use only
private PacketAdapter(
Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority,
@@ -374,20 +228,6 @@ public abstract class PacketAdapter implements PacketListener {
public static AdapterParameteters params() {
return new AdapterParameteters();
}
-
- /**
- * Construct a helper object for passing parameters to the packet adapter.
- *
- * This is often simpler and better than passing them directly to each constructor.
- * Deprecated: Use {@link #params(Plugin, PacketType...)} instead.
- * @param plugin - the plugin that spawned this listener.
- * @param packets - the packet IDs the listener is looking for.
- * @return Helper object.
- */
- @Deprecated
- public static AdapterParameteters params(Plugin plugin, Integer... packets) {
- return new AdapterParameteters().plugin(plugin).packets(packets);
- }
/**
* Construct a helper object for passing parameters to the packet adapter.
@@ -532,17 +372,7 @@ public abstract class PacketAdapter implements PacketListener {
public AdapterParameteters optionIntercept() {
return addOption(ListenerOptions.INTERCEPT_INPUT_BUFFER);
}
-
- /**
- * Set the listener option to {@link ListenerOptions#DISABLE_GAMEPHASE_DETECTION}, causing ProtocolLib to ignore automatic game phase detection.
- *
- * This is no longer relevant in 1.7.2.
- * @return This builder, for chaining.
- */
- public AdapterParameteters optionManualGamePhase() {
- return addOption(ListenerOptions.DISABLE_GAMEPHASE_DETECTION);
- }
-
+
/**
* Set the listener option to {@link ListenerOptions#ASYNC}, indicating that our listener is thread safe.
*
@@ -552,40 +382,7 @@ public abstract class PacketAdapter implements PacketListener {
public AdapterParameteters optionAsync() {
return addOption(ListenerOptions.ASYNC);
}
-
- /**
- * Set the packet IDs of the packets the listener is looking for.
- *
- * This parameter is required.
- *
- * Deprecated: Use {@link #types(PacketType...)} instead.
- * @param packets - the packet IDs to look for.
- * @return This builder, for chaining.
- */
- @Deprecated
- public AdapterParameteters packets(@Nonnull Integer... packets) {
- Preconditions.checkNotNull(packets, "packets cannot be NULL");
- PacketType[] types = new PacketType[packets.length];
-
- for (int i = 0; i < types.length; i++) {
- types[i] = PacketType.findLegacy(packets[i]);
- }
- this.packets = types;
- return this;
- }
-
- /**
- * Set the packet IDs of the packets the listener is looking for.
- *
- * This parameter is required.
- * @param packets - a set of the packet IDs to look for.
- * @return This builder, for chaining.
- */
- @Deprecated
- public AdapterParameteters packets(@Nonnull Set packets) {
- return packets(packets.toArray(new Integer[0]));
- }
-
+
/**
* Set the packet types the listener is looking for.
*
diff --git a/src/main/java/com/comphenix/protocol/events/PacketContainer.java b/src/main/java/com/comphenix/protocol/events/PacketContainer.java
index ed16eec7..f900516c 100644
--- a/src/main/java/com/comphenix/protocol/events/PacketContainer.java
+++ b/src/main/java/com/comphenix/protocol/events/PacketContainer.java
@@ -68,6 +68,7 @@ import org.bukkit.util.Vector;
*
* @author Kristian
*/
+@SuppressWarnings("unused")
public class PacketContainer implements Serializable {
private static final long serialVersionUID = 3;
@@ -111,40 +112,6 @@ public class PacketContainer implements Serializable {
private static final Set CLONING_UNSUPPORTED = Sets.newHashSet(
PacketType.Play.Server.UPDATE_ATTRIBUTES, PacketType.Status.Server.SERVER_INFO);
- /**
- * Creates a packet container for a new packet.
- *
- * Deprecated: Use {@link #PacketContainer(PacketType)} instead.
- * @param id - ID of the packet to create.
- */
- @Deprecated
- public PacketContainer(int id) {
- this(PacketType.findLegacy(id), StructureCache.newPacket(PacketType.findLegacy(id)));
- }
-
- /**
- * Creates a packet container for an existing packet.
- * @param id - ID of the given packet.
- * @param handle - contained packet.
- * @deprecated Use {@link #PacketContainer(PacketType, Object)} instead
- */
- @Deprecated
- public PacketContainer(int id, Object handle) {
- this(PacketType.findLegacy(id), handle);
- }
-
- /**
- * Creates a packet container for an existing packet.
- * @param id - ID of the given packet.
- * @param handle - contained packet.
- * @param structure - structure modifier.
- * @deprecated Use {@link #PacketContainer(PacketType, Object, StructureModifier)} instead
- */
- @Deprecated
- public PacketContainer(int id, Object handle, StructureModifier