Archiviert
13
0

Remove unused code, revert some unnecessary changes

Dieser Commit ist enthalten in:
Dan Mulloy 2015-01-17 19:23:51 -05:00
Ursprung 5e5eff5e5f
Commit 3dda5c6a0a
17 geänderte Dateien mit 140 neuen und 148 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * 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 * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * 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; * 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. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * 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; * 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 * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -81,7 +81,7 @@ public class AsyncFilterManager implements AsynchronousManager {
/** /**
* Initialize a asynchronous filter manager. * Initialize a asynchronous filter manager.
* <p> * <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 reporter - desired error reporter.
* @param scheduler - task scheduler. * @param scheduler - task scheduler.
*/ */
@ -148,7 +148,7 @@ public class AsyncFilterManager implements AsynchronousManager {
ImmutableSet.Builder<PacketListener> builder = ImmutableSet.builder(); ImmutableSet.Builder<PacketListener> builder = ImmutableSet.builder();
// Add every asynchronous packet listener // Add every asynchronous packet listener
for (PrioritizedListener<AsyncListenerHandler> handler : for (PrioritizedListener<AsyncListenerHandler> handler :
Iterables.concat(serverProcessingQueue.values(), clientProcessingQueue.values())) { Iterables.concat(serverProcessingQueue.values(), clientProcessingQueue.values())) {
builder.add(handler.getListener().getAsyncListener()); builder.add(handler.getListener().getAsyncListener());
} }
@ -221,7 +221,7 @@ public class AsyncFilterManager implements AsynchronousManager {
if (listener == null) if (listener == null)
throw new IllegalArgumentException("listener cannot be NULL."); throw new IllegalArgumentException("listener cannot be NULL.");
AsyncListenerHandler handler = AsyncListenerHandler handler =
findHandler(serverProcessingQueue, listener.getSendingWhitelist(), listener); findHandler(serverProcessingQueue, listener.getSendingWhitelist(), listener);
if (handler == null) { if (handler == null) {
@ -232,7 +232,7 @@ public class AsyncFilterManager implements AsynchronousManager {
// Search for the first correct handler // Search for the first correct handler
private AsyncListenerHandler findHandler(PacketProcessingQueue queue, ListeningWhitelist search, PacketListener target) { private AsyncListenerHandler findHandler(PacketProcessingQueue queue, ListeningWhitelist search, PacketListener target) {
if (ListeningWhitelist.isEmpty(search)) if (ListeningWhitelist.isEmpty(search))
return null; return null;
for (PacketType type : search.getTypes()) { for (PacketType type : search.getTypes()) {
@ -250,7 +250,7 @@ public class AsyncFilterManager implements AsynchronousManager {
if (handler == null) if (handler == null)
throw new IllegalArgumentException("listenerToken cannot be NULL"); throw new IllegalArgumentException("listenerToken cannot be NULL");
handler.cancel(); handler.cancel();
} }
// Called by AsyncListenerHandler // Called by AsyncListenerHandler
@ -295,7 +295,7 @@ public class AsyncFilterManager implements AsynchronousManager {
private void unregisterAsyncHandlers(PacketProcessingQueue processingQueue, Plugin plugin) { private void unregisterAsyncHandlers(PacketProcessingQueue processingQueue, Plugin plugin) {
// Iterate through every packet listener // Iterate through every packet listener
for (PrioritizedListener<AsyncListenerHandler> listener : processingQueue.values()) { for (PrioritizedListener<AsyncListenerHandler> listener : processingQueue.values()) {
// Remove the listener // Remove the listener
if (Objects.equal(listener.getListener().getPlugin(), plugin)) { if (Objects.equal(listener.getListener().getPlugin(), plugin)) {
unregisterAsyncHandler(listener.getListener()); unregisterAsyncHandler(listener.getListener());
@ -362,7 +362,7 @@ public class AsyncFilterManager implements AsynchronousManager {
* @return Asynchronous marker. * @return Asynchronous marker.
*/ */
public AsyncMarker createAsyncMarker() { 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. * @param timeoutDelta - how long (in ms) until the packet expire.
* @return An async marker. * @return An async marker.
*/ */
public AsyncMarker createAsyncMarker(long sendingDelta, long timeoutDelta) { public AsyncMarker createAsyncMarker(long timeoutDelta) {
return createAsyncMarker(sendingDelta, timeoutDelta, return createAsyncMarker(timeoutDelta, currentSendingIndex.incrementAndGet());
currentSendingIndex.incrementAndGet(), System.currentTimeMillis());
} }
// Helper method // Helper method
private AsyncMarker createAsyncMarker(long sendingDelta, long timeoutDelta, long sendingIndex, long currentTime) { private AsyncMarker createAsyncMarker(long timeoutDelta, long sendingIndex) {
return new AsyncMarker(manager, sendingIndex, sendingDelta, System.currentTimeMillis(), timeoutDelta); return new AsyncMarker(manager, sendingIndex, System.currentTimeMillis(), timeoutDelta);
} }
@Override @Override

Datei anzeigen

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

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * 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 * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * 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; * 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. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * 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; * 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 * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -53,7 +53,7 @@ class EntityUtilities {
private static Method scanPlayersMethod; 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: * version of the following:
* *
* @SuppressWarnings("unchecked") * @SuppressWarnings("unchecked")
@ -133,7 +133,7 @@ class EntityUtilities {
Object trackerEntry = getEntityTrackerEntry(entity.getWorld(), entity.getEntityId()); Object trackerEntry = getEntityTrackerEntry(entity.getWorld(), entity.getEntityId());
if (trackerEntry == null) { 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." : ".")); (entity.isDead() ? " - entity is dead." : "."));
} }
if (trackedPlayersField == null) { if (trackedPlayersField == null) {
@ -152,8 +152,6 @@ class EntityUtilities {
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
throw new FieldAccessException("Security limitation prevented access to the list of tracked players.", 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 world - world server.
* @param entityID - entity ID. * @param entityID - entity ID.
* @return The entity tracker entry. * @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(); BukkitUnwrapper unwrapper = new BukkitUnwrapper();
Object worldServer = unwrapper.unwrapItem(world); Object worldServer = unwrapper.unwrapItem(world);
@ -183,9 +181,9 @@ class EntityUtilities {
if (trackedEntitiesField == null) { if (trackedEntitiesField == null) {
@SuppressWarnings("rawtypes") @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). // created by the constructor(s).
for (Constructor<?> constructor : tracker.getClass().getConstructors()) { for (Constructor<?> constructor : tracker.getClass().getConstructors()) {
for (Class<?> type : constructor.getParameterTypes()) { for (Class<?> type : constructor.getParameterTypes()) {

Datei anzeigen

@ -441,7 +441,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
playerInjection.checkListener(listener); playerInjection.checkListener(listener);
} }
if (hasSending) if (hasSending)
incrementPhases(processPhase(sending, ConnectionSide.SERVER_SIDE)); incrementPhases(processPhase(sending));
// Handle receivers after senders // Handle receivers after senders
if (hasReceiving) { if (hasReceiving) {
@ -450,7 +450,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
enablePacketFilters(listener, receiving.getTypes()); enablePacketFilters(listener, receiving.getTypes());
} }
if (hasReceiving) if (hasReceiving)
incrementPhases(processPhase(receiving, ConnectionSide.CLIENT_SIDE)); incrementPhases(processPhase(receiving));
// Inform our injected hooks // Inform our injected hooks
packetListeners.add(listener); 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 // 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)) { !whitelist.getOptions().contains(ListenerOptions.DISABLE_GAMEPHASE_DETECTION)) {
@ -571,11 +571,11 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
// Remove listeners and phases // Remove listeners and phases
if (sending != null && sending.isEnabled()) { if (sending != null && sending.isEnabled()) {
sendingRemoved = sendingListeners.removeListener(listener, sending); sendingRemoved = sendingListeners.removeListener(listener, sending);
decrementPhases(processPhase(sending, ConnectionSide.SERVER_SIDE)); decrementPhases(processPhase(sending));
} }
if (receiving != null && receiving.isEnabled()) { if (receiving != null && receiving.isEnabled()) {
receivingRemoved = recievedListeners.removeListener(listener, receiving); receivingRemoved = recievedListeners.removeListener(listener, receiving);
decrementPhases(processPhase(receiving, ConnectionSide.CLIENT_SIDE)); decrementPhases(processPhase(receiving));
} }
// Remove hooks, if needed // Remove hooks, if needed

Datei anzeigen

@ -225,7 +225,7 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
protected void encode(ChannelHandlerContext ctx, Object packet, ByteBuf output) throws Exception { protected void encode(ChannelHandlerContext ctx, Object packet, ByteBuf output) throws Exception {
if (packet instanceof WirePacket) { if (packet instanceof WirePacket) {
// Special case for wire format // Special case for wire format
ChannelInjector.this.encodeWirePacket(ctx, (WirePacket) packet, output); ChannelInjector.this.encodeWirePacket((WirePacket) packet, output);
} else { } else {
ChannelInjector.this.encode(ctx, packet, output); ChannelInjector.this.encode(ctx, packet, output);
} }
@ -356,7 +356,7 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
*/ */
private boolean guessCompression(ChannelHandler handler) { private boolean guessCompression(ChannelHandler handler) {
String className = handler != null ? handler.getClass().getCanonicalName() : null; 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); 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.writeId(output);
packet.writeBytes(output); packet.writeBytes(output);
} }

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * 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 * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * 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; * 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. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * 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; * 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 * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -58,7 +58,7 @@ class NetworkFieldInjector extends PlayerInjector {
// Nothing // 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. // 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 // Thus, NetworkFieldInjector can safely handle every packet (though not perfectly - some packets
// will be slightly processed). // will be slightly processed).
@ -77,9 +77,7 @@ class NetworkFieldInjector extends PlayerInjector {
// Determine if we're listening // Determine if we're listening
private IntegerSet sendingFilters; private IntegerSet sendingFilters;
public NetworkFieldInjector(ErrorReporter reporter, Player player, public NetworkFieldInjector(ErrorReporter reporter, Player player, ListenerInvoker manager, IntegerSet sendingFilters) {
ListenerInvoker manager, IntegerSet sendingFilters) throws IllegalAccessException {
super(reporter, player, manager); super(reporter, player, manager);
this.sendingFilters = sendingFilters; this.sendingFilters = sendingFilters;
} }
@ -178,6 +176,7 @@ class NetworkFieldInjector extends PlayerInjector {
} }
} }
@Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected void cleanHook() { protected void cleanHook() {
// Clean up // Clean up

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * 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 * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * 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; * 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. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * 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; * 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 * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -53,7 +53,7 @@ import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.utility.MinecraftVersion; import com.comphenix.protocol.utility.MinecraftVersion;
/** /**
* Represents a player hook into the NetServerHandler class. * Represents a player hook into the NetServerHandler class.
* *
* @author Kristian * @author Kristian
*/ */
@ -79,10 +79,9 @@ class NetworkServerInjector extends PlayerInjector {
private final ObjectWriter writer = new ObjectWriter(); private final ObjectWriter writer = new ObjectWriter();
public NetworkServerInjector( public NetworkServerInjector(
ErrorReporter reporter, Player player, ErrorReporter reporter, Player player,
ListenerInvoker invoker, IntegerSet sendingFilters, ListenerInvoker invoker, IntegerSet sendingFilters,
InjectedServerConnection serverInjection) throws IllegalAccessException { InjectedServerConnection serverInjection) {
super(reporter, player, invoker); super(reporter, player, invoker);
this.sendingFilters = sendingFilters; this.sendingFilters = sendingFilters;
this.serverInjection = serverInjection; this.serverInjection = serverInjection;
@ -147,7 +146,7 @@ class NetworkServerInjector extends PlayerInjector {
} }
throw new RuntimeException( 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."); + serverHandlerClass.getName() + " object.");
} }
} }
@ -177,7 +176,7 @@ class NetworkServerInjector extends PlayerInjector {
}; };
Callback noOpCallback = NoOp.INSTANCE; 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. // every logged in player.
if (callbackFilter == null) { if (callbackFilter == null) {
callbackFilter = new SendMethodFilter(); callbackFilter = new SendMethodFilter();
@ -197,7 +196,7 @@ class NetworkServerInjector extends PlayerInjector {
// Use the existing server proxy when we create one // Use the existing server proxy when we create one
if (proxyInstance != null && proxyInstance != serverHandler) { if (proxyInstance != null && proxyInstance != serverHandler) {
serverInstances = DefaultInstances.fromArray(generator, serverInstances = DefaultInstances.fromArray(generator,
ExistingGenerator.fromObjectArray(new Object[] { proxyInstance })); ExistingGenerator.fromObjectArray(new Object[] { proxyInstance }));
} else { } else {
serverInstances = DefaultInstances.fromArray(generator); serverInstances = DefaultInstances.fromArray(generator);
@ -288,7 +287,7 @@ class NetworkServerInjector extends PlayerInjector {
* @param value - the new value. * @param value - the new value.
*/ */
private void setDisconnect(Object handler, boolean value) { private void setDisconnect(Object handler, boolean value) {
// Set it // Set it
try { try {
// Load the field // Load the field
if (disconnectField == null) { if (disconnectField == null) {
@ -296,7 +295,7 @@ class NetworkServerInjector extends PlayerInjector {
} }
FieldUtils.writeField(disconnectField, handler, value); FieldUtils.writeField(disconnectField, handler, value);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// Assume it's the first ... // Assume it's the first ...
if (disconnectField == null) { if (disconnectField == null) {
disconnectField = FuzzyReflection.fromObject(handler).getFieldByType("disconnected", boolean.class); disconnectField = FuzzyReflection.fromObject(handler).getFieldByType("disconnected", boolean.class);

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * 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 * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * 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; * 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. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * 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; * 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 * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 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_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_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!"); 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."); 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 // Previous markers
protected Map<Object, NetworkMarker> queuedMarkers = new MapMaker().weakKeys().makeMap(); protected Map<Object, NetworkMarker> queuedMarkers = new MapMaker().weakKeys().makeMap();
protected InterceptWritePacket writePacketInterceptor; protected InterceptWritePacket writePacketInterceptor;
// Whether or not the injector has been cleaned // Whether or not the injector has been cleaned
private boolean clean; private boolean clean;
@ -137,7 +137,7 @@ public abstract class PlayerInjector implements SocketInjector {
boolean updateOnLogin; boolean updateOnLogin;
volatile Player updatedPlayer; 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.reporter = reporter;
this.player = player; this.player = player;
this.invoker = invoker; this.invoker = invoker;
@ -167,7 +167,7 @@ public abstract class PlayerInjector implements SocketInjector {
initializePlayer((Player) injectionSource); initializePlayer((Player) injectionSource);
else if (MinecraftReflection.isLoginHandler(injectionSource)) else if (MinecraftReflection.isLoginHandler(injectionSource))
initializeLogin(injectionSource); initializeLogin(injectionSource);
else else
throw new IllegalArgumentException("Cannot initialize a player hook using a " + injectionSource.getClass().getName()); 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. * @param player - the player to hook.
*/ */
public void initializePlayer(Player player) { public void initializePlayer(Player player) {
Object notchEntity = getEntityPlayer((Player) player); Object notchEntity = getEntityPlayer(player);
// Save the player too // Save the player too
this.player = player; this.player = player;
@ -196,8 +196,8 @@ public abstract class PlayerInjector implements SocketInjector {
serverHandlerRef = new VolatileField(serverHandlerField, notchEntity); serverHandlerRef = new VolatileField(serverHandlerField, notchEntity);
serverHandler = serverHandlerRef.getValue(); serverHandler = serverHandlerRef.getValue();
// Next, get the network manager // Next, get the network manager
if (networkManagerField == null) if (networkManagerField == null)
networkManagerField = FuzzyReflection.fromObject(serverHandler).getFieldByType( networkManagerField = FuzzyReflection.fromObject(serverHandler).getFieldByType(
"networkManager", MinecraftReflection.getNetworkManagerClass()); "networkManager", MinecraftReflection.getNetworkManagerClass());
initializeNetworkManager(networkManagerField, serverHandler); initializeNetworkManager(networkManagerField, serverHandler);
@ -212,7 +212,7 @@ public abstract class PlayerInjector implements SocketInjector {
if (!hasInitialized) { if (!hasInitialized) {
// Just in case // Just in case
if (!MinecraftReflection.isLoginHandler(netLoginHandler)) if (!MinecraftReflection.isLoginHandler(netLoginHandler))
throw new IllegalArgumentException("netLoginHandler (" + netLoginHandler + ") is not a " + throw new IllegalArgumentException("netLoginHandler (" + netLoginHandler + ") is not a " +
MinecraftReflection.getNetLoginHandlerName()); MinecraftReflection.getNetLoginHandlerName());
hasInitialized = true; hasInitialized = true;

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * 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 * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * 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; * 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. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * 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; * 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 * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -65,7 +65,7 @@ public class PrettyPrinter {
* Print the content of an object. * Print the content of an object.
* @param object - the object to serialize. * @param object - the object to serialize.
* @return String representation of the class. * @return String representation of the class.
* @throws IllegalAccessException * @throws IllegalAccessException
*/ */
public static String printObject(Object object) throws IllegalAccessException { public static String printObject(Object object) throws IllegalAccessException {
if (object == null) if (object == null)
@ -79,7 +79,7 @@ public class PrettyPrinter {
* @param object - the object to serialize. * @param object - the object to serialize.
* @param stop - superclass that will stop the process. * @param stop - superclass that will stop the process.
* @return String representation of the class. * @return String representation of the class.
* @throws IllegalAccessException * @throws IllegalAccessException
*/ */
public static String printObject(Object object, Class<?> start, Class<?> stop) throws IllegalAccessException { public static String printObject(Object object, Class<?> start, Class<?> stop) throws IllegalAccessException {
if (object == null) if (object == null)
@ -93,7 +93,7 @@ public class PrettyPrinter {
* @param object - the object to serialize. * @param object - the object to serialize.
* @param stop - superclass that will stop the process. * @param stop - superclass that will stop the process.
* @return String representation of the class. * @return String representation of the class.
* @throws IllegalAccessException * @throws IllegalAccessException
*/ */
public static String printObject(Object object, Class<?> start, Class<?> stop, int hierachyDepth) throws IllegalAccessException { public static String printObject(Object object, Class<?> start, Class<?> stop, int hierachyDepth) throws IllegalAccessException {
return printObject(object, start, stop, hierachyDepth, ObjectPrinter.DEFAULT); return printObject(object, start, stop, hierachyDepth, ObjectPrinter.DEFAULT);
@ -106,7 +106,7 @@ public class PrettyPrinter {
* @param hierachyDepth - maximum recursion level. * @param hierachyDepth - maximum recursion level.
* @param printer - a generic object printer. * @param printer - a generic object printer.
* @return String representation of the class. * @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 { public static String printObject(Object object, Class<?> start, Class<?> stop, int hierachyDepth, ObjectPrinter printer) throws IllegalAccessException {
if (object == null) if (object == null)
@ -124,14 +124,14 @@ public class PrettyPrinter {
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private static void printIterables(StringBuilder output, Iterable iterable, Class<?> current, Class<?> stop, private static void printIterables(StringBuilder output, Iterable iterable, Class<?> stop,
Set<Object> previous, int hierachyIndex, ObjectPrinter printer) throws IllegalAccessException { Set<Object> previous, int hierachyIndex, ObjectPrinter printer) throws IllegalAccessException {
boolean first = true; boolean first = true;
output.append("("); output.append("(");
for (Object value : iterable) { for (Object value : iterable) {
if (first) if (first)
first = false; first = false;
else else
output.append(", "); output.append(", ");
@ -153,8 +153,8 @@ public class PrettyPrinter {
* @param hierachyIndex - hierachy index. * @param hierachyIndex - hierachy index.
* @throws IllegalAccessException If any reflection went wrong. * @throws IllegalAccessException If any reflection went wrong.
*/ */
private static void printMap(StringBuilder output, Map<Object, Object> map, Class<?> current, Class<?> stop, private static void printMap(StringBuilder output, Map<Object, Object> map, Class<?> current, Class<?> stop,
Set<Object> previous, int hierachyIndex, ObjectPrinter printer) throws IllegalAccessException { Set<Object> previous, int hierachyIndex, ObjectPrinter printer) throws IllegalAccessException {
boolean first = true; boolean first = true;
output.append("["); output.append("[");
@ -173,8 +173,8 @@ public class PrettyPrinter {
output.append("]"); output.append("]");
} }
private static void printArray(StringBuilder output, Object array, Class<?> current, Class<?> stop, private static void printArray(StringBuilder output, Object array, Class<?> current, Class<?> stop,
Set<Object> previous, int hierachyIndex, ObjectPrinter printer) throws IllegalAccessException { Set<Object> previous, int hierachyIndex, ObjectPrinter printer) throws IllegalAccessException {
Class<?> component = current.getComponentType(); Class<?> component = current.getComponentType();
boolean first = true; boolean first = true;
@ -184,7 +184,7 @@ public class PrettyPrinter {
output.append("["); output.append("[");
for (int i = 0; i < Array.getLength(array); i++) { for (int i = 0; i < Array.getLength(array); i++) {
if (first) if (first)
first = false; first = false;
else else
output.append(", "); output.append(", ");
@ -205,8 +205,8 @@ public class PrettyPrinter {
} }
// Internal recursion method // Internal recursion method
private static void printObject(StringBuilder output, Object object, Class<?> current, Class<?> stop, private static void printObject(StringBuilder output, Object object, Class<?> current, Class<?> stop,
Set<Object> previous, int hierachyIndex, boolean first, Set<Object> previous, int hierachyIndex, boolean first,
ObjectPrinter printer) throws IllegalAccessException { ObjectPrinter printer) throws IllegalAccessException {
// See if we're supposed to skip this class // 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); 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 { Set<Object> previous, int hierachyIndex, ObjectPrinter printer) throws IllegalAccessException {
// Handle the NULL case // Handle the NULL case
printValue(output, value, value != null ? value.getClass() : null, stop, previous, hierachyIndex, printer); printValue(output, value, value != null ? value.getClass() : null, stop, previous, hierachyIndex, printer);
} }
@SuppressWarnings({"rawtypes", "unchecked"}) @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, Class<?> stop, Set<Object> previous, int hierachyIndex,
ObjectPrinter printer) throws IllegalAccessException { ObjectPrinter printer) throws IllegalAccessException {
@ -270,7 +270,7 @@ public class PrettyPrinter {
} else if (type.isArray()) { } else if (type.isArray()) {
printArray(output, value, type, stop, previous, hierachyIndex, printer); printArray(output, value, type, stop, previous, hierachyIndex, printer);
} else if (Iterable.class.isAssignableFrom(type)) { } 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)) { } else if (Map.class.isAssignableFrom(type)) {
printMap(output, (Map<Object, Object>) value, type, stop, previous, hierachyIndex, printer); printMap(output, (Map<Object, Object>) value, type, stop, previous, hierachyIndex, printer);
} else if (ClassLoader.class.isAssignableFrom(type) || previous.contains(value)) { } else if (ClassLoader.class.isAssignableFrom(type) || previous.contains(value)) {

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -25,9 +25,9 @@ public class WrappedChatComponent extends AbstractWrapper {
FuzzyReflection fuzzy = FuzzyReflection.fromClass(SERIALIZER); FuzzyReflection fuzzy = FuzzyReflection.fromClass(SERIALIZER);
// Retrieve the correct methods // 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 })); 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 })); COMPONENT, new Class<?>[] { String.class }));
// Get a component from a standard Minecraft message // Get a component from a standard Minecraft message