use of com.elmakers.mine.bukkit.heroes.HeroesManager in project MagicPlugin by elBukkit.
the class Wand method tickMana.
@Override
public boolean tickMana() {
if (isHeroes) {
HeroesManager heroes = controller.getHeroes();
if (heroes != null && mage != null && mage.isPlayer()) {
Player player = mage.getPlayer();
effectiveManaMax = heroes.getMaxMana(player);
effectiveManaRegeneration = heroes.getManaRegen(player);
setManaMax(effectiveManaMax);
setManaRegeneration(effectiveManaRegeneration);
setMana(heroes.getMana(player));
return true;
}
return false;
}
return super.tickMana();
}
use of com.elmakers.mine.bukkit.heroes.HeroesManager 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.heroes.HeroesManager in project MagicPlugin by elBukkit.
the class SkillSelectorAction method openInventory.
protected void openInventory() {
MageController apiController = context.getController();
if (!(apiController instanceof MagicController))
return;
MagicController controller = (MagicController) apiController;
HeroesManager heroes = controller.getHeroes();
int inventorySize = 9 * controller.getSkillInventoryRows();
float numSlots = extraSlots + allSkills.size();
int numPages = (int) Math.ceil(numSlots / inventorySize);
if (page < 1)
page = numPages;
else if (page > numPages)
page = 1;
Mage mage = context.getMage();
Player player = mage.getPlayer();
int pageIndex = page - 1;
int startIndex = pageIndex * inventorySize;
int maxIndex = (pageIndex + 1) * inventorySize - 1;
List<SkillDescription> skills = new ArrayList<>();
for (int i = startIndex; i <= maxIndex && i < allSkills.size(); i++) {
skills.add(allSkills.get(i));
}
if (skills.size() == 0) {
String messageTemplate = controller.getMessages().get("skills.none_on_page", "$page");
player.sendMessage(messageTemplate.replace("$page", Integer.toString(page)));
return;
}
int invSize = (int) Math.ceil(numSlots / 9.0f) * 9;
String title = inventoryTitle;
title = title.replace("$pages", Integer.toString(numPages)).replace("$page", Integer.toString(page));
Inventory displayInventory = CompatibilityUtils.createInventory(null, invSize, title);
for (SkillDescription skill : skills) {
ItemStack skillItem = controller.getAPI().createItem(skill.getSkillKey(), mage);
if (skillItem == null)
continue;
InventoryUtils.configureSkillItem(skillItem, classKey, skillsConfig);
if (skill.isHeroes() && heroes != null && !heroes.canUseSkill(player, skill.heroesSkill)) {
String nameTemplate = controller.getMessages().get("skills.item_name_unavailable", "$skill");
String spellName = skill.spell != null ? skill.spell.getName() : skill.heroesSkill;
CompatibilityUtils.setDisplayName(skillItem, nameTemplate.replace("$skill", spellName));
InventoryUtils.setMetaBoolean(skillItem, "unavailable", true);
if (skill.spell != null) {
MaterialAndData disabledIcon = skill.spell.getDisabledIcon();
if (disabledIcon != null) {
disabledIcon.applyToItem(skillItem);
} else {
String disabledIconURL = skill.spell.getDisabledIconURL();
if (disabledIconURL != null && !disabledIconURL.isEmpty()) {
InventoryUtils.setNewSkullURL(skillItem, disabledIconURL);
}
}
}
}
displayInventory.addItem(skillItem);
}
mage.deactivateGUI();
mage.activateGUI(this, displayInventory);
}
Aggregations