Allow command overrides to be disabled seperately

This also leaves room for disabling overrides in other features in the future.
This commit is contained in:
ME1312 2020-08-18 20:03:59 -04:00
parent b68fa0fec1
commit d43aae8486
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
4 changed files with 29 additions and 8 deletions

View File

@ -120,13 +120,21 @@ public class ConfigUpdater {
existing = updated.clone(); existing = updated.clone();
i++; i++;
} if (was.compareTo(new Version("20w26a")) <= 0) { } if (was.compareTo(new Version("20w34a")) <= 0) {
if (existing.getMap("Settings", new YAMLSection()).contains("Smart-Fallback") && existing.getMap("Settings").isBoolean("Smart-Fallback")) { if (existing.getMap("Settings", new YAMLSection()).contains("Smart-Fallback") && existing.getMap("Settings").isBoolean("Smart-Fallback")) {
YAMLSection smart_fallback = new YAMLSection(); YAMLSection smart_fallback = new YAMLSection();
smart_fallback.set("Enabled", existing.getMap("Settings").getBoolean("Smart-Fallback")); smart_fallback.set("Enabled", existing.getMap("Settings").getBoolean("Smart-Fallback"));
smart_fallback.set("Fallback", existing.getMap("Settings").getBoolean("Smart-Fallback")); smart_fallback.set("Fallback", existing.getMap("Settings").getBoolean("Smart-Fallback"));
updated.getMap("Settings").set("Smart-Fallback", smart_fallback); updated.getMap("Settings").set("Smart-Fallback", smart_fallback);
} }
if (existing.getMap("Settings", new YAMLSection()).contains("Override-Bungee-Commands") && existing.getMap("Settings").isBoolean("Override-Bungee-Commands")) {
List<String> overrides = new LinkedList<>();
if (!existing.getMap("Settings").getBoolean("Override-Bungee-Commands")) {
overrides.add("/server");
overrides.add("/glist");
}
updated.getMap("Settings").set("Disabled-Overrides", overrides);
}
existing = updated.clone(); existing = updated.clone();
i++; i++;
@ -142,7 +150,7 @@ public class ConfigUpdater {
if (i > 0) { if (i > 0) {
YAMLSection settings = new YAMLSection(); YAMLSection settings = new YAMLSection();
settings.set("Version", ((now.compareTo(was) <= 0)?was:now).toString()); settings.set("Version", ((now.compareTo(was) <= 0)?was:now).toString());
settings.set("Override-Bungee-Commands", updated.getMap("Settings", new YAMLSection()).getBoolean("Override-Bungee-Commands", true)); settings.set("Disabled-Overrides", updated.getMap("Settings", new YAMLSection()).getRawStringList("Disabled-Overrides", Collections.emptyList()));
YAMLSection smart_fallback = new YAMLSection(); YAMLSection smart_fallback = new YAMLSection();
smart_fallback.set("Enabled", updated.getMap("Settings", new YAMLSection()).getMap("Smart-Fallback", new YAMLSection()).getBoolean("Enabled", true)); smart_fallback.set("Enabled", updated.getMap("Settings", new YAMLSection()).getMap("Smart-Fallback", new YAMLSection()).getBoolean("Enabled", true));

View File

@ -630,10 +630,11 @@ public final class SubProxy extends BungeeCord implements Listener {
} }
private void post() { private void post() {
if (config.get().getMap("Settings").getBoolean("Override-Bungee-Commands", true)) { if (!config.get().getMap("Settings").getRawStringList("Disabled-Overrides", Collections.emptyList()).contains("/server"))
getPluginManager().registerCommand(null, SubCommand.BungeeServer.newInstance(this, "server").get()); getPluginManager().registerCommand(null, SubCommand.BungeeServer.newInstance(this, "server").get());
if (!config.get().getMap("Settings").getRawStringList("Disabled-Overrides", Collections.emptyList()).contains("/glist"))
getPluginManager().registerCommand(null, new SubCommand.BungeeList(this, "glist")); getPluginManager().registerCommand(null, new SubCommand.BungeeList(this, "glist"));
}
getPluginManager().registerCommand(null, SubCommand.newInstance(this, "subservers").get()); getPluginManager().registerCommand(null, SubCommand.newInstance(this, "subservers").get());
getPluginManager().registerCommand(null, SubCommand.newInstance(this, "subserver").get()); getPluginManager().registerCommand(null, SubCommand.newInstance(this, "subserver").get());
getPluginManager().registerCommand(null, SubCommand.newInstance(this, "sub").get()); getPluginManager().registerCommand(null, SubCommand.newInstance(this, "sub").get());

View File

@ -199,10 +199,11 @@ public final class ExProxy extends BungeeCord implements Listener {
} }
private void post() { private void post() {
if (config.get().getMap("Settings").getBoolean("Override-Bungee-Commands", true)) { if (!config.get().getMap("Settings").getRawStringList("Disabled-Overrides", Collections.emptyList()).contains("/server"))
getPluginManager().registerCommand(null, SubCommand.BungeeServer.newInstance(this, "server").get()); getPluginManager().registerCommand(null, SubCommand.BungeeServer.newInstance(this, "server").get());
if (!config.get().getMap("Settings").getRawStringList("Disabled-Overrides", Collections.emptyList()).contains("/glist"))
getPluginManager().registerCommand(null, new SubCommand.BungeeList(this, "glist")); getPluginManager().registerCommand(null, new SubCommand.BungeeList(this, "glist"));
}
getPluginManager().registerCommand(null, SubCommand.newInstance(this, "subservers").get()); getPluginManager().registerCommand(null, SubCommand.newInstance(this, "subservers").get());
getPluginManager().registerCommand(null, SubCommand.newInstance(this, "subserver").get()); getPluginManager().registerCommand(null, SubCommand.newInstance(this, "subserver").get());
getPluginManager().registerCommand(null, SubCommand.newInstance(this, "sub").get()); getPluginManager().registerCommand(null, SubCommand.newInstance(this, "sub").get());

View File

@ -11,6 +11,9 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
/** /**
* SubServers Configuration Updater * SubServers Configuration Updater
@ -42,13 +45,21 @@ public class ConfigUpdater {
if (was.compareTo(new Version("19w17a")) <= 0) { if (was.compareTo(new Version("19w17a")) <= 0) {
i++; i++;
} if (was.compareTo(new Version("20w26a")) <= 0) { } if (was.compareTo(new Version("20w34a")) <= 0) {
if (existing.getMap("Settings", new YAMLSection()).contains("Smart-Fallback") && existing.getMap("Settings").isBoolean("Smart-Fallback")) { if (existing.getMap("Settings", new YAMLSection()).contains("Smart-Fallback") && existing.getMap("Settings").isBoolean("Smart-Fallback")) {
YAMLSection smart_fallback = new YAMLSection(); YAMLSection smart_fallback = new YAMLSection();
smart_fallback.set("Enabled", existing.getMap("Settings").getBoolean("Smart-Fallback")); smart_fallback.set("Enabled", existing.getMap("Settings").getBoolean("Smart-Fallback"));
smart_fallback.set("Fallback", existing.getMap("Settings").getBoolean("Smart-Fallback")); smart_fallback.set("Fallback", existing.getMap("Settings").getBoolean("Smart-Fallback"));
updated.getMap("Settings").set("Smart-Fallback", smart_fallback); updated.getMap("Settings").set("Smart-Fallback", smart_fallback);
} }
if (existing.getMap("Settings", new YAMLSection()).contains("Override-Bungee-Commands") && existing.getMap("Settings").isBoolean("Override-Bungee-Commands")) {
List<String> overrides = new LinkedList<>();
if (!existing.getMap("Settings").getBoolean("Override-Bungee-Commands")) {
overrides.add("/server");
overrides.add("/glist");
}
updated.getMap("Settings").set("Disabled-Overrides", overrides);
}
existing = updated.clone(); existing = updated.clone();
i++; i++;
@ -63,7 +74,7 @@ public class ConfigUpdater {
if (i > 0) { if (i > 0) {
YAMLSection settings = new YAMLSection(); YAMLSection settings = new YAMLSection();
settings.set("Version", ((now.compareTo(was) <= 0)?was:now).toString()); settings.set("Version", ((now.compareTo(was) <= 0)?was:now).toString());
settings.set("Override-Bungee-Commands", updated.getMap("Settings", new YAMLSection()).getBoolean("Override-Bungee-Commands", true)); settings.set("Disabled-Overrides", updated.getMap("Settings", new YAMLSection()).getRawStringList("Disabled-Overrides", Collections.emptyList()));
YAMLSection smart_fallback = new YAMLSection(); YAMLSection smart_fallback = new YAMLSection();
smart_fallback.set("Enabled", updated.getMap("Settings", new YAMLSection()).getMap("Smart-Fallback", new YAMLSection()).getBoolean("Enabled", true)); smart_fallback.set("Enabled", updated.getMap("Settings", new YAMLSection()).getMap("Smart-Fallback", new YAMLSection()).getBoolean("Enabled", true));