Require Spigot (not just CraftBukkit) at startup

This commit is contained in:
filoghost 2020-04-12 17:04:23 +02:00
parent 669f72437c
commit d78414c30e

View File

@ -96,14 +96,20 @@ public class HolographicDisplays extends JavaPlugin {
}); });
} }
// The bungee chat API is required.
try {
Class.forName("net.md_5.bungee.api.chat.ComponentBuilder");
} catch (ClassNotFoundException e) {
criticalShutdown(
"Holographic Displays requires the new chat API.",
"You are probably running CraftBukkit instead of Spigot.");
return;
}
if (!NMSVersion.isValid()) { if (!NMSVersion.isValid()) {
printWarnAndDisable( criticalShutdown(
"******************************************************", "Holographic Displays does not support this server version.",
" This version of HolographicDisplays only", "Supported Spigot versions: from 1.8 to 1.15.");
" works on server versions from 1.8 to 1.15.",
" The plugin will be disabled.",
"******************************************************"
);
return; return;
} }
@ -111,12 +117,8 @@ public class HolographicDisplays extends JavaPlugin {
nmsManager = (NMSManager) Class.forName("com.gmail.filoghost.holographicdisplays.nms." + NMSVersion.getCurrent() + ".NmsManagerImpl").getConstructor().newInstance(); nmsManager = (NMSManager) Class.forName("com.gmail.filoghost.holographicdisplays.nms." + NMSVersion.getCurrent() + ".NmsManagerImpl").getConstructor().newInstance();
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();
printWarnAndDisable( criticalShutdown(
"******************************************************", "Holographic Displays was unable to initialize the NMS manager.");
" HolographicDisplays was unable to instantiate",
" the NMS manager. The plugin will be disabled.",
"******************************************************"
);
return; return;
} }
@ -124,13 +126,8 @@ public class HolographicDisplays extends JavaPlugin {
nmsManager.setup(); nmsManager.setup();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
printWarnAndDisable( criticalShutdown(
"******************************************************", "Holographic Displays was unable to register custom entities.");
" HolographicDisplays was unable to register",
" custom entities, the plugin will be disabled.",
" Are you using the correct Bukkit/Spigot version?",
"******************************************************"
);
return; return;
} }
@ -154,14 +151,9 @@ public class HolographicDisplays extends JavaPlugin {
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new WorldPlayerCounterTask(), 0L, 3 * 20); Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new WorldPlayerCounterTask(), 0L, 3 * 20);
if (getCommand("holograms") == null) { if (getCommand("holograms") == null) {
printWarnAndDisable( criticalShutdown(
"******************************************************", "Holographic Displays was unable to register the command \"holograms\".",
" HolographicDisplays was unable to register", "This can be caused by edits to plugin.yml or other plugins.");
" the command \"holograms\". Do not modify",
" plugin.yml removing commands, if this is",
" the case.",
"******************************************************"
);
return; return;
} }
@ -201,14 +193,20 @@ public class HolographicDisplays extends JavaPlugin {
return commandHandler; return commandHandler;
} }
private static void printWarnAndDisable(String... messages) { private static void criticalShutdown(String... errorMessage) {
StringBuffer buffer = new StringBuffer("\n "); String separator = "****************************************************************************";
for (String message : messages) { StringBuffer output = new StringBuffer("\n ");
buffer.append('\n'); output.append("\n" + separator);
buffer.append(message); for (String line : errorMessage) {
output.append("\n " + line);
} }
buffer.append('\n'); output.append("\n ");
System.out.println(buffer.toString()); output.append("\n This plugin has been disabled.");
output.append("\n" + separator);
output.append("\n ");
System.out.println(output);
try { try {
Thread.sleep(5000); Thread.sleep(5000);
} catch (InterruptedException ex) { } } catch (InterruptedException ex) { }