use of com.elmakers.mine.bukkit.magic.Mage in project MagicPlugin by elBukkit.
the class Wand method takeOwnership.
public void takeOwnership(Player player) {
Mage mage = this.mage;
if (mage == null) {
mage = controller.getMage(player);
}
if ((ownerId == null || ownerId.length() == 0) && quietLevel < 2) {
mage.sendMessage(getMessage("bound_instructions", "").replace("$wand", getName()));
String spellKey = getActiveSpellKey();
SpellTemplate spellTemplate = spellKey != null && !spellKey.isEmpty() ? controller.getSpellTemplate(spellKey) : null;
if (spellTemplate != null) {
String message = getMessage("spell_instructions", "").replace("$wand", getName());
mage.sendMessage(message.replace("$spell", spellTemplate.getName()));
}
if (spells.size() > 1) {
String controlKey = getControlKey(WandAction.TOGGLE);
if (controlKey != null) {
controlKey = controller.getMessages().get("controls." + controlKey);
mage.sendMessage(getMessage("inventory_instructions", "").replace("$wand", getName()).replace("$toggle", controlKey));
}
}
com.elmakers.mine.bukkit.api.wand.WandUpgradePath path = getPath();
if (path != null) {
String message = getMessage("enchant_instructions", "").replace("$wand", getName());
mage.sendMessage(message);
}
}
owner = ChatColor.stripColor(player.getDisplayName());
ownerId = mage.getId();
setProperty("owner", owner);
setProperty("owner_id", ownerId);
updateLore();
saveState();
}
use of com.elmakers.mine.bukkit.magic.Mage in project MagicPlugin by elBukkit.
the class Wand method deactivate.
@Override
public void deactivate() {
if (mage == null)
return;
// Play deactivate FX
playPassiveEffects("deactivate");
Mage mage = this.mage;
if (isInventoryOpen()) {
closeInventory();
}
showActiveIcon(false);
storedInventory = null;
if (usesXPNumber() || usesXPBar()) {
mage.resetSentExperience();
}
saveState();
mage.deactivateWand(this);
this.mage = null;
updateMaxMana(true);
}
use of com.elmakers.mine.bukkit.magic.Mage in project MagicPlugin by elBukkit.
the class Wand method bind.
@Override
public void bind() {
if (bound)
return;
Mage holdingMage = mage;
deactivate();
bound = true;
setProperty("bound", true);
saveState();
if (holdingMage != null) {
holdingMage.checkWand();
}
}
use of com.elmakers.mine.bukkit.magic.Mage in project MagicPlugin by elBukkit.
the class Wand method fill.
@Override
public boolean fill(Player player, int maxLevel) {
closeInventory();
Collection<String> currentSpells = new ArrayList<>(getSpells());
for (String spellKey : currentSpells) {
SpellTemplate spell = controller.getSpellTemplate(spellKey);
if (!spell.hasCastPermission(player)) {
removeSpell(spellKey);
}
}
Collection<SpellTemplate> allSpells = controller.getPlugin().getSpellTemplates();
// Hack to prevent messaging
Mage mage = this.mage;
this.mage = null;
for (SpellTemplate spell : allSpells) {
String key = spell.getKey();
if (maxLevel > 0 && spell.getSpellKey().getLevel() > maxLevel) {
continue;
}
if (key.startsWith("heroes*")) {
continue;
}
if (spell.hasCastPermission(player) && spell.hasIcon() && !spell.isHidden()) {
addSpell(key);
}
}
this.mage = mage;
if (autoFill)
setProperty("fill", false);
autoFill = false;
saveState();
return true;
}
use of com.elmakers.mine.bukkit.magic.Mage in project MagicPlugin by elBukkit.
the class InventoryController method onInventoryDrag.
@EventHandler(ignoreCancelled = true)
public void onInventoryDrag(InventoryDragEvent event) {
Mage mage = controller.getMage(event.getWhoClicked());
GUIAction activeGUI = mage.getActiveGUI();
if (activeGUI != null) {
activeGUI.dragged(event);
return;
}
// Unfortunately this event gives us a shallow copy of the item so we need to dig a little bit.
// This could possibly be narrowed down to events only effecting held item slots and armor
ItemStack oldCursor = event.getOldCursor();
if (oldCursor.hasItemMeta() && Wand.isWand(InventoryUtils.makeReal(oldCursor))) {
controller.onArmorUpdated(mage);
}
if (!enableItemHacks)
return;
// this is a huge hack! :\
// I apologize for any weird behavior this causes.
// Bukkit, unfortunately, will blow away NBT data for anything you drag
// Which will nuke a wand or spell.
// To make matters worse, Bukkit passes a copy of the item in the event, so we can't
// even check for metadata and only cancel the event if it involves one of our special items.
// The best I can do is look for metadata at all, since Bukkit will retain the name and lore.
// I have now decided to copy over the CB default handler for this, and cancel the event.
// The only change I have made is that *real* ItemStack copies are made, instead of shallow Bukkit ones.
ItemStack oldStack = event.getOldCursor();
HumanEntity entity = event.getWhoClicked();
if (oldStack != null && oldStack.hasItemMeta() && entity instanceof Player) {
// Only do this if we're only dragging one item, since I don't
// really know what happens or how you would drag more than one.
Map<Integer, ItemStack> draggedSlots = event.getNewItems();
if (draggedSlots.size() != 1)
return;
event.setCancelled(true);
// Cancelling the event will put the item back on the cursor,
// and skip updating the inventory.
// So we will wait one tick and then fix this up using the original item.
InventoryView view = event.getView();
for (Integer dslot : draggedSlots.keySet()) {
CompleteDragTask completeDrag = new CompleteDragTask((Player) entity, view, dslot);
completeDrag.runTaskLater(controller.getPlugin(), 1);
}
}
}
Aggregations