Remove unused code, revert some unnecessary changes

This commit is contained in:
Dan Mulloy 2015-01-17 19:23:51 -05:00
parent 5e5eff5e5f
commit 3dda5c6a0a
17 changed files with 140 additions and 148 deletions

View File

@ -59,14 +59,14 @@ class CommandProtocol extends CommandBase {
else if (subCommand.equalsIgnoreCase("timings"))
toggleTimings(sender, args);
else if (subCommand.equalsIgnoreCase("listeners"))
printListeners(sender, args);
printListeners(sender);
else
return false;
return true;
}
// Display every listener on the server
private void printListeners(final CommandSender sender, String[] args) {
private void printListeners(final CommandSender sender) {
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
for (PacketListener listener : manager.getPacketListeners()) {

View File

@ -77,10 +77,6 @@ public class ProtocolConfig {
private int modCount;
public ProtocolConfig(Plugin plugin) {
this(plugin, plugin.getConfig());
}
public ProtocolConfig(Plugin plugin, Configuration config) {
this.plugin = plugin;
reloadConfig();
}

View File

@ -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
*/
@ -81,7 +81,7 @@ public class AsyncFilterManager implements AsynchronousManager {
/**
* Initialize a asynchronous filter manager.
* <p>
* <b>Internal method</b>. Retrieve the global asynchronous manager from the protocol manager instead.
* <b>Internal method</b>. Retrieve the global asynchronous manager from the protocol manager instead.
* @param reporter - desired error reporter.
* @param scheduler - task scheduler.
*/
@ -148,7 +148,7 @@ public class AsyncFilterManager implements AsynchronousManager {
ImmutableSet.Builder<PacketListener> builder = ImmutableSet.builder();
// Add every asynchronous packet listener
for (PrioritizedListener<AsyncListenerHandler> handler :
for (PrioritizedListener<AsyncListenerHandler> handler :
Iterables.concat(serverProcessingQueue.values(), clientProcessingQueue.values())) {
builder.add(handler.getListener().getAsyncListener());
}
@ -221,7 +221,7 @@ public class AsyncFilterManager implements AsynchronousManager {
if (listener == null)
throw new IllegalArgumentException("listener cannot be NULL.");
AsyncListenerHandler handler =
AsyncListenerHandler handler =
findHandler(serverProcessingQueue, listener.getSendingWhitelist(), listener);
if (handler == null) {
@ -232,7 +232,7 @@ public class AsyncFilterManager implements AsynchronousManager {
// Search for the first correct handler
private AsyncListenerHandler findHandler(PacketProcessingQueue queue, ListeningWhitelist search, PacketListener target) {
if (ListeningWhitelist.isEmpty(search))
if (ListeningWhitelist.isEmpty(search))
return null;
for (PacketType type : search.getTypes()) {
@ -250,7 +250,7 @@ public class AsyncFilterManager implements AsynchronousManager {
if (handler == null)
throw new IllegalArgumentException("listenerToken cannot be NULL");
handler.cancel();
handler.cancel();
}
// Called by AsyncListenerHandler
@ -295,7 +295,7 @@ public class AsyncFilterManager implements AsynchronousManager {
private void unregisterAsyncHandlers(PacketProcessingQueue processingQueue, Plugin plugin) {
// Iterate through every packet listener
for (PrioritizedListener<AsyncListenerHandler> listener : processingQueue.values()) {
for (PrioritizedListener<AsyncListenerHandler> listener : processingQueue.values()) {
// Remove the listener
if (Objects.equal(listener.getListener().getPlugin(), plugin)) {
unregisterAsyncHandler(listener.getListener());
@ -362,7 +362,7 @@ public class AsyncFilterManager implements AsynchronousManager {
* @return Asynchronous marker.
*/
public AsyncMarker createAsyncMarker() {
return createAsyncMarker(AsyncMarker.DEFAULT_SENDING_DELTA, AsyncMarker.DEFAULT_TIMEOUT_DELTA);
return createAsyncMarker(AsyncMarker.DEFAULT_TIMEOUT_DELTA);
}
/**
@ -371,14 +371,13 @@ public class AsyncFilterManager implements AsynchronousManager {
* @param timeoutDelta - how long (in ms) until the packet expire.
* @return An async marker.
*/
public AsyncMarker createAsyncMarker(long sendingDelta, long timeoutDelta) {
return createAsyncMarker(sendingDelta, timeoutDelta,
currentSendingIndex.incrementAndGet(), System.currentTimeMillis());
public AsyncMarker createAsyncMarker(long timeoutDelta) {
return createAsyncMarker(timeoutDelta, currentSendingIndex.incrementAndGet());
}
// Helper method
private AsyncMarker createAsyncMarker(long sendingDelta, long timeoutDelta, long sendingIndex, long currentTime) {
return new AsyncMarker(manager, sendingIndex, sendingDelta, System.currentTimeMillis(), timeoutDelta);
private AsyncMarker createAsyncMarker(long timeoutDelta, long sendingIndex) {
return new AsyncMarker(manager, sendingIndex, System.currentTimeMillis(), timeoutDelta);
}
@Override

View File

@ -110,7 +110,7 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
* Create a container for asyncronous packets.
* @param initialTime - the current time in milliseconds since 01.01.1970 00:00.
*/
AsyncMarker(PacketStream packetStream, long sendingIndex, long sendingDelta, long initialTime, long timeoutDelta) {
AsyncMarker(PacketStream packetStream, long sendingIndex, long initialTime, long timeoutDelta) {
if (packetStream == null)
throw new IllegalArgumentException("packetStream cannot be NULL");

View File

@ -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
*/
@ -53,7 +53,7 @@ class EntityUtilities {
private static Method scanPlayersMethod;
/*
* While this function may look pretty bad, it's essentially just a reflection-warped
* While this function may look pretty bad, it's essentially just a reflection-warped
* version of the following:
*
* @SuppressWarnings("unchecked")
@ -133,7 +133,7 @@ class EntityUtilities {
Object trackerEntry = getEntityTrackerEntry(entity.getWorld(), entity.getEntityId());
if (trackerEntry == null) {
throw new IllegalArgumentException("Cannot find entity trackers for " + entity +
throw new IllegalArgumentException("Cannot find entity trackers for " + entity +
(entity.isDead() ? " - entity is dead." : "."));
}
if (trackedPlayersField == null) {
@ -152,8 +152,6 @@ class EntityUtilities {
} catch (IllegalAccessException e) {
throw new FieldAccessException("Security limitation prevented access to the list of tracked players.", e);
} catch (InvocationTargetException e) {
throw new FieldAccessException("Exception occurred in Minecraft.", e);
}
}
@ -162,9 +160,9 @@ class EntityUtilities {
* @param world - world server.
* @param entityID - entity ID.
* @return The entity tracker entry.
* @throws FieldAccessException
* @throws FieldAccessException
*/
private static Object getEntityTrackerEntry(World world, int entityID) throws FieldAccessException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
private static Object getEntityTrackerEntry(World world, int entityID) throws FieldAccessException, IllegalArgumentException {
BukkitUnwrapper unwrapper = new BukkitUnwrapper();
Object worldServer = unwrapper.unwrapItem(world);
@ -183,9 +181,9 @@ class EntityUtilities {
if (trackedEntitiesField == null) {
@SuppressWarnings("rawtypes")
Set<Class> ignoredTypes = new HashSet<Class>();
Set<Class> ignoredTypes = new HashSet<Class>();
// Well, this is more difficult. But we're looking for a Minecraft object that is not
// Well, this is more difficult. But we're looking for a Minecraft object that is not
// created by the constructor(s).
for (Constructor<?> constructor : tracker.getClass().getConstructors()) {
for (Class<?> type : constructor.getParameterTypes()) {

View File

@ -441,7 +441,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
playerInjection.checkListener(listener);
}
if (hasSending)
incrementPhases(processPhase(sending, ConnectionSide.SERVER_SIDE));
incrementPhases(processPhase(sending));
// Handle receivers after senders
if (hasReceiving) {
@ -450,7 +450,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
enablePacketFilters(listener, receiving.getTypes());
}
if (hasReceiving)
incrementPhases(processPhase(receiving, ConnectionSide.CLIENT_SIDE));
incrementPhases(processPhase(receiving));
// Inform our injected hooks
packetListeners.add(listener);
@ -458,7 +458,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
}
}
private GamePhase processPhase(ListeningWhitelist whitelist, ConnectionSide side) {
private GamePhase processPhase(ListeningWhitelist whitelist) {
// Determine if this is a login packet, ensuring that gamephase detection is enabled
if (!whitelist.getGamePhase().hasLogin() &&
!whitelist.getOptions().contains(ListenerOptions.DISABLE_GAMEPHASE_DETECTION)) {
@ -571,11 +571,11 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
// Remove listeners and phases
if (sending != null && sending.isEnabled()) {
sendingRemoved = sendingListeners.removeListener(listener, sending);
decrementPhases(processPhase(sending, ConnectionSide.SERVER_SIDE));
decrementPhases(processPhase(sending));
}
if (receiving != null && receiving.isEnabled()) {
receivingRemoved = recievedListeners.removeListener(listener, receiving);
decrementPhases(processPhase(receiving, ConnectionSide.CLIENT_SIDE));
decrementPhases(processPhase(receiving));
}
// Remove hooks, if needed

View File

@ -225,7 +225,7 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
protected void encode(ChannelHandlerContext ctx, Object packet, ByteBuf output) throws Exception {
if (packet instanceof WirePacket) {
// Special case for wire format
ChannelInjector.this.encodeWirePacket(ctx, (WirePacket) packet, output);
ChannelInjector.this.encodeWirePacket((WirePacket) packet, output);
} else {
ChannelInjector.this.encode(ctx, packet, output);
}
@ -356,7 +356,7 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
*/
private boolean guessCompression(ChannelHandler handler) {
String className = handler != null ? handler.getClass().getCanonicalName() : null;
return className.contains("PacketCompressor") || className.contains("PacketDecompressor");
return className.contains("Compressor") || className.contains("Decompressor");
}
/**
@ -386,7 +386,7 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
super.exceptionCaught(ctx, cause);
}
protected void encodeWirePacket(ChannelHandlerContext ctx, WirePacket packet, ByteBuf output) throws Exception {
protected void encodeWirePacket(WirePacket packet, ByteBuf output) throws Exception {
packet.writeId(output);
packet.writeBytes(output);
}

View File

@ -160,19 +160,16 @@ public class PipelineProxy implements ChannelPipeline {
}
// We have to call the depreciated methods to properly implement the proxy
@SuppressWarnings("deprecation")
@Override
public ChannelFuture deregister() {
return pipeline.deregister();
}
@SuppressWarnings("deprecation")
@Override
public ChannelFuture deregister(ChannelPromise arg0) {
return pipeline.deregister(arg0);
}
@SuppressWarnings("deprecation")
@Override
public ChannelPipeline fireChannelUnregistered() {
pipeline.fireChannelUnregistered();

View File

@ -53,11 +53,12 @@ public class InterceptWritePacket {
this.modifierRest = new WritePacketModifier(reporter, false);
}
// TODO: PacketId should probably do something...
private Class<?> createProxyClass(int packetId) {
// Construct the proxy object
Enhancer ex = EnhancerFactory.getInstance().createEnhancer();
// Attempt to share callback filter
// Attempt to share callback filter
if (filter == null) {
filter = new CallbackFilter() {
@Override
@ -87,7 +88,7 @@ public class InterceptWritePacket {
if (proxyClass != null) {
// Check that we found the read method
if (!writePacketIntercepted) {
reporter.reportWarning(this,
reporter.reportWarning(this,
Report.newBuilder(REPORT_CANNOT_FIND_WRITE_PACKET_METHOD).
messageParam(MinecraftReflection.getPacketClass()));
}
@ -130,7 +131,7 @@ public class InterceptWritePacket {
return generated;
} catch (Exception e) {
reporter.reportWarning(this,
reporter.reportWarning(this,
Report.newBuilder(REPORT_CANNOT_CONSTRUCT_WRITE_PROXY).
messageParam(proxyClass));
return null;

View File

@ -11,8 +11,7 @@ import javax.annotation.Nonnull;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ConnectionSide;
import com.comphenix.protocol.events.NetworkMarker;
import com.google.common.io.ByteStreams;
import com.google.common.io.InputSupplier;
import com.google.common.io.ByteSource;
import com.google.common.primitives.Bytes;
/**
@ -39,27 +38,26 @@ public class LegacyNetworkMarker extends NetworkMarker {
return ByteBuffer.wrap(Bytes.concat(new byte[] { (byte) type.getLegacyId() }, buffer.array()));
}
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
protected DataInputStream addHeader(final DataInputStream input, final PacketType type) {
InputSupplier<InputStream> header = new InputSupplier<InputStream>() {
ByteSource header = new ByteSource() {
@Override
public InputStream getInput() throws IOException {
public InputStream openStream() throws IOException {
byte[] data = new byte[] { (byte) type.getLegacyId() };
return new ByteArrayInputStream(data);
}
};
InputSupplier<InputStream> data = new InputSupplier<InputStream>() {
ByteSource data = new ByteSource() {
@Override
public InputStream getInput() throws IOException {
public InputStream openStream() throws IOException {
return input;
}
};
// Combine them into a single stream
try {
return new DataInputStream(ByteStreams.join((InputSupplier) header, (InputSupplier) data).getInput());
return new DataInputStream(ByteSource.concat(header, data).openStream());
} catch (IOException e) {
throw new RuntimeException("Cannot add header.", e);
}

View File

@ -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
*/
@ -58,7 +58,7 @@ class NetworkFieldInjector extends PlayerInjector {
// Nothing
}
// After commit 336a4e00668fd2518c41242755ed6b3bdc3b0e6c (Update CraftBukkit to Minecraft 1.4.4.),
// After commit 336a4e00668fd2518c41242755ed6b3bdc3b0e6c (Update CraftBukkit to Minecraft 1.4.4.),
// CraftBukkit stopped redirecting map chunk and map chunk bulk packets to a separate queue.
// Thus, NetworkFieldInjector can safely handle every packet (though not perfectly - some packets
// will be slightly processed).
@ -77,9 +77,7 @@ class NetworkFieldInjector extends PlayerInjector {
// Determine if we're listening
private IntegerSet sendingFilters;
public NetworkFieldInjector(ErrorReporter reporter, Player player,
ListenerInvoker manager, IntegerSet sendingFilters) throws IllegalAccessException {
public NetworkFieldInjector(ErrorReporter reporter, Player player, ListenerInvoker manager, IntegerSet sendingFilters) {
super(reporter, player, manager);
this.sendingFilters = sendingFilters;
}
@ -178,6 +176,7 @@ class NetworkFieldInjector extends PlayerInjector {
}
}
@Override
@SuppressWarnings("unchecked")
protected void cleanHook() {
// Clean up

View File

@ -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
*/
@ -53,7 +53,7 @@ import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.utility.MinecraftVersion;
/**
* Represents a player hook into the NetServerHandler class.
* Represents a player hook into the NetServerHandler class.
*
* @author Kristian
*/
@ -79,10 +79,9 @@ class NetworkServerInjector extends PlayerInjector {
private final ObjectWriter writer = new ObjectWriter();
public NetworkServerInjector(
ErrorReporter reporter, Player player,
ListenerInvoker invoker, IntegerSet sendingFilters,
InjectedServerConnection serverInjection) throws IllegalAccessException {
ErrorReporter reporter, Player player,
ListenerInvoker invoker, IntegerSet sendingFilters,
InjectedServerConnection serverInjection) {
super(reporter, player, invoker);
this.sendingFilters = sendingFilters;
this.serverInjection = serverInjection;
@ -147,7 +146,7 @@ class NetworkServerInjector extends PlayerInjector {
}
throw new RuntimeException(
"Cannot hook player: Unable to find a valid constructor for the "
"Cannot hook player: Unable to find a valid constructor for the "
+ serverHandlerClass.getName() + " object.");
}
}
@ -177,7 +176,7 @@ class NetworkServerInjector extends PlayerInjector {
};
Callback noOpCallback = NoOp.INSTANCE;
// Share callback filter - that way, we avoid generating a new class for
// Share callback filter - that way, we avoid generating a new class for
// every logged in player.
if (callbackFilter == null) {
callbackFilter = new SendMethodFilter();
@ -197,7 +196,7 @@ class NetworkServerInjector extends PlayerInjector {
// Use the existing server proxy when we create one
if (proxyInstance != null && proxyInstance != serverHandler) {
serverInstances = DefaultInstances.fromArray(generator,
serverInstances = DefaultInstances.fromArray(generator,
ExistingGenerator.fromObjectArray(new Object[] { proxyInstance }));
} else {
serverInstances = DefaultInstances.fromArray(generator);
@ -288,7 +287,7 @@ class NetworkServerInjector extends PlayerInjector {
* @param value - the new value.
*/
private void setDisconnect(Object handler, boolean value) {
// Set it
// Set it
try {
// Load the field
if (disconnectField == null) {
@ -296,7 +295,7 @@ class NetworkServerInjector extends PlayerInjector {
}
FieldUtils.writeField(disconnectField, handler, value);
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException e) {
// Assume it's the first ...
if (disconnectField == null) {
disconnectField = FuzzyReflection.fromObject(handler).getFieldByType("disconnected", boolean.class);

View File

@ -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
*/
@ -62,7 +62,7 @@ public abstract class PlayerInjector implements SocketInjector {
public static final ReportType REPORT_CANNOT_CLOSE_SOCKET = new ReportType("Unable to close socket.");
public static final ReportType REPORT_ACCESS_DENIED_CLOSE_SOCKET = new ReportType("Insufficient permissions. Cannot close socket.");
public static final ReportType REPORT_DETECTED_CUSTOM_SERVER_HANDLER =
public static final ReportType REPORT_DETECTED_CUSTOM_SERVER_HANDLER =
new ReportType("Detected server handler proxy type by another plugin. Conflict may occur!");
public static final ReportType REPORT_CANNOT_PROXY_SERVER_HANDLER = new ReportType("Unable to load server handler from proxy type.");
@ -128,7 +128,7 @@ public abstract class PlayerInjector implements SocketInjector {
// Previous markers
protected Map<Object, NetworkMarker> queuedMarkers = new MapMaker().weakKeys().makeMap();
protected InterceptWritePacket writePacketInterceptor;
protected InterceptWritePacket writePacketInterceptor;
// Whether or not the injector has been cleaned
private boolean clean;
@ -137,7 +137,7 @@ public abstract class PlayerInjector implements SocketInjector {
boolean updateOnLogin;
volatile Player updatedPlayer;
public PlayerInjector(ErrorReporter reporter, Player player, ListenerInvoker invoker) throws IllegalAccessException {
public PlayerInjector(ErrorReporter reporter, Player player, ListenerInvoker invoker) {
this.reporter = reporter;
this.player = player;
this.invoker = invoker;
@ -167,7 +167,7 @@ public abstract class PlayerInjector implements SocketInjector {
initializePlayer((Player) injectionSource);
else if (MinecraftReflection.isLoginHandler(injectionSource))
initializeLogin(injectionSource);
else
else
throw new IllegalArgumentException("Cannot initialize a player hook using a " + injectionSource.getClass().getName());
}
@ -176,7 +176,7 @@ public abstract class PlayerInjector implements SocketInjector {
* @param player - the player to hook.
*/
public void initializePlayer(Player player) {
Object notchEntity = getEntityPlayer((Player) player);
Object notchEntity = getEntityPlayer(player);
// Save the player too
this.player = player;
@ -196,8 +196,8 @@ public abstract class PlayerInjector implements SocketInjector {
serverHandlerRef = new VolatileField(serverHandlerField, notchEntity);
serverHandler = serverHandlerRef.getValue();
// Next, get the network manager
if (networkManagerField == null)
// Next, get the network manager
if (networkManagerField == null)
networkManagerField = FuzzyReflection.fromObject(serverHandler).getFieldByType(
"networkManager", MinecraftReflection.getNetworkManagerClass());
initializeNetworkManager(networkManagerField, serverHandler);
@ -212,7 +212,7 @@ public abstract class PlayerInjector implements SocketInjector {
if (!hasInitialized) {
// Just in case
if (!MinecraftReflection.isLoginHandler(netLoginHandler))
throw new IllegalArgumentException("netLoginHandler (" + netLoginHandler + ") is not a " +
throw new IllegalArgumentException("netLoginHandler (" + netLoginHandler + ") is not a " +
MinecraftReflection.getNetLoginHandlerName());
hasInitialized = true;

View File

@ -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
*/
@ -65,7 +65,7 @@ public class PrettyPrinter {
* Print the content of an object.
* @param object - the object to serialize.
* @return String representation of the class.
* @throws IllegalAccessException
* @throws IllegalAccessException
*/
public static String printObject(Object object) throws IllegalAccessException {
if (object == null)
@ -79,7 +79,7 @@ public class PrettyPrinter {
* @param object - the object to serialize.
* @param stop - superclass that will stop the process.
* @return String representation of the class.
* @throws IllegalAccessException
* @throws IllegalAccessException
*/
public static String printObject(Object object, Class<?> start, Class<?> stop) throws IllegalAccessException {
if (object == null)
@ -93,7 +93,7 @@ public class PrettyPrinter {
* @param object - the object to serialize.
* @param stop - superclass that will stop the process.
* @return String representation of the class.
* @throws IllegalAccessException
* @throws IllegalAccessException
*/
public static String printObject(Object object, Class<?> start, Class<?> stop, int hierachyDepth) throws IllegalAccessException {
return printObject(object, start, stop, hierachyDepth, ObjectPrinter.DEFAULT);
@ -106,7 +106,7 @@ public class PrettyPrinter {
* @param hierachyDepth - maximum recursion level.
* @param printer - a generic object printer.
* @return String representation of the class.
* @throws IllegalAccessException
* @throws IllegalAccessException
*/
public static String printObject(Object object, Class<?> start, Class<?> stop, int hierachyDepth, ObjectPrinter printer) throws IllegalAccessException {
if (object == null)
@ -124,14 +124,14 @@ public class PrettyPrinter {
}
@SuppressWarnings("rawtypes")
private static void printIterables(StringBuilder output, Iterable iterable, Class<?> current, Class<?> stop,
Set<Object> previous, int hierachyIndex, ObjectPrinter printer) throws IllegalAccessException {
private static void printIterables(StringBuilder output, Iterable iterable, Class<?> stop,
Set<Object> previous, int hierachyIndex, ObjectPrinter printer) throws IllegalAccessException {
boolean first = true;
output.append("(");
for (Object value : iterable) {
if (first)
if (first)
first = false;
else
output.append(", ");
@ -153,8 +153,8 @@ public class PrettyPrinter {
* @param hierachyIndex - hierachy index.
* @throws IllegalAccessException If any reflection went wrong.
*/
private static void printMap(StringBuilder output, Map<Object, Object> map, Class<?> current, Class<?> stop,
Set<Object> previous, int hierachyIndex, ObjectPrinter printer) throws IllegalAccessException {
private static void printMap(StringBuilder output, Map<Object, Object> map, Class<?> current, Class<?> stop,
Set<Object> previous, int hierachyIndex, ObjectPrinter printer) throws IllegalAccessException {
boolean first = true;
output.append("[");
@ -173,8 +173,8 @@ public class PrettyPrinter {
output.append("]");
}
private static void printArray(StringBuilder output, Object array, Class<?> current, Class<?> stop,
Set<Object> previous, int hierachyIndex, ObjectPrinter printer) throws IllegalAccessException {
private static void printArray(StringBuilder output, Object array, Class<?> current, Class<?> stop,
Set<Object> previous, int hierachyIndex, ObjectPrinter printer) throws IllegalAccessException {
Class<?> component = current.getComponentType();
boolean first = true;
@ -184,7 +184,7 @@ public class PrettyPrinter {
output.append("[");
for (int i = 0; i < Array.getLength(array); i++) {
if (first)
if (first)
first = false;
else
output.append(", ");
@ -205,8 +205,8 @@ public class PrettyPrinter {
}
// Internal recursion method
private static void printObject(StringBuilder output, Object object, Class<?> current, Class<?> stop,
Set<Object> previous, int hierachyIndex, boolean first,
private static void printObject(StringBuilder output, Object object, Class<?> current, Class<?> stop,
Set<Object> previous, int hierachyIndex, boolean first,
ObjectPrinter printer) throws IllegalAccessException {
// See if we're supposed to skip this class
@ -247,14 +247,14 @@ public class PrettyPrinter {
printObject(output, object, current.getSuperclass(), stop, previous, hierachyIndex, first, printer);
}
private static void printValue(StringBuilder output, Object value, Class<?> stop,
private static void printValue(StringBuilder output, Object value, Class<?> stop,
Set<Object> previous, int hierachyIndex, ObjectPrinter printer) throws IllegalAccessException {
// Handle the NULL case
printValue(output, value, value != null ? value.getClass() : null, stop, previous, hierachyIndex, printer);
}
@SuppressWarnings({"rawtypes", "unchecked"})
private static void printValue(StringBuilder output, Object value, Class<?> type,
private static void printValue(StringBuilder output, Object value, Class<?> type,
Class<?> stop, Set<Object> previous, int hierachyIndex,
ObjectPrinter printer) throws IllegalAccessException {
@ -270,7 +270,7 @@ public class PrettyPrinter {
} else if (type.isArray()) {
printArray(output, value, type, stop, previous, hierachyIndex, printer);
} else if (Iterable.class.isAssignableFrom(type)) {
printIterables(output, (Iterable) value, type, stop, previous, hierachyIndex, printer);
printIterables(output, (Iterable) value, stop, previous, hierachyIndex, printer);
} else if (Map.class.isAssignableFrom(type)) {
printMap(output, (Map<Object, Object>) value, type, stop, previous, hierachyIndex, printer);
} else if (ClassLoader.class.isAssignableFrom(type) || previous.contains(value)) {

View File

@ -12,7 +12,6 @@ import com.comphenix.protocol.timing.TimedListenerManager.ListenerType;
import com.google.common.base.Charsets;
import com.google.common.base.Strings;
import com.google.common.collect.Sets;
import com.google.common.io.Closer;
import com.google.common.io.Files;
public class TimingReportGenerator {
@ -29,14 +28,13 @@ public class TimingReportGenerator {
private static final String SUM_MAIN_THREAD = " => Time on main thread: %.6f ms" + NEWLINE;
public void saveTo(File destination, TimedListenerManager manager) throws IOException {
Closer closer = Closer.create();
BufferedWriter writer = null;
Date started = manager.getStarted();
Date stopped = manager.getStopped();
long seconds = Math.abs((stopped.getTime() - started.getTime()) / 1000);
try {
writer = closer.register(Files.newWriter(destination, Charsets.UTF_8));
writer = Files.newWriter(destination, Charsets.UTF_8);
// Write some timing information
writer.write(String.format(META_STARTED, started));
@ -62,7 +60,9 @@ public class TimingReportGenerator {
writer.write(NEWLINE);
}
} finally {
closer.close();
if (writer != null) {
writer.flush();
}
}
}

View File

@ -104,12 +104,12 @@ public class StreamSerializer {
if (READ_ITEM_METHOD == null) {
READ_ITEM_METHOD = Accessors.getMethodAccessor(
FuzzyReflection.fromClass(MinecraftReflection.getPacketDataSerializerClass(), true).
getMethodByParameters("i", /* readItemStack */
getMethodByParameters("readItemStack", /* i */
MinecraftReflection.getItemStackClass(), new Class<?>[0])
);
}
nmsItem = READ_ITEM_METHOD.invoke(ByteBufAdapter.packetReader(input));
} else {
if (READ_ITEM_METHOD == null) {
READ_ITEM_METHOD = Accessors.getMethodAccessor(
@ -121,6 +121,7 @@ public class StreamSerializer {
build())
);
}
nmsItem = READ_ITEM_METHOD.invoke(null, input);
}
@ -147,12 +148,12 @@ public class StreamSerializer {
if (READ_NBT_METHOD == null) {
READ_NBT_METHOD = Accessors.getMethodAccessor(
FuzzyReflection.fromClass(MinecraftReflection.getPacketDataSerializerClass(), true).
getMethodByParameters("h", /* readNbtCompound */
getMethodByParameters("readNbtCompound", /* h */
MinecraftReflection.getNBTCompoundClass(), new Class<?>[0])
);
}
nmsCompound = READ_NBT_METHOD.invoke(ByteBufAdapter.packetReader(input));
} else {
if (READ_NBT_METHOD == null) {
READ_NBT_METHOD = Accessors.getMethodAccessor(
@ -200,12 +201,12 @@ public class StreamSerializer {
if (READ_STRING_METHOD == null) {
READ_STRING_METHOD = Accessors.getMethodAccessor(
FuzzyReflection.fromClass(MinecraftReflection.getPacketDataSerializerClass(), true).
getMethodByParameters("c", /* readString */
getMethodByParameters("readString", /* c */
String.class, new Class<?>[] { int.class })
);
}
return (String) READ_STRING_METHOD.invoke(ByteBufAdapter.packetReader(input), maximumLength);
} else {
if (READ_STRING_METHOD == null) {
READ_STRING_METHOD = Accessors.getMethodAccessor(
@ -218,6 +219,7 @@ public class StreamSerializer {
build())
);
}
return (String) READ_STRING_METHOD.invoke(null, input, maximumLength);
}
}
@ -259,12 +261,12 @@ public class StreamSerializer {
if (WRITE_ITEM_METHOD == null) {
WRITE_ITEM_METHOD = Accessors.getMethodAccessor(
FuzzyReflection.fromClass(MinecraftReflection.getPacketDataSerializerClass(), true).
getMethodByParameters("a", /* writeStack */
getMethodByParameters("writeStack", /* a */
MinecraftReflection.getItemStackClass())
);
}
WRITE_ITEM_METHOD.invoke(ByteBufAdapter.packetWriter(output), nmsItem);
} else {
if (WRITE_ITEM_METHOD == null)
WRITE_ITEM_METHOD = Accessors.getMethodAccessor(
@ -275,6 +277,7 @@ public class StreamSerializer {
parameterDerivedOf(DataOutput.class, 1).
build())
);
WRITE_ITEM_METHOD.invoke(null, nmsItem, output);
}
}
@ -299,12 +302,12 @@ public class StreamSerializer {
if (WRITE_NBT_METHOD == null) {
WRITE_NBT_METHOD = Accessors.getMethodAccessor(
FuzzyReflection.fromClass(MinecraftReflection.getPacketDataSerializerClass(), true).
getMethodByParameters("a", /* writeNbtCompound */
getMethodByParameters("writeNbtCompound", /* a */
MinecraftReflection.getNBTCompoundClass())
);
}
WRITE_NBT_METHOD.invoke(ByteBufAdapter.packetWriter(output), handle);
} else {
if (WRITE_NBT_METHOD == null) {
WRITE_NBT_METHOD = Accessors.getMethodAccessor(
@ -317,6 +320,7 @@ public class StreamSerializer {
build())
);
}
WRITE_NBT_METHOD.invoke(null, handle, output);
}
}
@ -339,12 +343,12 @@ public class StreamSerializer {
if (WRITE_STRING_METHOD == null) {
WRITE_STRING_METHOD = Accessors.getMethodAccessor(
FuzzyReflection.fromClass(MinecraftReflection.getPacketDataSerializerClass(), true).
getMethodByParameters("a", /* writeString */
getMethodByParameters("writeString", /* a */
String.class)
);
}
WRITE_STRING_METHOD.invoke(ByteBufAdapter.packetWriter(output), text);
} else {
if (WRITE_STRING_METHOD == null) {
WRITE_STRING_METHOD = Accessors.getMethodAccessor(
@ -357,6 +361,7 @@ public class StreamSerializer {
build())
);
}
WRITE_STRING_METHOD.invoke(null, text, output);
}
}
@ -371,12 +376,12 @@ public class StreamSerializer {
* @throws IOException If the operation fails due to reflection problems.
*/
public String serializeItemStack(ItemStack stack) throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DataOutputStream dataOutput = new DataOutputStream(outputStream);
serializeItemStack(dataOutput, stack);
// Serialize that array
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DataOutputStream dataOutput = new DataOutputStream(outputStream);
serializeItemStack(dataOutput, stack);
// Serialize that array
return Base64Coder.encodeLines(outputStream.toByteArray());
}
}

View File

@ -25,9 +25,9 @@ public class WrappedChatComponent extends AbstractWrapper {
FuzzyReflection fuzzy = FuzzyReflection.fromClass(SERIALIZER);
// Retrieve the correct methods
SERIALIZE_COMPONENT = Accessors.getMethodAccessor(fuzzy.getMethodByParameters("a", /* serialize */
SERIALIZE_COMPONENT = Accessors.getMethodAccessor(fuzzy.getMethodByParameters("serialize", /* a */
String.class, new Class<?>[] { COMPONENT }));
DESERIALIZE_COMPONENT = Accessors.getMethodAccessor(fuzzy.getMethodByParameters("a", /* serialize */
DESERIALIZE_COMPONENT = Accessors.getMethodAccessor(fuzzy.getMethodByParameters("deserialize", /* a */
COMPONENT, new Class<?>[] { String.class }));
// Get a component from a standard Minecraft message