From cfb59449905c2189685d34eafa4f2750bca99c10 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Sat, 15 Nov 2014 13:02:03 -0500 Subject: [PATCH] Update to 1.7.10, update readme, organize imports --- ProtocolLib/pom.xml | 285 ++++++------ .../comphenix/protocol/CommandProtocol.java | 1 + .../com/comphenix/protocol/PacketType.java | 2 +- .../concurrency/ConcurrentPlayerMap.java | 2 +- .../protocol/error/BasicErrorReporter.java | 1 + .../protocol/events/ListeningWhitelist.java | 1 - .../protocol/events/MonitorAdapter.java | 4 - .../protocol/events/NetworkMarker.java | 2 + .../protocol/events/PacketContainer.java | 11 +- .../protocol/events/ScheduledPacket.java | 5 +- .../injector/DelayedPacketManager.java | 3 +- .../injector/PacketFilterManager.java | 434 +++++++++--------- .../injector/SortedPacketListenerList.java | 2 +- .../injector/netty/BootstrapList.java | 5 +- .../injector/netty/ChannelInjector.java | 1 - .../protocol/injector/netty/ChannelProxy.java | 8 +- .../injector/netty/InjectionFactory.java | 2 + .../injector/netty/NettyProtocolInjector.java | 11 +- .../injector/packet/LegacyNetworkMarker.java | 1 + .../injector/packet/LegacyPacketRegistry.java | 3 +- .../injector/packet/ProxyPacketInjector.java | 5 +- .../injector/packet/ReadPacketModifier.java | 6 +- .../injector/packet/WritePacketModifier.java | 8 +- .../injector/player/InjectedArrayList.java | 10 +- .../player/NetworkObjectInjector.java | 3 +- .../player/NetworkServerInjector.java | 8 +- .../injector/player/PlayerInjector.java | 1 + .../player/ProxyPlayerInjectionHandler.java | 4 +- .../server/AbstractInputStreamLookup.java | 1 + .../injector/spigot/DummyPlayerHandler.java | 1 - .../injector/spigot/SpigotPacketInjector.java | 13 +- .../comphenix/protocol/metrics/Metrics.java | 34 +- .../comphenix/protocol/metrics/Updater.java | 9 +- .../protocol/reflect/ClassAnalyser.java | 10 +- .../reflect/compiler/BoxingHelper.java | 4 +- .../reflect/compiler/StructureCompiler.java | 9 +- .../reflect/instances/DefaultInstances.java | 3 +- .../timing/TimingReportGenerator.java | 1 + .../protocol/utility/BukkitUtil.java | 37 ++ .../protocol/utility/ByteBufAdapter.java | 8 +- .../protocol/utility/MinecraftVersion.java | 2 +- .../protocol/utility/RemappedClassSource.java | 1 + .../protocol/utility/StreamSerializer.java | 1 + .../protocol/wrappers/WrappedServerPing.java | 138 +++--- .../wrappers/WrappedSignedProperty.java | 1 + .../protocol/wrappers/nbt/NbtBase.java | 2 - .../wrappers/nbt/TileEntityAccessor.java | 63 ++- .../nbt/io/NbtConfigurationSerializer.java | 1 + .../integration/protocol/TestPingPacket.java | 1 - .../protocol/BukkitInitialization.java | 31 +- .../protocol/MinecraftVersionTest.java | 4 +- .../comphenix/protocol/PacketTypeTest.java | 2 +- .../concurrency/BlockingHashMapTest.java | 2 +- .../protocol/events/PacketContainerTest.java | 198 ++++---- .../protocol/injector/PluginVerifierTest.java | 10 +- .../injector/SortedCopyOnWriteArrayTest.java | 3 +- .../reflect/accessors/AccessorsTest.java | 2 +- .../reflect/cloning/AggregateClonerTest.java | 2 +- .../utility/MinecraftReflectionTest.java | 59 +-- .../protocol/utility/SnapshotVersionTest.java | 2 +- .../utility/StreamSerializerTest.java | 6 +- .../wrappers/ChunkCoordIntPairTest.java | 16 +- .../protocol/wrappers/CloningTest.java | 4 +- .../protocol/wrappers/EnumWrappersTest.java | 15 +- .../wrappers/WrappedAttributeTest.java | 10 +- .../wrappers/WrappedChatComponentTest.java | 2 +- .../wrappers/WrappedChunkCoordinateTest.java | 2 +- .../wrappers/WrappedGameProfileTest.java | 2 +- .../wrappers/WrappedIntHashMapTest.java | 3 +- .../wrappers/WrappedServerPingTest.java | 3 +- .../wrappers/WrappedWatchableObjectTest.java | 4 +- .../wrappers/nbt/NbtCompoundTest.java | 3 +- .../protocol/wrappers/nbt/NbtFactoryTest.java | 4 +- .../io/NbtConfigurationSerializerTest.java | 2 +- Readme.md | 2 + 75 files changed, 828 insertions(+), 734 deletions(-) create mode 100644 ProtocolLib/src/main/java/com/comphenix/protocol/utility/BukkitUtil.java diff --git a/ProtocolLib/pom.xml b/ProtocolLib/pom.xml index 8dbeedc8..942ca5b5 100644 --- a/ProtocolLib/pom.xml +++ b/ProtocolLib/pom.xml @@ -1,11 +1,12 @@ - + 4.0.0 com.comphenix.protocol ProtocolLib 3.5.0-SNAPSHOT jar Provides read/write access to the Minecraft protocol. - + cp1252 1.5 @@ -23,11 +24,11 @@ http://repo.comphenix.net/content/repositories/snapshots/ - + - bukkit-rep - http://repo.bukkit.org/content/groups/public + md_5-repo + http://repo.md-5.net/content/repositories/public/ comphenix-releases @@ -35,7 +36,7 @@ http://repo.comphenix.net/content/repositories/releases/ - + clean install src/main/java @@ -49,7 +50,7 @@ - + org.apache.maven.plugins @@ -71,7 +72,7 @@ com.comphenix.net.sf - + org.bukkit:craftbukkit @@ -82,7 +83,7 @@ - + maven-compiler-plugin 2.3.2 @@ -92,108 +93,108 @@ - - org.apache.maven.plugins - maven-failsafe-plugin - 2.12.4 - - ${basedir}/target/server/ - -Xmx1024m -Xms1024M -Dnojline=true + + org.apache.maven.plugins + maven-failsafe-plugin + 2.12.4 + + ${basedir}/target/server/ + -Xmx1024m -Xms1024M -Dnojline=true - - - - integration-test - verify - - - - + + + + integration-test + verify + + + + - + org.codehaus.mojo findbugs-maven-plugin 2.5.2 - - High - Default - + + High + Default + - + - - release-sign-artifacts - - - performRelease - true - - - - - - org.apache.maven.plugins - maven-source-plugin - 2.2 - - - attach-sources - - jar - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9 - - - attach-javadocs - - jar - - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.4 - - - sign-artifacts - verify - - sign - - - - - - - - + + release-sign-artifacts + + + performRelease + true + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2 + + + attach-sources + + jar + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9 + + + attach-javadocs + + jar + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.4 + + + sign-artifacts + verify + + sign + + + + + + + + - + http://dev.bukkit.org/server-mods/protocollib/ ProtocolLib - + scm:git:git://github.com/aadnk/ProtocolLib.git scm:git:git@github.com:aadnk/ProtocolLib.git https://github.com/aadnk/ProtocolLib - + GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 @@ -201,63 +202,75 @@ repo - + + + dmulloy2 + Dan Mulloy + http://shadowvolt.com/ + + developer + maintainer + + aadnk Kristian S. Stangeland kr_stang@hotmail.com http://comphenix.net/ - developer - maintainer + former author 1 - + - - cglib - cglib-nodep - 2.2.2 - compile - - - com.comphenix.executors - BukkitExecutors - 1.0.0 - compile - - - org.bukkit - craftbukkit - 1.7.8-R0.1-SNAPSHOT - provided - - - junit - junit - 4.10 - test - - - org.mockito - mockito-all - 1.8.4 - test - - - org.powermock - powermock-module-junit4 - ${powermock.version} - test - - - org.powermock - powermock-api-mockito - ${powermock.version} - test - + + cglib + cglib-nodep + 2.2.2 + compile + + + com.comphenix.executors + BukkitExecutors + 1.0.0 + compile + + + org.spigotmc + spigot-api + 1.7.10-R0.1-SNAPSHOT + + + org.spigotmc + spigot + 1.7.10-R0.1-SNAPSHOT + + + junit + junit + 4.10 + test + + + org.mockito + mockito-all + 1.8.4 + test + + + org.powermock + powermock-module-junit4 + ${powermock.version} + test + + + org.powermock + powermock-api-mockito + ${powermock.version} + test + \ No newline at end of file diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java b/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java index 2f61f4a8..89505c7d 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java @@ -19,6 +19,7 @@ package com.comphenix.protocol; import java.io.File; import java.io.IOException; + import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.plugin.Plugin; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/PacketType.java b/ProtocolLib/src/main/java/com/comphenix/protocol/PacketType.java index cc6375bf..c0cce1d7 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/PacketType.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/PacketType.java @@ -9,12 +9,12 @@ import java.util.concurrent.Callable; import java.util.concurrent.Future; import org.bukkit.Bukkit; + import com.comphenix.protocol.events.ConnectionSide; import com.comphenix.protocol.injector.packet.PacketRegistry; import com.comphenix.protocol.reflect.ObjectEnum; 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; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/ConcurrentPlayerMap.java b/ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/ConcurrentPlayerMap.java index 04c8e1ea..ae937846 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/ConcurrentPlayerMap.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/ConcurrentPlayerMap.java @@ -8,10 +8,10 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ExecutionException; -import com.comphenix.protocol.utility.SafeCacheBuilder; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import com.comphenix.protocol.utility.SafeCacheBuilder; import com.google.common.base.Function; import com.google.common.cache.CacheLoader; import com.google.common.cache.RemovalListener; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/error/BasicErrorReporter.java b/ProtocolLib/src/main/java/com/comphenix/protocol/error/BasicErrorReporter.java index c70b15c7..924e98fa 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/error/BasicErrorReporter.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/error/BasicErrorReporter.java @@ -1,6 +1,7 @@ package com.comphenix.protocol.error; import java.io.PrintStream; + import org.bukkit.plugin.Plugin; import com.comphenix.protocol.error.Report.ReportBuilder; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/events/ListeningWhitelist.java b/ProtocolLib/src/main/java/com/comphenix/protocol/events/ListeningWhitelist.java index 940028b7..a209d4ae 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/events/ListeningWhitelist.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/events/ListeningWhitelist.java @@ -26,7 +26,6 @@ import java.util.Set; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.injector.GamePhase; import com.comphenix.protocol.injector.packet.PacketRegistry; - import com.google.common.base.Objects; import com.google.common.collect.Sets; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/events/MonitorAdapter.java b/ProtocolLib/src/main/java/com/comphenix/protocol/events/MonitorAdapter.java index 5cd6b05f..dd58dd8e 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/events/MonitorAdapter.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/events/MonitorAdapter.java @@ -23,10 +23,6 @@ import java.util.logging.Logger; import org.bukkit.plugin.Plugin; import com.comphenix.protocol.Packets; -import com.comphenix.protocol.events.ConnectionSide; -import com.comphenix.protocol.events.ListenerPriority; -import com.comphenix.protocol.events.ListeningWhitelist; -import com.comphenix.protocol.events.PacketListener; import com.comphenix.protocol.injector.GamePhase; import com.comphenix.protocol.injector.packet.PacketRegistry; import com.comphenix.protocol.reflect.FieldAccessException; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/events/NetworkMarker.java b/ProtocolLib/src/main/java/com/comphenix/protocol/events/NetworkMarker.java index b774054c..90fe717f 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/events/NetworkMarker.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/events/NetworkMarker.java @@ -12,6 +12,8 @@ import java.util.PriorityQueue; import javax.annotation.Nonnull; +import org.bukkit.entity.Player; + import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.utility.ByteBufferInputStream; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java b/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java index 3fccc55b..05be700f 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java @@ -49,20 +49,19 @@ import org.bukkit.inventory.ItemStack; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType.Protocol; -import com.comphenix.protocol.PacketType.Sender; import com.comphenix.protocol.injector.StructureCache; import com.comphenix.protocol.reflect.EquivalentConverter; import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.reflect.ObjectWriter; import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.reflect.cloning.AggregateCloner; +import com.comphenix.protocol.reflect.cloning.AggregateCloner.BuilderParameters; import com.comphenix.protocol.reflect.cloning.BukkitCloner; import com.comphenix.protocol.reflect.cloning.Cloner; import com.comphenix.protocol.reflect.cloning.CollectionCloner; import com.comphenix.protocol.reflect.cloning.FieldCloner; import com.comphenix.protocol.reflect.cloning.ImmutableDetector; import com.comphenix.protocol.reflect.cloning.SerializableCloner; -import com.comphenix.protocol.reflect.cloning.AggregateCloner.BuilderParameters; import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract; import com.comphenix.protocol.reflect.instances.DefaultInstances; import com.comphenix.protocol.utility.MinecraftMethods; @@ -72,7 +71,11 @@ import com.comphenix.protocol.wrappers.BukkitConverters; import com.comphenix.protocol.wrappers.ChunkCoordIntPair; import com.comphenix.protocol.wrappers.ChunkPosition; import com.comphenix.protocol.wrappers.EnumWrappers; +import com.comphenix.protocol.wrappers.EnumWrappers.ChatVisibility; +import com.comphenix.protocol.wrappers.EnumWrappers.ClientCommand; import com.comphenix.protocol.wrappers.EnumWrappers.Difficulty; +import com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction; +import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode; import com.comphenix.protocol.wrappers.WrappedAttribute; import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedDataWatcher; @@ -80,10 +83,6 @@ import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.comphenix.protocol.wrappers.WrappedServerPing; import com.comphenix.protocol.wrappers.WrappedStatistic; import com.comphenix.protocol.wrappers.WrappedWatchableObject; -import com.comphenix.protocol.wrappers.EnumWrappers.ChatVisibility; -import com.comphenix.protocol.wrappers.EnumWrappers.ClientCommand; -import com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction; -import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode; import com.comphenix.protocol.wrappers.nbt.NbtBase; import com.google.common.base.Function; import com.google.common.base.Preconditions; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/events/ScheduledPacket.java b/ProtocolLib/src/main/java/com/comphenix/protocol/events/ScheduledPacket.java index b32bfefe..25085526 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/events/ScheduledPacket.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/events/ScheduledPacket.java @@ -5,9 +5,10 @@ import java.lang.reflect.InvocationTargetException; import org.bukkit.entity.Player; import com.comphenix.protocol.PacketStream; -import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.PacketType.Sender; -import com.google.common.base.Preconditions;import com.google.common.base.Objects; +import com.comphenix.protocol.ProtocolLibrary; +import com.google.common.base.Objects; +import com.google.common.base.Preconditions; /** * Represents a packet that is scheduled for transmission at a later stage. diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/DelayedPacketManager.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/DelayedPacketManager.java index e67be77f..263bbaea 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/DelayedPacketManager.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/DelayedPacketManager.java @@ -5,6 +5,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Set; + import javax.annotation.Nonnull; import org.bukkit.Location; @@ -16,8 +17,8 @@ import org.bukkit.plugin.PluginManager; import com.comphenix.protocol.AsynchronousManager; import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.PacketType.Sender; +import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.error.ErrorReporter; import com.comphenix.protocol.error.Report; import com.comphenix.protocol.error.ReportType; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PacketFilterManager.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PacketFilterManager.java index 7e1442eb..662c6744 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PacketFilterManager.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PacketFilterManager.java @@ -2,16 +2,16 @@ * 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 + * 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. + * 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 + * 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 */ @@ -19,7 +19,6 @@ package com.comphenix.protocol.injector; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Set; @@ -58,19 +57,28 @@ import com.comphenix.protocol.async.AsyncMarker; import com.comphenix.protocol.error.ErrorReporter; import com.comphenix.protocol.error.Report; import com.comphenix.protocol.error.ReportType; -import com.comphenix.protocol.events.*; +import com.comphenix.protocol.events.ConnectionSide; +import com.comphenix.protocol.events.ListenerOptions; +import com.comphenix.protocol.events.ListenerPriority; +import com.comphenix.protocol.events.ListeningWhitelist; +import com.comphenix.protocol.events.NetworkMarker; +import com.comphenix.protocol.events.PacketAdapter; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; +import com.comphenix.protocol.events.PacketListener; import com.comphenix.protocol.injector.netty.NettyProtocolInjector; import com.comphenix.protocol.injector.packet.InterceptWritePacket; import com.comphenix.protocol.injector.packet.PacketInjector; import com.comphenix.protocol.injector.packet.PacketInjectorBuilder; import com.comphenix.protocol.injector.packet.PacketRegistry; import com.comphenix.protocol.injector.player.PlayerInjectionHandler; +import com.comphenix.protocol.injector.player.PlayerInjectionHandler.ConflictStrategy; import com.comphenix.protocol.injector.player.PlayerInjector.ServerHandlerNull; import com.comphenix.protocol.injector.player.PlayerInjectorBuilder; -import com.comphenix.protocol.injector.player.PlayerInjectionHandler.ConflictStrategy; import com.comphenix.protocol.injector.spigot.SpigotPacketInjector; import com.comphenix.protocol.reflect.FieldAccessException; import com.comphenix.protocol.reflect.FuzzyReflection; +import com.comphenix.protocol.utility.BukkitUtil; import com.comphenix.protocol.utility.EnhancerFactory; import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftVersion; @@ -81,17 +89,17 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; public final class PacketFilterManager implements ProtocolManager, ListenerInvoker, InternalManager { - + public static final ReportType REPORT_CANNOT_LOAD_PACKET_LIST = new ReportType("Cannot load server and client packet list."); public static final ReportType REPORT_CANNOT_INITIALIZE_PACKET_INJECTOR = new ReportType("Unable to initialize packet injector"); - - public static final ReportType REPORT_PLUGIN_DEPEND_MISSING = + + public static final ReportType REPORT_PLUGIN_DEPEND_MISSING = new ReportType("%s doesn't depend on ProtocolLib. Check that its plugin.yml has a 'depend' directive."); - + // Registering packet IDs that are not supported public static final ReportType REPORT_UNSUPPORTED_SERVER_PACKET_ID = new ReportType("[%s] Unsupported server packet ID in current Minecraft version: %s"); public static final ReportType REPORT_UNSUPPORTED_CLIENT_PACKET_ID = new ReportType("[%s] Unsupported client packet ID in current Minecraft version: %s"); - + // Problems injecting and uninjecting players public static final ReportType REPORT_CANNOT_UNINJECT_PLAYER = new ReportType("Unable to uninject net handler for player."); public static final ReportType REPORT_CANNOT_UNINJECT_OFFLINE_PLAYER = new ReportType("Unable to uninject logged off player."); @@ -99,12 +107,12 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok public static final ReportType REPORT_CANNOT_UNREGISTER_PLUGIN = new ReportType("Unable to handle disabled plugin."); public static final ReportType REPORT_PLUGIN_VERIFIER_ERROR = new ReportType("Verifier error: %s"); - + /** * The number of ticks in a second. */ public static final int TICKS_PER_SECOND = 20; - + /** * Sets the inject hook type. Different types allow for maximum compatibility. * @author Kristian @@ -114,113 +122,113 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok * The injection hook that does nothing. Set when every other inject hook fails. */ NONE, - + /** * Override the network handler object itself. Only works in 1.3. *

- * Cannot intercept MapChunk packets. + * Cannot intercept MapChunk packets. */ NETWORK_MANAGER_OBJECT, - + /** - * Override the packet queue lists in NetworkHandler. + * Override the packet queue lists in NetworkHandler. *

- * Cannot intercept MapChunk packets. + * Cannot intercept MapChunk packets. */ NETWORK_HANDLER_FIELDS, - + /** * Override the server handler object. Versatile, but a tad slower. */ NETWORK_SERVER_OBJECT; } - + // The amount of time to wait until we actually unhook every player - private static final int UNHOOK_DELAY = 5 * TICKS_PER_SECOND; - + private static final int UNHOOK_DELAY = 5 * TICKS_PER_SECOND; + // Delayed unhook private DelayedSingleTask unhookTask; - + // Create a concurrent set - private Set packetListeners = + private Set packetListeners = Collections.newSetFromMap(new ConcurrentHashMap()); - + // Packet injection private PacketInjector packetInjector; - + // Different injection types per game phase private PlayerInjectionHandler playerInjection; // Intercepting write packet methods private InterceptWritePacket interceptWritePacket; - + // Whether or not a packet must be input buffered private volatile Set inputBufferedPackets = Sets.newHashSet(); - + // The two listener containers private SortedPacketListenerList recievedListeners; private SortedPacketListenerList sendingListeners; - + // Whether or not this class has been closed private volatile boolean hasClosed; - + // The default class loader private ClassLoader classLoader; - + // Error repoter private ErrorReporter reporter; - + // The current server private Server server; - + // The current ProtocolLib library private Plugin library; - + // The async packet handler private AsyncFilterManager asyncFilterManager; - + // Valid server and client packets private boolean knowsServerPackets; private boolean knowsClientPackets; - + // Ensure that we're not performing too may injections private AtomicInteger phaseLoginCount = new AtomicInteger(0); private AtomicInteger phasePlayingCount = new AtomicInteger(0); - + // Whether or not plugins are using the send/receive methods private AtomicBoolean packetCreation = new AtomicBoolean(); - + // Spigot listener, if in use private SpigotPacketInjector spigotInjector; - + // Netty injector (for 1.7.2) private NettyProtocolInjector nettyInjector; - + // Plugin verifier private PluginVerifier pluginVerifier; - + // Whether or not Location.distance(Location) exists - we assume this is the case private boolean hasRecycleDistance = true; - + // The current Minecraft version private MinecraftVersion minecraftVersion; - + // Login packets private LoginPackets loginPackets; - + // Debug mode private boolean debug; - + /** * Only create instances of this class if protocol lib is disabled. */ - public PacketFilterManager(PacketFilterBuilder builder) { + public PacketFilterManager(PacketFilterBuilder builder) { // Used to determine if injection is needed Predicate isInjectionNecessary = new Predicate() { @Override public boolean apply(@Nullable GamePhase phase) { boolean result = true; - + if (phase.hasLogin()) result &= getPhaseLoginCount() > 0; // Note that we will still hook players if the unhooking has been delayed @@ -229,17 +237,17 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok return result; } }; - + // Listener containers this.recievedListeners = new SortedPacketListenerList(); this.sendingListeners = new SortedPacketListenerList(); - + // References this.unhookTask = builder.getUnhookTask(); this.server = builder.getServer(); this.classLoader = builder.getClassLoader(); this.reporter = builder.getReporter(); - + // The plugin verifier - we don't want to stop ProtocolLib just because its failing try { this.pluginVerifier = new PluginVerifier(builder.getLibrary()); @@ -251,25 +259,25 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok reporter.reportWarning(this, Report.newBuilder(REPORT_PLUGIN_VERIFIER_ERROR). messageParam(e.getMessage()).error(e)); } - + // Prepare version this.minecraftVersion = builder.getMinecraftVersion(); this.loginPackets = new LoginPackets(minecraftVersion); - + // The write packet interceptor this.interceptWritePacket = new InterceptWritePacket(reporter); - + // Use the correct injection type if (MinecraftReflection.isUsingNetty()) { this.nettyInjector = new NettyProtocolInjector(builder.getLibrary(), this, reporter); this.playerInjection = nettyInjector.getPlayerInjector(); this.packetInjector = nettyInjector.getPacketInjector(); - + } else if (builder.isNettyEnabled()) { this.spigotInjector = new SpigotPacketInjector(reporter, this, server); this.playerInjection = spigotInjector.getPlayerHandler(); this.packetInjector = spigotInjector.getPacketInjector(); - + // Set real injector, in case we need it spigotInjector.setProxyPacketInjector(PacketInjectorBuilder.newBuilder(). invoker(this). @@ -277,7 +285,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok playerInjection(playerInjection). buildInjector() ); - + } else { // Initialize standard injection mangers this.playerInjection = PlayerInjectorBuilder.newBuilder(). @@ -288,7 +296,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok injectionFilter(isInjectionNecessary). version(builder.getMinecraftVersion()). buildHandler(); - + this.packetInjector = PacketInjectorBuilder.newBuilder(). invoker(this). reporter(reporter). @@ -297,7 +305,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok } this.asyncFilterManager = builder.getAsyncManager(); this.library = builder.getLibrary(); - + // Attempt to load the list of server and client packets try { knowsServerPackets = PacketRegistry.getClientPacketTypes() != null; @@ -314,22 +322,22 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok public static PacketFilterBuilder newBuilder() { return new PacketFilterBuilder(); } - + @Override public int getProtocolVersion(Player player) { return playerInjection.getProtocolVersion(player); } - + @Override public MinecraftVersion getMinecraftVersion() { return minecraftVersion; } - + @Override public AsynchronousManager getAsynchronousManager() { return asyncFilterManager; } - + @Override public boolean isDebug() { return debug; @@ -338,13 +346,13 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok @Override public void setDebug(boolean debug) { this.debug = debug; - + // Inform components that can handle debug mode if (nettyInjector != null) { nettyInjector.setDebug(debug); } } - + /** * Retrieves how the server packets are read. * @return Injection method for reading server packets. @@ -372,7 +380,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok public InterceptWritePacket getInterceptWritePacket() { return interceptWritePacket; } - + /** * Warn of common programming mistakes. * @param plugin - plugin to check. @@ -380,7 +388,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok private void printPluginWarnings(Plugin plugin) { if (pluginVerifier == null) return; - + try { switch (pluginVerifier.verify(plugin)) { case NO_DEPEND: @@ -393,27 +401,27 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok reporter.reportWarning(this, Report.newBuilder(REPORT_PLUGIN_VERIFIER_ERROR).messageParam(e.getMessage())); } } - + @Override public void addPacketListener(PacketListener listener) { if (listener == null) throw new IllegalArgumentException("listener cannot be NULL."); - + // A listener can only be added once if (packetListeners.contains(listener)) - return; + return; ListeningWhitelist sending = listener.getSendingWhitelist(); ListeningWhitelist receiving = listener.getReceivingWhitelist(); boolean hasSending = sending != null && sending.isEnabled(); boolean hasReceiving = receiving != null && receiving.isEnabled(); - + // Check plugin if (!(hasSending && sending.getOptions().contains(ListenerOptions.SKIP_PLUGIN_VERIFIER)) && !(hasReceiving && receiving.getOptions().contains(ListenerOptions.SKIP_PLUGIN_VERIFIER))) { - + printPluginWarnings(listener.getPlugin()); } - + if (hasSending || hasReceiving) { // Add listeners and hooks if (hasSending) { @@ -421,17 +429,17 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok if (sending.getOptions().contains(ListenerOptions.INTERCEPT_INPUT_BUFFER)) { throw new IllegalArgumentException("Sending whitelist cannot require input bufferes to be intercepted."); } - + verifyWhitelist(listener, sending); sendingListeners.addListener(listener, sending); enablePacketFilters(listener, sending.getTypes()); - + // Make sure this is possible playerInjection.checkListener(listener); } if (hasSending) incrementPhases(processPhase(sending, ConnectionSide.SERVER_SIDE)); - + // Handle receivers after senders if (hasReceiving) { verifyWhitelist(listener, receiving); @@ -440,18 +448,18 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok } if (hasReceiving) incrementPhases(processPhase(receiving, ConnectionSide.CLIENT_SIDE)); - + // Inform our injected hooks packetListeners.add(listener); updateRequireInputBuffers(); } } - + private GamePhase processPhase(ListeningWhitelist whitelist, ConnectionSide side) { // Determine if this is a login packet, ensuring that gamephase detection is enabled - if (!whitelist.getGamePhase().hasLogin() && + if (!whitelist.getGamePhase().hasLogin() && !whitelist.getOptions().contains(ListenerOptions.DISABLE_GAMEPHASE_DETECTION)) { - + for (PacketType type : whitelist.getTypes()) { if (loginPackets.isLoginPacket(type)) { return GamePhase.BOTH; @@ -460,16 +468,16 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok } return whitelist.getGamePhase(); } - + /** * Invoked when we need to update the input buffer set. */ private void updateRequireInputBuffers() { Set updated = Sets.newHashSet(); - + for (PacketListener listener : packetListeners) { ListeningWhitelist whitelist = listener.getReceivingWhitelist(); - + // We only check the recieving whitelist if (whitelist.getOptions().contains(ListenerOptions.INTERCEPT_INPUT_BUFFER)) { for (PacketType type : whitelist.getTypes()) { @@ -489,7 +497,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok private void incrementPhases(GamePhase phase) { if (phase.hasLogin()) phaseLoginCount.incrementAndGet(); - + // We may have to inject into every current player if (phase.hasPlaying()) { if (phasePlayingCount.incrementAndGet() == 1) { @@ -498,11 +506,11 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok unhookTask.cancel(); else // Inject our hook into already existing players - initializePlayers(server.getOnlinePlayers()); + initializePlayers(BukkitUtil.getOnlinePlayers()); } } } - + /** * Invoked to handle the different game phases of a removed listener. * @param phase - listener's game game phase. @@ -510,7 +518,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok private void decrementPhases(GamePhase phase) { if (phase.hasLogin()) phaseLoginCount.decrementAndGet(); - + // We may have to inject into every current player if (phase.hasPlaying()) { if (phasePlayingCount.decrementAndGet() == 0) { @@ -519,13 +527,13 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok @Override public void run() { // Inject our hook into already existing players - uninitializePlayers(server.getOnlinePlayers()); + uninitializePlayers(BukkitUtil.getOnlinePlayers()); } }); } } } - + /** * Determine if the packet IDs in a whitelist is valid. * @param listener - the listener that will be mentioned in the error. @@ -535,13 +543,13 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok public static void verifyWhitelist(PacketListener listener, ListeningWhitelist whitelist) { for (PacketType type : whitelist.getTypes()) { if (type == null) { - throw new IllegalArgumentException(String.format("Packet type in in listener %s was NULL.", + throw new IllegalArgumentException(String.format("Packet type in in listener %s was NULL.", PacketAdapter.getPluginName(listener)) ); } } } - + @Override public void removePacketListener(PacketListener listener) { if (listener == null) @@ -549,14 +557,14 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok List sendingRemoved = null; List receivingRemoved = null; - + ListeningWhitelist sending = listener.getSendingWhitelist(); ListeningWhitelist receiving = listener.getReceivingWhitelist(); - + // Remove from the overal list of listeners if (!packetListeners.remove(listener)) return; - + // Remove listeners and phases if (sending != null && sending.isEnabled()) { sendingRemoved = sendingListeners.removeListener(listener, sending); @@ -566,7 +574,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok receivingRemoved = recievedListeners.removeListener(listener, receiving); decrementPhases(processPhase(receiving, ConnectionSide.CLIENT_SIDE)); } - + // Remove hooks, if needed if (sendingRemoved != null && sendingRemoved.size() > 0) disablePacketFilters(ConnectionSide.SERVER_SIDE, sendingRemoved); @@ -574,21 +582,21 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok disablePacketFilters(ConnectionSide.CLIENT_SIDE, receivingRemoved); updateRequireInputBuffers(); } - + @Override public void removePacketListeners(Plugin plugin) { // Iterate through every packet listener - for (PacketListener listener : packetListeners) { + for (PacketListener listener : packetListeners) { // Remove the listener if (Objects.equal(listener.getPlugin(), plugin)) { removePacketListener(listener); } } - + // Do the same for the asynchronous events asyncFilterManager.unregisterAsyncHandlers(plugin); } - + @Override public void invokePacketRecieving(PacketEvent event) { if (!hasClosed) { @@ -607,7 +615,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok public boolean requireInputBuffer(int packetId) { return inputBufferedPackets.contains(PacketType.findLegacy(packetId, Sender.CLIENT)); } - + /** * Handle a packet sending or receiving event. *

@@ -620,13 +628,13 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok if (asyncFilterManager.hasAsynchronousListeners(event)) { event.setAsyncMarker(asyncFilterManager.createAsyncMarker()); } - + // Process synchronous events if (sending) packetListeners.invokePacketSending(reporter, event); else packetListeners.invokePacketRecieving(reporter, event); - + // To cancel asynchronous processing, use the async marker if (!event.isCancelled() && !hasAsyncCancelled(event.getAsyncMarker())) { asyncFilterManager.enqueueSyncPacket(event, event.getAsyncMarker()); @@ -636,17 +644,17 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok event.setCancelled(true); } } - - // NULL marker mean we're dealing with no asynchronous listeners + + // NULL marker mean we're dealing with no asynchronous listeners private boolean hasAsyncCancelled(AsyncMarker marker) { return marker == null || marker.isAsyncCancelled(); } - + /** * Enables packet events for a given packet ID. *

* Note that all packets are disabled by default. - * + * * @param listener - the listener that requested to enable these filters. * @param side - which side the event will arrive from. * @param packets - the packet id(s). @@ -654,7 +662,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok private void enablePacketFilters(PacketListener listener, Iterable packets) { // Note the difference between unsupported and valid. // Every packet ID between and including 0 - 255 is valid, but only a subset is supported. - + for (PacketType type : packets) { // Only register server packets that are actually supported by Minecraft if (type.getSender() == Sender.SERVER) { @@ -662,17 +670,17 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok if (!knowsServerPackets || PacketRegistry.getServerPacketTypes().contains(type)) playerInjection.addPacketHandler(type, listener.getSendingWhitelist().getOptions()); else - reporter.reportWarning(this, + reporter.reportWarning(this, Report.newBuilder(REPORT_UNSUPPORTED_SERVER_PACKET_ID).messageParam(PacketAdapter.getPluginName(listener), type) ); } - + // As above, only for client packets if (type.getSender() == Sender.CLIENT && packetInjector != null) { if (!knowsClientPackets || PacketRegistry.getClientPacketTypes().contains(type)) packetInjector.addPacketHandler(type, listener.getReceivingWhitelist().getOptions()); else - reporter.reportWarning(this, + reporter.reportWarning(this, Report.newBuilder(REPORT_UNSUPPORTED_CLIENT_PACKET_ID).messageParam(PacketAdapter.getPluginName(listener), type) ); } @@ -687,19 +695,19 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok private void disablePacketFilters(ConnectionSide side, Iterable packets) { if (side == null) throw new IllegalArgumentException("side cannot be NULL."); - + for (PacketType type : packets) { if (side.isForServer()) playerInjection.removePacketHandler(type); - if (side.isForClient() && packetInjector != null) + if (side.isForClient() && packetInjector != null) packetInjector.removePacketHandler(type); } } - + @Override public void broadcastServerPacket(PacketContainer packet) { Preconditions.checkNotNull(packet, "packet cannot be NULL."); - broadcastServerPacket(packet, Arrays.asList(server.getOnlinePlayers())); + broadcastServerPacket(packet, BukkitUtil.getOnlinePlayers()); } @Override @@ -707,40 +715,40 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok Preconditions.checkNotNull(packet, "packet cannot be NULL."); Preconditions.checkNotNull(entity, "entity cannot be NULL."); List trackers = getEntityTrackers(entity); - + // Only add it if it's a player if (includeTracker && entity instanceof Player) { trackers.add((Player) entity); } broadcastServerPacket(packet, trackers); } - + @Override public void broadcastServerPacket(PacketContainer packet, Location origin, int maxObserverDistance) { try { // Square the maximum too int maxDistance = maxObserverDistance * maxObserverDistance; - + World world = origin.getWorld(); Location recycle = origin.clone(); - + // Only broadcast the packet to nearby players for (Player player : server.getOnlinePlayers()) { - if (world.equals(player.getWorld()) && + if (world.equals(player.getWorld()) && getDistanceSquared(origin, recycle, player) <= maxDistance) { - + sendServerPacket(player, packet); } } - + } catch (InvocationTargetException e) { throw new FieldAccessException("Unable to send server packet.", e); } } - + /** * Retrieve the squared distance between a location and a player. - * @param origin - the origin location. + * @param origin - the origin location. * @param recycle - a location object to be recycled, if supported. * @param player - the player. * @return The squared distance between the player and the origin, @@ -754,11 +762,11 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok hasRecycleDistance = false; } } - + // The fallback method return player.getLocation().distanceSquared(origin); } - + /** * Broadcast a packet to a given iterable of players. * @param packet - the packet to broadcast. @@ -773,17 +781,17 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok throw new FieldAccessException("Unable to send server packet.", e); } } - + @Override public void sendServerPacket(Player reciever, PacketContainer packet) throws InvocationTargetException { sendServerPacket(reciever, packet, null, true); } - + @Override public void sendServerPacket(Player reciever, PacketContainer packet, boolean filters) throws InvocationTargetException { sendServerPacket(reciever, packet, null, filters); } - + @Override public void sendServerPacket(final Player receiver, final PacketContainer packet, NetworkMarker marker, final boolean filters) throws InvocationTargetException { if (receiver == null) @@ -792,22 +800,22 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok throw new IllegalArgumentException("packet cannot be NULL."); if (packet.getType().getSender() == Sender.CLIENT) throw new IllegalArgumentException("Packet of sender CLIENT cannot be sent to a client."); - + // We may have to enable player injection indefinitely after this - if (packetCreation.compareAndSet(false, true)) + if (packetCreation.compareAndSet(false, true)) incrementPhases(GamePhase.PLAYING); - - if (!filters) { + + if (!filters) { // We may have to delay the packet due to non-asynchronous monitor listeners if (!filters && !Bukkit.isPrimaryThread() && playerInjection.hasMainThreadListener(packet.getType())) { final NetworkMarker copy = marker; - + server.getScheduler().scheduleSyncDelayedTask(library, new Runnable() { @Override public void run() { try { // Prevent infinite loops - if (!Bukkit.isPrimaryThread()) + if (!Bukkit.isPrimaryThread()) throw new IllegalStateException("Scheduled task was not executed on the main thread!"); sendServerPacket(receiver, packet, copy, filters); } catch (Exception e) { @@ -817,24 +825,24 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok }); return; } - + PacketEvent event = PacketEvent.fromServer(this, packet, marker, receiver, false); sendingListeners.invokePacketSending(reporter, event, ListenerPriority.MONITOR); marker = NetworkMarker.getNetworkMarker(event); } playerInjection.sendServerPacket(receiver, packet, marker, filters); } - + @Override public void recieveClientPacket(Player sender, PacketContainer packet) throws IllegalAccessException, InvocationTargetException { recieveClientPacket(sender, packet, null, true); } - + @Override public void recieveClientPacket(Player sender, PacketContainer packet, boolean filters) throws IllegalAccessException, InvocationTargetException { recieveClientPacket(sender, packet, null, filters); } - + @Override public void recieveClientPacket(Player sender, PacketContainer packet, NetworkMarker marker, boolean filters) throws IllegalAccessException, InvocationTargetException { if (sender == null) @@ -843,55 +851,55 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok throw new IllegalArgumentException("packet cannot be NULL."); if (packet.getType().getSender() == Sender.SERVER) throw new IllegalArgumentException("Packet of sender SERVER cannot be sent to the server."); - + // And here too - if (packetCreation.compareAndSet(false, true)) + if (packetCreation.compareAndSet(false, true)) incrementPhases(GamePhase.PLAYING); - + Object mcPacket = packet.getHandle(); boolean cancelled = packetInjector.isCancelled(mcPacket); - + // Make sure the packet isn't cancelled if (cancelled) { packetInjector.setCancelled(mcPacket, false); } - + if (filters) { byte[] data = NetworkMarker.getByteBuffer(marker); PacketEvent event = packetInjector.packetRecieved(packet, sender, data); - + if (!event.isCancelled()) mcPacket = event.getPacket().getHandle(); else return; - + } else { // Let the monitors know though recievedListeners.invokePacketSending( - reporter, - PacketEvent.fromClient(this, packet, marker, sender, false), + reporter, + PacketEvent.fromClient(this, packet, marker, sender, false), ListenerPriority.MONITOR); } - + playerInjection.recieveClientPacket(sender, mcPacket); - + // Let it stay cancelled if (cancelled) { packetInjector.setCancelled(mcPacket, true); } } - + @Override @Deprecated public PacketContainer createPacket(int id) { return createPacket(PacketType.findLegacy(id), true); } - + @Override public PacketContainer createPacket(PacketType type) { return createPacket(type, true); } - + @Override @Deprecated public PacketContainer createPacket(int id, boolean forceDefaults) { @@ -901,7 +909,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok @Override public PacketContainer createPacket(PacketType type, boolean forceDefaults) { PacketContainer packet = new PacketContainer(type); - + // Use any default values if possible if (forceDefaults) { try { @@ -910,10 +918,10 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok throw new RuntimeException("Security exception.", e); } } - + return packet; } - + @Override @Deprecated public PacketConstructor createPacketConstructor(int id, Object... arguments) { @@ -924,13 +932,13 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok public PacketConstructor createPacketConstructor(PacketType type, Object... arguments) { return PacketConstructor.DEFAULT.withPacket(type, arguments); } - + @Override @Deprecated public Set getSendingFilters() { return PacketRegistry.toLegacy(playerInjection.getSendingFilters()); } - + @Override public Set getReceivingFilters() { return PacketRegistry.toLegacy(packetInjector.getPacketHandlers()); @@ -944,41 +952,41 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok public Set getReceivingFilterTypes() { return Collections.unmodifiableSet(packetInjector.getPacketHandlers()); } - + @Override public void updateEntity(Entity entity, List observers) throws FieldAccessException { EntityUtilities.updateEntity(entity, observers); } - + @Override public Entity getEntityFromID(World container, int id) throws FieldAccessException { return EntityUtilities.getEntityFromID(container, id); } - + @Override public List getEntityTrackers(Entity entity) throws FieldAccessException { return EntityUtilities.getEntityTrackers(entity); } - + /** * Initialize the packet injection for every player. - * @param players - list of players to inject. + * @param players - list of players to inject. */ - public void initializePlayers(Player[] players) { + public void initializePlayers(List players) { for (Player player : players) playerInjection.injectPlayer(player, ConflictStrategy.OVERRIDE); } - + /** * Uninitialize the packet injection of every player. - * @param players - list of players to uninject. + * @param players - list of players to uninject. */ - public void uninitializePlayers(Player[] players) { + public void uninitializePlayers(List players) { for (Player player : players) { playerInjection.uninjectPlayer(player); } } - + /** * Register this protocol manager on Bukkit. * @param manager - Bukkit plugin manager that provides player join/leave events. @@ -990,7 +998,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok throw new IllegalArgumentException("Spigot has already been registered."); if (nettyInjector != null) nettyInjector.inject(); - + try { manager.registerEvents(new Listener() { @EventHandler(priority = EventPriority.LOWEST) @@ -1013,23 +1021,23 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok public void onPluginDisabled(PluginDisableEvent event) { PacketFilterManager.this.onPluginDisabled(event, plugin); } - + }, plugin); - + } catch (NoSuchMethodError e) { // Oh wow! We're running on 1.0.0 or older. registerOld(manager, plugin); } } - + private void onPlayerLogin(PlayerLoginEvent event) { playerInjection.updatePlayer(event.getPlayer()); } - + private void onPrePlayerJoin(PlayerJoinEvent event) { playerInjection.updatePlayer(event.getPlayer()); } - + private void onPlayerJoin(PlayerJoinEvent event) { try { // Let's clean up the other injection first. @@ -1038,12 +1046,12 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok } catch (ServerHandlerNull e) { // Caused by logged out players, or fake login events in MCPC++. Ignore it. } catch (Exception e) { - reporter.reportDetailed(PacketFilterManager.this, + reporter.reportDetailed(PacketFilterManager.this, Report.newBuilder(REPORT_CANNOT_INJECT_PLAYER).callerParam(event).error(e) ); } } - + private void onPlayerQuit(PlayerQuitEvent event) { try { Player player = event.getPlayer(); @@ -1052,12 +1060,12 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok playerInjection.handleDisconnect(player); playerInjection.uninjectPlayer(player); } catch (Exception e) { - reporter.reportDetailed(PacketFilterManager.this, + reporter.reportDetailed(PacketFilterManager.this, Report.newBuilder(REPORT_CANNOT_UNINJECT_OFFLINE_PLAYER).callerParam(event).error(e) ); } } - + private void onPluginDisabled(PluginDisableEvent event, Plugin protocolLibrary) { try { // Clean up in case the plugin forgets @@ -1065,12 +1073,12 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok removePacketListeners(event.getPlugin()); } } catch (Exception e) { - reporter.reportDetailed(PacketFilterManager.this, + reporter.reportDetailed(PacketFilterManager.this, Report.newBuilder(REPORT_CANNOT_UNREGISTER_PLUGIN).callerParam(event).error(e) ); } } - + /** * Retrieve the number of listeners that expect packets during playing. * @return Number of listeners. @@ -1078,7 +1086,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok private int getPhasePlayingCount() { return phasePlayingCount.get(); } - + /** * Retrieve the number of listeners that expect packets during login. * @return Number of listeners @@ -1086,7 +1094,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok private int getPhaseLoginCount() { return phaseLoginCount.get(); } - + @Override @Deprecated public int getPacketID(Object packet) { @@ -1099,9 +1107,9 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok throw new IllegalArgumentException("Packet cannot be NULL."); if (!MinecraftReflection.isPacketClass(packet)) throw new IllegalArgumentException("The given object " + packet + " is not a packet."); - + PacketType type = PacketRegistry.getPacketType(packet.getClass()); - + if (type != null) { return type; } else { @@ -1109,13 +1117,13 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok "Unable to find associated packet of " + packet + ": Lookup returned NULL."); } } - + @Override @Deprecated public void registerPacketClass(Class clazz, int packetID) { PacketRegistry.getPacketToID().put(clazz, packetID); } - + @Override @Deprecated public void unregisterPacketClass(Class clazz) { @@ -1127,38 +1135,38 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok public Class getPacketClassFromID(int packetID, boolean forceVanilla) { return PacketRegistry.getPacketClassFromID(packetID, forceVanilla); } - + // Yes, this is crazy. @SuppressWarnings({ "unchecked", "rawtypes" }) private void registerOld(PluginManager manager, final Plugin plugin) { try { ClassLoader loader = manager.getClass().getClassLoader(); - + // The different enums we are going to need Class eventTypes = loader.loadClass("org.bukkit.event.Event$Type"); Class eventPriority = loader.loadClass("org.bukkit.event.Event$Priority"); - + // Get the priority Object priorityLowest = Enum.valueOf(eventPriority, "Lowest"); Object priorityMonitor = Enum.valueOf(eventPriority, "Monitor"); - + // Get event types Object playerJoinType = Enum.valueOf(eventTypes, "PLAYER_JOIN"); Object playerQuitType = Enum.valueOf(eventTypes, "PLAYER_QUIT"); Object pluginDisabledType = Enum.valueOf(eventTypes, "PLUGIN_DISABLE"); - + // The player listener! Good times. Class playerListener = loader.loadClass("org.bukkit.event.player.PlayerListener"); Class serverListener = loader.loadClass("org.bukkit.event.server.ServerListener"); - + // Find the register event method - Method registerEvent = FuzzyReflection.fromObject(manager).getMethodByParameters("registerEvent", + Method registerEvent = FuzzyReflection.fromObject(manager).getMethodByParameters("registerEvent", eventTypes, Listener.class, eventPriority, Plugin.class); - + Enhancer playerLow = EnhancerFactory.getInstance().createEnhancer(); Enhancer playerEx = EnhancerFactory.getInstance().createEnhancer(); Enhancer serverEx = EnhancerFactory.getInstance().createEnhancer(); - + playerLow.setSuperclass(playerListener); playerLow.setClassLoader(classLoader); playerLow.setCallback(new MethodInterceptor() { @@ -1176,7 +1184,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok return null; } }); - + playerEx.setSuperclass(playerListener); playerEx.setClassLoader(classLoader); playerEx.setCallback(new MethodInterceptor() { @@ -1184,7 +1192,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { if (args.length == 1) { Object event = args[0]; - + // Check for the correct event if (event instanceof PlayerJoinEvent) { onPlayerJoin((PlayerJoinEvent) event); @@ -1195,7 +1203,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok return null; } }); - + serverEx.setSuperclass(serverListener); serverEx.setClassLoader(classLoader); serverEx.setCallback(new MethodInterceptor() { @@ -1205,24 +1213,24 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok // Must have a parameter if (args.length == 1) { Object event = args[0]; - + if (event instanceof PluginDisableEvent) onPluginDisabled((PluginDisableEvent) event, plugin); } return null; } }); - + // Create our listener Object playerProxyLow = playerLow.create(); Object playerProxy = playerEx.create(); Object serverProxy = serverEx.create(); - + registerEvent.invoke(manager, playerJoinType, playerProxyLow, priorityLowest, plugin); registerEvent.invoke(manager, playerJoinType, playerProxy, priorityMonitor, plugin); registerEvent.invoke(manager, playerQuitType, playerProxy, priorityMonitor, plugin); registerEvent.invoke(manager, pluginDisabledType, serverProxy, priorityMonitor, plugin); - + // A lot can go wrong } catch (ClassNotFoundException e1) { e1.printStackTrace(); @@ -1234,7 +1242,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok e.printStackTrace(); } } - + /** * Retrieve every known and supported server packet. * @return An immutable set of every known server packet. @@ -1244,7 +1252,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok public static Set getServerPackets() throws FieldAccessException { return PacketRegistry.getServerPackets(); } - + /** * Retrieve every known and supported client packet. * @return An immutable set of every known client packet. @@ -1254,7 +1262,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok public static Set getClientPackets() throws FieldAccessException { return PacketRegistry.getClientPackets(); } - + /** * Retrieves the current plugin class loader. * @return Class loader. @@ -1262,12 +1270,12 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok public ClassLoader getClassLoader() { return classLoader; } - + @Override public boolean isClosed() { return hasClosed; } - + @Override public void close() { // Guard @@ -1281,23 +1289,23 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok spigotInjector.cleanupAll(); if (nettyInjector != null) nettyInjector.close(); - + // Remove server handler playerInjection.close(); hasClosed = true; - + // Remove listeners packetListeners.clear(); recievedListeners = null; sendingListeners = null; - + // Also cleanup the interceptor for the write packet method interceptWritePacket.cleanup(); - + // Clean up async handlers. We have to do this last. asyncFilterManager.cleanupAll(); } - + @Override protected void finalize() throws Throwable { close(); diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/SortedPacketListenerList.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/SortedPacketListenerList.java index 5c1bd1e6..80a47c7a 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/SortedPacketListenerList.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/SortedPacketListenerList.java @@ -25,8 +25,8 @@ import com.comphenix.protocol.events.ListenerPriority; import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketListener; import com.comphenix.protocol.timing.TimedListenerManager; -import com.comphenix.protocol.timing.TimedTracker; import com.comphenix.protocol.timing.TimedListenerManager.ListenerType; +import com.comphenix.protocol.timing.TimedTracker; /** * Registry of synchronous packet listeners. diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/BootstrapList.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/BootstrapList.java index fedf47f1..326f1642 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/BootstrapList.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/BootstrapList.java @@ -6,14 +6,13 @@ import java.util.List; import java.util.ListIterator; import java.util.concurrent.Callable; -import com.google.common.collect.Lists; - import net.minecraft.util.io.netty.channel.Channel; - // Hopefully, CB won't version these as well import net.minecraft.util.io.netty.channel.ChannelFuture; import net.minecraft.util.io.netty.channel.ChannelHandler; +import com.google.common.collect.Lists; + class BootstrapList implements List { private List delegate; private ChannelHandler handler; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java index fdfe560f..bb9124d9 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java @@ -35,7 +35,6 @@ import com.comphenix.protocol.PacketType.Protocol; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.error.Report; import com.comphenix.protocol.error.ReportType; -import com.comphenix.protocol.error.Report.ReportBuilder; import com.comphenix.protocol.events.ConnectionSide; import com.comphenix.protocol.events.NetworkMarker; import com.comphenix.protocol.events.PacketEvent; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelProxy.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelProxy.java index 250a68ae..7a2d6f77 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelProxy.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelProxy.java @@ -5,10 +5,6 @@ import java.net.SocketAddress; import java.util.Map; import java.util.concurrent.Callable; -import com.comphenix.protocol.reflect.accessors.Accessors; -import com.comphenix.protocol.reflect.accessors.FieldAccessor; -import com.google.common.collect.Maps; - import net.minecraft.util.io.netty.buffer.ByteBufAllocator; import net.minecraft.util.io.netty.channel.Channel; import net.minecraft.util.io.netty.channel.ChannelConfig; @@ -21,6 +17,10 @@ import net.minecraft.util.io.netty.channel.EventLoop; import net.minecraft.util.io.netty.util.Attribute; import net.minecraft.util.io.netty.util.AttributeKey; +import com.comphenix.protocol.reflect.accessors.Accessors; +import com.comphenix.protocol.reflect.accessors.FieldAccessor; +import com.google.common.collect.Maps; + abstract class ChannelProxy implements Channel { // Mark that a certain object does not contain a message field private static final FieldAccessor MARK_NO_MESSAGE = new FieldAccessor() { diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/InjectionFactory.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/InjectionFactory.java index 9f25f9e6..9e76aabf 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/InjectionFactory.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/InjectionFactory.java @@ -3,7 +3,9 @@ package com.comphenix.protocol.injector.netty; import java.util.concurrent.ConcurrentMap; import javax.annotation.Nonnull; + import net.minecraft.util.io.netty.channel.Channel; + import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyProtocolInjector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyProtocolInjector.java index e02514a3..61f402bc 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyProtocolInjector.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyProtocolInjector.java @@ -7,8 +7,6 @@ import java.lang.reflect.Method; import java.net.InetSocketAddress; import java.util.List; import java.util.Set; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; import net.minecraft.util.io.netty.channel.Channel; import net.minecraft.util.io.netty.channel.ChannelFuture; @@ -18,12 +16,19 @@ import net.minecraft.util.io.netty.channel.ChannelInboundHandler; import net.minecraft.util.io.netty.channel.ChannelInboundHandlerAdapter; import net.minecraft.util.io.netty.channel.ChannelInitializer; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + import com.comphenix.protocol.PacketType; import com.comphenix.protocol.concurrency.PacketTypeSet; import com.comphenix.protocol.error.ErrorReporter; import com.comphenix.protocol.error.Report; import com.comphenix.protocol.error.ReportType; -import com.comphenix.protocol.events.*; +import com.comphenix.protocol.events.ConnectionSide; +import com.comphenix.protocol.events.ListenerOptions; +import com.comphenix.protocol.events.NetworkMarker; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.injector.ListenerInvoker; import com.comphenix.protocol.injector.packet.PacketInjector; import com.comphenix.protocol.injector.packet.PacketRegistry; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/LegacyNetworkMarker.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/LegacyNetworkMarker.java index 9769446c..4adb0230 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/LegacyNetworkMarker.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/LegacyNetworkMarker.java @@ -5,6 +5,7 @@ import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; + import javax.annotation.Nonnull; import com.comphenix.protocol.PacketType; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/LegacyPacketRegistry.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/LegacyPacketRegistry.java index 6dd07377..1c1fe590 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/LegacyPacketRegistry.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/LegacyPacketRegistry.java @@ -4,8 +4,8 @@ import java.lang.reflect.Field; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; +import java.util.Set; import javax.annotation.Nullable; @@ -19,7 +19,6 @@ import com.comphenix.protocol.reflect.fuzzy.FuzzyFieldContract; import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract; import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.wrappers.TroveWrapper; - import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableSet; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/ProxyPacketInjector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/ProxyPacketInjector.java index 703d7e31..adb8a3d6 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/ProxyPacketInjector.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/ProxyPacketInjector.java @@ -24,14 +24,15 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Map; import java.util.Set; -import org.bukkit.entity.Player; import net.sf.cglib.proxy.Callback; +import net.sf.cglib.proxy.CallbackFilter; import net.sf.cglib.proxy.Enhancer; import net.sf.cglib.proxy.Factory; -import net.sf.cglib.proxy.CallbackFilter; import net.sf.cglib.proxy.NoOp; +import org.bukkit.entity.Player; + import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType.Sender; import com.comphenix.protocol.error.ErrorReporter; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/ReadPacketModifier.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/ReadPacketModifier.java index 815b1639..dc401dac 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/ReadPacketModifier.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/ReadPacketModifier.java @@ -23,6 +23,9 @@ import java.io.InputStream; import java.lang.reflect.Method; import java.util.Map; +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; + import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType.Sender; import com.comphenix.protocol.error.ErrorReporter; @@ -34,9 +37,6 @@ import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.injector.NetworkProcessor; import com.google.common.collect.MapMaker; -import net.sf.cglib.proxy.MethodInterceptor; -import net.sf.cglib.proxy.MethodProxy; - class ReadPacketModifier implements MethodInterceptor { public static final ReportType REPORT_CANNOT_HANDLE_CLIENT_PACKET = new ReportType("Cannot handle client packet."); diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/WritePacketModifier.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/WritePacketModifier.java index b5662eee..907e57f6 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/WritePacketModifier.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/WritePacketModifier.java @@ -22,20 +22,18 @@ import java.io.DataOutput; import java.io.DataOutputStream; import java.lang.reflect.Method; import java.util.Map; -import java.util.PriorityQueue; + +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; import com.comphenix.protocol.error.ErrorReporter; import com.comphenix.protocol.error.Report; import com.comphenix.protocol.error.ReportType; import com.comphenix.protocol.events.NetworkMarker; import com.comphenix.protocol.events.PacketEvent; -import com.comphenix.protocol.events.PacketOutputHandler; import com.comphenix.protocol.injector.NetworkProcessor; import com.google.common.collect.MapMaker; -import net.sf.cglib.proxy.MethodInterceptor; -import net.sf.cglib.proxy.MethodProxy; - public class WritePacketModifier implements MethodInterceptor { public static final ReportType REPORT_CANNOT_WRITE_SERVER_PACKET = new ReportType("Cannot write server packet."); diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/InjectedArrayList.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/InjectedArrayList.java index c88b021d..9e3a832b 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/InjectedArrayList.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/InjectedArrayList.java @@ -23,6 +23,11 @@ import java.util.ArrayList; import java.util.Set; import java.util.concurrent.ConcurrentMap; +import net.sf.cglib.proxy.Callback; +import net.sf.cglib.proxy.Enhancer; +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; + import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.error.Report; @@ -33,11 +38,6 @@ import com.comphenix.protocol.utility.EnhancerFactory; import com.comphenix.protocol.utility.MinecraftReflection; import com.google.common.collect.MapMaker; -import net.sf.cglib.proxy.Callback; -import net.sf.cglib.proxy.Enhancer; -import net.sf.cglib.proxy.MethodInterceptor; -import net.sf.cglib.proxy.MethodProxy; - /** * The array list that notifies when packets are sent by the server. * 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 992cbd32..bacaaa1b 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 @@ -18,6 +18,7 @@ package com.comphenix.protocol.injector.player; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import net.sf.cglib.proxy.Callback; import net.sf.cglib.proxy.CallbackFilter; @@ -26,8 +27,6 @@ import net.sf.cglib.proxy.LazyLoader; import net.sf.cglib.proxy.MethodInterceptor; import net.sf.cglib.proxy.MethodProxy; -import java.lang.reflect.Method; - import org.bukkit.Server; import org.bukkit.entity.Player; 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 6d522aaf..13993275 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 @@ -22,7 +22,13 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; -import net.sf.cglib.proxy.*; +import net.sf.cglib.proxy.Callback; +import net.sf.cglib.proxy.CallbackFilter; +import net.sf.cglib.proxy.Enhancer; +import net.sf.cglib.proxy.Factory; +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; +import net.sf.cglib.proxy.NoOp; import org.bukkit.entity.Player; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/PlayerInjector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/PlayerInjector.java index 2e6b7ed8..0b4325d4 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/PlayerInjector.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/PlayerInjector.java @@ -25,6 +25,7 @@ import java.lang.reflect.Method; import java.net.Socket; import java.net.SocketAddress; import java.util.Map; + import net.sf.cglib.proxy.Factory; import org.bukkit.entity.Player; 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 c081ee0a..474e0b91 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 @@ -26,7 +26,6 @@ import java.net.Socket; import java.net.SocketAddress; import java.util.Map; import java.util.Set; -import java.util.TreeMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; @@ -36,7 +35,6 @@ import org.bukkit.Server; import org.bukkit.entity.Player; import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.PacketType.Sender; import com.comphenix.protocol.Packets; import com.comphenix.protocol.concurrency.BlockingHashMap; @@ -52,8 +50,8 @@ import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketListener; import com.comphenix.protocol.injector.GamePhase; import com.comphenix.protocol.injector.ListenerInvoker; -import com.comphenix.protocol.injector.PlayerLoggedOutException; import com.comphenix.protocol.injector.PacketFilterManager.PlayerInjectHooks; +import com.comphenix.protocol.injector.PlayerLoggedOutException; import com.comphenix.protocol.injector.packet.PacketRegistry; import com.comphenix.protocol.injector.server.AbstractInputStreamLookup; import com.comphenix.protocol.injector.server.BukkitSocketInjector; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/server/AbstractInputStreamLookup.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/server/AbstractInputStreamLookup.java index 0af83561..6e60cbba 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/server/AbstractInputStreamLookup.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/server/AbstractInputStreamLookup.java @@ -3,6 +3,7 @@ package com.comphenix.protocol.injector.server; import java.io.InputStream; import java.net.Socket; import java.net.SocketAddress; + import org.bukkit.Server; import org.bukkit.entity.Player; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/spigot/DummyPlayerHandler.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/spigot/DummyPlayerHandler.java index d92c77f9..a7f1f372 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/spigot/DummyPlayerHandler.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/spigot/DummyPlayerHandler.java @@ -7,7 +7,6 @@ import java.net.InetSocketAddress; import org.bukkit.entity.Player; import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.concurrency.PacketTypeSet; import com.comphenix.protocol.events.NetworkMarker; import com.comphenix.protocol.events.PacketContainer; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/spigot/SpigotPacketInjector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/spigot/SpigotPacketInjector.java index b782e1d2..4653de65 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/spigot/SpigotPacketInjector.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/spigot/SpigotPacketInjector.java @@ -9,11 +9,6 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentMap; -import org.bukkit.Bukkit; -import org.bukkit.Server; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - import net.sf.cglib.proxy.Callback; import net.sf.cglib.proxy.CallbackFilter; import net.sf.cglib.proxy.Enhancer; @@ -22,9 +17,13 @@ import net.sf.cglib.proxy.MethodInterceptor; import net.sf.cglib.proxy.MethodProxy; import net.sf.cglib.proxy.NoOp; +import org.bukkit.Bukkit; +import org.bukkit.Server; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType.Sender; -import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.concurrency.PacketTypeSet; import com.comphenix.protocol.error.DelegatedErrorReporter; import com.comphenix.protocol.error.ErrorReporter; @@ -35,7 +34,6 @@ import com.comphenix.protocol.events.NetworkMarker; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.injector.ListenerInvoker; -import com.comphenix.protocol.injector.PacketFilterBuilder; import com.comphenix.protocol.injector.PacketFilterManager; import com.comphenix.protocol.injector.PlayerLoggedOutException; import com.comphenix.protocol.injector.packet.LegacyNetworkMarker; @@ -48,7 +46,6 @@ import com.comphenix.protocol.reflect.MethodInfo; import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract; import com.comphenix.protocol.utility.EnhancerFactory; import com.comphenix.protocol.utility.MinecraftReflection; - import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.MapMaker; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Metrics.java b/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Metrics.java index d7640502..4c94b4fb 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Metrics.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Metrics.java @@ -2,16 +2,16 @@ * 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 + * 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. + * 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 + * 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 */ @@ -45,14 +45,6 @@ package com.comphenix.protocol.metrics; * either expressed or implied, of anybody else. */ -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginDescriptionFile; - -import com.comphenix.protocol.utility.WrappedScheduler; - import java.io.BufferedReader; import java.io.File; import java.io.IOException; @@ -71,6 +63,15 @@ import java.util.Set; import java.util.UUID; import java.util.logging.Level; +import org.bukkit.Bukkit; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; + +import com.comphenix.protocol.utility.BukkitUtil; +import com.comphenix.protocol.utility.WrappedScheduler; + /** *

The metrics class obtains data about a plugin and submits statistics about it to the metrics backend.

* Public methods provided by this class:

@@ -243,7 +244,8 @@ public class Metrics { private boolean firstPost = true; - public void run() { + @Override + public void run() { try { // This has to be synchronized or it can collide with the disable method. synchronized (optOutLock) { @@ -373,7 +375,7 @@ public class Metrics { boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled String pluginVersion = description.getVersion(); String serverVersion = Bukkit.getVersion(); - int playersOnline = Bukkit.getServer().getOnlinePlayers().length; + int playersOnline = BukkitUtil.getOnlinePlayers().size(); // END server software specific section -- all code below does not use any code outside of this class / Java diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Updater.java b/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Updater.java index f9e08187..d39dc9aa 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Updater.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Updater.java @@ -7,7 +7,13 @@ // Somewhat modified by aadnk. package com.comphenix.protocol.metrics; -import java.io.*; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; @@ -28,7 +34,6 @@ import com.comphenix.protocol.error.Report; import com.comphenix.protocol.error.ReportType; import com.comphenix.protocol.utility.MinecraftVersion; import com.google.common.base.Preconditions; -import com.google.common.io.Files; /** * Check dev.bukkit.org to find updates for a given plugin, and download the updates if needed. diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/ClassAnalyser.java b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/ClassAnalyser.java index 3f9049fc..5f507b19 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/ClassAnalyser.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/ClassAnalyser.java @@ -4,16 +4,16 @@ import java.io.IOException; import java.lang.reflect.Method; import java.util.List; -import com.comphenix.protocol.reflect.ClassAnalyser.AsmMethod.AsmOpcodes; -import com.comphenix.protocol.reflect.compiler.EmptyClassVisitor; -import com.comphenix.protocol.reflect.compiler.EmptyMethodVisitor; -import com.google.common.collect.Lists; - import net.sf.cglib.asm.ClassReader; import net.sf.cglib.asm.MethodVisitor; import net.sf.cglib.asm.Opcodes; import net.sf.cglib.asm.Type; +import com.comphenix.protocol.reflect.ClassAnalyser.AsmMethod.AsmOpcodes; +import com.comphenix.protocol.reflect.compiler.EmptyClassVisitor; +import com.comphenix.protocol.reflect.compiler.EmptyMethodVisitor; +import com.google.common.collect.Lists; + public class ClassAnalyser { /** * Represents a method in ASM. diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/compiler/BoxingHelper.java b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/compiler/BoxingHelper.java index 8ff449ec..ad34e502 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/compiler/BoxingHelper.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/compiler/BoxingHelper.java @@ -17,7 +17,9 @@ package com.comphenix.protocol.reflect.compiler; -import net.sf.cglib.asm.*; +import net.sf.cglib.asm.MethodVisitor; +import net.sf.cglib.asm.Opcodes; +import net.sf.cglib.asm.Type; /** * Used by the compiler to automatically box and unbox values. diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/compiler/StructureCompiler.java b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/compiler/StructureCompiler.java index b681e77e..a5b8f5eb 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/compiler/StructureCompiler.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/compiler/StructureCompiler.java @@ -25,6 +25,13 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import net.sf.cglib.asm.ClassWriter; +import net.sf.cglib.asm.FieldVisitor; +import net.sf.cglib.asm.Label; +import net.sf.cglib.asm.MethodVisitor; +import net.sf.cglib.asm.Opcodes; +import net.sf.cglib.asm.Type; + import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.error.Report; import com.comphenix.protocol.error.ReportType; @@ -32,8 +39,6 @@ import com.comphenix.protocol.reflect.StructureModifier; import com.google.common.base.Objects; import com.google.common.primitives.Primitives; -import net.sf.cglib.asm.*; - // public class CompiledStructureModifierPacket20 extends CompiledStructureModifier { // // private Packet20NamedEntitySpawn typedTarget; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/instances/DefaultInstances.java b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/instances/DefaultInstances.java index 41306b56..442cfc03 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/instances/DefaultInstances.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/instances/DefaultInstances.java @@ -18,7 +18,8 @@ package com.comphenix.protocol.reflect.instances; import java.lang.reflect.Constructor; -import java.util.*; +import java.util.Collection; +import java.util.List; import javax.annotation.Nullable; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/timing/TimingReportGenerator.java b/ProtocolLib/src/main/java/com/comphenix/protocol/timing/TimingReportGenerator.java index 5a0f6821..ead644e8 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/timing/TimingReportGenerator.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/timing/TimingReportGenerator.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.io.Writer; import java.util.Date; import java.util.Map; + import com.comphenix.protocol.PacketType; import com.comphenix.protocol.timing.TimedListenerManager.ListenerType; import com.google.common.base.Charsets; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/BukkitUtil.java b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/BukkitUtil.java new file mode 100644 index 00000000..73ab58b8 --- /dev/null +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/BukkitUtil.java @@ -0,0 +1,37 @@ +package com.comphenix.protocol.utility; + +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +/** + * Utility methods relating to Bukkit. + * @author dmulloy2 + */ + +public class BukkitUtil { + + private static Method getOnlinePlayers; + + /** + * Gets a list of online {@link Player}s. This also provides backwards + * compatibility as Bukkit changed getOnlinePlayers. + * + * @return A list of online Players + */ + @SuppressWarnings("unchecked") + public static List getOnlinePlayers() { + try { + if (getOnlinePlayers == null) + getOnlinePlayers = Bukkit.class.getMethod("getOnlinePlayers"); + if (getOnlinePlayers.getReturnType() != Collection.class) + return Arrays.asList((Player[]) getOnlinePlayers.invoke(null)); + } catch (Throwable ex) { + } + return (List) Bukkit.getOnlinePlayers(); + } +} \ No newline at end of file diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/ByteBufAdapter.java b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/ByteBufAdapter.java index 74df7758..6d370b4a 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/ByteBufAdapter.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/ByteBufAdapter.java @@ -12,15 +12,15 @@ import java.nio.channels.GatheringByteChannel; import java.nio.channels.ScatteringByteChannel; import java.nio.channels.WritableByteChannel; +import net.minecraft.util.io.netty.buffer.AbstractByteBuf; +import net.minecraft.util.io.netty.buffer.ByteBuf; +import net.minecraft.util.io.netty.buffer.ByteBufAllocator; + import com.comphenix.protocol.reflect.accessors.Accessors; import com.comphenix.protocol.reflect.accessors.FieldAccessor; import com.google.common.io.ByteStreams; import com.google.common.io.LimitInputStream; -import net.minecraft.util.io.netty.buffer.AbstractByteBuf; -import net.minecraft.util.io.netty.buffer.ByteBuf; -import net.minecraft.util.io.netty.buffer.ByteBufAllocator; - /** * Construct a ByteBuf around an input stream and an output stream. *

diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftVersion.java b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftVersion.java index 6fd1dd9a..0fcf38e3 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftVersion.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftVersion.java @@ -24,8 +24,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.bukkit.Server; -import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.ProtocolLibrary; import com.google.common.base.Objects; import com.google.common.collect.ComparisonChain; import com.google.common.collect.Ordering; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/RemappedClassSource.java b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/RemappedClassSource.java index 32caec24..4cd4d088 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/RemappedClassSource.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/RemappedClassSource.java @@ -22,6 +22,7 @@ package com.comphenix.protocol.utility; // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import java.lang.reflect.Method; + import org.bukkit.Bukkit; import com.comphenix.protocol.reflect.FieldUtils; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/StreamSerializer.java b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/StreamSerializer.java index 17a386da..591c0fb3 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/StreamSerializer.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/StreamSerializer.java @@ -7,6 +7,7 @@ import java.io.DataInputStream; import java.io.DataOutput; import java.io.DataOutputStream; import java.io.IOException; + import javax.annotation.Nonnull; import org.bukkit.inventory.ItemStack; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java index e1102045..785e9c3b 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java @@ -7,11 +7,8 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.List; -import javax.imageio.ImageIO; -import org.bukkit.Bukkit; -import org.bukkit.Server; -import org.bukkit.entity.Player; +import javax.imageio.ImageIO; import net.minecraft.util.com.mojang.authlib.GameProfile; import net.minecraft.util.io.netty.buffer.ByteBuf; @@ -19,6 +16,10 @@ import net.minecraft.util.io.netty.buffer.Unpooled; import net.minecraft.util.io.netty.handler.codec.base64.Base64; import net.minecraft.util.io.netty.util.IllegalReferenceCountException; +import org.bukkit.Bukkit; +import org.bukkit.Server; +import org.bukkit.entity.Player; + import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; @@ -28,6 +29,7 @@ import com.comphenix.protocol.reflect.accessors.Accessors; import com.comphenix.protocol.reflect.accessors.ConstructorAccessor; import com.comphenix.protocol.reflect.accessors.FieldAccessor; import com.comphenix.protocol.reflect.accessors.MethodAccessor; +import com.comphenix.protocol.utility.BukkitUtil; import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftVersion; import com.google.common.base.Charsets; @@ -46,13 +48,13 @@ public class WrappedServerPing extends AbstractWrapper { /** * Lookup of Minecraft versions and ping version numbers. */ - private static ImmutableMap VERSION_NUMBERS = + private static ImmutableMap VERSION_NUMBERS = ImmutableMap.builder(). put(MinecraftVersion.WORLD_UPDATE, 4). put(MinecraftVersion.SKIN_UPDATE, 5). build(); private static MinecraftVersion LAST_VERSION = MinecraftVersion.SKIN_UPDATE; - + // Server ping fields private static Class SERVER_PING = MinecraftReflection.getServerPingClass(); private static ConstructorAccessor SERVER_PING_CONSTRUCTOR = Accessors.getConstructorAccessor(SERVER_PING); @@ -60,11 +62,11 @@ public class WrappedServerPing extends AbstractWrapper { private static FieldAccessor PLAYERS = Accessors.getFieldAccessor(SERVER_PING, MinecraftReflection.getServerPingPlayerSampleClass(), true); private static FieldAccessor VERSION = Accessors.getFieldAccessor(SERVER_PING, MinecraftReflection.getServerPingServerDataClass(), true); private static FieldAccessor FAVICON = Accessors.getFieldAccessor(SERVER_PING, String.class, true); - + // For converting to the underlying array - private static EquivalentConverter> PROFILE_CONVERT = + private static EquivalentConverter> PROFILE_CONVERT = BukkitConverters.getArrayConverter(GameProfile.class, BukkitConverters.getWrappedGameProfileConverter()); - + // Server ping player sample fields private static Class PLAYERS_CLASS = MinecraftReflection.getServerPingPlayerSampleClass(); private static ConstructorAccessor PLAYERS_CONSTRUCTOR = Accessors.getConstructorAccessor(PLAYERS_CLASS, int.class, int.class); @@ -72,7 +74,7 @@ public class WrappedServerPing extends AbstractWrapper { private static FieldAccessor PLAYERS_PROFILES = Accessors.getFieldAccessor(PLAYERS_CLASS, GameProfile[].class, true); private static FieldAccessor PLAYERS_MAXIMUM = PLAYERS_INTS[0]; private static FieldAccessor PLAYERS_ONLINE = PLAYERS_INTS[1]; - + // Server ping serialization private static Class GSON_CLASS = MinecraftReflection.getMinecraftGsonClass(); private static MethodAccessor GSON_TO_JSON = Accessors.getMethodAccessor(GSON_CLASS, "toJson", Object.class); @@ -80,23 +82,23 @@ public class WrappedServerPing extends AbstractWrapper { private static FieldAccessor PING_GSON = Accessors.getCached(Accessors.getFieldAccessor( PacketType.Status.Server.OUT_SERVER_INFO.getPacketClass(), GSON_CLASS, true )); - + // Server data fields private static Class VERSION_CLASS = MinecraftReflection.getServerPingServerDataClass(); private static ConstructorAccessor VERSION_CONSTRUCTOR = Accessors.getConstructorAccessor(VERSION_CLASS, String.class, int.class); private static FieldAccessor VERSION_NAME = Accessors.getFieldAccessor(VERSION_CLASS, String.class, true); private static FieldAccessor VERSION_PROTOCOL = Accessors.getFieldAccessor(VERSION_CLASS, int.class, true); - + // Get profile from player private static FieldAccessor ENTITY_HUMAN_PROFILE = Accessors.getFieldAccessor( MinecraftReflection.getEntityPlayerClass().getSuperclass(), GameProfile.class, true); - + // Inner class private Object players; // may be NULL private Object version; - + /** - * Construct a new server ping initialized with a zero player count, and zero maximum. + * Construct a new server ping initialized with a zero player count, and zero maximum. *

* Note that the version string is set to 1.7.2. */ @@ -106,14 +108,14 @@ public class WrappedServerPing extends AbstractWrapper { resetPlayers(); resetVersion(); } - + private WrappedServerPing(Object handle) { super(MinecraftReflection.getServerPingClass()); setHandle(handle); this.players = PLAYERS.get(handle); this.version = VERSION.get(handle); } - + /** * Set the player count and player maximum to the default values. */ @@ -121,14 +123,14 @@ public class WrappedServerPing extends AbstractWrapper { players = PLAYERS_CONSTRUCTOR.invoke(0, 0); PLAYERS.set(handle, players); } - + /** * Reset the version string to the default state. */ protected void resetVersion() { ProtocolManager manager = ProtocolLibrary.getProtocolManager(); MinecraftVersion minecraftVersion = LAST_VERSION; - + // Fetch the latest known version if (manager != null) { minecraftVersion = manager.getMinecraftVersion(); @@ -136,7 +138,7 @@ public class WrappedServerPing extends AbstractWrapper { version = VERSION_CONSTRUCTOR.invoke(minecraftVersion.toString(), VERSION_NUMBERS.get(minecraftVersion)); VERSION.set(handle, version); } - + /** * Construct a wrapped server ping from a native NMS object. * @param handle - the native object. @@ -145,7 +147,7 @@ public class WrappedServerPing extends AbstractWrapper { public static WrappedServerPing fromHandle(Object handle) { return new WrappedServerPing(handle); } - + /** * Construct a wrapper server ping from an encoded JSON string. * @param json - the JSON string. @@ -154,7 +156,7 @@ public class WrappedServerPing extends AbstractWrapper { public static WrappedServerPing fromJson(String json) { return fromHandle(GSON_FROM_JSON.invoke(PING_GSON.get(null), json, SERVER_PING)); } - + /** * Retrieve the message of the day. * @return The messge of the day. @@ -162,7 +164,7 @@ public class WrappedServerPing extends AbstractWrapper { public WrappedChatComponent getMotD() { return WrappedChatComponent.fromHandle(DESCRIPTION.get(handle)); } - + /** * Set the message of the day. * @param description - message of the day. @@ -178,7 +180,7 @@ public class WrappedServerPing extends AbstractWrapper { public void setMotD(String message) { setMotD(WrappedChatComponent.fromText(message)); } - + /** * Retrieve the compressed PNG file that is being displayed as a favicon. * @return The favicon, or NULL if no favicon will be displayed. @@ -187,7 +189,7 @@ public class WrappedServerPing extends AbstractWrapper { String favicon = (String) FAVICON.get(handle); return (favicon != null) ? CompressedImage.fromEncodedText(favicon) : null; } - + /** * Set the compressed PNG file that is being displayed. * @param image - the new compressed image or NULL if no favicon should be displayed. @@ -195,7 +197,7 @@ public class WrappedServerPing extends AbstractWrapper { public void setFavicon(CompressedImage image) { FAVICON.set(handle, (image != null) ? image.toEncodedText() : null); } - + /** * Retrieve the displayed number of online players. * @see {@link #setPlayersOnline(int)} for more information. @@ -207,11 +209,11 @@ public class WrappedServerPing extends AbstractWrapper { throw new IllegalStateException("The player count has been hidden."); return (Integer) PLAYERS_ONLINE.get(players); } - + /** * Set the displayed number of online players. *

- * As of 1.7.2, this is completely unrestricted, and can be both positive and + * As of 1.7.2, this is completely unrestricted, and can be both positive and * negative, as well as higher than the player maximum. * @param online - online players. */ @@ -220,7 +222,7 @@ public class WrappedServerPing extends AbstractWrapper { resetPlayers(); PLAYERS_ONLINE.set(players, online); } - + /** * Retrieve the displayed maximum number of players. * @see {@link #setPlayersMaximum(int)} for more information. @@ -232,7 +234,7 @@ public class WrappedServerPing extends AbstractWrapper { throw new IllegalStateException("The player maximum has been hidden."); return (Integer) PLAYERS_MAXIMUM.get(players); } - + /** * Set the displayed maximum number of players. *

@@ -245,7 +247,7 @@ public class WrappedServerPing extends AbstractWrapper { resetPlayers(); PLAYERS_MAXIMUM.set(players, maximum); } - + /** * Set whether or not the player count and player maximum is visible. *

@@ -258,13 +260,13 @@ public class WrappedServerPing extends AbstractWrapper { // Recreate the count and maximum Server server = Bukkit.getServer(); setPlayersMaximum(server.getMaxPlayers()); - setPlayersOnline(server.getOnlinePlayers().length); + setPlayersOnline(BukkitUtil.getOnlinePlayers().size()); } else { PLAYERS.set(handle, players = null); } } } - + /** * Determine if the player count and maximum is visible. *

@@ -274,7 +276,7 @@ public class WrappedServerPing extends AbstractWrapper { public boolean isPlayersVisible() { return players != null; } - + /** * Retrieve a copy of all the logged in players. * @return Logged in players or an empty list if no player names will be displayed. @@ -287,7 +289,7 @@ public class WrappedServerPing extends AbstractWrapper { return ImmutableList.of(); return ImmutableList.copyOf(PROFILE_CONVERT.getSpecific(playerProfiles)); } - + /** * Set the displayed list of logged in players. * @param profile - every logged in player. @@ -297,21 +299,21 @@ public class WrappedServerPing extends AbstractWrapper { resetPlayers(); PLAYERS_PROFILES.set(players, (profile != null) ? PROFILE_CONVERT.getGeneric(GameProfile[].class, profile) : null); } - + /** * Set the displayed lst of logged in players. * @param players - the players to display. */ public void setBukkitPlayers(Iterable players) { List profiles = Lists.newArrayList(); - + for (Player player : players) { GameProfile profile = (GameProfile) ENTITY_HUMAN_PROFILE.get(BukkitUnwrapper.getInstance().unwrapItem(player)); profiles.add(WrappedGameProfile.fromHandle(profile)); } setPlayers(profiles); } - + /** * Retrieve the version name of the current server. * @return The version name. @@ -319,7 +321,7 @@ public class WrappedServerPing extends AbstractWrapper { public String getVersionName() { return (String) VERSION_NAME.get(version); } - + /** * Set the version name of the current server. * @param name - the new version name. @@ -327,7 +329,7 @@ public class WrappedServerPing extends AbstractWrapper { public void setVersionName(String name) { VERSION_NAME.set(version, name); } - + /** * Retrieve the protocol number. * @return The protocol. @@ -335,7 +337,7 @@ public class WrappedServerPing extends AbstractWrapper { public int getVersionProtocol() { return (Integer) VERSION_PROTOCOL.get(version); } - + /** * Set the version protocol * @param protocol - the protocol number. @@ -343,7 +345,7 @@ public class WrappedServerPing extends AbstractWrapper { public void setVersionProtocol(int protocol) { VERSION_PROTOCOL.set(version, protocol); } - + /** * Retrieve a deep copy of the current wrapper object. * @return The current object. @@ -351,13 +353,13 @@ public class WrappedServerPing extends AbstractWrapper { public WrappedServerPing deepClone() { WrappedServerPing copy = new WrappedServerPing(); WrappedChatComponent motd = getMotD(); - + copy.setPlayers(getPlayers()); copy.setFavicon(getFavicon()); copy.setMotD(motd != null ? motd.deepClone() : null); copy.setVersionName(getVersionName()); copy.setVersionProtocol(getVersionProtocol()); - + if (isPlayersVisible()) { copy.setPlayersMaximum(getPlayersMaximum()); copy.setPlayersOnline(getPlayersOnline()); @@ -366,7 +368,7 @@ public class WrappedServerPing extends AbstractWrapper { } return copy; } - + /** * Retrieve the underlying JSON representation of this server ping. * @return The JSON representation. @@ -374,12 +376,12 @@ public class WrappedServerPing extends AbstractWrapper { public String toJson() { return (String) GSON_TO_JSON.invoke(PING_GSON.get(null), handle); } - + @Override public String toString() { return "WrappedServerPing< " + toJson() + ">"; } - + /** * Represents a compressed favicon. * @author Kristian @@ -389,14 +391,14 @@ public class WrappedServerPing extends AbstractWrapper { protected volatile String mime; protected volatile byte[] data; protected volatile String encoded; - + /** * Represents a compressed image with no content. */ protected CompressedImage() { // Derived class should initialize some of the fields } - + /** * Construct a new compressed image. * @param mime - the mime type. @@ -416,7 +418,7 @@ public class WrappedServerPing extends AbstractWrapper { public static CompressedImage fromPng(InputStream input) throws IOException { return new CompressedImage("image/png", ByteStreams.toByteArray(input)); } - + /** * Retrieve a compressed image from a byte array of a PNG file. * @param data - the file as a byte array. @@ -425,7 +427,7 @@ public class WrappedServerPing extends AbstractWrapper { public static CompressedImage fromPng(byte[] data) { return new CompressedImage("image/png", data); } - + /** * Retrieve a compressed image from a base-64 encoded PNG file. * @param base64 - the base 64-encoded PNG. @@ -439,7 +441,7 @@ public class WrappedServerPing extends AbstractWrapper { throw new IllegalReferenceCountException("Must be a pure base64 encoded string. Cannot be an encoded text.", e); } } - + /** * Retrieve a compressed image from an image. * @param image - the image. @@ -450,7 +452,7 @@ public class WrappedServerPing extends AbstractWrapper { ImageIO.write(image, "png", output); return new CompressedImage("image/png", output.toByteArray()); } - + /** * Retrieve a compressed image from an encoded text. * @param text - the encoded text. @@ -459,17 +461,17 @@ public class WrappedServerPing extends AbstractWrapper { public static CompressedImage fromEncodedText(String text) { return new EncodedCompressedImage(text); } - + /** * Retrieve the MIME type of the image. - *

+ *

* This is image/png in vanilla Minecraft. * @return The MIME type. */ public String getMime() { return mime; } - + /** * Retrieve a copy of the underlying data array. * @return The underlying compressed image. @@ -477,7 +479,7 @@ public class WrappedServerPing extends AbstractWrapper { public byte[] getDataCopy() { return getData().clone(); } - + /** * Retrieve the underlying data, with no copying. * @return The underlying data. @@ -485,7 +487,7 @@ public class WrappedServerPing extends AbstractWrapper { protected byte[] getData() { return data; } - + /** * Uncompress and return the stored image. * @return The image. @@ -494,7 +496,7 @@ public class WrappedServerPing extends AbstractWrapper { public BufferedImage getImage() throws IOException { return ImageIO.read(new ByteArrayInputStream(getData())); } - + /** * Convert the compressed image to encoded text. * @return The encoded text. @@ -502,15 +504,15 @@ public class WrappedServerPing extends AbstractWrapper { public String toEncodedText() { if (encoded == null) { final ByteBuf buffer = Unpooled.wrappedBuffer(getData()); - String computed = "data:" + mime + ";base64," + + String computed = "data:" + mime + ";base64," + Base64.encode(buffer).toString(Charsets.UTF_8); - + encoded = computed; } return encoded; } } - + /** * Represents a compressed image that starts out as an encoded base 64 string. * @author Kristian @@ -519,7 +521,7 @@ public class WrappedServerPing extends AbstractWrapper { public EncodedCompressedImage(String encoded) { this.encoded = Preconditions.checkNotNull(encoded, "encoded favicon cannot be NULL"); } - + /** * Ensure that we have decoded the content of the encoded text. */ @@ -528,7 +530,7 @@ public class WrappedServerPing extends AbstractWrapper { decode(); } } - + /** * Decode the encoded text. */ @@ -539,7 +541,7 @@ public class WrappedServerPing extends AbstractWrapper { } else if (segment.startsWith("base64,")) { byte[] encoded = segment.substring(7).getBytes(Charsets.UTF_8); ByteBuf decoded = Base64.decode(Unpooled.wrappedBuffer(encoded)); - + // Read into a byte array byte[] data = new byte[decoded.readableBytes()]; decoded.readBytes(data); @@ -549,19 +551,19 @@ public class WrappedServerPing extends AbstractWrapper { } } } - + @Override protected byte[] getData() { initialize(); return super.getData(); } - + @Override public String getMime() { initialize(); return super.getMime(); } - + @Override public String toEncodedText() { return encoded; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedSignedProperty.java b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedSignedProperty.java index 890d59d4..5970c8b2 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedSignedProperty.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedSignedProperty.java @@ -3,6 +3,7 @@ package com.comphenix.protocol.wrappers; import java.security.PublicKey; import net.minecraft.util.com.mojang.authlib.properties.Property; + import com.google.common.base.Objects; /** diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/NbtBase.java b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/NbtBase.java index 87f9ffe4..36b6df2a 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/NbtBase.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/NbtBase.java @@ -17,8 +17,6 @@ package com.comphenix.protocol.wrappers.nbt; -import com.comphenix.protocol.wrappers.nbt.NbtBase; -import com.comphenix.protocol.wrappers.nbt.NbtType; /** * Represents a generic container for an NBT element. diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/TileEntityAccessor.java b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/TileEntityAccessor.java index 6ca96f7c..597a5428 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/TileEntityAccessor.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/TileEntityAccessor.java @@ -4,8 +4,6 @@ import java.io.IOException; import java.lang.reflect.Method; import java.util.concurrent.ConcurrentMap; -import net.minecraft.server.v1_7_R3.NBTTagCompound; -import net.minecraft.server.v1_7_R3.TileEntityChest; import net.sf.cglib.asm.ClassReader; import net.sf.cglib.asm.MethodVisitor; import net.sf.cglib.asm.Opcodes; @@ -34,24 +32,24 @@ class TileEntityAccessor { * Token indicating that the given block state doesn't contany any tile entities. */ private static final TileEntityAccessor EMPTY_ACCESSOR = new TileEntityAccessor(); - + /** * Cached field accessors - {@link #EMPTY_ACCESSOR} represents no valid tile entity. */ private static final ConcurrentMap, TileEntityAccessor> cachedAccessors = Maps.newConcurrentMap(); - + private FieldAccessor tileEntityField; private MethodAccessor readCompound; private MethodAccessor writeCompound; - + // For CGLib detection private boolean writeDetected; private boolean readDetected; - + private TileEntityAccessor() { // Do nothing } - + /** * Construct a new tile entity accessor. * @param tileEntityField - the tile entity field. @@ -63,7 +61,7 @@ class TileEntityAccessor { if (tileEntityField != null) { this.tileEntityField = tileEntityField; Class type = tileEntityField.getField().getType(); - + // Possible read/write methods try { findMethodsUsingASM(type); @@ -75,7 +73,7 @@ class TileEntityAccessor { throw new RuntimeException("Cannot find read/write methods in " + type, ex2); } } - + // Ensure we found them if (readCompound == null) throw new RuntimeException("Unable to find read method in " + type); @@ -93,36 +91,37 @@ class TileEntityAccessor { private void findMethodsUsingASM(final Class tileEntityClass) throws IOException { final Class nbtCompoundClass = MinecraftReflection.getNBTCompoundClass(); final ClassReader reader = new ClassReader(tileEntityClass.getCanonicalName()); - + final String tagCompoundName = getJarName(MinecraftReflection.getNBTCompoundClass()); final String expectedDesc = "(L" + tagCompoundName + ";)V"; - + reader.accept(new EmptyClassVisitor() { @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { final String methodName = name; - + // Detect read/write calls to NBTTagCompound if (expectedDesc.equals(desc)) { return new EmptyMethodVisitor() { private int readMethods; private int writeMethods; - + + @Override public void visitMethodInsn(int opcode, String owner, String name, String desc) { // This must be a virtual call on NBTTagCompound that accepts a String - if (opcode == Opcodes.INVOKEVIRTUAL && - tagCompoundName.equals(owner) && + if (opcode == Opcodes.INVOKEVIRTUAL && + tagCompoundName.equals(owner) && desc.startsWith("(Ljava/lang/String")) { - + // Is this a write call? if (desc.endsWith(")V")) { writeMethods++; } else { readMethods++; } - } + } } - + @Override public void visitEnd() { if (readMethods > writeMethods) { @@ -138,7 +137,7 @@ class TileEntityAccessor { } }, 0); } - + /** * Find the read/write methods in TileEntity. * @param blockState - the block state. @@ -146,7 +145,7 @@ class TileEntityAccessor { */ private void findMethodUsingCGLib(T blockState) throws IOException { final Class nbtCompoundClass = MinecraftReflection.getNBTCompoundClass(); - + // This is a much slower method, but it is necessary in MCPC Enhancer enhancer = EnhancerFactory.getInstance().createEnhancer(); enhancer.setSuperclass(nbtCompoundClass); @@ -165,11 +164,11 @@ class TileEntityAccessor { }); Object compound = enhancer.create(); Object tileEntity = tileEntityField.get(blockState); - + // Look in every read/write like method for (Method method : FuzzyReflection.fromObject(tileEntity, true). getMethodListByParameters(Void.TYPE, new Class[] { nbtCompoundClass })) { - + try { readDetected = false; writeDetected = false; @@ -183,7 +182,7 @@ class TileEntityAccessor { } } } - + /** * Retrieve the JAR name (slash instead of dots) of the given clas. * @param clazz - the class. @@ -192,7 +191,7 @@ class TileEntityAccessor { private static String getJarName(Class clazz) { return clazz.getCanonicalName().replace('.', '/'); } - + /** * Read the NBT compound that represents a given tile entity. * @param state - tile entity represented by a block state. @@ -201,12 +200,12 @@ class TileEntityAccessor { public NbtCompound readBlockState(T state) { NbtCompound output = NbtFactory.ofCompound(""); Object tileEntity = tileEntityField.get(state); - + // Write the block state to the output compound writeCompound.invoke(tileEntity, NbtFactory.fromBase(output).getHandle()); return output; } - + /** * Write the NBT compound as a tile entity. * @param state - target block state. @@ -214,11 +213,11 @@ class TileEntityAccessor { */ public void writeBlockState(T state, NbtCompound compound) { Object tileEntity = tileEntityField.get(state); - + // Ensure the block state is set to the compound readCompound.invoke(tileEntity, NbtFactory.fromBase(compound).getHandle()); } - + /** * Retrieve an accessor for the tile entity at a specific location. * @param state - the block state. @@ -228,22 +227,22 @@ class TileEntityAccessor { public static TileEntityAccessor getAccessor(T state) { Class craftBlockState = state.getClass(); TileEntityAccessor accessor = cachedAccessors.get(craftBlockState); - + // Attempt to construct the accessor if (accessor == null ) { TileEntityAccessor created = null; FieldAccessor field = null; - + try { field = Accessors.getFieldAccessor(craftBlockState, MinecraftReflection.getTileEntityClass(), true); } catch (Exception e) { created = EMPTY_ACCESSOR; - } + } if (field != null) { created = new TileEntityAccessor(field, state); } accessor = cachedAccessors.putIfAbsent(craftBlockState, created); - + // We won the race if (accessor == null) { accessor = created; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/io/NbtConfigurationSerializer.java b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/io/NbtConfigurationSerializer.java index 7ddc9f1c..2b7c81ab 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/io/NbtConfigurationSerializer.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/io/NbtConfigurationSerializer.java @@ -8,6 +8,7 @@ import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Set; + import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/ProtocolLib/src/test/java/com/comphenix/integration/protocol/TestPingPacket.java b/ProtocolLib/src/test/java/com/comphenix/integration/protocol/TestPingPacket.java index e8eedfde..8b9e934a 100644 --- a/ProtocolLib/src/test/java/com/comphenix/integration/protocol/TestPingPacket.java +++ b/ProtocolLib/src/test/java/com/comphenix/integration/protocol/TestPingPacket.java @@ -8,7 +8,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import com.comphenix.protocol.PacketType; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/BukkitInitialization.java b/ProtocolLib/src/test/java/com/comphenix/protocol/BukkitInitialization.java index 10b821a3..db402a38 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/BukkitInitialization.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/BukkitInitialization.java @@ -3,30 +3,29 @@ package com.comphenix.protocol; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; - -import net.minecraft.server.v1_7_R3.Block; -import net.minecraft.server.v1_7_R3.Item; -import net.minecraft.server.v1_7_R3.StatisticList; - -// Will have to be updated for every version though -import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftItemFactory; +import net.minecraft.server.v1_7_R4.Block; +import net.minecraft.server.v1_7_R4.Item; +import net.minecraft.server.v1_7_R4.StatisticList; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Server; +import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemFactory; import org.bukkit.inventory.ItemFactory; import org.bukkit.inventory.meta.ItemMeta; + import com.comphenix.protocol.reflect.FieldUtils; import com.comphenix.protocol.utility.MinecraftReflection; +// Will have to be updated for every version though /** * Used to ensure that ProtocolLib and Bukkit is prepared to be tested. - * + * * @author Kristian */ public class BukkitInitialization { private static boolean initialized; - + /** * Initialize Bukkit and ProtocolLib such that we can perfrom unit testing. * @throws IllegalAccessException If we are unable to initialize Bukkit. @@ -35,9 +34,9 @@ public class BukkitInitialization { if (!initialized) { // Denote that we're done initialized = true; - + initializePackage(); - + try { Block.p(); Item.l(); @@ -46,24 +45,24 @@ public class BukkitInitialization { // Swallow e.printStackTrace(); } - + // Mock the server object Server mockedServer = mock(Server.class); ItemFactory mockedFactory = mock(CraftItemFactory.class); ItemMeta mockedMeta = mock(ItemMeta.class); - + when(mockedServer.getItemFactory()).thenReturn(mockedFactory); when(mockedServer.isPrimaryThread()).thenReturn(true); when(mockedFactory.getItemMeta(any(Material.class))).thenReturn(mockedMeta); - + // Inject this fake server FieldUtils.writeStaticField(Bukkit.class, "server", mockedServer, true); - + // And the fake item factory FieldUtils.writeStaticField(CraftItemFactory.class, "instance", mockedFactory, true); } } - + /** * Ensure that package names are correctly set up. */ diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/MinecraftVersionTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/MinecraftVersionTest.java index aa3a3691..75d2efc0 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/MinecraftVersionTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/MinecraftVersionTest.java @@ -17,7 +17,9 @@ package com.comphenix.protocol; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import org.junit.Test; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/PacketTypeTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/PacketTypeTest.java index abd501ef..aa744859 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/PacketTypeTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/PacketTypeTest.java @@ -1,6 +1,6 @@ package com.comphenix.protocol; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import org.junit.BeforeClass; import org.junit.Test; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/concurrency/BlockingHashMapTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/concurrency/BlockingHashMapTest.java index 75126855..f73e91ca 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/concurrency/BlockingHashMapTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/concurrency/BlockingHashMapTest.java @@ -17,7 +17,7 @@ package com.comphenix.protocol.concurrency; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java index 037fc6f4..dc46741d 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java @@ -2,39 +2,43 @@ * 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 + * 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. + * 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 + * 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.events; -import static org.junit.Assert.*; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.lang.reflect.Array; import java.util.List; import java.util.UUID; -import net.minecraft.server.v1_7_R3.AttributeModifier; -import net.minecraft.server.v1_7_R3.AttributeSnapshot; -import net.minecraft.server.v1_7_R3.PacketPlayOutUpdateAttributes; +import net.minecraft.server.v1_7_R4.AttributeModifier; +import net.minecraft.server.v1_7_R4.AttributeSnapshot; +import net.minecraft.server.v1_7_R4.PacketPlayOutUpdateAttributes; import org.apache.commons.lang.SerializationUtils; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; -// Will have to be updated for every version though -import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftItemFactory; - import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.WorldType; +import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemFactory; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; @@ -59,8 +63,8 @@ import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.comphenix.protocol.wrappers.WrappedWatchableObject; import com.comphenix.protocol.wrappers.nbt.NbtCompound; import com.comphenix.protocol.wrappers.nbt.NbtFactory; - import com.google.common.collect.Lists; +// Will have to be updated for every version though // Ensure that the CraftItemFactory is mockable @RunWith(org.powermock.modules.junit4.PowerMockRunner.class) @@ -70,12 +74,12 @@ public class PacketContainerTest { // Helper converters private EquivalentConverter watchConvert = BukkitConverters.getDataWatcherConverter(); private EquivalentConverter itemConvert = BukkitConverters.getItemStackConverter(); - + @BeforeClass public static void initializeBukkit() throws IllegalAccessException { BukkitInitialization.initializeItemMeta(); } - + private void testPrimitive(StructureModifier modifier, int index, T initialValue, T testValue) { // Check initial value assertEquals(initialValue, modifier.read(index)); @@ -84,7 +88,7 @@ public class PacketContainerTest { modifier.write(index, testValue); assertEquals(testValue, modifier.read(0)); } - + private void testObjectArray(StructureModifier modifier, int index, T[] initialValue, T[] testValue) { // Check initial value assertNull(modifier.read(index)); @@ -92,7 +96,7 @@ public class PacketContainerTest { // Test initial assertArrayEquals(initialValue, modifier.read(index)); - + // Test assignment modifier.write(index, testValue); assertArrayEquals(testValue, modifier.read(0)); @@ -104,25 +108,25 @@ public class PacketContainerTest { PacketContainer customPayload = new PacketContainer(PacketType.Play.Server.CUSTOM_PAYLOAD); StructureModifier bytes = customPayload.getByteArrays(); byte[] testArray = new byte[] { 1, 2, 3 }; - + // It's NULL at first - assertArrayEquals(null, (byte[]) bytes.read(0)); + assertArrayEquals(null, bytes.read(0)); customPayload.getModifier().writeDefaults(); - + // Then it should create an empty array - assertArrayEquals(new byte[0], (byte[]) bytes.read(0)); - + assertArrayEquals(new byte[0], bytes.read(0)); + // Check and see if we can write to it bytes.write(0, testArray); - assertArrayEquals(testArray, (byte[]) bytes.read(0)); + assertArrayEquals(testArray, bytes.read(0)); } - + @Test public void testGetBytes() { PacketContainer spawnMob = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY_LIVING); testPrimitive(spawnMob.getBytes(), 0, (byte)0, (byte)1); } - + @Test public void testGetShorts() { PacketContainer itemData = new PacketContainer(PacketType.Play.Server.TRANSACTION); @@ -132,7 +136,7 @@ public class PacketContainerTest { @Test public void testGetIntegers() { PacketContainer updateSign = new PacketContainer(PacketType.Play.Server.UPDATE_SIGN); - testPrimitive(updateSign.getIntegers(), 0, (int)0, (int)1); + testPrimitive(updateSign.getIntegers(), 0, 0, 1); } @Test @@ -150,7 +154,7 @@ public class PacketContainerTest { @Test public void testGetDoubles() { PacketContainer explosion = new PacketContainer(PacketType.Play.Server.EXPLOSION); - testPrimitive(explosion.getDoubles(), 0, (double)0, (double)0.8); + testPrimitive(explosion.getDoubles(), 0, (double)0, 0.8); } @Test @@ -171,57 +175,57 @@ public class PacketContainerTest { PacketContainer mapChunkBulk = new PacketContainer(PacketType.Play.Server.MAP_CHUNK_BULK); StructureModifier integers = mapChunkBulk.getIntegerArrays(); int[] testArray = new int[] { 1, 2, 3 }; - + // Pre and post conditions - assertArrayEquals(null, (int[]) integers.read(0)); + assertArrayEquals(null, integers.read(0)); mapChunkBulk.getModifier().writeDefaults(); - assertArrayEquals(new int[0], (int[]) integers.read(0)); - + assertArrayEquals(new int[0], integers.read(0)); + integers.write(0, testArray); - assertArrayEquals(testArray, (int[]) integers.read(0)); + assertArrayEquals(testArray, integers.read(0)); } @Test public void testGetItemModifier() { PacketContainer windowClick = new PacketContainer(PacketType.Play.Client.WINDOW_CLICK); - + StructureModifier items = windowClick.getItemModifier(); ItemStack goldAxe = new ItemStack(Material.GOLD_AXE); - + assertNotNull(goldAxe.getType()); assertNull(items.read(0)); - + // Insert the goldaxe and check if it's there items.write(0, goldAxe); assertTrue("Item " + goldAxe + " != " + items.read(0), equivalentItem(goldAxe, items.read(0))); } - + @Test public void testGetItemArrayModifier() { PacketContainer windowItems = new PacketContainer(PacketType.Play.Server.WINDOW_ITEMS); StructureModifier itemAccess = windowItems.getItemArrayModifier(); - - ItemStack[] itemArray = new ItemStack[] { + + ItemStack[] itemArray = new ItemStack[] { new ItemStack(Material.GOLD_AXE), new ItemStack(Material.DIAMOND_AXE) }; - + assertNull(itemAccess.read(0)); - + // Insert and check that it was succesful itemAccess.write(0, itemArray); - + // Read back array ItemStack[] comparision = itemAccess.read(0); assertEquals(itemArray.length, comparision.length); - + // Check that it is equivalent for (int i = 0; i < itemArray.length; i++) { assertTrue(String.format("Array element %s is not the same: %s != %s", i, itemArray[i], comparision[i]), equivalentItem(itemArray[i], comparision[i])); } } - + private boolean equivalentItem(ItemStack first, ItemStack second) { if (first == null) { return second == null; @@ -231,20 +235,20 @@ public class PacketContainerTest { return first.getType().equals(second.getType()); } } - + @Test public void testGetWorldTypeModifier() { // Not used in Netty if (MinecraftReflection.isUsingNetty()) return; - + PacketContainer loginPacket = new PacketContainer(PacketType.Play.Server.LOGIN); StructureModifier worldAccess = loginPacket.getWorldTypeModifier(); - + WorldType testValue = WorldType.LARGE_BIOMES; - + assertNull(worldAccess.read(0)); - + // Insert and read back worldAccess.write(0, testValue); assertEquals(testValue, worldAccess.read(0)); @@ -253,30 +257,30 @@ public class PacketContainerTest { @Test public void testGetNbtModifier() { PacketContainer updateTileEntity = new PacketContainer(PacketType.Play.Server.TILE_ENTITY_DATA); - + NbtCompound compound = NbtFactory.ofCompound("test"); compound.put("test", "name"); compound.put(NbtFactory.ofList("ages", 1, 2, 3)); - + updateTileEntity.getNbtModifier().write(0, compound); - + NbtCompound result = (NbtCompound) updateTileEntity.getNbtModifier().read(0); - + assertEquals(compound.getString("test"), result.getString("test")); assertEquals(compound.getList("ages"), result.getList("ages")); } - + @Test public void testGetDataWatcherModifier() { PacketContainer mobSpawnPacket = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY_LIVING); StructureModifier watcherAccessor = mobSpawnPacket.getDataWatcherModifier(); - + WrappedDataWatcher dataWatcher = new WrappedDataWatcher(); dataWatcher.setObject(1, 100); dataWatcher.setObject(2, 125); - + assertNull(watcherAccessor.read(0)); - + // Insert and read back watcherAccessor.write(0, dataWatcher); assertEquals(dataWatcher, watcherAccessor.read(0)); @@ -285,7 +289,7 @@ public class PacketContainerTest { // Unfortunately, it might be too difficult to mock this one // // @Test - // public void testGetEntityModifier() { } + // public void testGetEntityModifier() { } // No packet expose this type directly. // @@ -296,94 +300,94 @@ public class PacketContainerTest { public void testGetPositionCollectionModifier() { PacketContainer explosionPacket = new PacketContainer(PacketType.Play.Server.EXPLOSION); StructureModifier> positionAccessor = explosionPacket.getPositionCollectionModifier(); - + assertNull(positionAccessor.read(0)); - + List positions = Lists.newArrayList(); positions.add(new ChunkPosition(1, 2, 3)); positions.add(new ChunkPosition(3, 4, 5)); - + // Insert and read back positionAccessor.write(0, positions); List cloned = positionAccessor.read(0); - + assertEquals(positions, cloned); } @Test public void testGetWatchableCollectionModifier() { PacketContainer entityMetadata = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); - StructureModifier> watchableAccessor = + StructureModifier> watchableAccessor = entityMetadata.getWatchableCollectionModifier(); - + assertNull(watchableAccessor.read(0)); - + WrappedDataWatcher watcher = new WrappedDataWatcher(); watcher.setObject(1, 10); watcher.setObject(8, 10); - + List list = watcher.getWatchableObjects(); - + // Insert and read back watchableAccessor.write(0, list); assertEquals(list, watchableAccessor.read(0)); } - + @Test public void testGameProfiles() { PacketContainer spawnEntity = new PacketContainer(PacketType.Play.Server.NAMED_ENTITY_SPAWN); WrappedGameProfile profile = new WrappedGameProfile("d7047a08-3150-4aa8-a2f2-7c1e2b17e298", "name"); spawnEntity.getGameProfiles().write(0, profile); - + assertEquals(profile, spawnEntity.getGameProfiles().read(0)); } - + @Test public void testChatComponents() { PacketContainer chatPacket = new PacketContainer(PacketType.Play.Server.CHAT); - chatPacket.getChatComponents().write(0, + chatPacket.getChatComponents().write(0, WrappedChatComponent.fromChatMessage("You shall not " + ChatColor.ITALIC + "pass!")[0]); - - assertEquals("{\"extra\":[\"You shall not \",{\"italic\":true,\"text\":\"pass!\"}],\"text\":\"\"}", + + assertEquals("{\"extra\":[\"You shall not \",{\"italic\":true,\"text\":\"pass!\"}],\"text\":\"\"}", chatPacket.getChatComponents().read(0).getJson()); } - + @Test public void testSerialization() { PacketContainer chat = new PacketContainer(PacketType.Play.Client.CHAT); chat.getStrings().write(0, "Test"); - + PacketContainer copy = (PacketContainer) SerializationUtils.clone(chat); - + assertEquals(PacketType.Play.Client.CHAT, copy.getType()); assertEquals("Test", copy.getStrings().read(0)); } - + @Test public void testAttributeList() { PacketContainer attribute = new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES); attribute.getIntegers().write(0, 123); // Entity ID - + // Initialize some test data List modifiers = Lists.newArrayList( new AttributeModifier(UUID.randomUUID(), "Unknown synced attribute modifier", 10, 0)); AttributeSnapshot snapshot = new AttributeSnapshot( (PacketPlayOutUpdateAttributes) attribute.getHandle(), "generic.Maxhealth", 20.0, modifiers); - + attribute.getSpecificModifier(List.class).write(0, Lists.newArrayList(snapshot)); PacketContainer cloned = attribute.deepClone(); AttributeSnapshot clonedSnapshot = (AttributeSnapshot) cloned.getSpecificModifier(List.class).read(0).get(0); - + assertEquals( ToStringBuilder.reflectionToString(snapshot, ToStringStyle.SHORT_PREFIX_STYLE), ToStringBuilder.reflectionToString(clonedSnapshot, ToStringStyle.SHORT_PREFIX_STYLE)); } - + @Test public void testBlocks() { PacketContainer blockAction = new PacketContainer(PacketType.Play.Server.BLOCK_ACTION); blockAction.getBlocks().write(0, Material.STONE); - + assertEquals(Material.STONE, blockAction.getBlocks().read(0)); } @@ -391,38 +395,38 @@ public class PacketContainerTest { @Test public void testPotionEffect() { PotionEffect effect = new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 20 * 60, 1); - + // The constructor we want to call PacketConstructor creator = PacketConstructor.DEFAULT.withPacket( - PacketType.Play.Server.ENTITY_EFFECT, new Class[] { int.class, PotionEffect.class }); + PacketType.Play.Server.ENTITY_EFFECT, new Class[] { int.class, PotionEffect.class }); PacketContainer packet = creator.createPacket(1, effect); - + assertEquals(1, (int) packet.getIntegers().read(0)); assertEquals(effect.getType().getId(), (byte) packet.getBytes().read(0)); assertEquals(effect.getAmplifier(), (byte) packet.getBytes().read(1)); assertEquals(effect.getDuration(), (short) packet.getShorts().read(0)); } - + @Test public void testDeepClone() { // Try constructing all the packets for (PacketType type : PacketType.values()) { // Whether or not this packet has been registered boolean registered = type.isSupported(); - + try { PacketContainer constructed = new PacketContainer(type); - + if (!registered) { fail("Expected IllegalArgumentException(Packet " + type + " not registered"); } - + // Initialize default values constructed.getModifier().writeDefaults(); - + // Clone the packet PacketContainer cloned = constructed.deepClone(); - + // Make sure they're equivalent StructureModifier firstMod = constructed.getModifier(), secondMod = cloned.getModifier(); assertEquals(firstMod.size(), secondMod.size()); @@ -439,7 +443,7 @@ public class PacketContainerTest { testEquality(firstMod.read(i), secondMod.read(i)); } } - + } catch (IllegalArgumentException e) { if (!registered) { // Check the same @@ -451,12 +455,12 @@ public class PacketContainerTest { } } } - + @Test public void testPacketType() { assertEquals(PacketType.Legacy.Server.SET_CREATIVE_SLOT, PacketType.findLegacy(107, Sender.SERVER)); } - + // Convert to objects that support equals() private void testEquality(Object a, Object b) { if (a != null && b != null) { @@ -468,10 +472,10 @@ public class PacketContainerTest { b = itemConvert.getSpecific(b); } } - + assertEquals(a, b); } - + /** * Get the underlying array as an object array. * @param val - array wrapped as an Object. @@ -485,7 +489,7 @@ public class PacketContainerTest { int arrlength = Array.getLength(val); Object[] outputArray = new Object[arrlength]; - + for (int i = 0; i < arrlength; ++i) outputArray[i] = Array.get(val, i); return outputArray; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/injector/PluginVerifierTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/injector/PluginVerifierTest.java index 26d8dda8..15febf7f 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/injector/PluginVerifierTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/injector/PluginVerifierTest.java @@ -1,25 +1,25 @@ package com.comphenix.protocol.injector; -import static org.junit.Assert.*; - -import java.util.Arrays; -import java.util.List; +import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import java.util.Arrays; +import java.util.List; + import org.bukkit.Server; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginLoadOrder; import org.bukkit.plugin.PluginManager; - import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; + import com.comphenix.protocol.injector.PluginVerifier.VerificationResult; import com.google.common.base.Objects; import com.google.common.collect.Lists; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/injector/SortedCopyOnWriteArrayTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/injector/SortedCopyOnWriteArrayTest.java index 610759c4..783f4008 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/injector/SortedCopyOnWriteArrayTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/injector/SortedCopyOnWriteArrayTest.java @@ -17,7 +17,8 @@ package com.comphenix.protocol.injector; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import java.util.ArrayList; import java.util.Collections; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/reflect/accessors/AccessorsTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/reflect/accessors/AccessorsTest.java index 20be86b1..aec4fe38 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/reflect/accessors/AccessorsTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/reflect/accessors/AccessorsTest.java @@ -1,6 +1,6 @@ package com.comphenix.protocol.reflect.accessors; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import org.junit.Test; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/reflect/cloning/AggregateClonerTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/reflect/cloning/AggregateClonerTest.java index 737e889a..d8b0925c 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/reflect/cloning/AggregateClonerTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/reflect/cloning/AggregateClonerTest.java @@ -1,6 +1,6 @@ package com.comphenix.protocol.reflect.cloning; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import java.util.Arrays; import java.util.List; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTest.java index d5404849..28f286fb 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTest.java @@ -1,17 +1,18 @@ package com.comphenix.protocol.utility; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; - -import net.minecraft.server.v1_7_R3.ChatComponentText; -import net.minecraft.server.v1_7_R3.ChatSerializer; -import net.minecraft.server.v1_7_R3.ChunkCoordIntPair; -import net.minecraft.server.v1_7_R3.IChatBaseComponent; -import net.minecraft.server.v1_7_R3.NBTCompressedStreamTools; -import net.minecraft.server.v1_7_R3.ServerPing; -import net.minecraft.server.v1_7_R3.ServerPingPlayerSample; -import net.minecraft.server.v1_7_R3.ServerPingServerData; -import net.minecraft.server.v1_7_R3.WatchableObject; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import net.minecraft.server.v1_7_R4.ChatComponentText; +import net.minecraft.server.v1_7_R4.ChatSerializer; +import net.minecraft.server.v1_7_R4.ChunkCoordIntPair; +import net.minecraft.server.v1_7_R4.IChatBaseComponent; +import net.minecraft.server.v1_7_R4.NBTCompressedStreamTools; +import net.minecraft.server.v1_7_R4.ServerPing; +import net.minecraft.server.v1_7_R4.ServerPingPlayerSample; +import net.minecraft.server.v1_7_R4.ServerPingServerData; +import net.minecraft.server.v1_7_R4.WatchableObject; import org.bukkit.block.Block; import org.bukkit.entity.Entity; @@ -27,40 +28,40 @@ public class MinecraftReflectionTest { private interface FakeEntity { public Entity getBukkitEntity(); } - + private interface FakeBlock { public Block getBukkitEntity(); } - + @BeforeClass public static void initializeReflection() throws IllegalAccessException { BukkitInitialization.initializePackage(); - + // Set up a package with no class loader knowledge MinecraftReflection.minecraftPackage = new CachedPackage( - MinecraftReflection.getMinecraftPackage(), + MinecraftReflection.getMinecraftPackage(), ClassSource.fromMap(Maps.>newHashMap()) ); } - + @AfterClass public static void undoMocking() { // NOP MinecraftReflection.minecraftPackage = null; } - + @Test public void testBukkitMethod() { FakeEntity entity = mock(FakeEntity.class); FakeBlock block = mock(FakeBlock.class); - + MinecraftReflection.getBukkitEntity(entity); MinecraftReflection.getBukkitEntity(block); - + verify(entity, times(1)).getBukkitEntity(); verify(block, times(1)).getBukkitEntity(); } - + @Test(expected = IllegalArgumentException.class) public void testIllegalClass() { MinecraftReflection.getBukkitEntity("Hello"); @@ -70,42 +71,42 @@ public class MinecraftReflectionTest { public void testNbtStreamTools() { assertEquals(NBTCompressedStreamTools.class, MinecraftReflection.getNbtCompressedStreamToolsClass()); } - + @Test public void testChatComponent() { assertEquals(IChatBaseComponent.class, MinecraftReflection.getIChatBaseComponentClass()); } - + @Test public void testChatComponentText() { assertEquals(ChatComponentText.class, MinecraftReflection.getChatComponentTextClass()); } - + @Test public void testChatSerializer() { assertEquals(ChatSerializer.class, MinecraftReflection.getChatSerializerClass()); } - + @Test public void testServerPing() { assertEquals(ServerPing.class, MinecraftReflection.getServerPingClass()); } - + @Test public void testServerPingPlayerSample() { assertEquals(ServerPingPlayerSample.class, MinecraftReflection.getServerPingPlayerSampleClass()); } - + @Test public void testServerPingServerData() { assertEquals(ServerPingServerData.class, MinecraftReflection.getServerPingServerDataClass()); } - + @Test public void testChunkCoordIntPair() { assertEquals(ChunkCoordIntPair.class, MinecraftReflection.getChunkCoordIntPair()); } - + @Test public void testWatchableObject() { assertEquals(WatchableObject.class, MinecraftReflection.getWatchableObjectClass()); diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/utility/SnapshotVersionTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/utility/SnapshotVersionTest.java index 534a5d2d..226e45a7 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/utility/SnapshotVersionTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/utility/SnapshotVersionTest.java @@ -1,6 +1,6 @@ package com.comphenix.protocol.utility; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import java.util.Calendar; import java.util.Date; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/utility/StreamSerializerTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/utility/StreamSerializerTest.java index 6646249b..3686eaa3 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/utility/StreamSerializerTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/utility/StreamSerializerTest.java @@ -1,6 +1,6 @@ package com.comphenix.protocol.utility; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -8,10 +8,10 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; -import net.minecraft.server.v1_7_R3.IntHashMap; +import net.minecraft.server.v1_7_R4.IntHashMap; import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftItemFactory; +import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemFactory; import org.bukkit.inventory.ItemStack; import org.junit.BeforeClass; import org.junit.Test; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/ChunkCoordIntPairTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/ChunkCoordIntPairTest.java index 75593fd1..a28fe23f 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/ChunkCoordIntPairTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/ChunkCoordIntPairTest.java @@ -1,6 +1,6 @@ package com.comphenix.protocol.wrappers; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import org.junit.BeforeClass; import org.junit.Test; @@ -15,16 +15,16 @@ public class ChunkCoordIntPairTest { @Test public void test() { - net.minecraft.server.v1_7_R3.ChunkCoordIntPair pair = new net.minecraft.server.v1_7_R3.ChunkCoordIntPair(1, 2); + net.minecraft.server.v1_7_R4.ChunkCoordIntPair pair = new net.minecraft.server.v1_7_R4.ChunkCoordIntPair(1, 2); ChunkCoordIntPair specific = ChunkCoordIntPair.getConverter().getSpecific(pair); - + assertEquals(1, specific.getChunkX()); assertEquals(2, specific.getChunkZ()); - - net.minecraft.server.v1_7_R3.ChunkCoordIntPair roundtrip = - (net.minecraft.server.v1_7_R3.ChunkCoordIntPair) ChunkCoordIntPair.getConverter(). - getGeneric(net.minecraft.server.v1_7_R3.ChunkCoordIntPair.class, specific); - + + net.minecraft.server.v1_7_R4.ChunkCoordIntPair roundtrip = + (net.minecraft.server.v1_7_R4.ChunkCoordIntPair) ChunkCoordIntPair.getConverter(). + getGeneric(net.minecraft.server.v1_7_R4.ChunkCoordIntPair.class, specific); + assertEquals(1, roundtrip.x); assertEquals(2, roundtrip.z); } diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/CloningTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/CloningTest.java index fa823741..917a9a9e 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/CloningTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/CloningTest.java @@ -1,10 +1,10 @@ package com.comphenix.protocol.wrappers; +import static org.junit.Assert.assertEquals; + import org.junit.BeforeClass; import org.junit.Test; -import static org.junit.Assert.*; - import com.comphenix.protocol.BukkitInitialization; import com.comphenix.protocol.reflect.cloning.AggregateCloner; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/EnumWrappersTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/EnumWrappersTest.java index bb9bb8ca..3e2d0561 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/EnumWrappersTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/EnumWrappersTest.java @@ -1,13 +1,12 @@ package com.comphenix.protocol.wrappers; -import static org.junit.Assert.*; - -import net.minecraft.server.v1_7_R3.EnumChatVisibility; -import net.minecraft.server.v1_7_R3.EnumClientCommand; -import net.minecraft.server.v1_7_R3.EnumDifficulty; -import net.minecraft.server.v1_7_R3.EnumEntityUseAction; -import net.minecraft.server.v1_7_R3.EnumGamemode; -import net.minecraft.server.v1_7_R3.EnumProtocol; +import static org.junit.Assert.assertEquals; +import net.minecraft.server.v1_7_R4.EnumChatVisibility; +import net.minecraft.server.v1_7_R4.EnumClientCommand; +import net.minecraft.server.v1_7_R4.EnumDifficulty; +import net.minecraft.server.v1_7_R4.EnumEntityUseAction; +import net.minecraft.server.v1_7_R4.EnumGamemode; +import net.minecraft.server.v1_7_R4.EnumProtocol; import org.junit.BeforeClass; import org.junit.Test; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedAttributeTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedAttributeTest.java index b607f3d6..77c4e59d 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedAttributeTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedAttributeTest.java @@ -1,12 +1,14 @@ package com.comphenix.protocol.wrappers; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertTrue; import java.util.List; -import net.minecraft.server.v1_7_R3.AttributeModifier; -import net.minecraft.server.v1_7_R3.AttributeSnapshot; -import net.minecraft.server.v1_7_R3.PacketPlayOutUpdateAttributes; +import net.minecraft.server.v1_7_R4.AttributeModifier; +import net.minecraft.server.v1_7_R4.AttributeSnapshot; +import net.minecraft.server.v1_7_R4.PacketPlayOutUpdateAttributes; import org.junit.Before; import org.junit.BeforeClass; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedChatComponentTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedChatComponentTest.java index c5b65c6f..ebd58442 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedChatComponentTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedChatComponentTest.java @@ -1,6 +1,6 @@ package com.comphenix.protocol.wrappers; -import static org.junit.Assert.*; +import static org.junit.Assert.assertNotNull; import org.junit.BeforeClass; import org.junit.Test; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedChunkCoordinateTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedChunkCoordinateTest.java index 325885b6..15b9de9d 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedChunkCoordinateTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedChunkCoordinateTest.java @@ -1,6 +1,6 @@ package com.comphenix.protocol.wrappers; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import org.junit.BeforeClass; import org.junit.Test; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedGameProfileTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedGameProfileTest.java index 29633383..7589cecc 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedGameProfileTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedGameProfileTest.java @@ -1,6 +1,6 @@ package com.comphenix.protocol.wrappers; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import java.util.UUID; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedIntHashMapTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedIntHashMapTest.java index 939a71cd..8cd34366 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedIntHashMapTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedIntHashMapTest.java @@ -1,6 +1,7 @@ package com.comphenix.protocol.wrappers; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import org.junit.BeforeClass; import org.junit.Test; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedServerPingTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedServerPingTest.java index d3c9c641..d6b2767a 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedServerPingTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedServerPingTest.java @@ -1,6 +1,7 @@ package com.comphenix.protocol.wrappers; -import static org.junit.Assert.*; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; import java.io.IOException; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedWatchableObjectTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedWatchableObjectTest.java index 98b14487..70c5ae3c 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedWatchableObjectTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedWatchableObjectTest.java @@ -1,9 +1,9 @@ package com.comphenix.protocol.wrappers; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftItemFactory; +import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemFactory; import org.bukkit.inventory.ItemStack; import org.junit.BeforeClass; import org.junit.Test; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/nbt/NbtCompoundTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/nbt/NbtCompoundTest.java index f512944e..d5cc001a 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/nbt/NbtCompoundTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/nbt/NbtCompoundTest.java @@ -17,10 +17,11 @@ package com.comphenix.protocol.wrappers.nbt; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import org.junit.BeforeClass; import org.junit.Test; + import com.comphenix.protocol.BukkitInitialization; public class NbtCompoundTest { diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/nbt/NbtFactoryTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/nbt/NbtFactoryTest.java index 7f6a49aa..7a65445b 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/nbt/NbtFactoryTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/nbt/NbtFactoryTest.java @@ -17,7 +17,7 @@ package com.comphenix.protocol.wrappers.nbt; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -27,7 +27,7 @@ import java.io.DataOutput; import java.io.DataOutputStream; import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftItemFactory; +import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemFactory; import org.bukkit.inventory.ItemStack; import org.junit.BeforeClass; import org.junit.Test; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/nbt/io/NbtConfigurationSerializerTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/nbt/io/NbtConfigurationSerializerTest.java index 3cc4f675..a1fa8495 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/nbt/io/NbtConfigurationSerializerTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/nbt/io/NbtConfigurationSerializerTest.java @@ -1,6 +1,6 @@ package com.comphenix.protocol.wrappers.nbt.io; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import org.bukkit.configuration.file.YamlConfiguration; import org.junit.BeforeClass; diff --git a/Readme.md b/Readme.md index f440d553..daebe85b 100644 --- a/Readme.md +++ b/Readme.md @@ -11,6 +11,8 @@ Critically, different plugins that use this approach may _hook_ into the same cl with unpredictable outcomes. More than often this causes plugins to crash, but it may also lead to more subtle bugs. +Currently maintained by dmulloy2 on behalf of [SpigotMC](http://www.spigotmc.org/) + ### Resources