Skip to content

Commit 96deee7

Browse files
authored
Merge pull request #3397 from Multiverse/fix/config-reset
Remove config saving on plugin disable
2 parents 8a60761 + 86d77ae commit 96deee7

File tree

6 files changed

+33
-35
lines changed

6 files changed

+33
-35
lines changed

src/main/java/org/mvplugins/multiverse/core/MultiverseCore.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ public void onEnable() {
124124
public void onDisable() {
125125
super.onDisable();
126126
MultiverseCoreApi.shutdown();
127-
saveAllConfigs();
128127
shutdownDependencyInjection();
129128
PluginServiceLocatorFactory.get().shutdown();
130129
Logging.shutdown();
@@ -215,11 +214,11 @@ private void loadApiService() {
215214
*/
216215
private Try<Void> saveAllConfigs() {
217216
return configProvider.get().save()
218-
.flatMap(ignore -> worldManagerProvider.get().saveWorldsConfig())
219-
.flatMap(ignore ->anchorManagerProvider.get().saveAllAnchors())
220-
.onFailure(e -> {
221-
Logging.severe("Failed to save configs, things may not work as expected.");
222-
});
217+
.andThenTry(() -> worldManagerProvider.get().saveWorldsConfig())
218+
.andThenTry(() -> anchorManagerProvider.get().saveAllAnchors())
219+
.onFailure(e ->
220+
Logging.severe("Failed to save all configs, things may not work as expected. %s",
221+
e.getLocalizedMessage()));
223222
}
224223

225224
/**

src/main/java/org/mvplugins/multiverse/core/commands/ConfigCommand.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,10 @@ private void showConfigValue(MVCommandIssuer issuer, String name) {
6767
private void updateConfigValue(MVCommandIssuer issuer, String name, String value) {
6868
var stringPropertyHandle = config.getStringPropertyHandle();
6969
stringPropertyHandle.setPropertyString(issuer.getIssuer(), name, value)
70-
.onSuccess(ignore -> {
71-
config.save();
72-
issuer.sendMessage(MVCorei18n.CONFIG_SET_SUCCESS,
73-
Replace.NAME.with(name),
74-
Replace.VALUE.with(stringPropertyHandle.getProperty(name).getOrNull()));
75-
})
70+
.andThenTry(config::save)
71+
.onSuccess(ignore -> issuer.sendMessage(MVCorei18n.CONFIG_SET_SUCCESS,
72+
Replace.NAME.with(name),
73+
Replace.VALUE.with(stringPropertyHandle.getProperty(name).getOrNull())))
7674
.onFailure(e -> issuer.sendMessage(MVCorei18n.CONFIG_SET_ERROR,
7775
Replace.NAME.with(name),
7876
Replace.VALUE.with(value),

src/main/java/org/mvplugins/multiverse/core/commands/EntitySpawnConfigCommand.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,10 @@ void onModifyCommand(
113113
.getSpawnCategoryConfig(spawnCategory)
114114
.getStringPropertyHandle()
115115
.modifyPropertyString(property, value, action)
116+
.andThenTry(worldManager::saveWorldsConfig)
116117
.onSuccess(ignore -> issuer.sendInfo("Successfully set " + property + " to " + value
117118
+ " for " + spawnCategory.name() + " in " + world.getName()))
118119
.onFailure(e -> issuer.sendError("Unable to set " + property + " to " + value
119120
+ " for " + spawnCategory.name() + " in " + world.getName() + ": " + e.getMessage()));
120-
121-
worldManager.saveWorldsConfig();
122121
}
123122
}

src/main/java/org/mvplugins/multiverse/core/commands/ModifyCommand.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,28 +94,28 @@ void onModifyCommand(// SUPPRESS CHECKSTYLE: ParameterNumber
9494
}
9595

9696
StringPropertyHandle worldPropertyHandle = world.getStringPropertyHandle();
97-
worldPropertyHandle.modifyPropertyString(issuer.getIssuer(), propertyName, propertyValue, action).onSuccess(ignore -> {
98-
issuer.sendMessage(MVCorei18n.MODIFY_SUCCESS,
97+
worldPropertyHandle.modifyPropertyString(issuer.getIssuer(), propertyName, propertyValue, action)
98+
.andThenTry(worldManager::saveWorldsConfig)
99+
.onSuccess(ignore -> issuer.sendMessage(MVCorei18n.MODIFY_SUCCESS,
99100
replace("{action}").with(action.name().toLowerCase()),
100101
replace("{property}").with(propertyName),
101102
Replace.VALUE.with(worldPropertyHandle.getProperty(propertyName).getOrNull()),
102-
Replace.WORLD.with(world.getName()));
103-
worldManager.saveWorldsConfig();
104-
}).onFailure(exception -> {
105-
if (propertyValue == null) {
106-
issuer.sendMessage(MVCorei18n.MODIFY_FAILURE_NOVALUE,
107-
replace("{action}").with(action.name().toLowerCase()),
108-
replace("{property}").with(propertyName),
109-
Replace.WORLD.with(world.getName()),
110-
Replace.ERROR.with(exception.getMessage()));
111-
} else {
112-
issuer.sendMessage(MVCorei18n.MODIFY_FAILURE,
113-
replace("{action}").with(action.name().toLowerCase()),
114-
replace("{property}").with(propertyName),
115-
Replace.VALUE.with(propertyValue),
116-
Replace.WORLD.with(world.getName()),
117-
Replace.ERROR.with(exception.getMessage()));
118-
}
103+
Replace.WORLD.with(world.getName())))
104+
.onFailure(exception -> {
105+
if (propertyValue == null) {
106+
issuer.sendMessage(MVCorei18n.MODIFY_FAILURE_NOVALUE,
107+
replace("{action}").with(action.name().toLowerCase()),
108+
replace("{property}").with(propertyName),
109+
Replace.WORLD.with(world.getName()),
110+
Replace.ERROR.with(exception.getMessage()));
111+
} else {
112+
issuer.sendMessage(MVCorei18n.MODIFY_FAILURE,
113+
replace("{action}").with(action.name().toLowerCase()),
114+
replace("{property}").with(propertyName),
115+
Replace.VALUE.with(propertyValue),
116+
Replace.WORLD.with(world.getName()),
117+
Replace.ERROR.with(exception.getMessage()));
118+
}
119119
});
120120
}
121121

src/main/java/org/mvplugins/multiverse/core/commands/SetSpawnCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void onSetSpawnCommand(
6363

6464
worldManager.getLoadedWorld(location.getWorld())
6565
.peek(mvWorld -> mvWorld.setSpawnLocation(location)
66-
.flatMap(ignore -> worldManager.saveWorldsConfig())
66+
.andThenTry(worldManager::saveWorldsConfig)
6767
.onSuccess(ignore -> issuer.sendMessage(MVCorei18n.SETSPAWN_SUCCESS,
6868
Replace.WORLD.with(mvWorld.getName()),
6969
Replace.LOCATION.with(prettyLocation(location))))

src/main/java/org/mvplugins/multiverse/core/world/WorldConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ Try<Void> load(ConfigurationSection section) {
130130
}
131131

132132
Try<Void> save() {
133-
return configHandle.save();
133+
return configHandle.save().onFailure(ex ->
134+
Logging.warning("Failed to save world config for world '%s'. %s",
135+
worldName, ex.getLocalizedMessage()));
134136
}
135137

136138
ConfigurationSection getConfigurationSection() {

0 commit comments

Comments
 (0)