Search in sources :

Example 1 with QueryWandBase

use of me.botsko.prism.wands.QueryWandBase in project Prism-Bukkit by prism.

the class WandCommand method constructWand.

private void constructWand(CallInfo call, boolean enabled, final Material itemMaterial, String mode, Wand wand, boolean isInspect, Wand oldWand) {
    Material item = itemMaterial;
    final PlayerInventory inv = call.getPlayer().getInventory();
    if (enabled) {
        if (item == null) {
            if (Objects.equals(mode, "block")) {
                item = Material.SPRUCE_LOG;
            } else if (Objects.equals(mode, "item")) {
                item = Material.STICK;
            } else {
                item = Material.AIR;
            }
        }
        wand.setWandMode(mode);
        wand.setItem(item);
        Prism.debug("Wand activated for player - mode: " + mode + " Item:" + item);
        // Move any existing item to the hand, otherwise give it to them
        if (plugin.getConfig().getBoolean("prism.wands.auto-equip")) {
            if (!InventoryUtils.moveItemToHand(inv, item)) {
                // Store the item they're holding, if any
                wand.setOriginallyHeldItem(inv.getItemInMainHand());
                // They don't have the item, so we need to give them an item
                if (InventoryUtils.handItemToPlayer(inv, new ItemStack(item, 1))) {
                    wand.setItemWasGiven(true);
                } else {
                    Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError(Il8nHelper.getMessage("wand-inventory-full")));
                }
            }
            InventoryUtils.updateInventory(call.getPlayer());
        }
        // Let's build the QueryParameters for it if it's a Query wand.
        if (wand instanceof QueryWandBase) {
            if (!((QueryWandBase) wand).setParameters(call.getPlayer(), call.getArgs(), (isInspect ? 1 : 2))) {
                // This
                // returns
                // if
                // it
                // was
                // successful
                Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError(Il8nHelper.getMessage("wand-params-few")));
            }
        }
        // Store
        Prism.playersWithActiveTools.put(call.getPlayer().getName(), wand);
    } else {
        if (oldWand != null) {
            oldWand.disable(call.getPlayer());
        }
    }
}
Also used : Material(org.bukkit.Material) PlayerInventory(org.bukkit.inventory.PlayerInventory) ItemStack(org.bukkit.inventory.ItemStack) QueryWandBase(me.botsko.prism.wands.QueryWandBase)

Aggregations

QueryWandBase (me.botsko.prism.wands.QueryWandBase)1 Material (org.bukkit.Material)1 ItemStack (org.bukkit.inventory.ItemStack)1 PlayerInventory (org.bukkit.inventory.PlayerInventory)1