Search in sources :

Example 1 with Messages

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

the class PlayerController method onPlayerAnimate.

@EventHandler(ignoreCancelled = true)
public void onPlayerAnimate(PlayerAnimationEvent event) {
    Player player = event.getPlayer();
    if (event.getAnimationType() != PlayerAnimationType.ARM_SWING) {
        return;
    }
    Mage mage = controller.getMage(player);
    Wand wand = mage.checkWand();
    if (wand == null)
        return;
    Messages messages = controller.getMessages();
    if (!controller.hasWandPermission(player)) {
        return;
    }
    // Check for region or wand-specific permissions
    if (!controller.hasWandPermission(player, wand)) {
        wand.deactivate();
        mage.sendMessage(messages.get("wand.no_permission").replace("$wand", wand.getName()));
        return;
    }
    if (!mage.checkLastClick(clickCooldown)) {
        return;
    }
    if (wand.isUpgrade())
        return;
    wand.playEffects("swing");
    wand.performAction(wand.getLeftClickAction());
}
Also used : Player(org.bukkit.entity.Player) Messages(com.elmakers.mine.bukkit.api.magic.Messages) Mage(com.elmakers.mine.bukkit.magic.Mage) Wand(com.elmakers.mine.bukkit.wand.Wand) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Messages

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

the class PlayerController method onPlayerInteract.

@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerInteract(PlayerInteractEvent event) {
    if (!controller.isLoaded())
        return;
    Action action = event.getAction();
    boolean isLeftClick = action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK;
    boolean isRightClick = (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK);
    // We only care about left click and right click.
    if (!isLeftClick && !isRightClick)
        return;
    // Note that an interact on air event will arrive pre-cancelled
    // So this is kind of useless. :\
    // if (event.isCancelled()) return;
    // Block block = event.getClickedBlock();
    // controller.getLogger().info("INTERACT: " + event.getAction() + " on " + (block == null ? "NOTHING" : block.getType()) + " cancelled: " + event.isCancelled());
    Player player = event.getPlayer();
    // Don't allow interacting while holding spells, brushes or upgrades
    ItemStack itemInHand = player.getInventory().getItemInMainHand();
    boolean isSkill = Wand.isSkill(itemInHand);
    boolean isSpell = !isSkill && Wand.isSpell(itemInHand);
    if (isSpell || Wand.isBrush(itemInHand) || Wand.isUpgrade(itemInHand)) {
        event.setCancelled(true);
        return;
    }
    boolean isOffhandSkill = false;
    ItemStack itemInOffhand = player.getInventory().getItemInOffHand();
    if (isRightClick) {
        isOffhandSkill = Wand.isSkill(itemInOffhand);
        boolean isOffhandSpell = !isOffhandSkill && Wand.isSpell(itemInOffhand);
        if (isOffhandSpell || Wand.isBrush(itemInOffhand) || Wand.isUpgrade(itemInOffhand)) {
            event.setCancelled(true);
            return;
        }
    }
    Mage mage = controller.getMage(player);
    Wand wand = mage.checkWand();
    if (action == Action.RIGHT_CLICK_BLOCK) {
        Material material = event.getClickedBlock().getType();
        isRightClick = !controller.isInteractable(event.getClickedBlock());
        // This is to prevent Essentials signs from giving you an item in your wand inventory.
        if (wand != null && (material == Material.SIGN_POST || material == Material.WALL_SIGN)) {
            wand.closeInventory();
        }
    }
    if (!isLeftClick && !mage.checkLastClick(clickCooldown)) {
        return;
    }
    // Prefer wand right-click if wand is active
    if (isOffhandSkill && wand != null) {
        if (wand.getRightClickAction() != WandAction.NONE) {
            isOffhandSkill = false;
        }
    }
    if (isRightClick && (isOffhandSkill || isSkill)) {
        if (isSkill) {
            mage.useSkill(itemInHand);
        } else {
            mage.useSkill(itemInOffhand);
        }
        event.setCancelled(true);
        return;
    }
    // Check for offhand casting
    if (isRightClick) {
        if (allowOffhandCasting && mage.offhandCast()) {
            // which in the offhand case are right-click actions.
            if (cancelInteractOnLeftClick) {
                event.setCancelled(true);
            }
            return;
        }
    }
    // Special-case here for skulls, which actually are not wearable via right-click.
    if (itemInHand != null && isRightClick && controller.isWearable(itemInHand) && itemInHand.getType() != Material.SKULL_ITEM) {
        if (wand != null) {
            wand.deactivate();
        }
        controller.onArmorUpdated(mage);
        return;
    }
    if (wand == null)
        return;
    Messages messages = controller.getMessages();
    if (!controller.hasWandPermission(player)) {
        return;
    }
    // Check for region or wand-specific permissions
    if (!controller.hasWandPermission(player, wand)) {
        wand.deactivate();
        mage.sendMessage(messages.get("wand.no_permission").replace("$wand", wand.getName()));
        return;
    }
    // Check for enchantment table click
    Block clickedBlock = event.getClickedBlock();
    if (clickedBlock != null && clickedBlock.getType() != Material.AIR && enchantBlockMaterial != null && enchantBlockMaterial.is(clickedBlock)) {
        Spell spell = null;
        if (player.isSneaking()) {
            spell = enchantSneakClickSpell != null ? mage.getSpell(enchantSneakClickSpell) : null;
        } else {
            spell = enchantClickSpell != null ? mage.getSpell(enchantClickSpell) : null;
        }
        if (spell != null) {
            spell.cast();
            event.setCancelled(true);
            return;
        }
    }
    if (isLeftClick && !wand.isUpgrade() && wand.getLeftClickAction() != WandAction.NONE && cancelInteractOnLeftClick) {
        event.setCancelled(true);
    }
    if (isRightClick && wand.performAction(wand.getRightClickAction()) && cancelInteractOnRightClick) {
        event.setCancelled(true);
    }
}
Also used : Action(org.bukkit.event.block.Action) WandAction(com.elmakers.mine.bukkit.api.wand.WandAction) Player(org.bukkit.entity.Player) Messages(com.elmakers.mine.bukkit.api.magic.Messages) Mage(com.elmakers.mine.bukkit.magic.Mage) Wand(com.elmakers.mine.bukkit.wand.Wand) Block(org.bukkit.block.Block) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) Spell(com.elmakers.mine.bukkit.api.spell.Spell) EventHandler(org.bukkit.event.EventHandler)

Example 3 with Messages

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

the class PlayerController method onPlayerPrePickupItem.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerPrePickupItem(PlayerPickupItemEvent event) {
    Item item = event.getItem();
    ItemStack pickup = item.getItemStack();
    if (NMSUtils.isTemporary(pickup) || item.hasMetadata("temporary")) {
        item.remove();
        event.setCancelled(true);
        return;
    }
    boolean isWand = Wand.isWand(pickup);
    // Creative mode inventory hacky work-around :\
    if (event.getPlayer().getGameMode() == GameMode.CREATIVE && isWand && enableCreativeModeEjecting) {
        event.setCancelled(true);
        return;
    }
    // Check to see if this is an item we might undo, and remove it from undo
    UndoList undoList = controller.getEntityUndo(item);
    if (undoList != null) {
        undoList.remove(item);
    }
    Player player = event.getPlayer();
    Mage mage = controller.getMage(player);
    // Remove lost wands from records
    Messages messages = controller.getMessages();
    if (isWand) {
        Wand wand = controller.getWand(pickup);
        if (!wand.canUse(player)) {
            if (lastDropWarn == 0 || System.currentTimeMillis() - lastDropWarn > 10000) {
                mage.sendMessage(messages.get("wand.bound").replace("$name", wand.getOwner()));
            }
            lastDropWarn = System.currentTimeMillis();
            event.setCancelled(true);
            return;
        }
        controller.removeLostWand(wand.getId());
    }
    // Wands will absorb spells and upgrade items
    Wand activeWand = mage.getActiveWand();
    if (activeWand != null && activeWand.isModifiable() && (Wand.isSpell(pickup) || Wand.isBrush(pickup) || Wand.isUpgrade(pickup) || Wand.isSP(pickup)) && activeWand.addItem(pickup)) {
        event.getItem().remove();
        event.setCancelled(true);
        return;
    }
    if (!mage.hasStoredInventory() && isWand) {
        mage.checkWandNextTick();
    }
}
Also used : Item(org.bukkit.entity.Item) Player(org.bukkit.entity.Player) Messages(com.elmakers.mine.bukkit.api.magic.Messages) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Mage(com.elmakers.mine.bukkit.magic.Mage) Wand(com.elmakers.mine.bukkit.wand.Wand) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 4 with Messages

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

the class AnimateSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    if (parameters.getString("animate", null) != null) {
        return super.onCast(parameters);
    }
    final Block targetBlock = getTargetBlock();
    if (targetBlock == null) {
        return SpellResult.NO_TARGET;
    }
    if (!hasBuildPermission(targetBlock)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    int seedRadius = parameters.getInt("seed_radius", 0);
    MaterialAndData targetMaterial = new MaterialAndData(targetBlock);
    List<String> materials = ConfigurationUtils.getStringList(parameters, "materials");
    if (seedRadius > 0 && materials != null && !materials.isEmpty()) {
        targetMaterial = new MaterialAndData(RandomUtils.getRandom(materials));
    } else if (parameters.contains("material")) {
        targetMaterial = ConfigurationUtils.getMaterialAndData(parameters, "material", targetMaterial);
        if (targetMaterial.isValid()) {
            addDestructible(targetMaterial);
        }
    }
    if (!mage.isSuperPowered() && seedRadius == 0) {
        MaterialSetManager materialSets = controller.getMaterialSetManager();
        MaterialSet restricted = materialSets.getMaterialSet("restricted");
        if (restricted != null && restricted.testMaterialAndData(targetMaterial)) {
            return SpellResult.FAIL;
        }
        if (parameters.contains("restricted")) {
            String customRestricted = parameters.getString("restricted");
            if (customRestricted != null && !customRestricted.equals("restricted")) {
                restricted = materialSets.fromConfigEmpty(customRestricted);
                if (restricted.testMaterialAndData(targetMaterial)) {
                    return SpellResult.FAIL;
                }
            }
        }
    }
    if (!isDestructible(targetBlock)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    registerForUndo(targetBlock);
    if (seedRadius > 0) {
        for (int dx = -seedRadius; dx < seedRadius; dx++) {
            for (int dz = -seedRadius; dz < seedRadius; dz++) {
                for (int dy = -seedRadius; dy < seedRadius; dy++) {
                    Block seedBlock = targetBlock.getRelative(dx, dy, dz);
                    if (isDestructible(seedBlock)) {
                        registerForUndo(seedBlock);
                        targetMaterial.modify(seedBlock);
                    }
                }
            }
        }
    }
    // Look for randomized levels
    int level = 0;
    if (parameters.contains("level")) {
        level = parameters.getInt("level", level);
    } else if (levelWeights != null) {
        level = RandomUtils.weightedRandom(levelWeights);
    }
    boolean simCheckDestructible = parameters.getBoolean("sim_check_destructible", true);
    simCheckDestructible = parameters.getBoolean("scd", simCheckDestructible);
    final ConfigurationSection automataParameters = new MemoryConfiguration();
    automataParameters.set("target", "self");
    automataParameters.set("cooldown", 0);
    automataParameters.set("m", targetMaterial.getKey());
    automataParameters.set("cd", (simCheckDestructible ? true : false));
    automataParameters.set("level", level);
    String automataName = parameters.getString("name", "Automata");
    Messages messages = controller.getMessages();
    String automataType = parameters.getString("message_type", "evil");
    List<String> prefixes = messages.getAll("automata." + automataType + ".prefixes");
    List<String> suffixes = messages.getAll("automata." + automataType + ".suffixes");
    automataName = prefixes.get(random.nextInt(prefixes.size())) + " " + automataName + " " + suffixes.get(random.nextInt(suffixes.size()));
    if (level > 1) {
        automataName += " " + escapeLevel(messages, "automata.level", level);
    }
    String message = getMessage("cast_broadcast").replace("$name", automataName);
    if (message.length() > 0) {
        controller.sendToMages(message, targetBlock.getLocation());
    }
    automataParameters.set("animate", automataName);
    String automataId = UUID.randomUUID().toString();
    final Mage mage = controller.getAutomaton(automataId, automataName);
    mage.setLocation(targetBlock.getLocation());
    mage.setQuiet(true);
    mage.addTag(getKey());
    final Spell spell = mage.getSpell(getKey());
    Bukkit.getScheduler().runTaskLater(controller.getPlugin(), new Runnable() {

        @Override
        public void run() {
            spell.cast(automataParameters);
        }
    }, 1);
    registerForUndo();
    return SpellResult.CAST;
}
Also used : Messages(com.elmakers.mine.bukkit.api.magic.Messages) MaterialSet(com.elmakers.mine.bukkit.api.magic.MaterialSet) MemoryConfiguration(org.bukkit.configuration.MemoryConfiguration) Spell(com.elmakers.mine.bukkit.api.spell.Spell) Mage(com.elmakers.mine.bukkit.api.magic.Mage) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) Block(org.bukkit.block.Block) MaterialSetManager(com.elmakers.mine.bukkit.api.magic.MaterialSetManager) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 5 with Messages

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

the class CasterProperties method addBrush.

@Override
public boolean addBrush(String brushKey) {
    BaseMagicConfigurable storage = getStorage("brushes");
    if (storage != this && storage != null) {
        return storage.addBrush(brushKey);
    }
    Collection<String> brushes = getBrushes();
    boolean modified = brushes.add(brushKey);
    if (modified) {
        setProperty("brushes", new ArrayList<>(brushes));
    }
    Mage mage = getMage();
    if (modified && mage != null) {
        Messages messages = controller.getMessages();
        String materialName = MaterialBrush.getMaterialName(messages, brushKey);
        if (materialName == null) {
            mage.getController().getLogger().warning("Invalid material: " + brushKey);
            materialName = brushKey;
        }
        sendAddMessage("brush_added", materialName);
    }
    return modified;
}
Also used : Messages(com.elmakers.mine.bukkit.api.magic.Messages)

Aggregations

Messages (com.elmakers.mine.bukkit.api.magic.Messages)17 Player (org.bukkit.entity.Player)6 Mage (com.elmakers.mine.bukkit.api.magic.Mage)5 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)5 ItemStack (org.bukkit.inventory.ItemStack)5 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)4 MageController (com.elmakers.mine.bukkit.api.magic.MageController)3 Mage (com.elmakers.mine.bukkit.magic.Mage)3 Wand (com.elmakers.mine.bukkit.wand.Wand)3 ArrayList (java.util.ArrayList)3 EventHandler (org.bukkit.event.EventHandler)3 MageSpell (com.elmakers.mine.bukkit.api.spell.MageSpell)2 Spell (com.elmakers.mine.bukkit.api.spell.Spell)2 Block (org.bukkit.block.Block)2 ItemMeta (org.bukkit.inventory.meta.ItemMeta)2 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)1 CastEvent (com.elmakers.mine.bukkit.api.event.CastEvent)1 PreCastEvent (com.elmakers.mine.bukkit.api.event.PreCastEvent)1 CasterProperties (com.elmakers.mine.bukkit.api.magic.CasterProperties)1 MageClass (com.elmakers.mine.bukkit.api.magic.MageClass)1