com.nisovin.MagicSpells
Class Spell

java.lang.Object
  extended by com.nisovin.MagicSpells.Spell
All Implemented Interfaces:
java.lang.Comparable<Spell>
Direct Known Subclasses:
BuffSpell, ChanneledSpell, CommandSpell, ExternalCommandSpell, InstantSpell

public abstract class Spell
extends java.lang.Object
implements java.lang.Comparable<Spell>


Nested Class Summary
protected static class Spell.PostCastAction
           
protected static class Spell.SpellCastState
           
 
Field Summary
protected  int broadcastRange
           
protected  int castItem
           
protected  int cooldown
           
protected  org.bukkit.inventory.ItemStack[] cost
           
protected  java.lang.String description
           
protected  int healthCost
           
protected  java.lang.String internalName
           
protected  int manaCost
           
protected  java.lang.String name
           
protected  java.lang.String strCastOthers
           
protected  java.lang.String strCastSelf
           
protected  java.lang.String strCost
           
 
Constructor Summary
Spell(org.bukkit.util.config.Configuration config, java.lang.String spellName)
           
 
Method Summary
protected  void addListener(org.bukkit.event.Event.Type eventType)
          Makes this spell listen for the specified event
abstract  boolean canCastByCommand()
           
abstract  boolean canCastWithItem()
           
 Spell.SpellCastState cast(org.bukkit.entity.Player player)
           
 Spell.SpellCastState cast(org.bukkit.entity.Player player, java.lang.String[] args)
           
 boolean castFromConsole(org.bukkit.command.CommandSender sender, java.lang.String[] args)
          This method is called when the spell is cast from the console.
protected abstract  Spell.PostCastAction castSpell(org.bukkit.entity.Player player, Spell.SpellCastState state, java.lang.String[] args)
          This method is called when a player casts a spell, either by command, with a wand item, or otherwise.
 int compareTo(Spell spell)
           
static java.lang.String formatMessage(java.lang.String message, java.lang.String... replacements)
          Formats a string by performing the specified replacements.
 int getCastItem()
           
protected  boolean getConfigBoolean(java.lang.String key, boolean defaultValue)
          Access a boolean config value for this spell.
protected  int getConfigInt(java.lang.String key, int defaultValue)
          Access an integer config value for this spell.
protected  java.util.List<java.lang.Integer> getConfigIntList(java.lang.String key, java.util.List<java.lang.Integer> defaultValue)
           
protected  java.lang.String getConfigString(java.lang.String key, java.lang.String defaultValue)
          Access a String config value for this spell.
protected  java.util.List<java.lang.String> getConfigStringList(java.lang.String key, java.util.List<java.lang.String> defaultValue)
           
protected  int getCooldown(org.bukkit.entity.Player player)
          Get how many seconds remain on the cooldown of this spell for the specified player
 java.lang.String getCostStr()
           
 java.lang.String getDescription()
           
 int getHealthCost()
           
 java.lang.String getInternalName()
           
 int getManaCost()
           
 java.lang.String getName()
           
 org.bukkit.inventory.ItemStack[] getReagentCost()
           
protected  boolean hasReagents(org.bukkit.entity.Player player)
          Checks if a player has the reagents required to cast this spell
protected  boolean hasReagents(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack[] cost)
          Checks if a player has the specified reagents
protected  boolean hasReagents(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack[] reagents, int healthCost, int manaCost)
          Checks if a player has the specified reagents, including health and mana
protected  void initialize()
          This method is called immediately after all spells have been loaded into the plugin.
 void onBlockBreak(org.bukkit.event.block.BlockBreakEvent event)
           
 void onBlockPlace(org.bukkit.event.block.BlockPlaceEvent event)
           
protected  boolean onCooldown(org.bukkit.entity.Player player)
          Check whether this spell is currently on cooldown for the specified player
 void onEntityCombust(org.bukkit.event.entity.EntityCombustEvent event)
           
 void onEntityDamage(org.bukkit.event.entity.EntityDamageEvent event)
           
 void onEntityTarget(org.bukkit.event.entity.EntityTargetEvent event)
           
 void onExplosionPrime(org.bukkit.event.entity.ExplosionPrimeEvent event)
           
 void onItemHeldChange(org.bukkit.event.player.PlayerItemHeldEvent event)
           
 void onPlayerCommandPreprocess(org.bukkit.event.player.PlayerCommandPreprocessEvent event)
           
 void onPlayerInteract(org.bukkit.event.player.PlayerInteractEvent event)
           
 void onPlayerJoin(org.bukkit.event.player.PlayerJoinEvent event)
           
 void onPlayerMove(org.bukkit.event.player.PlayerMoveEvent event)
           
 void onPlayerQuit(org.bukkit.event.player.PlayerQuitEvent event)
           
 void onPlayerTeleport(org.bukkit.event.player.PlayerTeleportEvent event)
           
 void onPlayerToggleSneak(org.bukkit.event.player.PlayerToggleSneakEvent event)
           
protected  void removeListener(org.bukkit.event.Event.Type eventType)
          Makes this spell stop listening for the specified event
protected  void removeReagents(org.bukkit.entity.Player player)
          Removes the reagent cost of this spell from the player's inventoryy.
protected  void removeReagents(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack[] reagents)
          Removes the specified reagents from the player's inventoryy.
protected  void removeReagents(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack[] reagents, int healthCost, int manaCost)
          Removes the specified reagents, including health and mana, from the player's inventory.
static void sendMessage(org.bukkit.entity.Player player, java.lang.String message)
          Sends a message to a player.
static void sendMessage(org.bukkit.entity.Player player, java.lang.String message, java.lang.String... replacements)
          Sends a message to a player, first making the specified replacements.
protected  void sendMessageNear(org.bukkit.entity.Player player, java.lang.String message)
          Sends a message to all players near the specified player, within the configured broadcast range.
protected  void sendMessageNear(org.bukkit.entity.Player player, java.lang.String message, int range)
          Sends a message to all players near the specified player, within the specified broadcast range.
protected  void setCooldown(org.bukkit.entity.Player player)
          Begins the cooldown for the spell for the specified player
protected  void turnOff()
          This methid is called when the plugin is being disabled, for any reason.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

internalName

protected java.lang.String internalName

name

protected java.lang.String name

description

protected java.lang.String description

castItem

protected int castItem

cost

protected org.bukkit.inventory.ItemStack[] cost

healthCost

protected int healthCost

manaCost

protected int manaCost

cooldown

protected int cooldown

broadcastRange

protected int broadcastRange

strCost

protected java.lang.String strCost

strCastSelf

protected java.lang.String strCastSelf

strCastOthers

protected java.lang.String strCastOthers
Constructor Detail

Spell

public Spell(org.bukkit.util.config.Configuration config,
             java.lang.String spellName)
Method Detail

getConfigInt

protected int getConfigInt(java.lang.String key,
                           int defaultValue)
Access an integer config value for this spell.

Parameters:
key - The key of the config value
defaultValue - The value to return if it does not exist in the config
Returns:
The config value, or defaultValue if it does not exist

getConfigBoolean

protected boolean getConfigBoolean(java.lang.String key,
                                   boolean defaultValue)
Access a boolean config value for this spell.

Parameters:
key - The key of the config value
defaultValue - The value to return if it does not exist in the config
Returns:
The config value, or defaultValue if it does not exist

getConfigString

protected java.lang.String getConfigString(java.lang.String key,
                                           java.lang.String defaultValue)
Access a String config value for this spell.

Parameters:
key - The key of the config value
defaultValue - The value to return if it does not exist in the config
Returns:
The config value, or defaultValue if it does not exist

getConfigIntList

protected java.util.List<java.lang.Integer> getConfigIntList(java.lang.String key,
                                                             java.util.List<java.lang.Integer> defaultValue)

getConfigStringList

protected java.util.List<java.lang.String> getConfigStringList(java.lang.String key,
                                                               java.util.List<java.lang.String> defaultValue)

cast

public final Spell.SpellCastState cast(org.bukkit.entity.Player player)

cast

public final Spell.SpellCastState cast(org.bukkit.entity.Player player,
                                       java.lang.String[] args)

castSpell

protected abstract Spell.PostCastAction castSpell(org.bukkit.entity.Player player,
                                                  Spell.SpellCastState state,
                                                  java.lang.String[] args)
This method is called when a player casts a spell, either by command, with a wand item, or otherwise.

Parameters:
player - the player casting the spell
state - the state of the spell cast (normal, on cooldown, missing reagents, etc)
args - the spell arguments, if cast by command
Returns:
the action to take after the spell is processed

castFromConsole

public boolean castFromConsole(org.bukkit.command.CommandSender sender,
                               java.lang.String[] args)
This method is called when the spell is cast from the console.

Parameters:
sender - the console sender.
args - the command arguments
Returns:
true if the spell was handled, false otherwise

canCastWithItem

public abstract boolean canCastWithItem()

canCastByCommand

public abstract boolean canCastByCommand()

getCostStr

public java.lang.String getCostStr()

onCooldown

protected boolean onCooldown(org.bukkit.entity.Player player)
Check whether this spell is currently on cooldown for the specified player

Parameters:
player - The player to check
Returns:
whether the spell is on cooldown

getCooldown

protected int getCooldown(org.bukkit.entity.Player player)
Get how many seconds remain on the cooldown of this spell for the specified player

Parameters:
player - The player to check
Returns:
The number of seconds remaining in the cooldown

setCooldown

protected void setCooldown(org.bukkit.entity.Player player)
Begins the cooldown for the spell for the specified player

Parameters:
player - The player to set the cooldown for

hasReagents

protected boolean hasReagents(org.bukkit.entity.Player player)
Checks if a player has the reagents required to cast this spell

Parameters:
player - the player to check
Returns:
true if the player has the reagents, false otherwise

hasReagents

protected boolean hasReagents(org.bukkit.entity.Player player,
                              org.bukkit.inventory.ItemStack[] cost)
Checks if a player has the specified reagents

Parameters:
player - the player to check
cost - the reagents to look for
Returns:
true if the player has the reagents, false otherwise

hasReagents

protected boolean hasReagents(org.bukkit.entity.Player player,
                              org.bukkit.inventory.ItemStack[] reagents,
                              int healthCost,
                              int manaCost)
Checks if a player has the specified reagents, including health and mana

Parameters:
player - the player to check
reagents - the inventory item reagents to look for
healthCost - the health cost, in half-hearts
manaCost - the mana cost
Returns:
true if the player has all the reagents, false otherwise

removeReagents

protected void removeReagents(org.bukkit.entity.Player player)
Removes the reagent cost of this spell from the player's inventoryy. This does not check if the player has the reagents, use hasReagents() for that.

Parameters:
player - the player to remove reagents from

removeReagents

protected void removeReagents(org.bukkit.entity.Player player,
                              org.bukkit.inventory.ItemStack[] reagents)
Removes the specified reagents from the player's inventoryy. This does not check if the player has the reagents, use hasReagents() for that.

Parameters:
player - the player to remove the reagents from
reagents - the inventory item reagents to remove

removeReagents

protected void removeReagents(org.bukkit.entity.Player player,
                              org.bukkit.inventory.ItemStack[] reagents,
                              int healthCost,
                              int manaCost)
Removes the specified reagents, including health and mana, from the player's inventory. This does not check if the player has the reagents, use hasReagents() for that.

Parameters:
player - the player to remove the reagents from
reagents - the inventory item reagents to remove
healthCost - the health to remove
manaCost - the mana to remove

formatMessage

public static java.lang.String formatMessage(java.lang.String message,
                                             java.lang.String... replacements)
Formats a string by performing the specified replacements.

Parameters:
message - the string to format
replacements - the replacements to make, in pairs.
Returns:
the formatted string

sendMessage

public static void sendMessage(org.bukkit.entity.Player player,
                               java.lang.String message,
                               java.lang.String... replacements)
Sends a message to a player, first making the specified replacements. This method also does color replacement and has multi-line functionality.

Parameters:
player - the player to send the message to
message - the message to send
replacements - the replacements to be made, in pairs

sendMessage

public static void sendMessage(org.bukkit.entity.Player player,
                               java.lang.String message)
Sends a message to a player. This method also does color replacement and has multi-line functionality.

Parameters:
player - the player to send the message to
message - the message to send

sendMessageNear

protected void sendMessageNear(org.bukkit.entity.Player player,
                               java.lang.String message)
Sends a message to all players near the specified player, within the configured broadcast range.

Parameters:
player - the "center" player used to find nearby players
message - the message to send

sendMessageNear

protected void sendMessageNear(org.bukkit.entity.Player player,
                               java.lang.String message,
                               int range)
Sends a message to all players near the specified player, within the specified broadcast range.

Parameters:
player - the "center" player used to find nearby players
message - the message to send
range - the broadcast range

getInternalName

public java.lang.String getInternalName()

getName

public java.lang.String getName()

getCastItem

public int getCastItem()

getDescription

public java.lang.String getDescription()

getReagentCost

public org.bukkit.inventory.ItemStack[] getReagentCost()

getManaCost

public int getManaCost()

getHealthCost

public int getHealthCost()

addListener

protected void addListener(org.bukkit.event.Event.Type eventType)
Makes this spell listen for the specified event

Parameters:
eventType - the event to listen for

removeListener

protected void removeListener(org.bukkit.event.Event.Type eventType)
Makes this spell stop listening for the specified event

Parameters:
eventType - the event

initialize

protected void initialize()
This method is called immediately after all spells have been loaded into the plugin.


turnOff

protected void turnOff()
This methid is called when the plugin is being disabled, for any reason.


onPlayerJoin

public void onPlayerJoin(org.bukkit.event.player.PlayerJoinEvent event)

onPlayerQuit

public void onPlayerQuit(org.bukkit.event.player.PlayerQuitEvent event)

onPlayerInteract

public void onPlayerInteract(org.bukkit.event.player.PlayerInteractEvent event)

onItemHeldChange

public void onItemHeldChange(org.bukkit.event.player.PlayerItemHeldEvent event)

onPlayerMove

public void onPlayerMove(org.bukkit.event.player.PlayerMoveEvent event)

onPlayerTeleport

public void onPlayerTeleport(org.bukkit.event.player.PlayerTeleportEvent event)

onPlayerToggleSneak

public void onPlayerToggleSneak(org.bukkit.event.player.PlayerToggleSneakEvent event)

onPlayerCommandPreprocess

public void onPlayerCommandPreprocess(org.bukkit.event.player.PlayerCommandPreprocessEvent event)

onBlockBreak

public void onBlockBreak(org.bukkit.event.block.BlockBreakEvent event)

onBlockPlace

public void onBlockPlace(org.bukkit.event.block.BlockPlaceEvent event)

onEntityDamage

public void onEntityDamage(org.bukkit.event.entity.EntityDamageEvent event)

onEntityTarget

public void onEntityTarget(org.bukkit.event.entity.EntityTargetEvent event)

onEntityCombust

public void onEntityCombust(org.bukkit.event.entity.EntityCombustEvent event)

onExplosionPrime

public void onExplosionPrime(org.bukkit.event.entity.ExplosionPrimeEvent event)

compareTo

public int compareTo(Spell spell)
Specified by:
compareTo in interface java.lang.Comparable<Spell>