We cannot support plugin reloaders (PlugMan, PluginManagers).

This is because multiple plugins depend on us, and are not properly 
notified after ProtocolLib has been reloaded.

The only possible solution is to reload every dependent plugin after 
ProtocolLib has been reloaded, but unfortunately, I ran into
LinkageErrors when I tried it. So it's probably not possible with the
current architecture to support reloaders.

Instead, we'll simply print a BIG BOLD warning telling any users of
these plugins that ProtocolLib cannot be reloaded except through the
built in "/reload" command.
This commit is contained in:
Kristian S. Stangeland 2013-02-25 14:38:53 +01:00
parent df4542017a
commit 89d2604ce2
2 changed files with 69 additions and 4 deletions

View File

@ -42,6 +42,7 @@ import com.comphenix.protocol.metrics.Statistics;
import com.comphenix.protocol.metrics.Updater; import com.comphenix.protocol.metrics.Updater;
import com.comphenix.protocol.metrics.Updater.UpdateResult; import com.comphenix.protocol.metrics.Updater.UpdateResult;
import com.comphenix.protocol.reflect.compiler.BackgroundCompiler; import com.comphenix.protocol.reflect.compiler.BackgroundCompiler;
import com.comphenix.protocol.utility.ChatExtensions;
/** /**
* The main entry point for ProtocolLib. * The main entry point for ProtocolLib.
@ -216,6 +217,21 @@ public class ProtocolLibrary extends JavaPlugin {
// Don't do anything else! // Don't do anything else!
if (manager == null) if (manager == null)
return; return;
// Silly plugin reloaders!
if (protocolManager == null) {
Logger directLogging = Logger.getLogger("Minecraft");
String[] message = new String[] {
" PROTOCOLLIB DOES NOT SUPPORT PLUGIN RELOADERS. ",
" PLEASE USE THE BUILT-IN RELOAD COMMAND. ",
};
// Print as severe
for (String line : ChatExtensions.toFlowerBox(message, "*", 3, 1)) {
directLogging.severe(line);
}
disablePlugin();
return;
}
// Perform logic when the world has loaded // Perform logic when the world has loaded
protocolManager.postWorldLoaded(); protocolManager.postWorldLoaded();
@ -426,9 +442,13 @@ public class ProtocolLibrary extends JavaPlugin {
if (redirectHandler != null) { if (redirectHandler != null) {
logger.removeHandler(redirectHandler); logger.removeHandler(redirectHandler);
} }
if (protocolManager != null)
unhookTask.close();
protocolManager.close(); protocolManager.close();
else
return; // Plugin reloaders!
if (unhookTask != null)
unhookTask.close();
protocolManager = null; protocolManager = null;
statistisc = null; statistisc = null;
reporter = null; reporter = null;

View File

@ -27,6 +27,7 @@ import com.comphenix.protocol.Packets;
import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.injector.PacketConstructor; import com.comphenix.protocol.injector.PacketConstructor;
import com.comphenix.protocol.reflect.FieldAccessException; import com.comphenix.protocol.reflect.FieldAccessException;
import com.google.common.base.Strings;
/** /**
* Utility methods for sending chat messages. * Utility methods for sending chat messages.
@ -98,4 +99,48 @@ public class ChatExtensions {
} }
} }
} }
/**
* Print a flower box around a given message.
* @param message - the message to print.
* @param marginChar - the character to use as margin.
* @param marginWidth - the width (in characters) of the left and right margin.
* @param marginHeight - the height (in characters) of the top and buttom margin.
*/
public static String[] toFlowerBox(String[] message, String marginChar, int marginWidth, int marginHeight) {
String[] output = new String[message.length + marginHeight * 2];
int width = getMaximumLength(message);
// Margins
String topButtomMargin = Strings.repeat(marginChar, width + marginWidth * 2);
String leftRightMargin = Strings.repeat(marginChar, marginWidth);
// Add left and right margin
for (int i = 0; i < message.length; i++) {
output[i + marginHeight] = leftRightMargin + Strings.padEnd(message[i], width, ' ') + leftRightMargin;
}
// Insert top and bottom margin
for (int i = 0; i < marginHeight; i++) {
output[i] = topButtomMargin;
output[output.length - i - 1] = topButtomMargin;
}
return output;
}
/**
* Retrieve the longest line lenght in a list of strings.
* @param lines - the lines.
* @return Longest line lenght.
*/
private static int getMaximumLength(String[] lines) {
int current = 0;
// Find the longest line
for (int i = 0; i < lines.length; i++) {
if (current < lines[i].length())
current = lines[i].length();
}
return current;
}
} }