Search in sources :

Example 1 with LostWand

use of com.elmakers.mine.bukkit.wand.LostWand in project MagicPlugin by elBukkit.

the class MagicController method loadLostWands.

protected void loadLostWands() {
    try {
        ConfigurationSection lostWandConfiguration = loadDataFile(LOST_WANDS_FILE);
        if (lostWandConfiguration != null) {
            Set<String> wandIds = lostWandConfiguration.getKeys(false);
            for (String wandId : wandIds) {
                if (wandId == null || wandId.length() == 0)
                    continue;
                LostWand lostWand = new LostWand(wandId, lostWandConfiguration.getConfigurationSection(wandId));
                if (!lostWand.isValid()) {
                    getLogger().info("Skipped invalid entry in lostwands.yml file, entry will be deleted. The wand is really lost now!");
                    continue;
                }
                addLostWand(lostWand);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    getLogger().info("Loaded " + lostWands.size() + " lost wands");
}
Also used : LostWand(com.elmakers.mine.bukkit.wand.LostWand) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException) IOException(java.io.IOException) ParseException(java.text.ParseException) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 2 with LostWand

use of com.elmakers.mine.bukkit.wand.LostWand in project MagicPlugin by elBukkit.

the class MagicController method removeLostWand.

public boolean removeLostWand(String wandId) {
    if (wandId == null || wandId.length() == 0 || !lostWands.containsKey(wandId))
        return false;
    LostWand lostWand = lostWands.get(wandId);
    lostWands.remove(wandId);
    String chunkKey = getChunkKey(lostWand.getLocation());
    if (chunkKey == null)
        return false;
    Set<String> chunkWands = lostWandChunks.get(chunkKey);
    if (chunkWands != null) {
        chunkWands.remove(wandId);
        if (chunkWands.size() == 0) {
            lostWandChunks.remove(chunkKey);
        }
    }
    if (dynmapShowWands) {
        if (removeMarker("wand-" + wandId, "Wands")) {
            info("Wand removed from map");
        }
    }
    return true;
}
Also used : LostWand(com.elmakers.mine.bukkit.wand.LostWand)

Example 3 with LostWand

use of com.elmakers.mine.bukkit.wand.LostWand in project MagicPlugin by elBukkit.

the class MagicController method saveLostWands.

protected void saveLostWands(Collection<YamlDataFile> stores) {
    String lastKey = "";
    try {
        YamlDataFile lostWandsConfiguration = createDataFile(LOST_WANDS_FILE);
        for (Entry<String, LostWand> wandEntry : lostWands.entrySet()) {
            lastKey = wandEntry.getKey();
            if (lastKey == null || lastKey.length() == 0)
                continue;
            ConfigurationSection wandNode = lostWandsConfiguration.createSection(lastKey);
            if (wandNode == null) {
                getLogger().warning("Error saving lost wand data for " + lastKey);
                continue;
            }
            if (!wandEntry.getValue().isValid()) {
                getLogger().warning("Invalid lost and data for " + lastKey);
                continue;
            }
            wandEntry.getValue().save(wandNode);
        }
        stores.add(lostWandsConfiguration);
    } catch (Throwable ex) {
        getLogger().warning("Error saving lost wand data for " + lastKey);
        ex.printStackTrace();
    }
}
Also used : LostWand(com.elmakers.mine.bukkit.wand.LostWand) YamlDataFile(com.elmakers.mine.bukkit.data.YamlDataFile) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Aggregations

LostWand (com.elmakers.mine.bukkit.wand.LostWand)3 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)2 YamlDataFile (com.elmakers.mine.bukkit.data.YamlDataFile)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 InvalidConfigurationException (org.bukkit.configuration.InvalidConfigurationException)1