Skip to content

Commit

Permalink
Allow command overrides to be disabled seperately
Browse files Browse the repository at this point in the history
This also leaves room for disabling overrides in other features in the future.
  • Loading branch information
ME1312 committed Aug 19, 2020
1 parent b68fa0f commit d43aae8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
Expand Up @@ -120,13 +120,21 @@ public static void updateConfig(File file) throws IOException {

existing = updated.clone();
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")) {
YAMLSection smart_fallback = new YAMLSection();
smart_fallback.set("Enabled", existing.getMap("Settings").getBoolean("Smart-Fallback"));
smart_fallback.set("Fallback", existing.getMap("Settings").getBoolean("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();
i++;
Expand All @@ -142,7 +150,7 @@ public static void updateConfig(File file) throws IOException {
if (i > 0) {
YAMLSection settings = new YAMLSection();
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();
smart_fallback.set("Enabled", updated.getMap("Settings", new YAMLSection()).getMap("Smart-Fallback", new YAMLSection()).getBoolean("Enabled", true));
Expand Down
Expand Up @@ -630,10 +630,11 @@ public void reload() throws IOException {
}

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());
if (!config.get().getMap("Settings").getRawStringList("Disabled-Overrides", Collections.emptyList()).contains("/glist"))
getPluginManager().registerCommand(null, new SubCommand.BungeeList(this, "glist"));
}

getPluginManager().registerCommand(null, SubCommand.newInstance(this, "subservers").get());
getPluginManager().registerCommand(null, SubCommand.newInstance(this, "subserver").get());
getPluginManager().registerCommand(null, SubCommand.newInstance(this, "sub").get());
Expand Down
5 changes: 3 additions & 2 deletions SubServers.Sync/src/net/ME1312/SubServers/Sync/ExProxy.java
Expand Up @@ -199,10 +199,11 @@ public void run() {
}

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());
if (!config.get().getMap("Settings").getRawStringList("Disabled-Overrides", Collections.emptyList()).contains("/glist"))
getPluginManager().registerCommand(null, new SubCommand.BungeeList(this, "glist"));
}

getPluginManager().registerCommand(null, SubCommand.newInstance(this, "subservers").get());
getPluginManager().registerCommand(null, SubCommand.newInstance(this, "subserver").get());
getPluginManager().registerCommand(null, SubCommand.newInstance(this, "sub").get());
Expand Down
Expand Up @@ -11,6 +11,9 @@
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

/**
* SubServers Configuration Updater
Expand Down Expand Up @@ -42,13 +45,21 @@ public static void updateConfig(File file) throws IOException {
if (was.compareTo(new Version("19w17a")) <= 0) {

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")) {
YAMLSection smart_fallback = new YAMLSection();
smart_fallback.set("Enabled", existing.getMap("Settings").getBoolean("Smart-Fallback"));
smart_fallback.set("Fallback", existing.getMap("Settings").getBoolean("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();
i++;
Expand All @@ -63,7 +74,7 @@ public static void updateConfig(File file) throws IOException {
if (i > 0) {
YAMLSection settings = new YAMLSection();
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();
smart_fallback.set("Enabled", updated.getMap("Settings", new YAMLSection()).getMap("Smart-Fallback", new YAMLSection()).getBoolean("Enabled", true));
Expand Down

0 comments on commit d43aae8

Please sign in to comment.