use of com.elmakers.mine.bukkit.api.spell.Spell in project MagicPlugin by elBukkit.
the class MageTrigger method cast.
private void cast(Mage mage, String castSpell) {
if (castSpell.length() > 0) {
String[] parameters = null;
Spell spell = null;
if (!castSpell.equalsIgnoreCase("none")) {
if (castSpell.contains(" ")) {
parameters = StringUtils.split(castSpell, ' ');
castSpell = parameters[0];
parameters = Arrays.copyOfRange(parameters, 1, parameters.length);
}
spell = mage.getSpell(castSpell);
}
if (spell != null) {
spell.cast(parameters);
}
}
}
use of com.elmakers.mine.bukkit.api.spell.Spell in project MagicPlugin by elBukkit.
the class MagicController method loadSpells.
protected void loadSpells(Map<String, ConfigurationSection> spellConfigs) {
if (spellConfigs == null)
return;
// Reset existing spells.
spells.clear();
spellAliases.clear();
categories.clear();
for (Entry<String, ConfigurationSection> entry : spellConfigs.entrySet()) {
String key = entry.getKey();
if (key.equals("default") || key.equals("override"))
continue;
ConfigurationSection spellNode = entry.getValue();
if (spellNode == null) {
continue;
}
Spell newSpell = null;
try {
newSpell = loadSpell(key, spellNode, this);
} catch (Exception ex) {
newSpell = null;
ex.printStackTrace();
}
if (newSpell == null) {
getLogger().warning("Magic: Error loading spell " + key);
continue;
}
if (!newSpell.hasIcon()) {
String icon = spellNode.getString("icon");
if (icon != null && !icon.isEmpty()) {
getLogger().info("Couldn't load spell icon '" + icon + "' for spell: " + newSpell.getKey());
}
}
addSpell(newSpell);
}
// Second pass to fulfill requirements, which needs all spells loaded
for (Entry<String, ConfigurationSection> entry : spellConfigs.entrySet()) {
SpellTemplate template = getSpellTemplate(entry.getKey());
if (template != null) {
template.loadPrerequisites(entry.getValue());
}
}
// Update registered mages so their spells are current
for (Mage mage : mages.values()) {
if (mage instanceof com.elmakers.mine.bukkit.magic.Mage) {
((com.elmakers.mine.bukkit.magic.Mage) mage).loadSpells(spellConfigurations);
}
}
}
use of com.elmakers.mine.bukkit.api.spell.Spell in project MagicPlugin by elBukkit.
the class EffCast method execute.
@Override
protected void execute(Event event) {
String spellKey = spell.getSingle(event);
String parameterString = arguments == null ? null : arguments.getSingle(event);
String[] parameters = parameterString == null ? null : StringUtils.split(parameterString, ' ');
if (senders != null) {
for (final CommandSender sender : senders.getArray(event)) {
if (sender != null) {
Spell spell = MagicPlugin.getAPI().getController().getMage(sender).getSpell(spellKey);
if (spell != null) {
spell.cast(parameters);
}
}
}
} else {
Spell spell = MagicPlugin.getAPI().getController().getMage(Bukkit.getConsoleSender()).getSpell(spellKey);
if (spell != null) {
spell.cast(parameters);
}
}
}
use of com.elmakers.mine.bukkit.api.spell.Spell in project MagicPlugin by elBukkit.
the class MageCommandExecutor method onMageDescribe.
public boolean onMageDescribe(CommandSender sender, Player player, String[] parameters) {
Mage mage = controller.getMage(player);
MageClass activeClass = mage.getActiveClass();
MagicProperties mageProperties = mage.getProperties();
if (parameters.length == 0) {
sender.sendMessage(ChatColor.BLUE + "Use " + ChatColor.AQUA + "/mage describe <property>" + ChatColor.BLUE + " for specific properties");
sender.sendMessage(ChatColor.BLUE + "Use " + ChatColor.AQUA + "/mage activate" + ChatColor.BLUE + " to change or clear the active class");
Collection<String> classKeys = mage.getClassKeys();
if (classKeys.size() > 0) {
Collection<String> coloredClasses = new ArrayList<>();
for (String classKey : classKeys) {
ChatColor color = mage.hasClassUnlocked(classKey) ? ChatColor.GREEN : ChatColor.GRAY;
coloredClasses.add(color + classKey);
}
sender.sendMessage(ChatColor.AQUA + "Classes: " + ChatColor.GREEN + StringUtils.join(coloredClasses, ","));
}
if (!mageProperties.isEmpty()) {
sender.sendMessage(ChatColor.AQUA + "Mage properties:");
mageProperties.describe(sender, BaseMagicProperties.HIDDEN_PROPERTY_KEYS);
}
if (activeClass != null) {
sender.sendMessage(ChatColor.AQUA + "Active class: " + ChatColor.GREEN + activeClass.getKey());
} else {
sender.sendMessage(ChatColor.DARK_GREEN + "No active class");
}
Set<Spell> activeSpells = mage.getActiveSpells();
if (activeSpells != null && !activeSpells.isEmpty()) {
Collection<String> spellNames = new ArrayList<>();
for (Spell spell : activeSpells) {
spellNames.add(spell.getName());
}
sender.sendMessage(ChatColor.AQUA + "Active spells: " + ChatColor.DARK_AQUA + StringUtils.join(spellNames, ","));
}
if (activeClass != null) {
activeClass.describe(sender, BaseMagicProperties.HIDDEN_PROPERTY_KEYS);
}
} else {
Object property = activeClass.getProperty(parameters[0]);
if (property == null) {
sender.sendMessage(ChatColor.DARK_AQUA + parameters[0] + ChatColor.GRAY + ": " + ChatColor.RED + "(Not Set)");
} else {
sender.sendMessage(ChatColor.DARK_AQUA + parameters[0] + ChatColor.GRAY + ": " + ChatColor.WHITE + InventoryUtils.describeProperty(property));
}
}
return true;
}
use of com.elmakers.mine.bukkit.api.spell.Spell in project MagicPlugin by elBukkit.
the class Wand method updateEffects.
public void updateEffects(Mage mage) {
if (mage == null)
return;
Player player = mage.getPlayer();
if (player == null)
return;
// Update Bubble effects effects
if (effectBubbles && effectColor != null) {
Location potionEffectLocation = player.getLocation();
potionEffectLocation.setX(potionEffectLocation.getX() + random.nextDouble() - 0.5);
potionEffectLocation.setY(potionEffectLocation.getY() + random.nextDouble() * player.getEyeHeight());
potionEffectLocation.setZ(potionEffectLocation.getZ() + random.nextDouble() - 0.5);
ParticleEffect.SPELL_MOB.display(potionEffectLocation, effectColor.getColor(), 24);
}
Location location = mage.getLocation();
long now = System.currentTimeMillis();
boolean playEffects = !activeEffectsOnly || inventoryIsOpen || isInOffhand;
if (playEffects && effectParticle != null && effectParticleInterval > 0 && effectParticleCount > 0) {
boolean velocityCheck = true;
if (effectParticleMinVelocity > 0) {
double velocitySquared = effectParticleMinVelocity * effectParticleMinVelocity;
Vector velocity = mage.getVelocity().clone();
velocity.setY(0);
double speedSquared = velocity.lengthSquared();
velocityCheck = (speedSquared > velocitySquared);
}
if (velocityCheck && (lastParticleEffect == 0 || now > lastParticleEffect + effectParticleInterval)) {
lastParticleEffect = now;
Location effectLocation = player.getLocation();
Location eyeLocation = player.getEyeLocation();
effectLocation.setY(eyeLocation.getY() + effectParticleOffset);
if (effectPlayer == null) {
effectPlayer = new EffectRing(controller.getPlugin());
effectPlayer.setParticleCount(1);
effectPlayer.setIterations(1);
effectPlayer.setParticleOffset(0, 0, 0);
}
effectPlayer.setMaterial(location.getBlock().getRelative(BlockFace.DOWN));
if (effectParticleData == 0) {
effectPlayer.setColor(getEffectColor());
} else {
effectPlayer.setColor(null);
}
effectPlayer.setParticleType(effectParticle);
effectPlayer.setParticleData(effectParticleData);
effectPlayer.setSize(effectParticleCount);
effectPlayer.setRadius((float) effectParticleRadius);
effectPlayer.start(effectLocation, null);
}
}
if (castSpell != null && castInterval > 0) {
if (lastSpellCast == 0 || now > lastSpellCast + castInterval) {
boolean velocityCheck = true;
if (castMinVelocity > 0) {
double velocitySquared = castMinVelocity * castMinVelocity;
Vector velocity = mage.getVelocity();
if (castVelocityDirection != null) {
velocity = velocity.clone().multiply(castVelocityDirection);
// This is kind of a hack to make jump-detection work.
if (castVelocityDirection.getY() < 0) {
velocityCheck = velocity.getY() < 0;
} else {
velocityCheck = velocity.getY() > 0;
}
}
if (velocityCheck) {
double speedSquared = velocity.lengthSquared();
velocityCheck = (speedSquared > velocitySquared);
}
}
if (velocityCheck) {
lastSpellCast = now;
Spell spell = mage.getSpell(castSpell);
if (spell != null) {
if (castParameters == null) {
castParameters = new MemoryConfiguration();
}
castParameters.set("passive", true);
mage.setCostFree(true);
mage.setQuiet(true);
try {
spell.cast(castParameters);
} catch (Exception ex) {
controller.getLogger().log(Level.WARNING, "Error casting aura spell " + spell.getKey(), ex);
}
mage.setCostFree(false);
mage.setQuiet(false);
}
}
}
}
if (playEffects && effectSound != null && controller.soundsEnabled() && effectSoundInterval > 0) {
if (lastSoundEffect == 0 || now > lastSoundEffect + effectSoundInterval) {
lastSoundEffect = now;
effectSound.play(controller.getPlugin(), mage.getPlayer());
}
}
}
Aggregations