use of com.elmakers.mine.bukkit.api.spell.Spell in project MagicPlugin by elBukkit.
the class PlayerController method onPlayerEquip.
@EventHandler
public void onPlayerEquip(PlayerItemHeldEvent event) {
if (!controller.isLoaded())
return;
Player player = event.getPlayer();
PlayerInventory inventory = player.getInventory();
ItemStack next = inventory.getItem(event.getNewSlot());
Mage mage = controller.getMage(player);
// Check for self-destructing and temporary items
if (Wand.isSelfDestructWand(next)) {
mage.sendMessageKey("wand.self_destruct");
inventory.setItem(event.getNewSlot(), null);
mage.checkWand();
return;
}
if (NMSUtils.isTemporary(next)) {
inventory.setItem(event.getNewSlot(), null);
mage.checkWand();
return;
}
Wand activeWand = mage.getActiveWand();
boolean isSkill = Wand.isSkill(next);
if (isSkill && Wand.isQuickCastSkill(next)) {
mage.useSkill(next);
event.setCancelled(true);
return;
}
boolean isQuickCast = activeWand != null && activeWand.isQuickCast() && activeWand.isInventoryOpen();
if (isQuickCast) {
Spell spell = mage.getSpell(Wand.getSpell(next));
if (spell != null) {
activeWand.cast(spell);
}
event.setCancelled(true);
return;
}
// Check for active Wand
boolean isWand = Wand.isWand(next);
if (activeWand != null && activeWand.isInventoryOpen()) {
// If the wand inventory is open, we're going to let them select a spell or material
if (!isWand) {
mage.activateIcon(activeWand, next);
// Make sure we have the current wand item in the player's inventory so the
// item text gets updated on hotbar item selection "bounce"
int previousSlot = event.getPreviousSlot();
ItemStack previous = inventory.getItem(previousSlot);
if (previous != null && previous.equals(activeWand.getItem())) {
player.getInventory().setItem(previousSlot, activeWand.getItem());
}
}
event.setCancelled(true);
} else if (isWand || activeWand != null) {
// Check to see if we've switched to/from a wand
mage.checkWandNextTick();
}
// Check for map selection if no wand is active
activeWand = mage.getActiveWand();
if (activeWand == null && next != null) {
if (next.getType() == Material.MAP) {
mage.setLastHeldMapId(next.getDurability());
}
}
}
use of com.elmakers.mine.bukkit.api.spell.Spell in project MagicPlugin by elBukkit.
the class PlayerController method onProjectileLaunch.
@EventHandler
public void onProjectileLaunch(ProjectileLaunchEvent event) {
if (launching || event.isCancelled())
return;
Projectile projectile = event.getEntity();
ProjectileSource shooter = projectile.getShooter();
// Not really handling magic mobs with magic bows...
if (!(shooter instanceof Player))
return;
Player player = (Player) shooter;
Mage mage = controller.getRegisteredMage(player);
if (mage == null)
return;
Wand wand = mage.getActiveWand();
if (wand == null)
return;
if (wand.getIcon().getMaterial() != Material.BOW)
return;
double minPull = wand.getDouble("cast_min_bowpull");
double pull = Math.min(1.0, projectile.getVelocity().length() / MAX_ARROW_SPEED);
if (minPull > 0 && pull < minPull) {
if (wand.isInventoryOpen())
event.setCancelled(true);
return;
}
Spell spell = wand.getActiveSpell();
if (spell == null) {
if (wand.isInventoryOpen())
event.setCancelled(true);
return;
}
event.setCancelled(true);
String[] parameters = { "bowpull", Double.toString(pull) };
// prevent recursion!
launching = true;
try {
wand.cast(parameters);
} catch (Exception ex) {
controller.getLogger().log(Level.SEVERE, "Error casting bow spell", ex);
}
launching = false;
}
use of com.elmakers.mine.bukkit.api.spell.Spell in project MagicPlugin by elBukkit.
the class PlayerController method onConsume.
@EventHandler(ignoreCancelled = true)
public void onConsume(PlayerItemConsumeEvent event) {
ItemStack item = event.getItem();
if (!item.hasItemMeta())
return;
// The item we get passed in this event is a shallow bukkit copy.
item = CompatibilityUtils.makeReal(item);
String consumeSpell = controller.getWandProperty(item, "consume_spell", "");
if (!consumeSpell.isEmpty()) {
Mage mage = controller.getMage(event.getPlayer());
Spell spell = mage.getSpell(consumeSpell);
if (spell != null) {
spell.cast();
}
}
}
use of com.elmakers.mine.bukkit.api.spell.Spell in project MagicPlugin by elBukkit.
the class WandCommandExecutor method onWandAdd.
public boolean onWandAdd(CommandSender sender, Player player, String[] parameters) {
if (parameters.length < 1) {
sender.sendMessage("Usage: /wand add <spell|material> [material:data]");
return true;
}
Wand wand = checkWand(sender, player);
if (wand == null) {
return true;
}
Mage mage = controller.getMage(player);
String spellName = parameters[0];
if (spellName.equals("material") || spellName.equals("brush")) {
if (parameters.length < 2) {
sender.sendMessage("Use: /wand add brush <material:data>");
return true;
}
String materialKey = parameters[1];
if (!MaterialBrush.isValidMaterial(materialKey, false)) {
sender.sendMessage(materialKey + " is not a valid brush");
return true;
}
if (wand.addBrush(materialKey)) {
wand.setActiveBrush(materialKey);
if (sender != player) {
sender.sendMessage("Added brush '" + materialKey + "' to " + player.getName() + "'s wand");
}
} else {
wand.setActiveBrush(materialKey);
mage.sendMessage("Brush activated: " + materialKey);
if (sender != player) {
sender.sendMessage(player.getName() + "'s wand already has brush " + materialKey);
}
}
wand.saveState();
return true;
}
Spell spell = mage.getSpell(spellName);
if (spell == null) {
sender.sendMessage("Spell '" + spellName + "' unknown, Use /spells for spell list");
return true;
}
SpellTemplate currentSpell = wand.getBaseSpell(spellName);
if (wand.addSpell(spellName)) {
wand.setActiveSpell(spellName);
if (currentSpell != null) {
String levelDescription = spell.getLevelDescription();
if (levelDescription == null || levelDescription.isEmpty()) {
levelDescription = spell.getName();
}
if (sender != player) {
sender.sendMessage(api.getMessages().get("wand.player_spell_upgraded").replace("$player", player.getName()).replace("$name", currentSpell.getName()).replace("$level", levelDescription));
}
} else {
if (sender != player) {
sender.sendMessage("Added '" + spell.getName() + "' to " + player.getName() + "'s wand");
}
}
} else {
wand.setActiveSpell(spellName);
mage.sendMessage(spell.getName() + " activated");
if (sender != player) {
sender.sendMessage(player.getName() + "'s wand already has " + spell.getName());
}
}
wand.saveState();
return true;
}
Aggregations