use of au.com.mineauz.minigames.config.MinigameSave in project Minigames by AddstarMC.
the class Minigames method setupMinigames.
private void setupMinigames() {
this.minigameManager = new MinigameManager();
this.playerManager = new MinigamePlayerManager();
this.display = new DisplayManager();
this.resourceManager = new ResourcePackManager();
final MinigameSave resources = new MinigameSave("resources");
this.minigameManager.addConfigurationFile("resources", resources.getConfig());
this.resourceManager.initialize(resources);
this.minigameManager.addMinigameType(new SingleplayerType());
this.minigameManager.addMinigameType(new MultiplayerType());
final MinigameSave completion = new MinigameSave("completion");
this.minigameManager.addConfigurationFile("completion", completion.getConfig());
this.getServer().getPluginManager().registerEvents(new Events(), this);
this.getServer().getPluginManager().registerEvents(new BasicRecorder(), this);
try {
this.getConfig().load(this.getDataFolder() + "/config.yml");
List<String> mgs = new ArrayList<>();
if (this.getConfig().contains("minigames")) {
mgs = this.getConfig().getStringList("minigames");
}
this.debug = this.getConfig().getBoolean("debug", false);
final List<String> allMGS = new ArrayList<>(mgs);
if (!mgs.isEmpty()) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
for (final String minigame : allMGS) {
final Minigame game = new Minigame(minigame);
try {
game.loadMinigame();
this.minigameManager.addMinigame(game);
} catch (final Exception e) {
this.getLogger().severe(ChatColor.RED + "Failed to load \"" + minigame + "\"! The configuration file may be corrupt or missing!");
e.printStackTrace();
}
}
}, 1L);
}
} catch (final FileNotFoundException ex) {
log().info("Failed to load config, creating one.");
try {
this.getConfig().save(this.getDataFolder() + "/config.yml");
} catch (final IOException e) {
log().log(Level.SEVERE, "Could not save config.yml!");
e.printStackTrace();
}
} catch (final Exception e) {
log().log(Level.SEVERE, "Failed to load config!");
e.printStackTrace();
}
}
use of au.com.mineauz.minigames.config.MinigameSave in project Minigames by AddstarMC.
the class StoredPlayerCheckpoints method saveCheckpoints.
public void saveCheckpoints() {
MinigameSave save = new MinigameSave("playerdata/checkpoints/" + uuid);
save.deleteFile();
if (hasNoCheckpoints())
return;
save = new MinigameSave("playerdata/checkpoints/" + uuid);
for (String mgm : checkpoints.keySet()) {
MinigameUtils.debugMessage("Attempting to save checkpoint for " + mgm + "...");
try {
save.getConfig().set(mgm, null);
save.getConfig().set(mgm + ".x", checkpoints.get(mgm).getX());
save.getConfig().set(mgm + ".y", checkpoints.get(mgm).getY());
save.getConfig().set(mgm + ".z", checkpoints.get(mgm).getZ());
save.getConfig().set(mgm + ".yaw", checkpoints.get(mgm).getYaw());
save.getConfig().set(mgm + ".pitch", checkpoints.get(mgm).getPitch());
save.getConfig().set(mgm + ".world", checkpoints.get(mgm).getWorld().getName());
if (flags.containsKey(mgm))
save.getConfig().set(mgm + ".flags", getFlags(mgm));
if (storedTime.containsKey(mgm))
save.getConfig().set(mgm + ".time", getTime(mgm));
if (storedDeaths.containsKey(mgm))
save.getConfig().set(mgm + ".deaths", getDeaths(mgm));
if (storedReverts.containsKey(mgm))
save.getConfig().set(mgm + ".reverts", getReverts(mgm));
} catch (Exception e) {
// When an error is detected, remove the stored erroneous checkpoint
Minigames.getPlugin().getLogger().warning("Unable to save checkpoint for " + mgm + "! It has been been removed.");
e.printStackTrace();
// Remove the checkpoint from memory so it doesn't cause an error again
save.getConfig().set(mgm, null);
checkpoints.remove(mgm);
flags.remove(mgm);
storedTime.remove(mgm);
storedDeaths.remove(mgm);
storedReverts.remove(mgm);
}
}
if (hasGlobalCheckpoint()) {
try {
save.getConfig().set("globalcheckpoint.x", globalCheckpoint.getX());
save.getConfig().set("globalcheckpoint.y", globalCheckpoint.getY());
save.getConfig().set("globalcheckpoint.z", globalCheckpoint.getZ());
save.getConfig().set("globalcheckpoint.yaw", globalCheckpoint.getYaw());
save.getConfig().set("globalcheckpoint.pitch", globalCheckpoint.getPitch());
save.getConfig().set("globalcheckpoint.world", globalCheckpoint.getWorld().getName());
} catch (Exception e) {
// When an error is detected, remove the global checkpoint
save.getConfig().set("globalcheckpoint", null);
Minigames.getPlugin().getLogger().warning("Unable to save global checkpoint!");
e.printStackTrace();
}
}
save.saveConfig();
}
use of au.com.mineauz.minigames.config.MinigameSave in project Minigames by AddstarMC.
the class StoredPlayerCheckpoints method loadCheckpoints.
public void loadCheckpoints() {
MinigameSave save = new MinigameSave("playerdata/checkpoints/" + uuid);
Set<String> mgms = save.getConfig().getKeys(false);
for (String mgm : mgms) {
if (!mgm.equals("globalcheckpoint")) {
MinigameUtils.debugMessage("Attempting to load checkpoint for " + mgm + "...");
try {
Double locx = (Double) save.getConfig().get(mgm + ".x");
Double locy = (Double) save.getConfig().get(mgm + ".y");
Double locz = (Double) save.getConfig().get(mgm + ".z");
Float yaw = new Float(save.getConfig().get(mgm + ".yaw").toString());
Float pitch = new Float(save.getConfig().get(mgm + ".pitch").toString());
String world = (String) save.getConfig().get(mgm + ".world");
World w = Minigames.getPlugin().getServer().getWorld(world);
if (w == null) {
Minigames.getPlugin().getLogger().warning("WARNING: Invalid world \"" + world + "\" found in checkpoint for " + mgm + "! Checkpoint has been removed.");
continue;
}
Location loc = new Location(w, locx, locy, locz, yaw, pitch);
checkpoints.put(mgm, loc);
} catch (ClassCastException e) {
MinigameUtils.debugMessage("Checkpoint could not be loaded ... " + mgm + " xyz not double");
} catch (NullPointerException e) {
e.printStackTrace();
}
if (save.getConfig().contains(mgm + ".flags")) {
flags.put(mgm, save.getConfig().getStringList(mgm + ".flags"));
}
if (save.getConfig().contains(mgm + ".time")) {
storedTime.put(mgm, save.getConfig().getLong(mgm + ".time"));
}
if (save.getConfig().contains(mgm + ".deaths")) {
storedDeaths.put(mgm, save.getConfig().getInt(mgm + ".deaths"));
}
if (save.getConfig().contains(mgm + ".reverts")) {
storedReverts.put(mgm, save.getConfig().getInt(mgm + ".reverts"));
}
}
}
if (save.getConfig().contains("globalcheckpoint")) {
double x = save.getConfig().getDouble("globalcheckpoint.x");
double y = save.getConfig().getDouble("globalcheckpoint.y");
double z = save.getConfig().getDouble("globalcheckpoint.z");
Float yaw = new Float(save.getConfig().get("globalcheckpoint.yaw").toString());
Float pitch = new Float(save.getConfig().get("globalcheckpoint.pitch").toString());
String world = save.getConfig().getString("globalcheckpoint.world");
World w = Minigames.getPlugin().getServer().getWorld(world);
if (w == null) {
Minigames.getPlugin().getLogger().warning("WARNING: Invalid world \"" + world + "\" found in global checkpoint! Checkpoint has been removed.");
} else {
globalCheckpoint = new Location(Minigames.getPlugin().getServer().getWorld(world), x, y, z, yaw, pitch);
}
}
}
Aggregations