Search in sources :

Example 1 with PathUpgradeEvent

use of com.elmakers.mine.bukkit.api.event.PathUpgradeEvent in project MagicPlugin by elBukkit.

the class WandUpgradePath method upgrade.

@Override
public void upgrade(com.elmakers.mine.bukkit.api.wand.Wand wand, com.elmakers.mine.bukkit.api.magic.Mage mage) {
    WandUpgradePath newPath = getUpgrade();
    if (newPath == null) {
        if (mage != null)
            mage.sendMessage("Configuration issue, please check logs");
        wand.getController().getLogger().warning("Invalid upgrade path: " + this.getUpgrade());
        return;
    }
    if (mage != null) {
        MageController controller = mage.getController();
        mage.sendMessage(getMessage(controller.getMessages(), "level_up").replace("$wand", wand.getName()).replace("$path", newPath.getName()));
    }
    this.upgraded(wand, mage);
    if (this.icon != null && this.icon.equals(wand.getIcon())) {
        com.elmakers.mine.bukkit.api.block.MaterialAndData newIcon = newPath.getIcon();
        if (newIcon != null) {
            wand.setIcon(newIcon);
        }
    }
    newPath.upgradeTo(wand);
    // Don't do events without a mage
    if (mage == null) {
        return;
    }
    WandUpgradeEvent legacyEvent = new WandUpgradeEvent(mage, wand, this, newPath);
    Bukkit.getPluginManager().callEvent(legacyEvent);
    PathUpgradeEvent upgradeEvent = new PathUpgradeEvent(mage, wand, wand.getMageClass(), this, newPath);
    Bukkit.getPluginManager().callEvent(upgradeEvent);
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) WandUpgradeEvent(com.elmakers.mine.bukkit.api.event.WandUpgradeEvent) PathUpgradeEvent(com.elmakers.mine.bukkit.api.event.PathUpgradeEvent)

Aggregations

PathUpgradeEvent (com.elmakers.mine.bukkit.api.event.PathUpgradeEvent)1 WandUpgradeEvent (com.elmakers.mine.bukkit.api.event.WandUpgradeEvent)1 MageController (com.elmakers.mine.bukkit.api.magic.MageController)1