Skip to content

Commit

Permalink
Fixed the config values being overwritten when modified by file. Now …
Browse files Browse the repository at this point in the history
…only overwrites when modified at runtime by the plugin.
  • Loading branch information
me4502 committed Oct 31, 2016
1 parent 3fb8598 commit 8581308
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Expand Up @@ -28,11 +28,11 @@ repositories {
}

dependencies {
compile 'org.spongepowered:spongeapi:5.0.0-SNAPSHOT'
compile 'org.spongepowered:spongeapi:6.0.0-SNAPSHOT'
compile 'com.google.guava:guava:18.0'
compile 'com.google.code.findbugs:jsr305:1.3.9'
compile 'com.owlike:genson:1.3'
compile 'com.me4502:ModularFramework:1.4.1'
compile 'com.me4502:ModularFramework:1.5'
compile 'com.sk89q.worldedit:worldedit-sponge-mc1.10.2:6.1.4-SNAPSHOT:dev'
testCompile 'org.mockito:mockito-core:2.+'
testCompile 'junit:junit:5.+'
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
#Fri Oct 14 12:08:00 AEST 2016
#Sat Oct 22 21:32:59 AEST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-bin.zip
21 changes: 19 additions & 2 deletions src/main/java/com/sk89q/craftbook/core/util/ConfigValue.java
Expand Up @@ -23,6 +23,8 @@
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;

import java.util.Objects;

public class ConfigValue<T> {

private String key;
Expand All @@ -32,6 +34,8 @@ public class ConfigValue<T> {

private TypeToken<T> typeToken;

private boolean modified;

public ConfigValue(String key, String comment, T value) {
this(key, comment, value, null);
}
Expand All @@ -45,15 +49,25 @@ public ConfigValue(String key, String comment, T value, TypeToken<T> typeToken)

public ConfigValue<T> load(ConfigurationNode configurationNode) {
this.value = getValueInternal(configurationNode);
save(configurationNode);
setValueInternal(configurationNode); // Directly bypass modified checks.
return this;
}

public ConfigValue<T> save(ConfigurationNode configurationNode) {
setValueInternal(configurationNode);
if (this.modified) {
setValueInternal(configurationNode);
}
return this;
}

public boolean isModified() {
return this.modified;
}

public void setModified(boolean modified) {
this.modified = modified;
}

public String getKey() {
return this.key;
}
Expand All @@ -79,6 +93,9 @@ public T getDefaultValue() {
}

public void setValue(T value) {
if (!Objects.equals(value, this.value)) {
this.modified = true;
}
this.value = value;
}

Expand Down
Expand Up @@ -51,7 +51,8 @@

import java.io.File;

@Plugin(id = "craftbook", name = "CraftBook", version = "4.0")
@Plugin(id = "craftbook", name = "CraftBook", version = "4.0",
description = "CraftBook adds a number of new mechanics to Minecraft with no client mods required.")
public class CraftBookPlugin extends CraftBookAPI {

private MechanicDataCache cache;
Expand Down Expand Up @@ -209,6 +210,7 @@ public void discoverMechanics() {
configDir.mkdir();
moduleController.setConfigurationDirectory(configDir);
moduleController.setConfigurationOptions(configurationOptions);
moduleController.setOverrideConfigurationNode(true);

//Standard Mechanics
moduleController.registerModule("com.sk89q.craftbook.sponge.mechanics.variable.Variables");
Expand Down
Expand Up @@ -67,6 +67,9 @@ public void load() {

public void save() {
try {
// Reload the actual config to account for changes. But don't load it back into the ConfigValues.
config = configManager.load(CraftBookPlugin.<CraftBookPlugin>inst().configurationOptions);

enabledMechanics.save(config);
dataOnlyMode.save(config);

Expand Down

0 comments on commit 8581308

Please sign in to comment.