@EventHandler(priority = EventPriority.LOW) public void onManaRegen(ManaChangeEvent event) { if (event.getReason() == ManaChangeReason.REGEN) { ModifierSet modifiers = MagicSpells.getManaHandler().getModifiers(); if (modifiers != null) { modifiers.apply(event); } } }
public boolean apply(ManaChangeEvent event) { Player player = event.getPlayer(); boolean check = condition.check(player); if (check == false && type == ModifierType.REQUIRED) { event.setNewAmount(event.getOldAmount()); return false; } else if (check == true && type == ModifierType.DENIED) { event.setNewAmount(event.getOldAmount()); return false; } else if (check == true && type == ModifierType.STOP) { return false; } else if (check == false && type == ModifierType.CONTINUE) { return false; } else if (check == true && type == ModifierType.POWER) { int gain = event.getNewAmount() - event.getOldAmount(); gain = Math.round(gain * modifierVarFloat); int newAmt = event.getOldAmount() + gain; if (newAmt > event.getMaxMana()) newAmt = event.getMaxMana(); event.setNewAmount(newAmt); } else if (check == true && type == ModifierType.ADD_POWER) { int newAmt = event.getNewAmount() + (int) modifierVarFloat; if (newAmt > event.getMaxMana()) newAmt = event.getMaxMana(); event.setNewAmount(newAmt); } else if (check == true && (type == ModifierType.CAST || type == ModifierType.CAST_INSTEAD)) { Spell spell = MagicSpells.getSpellByInternalName(modifierVar); if (spell != null) { spell.cast(event.getPlayer(), 1, null); } } return true; }