Search in sources :

Example 1 with BaseSpell

use of com.elmakers.mine.bukkit.spell.BaseSpell in project MagicPlugin by elBukkit.

the class CastContext method setSpell.

public void setSpell(Spell spell) {
    this.spell = spell;
    if (spell instanceof BaseSpell) {
        this.baseSpell = (BaseSpell) spell;
    }
    if (spell instanceof MageSpell) {
        MageSpell mageSpell = (MageSpell) spell;
        this.mage = mageSpell.getMage();
        this.wand = mage.getActiveWand();
        this.mageClass = (this.wand == null ? this.mage.getActiveClass() : this.wand.getMageClass());
    }
    if (spell instanceof UndoableSpell) {
        this.undoSpell = (UndoableSpell) spell;
        undoList = this.undoSpell.getUndoList();
    }
    if (spell instanceof TargetingSpell) {
        this.targetingSpell = (TargetingSpell) spell;
    }
    if (spell instanceof BlockSpell) {
        this.blockSpell = (BlockSpell) spell;
    }
    if (spell instanceof BrushSpell) {
        this.brushSpell = (BrushSpell) spell;
    }
}
Also used : BrushSpell(com.elmakers.mine.bukkit.spell.BrushSpell) BaseSpell(com.elmakers.mine.bukkit.spell.BaseSpell) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) TargetingSpell(com.elmakers.mine.bukkit.spell.TargetingSpell) BlockSpell(com.elmakers.mine.bukkit.spell.BlockSpell) UndoableSpell(com.elmakers.mine.bukkit.spell.UndoableSpell)

Example 2 with BaseSpell

use of com.elmakers.mine.bukkit.spell.BaseSpell in project MagicPlugin by elBukkit.

the class Mage method updateHotbarStatus.

public void updateHotbarStatus() {
    Player player = getPlayer();
    if (player != null) {
        Location location = getLocation();
        for (int i = 0; i < Wand.HOTBAR_SIZE; i++) {
            ItemStack spellItem = player.getInventory().getItem(i);
            String spellKey = Wand.getSpell(spellItem);
            String classKey = Wand.getSpellClass(spellItem);
            if (spellKey != null) {
                Spell spell = getSpell(spellKey);
                if (spell != null) {
                    int targetAmount = 1;
                    long remainingCooldown = 0;
                    CastingCost requiredCost = null;
                    boolean canCastSpell = false;
                    if (classKey != null && !classKey.isEmpty()) {
                        MageClass mageClass = getClass(classKey);
                        if (mageClass != null && spell instanceof BaseSpell) {
                            BaseSpell baseSpell = (BaseSpell) spell;
                            baseSpell.setMageClass(mageClass);
                            remainingCooldown = spell.getRemainingCooldown();
                            requiredCost = spell.getRequiredCost();
                            canCastSpell = spell.canCast(location);
                            baseSpell.setMageClass(null);
                        }
                    } else {
                        remainingCooldown = spell.getRemainingCooldown();
                        requiredCost = spell.getRequiredCost();
                        canCastSpell = spell.canCast(location);
                    }
                    boolean canCast = canCastSpell;
                    if (canCastSpell && remainingCooldown == 0 && requiredCost == null) {
                        targetAmount = 1;
                    } else if (canCastSpell) {
                        canCast = remainingCooldown == 0;
                        targetAmount = Wand.LiveHotbarCooldown ? (int) Math.min(Math.ceil((double) remainingCooldown / 1000), 99) : 99;
                        if (Wand.LiveHotbarCooldown && requiredCost != null) {
                            int mana = requiredCost.getMana();
                            if (mana > 0) {
                                if (mana <= getEffectiveManaMax() && getEffectiveManaRegeneration() > 0) {
                                    float remainingMana = mana - getMana();
                                    canCast = canCast && remainingMana <= 0;
                                    int targetManaTime = (int) Math.min(Math.ceil(remainingMana / getEffectiveManaRegeneration()), 99);
                                    targetAmount = Math.max(targetManaTime, targetAmount);
                                } else {
                                    canCastSpell = false;
                                    canCast = false;
                                }
                            }
                        }
                    }
                    if (targetAmount == 0)
                        targetAmount = 1;
                    boolean setAmount = false;
                    MaterialAndData disabledIcon = spell.getDisabledIcon();
                    MaterialAndData spellIcon = spell.getIcon();
                    String urlIcon = spell.getIconURL();
                    String disabledUrlIcon = spell.getDisabledIconURL();
                    boolean usingURLIcon = (controller.isUrlIconsEnabled() || spellIcon == null || spellIcon.getMaterial() == Material.AIR) && urlIcon != null && !urlIcon.isEmpty();
                    if (disabledIcon != null && spellIcon != null && !usingURLIcon) {
                        if (!canCast) {
                            if (disabledIcon.isValid() && (disabledIcon.getMaterial() != spellItem.getType() || disabledIcon.getData() != spellItem.getDurability())) {
                                disabledIcon.applyToItem(spellItem);
                            }
                            if (!canCastSpell) {
                                if (spellItem.getAmount() != 1) {
                                    spellItem.setAmount(1);
                                }
                                setAmount = true;
                            }
                        } else {
                            if (spellIcon.isValid() && (spellIcon.getMaterial() != spellItem.getType() || spellIcon.getData() != spellItem.getDurability())) {
                                spellIcon.applyToItem(spellItem);
                            }
                        }
                    } else if (usingURLIcon && disabledUrlIcon != null && !disabledUrlIcon.isEmpty() && spellItem.getType() == Material.SKULL_ITEM) {
                        String currentURL = InventoryUtils.getSkullURL(spellItem);
                        if (!canCast) {
                            if (!disabledUrlIcon.equals(currentURL)) {
                                InventoryUtils.setNewSkullURL(spellItem, disabledUrlIcon);
                                player.getInventory().setItem(i, spellItem);
                            }
                            if (!canCastSpell) {
                                if (spellItem.getAmount() != 1) {
                                    spellItem.setAmount(1);
                                }
                                setAmount = true;
                            }
                        } else {
                            if (!urlIcon.equals(currentURL)) {
                                InventoryUtils.setNewSkullURL(spellItem, urlIcon);
                                player.getInventory().setItem(i, spellItem);
                            }
                        }
                    }
                    if (!setAmount && spellItem.getAmount() != targetAmount) {
                        spellItem.setAmount(targetAmount);
                    }
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) CastingCost(com.elmakers.mine.bukkit.api.spell.CastingCost) BaseSpell(com.elmakers.mine.bukkit.spell.BaseSpell) MaterialAndData(com.elmakers.mine.bukkit.api.block.MaterialAndData) ItemStack(org.bukkit.inventory.ItemStack) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) ActionSpell(com.elmakers.mine.bukkit.spell.ActionSpell) Spell(com.elmakers.mine.bukkit.api.spell.Spell) BaseSpell(com.elmakers.mine.bukkit.spell.BaseSpell) Location(org.bukkit.Location) CastSourceLocation(com.elmakers.mine.bukkit.api.magic.CastSourceLocation)

Example 3 with BaseSpell

use of com.elmakers.mine.bukkit.spell.BaseSpell in project MagicPlugin by elBukkit.

the class Mage method debugPermissions.

@Override
public void debugPermissions(CommandSender sender, Spell spell) {
    com.elmakers.mine.bukkit.api.wand.Wand wand = getActiveWand();
    Location location = getLocation();
    if (spell == null && wand != null) {
        spell = wand.getActiveSpell();
    }
    sender.sendMessage(ChatColor.GOLD + "Permission check for " + ChatColor.AQUA + getDisplayName());
    sender.sendMessage(ChatColor.GOLD + "  id " + ChatColor.DARK_AQUA + getId());
    sender.sendMessage(ChatColor.GOLD + " at " + ChatColor.AQUA + ChatColor.BLUE + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ() + " " + ChatColor.DARK_BLUE + location.getWorld().getName());
    Player player = getPlayer();
    boolean hasBypass = false;
    boolean hasPVPBypass = false;
    boolean hasBuildBypass = false;
    boolean hasBreakBypass = false;
    if (player != null) {
        hasBypass = player.hasPermission("Magic.bypass");
        hasPVPBypass = player.hasPermission("Magic.bypass_pvp");
        hasBuildBypass = player.hasPermission("Magic.bypass_build");
        sender.sendMessage(ChatColor.AQUA + " Has bypass: " + formatBoolean(hasBypass, true, null));
        sender.sendMessage(ChatColor.AQUA + " Has PVP bypass: " + formatBoolean(hasPVPBypass, true, null));
        sender.sendMessage(ChatColor.AQUA + " Has Build bypass: " + formatBoolean(hasBuildBypass, true, null));
        sender.sendMessage(ChatColor.AQUA + " Has Break bypass: " + formatBoolean(hasBreakBypass, true, null));
    }
    boolean buildPermissionRequired = spell == null ? false : spell.requiresBuildPermission();
    boolean breakPermissionRequired = spell == null ? false : spell.requiresBreakPermission();
    boolean pvpRestricted = spell == null ? false : spell.isPvpRestricted();
    sender.sendMessage(ChatColor.AQUA + " Can build: " + formatBoolean(hasBuildPermission(location.getBlock()), hasBuildBypass || !buildPermissionRequired ? null : true));
    sender.sendMessage(ChatColor.AQUA + " Can break: " + formatBoolean(hasBreakPermission(location.getBlock()), hasBreakBypass || !breakPermissionRequired ? null : true));
    sender.sendMessage(ChatColor.AQUA + " Can pvp: " + formatBoolean(isPVPAllowed(location), hasPVPBypass || !pvpRestricted ? null : true));
    boolean isPlayer = player != null;
    boolean spellDisguiseRestricted = (spell == null) ? false : spell.isDisguiseRestricted();
    sender.sendMessage(ChatColor.AQUA + " Is disguised: " + formatBoolean(controller.isDisguised(getEntity()), null, isPlayer && spellDisguiseRestricted ? true : null));
    WorldBorder border = location.getWorld().getWorldBorder();
    double borderSize = border.getSize();
    // Kind of a hack, meant to prevent this from showing up when there's no border defined
    if (borderSize < 50000000) {
        borderSize = borderSize / 2 - border.getWarningDistance();
        Location offset = location.subtract(border.getCenter());
        boolean isOutsideBorder = (offset.getX() < -borderSize || offset.getX() > borderSize || offset.getZ() < -borderSize || offset.getZ() > borderSize);
        sender.sendMessage(ChatColor.AQUA + " Is in world border (" + ChatColor.GRAY + borderSize + ChatColor.AQUA + "): " + formatBoolean(!isOutsideBorder, true, false));
    }
    if (spell != null) {
        sender.sendMessage(ChatColor.AQUA + " Has pnode " + ChatColor.GOLD + spell.getPermissionNode() + ChatColor.AQUA + ": " + formatBoolean(spell.hasCastPermission(player), hasBypass ? null : true));
        sender.sendMessage(ChatColor.AQUA + " Region override: " + formatBoolean(controller.getRegionCastPermission(player, spell, location), hasBypass ? null : true));
        sender.sendMessage(ChatColor.AQUA + " Field override: " + formatBoolean(controller.getPersonalCastPermission(player, spell, location), hasBypass ? null : true));
        com.elmakers.mine.bukkit.api.block.MaterialBrush brush = spell.getBrush();
        if (brush != null) {
            sender.sendMessage(ChatColor.GOLD + " " + spell.getName() + ChatColor.AQUA + " is erase: " + formatBoolean(brush.isErase(), null));
        }
        sender.sendMessage(ChatColor.GOLD + " " + spell.getName() + ChatColor.AQUA + " requires build: " + formatBoolean(spell.requiresBuildPermission(), null, true, true));
        sender.sendMessage(ChatColor.GOLD + " " + spell.getName() + ChatColor.AQUA + " requires break: " + formatBoolean(spell.requiresBreakPermission(), null, true, true));
        sender.sendMessage(ChatColor.GOLD + " " + spell.getName() + ChatColor.AQUA + " requires pvp: " + formatBoolean(spell.isPvpRestricted(), null, true, true));
        sender.sendMessage(ChatColor.GOLD + " " + spell.getName() + ChatColor.AQUA + " allowed while disguised: " + formatBoolean(!spell.isDisguiseRestricted(), null, false, true));
        if (spell instanceof BaseSpell) {
            boolean buildPermission = ((BaseSpell) spell).hasBuildPermission(location.getBlock());
            sender.sendMessage(ChatColor.GOLD + " " + spell.getName() + ChatColor.AQUA + " has build: " + formatBoolean(buildPermission, hasBuildBypass || !spell.requiresBuildPermission() ? null : true));
            boolean breakPermission = ((BaseSpell) spell).hasBreakPermission(location.getBlock());
            sender.sendMessage(ChatColor.GOLD + " " + spell.getName() + ChatColor.AQUA + " has break: " + formatBoolean(breakPermission, hasBreakBypass || !spell.requiresBreakPermission() ? null : true));
        }
        sender.sendMessage(ChatColor.AQUA + " Can cast " + ChatColor.GOLD + spell.getName() + ChatColor.AQUA + ": " + formatBoolean(spell.canCast(location)));
    }
}
Also used : Player(org.bukkit.entity.Player) BaseSpell(com.elmakers.mine.bukkit.spell.BaseSpell) WorldBorder(org.bukkit.WorldBorder) Location(org.bukkit.Location) CastSourceLocation(com.elmakers.mine.bukkit.api.magic.CastSourceLocation)

Aggregations

BaseSpell (com.elmakers.mine.bukkit.spell.BaseSpell)3 CastSourceLocation (com.elmakers.mine.bukkit.api.magic.CastSourceLocation)2 MageSpell (com.elmakers.mine.bukkit.api.spell.MageSpell)2 Location (org.bukkit.Location)2 Player (org.bukkit.entity.Player)2 MaterialAndData (com.elmakers.mine.bukkit.api.block.MaterialAndData)1 CastingCost (com.elmakers.mine.bukkit.api.spell.CastingCost)1 Spell (com.elmakers.mine.bukkit.api.spell.Spell)1 ActionSpell (com.elmakers.mine.bukkit.spell.ActionSpell)1 BlockSpell (com.elmakers.mine.bukkit.spell.BlockSpell)1 BrushSpell (com.elmakers.mine.bukkit.spell.BrushSpell)1 TargetingSpell (com.elmakers.mine.bukkit.spell.TargetingSpell)1 UndoableSpell (com.elmakers.mine.bukkit.spell.UndoableSpell)1 WorldBorder (org.bukkit.WorldBorder)1 ItemStack (org.bukkit.inventory.ItemStack)1