use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.
the class MagicItemDb method get.
@Nullable
@Override
public ItemStack get(final String id) throws Exception {
if (id.startsWith("m:")) {
String itemId = id.replace("m:", "");
return controller.createItem(itemId);
}
if (id.startsWith("magic:")) {
String itemId = id.replace("magic:", "");
return controller.createItem(itemId);
} else if (id.equals("wand")) {
Wand wand = Wand.createWand(controller, "");
if (wand != null) {
return wand.getItem();
}
} else if (id.startsWith("wand:")) {
String wandId = id.replace("wand:", "");
Wand wand = Wand.createWand(controller, wandId.trim());
if (wand != null) {
return wand.getItem();
}
} else if (id.startsWith("w:")) {
String wandId = id.replace("w:", "");
Wand wand = Wand.createWand(controller, wandId.trim());
if (wand != null) {
return wand.getItem();
}
} else if (id.startsWith("book:")) {
String bookCategory = id.replace("book:", "");
SpellCategory category = null;
if (bookCategory.length() > 0 && !bookCategory.equalsIgnoreCase("all")) {
category = controller.getCategory(bookCategory);
}
ItemStack bookItem = controller.getSpellBook(category, 1);
if (bookItem != null) {
return bookItem;
}
} else if (id.startsWith("spell:")) {
String spellKey = id.replace("spell:", "");
ItemStack itemStack = Wand.createSpellItem(spellKey, controller, null, true);
if (itemStack != null) {
return itemStack;
}
} else if (id.startsWith("s:")) {
String spellKey = id.replace("s:", "");
ItemStack itemStack = Wand.createSpellItem(spellKey, controller, null, true);
if (itemStack != null) {
return itemStack;
}
} else if (id.startsWith("brush:")) {
String brushKey = id.replace("brush:", "");
ItemStack itemStack = Wand.createBrushItem(brushKey, controller, null, true);
if (itemStack != null) {
return itemStack;
}
} else if (id.startsWith("upgrade:")) {
String wandId = id.replace("upgrade:", "");
Wand wand = Wand.createWand(controller, wandId.trim());
if (wand != null) {
wand.makeUpgrade();
return wand.getItem();
}
} else if (id.startsWith("item:")) {
String wandId = id.replace("item:", "");
return controller.createItem(wandId);
}
return super.get(id);
}
use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.
the class MagicController method giveItemToPlayer.
@Override
public void giveItemToPlayer(Player player, ItemStack itemStack) {
// Bind item if configured to do so
if (bindOnGive && Wand.isWand(itemStack)) {
Wand wand = getWand(itemStack);
if (wand.isBound()) {
wand.tryToOwn(player);
itemStack = wand.getItem();
}
}
Mage mage = getMage(player);
mage.giveItem(itemStack);
}
use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.
the class MagicController method itemsAreEqual.
@Override
public boolean itemsAreEqual(ItemStack first, ItemStack second) {
if (first == null || second == null)
return false;
if (first.getType() != second.getType() || first.getDurability() != second.getDurability())
return false;
boolean firstIsWand = Wand.isWandOrUpgrade(first);
boolean secondIsWand = Wand.isWandOrUpgrade(second);
if (firstIsWand || secondIsWand) {
if (!firstIsWand || !secondIsWand)
return false;
Wand firstWand = getWand(InventoryUtils.getCopy(first));
Wand secondWand = getWand(InventoryUtils.getCopy(second));
String firstTemplate = firstWand.getTemplateKey();
String secondTemplate = secondWand.getTemplateKey();
if (firstTemplate == null || secondTemplate == null)
return false;
return firstTemplate.equalsIgnoreCase(secondTemplate);
}
String firstSpellKey = Wand.getSpell(first);
String secondSpellKey = Wand.getSpell(second);
if (firstSpellKey != null || secondSpellKey != null) {
if (firstSpellKey == null || secondSpellKey == null)
return false;
return firstSpellKey.equalsIgnoreCase(secondSpellKey);
}
String firstBrushKey = Wand.getBrush(first);
String secondBrushKey = Wand.getBrush(second);
if (firstBrushKey != null || secondBrushKey != null) {
if (firstBrushKey == null || secondBrushKey == null)
return false;
return firstBrushKey.equalsIgnoreCase(secondBrushKey);
}
String firstName = first.hasItemMeta() ? first.getItemMeta().getDisplayName() : null;
String secondName = second.hasItemMeta() ? second.getItemMeta().getDisplayName() : null;
return Objects.equals(firstName, secondName);
}
use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.
the class Mage method giveItem.
@Override
public void giveItem(ItemStack itemStack) {
if (InventoryUtils.isEmpty(itemStack))
return;
// Check for wand upgrades if appropriate
Wand activeWand = getActiveWand();
if (activeWand != null) {
if (activeWand.addItem(itemStack)) {
return;
}
}
if (hasStoredInventory()) {
addToStoredInventory(itemStack);
return;
}
// Place directly in hand if possible
Player player = getPlayer();
if (player == null)
return;
PlayerInventory inventory = player.getInventory();
ItemStack inHand = inventory.getItemInMainHand();
if (inHand == null || inHand.getType() == Material.AIR) {
inventory.setItemInMainHand(itemStack);
// Get the new item reference -
// it might change when added to an Inventory! :|
itemStack = inventory.getItemInMainHand();
if (Wand.isWand(itemStack)) {
checkWand();
} else {
if (itemStack.getType() == Material.MAP) {
setLastHeldMapId(itemStack.getDurability());
}
}
} else {
HashMap<Integer, ItemStack> returned = player.getInventory().addItem(itemStack);
if (returned.size() > 0) {
player.getWorld().dropItem(player.getLocation(), itemStack);
}
}
}
use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.
the class Mage method findWand.
@Override
@Nullable
public Wand findWand(@Nonnull String template) {
Player player = getPlayer();
if (player == null)
return null;
Inventory inventory = player.getInventory();
for (ItemStack itemStack : inventory.getContents()) {
String itemTemplate = Wand.getWandTemplate(itemStack);
if (itemTemplate != null && itemTemplate.equals(template)) {
return new Wand(controller, itemStack);
}
}
return null;
}
Aggregations