mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-28 13:36:33 +01:00
Recode global data loading; resolves #122
This commit is contained in:
parent
cc19684407
commit
ddb955a8c1
@ -212,7 +212,7 @@ public class DungeonsXL extends DREPlugin {
|
|||||||
|
|
||||||
public void loadConfig() {
|
public void loadConfig() {
|
||||||
messageConfig = new MessageConfig(DMessage.class, new File(LANGUAGES, "english.yml"));
|
messageConfig = new MessageConfig(DMessage.class, new File(LANGUAGES, "english.yml"));
|
||||||
globalData = new GlobalData(new File(getDataFolder(), "data.yml"));
|
globalData = new GlobalData(this, new File(getDataFolder(), "data.yml"));
|
||||||
mainConfig = new MainConfig(this, new File(getDataFolder(), "config.yml"));
|
mainConfig = new MainConfig(this, new File(getDataFolder(), "config.yml"));
|
||||||
messageConfig = new MessageConfig(DMessage.class, new File(LANGUAGES, mainConfig.getLanguage() + ".yml"));
|
messageConfig = new MessageConfig(DMessage.class, new File(LANGUAGES, mainConfig.getLanguage() + ".yml"));
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.block.SignChangeEvent;
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
import org.bukkit.material.Attachable;
|
import org.bukkit.material.Attachable;
|
||||||
@ -49,6 +49,10 @@ public class GameSign extends JoinSign {
|
|||||||
super(plugin, id, startSign, identifier, maxGroupsPerGame, startIfElementsAtLeast);
|
super(plugin, id, startSign, identifier, maxGroupsPerGame, startIfElementsAtLeast);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GameSign(DungeonsXL plugin, World world, int id, ConfigurationSection config) {
|
||||||
|
super(plugin, world, id, config);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the attached game
|
* @return the attached game
|
||||||
*/
|
*/
|
||||||
@ -117,20 +121,6 @@ public class GameSign extends JoinSign {
|
|||||||
sign.update();
|
sign.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void save(FileConfiguration config) {
|
|
||||||
String preString = "protections.gameSigns." + getWorld().getName() + "." + getId();
|
|
||||||
|
|
||||||
config.set(preString + ".x", startSign.getX());
|
|
||||||
config.set(preString + ".y", startSign.getY());
|
|
||||||
config.set(preString + ".z", startSign.getZ());
|
|
||||||
if (dungeon != null) {
|
|
||||||
config.set(preString + ".dungeon", dungeon.getName());
|
|
||||||
}
|
|
||||||
config.set(preString + ".maxGroupsPerGame", maxElements);
|
|
||||||
config.set(preString + ".startIfElementsAtLeast", startIfElementsAtLeast);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPlayerInteract(Block block, Player player) {
|
public void onPlayerInteract(Block block, Player player) {
|
||||||
DGroup dGroup = DGroup.getByPlayer(player);
|
DGroup dGroup = DGroup.getByPlayer(player);
|
||||||
if (dGroup == null) {
|
if (dGroup == null) {
|
||||||
|
@ -17,7 +17,11 @@
|
|||||||
package de.erethon.dungeonsxl.global;
|
package de.erethon.dungeonsxl.global;
|
||||||
|
|
||||||
import de.erethon.commons.config.DREConfig;
|
import de.erethon.commons.config.DREConfig;
|
||||||
|
import de.erethon.dungeonsxl.DungeonsXL;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the global data.yml.
|
* Represents the global data.yml.
|
||||||
@ -26,11 +30,15 @@ import java.io.File;
|
|||||||
*/
|
*/
|
||||||
public class GlobalData extends DREConfig {
|
public class GlobalData extends DREConfig {
|
||||||
|
|
||||||
|
private DungeonsXL plugin;
|
||||||
|
|
||||||
public static final int CONFIG_VERSION = 2;
|
public static final int CONFIG_VERSION = 2;
|
||||||
|
|
||||||
public GlobalData(File file) {
|
public GlobalData(DungeonsXL plugin, File file) {
|
||||||
super(file, CONFIG_VERSION);
|
super(file, CONFIG_VERSION);
|
||||||
|
|
||||||
|
this.plugin = plugin;
|
||||||
|
|
||||||
if (initialize) {
|
if (initialize) {
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
@ -44,7 +52,27 @@ public class GlobalData extends DREConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load() {
|
public void load() {
|
||||||
// Load?
|
for (World world : Bukkit.getWorlds()) {
|
||||||
|
ConfigurationSection gameSigns = config.getConfigurationSection("protections.gameSigns." + world.getName());
|
||||||
|
ConfigurationSection groupSigns = config.getConfigurationSection("protections.groupSigns." + world.getName());
|
||||||
|
if (gameSigns == null && groupSigns == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
while (true) {
|
||||||
|
String key = String.valueOf("i");
|
||||||
|
if (gameSigns != null && gameSigns.contains(key)) {
|
||||||
|
new GameSign(plugin, world, i, gameSigns.getConfigurationSection(key));
|
||||||
|
}
|
||||||
|
if (groupSigns != null && groupSigns.contains(key)) {
|
||||||
|
new GroupSign(plugin, world, i, groupSigns.getConfigurationSection(key));
|
||||||
|
|
||||||
|
} else if ((gameSigns == null || !gameSigns.contains(key)) && (groupSigns == null || !groupSigns.contains(key))) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.block.SignChangeEvent;
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
@ -50,6 +51,11 @@ public class GroupSign extends JoinSign {
|
|||||||
this.groupName = groupName;
|
this.groupName = groupName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GroupSign(DungeonsXL plugin, World world, int id, ConfigurationSection config) {
|
||||||
|
super(plugin, world, id, config);
|
||||||
|
groupName = config.getString("groupName");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the attached group
|
* @return the attached group
|
||||||
*/
|
*/
|
||||||
@ -120,17 +126,9 @@ public class GroupSign extends JoinSign {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(FileConfiguration config) {
|
public void save(FileConfiguration config) {
|
||||||
|
super.save(config);
|
||||||
String preString = "protections.groupSigns." + getWorld().getName() + "." + getId();
|
String preString = "protections.groupSigns." + getWorld().getName() + "." + getId();
|
||||||
|
|
||||||
config.set(preString + ".x", startSign.getX());
|
|
||||||
config.set(preString + ".y", startSign.getY());
|
|
||||||
config.set(preString + ".z", startSign.getZ());
|
|
||||||
if (dungeon != null) {
|
|
||||||
config.set(preString + ".dungeon", dungeon.getName());
|
|
||||||
}
|
|
||||||
config.set(preString + ".groupName", groupName);
|
config.set(preString + ".groupName", groupName);
|
||||||
config.set(preString + ".maxPlayersPerGroup", maxElements);
|
|
||||||
config.set(preString + ".startIfElementsAtLeast", startIfElementsAtLeast);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPlayerInteract(Block block, Player player) {
|
public void onPlayerInteract(Block block, Player player) {
|
||||||
|
@ -22,8 +22,10 @@ import de.erethon.dungeonsxl.dungeon.Dungeon;
|
|||||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,6 +63,37 @@ public class JoinSign extends GlobalProtection {
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected JoinSign(DungeonsXL plugin, World world, int id, ConfigurationSection config) {
|
||||||
|
super(plugin, world, id);
|
||||||
|
|
||||||
|
startSign = world.getBlockAt(config.getInt("x"), config.getInt("y"), config.getInt("z"));
|
||||||
|
String identifier = config.getString("dungeon");
|
||||||
|
dungeon = plugin.getDungeonCache().getByName(identifier);
|
||||||
|
if (dungeon == null) {
|
||||||
|
DResourceWorld resource = plugin.getDWorldCache().getResourceByName(identifier);
|
||||||
|
if (resource != null) {
|
||||||
|
dungeon = new Dungeon(plugin, resource);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
verticalSigns = (int) Math.ceil((float) (1 + maxElements) / 4);
|
||||||
|
|
||||||
|
// LEGACY
|
||||||
|
if (config.contains("maxElements")) {
|
||||||
|
maxElements = config.getInt("maxElements");
|
||||||
|
} else if (config.contains("maxGroupsPerGame")) {
|
||||||
|
maxElements = config.getInt("maxGroupsPerGame");
|
||||||
|
} else if (config.contains("maxPlayersPerGroup")) {
|
||||||
|
maxElements = config.getInt("maxPlayersPerGroup");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startIfElementsAtLeast > 0 && startIfElementsAtLeast <= maxElements) {
|
||||||
|
startIfElementsAtLeast = config.getInt("startIfElementsAtLeast");
|
||||||
|
}
|
||||||
|
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the dungeon
|
* @return the dungeon
|
||||||
*/
|
*/
|
||||||
@ -159,6 +192,16 @@ public class JoinSign extends GlobalProtection {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(FileConfiguration config) {
|
public void save(FileConfiguration config) {
|
||||||
|
String preString = "protections.groupSigns." + getWorld().getName() + "." + getId();
|
||||||
|
|
||||||
|
config.set(preString + ".x", startSign.getX());
|
||||||
|
config.set(preString + ".y", startSign.getY());
|
||||||
|
config.set(preString + ".z", startSign.getZ());
|
||||||
|
if (dungeon != null) {
|
||||||
|
config.set(preString + ".dungeon", dungeon.getName());
|
||||||
|
}
|
||||||
|
config.set(preString + ".maxElements", maxElements);
|
||||||
|
config.set(preString + ".startIfElementsAtLeast", startIfElementsAtLeast);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user