Search in sources :

Example 11 with Mage

use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.

the class CraftingController method onCraftItem.

@EventHandler
public void onCraftItem(CraftItemEvent event) {
    HumanEntity human = event.getWhoClicked();
    if (!(human instanceof Player))
        return;
    Player player = (Player) human;
    Mage mage = controller.getMage(player);
    // Don't allow crafting in the wand inventory.
    if (mage.hasStoredInventory()) {
        event.setCancelled(true);
        return;
    }
    ItemStack currentItem = event.getCurrentItem();
    if (Wand.isWand(currentItem)) {
        CraftWandEvent castEvent = new CraftWandEvent(mage, controller.getWand(currentItem));
        Bukkit.getPluginManager().callEvent(castEvent);
    }
}
Also used : Player(org.bukkit.entity.Player) Mage(com.elmakers.mine.bukkit.api.magic.Mage) HumanEntity(org.bukkit.entity.HumanEntity) ItemStack(org.bukkit.inventory.ItemStack) CraftWandEvent(com.elmakers.mine.bukkit.api.event.CraftWandEvent) EventHandler(org.bukkit.event.EventHandler)

Example 12 with Mage

use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.

the class EntityController method onEntityPreDamageByEntity.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEntityPreDamageByEntity(EntityDamageByEntityEvent event) {
    Entity entity = event.getEntity();
    if (entity instanceof Projectile || entity instanceof TNTPrimed)
        return;
    Mage entityMage = controller.getRegisteredMage(entity);
    if (entityMage != null) {
        entityMage.damagedBy(event.getDamager(), event.getDamage());
        if (entity instanceof Player) {
            Player damaged = (Player) entity;
            if (damaged.isBlocking()) {
                com.elmakers.mine.bukkit.api.wand.Wand damagedWand = entityMage.getActiveWand();
                if (damagedWand != null) {
                    damagedWand.playEffects("hit_blocked");
                }
            }
        }
        if (entityMage.isSuperProtected()) {
            event.setCancelled(true);
            return;
        }
    }
    Entity damager = event.getDamager();
    if (entityDamageReduction != null) {
        Double reduction = entityDamageReduction.get(damager.getType());
        if (reduction != null) {
            if (reduction >= 1) {
                event.setCancelled(true);
                return;
            }
            event.setDamage(event.getDamage() * (1 - reduction));
        }
    }
    if (damager instanceof Player) {
        Mage damagerMage = controller.getRegisteredMage(damager);
        com.elmakers.mine.bukkit.api.wand.Wand activeWand = null;
        boolean isMelee = event.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK && !CompatibilityUtils.isDamaging;
        if (isMelee && meleeDamageReduction > 0) {
            if (meleeDamageReduction >= 1) {
                event.setCancelled(true);
                return;
            }
            event.setDamage(event.getDamage() * (1 - meleeDamageReduction));
        }
        if (isMelee && damagerMage != null) {
            activeWand = damagerMage.getActiveWand();
            if (activeWand != null) {
                activeWand.playEffects("hit_entity");
                activeWand.damageDealt(event.getDamage(), entity);
            }
        }
        if (preventWandMeleeDamage) {
            boolean hasWand = activeWand != null;
            Player player = (Player) damager;
            ItemStack itemInHand = player.getInventory().getItemInMainHand();
            boolean isMeleeWeapon = controller.isMeleeWeapon(itemInHand);
            if (isMelee && hasWand && !isMeleeWeapon) {
                event.setCancelled(true);
                CompatibilityUtils.isDamaging = true;
                activeWand.performAction(activeWand.getLeftClickAction());
                CompatibilityUtils.isDamaging = false;
            } else if (!hasWand && preventMeleeDamage && isMelee && !isMeleeWeapon) {
                event.setCancelled(true);
            }
        }
    } else {
        Targeting.checkTracking(controller.getPlugin(), damager, entity, null);
    }
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) Mage(com.elmakers.mine.bukkit.api.magic.Mage) TNTPrimed(org.bukkit.entity.TNTPrimed) ItemStack(org.bukkit.inventory.ItemStack) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 13 with Mage

use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.

the class MagicRequirement method checkRequirement.

public boolean checkRequirement(@Nonnull CastContext context) {
    Mage mage = context.getMage();
    Player player = mage.getPlayer();
    if (permissionNode != null && (player == null || !player.hasPermission(permissionNode))) {
        return false;
    }
    Wand wand = context.getWand();
    if (wand == null && requireWand) {
        return false;
    }
    if (requiredTemplate != null) {
        String template = wand.getTemplateKey();
        if (template == null || !template.equals(requiredTemplate)) {
            return false;
        }
    }
    if (requiredTemplates != null) {
        String template = wand.getTemplateKey();
        if (template == null || !requiredTemplates.contains(template)) {
            return false;
        }
    }
    CasterProperties checkProperties = context.getActiveProperties();
    ProgressionPath path = checkProperties.getPath();
    if (mageClass != null && !mageClass.isEmpty()) {
        if (!mage.hasClassUnlocked(mageClass)) {
            return false;
        }
    }
    if (requiredPath != null || exactPath != null) {
        if (path == null) {
            return false;
        }
        if (requiredPath != null && !path.hasPath(requiredPath)) {
            return false;
        }
        if (exactPath != null && !exactPath.equals(path.getKey())) {
            return false;
        }
        if (requiresCompletedPath != null) {
            boolean hasPathCompleted = false;
            if (path.hasPath(requiresCompletedPath)) {
                if (path.getKey().equals(requiresCompletedPath)) {
                    hasPathCompleted = !path.canProgress(checkProperties);
                } else {
                    hasPathCompleted = true;
                }
            }
            if (!hasPathCompleted) {
                return false;
            }
        }
    }
    if (wandProperties != null) {
        if (!checkProperties(wand, wandProperties)) {
            return false;
        }
    }
    if (classProperties != null) {
        MageClass activeClass = mageClass == null ? mage.getActiveClass() : mage.getClass(mageClass);
        if (activeClass == null) {
            return false;
        }
        if (!checkProperties(activeClass, classProperties)) {
            return false;
        }
    }
    if (attributes != null) {
        for (PropertyRequirement requirement : attributes) {
            String key = requirement.key;
            Double value = mage.getAttribute(key);
            if (!checkProperty(requirement, value)) {
                return false;
            }
        }
    }
    return true;
}
Also used : ProgressionPath(com.elmakers.mine.bukkit.api.magic.ProgressionPath) CasterProperties(com.elmakers.mine.bukkit.api.magic.CasterProperties) Player(org.bukkit.entity.Player) MageClass(com.elmakers.mine.bukkit.api.magic.MageClass) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Wand(com.elmakers.mine.bukkit.api.wand.Wand)

Example 14 with Mage

use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.

the class MagicCommandExecutor method onGiveUpgrade.

protected boolean onGiveUpgrade(CommandSender sender, Player player, String wandKey, boolean quiet, boolean giveItem, boolean giveValue, boolean showWorth) {
    Mage mage = controller.getMage(player);
    Wand currentWand = mage.getActiveWand();
    if (currentWand != null) {
        currentWand.closeInventory();
    }
    Wand wand = api.createWand(wandKey);
    if (wand != null) {
        wand.makeUpgrade();
        if (giveItem) {
            api.giveItemToPlayer(player, wand.getItem());
            if (sender != player && !quiet) {
                sender.sendMessage("Gave upgrade " + wand.getName() + " to " + player.getName());
            }
        }
        if (showWorth) {
            showWorth(sender, wand.getItem());
        }
    } else {
        if (!quiet)
            sender.sendMessage(api.getMessages().getParameterized("wand.unknown_template", "$name", wandKey));
        return false;
    }
    return true;
}
Also used : Mage(com.elmakers.mine.bukkit.api.magic.Mage) Wand(com.elmakers.mine.bukkit.api.wand.Wand) LostWand(com.elmakers.mine.bukkit.api.wand.LostWand)

Example 15 with Mage

use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.

the class MagicCommandExecutor method onTabComplete.

@Override
public Collection<String> onTabComplete(CommandSender sender, String commandName, String[] args) {
    List<String> options = new ArrayList<>();
    if (args.length == 1) {
        addIfPermissible(sender, options, "Magic.commands.magic.", "clean");
        addIfPermissible(sender, options, "Magic.commands.magic.", "clearcache");
        addIfPermissible(sender, options, "Magic.commands.magic.", "cancel");
        addIfPermissible(sender, options, "Magic.commands.magic.", "load");
        addIfPermissible(sender, options, "Magic.commands.magic.", "save");
        addIfPermissible(sender, options, "Magic.commands.magic.", "commit");
        addIfPermissible(sender, options, "Magic.commands.magic.", "give");
        addIfPermissible(sender, options, "Magic.commands.magic.", "worth");
        addIfPermissible(sender, options, "Magic.commands.magic.", "sell");
        addIfPermissible(sender, options, "Magic.commands.magic.", "list");
        addIfPermissible(sender, options, "Magic.commands.magic.", "rpcheck");
        addIfPermissible(sender, options, "Magic.commands.magic.", "rpsend");
    } else if (args.length == 2) {
        if (args[0].equalsIgnoreCase("list")) {
            addIfPermissible(sender, options, "Magic.commands.magic.list", "maps");
            addIfPermissible(sender, options, "Magic.commands.magic.list", "wands");
            addIfPermissible(sender, options, "Magic.commands.magic.list", "automata");
            addIfPermissible(sender, options, "Magic.commands.magic.list", "schematics");
            addIfPermissible(sender, options, "Magic.commands.magic.list", "entities");
            addIfPermissible(sender, options, "Magic.commands.magic.list", "tasks");
            addIfPermissible(sender, options, "Magic.commands.magic.list", "blocks");
            addIfPermissible(sender, options, "Magic.commands.magic.list", "mages");
        } else if (args[0].equalsIgnoreCase("give") || args[0].equalsIgnoreCase("worth") || args[0].equalsIgnoreCase("sell")) {
            options.add("wand");
            options.add("material");
            options.add("upgrade");
            Collection<SpellTemplate> spellList = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
            for (SpellTemplate spell : spellList) {
                options.add(spell.getKey());
            }
            Collection<String> allWands = api.getWandKeys();
            for (String wandKey : allWands) {
                options.add(wandKey);
            }
            options.addAll(api.getBrushes());
        }
    } else if (args.length == 3) {
        if (args[0].equalsIgnoreCase("give") || args[0].equalsIgnoreCase("sell")) {
            if (args[1].equalsIgnoreCase("upgrade") || args[1].equalsIgnoreCase("wand")) {
                Collection<String> allWands = api.getWandKeys();
                for (String wandKey : allWands) {
                    options.add(wandKey);
                }
            } else if (args[1].equalsIgnoreCase("material")) {
                options.addAll(api.getBrushes());
            }
        } else if (args[0].equalsIgnoreCase("configure") || args[0].equalsIgnoreCase("describe")) {
            Player player = DeprecatedUtils.getPlayer(args[1]);
            if (player != null) {
                Mage mage = controller.getMage(player);
                ConfigurationSection data = mage.getData();
                options.addAll(data.getKeys(false));
            }
        }
    }
    return options;
}
Also used : Player(org.bukkit.entity.Player) Mage(com.elmakers.mine.bukkit.api.magic.Mage) ArrayList(java.util.ArrayList) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Aggregations

Mage (com.elmakers.mine.bukkit.api.magic.Mage)187 Player (org.bukkit.entity.Player)62 Entity (org.bukkit.entity.Entity)56 Wand (com.elmakers.mine.bukkit.api.wand.Wand)47 MageController (com.elmakers.mine.bukkit.api.magic.MageController)45 ItemStack (org.bukkit.inventory.ItemStack)38 Location (org.bukkit.Location)33 LivingEntity (org.bukkit.entity.LivingEntity)31 ArrayList (java.util.ArrayList)25 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)18 Inventory (org.bukkit.inventory.Inventory)16 MageClass (com.elmakers.mine.bukkit.api.magic.MageClass)15 Spell (com.elmakers.mine.bukkit.api.spell.Spell)14 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)14 Block (org.bukkit.block.Block)14 Target (com.elmakers.mine.bukkit.utility.Target)13 EventHandler (org.bukkit.event.EventHandler)13 ItemMeta (org.bukkit.inventory.meta.ItemMeta)12 CasterProperties (com.elmakers.mine.bukkit.api.magic.CasterProperties)10 Vector (org.bukkit.util.Vector)10