public boolean apply(SpellCastEvent event) {
   Player player = event.getCaster();
   boolean check = condition.check(player);
   if (check == false && type == ModifierType.REQUIRED) {
     event.setCancelled(true);
     return false;
   } else if (check == true && type == ModifierType.DENIED) {
     event.setCancelled(true);
     return false;
   } else if (check == true) {
     if (type == ModifierType.STOP) {
       return false;
     } else if (type == ModifierType.POWER) {
       event.increasePower(modifierVarFloat);
     } else if (type == ModifierType.ADD_POWER) {
       event.setPower(event.getPower() + modifierVarFloat);
     } else if (type == ModifierType.COOLDOWN) {
       event.setCooldown(modifierVarFloat);
     } else if (type == ModifierType.REAGENTS) {
       event.setReagents(event.getReagents().multiply(modifierVarFloat));
     } else if (type == ModifierType.CAST_TIME) {
       event.setCastTime(modifierVarInt);
     }
   } else if (check == false && type == ModifierType.CONTINUE) {
     return false;
   } else if (check == true && type == ModifierType.CAST) {
     Spell spell = MagicSpells.getSpellByInternalName(modifierVar);
     if (spell != null) {
       spell.cast(event.getCaster(), event.getPower(), event.getSpellArgs());
     }
   } else if (check == true && type == ModifierType.CAST_INSTEAD) {
     Spell spell = MagicSpells.getSpellByInternalName(modifierVar);
     if (spell != null) {
       spell.cast(event.getCaster(), event.getPower(), event.getSpellArgs());
     }
     event.setCancelled(true);
   }
   return true;
 }
Exemplo n.º 2
0
 @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
 public void onSpellCast(SpellCastEvent event) {
   if (isActive(event.getCaster()) && !event.getSpell().getInternalName().equals(internalName)) {
     turnOff(event.getCaster());
   }
 }
Exemplo n.º 3
0
 private boolean activateSpells(
     Player caster, LivingEntity target, Location location, float basePower) {
   SpellCastState state = getCastState(caster);
   MagicSpells.debug(
       3,
       "Activating passive spell '"
           + name
           + "' for player "
           + caster.getName()
           + " (state: "
           + state
           + ")");
   if (!disabled
       && (chance >= .999 || random.nextFloat() <= chance)
       && state == SpellCastState.NORMAL) {
     disabled = true;
     SpellCastEvent event =
         new SpellCastEvent(
             this,
             caster,
             SpellCastState.NORMAL,
             basePower,
             null,
             this.cooldown,
             this.reagents.clone(),
             0);
     Bukkit.getPluginManager().callEvent(event);
     if (!event.isCancelled() && event.getSpellCastState() == SpellCastState.NORMAL) {
       if (event.haveReagentsChanged() && !hasReagents(caster, event.getReagents())) {
         disabled = false;
         return false;
       }
       setCooldown(caster, event.getCooldown());
       basePower = event.getPower();
       for (Spell spell : spells) {
         MagicSpells.debug(3, "    Casting spell effect '" + spell.getName() + "'");
         if (castWithoutTarget) {
           MagicSpells.debug(3, "    Casting without target");
           spell.castSpell(caster, SpellCastState.NORMAL, basePower, null);
           playSpellEffects(EffectPosition.CASTER, caster);
         } else if (spell instanceof TargetedEntitySpell
             && target != null
             && !isNonTargetedExternal(spell)) {
           MagicSpells.debug(3, "    Casting at entity");
           SpellTargetEvent targetEvent = new SpellTargetEvent(this, caster, target, basePower);
           Bukkit.getPluginManager().callEvent(targetEvent);
           if (!targetEvent.isCancelled()) {
             target = targetEvent.getTarget();
             ((TargetedEntitySpell) spell).castAtEntity(caster, target, targetEvent.getPower());
             playSpellEffects(caster, target);
           } else {
             MagicSpells.debug(3, "      Target cancelled (TE)");
           }
         } else if (spell instanceof TargetedLocationSpell
             && (location != null || target != null)) {
           MagicSpells.debug(3, "    Casting at location");
           Location loc = null;
           if (location != null) {
             loc = location;
           } else if (target != null) {
             loc = target.getLocation();
           }
           if (loc != null) {
             SpellTargetLocationEvent targetEvent =
                 new SpellTargetLocationEvent(this, caster, loc, basePower);
             Bukkit.getPluginManager().callEvent(targetEvent);
             if (!targetEvent.isCancelled()) {
               loc = targetEvent.getTargetLocation();
               ((TargetedLocationSpell) spell).castAtLocation(caster, loc, targetEvent.getPower());
               playSpellEffects(caster, loc);
             } else {
               MagicSpells.debug(3, "      Target cancelled (TL)");
             }
           }
         } else {
           MagicSpells.debug(3, "    Casting normally");
           float power = basePower;
           if (target != null) {
             SpellTargetEvent targetEvent = new SpellTargetEvent(this, caster, target, power);
             Bukkit.getPluginManager().callEvent(targetEvent);
             if (!targetEvent.isCancelled()) {
               power = targetEvent.getPower();
             } else {
               MagicSpells.debug(3, "      Target cancelled (UE)");
               continue;
             }
           } else if (location != null) {
             SpellTargetLocationEvent targetEvent =
                 new SpellTargetLocationEvent(this, caster, location, basePower);
             Bukkit.getPluginManager().callEvent(targetEvent);
             if (!targetEvent.isCancelled()) {
               power = targetEvent.getPower();
             } else {
               MagicSpells.debug(3, "      Target cancelled (UL)");
               continue;
             }
           }
           spell.castSpell(caster, SpellCastState.NORMAL, power, null);
           playSpellEffects(EffectPosition.CASTER, caster);
         }
       }
       removeReagents(caster, event.getReagents());
       sendMessage(caster, strCastSelf);
       SpellCastedEvent event2 =
           new SpellCastedEvent(
               this,
               caster,
               SpellCastState.NORMAL,
               basePower,
               null,
               event.getCooldown(),
               event.getReagents(),
               PostCastAction.HANDLE_NORMALLY);
       Bukkit.getPluginManager().callEvent(event2);
       disabled = false;
       return true;
     } else {
       MagicSpells.debug(3, "   Passive spell canceled");
       disabled = false;
       return false;
     }
   } else if (state != SpellCastState.NORMAL && sendFailureMessages) {
     if (state == SpellCastState.ON_COOLDOWN) {
       MagicSpells.sendMessage(
           caster, formatMessage(strOnCooldown, "%c", Math.round(getCooldown(caster)) + ""));
     } else if (state == SpellCastState.MISSING_REAGENTS) {
       MagicSpells.sendMessage(caster, strMissingReagents);
       if (MagicSpells.showStrCostOnMissingReagents() && strCost != null && !strCost.isEmpty()) {
         MagicSpells.sendMessage(caster, "    (" + strCost + ")");
       }
     }
   }
   return false;
 }