improved load error handling

This commit is contained in:
Lukas Alt 2024-01-03 19:51:18 +01:00
parent bc5391c987
commit ebb3bea464
1 changed files with 9 additions and 3 deletions

View File

@ -114,6 +114,7 @@ public class ProtocolLib extends JavaPlugin {
// Whether disabling field resetting is needed // Whether disabling field resetting is needed
private boolean skipDisable; private boolean skipDisable;
private boolean loadingFailed = false;
@Override @Override
public void onLoad() { public void onLoad() {
@ -167,7 +168,7 @@ public class ProtocolLib extends JavaPlugin {
// Handle unexpected Minecraft versions // Handle unexpected Minecraft versions
MinecraftVersion version = this.verifyMinecraftVersion(); // returns the current version or null if a version mismatch was detected MinecraftVersion version = this.verifyMinecraftVersion(); // returns the current version or null if a version mismatch was detected
if(version == null) { if(version == null) {
this.disablePlugin(); loadingFailed = true;
return; return;
} }
@ -192,7 +193,7 @@ public class ProtocolLib extends JavaPlugin {
} catch (Exception e) { } catch (Exception e) {
reporter.reportDetailed(this, Report.newBuilder(REPORT_PLUGIN_LOAD_ERROR).error(e).callerParam(protocolManager)); reporter.reportDetailed(this, Report.newBuilder(REPORT_PLUGIN_LOAD_ERROR).error(e).callerParam(protocolManager));
this.disablePlugin(); loadingFailed = true;
} }
} }
@ -311,6 +312,11 @@ public class ProtocolLib extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
if(loadingFailed) {
this.getLogger().log(Level.SEVERE, "Loading of ProtocolLib failed (see log above). ProtocolLib will be disabled.");
this.disablePlugin();
return;
}
try { try {
Server server = this.getServer(); Server server = this.getServer();
PluginManager manager = server.getPluginManager(); PluginManager manager = server.getPluginManager();
@ -404,7 +410,7 @@ public class ProtocolLib extends JavaPlugin {
Level level = ignore ? Level.WARNING : Level.SEVERE; Level level = ignore ? Level.WARNING : Level.SEVERE;
logger.log(level, line); logger.log(level, line);
logger.log(level, ""); logger.log(level, "");
logger.log(level, "This version of ProtocolLib (" + getDescription().getVersion() + ") has not been tested with Minecraft " + current + " and is likely not work as expected."); logger.log(level, "This version of ProtocolLib (" + getDescription().getVersion() + ") has not been tested with Minecraft " + current.getVersion() + " and is likely not work as expected.");
if(ignore) { if(ignore) {
logger.log(level, "As you configured ProtocolLib to ignore this, ProtocolLib will attempt to continue initialization. Proceed with caution!"); logger.log(level, "As you configured ProtocolLib to ignore this, ProtocolLib will attempt to continue initialization. Proceed with caution!");
} else { } else {