mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-12-25 18:47:52 +01:00
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:
parent
df4542017a
commit
89d2604ce2
@ -42,6 +42,7 @@ import com.comphenix.protocol.metrics.Statistics;
|
||||
import com.comphenix.protocol.metrics.Updater;
|
||||
import com.comphenix.protocol.metrics.Updater.UpdateResult;
|
||||
import com.comphenix.protocol.reflect.compiler.BackgroundCompiler;
|
||||
import com.comphenix.protocol.utility.ChatExtensions;
|
||||
|
||||
/**
|
||||
* The main entry point for ProtocolLib.
|
||||
@ -216,6 +217,21 @@ public class ProtocolLibrary extends JavaPlugin {
|
||||
// Don't do anything else!
|
||||
if (manager == null)
|
||||
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
|
||||
protocolManager.postWorldLoaded();
|
||||
@ -426,9 +442,13 @@ public class ProtocolLibrary extends JavaPlugin {
|
||||
if (redirectHandler != null) {
|
||||
logger.removeHandler(redirectHandler);
|
||||
}
|
||||
|
||||
unhookTask.close();
|
||||
if (protocolManager != null)
|
||||
protocolManager.close();
|
||||
else
|
||||
return; // Plugin reloaders!
|
||||
|
||||
if (unhookTask != null)
|
||||
unhookTask.close();
|
||||
protocolManager = null;
|
||||
statistisc = null;
|
||||
reporter = null;
|
||||
|
@ -27,6 +27,7 @@ import com.comphenix.protocol.Packets;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.injector.PacketConstructor;
|
||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user