use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class MagicController method cast.
public boolean cast(Mage mage, String spellName, ConfigurationSection parameters, CommandSender sender, Entity entity) {
Player usePermissions = (sender == entity && entity instanceof Player) ? (Player) entity : (sender instanceof Player ? (Player) sender : null);
if (entity == null && sender instanceof Player) {
entity = (Player) sender;
}
Location targetLocation = null;
if (mage == null) {
CommandSender mageController = (entity != null && entity instanceof Player) ? (Player) entity : sender;
if (sender != null && sender instanceof BlockCommandSender) {
targetLocation = ((BlockCommandSender) sender).getBlock().getLocation();
}
if (entity == null) {
mage = getMage(mageController);
} else {
mage = getMageFromEntity(entity, mageController);
}
}
// This is a bit of a hack to make automata maintain direction
if (targetLocation != null) {
Location mageLocation = mage.getLocation();
if (mageLocation != null) {
targetLocation.setPitch(mageLocation.getPitch());
targetLocation.setYaw(mageLocation.getYaw());
}
}
SpellTemplate template = getSpellTemplate(spellName);
if (template == null || !template.hasCastPermission(usePermissions)) {
if (sender != null) {
sender.sendMessage("Spell " + spellName + " unknown");
}
return false;
}
com.elmakers.mine.bukkit.api.spell.Spell spell = mage.getSpell(spellName);
if (spell == null) {
if (sender != null) {
sender.sendMessage("Spell " + spellName + " unknown");
}
return false;
}
// TODO: Load configured list of parameters!
// Make it free and skip cooldowns, if configured to do so.
toggleCastCommandOverrides(mage, sender, true);
boolean success = false;
try {
success = spell.cast(parameters, targetLocation);
} catch (Exception ex) {
ex.printStackTrace();
}
toggleCastCommandOverrides(mage, sender, false);
return success;
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class MagicController method removeItemFromWand.
@Nullable
public ItemStack removeItemFromWand(Wand wand, ItemStack droppedItem) {
if (wand == null || droppedItem == null || Wand.isWand(droppedItem)) {
return null;
}
if (Wand.isSpell(droppedItem)) {
String spellKey = Wand.getSpell(droppedItem);
wand.removeSpell(spellKey);
// Update the item for proper naming and lore
SpellTemplate spell = getSpellTemplate(spellKey);
if (spell != null) {
Wand.updateSpellItem(messages, droppedItem, spell, "", null, null, true);
}
} else if (Wand.isBrush(droppedItem)) {
String brushKey = Wand.getBrush(droppedItem);
wand.removeBrush(brushKey);
// Update the item for proper naming and lore
Wand.updateBrushItem(getMessages(), droppedItem, brushKey, null);
}
return droppedItem;
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class MagicController method activateMetrics.
protected void activateMetrics() {
// Activate Metrics
final MagicController controller = this;
metrics = null;
if (metricsLevel > 0) {
try {
metrics = new Metrics(plugin);
if (metricsLevel > 1) {
metrics.addCustomChart(new Metrics.MultiLineChart("Plugin Integration") {
@Override
public HashMap<String, Integer> getValues(HashMap<String, Integer> valueMap) {
valueMap.put("Essentials", controller.hasEssentials ? 1 : 0);
valueMap.put("Dynmap", controller.hasDynmap ? 1 : 0);
valueMap.put("Factions", controller.factionsManager.isEnabled() ? 1 : 0);
valueMap.put("WorldGuard", controller.worldGuardManager.isEnabled() ? 1 : 0);
valueMap.put("Elementals", controller.elementalsEnabled() ? 1 : 0);
valueMap.put("Citizens", controller.citizens != null ? 1 : 0);
valueMap.put("CommandBook", controller.hasCommandBook ? 1 : 0);
valueMap.put("PvpManager", controller.pvpManager.isEnabled() ? 1 : 0);
valueMap.put("Multiverse-Core", controller.multiverseManager.isEnabled() ? 1 : 0);
valueMap.put("Towny", controller.townyManager.isEnabled() ? 1 : 0);
valueMap.put("GriefPrevention", controller.griefPreventionManager.isEnabled() ? 1 : 0);
valueMap.put("PreciousStones", controller.preciousStonesManager.isEnabled() ? 1 : 0);
valueMap.put("Lockette", controller.locketteManager.isEnabled() ? 1 : 0);
valueMap.put("NoCheatPlus", controller.ncpManager.isEnabled() ? 1 : 0);
return valueMap;
}
});
metrics.addCustomChart(new Metrics.MultiLineChart("Features Enabled") {
@Override
public HashMap<String, Integer> getValues(HashMap<String, Integer> valueMap) {
valueMap.put("Crafting", controller.crafting.isEnabled() ? 1 : 0);
valueMap.put("Enchanting", controller.enchanting.isEnabled() ? 1 : 0);
valueMap.put("SP", controller.isSPEnabled() ? 1 : 0);
return valueMap;
}
});
}
if (metricsLevel > 2) {
metrics.addCustomChart(new Metrics.MultiLineChart("Total Casts by Category") {
@Override
public HashMap<String, Integer> getValues(HashMap<String, Integer> valueMap) {
for (final SpellCategory category : categories.values()) {
valueMap.put(category.getName(), (int) category.getCastCount());
}
return valueMap;
}
});
}
if (metricsLevel > 3) {
metrics.addCustomChart(new Metrics.MultiLineChart("Total Casts") {
@Override
public HashMap<String, Integer> getValues(HashMap<String, Integer> valueMap) {
for (final SpellTemplate spell : spells.values()) {
if (!(spell instanceof Spell))
continue;
valueMap.put(spell.getName(), (int) ((Spell) spell).getCastCount());
}
return valueMap;
}
});
}
plugin.getLogger().info("Activated BStats");
} catch (Exception ex) {
plugin.getLogger().warning("Failed to load BStats: " + ex.getMessage());
}
}
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class MagicConfigurableExecutor method onLevelSpells.
protected boolean onLevelSpells(String command, CommandSender sender, Player player, CasterProperties caster, Integer maxLevel) {
Collection<String> spells = caster.getSpells();
MageController controller = api.getController();
int levelledCount = 0;
for (String spellKey : spells) {
SpellTemplate spellTemplate = controller.getSpellTemplate(spellKey);
if (spellTemplate == null)
continue;
SpellKey key = spellTemplate.getSpellKey();
int currentLevel = key.getLevel();
if (maxLevel != null && currentLevel >= maxLevel)
continue;
int targetLevel = key.getLevel();
while (spellTemplate != null && (maxLevel == null || targetLevel < maxLevel)) {
key = new SpellKey(key.getBaseKey(), targetLevel + 1);
spellTemplate = controller.getSpellTemplate(key.getKey());
if (spellTemplate != null) {
targetLevel++;
}
}
if (currentLevel >= targetLevel)
continue;
key = new SpellKey(key.getBaseKey(), targetLevel);
caster.addSpell(key.getKey());
levelledCount++;
}
if (sender != player) {
if (levelledCount > 0) {
sender.sendMessage(api.getMessages().getParameterized(command + ".player_spells_levelled", "$name", player.getName(), "$count", Integer.toString(levelledCount)));
} else {
sender.sendMessage(api.getMessages().getParameterized(command + ".player_spells_not_levelled", "$name", player.getName()));
}
} else {
if (levelledCount > 0) {
sender.sendMessage(api.getMessages().getParameterized(command + ".spells_levelled", "$name", player.getName(), "$count", Integer.toString(levelledCount)));
} else {
sender.sendMessage(api.getMessages().getParameterized(command + ".spells_not_levelled", "$name", player.getName()));
}
}
return true;
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class MagicGiveCommandExecutor method onTabComplete.
@Override
public Collection<String> onTabComplete(CommandSender sender, String commandName, String[] args) {
Set<String> options = new HashSet<>();
if (!sender.hasPermission("Magic.commands.mgive"))
return options;
if (args.length == 1 && sender.hasPermission("Magic.commands.mgive.others")) {
options.addAll(api.getPlayerNames());
}
if (args.length == 1 || args.length == 2) {
Collection<SpellTemplate> spellList = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
for (SpellTemplate spell : spellList) {
addIfPermissible(sender, options, "Magic.create.", spell.getKey());
}
Collection<String> allWands = api.getWandKeys();
for (String wandKey : allWands) {
addIfPermissible(sender, options, "Magic.create.", wandKey);
}
for (Material material : Material.values()) {
addIfPermissible(sender, options, "Magic.create.", material.name().toLowerCase());
}
Collection<String> allItems = api.getController().getItemKeys();
for (String itemKey : allItems) {
addIfPermissible(sender, options, "Magic.create.", itemKey);
}
addIfPermissible(sender, options, "Magic.create.", "xp");
addIfPermissible(sender, options, "Magic.create.", "sp");
}
return options;
}
Aggregations