Search in sources :

Example 1 with HeroesManager

use of com.elmakers.mine.bukkit.heroes.HeroesManager in project MagicPlugin by elBukkit.

the class Mage method clearCooldown.

@Override
public void clearCooldown() {
    cooldownExpiration = 0;
    HeroesManager heroes = controller.getHeroes();
    Player player = getPlayer();
    if (heroes != null && player != null) {
        heroes.clearCooldown(player);
    }
}
Also used : Player(org.bukkit.entity.Player) HeroesManager(com.elmakers.mine.bukkit.heroes.HeroesManager)

Example 2 with HeroesManager

use of com.elmakers.mine.bukkit.heroes.HeroesManager in project MagicPlugin by elBukkit.

the class Wand method removeMana.

@Override
public void removeMana(float amount) {
    if (isHeroes && mage != null) {
        HeroesManager heroes = controller.getHeroes();
        if (heroes != null) {
            heroes.removeMana(mage.getPlayer(), (int) Math.ceil(amount));
        }
    }
    super.removeMana(amount);
    updateMana();
}
Also used : HeroesManager(com.elmakers.mine.bukkit.heroes.HeroesManager)

Example 3 with HeroesManager

use of com.elmakers.mine.bukkit.heroes.HeroesManager in project MagicPlugin by elBukkit.

the class MagicController method finalizeIntegration.

protected void finalizeIntegration() {
    final PluginManager pluginManager = plugin.getServer().getPluginManager();
    // Check for BlockPhysics
    if (useBlockPhysics) {
        Plugin blockPhysicsPlugin = pluginManager.getPlugin("BlockPhysics");
        if (blockPhysicsPlugin != null) {
            blockPhysicsManager = new BlockPhysicsManager(plugin, blockPhysicsPlugin);
            if (blockPhysicsManager.isEnabled()) {
                getLogger().info("BlockPhysics found, some spells will now use physics-based block effects");
            } else {
                getLogger().warning("Error integrating with BlockPhysics, you may want to set 'enable_block_physics: false' in config.yml");
            }
        }
    }
    // Check for Minigames
    Plugin minigamesPlugin = pluginManager.getPlugin("Minigames");
    if (minigamesPlugin != null) {
        pluginManager.registerEvents(new MinigamesListener(this), plugin);
        getLogger().info("Minigames found, wands will deactivate before joining a minigame");
    }
    // Check for LibsDisguise
    Plugin libsDisguisePlugin = pluginManager.getPlugin("LibsDisguises");
    if (libsDisguisePlugin == null) {
        getLogger().info("LibsDisguises not found");
    } else if (libsDisguiseEnabled) {
        libsDisguiseManager = new LibsDisguiseManager(plugin, libsDisguisePlugin);
        if (libsDisguiseManager.initialize()) {
            getLogger().info("LibsDisguises found, mob disguises and disguise_restricted features enabled");
        } else {
            getLogger().warning("LibsDisguises integration failed");
        }
    } else {
        libsDisguiseManager = null;
        getLogger().info("LibsDisguises integration disabled");
    }
    // Check for MobArena
    Plugin mobArenaPlugin = pluginManager.getPlugin("MobArena");
    if (mobArenaPlugin == null) {
        getLogger().info("MobArena not found");
    } else if (mobArenaConfiguration.getBoolean("enabled", true)) {
        try {
            mobArenaManager = new MobArenaManager(this, mobArenaPlugin, mobArenaConfiguration);
            // getLogger().info("Integrated with MobArena, use \"magic:<itemkey>\" in arena configs for Magic items, magic mobs can be used in monster configurations");
            getLogger().info("MobArena found, magic mobs can be used in monster configurations");
        } catch (Throwable ex) {
            getLogger().warning("MobArena integration failed, you may need to update the MobArena plugin to use Magic items");
        }
    } else {
        getLogger().info("MobArena integration disabled");
    }
    // Vault integration is handled internally in MagicLib
    Plugin vaultPlugin = pluginManager.getPlugin("Vault");
    if (vaultPlugin == null) {
        getLogger().info("Vault not found, virtual economy unavailable");
    } else {
        if (VaultController.initialize(plugin, vaultPlugin)) {
            getLogger().info("Vault found, virtual economy and descriptive item names available");
        } else {
            getLogger().warning("Vault integration failed");
        }
    }
    // Try to link to Essentials:
    Plugin essentials = pluginManager.getPlugin("Essentials");
    hasEssentials = essentials != null;
    if (hasEssentials) {
        if (warpController.setEssentials(essentials)) {
            getLogger().info("Integrating with Essentials for Recall warps");
        }
        try {
            mailer = new Mailer(essentials);
        } catch (Exception ex) {
            getLogger().warning("Essentials found, but failed to hook up to Mailer");
            mailer = null;
        }
    }
    if (essentialsSignsEnabled) {
        final MagicController me = this;
        Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

            @Override
            public void run() {
                try {
                    Object essentials = me.plugin.getServer().getPluginManager().getPlugin("Essentials");
                    if (essentials != null) {
                        Class<?> essentialsClass = essentials.getClass();
                        Field itemDbField = essentialsClass.getDeclaredField("itemDb");
                        itemDbField.setAccessible(true);
                        Object oldEntry = itemDbField.get(essentials);
                        if (oldEntry == null) {
                            getLogger().info("Essentials integration failure");
                            return;
                        }
                        if (oldEntry instanceof MagicItemDb) {
                            getLogger().info("Essentials integration already set up, skipping");
                            return;
                        }
                        if (!oldEntry.getClass().getName().equals("com.earth2me.essentials.ItemDb")) {
                            getLogger().info("Essentials Item DB class unexepcted: " + oldEntry.getClass().getName() + ", skipping integration");
                            return;
                        }
                        Object newEntry = new MagicItemDb(me, essentials);
                        itemDbField.set(essentials, newEntry);
                        Field confListField = essentialsClass.getDeclaredField("confList");
                        confListField.setAccessible(true);
                        @SuppressWarnings("unchecked") List<Object> confList = (List<Object>) confListField.get(essentials);
                        confList.remove(oldEntry);
                        confList.add(newEntry);
                        getLogger().info("Essentials found, hooked up custom item handler");
                    }
                } catch (Throwable ex) {
                    ex.printStackTrace();
                }
            }
        }, 5);
    }
    // Try to link to CommandBook
    hasCommandBook = false;
    try {
        Plugin commandBookPlugin = plugin.getServer().getPluginManager().getPlugin("CommandBook");
        if (commandBookPlugin != null) {
            if (warpController.setCommandBook(commandBookPlugin)) {
                getLogger().info("CommandBook found, integrating for Recall warps");
                hasCommandBook = true;
            } else {
                getLogger().warning("CommandBook integration failed");
            }
        }
    } catch (Throwable ignored) {
    }
    // Link to factions
    factionsManager.initialize(plugin);
    // Try to (dynamically) link to WorldGuard:
    worldGuardManager.initialize(plugin);
    // Link to PvpManager
    pvpManager.initialize(plugin);
    // Link to Multiverse
    multiverseManager.initialize(plugin);
    // Link to PreciousStones
    preciousStonesManager.initialize(plugin);
    // Link to Towny
    townyManager.initialize(plugin);
    // Link to Lockette
    locketteManager.initialize(plugin);
    // Link to GriefPrevention
    griefPreventionManager.initialize(plugin);
    // Link to NoCheatPlus
    ncpManager.initialize(plugin);
    // Try to link to Heroes:
    Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

        @Override
        public void run() {
            try {
                Plugin heroesPlugin = plugin.getServer().getPluginManager().getPlugin("Heroes");
                if (heroesPlugin != null) {
                    heroesManager = new HeroesManager(plugin, heroesPlugin);
                } else {
                    heroesManager = null;
                }
            } catch (Throwable ex) {
                plugin.getLogger().warning(ex.getMessage());
            }
        }
    }, 2);
    // Try to link to dynmap:
    try {
        Plugin dynmapPlugin = plugin.getServer().getPluginManager().getPlugin("dynmap");
        if (dynmapPlugin != null) {
            dynmap = new DynmapController(plugin, dynmapPlugin);
        } else {
            dynmap = null;
        }
    } catch (Throwable ex) {
        plugin.getLogger().warning(ex.getMessage());
    }
    if (dynmap == null) {
        getLogger().info("dynmap not found, not integrating.");
    } else {
        getLogger().info("dynmap found, integrating.");
    }
    // Try to link to Elementals:
    try {
        Plugin elementalsPlugin = plugin.getServer().getPluginManager().getPlugin("Splateds_Elementals");
        if (elementalsPlugin != null) {
            elementals = new ElementalsController(elementalsPlugin);
        } else {
            elementals = null;
        }
    } catch (Throwable ex) {
        plugin.getLogger().warning(ex.getMessage());
    }
    if (elementals != null) {
        getLogger().info("Elementals found, integrating.");
    }
    // Try to link to Citizens
    if (citizensEnabled) {
        try {
            Plugin citizensPlugin = plugin.getServer().getPluginManager().getPlugin("Citizens");
            if (citizensPlugin != null) {
                citizens = new CitizensController(citizensPlugin);
            } else {
                citizens = null;
                getLogger().info("Citizens not found, Magic trait unavailable.");
            }
        } catch (Throwable ex) {
            citizens = null;
            getLogger().warning("Error integrating with Citizens");
            plugin.getLogger().warning(ex.getMessage());
        }
    } else {
        citizens = null;
        getLogger().info("Citizens integration disabled.");
    }
    // Placeholder API
    if (placeholdersEnabled) {
        if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
            try {
                // Can only register this once
                if (placeholderAPIManager == null) {
                    placeholderAPIManager = new PlaceholderAPIManager(this);
                }
            } catch (Throwable ex) {
                getLogger().log(Level.WARNING, "Error integrating with PlaceholderAPI", ex);
            }
        }
    } else {
        getLogger().info("PlaceholderAPI integration disabled.");
    }
    // Light API
    if (lightAPIEnabled) {
        if (Bukkit.getPluginManager().isPluginEnabled("LightAPI")) {
            try {
                lightAPIManager = new LightAPIManager(plugin);
            } catch (Throwable ex) {
                getLogger().log(Level.WARNING, "Error integrating with LightAPI", ex);
            }
        } else {
            getLogger().info("LightAPI not found, Light action will not work");
        }
    } else {
        lightAPIManager = null;
        getLogger().info("LightAPI integration disabled.");
    }
    // Skript
    if (skriptEnabled) {
        if (Bukkit.getPluginManager().isPluginEnabled("Skript")) {
            try {
                new SkriptManager(this);
            } catch (Throwable ex) {
                getLogger().log(Level.WARNING, "Error integrating with Skript", ex);
            }
        }
    } else {
        getLogger().info("Skript integration disabled.");
    }
    // Citadel
    if (citadelConfiguration.getBoolean("enabled")) {
        if (Bukkit.getPluginManager().isPluginEnabled("Citadel")) {
            try {
                citadelManager = new CitadelManager(this, citadelConfiguration);
            } catch (Throwable ex) {
                getLogger().log(Level.WARNING, "Error integrating with Citadel", ex);
            }
        }
    } else {
        getLogger().info("Citadel integration disabled.");
    }
    // Activate Metrics
    activateMetrics();
    // Set up the PlayerSpells timer
    final MageUpdateTask mageTask = new MageUpdateTask(this);
    Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, mageTask, 0, mageUpdateFrequency);
    // Set up the Block update timer
    final BatchUpdateTask blockTask = new BatchUpdateTask(this);
    Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, blockTask, 0, workFrequency);
    // Set up the Update check timer
    final UndoUpdateTask undoTask = new UndoUpdateTask(this);
    Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, undoTask, 0, undoFrequency);
    registerListeners();
    // Activate/load any active player Mages
    Collection<? extends Player> allPlayers = plugin.getServer().getOnlinePlayers();
    for (Player player : allPlayers) {
        getMage(player);
    }
    // Set up Break/Build/PVP Managers
    blockBreakManagers.clear();
    blockBuildManagers.clear();
    pvpManagers.clear();
    // PVP Managers
    if (worldGuardManager.isEnabled())
        pvpManagers.add(worldGuardManager);
    if (pvpManager.isEnabled())
        pvpManagers.add(pvpManager);
    if (multiverseManager.isEnabled())
        pvpManagers.add(multiverseManager);
    if (preciousStonesManager.isEnabled())
        pvpManagers.add(preciousStonesManager);
    if (townyManager.isEnabled())
        pvpManagers.add(townyManager);
    if (griefPreventionManager.isEnabled())
        pvpManagers.add(griefPreventionManager);
    if (factionsManager.isEnabled())
        pvpManagers.add(factionsManager);
    // Build Managers
    if (worldGuardManager.isEnabled())
        blockBuildManagers.add(worldGuardManager);
    if (factionsManager.isEnabled())
        blockBuildManagers.add(factionsManager);
    if (locketteManager.isEnabled())
        blockBuildManagers.add(locketteManager);
    if (preciousStonesManager.isEnabled())
        blockBuildManagers.add(preciousStonesManager);
    if (townyManager.isEnabled())
        blockBuildManagers.add(townyManager);
    if (griefPreventionManager.isEnabled())
        blockBuildManagers.add(griefPreventionManager);
    if (mobArenaManager != null && mobArenaManager.isProtected())
        blockBuildManagers.add(mobArenaManager);
    // Break Managers
    if (worldGuardManager.isEnabled())
        blockBreakManagers.add(worldGuardManager);
    if (factionsManager.isEnabled())
        blockBreakManagers.add(factionsManager);
    if (locketteManager.isEnabled())
        blockBreakManagers.add(locketteManager);
    if (preciousStonesManager.isEnabled())
        blockBreakManagers.add(preciousStonesManager);
    if (townyManager.isEnabled())
        blockBreakManagers.add(townyManager);
    if (griefPreventionManager.isEnabled())
        blockBreakManagers.add(griefPreventionManager);
    if (mobArenaManager != null && mobArenaManager.isProtected())
        blockBreakManagers.add(mobArenaManager);
    if (citadelManager != null)
        blockBreakManagers.add(citadelManager);
    initialized = true;
}
Also used : PlaceholderAPIManager(com.elmakers.mine.bukkit.integration.PlaceholderAPIManager) BlockPhysicsManager(com.elmakers.mine.bukkit.integration.BlockPhysicsManager) HeroesManager(com.elmakers.mine.bukkit.heroes.HeroesManager) PluginManager(org.bukkit.plugin.PluginManager) Field(java.lang.reflect.Field) ElementalsController(com.elmakers.mine.bukkit.elementals.ElementalsController) CitizensController(com.elmakers.mine.bukkit.citizens.CitizensController) SkriptManager(com.elmakers.mine.bukkit.integration.SkriptManager) LightAPIManager(com.elmakers.mine.bukkit.integration.LightAPIManager) ArrayList(java.util.ArrayList) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) List(java.util.List) MinigamesListener(com.elmakers.mine.bukkit.magic.listener.MinigamesListener) MobArenaManager(com.elmakers.mine.bukkit.integration.MobArenaManager) EffectPlayer(com.elmakers.mine.bukkit.effect.EffectPlayer) Player(org.bukkit.entity.Player) DynmapController(com.elmakers.mine.bukkit.dynmap.DynmapController) LibsDisguiseManager(com.elmakers.mine.bukkit.integration.LibsDisguiseManager) Mailer(com.elmakers.mine.bukkit.essentials.Mailer) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException) IOException(java.io.IOException) ParseException(java.text.ParseException) MagicItemDb(com.elmakers.mine.bukkit.essentials.MagicItemDb) CitadelManager(com.elmakers.mine.bukkit.protection.CitadelManager) Plugin(org.bukkit.plugin.Plugin)

Example 4 with HeroesManager

use of com.elmakers.mine.bukkit.heroes.HeroesManager in project MagicPlugin by elBukkit.

the class Mage method setRemainingCooldown.

@Override
public void setRemainingCooldown(long ms) {
    cooldownExpiration = Math.max(ms + System.currentTimeMillis(), cooldownExpiration);
    HeroesManager heroes = controller.getHeroes();
    Player player = getPlayer();
    if (heroes != null && player != null) {
        heroes.setCooldown(player, ms);
    }
}
Also used : Player(org.bukkit.entity.Player) HeroesManager(com.elmakers.mine.bukkit.heroes.HeroesManager)

Example 5 with HeroesManager

use of com.elmakers.mine.bukkit.heroes.HeroesManager in project MagicPlugin by elBukkit.

the class Wand method activate.

public boolean activate(Mage mage, boolean offhand) {
    if (mage == null)
        return false;
    Player player = mage.getPlayer();
    if (player == null)
        return false;
    if (!controller.hasWandPermission(player, this))
        return false;
    InventoryView openInventory = player.getOpenInventory();
    InventoryType inventoryType = openInventory.getType();
    if (inventoryType == InventoryType.ENCHANTING || inventoryType == InventoryType.ANVIL)
        return false;
    if (hasUses && uses <= 0) {
        if (offhand) {
            player.getInventory().setItemInOffHand(new ItemStack(Material.AIR, 1));
        } else {
            player.getInventory().setItemInMainHand(new ItemStack(Material.AIR, 1));
        }
        return false;
    }
    if (!canUse(player)) {
        mage.sendMessage(getMessage("bound").replace("$name", getOwner()));
        return false;
    }
    if (this.isUpgrade) {
        controller.getLogger().warning("Activated an upgrade item- this shouldn't happen");
        return false;
    }
    WandPreActivateEvent preActivateEvent = new WandPreActivateEvent(mage, this);
    Bukkit.getPluginManager().callEvent(preActivateEvent);
    if (preActivateEvent.isCancelled()) {
        return false;
    }
    boolean needsSave = false;
    if (hasId) {
        needsSave = this.checkId() || needsSave;
    } else {
        setProperty("id", null);
    }
    this.mage = mage;
    this.isInOffhand = offhand;
    this.heldSlot = offhand ? OFFHAND_SLOT : player.getInventory().getHeldItemSlot();
    if (mageClassKeys != null && !mageClassKeys.isEmpty()) {
        MageClass mageClass = null;
        for (String mageClassKey : mageClassKeys) {
            mageClass = mage.getClass(mageClassKey);
            if (mageClass != null)
                break;
        }
        if (mageClass == null) {
            Integer lastSlot = mage.getLastActivatedSlot();
            if (!offhand && (lastSlot == null || lastSlot != player.getInventory().getHeldItemSlot())) {
                mage.setLastActivatedSlot(player.getInventory().getHeldItemSlot());
                mage.sendMessage(controller.getMessages().get("mage.no_class").replace("$name", getName()));
            }
            return false;
        }
        setMageClass(mageClass);
        if (!offhand) {
            mage.setActiveClass(mageClass.getKey());
        }
        // This double-load here is not really ideal.
        // Seems hard to prevent without merging Wand construction and activation, though.
        loadProperties();
    }
    mage.setLastActivatedSlot(player.getInventory().getHeldItemSlot());
    // Check for replacement template
    String replacementTemplate = getString("replace_on_activate", "");
    if (!replacementTemplate.isEmpty() && !replacementTemplate.equals(template)) {
        playEffects("replace");
        setTemplate(replacementTemplate);
        loadProperties();
        saveState();
        return activate(mage, offhand);
    }
    // We have to delay this 1 tick so it happens after the Mage has accepted the Wand
    if (getMode() != WandMode.INVENTORY || offhand) {
        Plugin plugin = controller.getPlugin();
        plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

            @Override
            public void run() {
                showActiveIcon(true);
                playPassiveEffects("open");
            }
        }, 1);
    }
    // Check for an empty wand and auto-fill
    if (!isUpgrade && (controller.fillWands() || autoFill)) {
        fill(mage.getPlayer(), controller.getMaxWandFillLevel());
        needsSave = true;
    }
    if (isHeroes) {
        HeroesManager heroes = controller.getHeroes();
        if (heroes != null) {
            Set<String> skills = heroes.getSkills(player);
            Collection<String> currentSpells = new ArrayList<>(getSpells());
            for (String spellKey : currentSpells) {
                if (spellKey.startsWith("heroes*") && !skills.contains(spellKey.substring(7))) {
                    removeSpell(spellKey);
                }
            }
            // Hack to prevent messaging
            this.mage = null;
            for (String skillKey : skills) {
                String heroesKey = "heroes*" + skillKey;
                if (!spells.contains(heroesKey)) {
                    addSpell(heroesKey);
                }
            }
            this.mage = mage;
        }
    }
    // Check for auto-organize
    if (autoOrganize && !isUpgrade) {
        organizeInventory(mage);
        needsSave = true;
    }
    // Check for auto-alphabetize
    if (autoAlphabetize && !isUpgrade) {
        alphabetizeInventory();
        needsSave = true;
    }
    boolean forceUpdate = false;
    if (checkInventoryForUpgrades()) {
        forceUpdate = true;
        needsSave = true;
    }
    // Check for auto-bind
    if (bound) {
        String mageName = ChatColor.stripColor(mage.getPlayer().getDisplayName());
        String mageId = mage.getId();
        boolean ownerRenamed = owner != null && ownerId != null && ownerId.equals(mageId) && !owner.equals(mageName);
        if (ownerId == null || ownerId.length() == 0 || owner == null || ownerRenamed) {
            takeOwnership(mage.getPlayer());
            needsSave = true;
        }
    }
    // Check for randomized wands
    if (randomizeOnActivate) {
        randomize();
        randomizeOnActivate = false;
        forceUpdate = true;
        needsSave = true;
    }
    // Don't build the inventory until activated so we can take Mage boosts into account
    if (offhand) {
        mage.setOffhandWand(this);
    } else {
        mage.setActiveWand(this);
    }
    buildInventory();
    updateMaxMana(false);
    tick();
    if (!isInOffhand) {
        updateMana();
    }
    checkActiveMaterial();
    if (needsSave) {
        saveState();
    }
    updateActiveMaterial();
    updateName();
    updateLore();
    // Play activate FX
    playPassiveEffects("activate");
    lastSoundEffect = 0;
    lastParticleEffect = 0;
    lastSpellCast = 0;
    if (forceUpdate) {
        DeprecatedUtils.updateInventory(player);
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) MageClass(com.elmakers.mine.bukkit.magic.MageClass) InventoryType(org.bukkit.event.inventory.InventoryType) ArrayList(java.util.ArrayList) WandPreActivateEvent(com.elmakers.mine.bukkit.api.event.WandPreActivateEvent) HeroesManager(com.elmakers.mine.bukkit.heroes.HeroesManager) InventoryView(org.bukkit.inventory.InventoryView) ItemStack(org.bukkit.inventory.ItemStack) Plugin(org.bukkit.plugin.Plugin)

Aggregations

HeroesManager (com.elmakers.mine.bukkit.heroes.HeroesManager)8 Player (org.bukkit.entity.Player)7 ArrayList (java.util.ArrayList)3 ItemStack (org.bukkit.inventory.ItemStack)3 Mage (com.elmakers.mine.bukkit.api.magic.Mage)2 MageController (com.elmakers.mine.bukkit.api.magic.MageController)2 MagicController (com.elmakers.mine.bukkit.magic.MagicController)2 Plugin (org.bukkit.plugin.Plugin)2 MaterialAndData (com.elmakers.mine.bukkit.api.block.MaterialAndData)1 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)1 WandPreActivateEvent (com.elmakers.mine.bukkit.api.event.WandPreActivateEvent)1 MageClass (com.elmakers.mine.bukkit.api.magic.MageClass)1 Messages (com.elmakers.mine.bukkit.api.magic.Messages)1 SpellKey (com.elmakers.mine.bukkit.api.spell.SpellKey)1 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)1 CitizensController (com.elmakers.mine.bukkit.citizens.CitizensController)1 DynmapController (com.elmakers.mine.bukkit.dynmap.DynmapController)1 EffectPlayer (com.elmakers.mine.bukkit.effect.EffectPlayer)1 ElementalsController (com.elmakers.mine.bukkit.elementals.ElementalsController)1 MagicItemDb (com.elmakers.mine.bukkit.essentials.MagicItemDb)1