Skip to content

Commit 3918843

Browse files
committed
This improves the feedback given when prism fails to start correctly.
Signed-off-by: Narimm <benjicharlton@gmail.com> (cherry picked from commit e5cfa0b)
1 parent ea3dc38 commit 3918843

3 files changed

Lines changed: 64 additions & 32 deletions

File tree

src/main/java/me/botsko/prism/Prism.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ public static String getPasteKey() {
142142
*
143143
* @return String
144144
*/
145-
@SuppressWarnings("WeakerAccess")
146145
public static String getPrismName() {
147146
return pluginName;
148147
}
@@ -310,6 +309,7 @@ public void onEnable() {
310309

311310
pluginName = this.getDescription().getName();
312311
pluginVersion = this.getDescription().getVersion();
312+
messenger = new Messenger(pluginName);
313313
log("Initializing Prism " + pluginVersion + ". Originally by Viveleroi; maintained by the AddstarMC Network");
314314
loadConfig(); // Load configuration, or install if new
315315
if (!getConfig().getBoolean("prism.suppress-paper-message", false)) {
@@ -343,7 +343,7 @@ public void onEnable() {
343343
testConnection = prismDataSource.getConnection();
344344
if (testConnection == null) {
345345
notifyDisabled();
346-
Bukkit.getScheduler().runTask(instance, () -> instance.onDisable());
346+
Bukkit.getScheduler().runTask(instance, () -> instance.enableFailedDatabase());
347347
updating.cancel();
348348
return;
349349
}
@@ -354,7 +354,7 @@ public void onEnable() {
354354
}
355355
} else {
356356
notifyDisabled();
357-
Bukkit.getScheduler().runTask(instance, () -> instance.onDisable());
357+
Bukkit.getScheduler().runTask(instance, () -> instance.enableFailedDatabase());
358358
updating.cancel();
359359
return;
360360
}
@@ -386,10 +386,25 @@ public void onEnable() {
386386

387387
private void notifyDisabled() {
388388
final String[] dbDisabled = new String[3];
389-
dbDisabled[0] = "Prism will disable itself because it couldn't connect to a database.";
389+
dbDisabled[0] = "Prism will disable most commands because it couldn't connect to a database.";
390390
dbDisabled[1] = "If you're using MySQL, check your config. Be sure MySQL is running.";
391391
dbDisabled[2] = "For help - try our Discord Channel or the Wiki on Github.";
392392
logSection(dbDisabled);
393+
394+
}
395+
396+
private void enableFailedDatabase() {
397+
if (isEnabled()) {
398+
PluginCommand command = getCommand("prism");
399+
if (command != null) {
400+
PrismCommands commands = new PrismCommands(this,true);
401+
command.setExecutor(commands);
402+
command.setTabCompleter(commands);
403+
} else {
404+
warn("Command Executor Error: Check plugin.yml");
405+
Bukkit.getPluginManager().disablePlugin(instance);
406+
}
407+
}
393408
}
394409

395410
private void enabled() {
@@ -423,7 +438,7 @@ private void enabled() {
423438
// Add commands
424439
PluginCommand command = getCommand("prism");
425440
if (command != null) {
426-
PrismCommands commands = new PrismCommands(this);
441+
PrismCommands commands = new PrismCommands(this,false);
427442
command.setExecutor(commands);
428443
command.setTabCompleter(commands);
429444
} else {
@@ -451,7 +466,6 @@ private void enabled() {
451466
registerParameter(new WorldParameter());
452467

453468
// Init re-used classes
454-
messenger = new Messenger(pluginName);
455469
oreMonitor = new OreMonitor(instance);
456470
useMonitor = new UseMonitor(instance);
457471

@@ -562,7 +576,6 @@ public PurgeManager getPurgeManager() {
562576
/**
563577
* Clears the Query Cache.
564578
*/
565-
@SuppressWarnings("WeakerAccess")
566579
public void endExpiredQueryCaches() {
567580
getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> {
568581
final java.util.Date date = new java.util.Date();
@@ -602,7 +615,6 @@ public void endExpiredPreviews() {
602615
/**
603616
* Remove expired locations.
604617
*/
605-
@SuppressWarnings("WeakerAccess")
606618
public void removeExpiredLocations() {
607619
getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> {
608620
final java.util.Date date = new java.util.Date();

src/main/java/me/botsko/prism/commands/HelpCommand.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010

1111
public class HelpCommand implements SubHandler {
1212

13+
private final boolean failed;
14+
15+
public HelpCommand(boolean failed) {
16+
this.failed = failed;
17+
}
18+
1319
/**
1420
* {@inheritDoc}
1521
*/
@@ -29,7 +35,19 @@ public List<String> handleComplete(CallInfo call) {
2935
* @param sender CommandSender
3036
*/
3137
protected void help(CommandSender sender) {
32-
38+
if (failed) {
39+
sender.sendMessage(Prism.messenger.playerHeaderMsg(ChatColor.GOLD + "--- Prism Disabled ---"));
40+
sender.sendMessage(Prism.messenger.playerMsg("Prism is running in a disabled mode because the"
41+
+ " database could not be connected. \n Please seek help by running /prism debug and perusing"
42+
+ " the contents to help with errors. "));
43+
sender.sendMessage(
44+
Prism.messenger.playerSubduedHeaderMsg("Discord: " + ChatColor.WHITE
45+
+ "https://discord.gg/Y9Qx3V"));
46+
sender.sendMessage(
47+
Prism.messenger.playerSubduedHeaderMsg("Wiki: " + ChatColor.WHITE
48+
+ "https://github.com/AddstarMC/Prism-Bukkit/wiki\n"));
49+
return;
50+
}
3351
sender.sendMessage(Prism.messenger.playerHeaderMsg(ChatColor.GOLD + "--- Basic Usage ---"));
3452

3553
sender.sendMessage(Prism.messenger.playerHelp("i", "Toggle the inspector wand."));

src/main/java/me/botsko/prism/commands/PrismCommands.java

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,39 @@ public class PrismCommands extends Executor {
1414
* Constructor.
1515
* @param prism Plugin.
1616
*/
17-
public PrismCommands(Plugin prism) {
17+
public PrismCommands(Plugin prism,boolean failed) {
1818
super(prism, "subcommand", "prism");
19-
setupCommands();
19+
setupCommands(failed);
2020
}
2121

22-
private void setupCommands() {
23-
22+
private void setupCommands(boolean failed) {
2423
final Prism prism = (Prism) plugin;
2524
addSub(new String[]{"about", "default"}, "prism.help").allowConsole().setHandler(new AboutCommand(prism));
25+
addSub("debug", "prism.debug").allowConsole().setHandler(new DebugCommand());
26+
addSub(new String[]{"help", "?"}, "prism.help").allowConsole().setHandler(new HelpCommand(failed));
27+
addSub("flags", "prism.help").allowConsole().setHandler(new FlagsCommand());
28+
addSub("params", "prism.help").allowConsole().setHandler(new ParamsCommand());
29+
addSub("actions", "prism.help").allowConsole().setHandler(new ActionsCommand());
30+
addSub("reload", "prism.reload").allowConsole().setHandler(new SubHandler() {
31+
32+
@Override
33+
public void handle(CallInfo call) {
34+
prism.reloadConfig();
35+
prism.loadConfig();
36+
call.getSender().sendMessage(Prism.messenger.playerHeaderMsg("Configuration reloaded successfully."));
37+
}
38+
39+
@Override
40+
public List<String> handleComplete(CallInfo call) {
41+
return null;
42+
}
43+
});
44+
if (failed) {
45+
return;
46+
}
2647
addSub(new String[]{"lookup", "l"}, "prism.lookup").allowConsole().setMinArgs(1)
2748
.setHandler(new LookupCommand(prism));
2849
addSub("near", "prism.lookup").setHandler(new NearCommand(prism));
29-
3050
addSub(new String[]{"page", "pg"}, new String[]{"prism.lookup.paginate", "prism.lookup"}).allowConsole()
3151
.setMinArgs(1).setHandler(new PageCommand(prism));
3252
addSub(new String[]{"wand", "w", "i", "inspect"},
@@ -48,24 +68,6 @@ private void setupCommands() {
4868
addSub("recorder", "prism.recorder").allowConsole().setHandler(new RecorderCommand(prism));
4969
addSub("undo", "prism.rollback").setHandler(new UndoCommand(prism));
5070
addSub(new String[]{"view", "v"}, "prism.view").setMinArgs(1).setHandler(new ViewCommand(prism));
51-
addSub(new String[]{"help", "?"}, "prism.help").allowConsole().setHandler(new HelpCommand());
52-
addSub("params", "prism.help").allowConsole().setHandler(new ParamsCommand());
53-
addSub("actions", "prism.help").allowConsole().setHandler(new ActionsCommand());
54-
addSub("flags", "prism.help").allowConsole().setHandler(new FlagsCommand());
55-
addSub("debug","prism.debug").allowConsole().setHandler(new DebugCommand());
56-
addSub("reload", "prism.reload").allowConsole().setHandler(new SubHandler() {
57-
@Override
58-
public void handle(CallInfo call) {
59-
prism.reloadConfig();
60-
prism.loadConfig();
61-
call.getSender().sendMessage(Prism.messenger.playerHeaderMsg("Configuration reloaded successfully."));
62-
}
63-
64-
@Override
65-
public List<String> handleComplete(CallInfo call) {
66-
return null;
67-
}
68-
});
6971
}
7072

7173
}

0 commit comments

Comments
 (0)