use of au.com.mineauz.minigames.MinigameSave in project Minigames by AddstarMC.
the class PresetLoader method getPresetInfo.
public static String getPresetInfo(String preset) {
preset = preset.toLowerCase();
File file = new File(Minigames.plugin.getDataFolder() + "/presets/" + preset + ".yml");
if (file.exists()) {
MinigameSave save = new MinigameSave("presets/" + preset);
FileConfiguration config = save.getConfig();
if (config.contains(preset + ".info"))
return config.getString(preset + ".info");
else
return "No information given on this preset.";
}
return ChatColor.RED + "Failed to load preset: " + ChatColor.GRAY + preset + ".yml was not found in the presets folder!";
}
use of au.com.mineauz.minigames.MinigameSave in project Minigames by AddstarMC.
the class PresetLoader method loadPreset.
public static String loadPreset(String preset, Minigame minigame) {
preset = preset.toLowerCase();
File file = new File(Minigames.plugin.getDataFolder() + "/presets/" + preset + ".yml");
if (file.exists()) {
MinigameSave save = new MinigameSave("presets/" + preset);
FileConfiguration config = save.getConfig();
for (String opt : config.getConfigurationSection(preset).getKeys(false)) {
Flag<?> flag = minigame.getConfigFlag(opt);
if (flag != null) {
flag.loadValue(preset, config);
}
}
return ChatColor.GRAY + "Loaded the " + MinigameUtils.capitalize(preset) + " preset to " + minigame.getName(false);
} else {
return ChatColor.RED + "Failed to load preset: " + ChatColor.GRAY + preset + ".yml was not found in the presets folder!";
}
}
use of au.com.mineauz.minigames.MinigameSave in project Minigames by AddstarMC.
the class Minigame method loadMinigame.
public void loadMinigame() {
MinigameSave minigame = new MinigameSave(name, "config");
FileConfiguration cfg = minigame.getConfig();
//TODO: Remove me after 1.7
if (cfg.contains(name + ".type")) {
//Minigames.plugin.getLogger().warning("Your configuration files ("+cfg.getCurrentPath()+") are of an old version. They will not be supported past ver1.11");
if (cfg.getString(name + ".type").equals("TEAMS")) {
cfg.set(name + ".type", "MULTIPLAYER");
TeamsModule.getMinigameModule(this).addTeam(TeamColor.RED);
TeamsModule.getMinigameModule(this).addTeam(TeamColor.BLUE);
} else if (cfg.getString(name + ".type").equals("FREE_FOR_ALL")) {
cfg.set(name + ".type", "MULTIPLAYER");
} else if (cfg.getString(name + ".type").equals("TREASURE_HUNT")) {
cfg.set(name + ".type", "GLOBAL");
cfg.set(name + ".scoretype", "treasure_hunt");
cfg.set(name + ".timer", Minigames.plugin.getConfig().getInt("treasurehunt.findtime") * 60);
}
}
for (MinigameModule module : getModules()) {
if (!module.useSeparateConfig()) {
module.load(cfg);
if (module.getFlags() != null) {
for (String flag : module.getFlags().keySet()) {
if (cfg.contains(name + "." + flag))
module.getFlags().get(flag).loadValue(name, cfg);
}
}
} else {
MinigameSave modsave = new MinigameSave("minigames/" + name + "/" + module.getName().toLowerCase());
module.load(modsave.getConfig());
if (module.getFlags() != null) {
for (String flag : module.getFlags().keySet()) {
if (modsave.getConfig().contains(name + "." + flag))
module.getFlags().get(flag).loadValue(name, modsave.getConfig());
}
}
}
}
for (String flag : configFlags.keySet()) {
if (cfg.contains(name + "." + flag))
configFlags.get(flag).loadValue(name, cfg);
}
if (minigame.getConfig().contains(name + ".whitelistmode")) {
getBlockRecorder().setWhitelistMode(minigame.getConfig().getBoolean(name + ".whitelistmode"));
}
if (minigame.getConfig().contains(name + ".whitelistblocks")) {
List<String> blocklist = minigame.getConfig().getStringList(name + ".whitelistblocks");
for (String block : blocklist) {
getBlockRecorder().addWBBlock(Material.matchMaterial(block));
}
}
// Bukkit.getLogger().info("------- Minigame Load -------");
// Bukkit.getLogger().info("Name: " + getName());
// Bukkit.getLogger().info("Type: " + getType());
// Bukkit.getLogger().info("Enabled: " + isEnabled());
// Bukkit.getLogger().info("-----------------------------");
final Minigame mgm = this;
if (getType() == MinigameType.GLOBAL && isEnabled()) {
Bukkit.getScheduler().scheduleSyncDelayedTask(Minigames.plugin, new Runnable() {
@Override
public void run() {
Minigames.plugin.mdata.startGlobalMinigame(mgm, null);
}
});
}
getScoreboardData().loadDisplays(minigame, this);
ListenableFuture<Map<MinigameStat, StatSettings>> settingsFuture = Minigames.plugin.getBackend().loadStatSettings(this);
Minigames.plugin.getBackend().addServerThreadCallback(settingsFuture, new FutureCallback<Map<MinigameStat, StatSettings>>() {
@Override
public void onSuccess(Map<MinigameStat, StatSettings> result) {
statSettings.clear();
statSettings.putAll(result);
getScoreboardData().reload();
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
});
saveMinigame();
}
use of au.com.mineauz.minigames.MinigameSave in project Minigames by AddstarMC.
the class Minigame method saveMinigame.
public void saveMinigame() {
MinigameSave minigame = new MinigameSave(name, "config");
FileConfiguration cfg = minigame.getConfig();
cfg.set(name, null);
cfg.createSection(name);
for (MinigameModule module : getModules()) {
if (!module.useSeparateConfig()) {
module.save(cfg);
if (module.getFlags() != null) {
for (Flag<?> flag : module.getFlags().values()) {
if (flag.getFlag() != null && (flag.getDefaultFlag() == null || !flag.getDefaultFlag().equals(flag.getFlag())))
flag.saveValue(name, cfg);
}
}
} else {
MinigameSave modsave = new MinigameSave("minigames/" + name + "/" + module.getName().toLowerCase());
modsave.getConfig().set(name, null);
modsave.getConfig().createSection(name);
module.save(modsave.getConfig());
if (module.getFlags() != null) {
for (Flag<?> flag : module.getFlags().values()) {
if (flag.getFlag() != null && (flag.getDefaultFlag() == null || !flag.getDefaultFlag().equals(flag.getFlag())))
flag.saveValue(name, modsave.getConfig());
}
}
modsave.saveConfig();
}
}
for (String configOpt : configFlags.keySet()) {
if (configFlags.get(configOpt).getFlag() != null && (configFlags.get(configOpt).getDefaultFlag() == null || !configFlags.get(configOpt).getDefaultFlag().equals(configFlags.get(configOpt).getFlag())))
configFlags.get(configOpt).saveValue(name, cfg);
}
if (!getBlockRecorder().getWBBlocks().isEmpty()) {
List<String> blocklist = new ArrayList<String>();
for (Material mat : getBlockRecorder().getWBBlocks()) {
blocklist.add(mat.toString());
}
minigame.getConfig().set(name + ".whitelistblocks", blocklist);
}
if (getBlockRecorder().getWhitelistMode()) {
minigame.getConfig().set(name + ".whitelistmode", getBlockRecorder().getWhitelistMode());
}
getScoreboardData().saveDisplays(minigame, name);
getScoreboardData().refreshDisplays();
Minigames.plugin.getBackend().saveStatSettings(this, statSettings.values());
minigame.saveConfig();
}
Aggregations