mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-28 13:36:33 +01:00
Fix loading game rules
This commit is contained in:
parent
0212a865f8
commit
d0042949fc
@ -144,13 +144,6 @@ public interface Dungeon {
|
||||
*/
|
||||
GameRuleContainer getOverrideValues();
|
||||
|
||||
/**
|
||||
* Sets the game rule container whose values override all values of the game rule containers of the dungeon's maps.
|
||||
*
|
||||
* @param rules the override values
|
||||
*/
|
||||
void setOverrideValues(GameRuleContainer rules);
|
||||
|
||||
/**
|
||||
* The values from this game rule container will be overriden by values of the game rule containers of the dungeon's maps. They will however still override
|
||||
* the values from the main config.
|
||||
@ -159,14 +152,6 @@ public interface Dungeon {
|
||||
*/
|
||||
GameRuleContainer getDefaultValues();
|
||||
|
||||
/**
|
||||
* Sets the game rule container whose values will be overriden by values of the game rule containers of the dungeon's maps. They will however still override
|
||||
* the values from the main config.
|
||||
*
|
||||
* @param rules the default values
|
||||
*/
|
||||
void setDefaultValues(GameRuleContainer rules);
|
||||
|
||||
/**
|
||||
* Returns true if the floor is either in the floors list or the start / end floor.
|
||||
*
|
||||
|
@ -309,7 +309,7 @@ public class GameRule<V> {
|
||||
/**
|
||||
* Messages; also to be created with /dxl msg
|
||||
*/
|
||||
public static final GameRule<Map<Integer, String>> MESSAGES = new MapGameRule<>("msgs", new HashMap<>(), (api, value) -> {
|
||||
public static final GameRule<Map<Integer, String>> MESSAGES = new MapGameRule<>("messages", new HashMap<>(), (api, value) -> {
|
||||
if (!(value instanceof ConfigurationSection)) {
|
||||
return null;
|
||||
}
|
||||
@ -463,4 +463,9 @@ public class GameRule<V> {
|
||||
writeTo.setState(this, overridingValue != null ? overridingValue : subsidiaryValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GameRule{key=" + key + "}";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -116,4 +116,9 @@ public class GameRuleContainer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GameRuleContainer{" + rules + "}";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -82,6 +82,7 @@ import de.erethon.dungeonsxl.util.PlaceholderUtil;
|
||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||
import de.erethon.dungeonsxl.world.DWorldListener;
|
||||
import de.erethon.dungeonsxl.world.LWCIntegration;
|
||||
import de.erethon.dungeonsxl.world.WorldConfig;
|
||||
import de.erethon.dungeonsxl.world.WorldUnloadTask;
|
||||
import de.erethon.vignette.api.VignetteAPI;
|
||||
import java.io.File;
|
||||
@ -155,12 +156,26 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI {
|
||||
@Override
|
||||
public void add(String key, GameRule rule) {
|
||||
super.add(key, rule);
|
||||
GameRuleContainer.DEFAULT_VALUES.setState(rule, rule.getDefaultValue());
|
||||
if (loaded) {
|
||||
GameRuleContainer.DEFAULT_VALUES.setState(rule, rule.getDefaultValue());
|
||||
mainConfig.getDefaultWorldConfig().updateGameRule(rule);
|
||||
for (Dungeon apiDungeon : dungeonRegistry) {
|
||||
DDungeon dungeon = ((DDungeon) apiDungeon);
|
||||
if (dungeon.isMultiFloor()) {
|
||||
dungeon.getConfig().getDefaultValues().updateGameRule(rule);
|
||||
dungeon.getConfig().getOverrideValues().updateGameRule(rule);
|
||||
} else {
|
||||
WorldConfig cfg = ((DResourceWorld) dungeon.getMap()).getConfig(false);
|
||||
cfg.updateGameRule(rule);
|
||||
}
|
||||
}
|
||||
dungeonRegistry.forEach(Dungeon::setupRules);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean loadingWorld;
|
||||
private boolean loaded, loadingWorld;
|
||||
|
||||
private GlobalData globalData;
|
||||
private MainConfig mainConfig;
|
||||
@ -287,6 +302,10 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI {
|
||||
signRegistry.add("WAVE", WaveSign.class);
|
||||
Bukkit.getPluginManager().registerEvents(new DSignListener(this), this);
|
||||
|
||||
for (GameRule rule : GameRule.VALUES) {
|
||||
gameRuleRegistry.add(rule.getKey(), rule);
|
||||
}
|
||||
|
||||
// Maps
|
||||
for (File file : MAPS.listFiles()) {
|
||||
if (file.isDirectory() && !file.getName().equals(".raw")) {
|
||||
@ -323,10 +342,6 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI {
|
||||
globalData = new GlobalData(this, new File(getDataFolder(), "data.yml"));
|
||||
globalData.load();
|
||||
|
||||
for (GameRule rule : GameRule.VALUES) {
|
||||
gameRuleRegistry.add(rule.getKey(), rule);
|
||||
}
|
||||
|
||||
// Mobs - Supported providers
|
||||
for (ExternalMobPlugin externalMobPlugin : ExternalMobPlugin.values()) {
|
||||
externalMobProviderRegistry.add(externalMobPlugin.getIdentifier(), externalMobPlugin);
|
||||
@ -375,6 +390,7 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI {
|
||||
}
|
||||
|
||||
dCommands.register(this);
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
public void saveData() {
|
||||
|
@ -149,21 +149,11 @@ public class DDungeon implements Dungeon {
|
||||
return config.getOverrideValues();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOverrideValues(GameRuleContainer rules) {
|
||||
config.setOverrideValues(rules);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameRuleContainer getDefaultValues() {
|
||||
return config.getDefaultValues();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultValues(GameRuleContainer rules) {
|
||||
config.setDefaultValues(rules);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameRuleContainer getRules() {
|
||||
return rules;
|
||||
|
@ -18,7 +18,6 @@ package de.erethon.dungeonsxl.dungeon;
|
||||
|
||||
import de.erethon.commons.config.DREConfig;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.dungeon.GameRuleContainer;
|
||||
import de.erethon.dungeonsxl.api.world.ResourceWorld;
|
||||
import de.erethon.dungeonsxl.world.WorldConfig;
|
||||
import java.io.File;
|
||||
@ -42,8 +41,8 @@ public class DungeonConfig extends DREConfig {
|
||||
private List<ResourceWorld> floors = new ArrayList<>();
|
||||
private int floorCount;
|
||||
private boolean removeWhenPlayed;
|
||||
private GameRuleContainer overrideValues;
|
||||
private GameRuleContainer defaultValues;
|
||||
private WorldConfig overrideValues;
|
||||
private WorldConfig defaultValues;
|
||||
|
||||
public DungeonConfig(DungeonsXL plugin, File file) {
|
||||
super(file, CONFIG_VERSION);
|
||||
@ -100,22 +99,14 @@ public class DungeonConfig extends DREConfig {
|
||||
this.removeWhenPlayed = removeWhenPlayed;
|
||||
}
|
||||
|
||||
public GameRuleContainer getOverrideValues() {
|
||||
public WorldConfig getOverrideValues() {
|
||||
return overrideValues;
|
||||
}
|
||||
|
||||
public void setOverrideValues(GameRuleContainer worldConfig) {
|
||||
overrideValues = worldConfig;
|
||||
}
|
||||
|
||||
public GameRuleContainer getDefaultValues() {
|
||||
public WorldConfig getDefaultValues() {
|
||||
return defaultValues;
|
||||
}
|
||||
|
||||
public void setDefaultValues(GameRuleContainer worldConfig) {
|
||||
defaultValues = worldConfig;
|
||||
}
|
||||
|
||||
public boolean containsFloor(ResourceWorld resource) {
|
||||
return floors.contains(resource) || startFloor.equals(resource) || endFloor.equals(resource);
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ public class WorldConfig extends GameRuleContainer {
|
||||
private DungeonsXL plugin;
|
||||
|
||||
private File file;
|
||||
private ConfigurationSection config;
|
||||
|
||||
private List<String> invitedPlayers = new ArrayList<>();
|
||||
private Environment worldEnvironment;
|
||||
@ -51,21 +52,23 @@ public class WorldConfig extends GameRuleContainer {
|
||||
this(plugin);
|
||||
|
||||
this.file = file;
|
||||
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
|
||||
load(configFile);
|
||||
config = YamlConfiguration.loadConfiguration(file);
|
||||
load();
|
||||
}
|
||||
|
||||
public WorldConfig(DungeonsXL plugin, ConfigurationSection config) {
|
||||
this(plugin);
|
||||
|
||||
load(config);
|
||||
this.config = config;
|
||||
load();
|
||||
}
|
||||
|
||||
// Load & Save
|
||||
public void load(ConfigurationSection config) {
|
||||
for (GameRule rule : plugin.getGameRuleRegistry()) {
|
||||
rule.fromConfig(plugin, this, config);
|
||||
}
|
||||
public void load() {
|
||||
plugin.getGameRuleRegistry().forEach(this::updateGameRule);
|
||||
}
|
||||
|
||||
public void updateGameRule(GameRule rule) {
|
||||
rule.fromConfig(plugin, this, config);
|
||||
}
|
||||
|
||||
public void save() {
|
||||
@ -76,7 +79,7 @@ public class WorldConfig extends GameRuleContainer {
|
||||
|
||||
if (getState(GameRule.MESSAGES) != null) {
|
||||
for (int msgs : getState(GameRule.MESSAGES).keySet()) {
|
||||
configFile.set("message." + msgs, getState(GameRule.MESSAGES).get(msgs));
|
||||
configFile.set("messages." + msgs, getState(GameRule.MESSAGES).get(msgs));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user