use of com.elmakers.mine.bukkit.api.magic.MageClass in project MagicPlugin by elBukkit.
the class CondHasSpell method check.
@Override
public boolean check(final Event e) {
return entities.check(e, new Checker<Entity>() {
@Override
public boolean check(final Entity entity) {
final Mage mage = MagicPlugin.getAPI().getController().getRegisteredMage(entity);
if (mage == null) {
return false;
}
return spells.check(e, new Checker<String>() {
@Override
public boolean check(final String spellKey) {
Wand wand = mage.getActiveWand();
if (wand != null && wand.hasSpell(spellKey)) {
return true;
}
MageClass activeClass = mage.getActiveClass();
if (activeClass != null && activeClass.hasSpell(spellKey)) {
return true;
}
return false;
}
}, isNegated());
}
});
}
use of com.elmakers.mine.bukkit.api.magic.MageClass 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.magic.MageClass in project MagicPlugin by elBukkit.
the class MageCommandExecutor method onMageRemove.
public boolean onMageRemove(CommandSender sender, Player player, String[] parameters) {
if (parameters.length < 1) {
sender.sendMessage("Use: /mage remove <spell|material> [material:data]");
return true;
}
Mage mage = controller.getMage(player);
MageClass activeClass = mage.getActiveClass();
if (activeClass == null) {
sender.sendMessage("Can't modify player " + player.getName());
return true;
}
String spellName = parameters[0];
if (spellName.equals("material") || spellName.equals("brush")) {
if (parameters.length < 2) {
sender.sendMessage("Use: /mage remove brush <material:data>");
return true;
}
String materialKey = parameters[1];
if (activeClass.removeBrush(materialKey)) {
mage.sendMessage("Brush '" + materialKey + "' has been removed");
if (sender != player) {
sender.sendMessage("Removed brush '" + materialKey + "' from " + player.getName());
}
} else {
if (sender != player) {
sender.sendMessage(player.getName() + " does not have brush " + materialKey);
}
}
return true;
}
if (activeClass.removeSpell(spellName)) {
SpellTemplate template = api.getSpellTemplate(spellName);
if (template != null) {
spellName = template.getName();
}
mage.sendMessage("Spell '" + spellName + "' has been removed");
if (sender != player) {
sender.sendMessage("Removed '" + spellName + "' from " + player.getName());
}
} else {
if (sender != player) {
sender.sendMessage(player.getName() + " does not have " + spellName);
}
}
return true;
}
use of com.elmakers.mine.bukkit.api.magic.MageClass in project MagicPlugin by elBukkit.
the class SkillSelectorAction method perform.
@Override
public SpellResult perform(CastContext context) {
this.context = context;
MageController apiController = context.getController();
Player player = context.getMage().getPlayer();
if (player == null) {
return SpellResult.PLAYER_REQUIRED;
}
if (!(apiController instanceof MagicController))
return SpellResult.FAIL;
MagicController controller = (MagicController) apiController;
Messages messages = controller.getMessages();
HeroesManager heroes = controller.getHeroes();
allSkills.clear();
if (controller.useHeroesSkills() && heroes != null) {
@Nonnull String classString = heroes.getClassName(player);
@Nonnull String class2String = heroes.getSecondaryClassName(player);
String messageKey = !class2String.isEmpty() ? "skills.inventory_title_secondary" : "skills.inventory_title";
inventoryTitle = controller.getMessages().get(messageKey, "Skills ($page/$pages)");
inventoryTitle = inventoryTitle.replace("$class2", class2String).replace("$class", classString);
List<String> heroesSkills = heroes.getSkillList(player, true, true);
for (String heroesSkill : heroesSkills) {
allSkills.add(new SkillDescription(heroes, controller, player, heroesSkill));
}
} else {
inventoryTitle = messages.get("skills.inventory_title");
}
if (controller.usePermissionSkills()) {
boolean bypassHidden = player.hasPermission("Magic.bypass_hidden");
Collection<SpellTemplate> spells = controller.getSpellTemplates(bypassHidden);
for (SpellTemplate spell : spells) {
SpellKey key = spell.getSpellKey();
if (key.isVariant())
continue;
if (key.getBaseKey().startsWith("heroes*"))
continue;
if (!spell.hasCastPermission(player))
continue;
allSkills.add(new SkillDescription(spell));
}
} else {
Mage mage = controller.getMage(player);
MageClass activeClass = mage.getActiveClass();
if (activeClass != null) {
// gather spells in player's inventory to avoid showing
Set<String> hasSpells = new HashSet<>();
for (ItemStack item : player.getInventory().getContents()) {
String spellKey = controller.getSpell(item);
if (spellKey != null) {
hasSpells.add(spellKey);
}
}
classKey = activeClass.getKey();
skillsConfig = activeClass.getProperty("skills", ConfigurationSection.class);
inventoryLimit = activeClass.getProperty("skills.skill_limit", 0);
Collection<String> spells = activeClass.getSpells();
for (String spellKey : spells) {
if (hasSpells.contains(spellKey)) {
extraSlots++;
continue;
}
SpellTemplate spell = controller.getSpellTemplate(spellKey);
if (spell != null) {
allSkills.add(new SkillDescription(spell));
}
}
}
}
if (allSkills.size() == 0) {
player.sendMessage(messages.get("skills.none"));
return SpellResult.NO_ACTION;
}
Collections.sort(allSkills);
openInventory();
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.magic.MageClass in project MagicPlugin by elBukkit.
the class MagicRequirement method getRequirementDescription.
@Nullable
public String getRequirementDescription(@Nonnull CastContext context) {
Mage mage = context.getMage();
MageController controller = mage.getController();
Player player = mage.getPlayer();
if (permissionNode != null && (player == null || !player.hasPermission(permissionNode))) {
return context.getMessage(SpellResult.INSUFFICIENT_PERMISSION.name().toLowerCase());
}
Wand wand = context.getWand();
if (wand == null && requireWand) {
return getMessage(context, "no_wand");
}
if (requiredTemplate != null) {
String template = wand.getTemplateKey();
if (template == null || !template.equals(requiredTemplate)) {
return getMessage(context, "no_template").replace("$wand", wand.getName());
}
}
if (requiredTemplates != null) {
String template = wand.getTemplateKey();
if (template == null || !requiredTemplates.contains(template)) {
return getMessage(context, "no_template").replace("$wand", wand.getName());
}
}
if (mageClass != null && !mageClass.isEmpty()) {
if (mage.hasClassUnlocked(mageClass)) {
return getMessage(context, "no_class").replace("$class", mageClass);
}
}
CasterProperties checkProperties = context.getActiveProperties();
ProgressionPath path = checkProperties.getPath();
if (requiredPath != null || exactPath != null) {
if (path == null) {
return getMessage(context, "no_path");
}
if (requiredPath != null && !path.hasPath(requiredPath)) {
WandUpgradePath requiresPath = controller.getPath(requiredPath);
String pathName = requiredPath;
if (requiresPath != null) {
pathName = requiresPath.getName();
} else {
context.getLogger().warning("Invalid path specified in requirement " + requiredPath);
}
return getMessage(context, "no_required_path").replace("$path", pathName);
}
if (exactPath != null && !exactPath.equals(path.getKey())) {
WandUpgradePath requiresPath = controller.getPath(exactPath);
String pathName = exactPath;
if (requiresPath != null) {
pathName = requiresPath.getName();
} else {
context.getLogger().warning("Invalid path specified in requirement: " + exactPath);
}
return getMessage(context, "no_path_exact").replace("$path", pathName);
}
if (requiresCompletedPath != null) {
boolean hasPathCompleted = false;
if (path.hasPath(requiresCompletedPath)) {
if (path.getKey().equals(requiresCompletedPath)) {
hasPathCompleted = !path.canProgress(checkProperties);
} else {
hasPathCompleted = true;
}
}
if (!hasPathCompleted) {
WandUpgradePath requiresPath = controller.getPath(requiresCompletedPath);
String pathName = requiresCompletedPath;
if (requiresPath != null) {
pathName = requiresPath.getName();
} else {
context.getLogger().warning("Invalid path specified in requirement: " + exactPath);
}
return getMessage(context, "no_path_end").replace("$path", pathName);
}
}
}
if (wandProperties != null) {
String message = getRequiredProperty(context, wand, wandProperties);
if (message != null) {
return message;
}
}
if (classProperties != null) {
MageClass activeClass = mageClass == null ? mage.getActiveClass() : mage.getClass(mageClass);
if (activeClass == null) {
return getMessage(context, "no_path");
}
String message = getRequiredProperty(context, activeClass, classProperties);
if (message != null) {
return message;
}
}
if (attributes != null) {
for (PropertyRequirement requirement : attributes) {
String key = requirement.key;
Double value = mage.getAttribute(key);
String message = checkRequiredProperty(context, requirement, key, value);
if (message != null) {
return message;
}
}
}
return null;
}
Aggregations