use of com.elmakers.mine.bukkit.api.data.SpellData in project MagicPlugin by elBukkit.
the class MagicController method loadSpellData.
protected void loadSpellData() {
try {
ConfigurationSection configNode = loadDataFile(SPELLS_DATA_FILE);
if (configNode == null)
return;
Set<String> keys = configNode.getKeys(false);
for (String key : keys) {
ConfigurationSection node = configNode.getConfigurationSection(key);
SpellKey spellKey = new SpellKey(key);
SpellData templateData = templateDataMap.get(spellKey.getBaseKey());
if (templateData == null) {
templateData = new SpellData(spellKey.getBaseKey());
templateDataMap.put(templateData.getKey().getBaseKey(), templateData);
}
templateData.setCastCount(templateData.getCastCount() + node.getLong("cast_count", 0));
templateData.setLastCast(Math.max(templateData.getLastCast(), node.getLong("last_cast", 0)));
}
} catch (Exception ex) {
getLogger().warning("Failed to load spell metrics");
}
}
use of com.elmakers.mine.bukkit.api.data.SpellData in project MagicPlugin by elBukkit.
the class MagicController method saveSpellData.
protected void saveSpellData(Collection<YamlDataFile> stores) {
String lastKey = "";
try {
YamlDataFile spellsDataFile = createDataFile(SPELLS_DATA_FILE);
for (SpellData data : templateDataMap.values()) {
lastKey = data.getKey().getBaseKey();
ConfigurationSection spellNode = spellsDataFile.createSection(lastKey);
if (spellNode == null) {
getLogger().warning("Error saving spell data for " + lastKey);
continue;
}
spellNode.set("cast_count", data.getCastCount());
spellNode.set("last_cast", data.getLastCast());
}
stores.add(spellsDataFile);
} catch (Throwable ex) {
getLogger().warning("Error saving spell data for " + lastKey);
ex.printStackTrace();
}
}
use of com.elmakers.mine.bukkit.api.data.SpellData in project MagicPlugin by elBukkit.
the class MagicController method addSpell.
public void addSpell(Spell variant) {
SpellTemplate conflict = spells.get(variant.getKey());
if (conflict != null) {
getLogger().log(Level.WARNING, "Duplicate spell key: '" + conflict.getKey() + "'");
} else {
spells.put(variant.getKey(), variant);
SpellData data = templateDataMap.get(variant.getSpellKey().getBaseKey());
if (data == null) {
data = new SpellData(variant.getSpellKey().getBaseKey());
templateDataMap.put(variant.getSpellKey().getBaseKey(), data);
}
if (variant instanceof MageSpell) {
((MageSpell) variant).setSpellData(data);
}
String alias = variant.getAlias();
if (alias != null && alias.length() > 0) {
spellAliases.put(alias, variant);
}
}
}
use of com.elmakers.mine.bukkit.api.data.SpellData in project MagicPlugin by elBukkit.
the class Mage method onLoad.
protected void onLoad(MageData data) {
try {
Collection<SpellData> spellDataList = data == null ? null : data.getSpellData();
if (spellDataList != null) {
for (SpellData spellData : spellDataList) {
this.spellData.put(spellData.getKey().getKey(), spellData);
}
}
// Load player-specific data
Player player = getPlayer();
if (player != null) {
if (controller.isInventoryBackupEnabled()) {
if (restoreInventory != null) {
controller.getLogger().info("Restoring saved inventory for player " + player.getName() + " - did the server not shut down properly?");
if (activeWand != null) {
activeWand.deactivate();
}
Inventory inventory = player.getInventory();
for (int slot = 0; slot < restoreInventory.size(); slot++) {
Object item = restoreInventory.get(slot);
if (item instanceof ItemStack) {
inventory.setItem(slot, (ItemStack) item);
} else {
inventory.setItem(slot, null);
}
}
restoreInventory = null;
}
if (restoreExperience != null) {
player.setExp(restoreExperience);
restoreExperience = null;
}
if (restoreLevel != null) {
player.setLevel(restoreLevel);
restoreLevel = null;
}
}
if (activeWand == null) {
String welcomeWand = controller.getWelcomeWand();
if (!gaveWelcomeWand && welcomeWand.length() > 0) {
gaveWelcomeWand = true;
Wand wand = Wand.createWand(controller, welcomeWand);
if (wand != null) {
wand.takeOwnership(player);
giveItem(wand.getItem());
controller.getLogger().info("Gave welcome wand " + wand.getName() + " to " + player.getName());
} else {
controller.getLogger().warning("Unable to give welcome wand '" + welcomeWand + "' to " + player.getName());
}
}
}
if (activeWand != null && restoreOpenWand && !activeWand.isInventoryOpen()) {
activeWand.openInventory();
}
restoreOpenWand = false;
}
armorUpdated();
loading = false;
} catch (Exception ex) {
controller.getLogger().warning("Error finalizing player data for " + playerName + ": " + ex.getMessage());
}
}
use of com.elmakers.mine.bukkit.api.data.SpellData in project MagicPlugin by elBukkit.
the class Mage method getSpell.
@Nullable
@Override
public MageSpell getSpell(String key) {
if (loading)
return null;
MageSpell playerSpell = spells.get(key);
if (playerSpell == null) {
playerSpell = createSpell(key);
if (playerSpell != null) {
SpellData spellData = this.spellData.get(key);
if (spellData == null) {
spellData = new SpellData(key);
this.spellData.put(key, spellData);
}
playerSpell.load(spellData);
}
} else {
playerSpell.setMage(this);
}
return playerSpell;
}
Aggregations