use of au.com.mineauz.minigames.config.MinigameSave in project Minigames by AddstarMC.
the class Minigames method setupLoadOuts.
private void setupLoadOuts() {
final MinigameSave globalLoadouts = new MinigameSave("globalLoadouts");
final Set<String> keys = globalLoadouts.getConfig().getKeys(false);
for (final String loadout : keys) {
this.minigameManager.addLoadout(loadout);
ConfigurationSection loadOutSection = globalLoadouts.getConfig().getConfigurationSection(loadout);
if (loadOutSection != null) {
final Set<String> items = loadOutSection.getKeys(false);
for (final String slot : items) {
if (COMPILE.matcher(slot).matches()) {
this.minigameManager.getLoadout(loadout).addItem(globalLoadouts.getConfig().getItemStack(loadout + '.' + slot), Integer.parseInt(slot));
}
}
}
if (globalLoadouts.getConfig().contains(loadout + ".potions")) {
ConfigurationSection potionLoadOutSection = globalLoadouts.getConfig().getConfigurationSection(loadout + ".potions");
if (potionLoadOutSection != null) {
final Set<String> pots = potionLoadOutSection.getKeys(false);
for (final String eff : pots) {
PotionEffectType type = PotionEffectType.getByName(eff);
if (type != null) {
final PotionEffect effect = new PotionEffect(type, globalLoadouts.getConfig().getInt(loadout + ".potions." + eff + ".dur"), globalLoadouts.getConfig().getInt(loadout + ".potions." + eff + ".amp"));
this.minigameManager.getLoadout(loadout).addPotionEffect(effect);
}
}
}
}
if (globalLoadouts.getConfig().contains(loadout + ".usepermissions")) {
this.minigameManager.getLoadout(loadout).setUsePermissions(globalLoadouts.getConfig().getBoolean(loadout + ".usepermissions"));
}
}
}
use of au.com.mineauz.minigames.config.MinigameSave in project Minigames by AddstarMC.
the class Minigames method onDisable.
public void onDisable() {
if (getPlugin() == null) {
log().info("Minigames is disabled");
return;
}
final PluginDescriptionFile desc = this.getDescription();
for (final Player p : this.getServer().getOnlinePlayers()) {
if (this.playerManager.getMinigamePlayer(p).isInMinigame()) {
this.playerManager.quitMinigame(this.playerManager.getMinigamePlayer(p), true);
}
}
for (final Minigame minigame : this.minigameManager.getAllMinigames().values()) {
if (minigame.getType() == MinigameType.GLOBAL && "treasure_hunt".equals(minigame.getMechanicName()) && minigame.isEnabled()) {
if (minigame.getMinigameTimer() != null) {
minigame.getMinigameTimer().stopTimer();
}
TreasureHuntMechanic.removeTreasure(minigame);
}
}
for (final Minigame mg : this.minigameManager.getAllMinigames().values()) {
mg.saveMinigame();
}
this.backend.shutdown();
this.playerManager.saveDeniedCommands();
final MinigameSave globalLoadouts = new MinigameSave("globalLoadouts");
if (this.minigameManager.hasLoadouts()) {
for (final String loadout : this.minigameManager.getLoadouts()) {
for (final Integer slot : this.minigameManager.getLoadout(loadout).getItems()) {
globalLoadouts.getConfig().set(loadout + '.' + slot, this.minigameManager.getLoadout(loadout).getItem(slot));
}
if (!this.minigameManager.getLoadout(loadout).getAllPotionEffects().isEmpty()) {
for (final PotionEffect eff : this.minigameManager.getLoadout(loadout).getAllPotionEffects()) {
globalLoadouts.getConfig().set(loadout + ".potions." + eff.getType().getName() + ".amp", eff.getAmplifier());
globalLoadouts.getConfig().set(loadout + ".potions." + eff.getType().getName() + ".dur", eff.getDuration());
}
} else {
globalLoadouts.getConfig().set(loadout + ".potions", null);
}
if (this.minigameManager.getLoadout(loadout).getUsePermissions()) {
globalLoadouts.getConfig().set(loadout + ".usepermissions", true);
} else {
globalLoadouts.getConfig().set(loadout + ".usepermissions", null);
}
}
} else {
globalLoadouts.getConfig().set("globalloadouts", null);
}
globalLoadouts.saveConfig();
this.minigameManager.saveRewardSigns();
resourceManager.saveResources();
log().info(desc.getName() + " successfully disabled.");
}
use of au.com.mineauz.minigames.config.MinigameSave in project Minigames by AddstarMC.
the class Minigame method loadMinigame.
public void loadMinigame() {
MinigameSave minigame = new MinigameSave(name, "config");
FileConfiguration cfg = minigame.getConfig();
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) {
Material material = Material.matchMaterial(block);
if (material == null) {
material = Material.matchMaterial(block, true);
if (material == null) {
Minigames.log().info(" Failed to match config material.");
Minigames.log().info(block + " did not match a material please update config: " + this.name);
} else {
Minigames.log().info(block + " is a legacy material please review the config we will attempt to auto update..but you may want to add newer materials GAME: " + this.name);
getBlockRecorder().addWBBlock(material);
}
} else {
getBlockRecorder().addWBBlock(material);
}
}
}
// 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.getPlugin(), () -> Minigames.getPlugin().getMinigameManager().startGlobalMinigame(mgm, null));
}
getScoreboardData().loadDisplays(minigame, this);
ListenableFuture<Map<MinigameStat, StatSettings>> settingsFuture = Minigames.getPlugin().getBackend().loadStatSettings(this);
Minigames.getPlugin().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.config.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<>();
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.getPlugin().getBackend().saveStatSettings(this, statSettings.values());
minigame.saveConfig();
}
use of au.com.mineauz.minigames.config.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.getPlugin().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!";
}
}
Aggregations