mirror of
https://github.com/NLthijs48/AreaShop.git
synced 2025-02-21 14:22:12 +01:00
Fix default settings leaking when getting configuration sections
- Default settings and custom settings are in separate YamlConfiguration instances now to prevent leaking - When getting a configuration section you now know that either it is from the current default.yml file or the default.yml file in the jar (querying settings from the section will always have the same source) - Fixed a startup null pointer - Fixed #266
This commit is contained in:
parent
b18a7cc6d5
commit
b525c5902c
@ -39,6 +39,7 @@ public class FileManager {
|
|||||||
private YamlConfiguration groupsConfig = null;
|
private YamlConfiguration groupsConfig = null;
|
||||||
private String defaultPath = null;
|
private String defaultPath = null;
|
||||||
private YamlConfiguration defaultConfig = null;
|
private YamlConfiguration defaultConfig = null;
|
||||||
|
private YamlConfiguration defaultConfigFallback = null;
|
||||||
private boolean saveGroupsRequired = false;
|
private boolean saveGroupsRequired = false;
|
||||||
private Set<String> worldRegionsRequireSaving;
|
private Set<String> worldRegionsRequireSaving;
|
||||||
|
|
||||||
@ -112,10 +113,14 @@ public class FileManager {
|
|||||||
public Collection<RegionGroup> getGroups() {
|
public Collection<RegionGroup> getGroups() {
|
||||||
return groups.values();
|
return groups.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
public YamlConfiguration getDefaultSettings() {
|
public YamlConfiguration getRegionSettings() {
|
||||||
return defaultConfig;
|
return defaultConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public YamlConfiguration getFallbackRegionSettings() {
|
||||||
|
return defaultConfigFallback;
|
||||||
|
}
|
||||||
|
|
||||||
public YamlConfiguration getConfig() {
|
public YamlConfiguration getConfig() {
|
||||||
return config;
|
return config;
|
||||||
@ -763,9 +768,8 @@ public class FileManager {
|
|||||||
if(defaultConfig.getKeys(false).size() == 0) {
|
if(defaultConfig.getKeys(false).size() == 0) {
|
||||||
AreaShop.warn("File 'default.yml' is empty, check for errors in the log.");
|
AreaShop.warn("File 'default.yml' is empty, check for errors in the log.");
|
||||||
result = false;
|
result = false;
|
||||||
} else {
|
|
||||||
defaultConfig.addDefaults(YamlConfiguration.loadConfiguration(normal));
|
|
||||||
}
|
}
|
||||||
|
defaultConfigFallback = YamlConfiguration.loadConfiguration(normal);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import me.wiefferink.areashop.AreaShop;
|
|||||||
import me.wiefferink.areashop.Utils;
|
import me.wiefferink.areashop.Utils;
|
||||||
import me.wiefferink.areashop.events.NotifyRegionEvent;
|
import me.wiefferink.areashop.events.NotifyRegionEvent;
|
||||||
import me.wiefferink.areashop.events.notify.UpdateRegionEvent;
|
import me.wiefferink.areashop.events.notify.UpdateRegionEvent;
|
||||||
import me.wiefferink.areashop.features.Feature;
|
|
||||||
import me.wiefferink.areashop.features.FriendsFeature;
|
import me.wiefferink.areashop.features.FriendsFeature;
|
||||||
import me.wiefferink.areashop.features.SignsFeature;
|
import me.wiefferink.areashop.features.SignsFeature;
|
||||||
import me.wiefferink.areashop.interfaces.GeneralRegionInterface;
|
import me.wiefferink.areashop.interfaces.GeneralRegionInterface;
|
||||||
@ -43,8 +42,6 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
|||||||
private FriendsFeature friendsFeature;
|
private FriendsFeature friendsFeature;
|
||||||
private SignsFeature signsFeature;
|
private SignsFeature signsFeature;
|
||||||
|
|
||||||
private Map<Class, Feature> features;
|
|
||||||
|
|
||||||
// Enum for region types
|
// Enum for region types
|
||||||
public enum RegionType {
|
public enum RegionType {
|
||||||
RENT("rent"),
|
RENT("rent"),
|
||||||
@ -160,13 +157,8 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
|||||||
* Setup the features of this class
|
* Setup the features of this class
|
||||||
*/
|
*/
|
||||||
private void setupFeatures() {
|
private void setupFeatures() {
|
||||||
addFeature(new FriendsFeature(this));
|
friendsFeature = new FriendsFeature(this);
|
||||||
addFeature(new SignsFeature(this));
|
signsFeature = new SignsFeature(this);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void addFeature(Feature feature) {
|
|
||||||
features.put(feature.getClass(), feature);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1277,11 +1269,15 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
|||||||
if(found) {
|
if(found) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.getFileManager().getDefaultSettings().isString(path)) {
|
if(this.getFileManager().getRegionSettings().isString(path)) {
|
||||||
return this.getFileManager().getDefaultSettings().getString(path).equalsIgnoreCase("true");
|
return this.getFileManager().getRegionSettings().getString(path).equalsIgnoreCase("true");
|
||||||
|
}
|
||||||
|
if(this.getFileManager().getRegionSettings().isSet(path)) {
|
||||||
|
return this.getFileManager().getRegionSettings().getBoolean(path);
|
||||||
|
} else {
|
||||||
|
return this.getFileManager().getFallbackRegionSettings().getBoolean(path);
|
||||||
}
|
}
|
||||||
return this.getFileManager().getDefaultSettings().getBoolean(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1309,7 +1305,12 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
|||||||
if(found) {
|
if(found) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return this.getFileManager().getDefaultSettings().getInt(path);
|
|
||||||
|
if(this.getFileManager().getRegionSettings().isSet(path)) {
|
||||||
|
return this.getFileManager().getRegionSettings().getInt(path);
|
||||||
|
} else {
|
||||||
|
return this.getFileManager().getFallbackRegionSettings().getInt(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1337,7 +1338,12 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
|||||||
if(found) {
|
if(found) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return this.getFileManager().getDefaultSettings().getDouble(path);
|
|
||||||
|
if(this.getFileManager().getRegionSettings().isSet(path)) {
|
||||||
|
return this.getFileManager().getRegionSettings().getDouble(path);
|
||||||
|
} else {
|
||||||
|
return this.getFileManager().getFallbackRegionSettings().getDouble(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1365,7 +1371,12 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
|||||||
if(found) {
|
if(found) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return this.getFileManager().getDefaultSettings().getLong(path);
|
|
||||||
|
if(this.getFileManager().getRegionSettings().isSet(path)) {
|
||||||
|
return this.getFileManager().getRegionSettings().getLong(path);
|
||||||
|
} else {
|
||||||
|
return this.getFileManager().getFallbackRegionSettings().getLong(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1393,7 +1404,12 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
|||||||
if(found) {
|
if(found) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return this.getFileManager().getDefaultSettings().getString(path);
|
|
||||||
|
if(this.getFileManager().getRegionSettings().isSet(path)) {
|
||||||
|
return this.getFileManager().getRegionSettings().getString(path);
|
||||||
|
} else {
|
||||||
|
return this.getFileManager().getFallbackRegionSettings().getString(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1421,7 +1437,12 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
|||||||
if(found) {
|
if(found) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return this.getFileManager().getDefaultSettings().getStringList(path);
|
|
||||||
|
if(this.getFileManager().getRegionSettings().isSet(path)) {
|
||||||
|
return this.getFileManager().getRegionSettings().getStringList(path);
|
||||||
|
} else {
|
||||||
|
return this.getFileManager().getFallbackRegionSettings().getStringList(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1449,7 +1470,12 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
|||||||
if(found) {
|
if(found) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return this.getFileManager().getDefaultSettings().getConfigurationSection(path);
|
|
||||||
|
if(this.getFileManager().getRegionSettings().isSet(path)) {
|
||||||
|
return this.getFileManager().getRegionSettings().getConfigurationSection(path);
|
||||||
|
} else {
|
||||||
|
return this.getFileManager().getFallbackRegionSettings().getConfigurationSection(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1493,7 +1519,11 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!found) {
|
if(!found) {
|
||||||
result = this.getFileManager().getDefaultSettings().get(path);
|
if(this.getFileManager().getRegionSettings().isSet(path)) {
|
||||||
|
result = this.getFileManager().getRegionSettings().getConfigurationSection(path);
|
||||||
|
} else {
|
||||||
|
result = this.getFileManager().getFallbackRegionSettings().getConfigurationSection(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user