Adds an option for disabling startup fixes

Also fixes configuration default values not being used when the option is missing from the configuration file.
This commit is contained in:
2024-04-21 23:10:26 +02:00
parent 6287a5e492
commit 9db73b7bae
5 changed files with 39 additions and 18 deletions

View File

@@ -66,6 +66,11 @@ public enum ConfigOption {
*/ */
DESTROYED_BY_EXPLOSION("gates.integrity.destroyedByExplosion", "Whether stargates should be destroyed by explosions", false), DESTROYED_BY_EXPLOSION("gates.integrity.destroyedByExplosion", "Whether stargates should be destroyed by explosions", false),
/**
* Whether to fix incorrect signs, buttons or openings during startup
*/
APPLY_STARTUP_FIXES("gates.integrity.applyStartupFixes", "Whether Stargates should fix incorrect signs, buttons or openings during startup", true),
/** /**
* Whether to verify each portal's gate layout after each load * Whether to verify each portal's gate layout after each load
*/ */

View File

@@ -418,13 +418,10 @@ public final class StargateConfig {
//Load the option using its correct data type //Load the option using its correct data type
switch (option.getDataType()) { switch (option.getDataType()) {
case STRING_LIST -> optionValue = newConfig.getStringList(configNode); case STRING_LIST -> optionValue = newConfig.getStringList(configNode);
case STRING -> { case STRING -> optionValue = newConfig.getString(configNode, (String) option.getDefaultValue()).trim();
String value = newConfig.getString(configNode); case BOOLEAN -> optionValue = newConfig.getBoolean(configNode, (boolean) option.getDefaultValue());
optionValue = value != null ? value.trim() : ""; case INTEGER -> optionValue = newConfig.getInt(configNode, (int) option.getDefaultValue());
} case DOUBLE -> optionValue = newConfig.getDouble(configNode, (double) option.getDefaultValue());
case BOOLEAN -> optionValue = newConfig.getBoolean(configNode);
case INTEGER -> optionValue = newConfig.getInt(configNode);
case DOUBLE -> optionValue = newConfig.getDouble(configNode);
default -> throw new IllegalArgumentException("Invalid config data type encountered"); default -> throw new IllegalArgumentException("Invalid config data type encountered");
} }
configOptions.put(option, optionValue); configOptions.put(option, optionValue);

View File

@@ -195,6 +195,15 @@ public final class StargateGateConfig {
return (boolean) configOptions.get(ConfigOption.DESTROYED_BY_EXPLOSION); return (boolean) configOptions.get(ConfigOption.DESTROYED_BY_EXPLOSION);
} }
/**
* Gets whether to destroy portals when any blocks are broken by explosions
*
* @return <p>Whether to destroy portals when any blocks are broken by explosions</p>
*/
public boolean applyStartupFixes() {
return (boolean) configOptions.get(ConfigOption.APPLY_STARTUP_FIXES);
}
/** /**
* Gets the default portal network to use if no other network is given * Gets the default portal network to use if no other network is given
* *

View File

@@ -236,6 +236,8 @@ public final class PortalFileHelper {
Stargate.logInfo(String.format("{%s} Loaded %d stargates with %d set as always-on", world.getName(), Stargate.logInfo(String.format("{%s} Loaded %d stargates with %d set as always-on", world.getName(),
portalCount, openCount)); portalCount, openCount));
if (Stargate.getGateConfig().applyStartupFixes()) {
//Re-draw the signs in case a bug in the config prevented the portal from loading and has been fixed since //Re-draw the signs in case a bug in the config prevented the portal from loading and has been fixed since
Stargate.debug("PortalFileHelper::doPostLoadTasks::update", Stargate.debug("PortalFileHelper::doPostLoadTasks::update",
String.format("Updating portal signs/buttons for %s", world)); String.format("Updating portal signs/buttons for %s", world));
@@ -248,6 +250,7 @@ public final class PortalFileHelper {
portal.getName())); portal.getName()));
} }
} }
}
//Save the portals to disk to update with any changes //Save the portals to disk to update with any changes
Stargate.debug("PortalFileHelper::doPostLoadTasks", String.format("Saving database for world %s", world)); Stargate.debug("PortalFileHelper::doPostLoadTasks", String.format("Saving database for world %s", world));
if (needsToSaveDatabase) { if (needsToSaveDatabase) {
@@ -299,7 +302,9 @@ public final class PortalFileHelper {
//Register the portal, and close it in case it wasn't properly closed when the server stopped //Register the portal, and close it in case it wasn't properly closed when the server stopped
boolean buttonLocationChanged = updateButtonVector(portal); boolean buttonLocationChanged = updateButtonVector(portal);
PortalHandler.registerPortal(portal); PortalHandler.registerPortal(portal);
if (Stargate.getGateConfig().applyStartupFixes()) {
portal.getPortalOpener().closePortal(true); portal.getPortalOpener().closePortal(true);
}
return buttonLocationChanged; return buttonLocationChanged;
} }

View File

@@ -107,6 +107,11 @@ gates:
# Or if using an easily destroyable open/closed material. # Or if using an easily destroyable open/closed material.
protectEntrance: false protectEntrance: false
# Should things like outdated signs, invalid button materials and not properly closed Stargates be fixed at startup?
# It is generally recommended to enable this, but for huge servers, the amount of chunks loaded might require way
# too much RAM.
applyStartupFixes: true
# +----------------------------------------------------------------------------------------------+ # # +----------------------------------------------------------------------------------------------+ #
# | Aesthetic Tweaks | # # | Aesthetic Tweaks | #
# +----------------------------------------------------------------------------------------------+ # # +----------------------------------------------------------------------------------------------+ #