From e0f7c72e1806b84bd2f42621364a27def70b3f51 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Fri, 19 Jun 2015 13:14:20 -0400 Subject: [PATCH] Use correct Guava package, fix a few compatibility issues --- .../protocol/compat/guava/Guava10.java | 5 ++- .../comphenix/protocol/ProtocolLibrary.java | 2 ++ .../protocol/error/DetailedErrorReporter.java | 10 +++++- .../protocol/events/PacketContainer.java | 7 +++- .../protocol/events/PacketEvent.java | 35 +++++++++++-------- .../protocol/injector/PluginVerifier.java | 26 +++++++++----- .../protocol/reflect/StructureModifier.java | 7 +++- 7 files changed, 63 insertions(+), 29 deletions(-) diff --git a/Modules/ProtocolLib-ShadedNetty/src/main/java/com/comphenix/protocol/compat/guava/Guava10.java b/Modules/ProtocolLib-ShadedNetty/src/main/java/com/comphenix/protocol/compat/guava/Guava10.java index c8e0decb..cb9feeaf 100644 --- a/Modules/ProtocolLib-ShadedNetty/src/main/java/com/comphenix/protocol/compat/guava/Guava10.java +++ b/Modules/ProtocolLib-ShadedNetty/src/main/java/com/comphenix/protocol/compat/guava/Guava10.java @@ -22,13 +22,12 @@ import java.io.IOException; import java.io.InputStream; import java.util.Set; -import net.minecraft.util.com.google.common.io.ByteStreams; -import net.minecraft.util.com.google.common.io.InputSupplier; - import com.comphenix.protocol.PacketType; import com.google.common.collect.DiscreteDomains; import com.google.common.collect.Range; import com.google.common.collect.Ranges; +import com.google.common.io.ByteStreams; +import com.google.common.io.InputSupplier; /** * @author dmulloy2 diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java index b4ca4b0a..3621abee 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java @@ -261,6 +261,8 @@ public class ProtocolLibrary extends JavaPlugin { throw e; } catch (ThreadDeath e) { throw e; + } catch (LinkageError e) { + logger.warning("Failed to register command " + command.name() + ": " + e); } catch (Throwable e) { reporter.reportWarning(this, Report.newBuilder(REPORT_CANNOT_REGISTER_COMMAND) .messageParam(command.name(), e.getMessage()).error(e)); diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/error/DetailedErrorReporter.java b/ProtocolLib/src/main/java/com/comphenix/protocol/error/DetailedErrorReporter.java index 7138857e..615c1cc7 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/error/DetailedErrorReporter.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/error/DetailedErrorReporter.java @@ -122,13 +122,21 @@ public class DetailedErrorReporter implements ErrorReporter { throw new IllegalArgumentException("Plugin cannot be NULL."); this.pluginReference = new WeakReference(plugin); - this.pluginName = plugin.getName(); + this.pluginName = getNameSafely(plugin); this.prefix = prefix; this.supportURL = supportURL; this.maxErrorCount = maxErrorCount; this.logger = logger; } + private String getNameSafely(Plugin plugin) { + try { + return plugin.getName(); + } catch (LinkageError e) { + return "ProtocolLib"; + } + } + // Attempt to get the logger. private static Logger getBukkitLogger() { try { diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java b/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java index 65f53b59..7499d9ae 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java @@ -1166,4 +1166,9 @@ public class PacketContainer implements Serializable { return WrappedChatComponent[].class; } } -} + + @Override + public String toString() { + return "PacketContainer[type=" + type + ", structureModifier=" + structureModifier + "]"; + } +} \ No newline at end of file diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketEvent.java b/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketEvent.java index 7e6b054f..bc8d84be 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketEvent.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketEvent.java @@ -2,16 +2,16 @@ * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * Copyright (C) 2012 Kristian S. Stangeland * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation; either version 2 of + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * You should have received a copy of the GNU General Public License along with this program; + * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA */ @@ -39,7 +39,7 @@ import com.google.common.collect.Multimaps; import com.google.common.collect.SetMultimap; /** - * Represents a packet sending or receiving event. Changes to the packet will be + * Represents a packet sending or receiving event. Changes to the packet will be * reflected in the final version to be sent or received. It is also possible to cancel an event. * @author Kristian */ @@ -47,7 +47,7 @@ public class PacketEvent extends EventObject implements Cancellable { public static final ReportType REPORT_CHANGING_PACKET_TYPE_IS_CONFUSING = new ReportType( "Plugin %s changed packet type from %s to %s in packet listener. This is confusing for other plugins! (Not an error, though!)"); - private static final SetMultimap CHANGE_WARNINGS = + private static final SetMultimap CHANGE_WARNINGS = Multimaps.synchronizedSetMultimap(HashMultimap.create()); /** @@ -229,7 +229,7 @@ public class PacketEvent extends EventObject implements Cancellable { if (this.packet != null && !Objects.equal(oldType, newType)) { // Only report this once if (CHANGE_WARNINGS.put(oldType, newType)) { - ProtocolLibrary.getErrorReporter().reportWarning(this, + ProtocolLibrary.getErrorReporter().reportWarning(this, Report.newBuilder(REPORT_CHANGING_PACKET_TYPE_IS_CONFUSING). messageParam(oldType, newType). build()); @@ -261,6 +261,7 @@ public class PacketEvent extends EventObject implements Cancellable { * Retrieves whether or not the packet should be cancelled. * @return TRUE if it should be cancelled, FALSE otherwise. */ + @Override public boolean isCancelled() { return cancel; } @@ -307,6 +308,7 @@ public class PacketEvent extends EventObject implements Cancellable { * * @param cancel - TRUE if it should be cancelled, FALSE otherwise. */ + @Override public void setCancelled(boolean cancel) { if (readOnly) throw new IllegalStateException("The packet event is read-only."); @@ -354,12 +356,12 @@ public class PacketEvent extends EventObject implements Cancellable { return asyncMarker; } /** - * Set the asynchronous marker. + * Set the asynchronous marker. *

* If the marker is non-null at the end of an synchronous event processing, the packet will be scheduled * to be processed asynchronously with the given settings. *

- * Note that if there are no asynchronous events that can receive this packet, the marker should be NULL. + * Note that if there are no asynchronous events that can receive this packet, the marker should be NULL. * @param asyncMarker - the new asynchronous marker, or NULL. * @throws IllegalStateException If the current event is asynchronous. */ @@ -425,7 +427,7 @@ public class PacketEvent extends EventObject implements Cancellable { } private void writeObject(ObjectOutputStream output) throws IOException { - // Default serialization + // Default serialization output.defaultWriteObject(); // Write the name of the player (or NULL if it's not set) @@ -439,10 +441,15 @@ public class PacketEvent extends EventObject implements Cancellable { final SerializedOfflinePlayer serialized = (SerializedOfflinePlayer) input.readObject(); // Better than nothing - if (serialized != null) { + if (serialized != null) { // Store it, to prevent weak reference from cleaning up the reference offlinePlayer = serialized.getPlayer(); playerReference = new WeakReference(offlinePlayer); } } -} + + @Override + public String toString() { + return "PacketEvent[player=" + getPlayer() + ", packet=" + packet + "]"; + } +} \ No newline at end of file diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PluginVerifier.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PluginVerifier.java index dfb40242..fff08c37 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PluginVerifier.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PluginVerifier.java @@ -4,10 +4,12 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.logging.Level; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginLoadOrder; +import com.comphenix.protocol.ProtocolLibrary; import com.google.common.collect.Sets; /** @@ -73,10 +75,16 @@ class PluginVerifier { public PluginVerifier(Plugin dependency) { if (dependency == null) throw new IllegalArgumentException("dependency cannot be NULL."); - // This would screw with the assumption in hasDependency(Plugin, Plugin) - if (safeConversion(dependency.getDescription().getLoadBefore()).size() > 0) - throw new IllegalArgumentException("dependency cannot have a load directives."); - + + try { + // This would screw with the assumption in hasDependency(Plugin, Plugin) + if (safeConversion(dependency.getDescription().getLoadBefore()).size() > 0) + throw new IllegalArgumentException("dependency cannot have a load directives."); + } catch (LinkageError e) { + // They're probably using an ancient version of Bukkit + ProtocolLibrary.log(Level.WARNING, "Failed to determine loadBefore: " + e); + } + this.dependency = dependency; } @@ -93,7 +101,7 @@ class PluginVerifier { if (plugin != null) return plugin; else - throw new PluginNotFoundException("Cannot find plugin " + pluginName); + throw new PluginNotFoundException("Cannot find plugin " + pluginName); } /** @@ -153,7 +161,7 @@ class PluginVerifier { /** * Determine if a given plugin is guarenteed to be loaded before the other. *

- * Note that the before plugin is assumed to have no "load" directives - that is, plugins to be + * Note that the before plugin is assumed to have no "load" directives - that is, plugins to be * loaded after itself. The after plugin may have "load" directives, but it is irrelevant for our purposes. * @param beforePlugin - the plugin that is loaded first. * @param afterPlugin - the plugin that is loaded last. @@ -166,7 +174,7 @@ class PluginVerifier { } // No dependency - check the load order - if (beforePlugin.getDescription().getLoad() == PluginLoadOrder.STARTUP && + if (beforePlugin.getDescription().getLoad() == PluginLoadOrder.STARTUP && afterPlugin.getDescription().getLoad() == PluginLoadOrder.POSTWORLD) { return true; } @@ -177,14 +185,14 @@ class PluginVerifier { * Determine if a plugin has a given dependency, either directly or indirectly. * @param plugin - the plugin to check. * @param dependency - the dependency to find. - * @return TRUE if the plugin has the given dependency, FALSE otherwise. + * @return TRUE if the plugin has the given dependency, FALSE otherwise. */ private boolean hasDependency(Plugin plugin, Plugin dependency) { return hasDependency(plugin, dependency, Sets.newHashSet()); } /** - * Convert a list to a set. + * Convert a list to a set. *

* A null list will be converted to an empty set. * @param list - the list to convert. diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/StructureModifier.java b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/StructureModifier.java index 55e31e82..22f3c94b 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/StructureModifier.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/StructureModifier.java @@ -656,4 +656,9 @@ public class StructureModifier { } return result; } -} + + @Override + public String toString() { + return "StructureModifier[fieldType=" + fieldType + ", data=" + data + "]"; + } +} \ No newline at end of file