Search in sources :

Example 11 with Wand

use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.

the class Mage method load.

@Override
public boolean load(MageData data) {
    try {
        if (data == null) {
            finishLoad(data);
            return true;
        }
        boundWands.clear();
        Map<String, ItemStack> boundWandItems = data.getBoundWands();
        if (boundWandItems != null) {
            for (ItemStack boundWandItem : boundWandItems.values()) {
                try {
                    Wand boundWand = controller.getWand(boundWandItem);
                    boundWands.put(boundWand.getTemplateKey(), boundWand);
                } catch (Exception ex) {
                    controller.getLogger().log(Level.WARNING, "Failed to load bound wand for " + playerName + ": " + boundWandItem, ex);
                }
            }
        }
        this.data = data.getExtraData();
        this.properties.load(data.getProperties());
        this.properties.loadProperties();
        this.classes.clear();
        Map<String, ConfigurationSection> classProperties = data.getClassProperties();
        for (Map.Entry<String, ConfigurationSection> entry : classProperties.entrySet()) {
            // ... what to do if missing templates? Don't want to lose data. Will need to think about this.
            String mageClassKey = entry.getKey();
            MageClassTemplate classTemplate = controller.getMageClass(mageClassKey);
            if (classTemplate != null) {
                MageClass newClass = new MageClass(this, classTemplate);
                newClass.load(entry.getValue());
                classes.put(mageClassKey, newClass);
            }
        }
        // Link up parents
        for (MageClass mageClass : classes.values()) {
            assignParent(mageClass);
        }
        // Load activeClass
        setActiveClass(data.getActiveClass());
        cooldownExpiration = data.getCooldownExpiration();
        fallProtectionCount = data.getFallProtectionCount();
        fallProtection = data.getFallProtectionDuration();
        if (fallProtectionCount > 0 && fallProtection > 0) {
            fallProtection = System.currentTimeMillis() + fallProtection;
        }
        gaveWelcomeWand = data.getGaveWelcomeWand();
        playerName = data.getName();
        lastDeathLocation = data.getLastDeathLocation();
        lastCast = data.getLastCast();
        destinationWarp = data.getDestinationWarp();
        if (destinationWarp != null) {
            if (!destinationWarp.isEmpty()) {
                Location destination = controller.getWarp(destinationWarp);
                if (destination != null) {
                    Plugin plugin = controller.getPlugin();
                    controller.info("Warping " + getEntity().getName() + " to " + destinationWarp + " on login");
                    TeleportTask task = new TeleportTask(getController(), getEntity(), destination, 4, true, true, null);
                    Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, task, 1);
                } else {
                    controller.info("Failed to warp " + getEntity().getName() + " to " + destinationWarp + " on login, warp doesn't exist");
                }
            }
            destinationWarp = null;
        }
        getUndoQueue().load(data.getUndoData());
        respawnInventory = data.getRespawnInventory();
        respawnArmor = data.getRespawnArmor();
        restoreOpenWand = data.isOpenWand();
        BrushData brushData = data.getBrushData();
        if (brushData != null) {
            brush.load(brushData);
        }
        if (controller.isInventoryBackupEnabled()) {
            restoreInventory = data.getStoredInventory();
            restoreLevel = data.getStoredLevel();
            restoreExperience = data.getStoredExperience();
        }
    } catch (Exception ex) {
        controller.getLogger().log(Level.WARNING, "Failed to load player data for " + playerName, ex);
        return false;
    }
    finishLoad(data);
    return true;
}
Also used : Wand(com.elmakers.mine.bukkit.wand.Wand) LostWand(com.elmakers.mine.bukkit.api.wand.LostWand) TeleportTask(com.elmakers.mine.bukkit.action.TeleportTask) ItemStack(org.bukkit.inventory.ItemStack) Map(java.util.Map) HashMap(java.util.HashMap) BrushData(com.elmakers.mine.bukkit.api.data.BrushData) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) Location(org.bukkit.Location) CastSourceLocation(com.elmakers.mine.bukkit.api.magic.CastSourceLocation) Plugin(org.bukkit.plugin.Plugin)

Example 12 with Wand

use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.

the class Mage method updatePassiveEffects.

protected void updatePassiveEffects() {
    protection.clear();
    strength.clear();
    weakness.clear();
    attributes.clear();
    spMultiplier = 1;
    cooldownReduction = 0;
    costReduction = 0;
    consumeReduction = 0;
    List<PotionEffectType> currentEffects = new ArrayList<>(effectivePotionEffects.keySet());
    LivingEntity entity = getLivingEntity();
    effectivePotionEffects.clear();
    addPassiveEffects(properties, true);
    if (activeClass != null) {
        addPassiveEffects(activeClass, true);
        spMultiplier = (float) (spMultiplier * activeClass.getDouble("sp_multiplier", 1.0));
    }
    if (activeWand != null && !activeWand.isPassive()) {
        addPassiveEffects(activeWand, false);
        effectivePotionEffects.putAll(activeWand.getPotionEffects());
    }
    // Don't add these together so things stay balanced!
    if (offhandWand != null && !offhandWand.isPassive()) {
        addPassiveEffects(offhandWand, false);
        effectivePotionEffects.putAll(offhandWand.getPotionEffects());
        spMultiplier *= offhandWand.getSPMultiplier();
    }
    for (Wand armorWand : activeArmor.values()) {
        if (armorWand != null) {
            addPassiveEffects(armorWand, false);
            effectivePotionEffects.putAll(armorWand.getPotionEffects());
        }
    }
    if (entity != null) {
        for (PotionEffectType effectType : currentEffects) {
            if (!effectivePotionEffects.containsKey(effectType)) {
                entity.removePotionEffect(effectType);
            }
        }
        for (Map.Entry<PotionEffectType, Integer> effects : effectivePotionEffects.entrySet()) {
            PotionEffect effect = new PotionEffect(effects.getKey(), Integer.MAX_VALUE, effects.getValue(), true, false);
            CompatibilityUtils.applyPotionEffect(entity, effect);
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) ArrayList(java.util.ArrayList) Wand(com.elmakers.mine.bukkit.wand.Wand) LostWand(com.elmakers.mine.bukkit.api.wand.LostWand) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with Wand

use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.

the class Mage method save.

@Override
public boolean save(MageData data) {
    if (loading)
        return false;
    try {
        data.setName(getName());
        data.setId(getId());
        data.setLastCast(lastCast);
        data.setLastDeathLocation(lastDeathLocation);
        data.setLocation(location);
        data.setDestinationWarp(destinationWarp);
        data.setCooldownExpiration(cooldownExpiration);
        long now = System.currentTimeMillis();
        if (fallProtectionCount > 0 && fallProtection > now) {
            data.setFallProtectionCount(fallProtectionCount);
            data.setFallProtectionDuration(fallProtection - now);
        } else {
            data.setFallProtectionCount(0);
            data.setFallProtectionDuration(0);
        }
        BrushData brushData = new BrushData();
        brush.save(brushData);
        data.setBrushData(brushData);
        UndoData undoData = new UndoData();
        getUndoQueue().save(undoData);
        data.setUndoData(undoData);
        data.setSpellData(this.spellData.values());
        if (boundWands.size() > 0) {
            Map<String, ItemStack> wandItems = new HashMap<>();
            for (Map.Entry<String, Wand> wandEntry : boundWands.entrySet()) {
                wandItems.put(wandEntry.getKey(), wandEntry.getValue().getItem());
            }
            data.setBoundWands(wandItems);
        }
        data.setRespawnArmor(respawnArmor);
        data.setRespawnInventory(respawnInventory);
        data.setOpenWand(false);
        if (activeWand != null) {
            if (activeWand.hasStoredInventory()) {
                data.setStoredInventory(Arrays.asList(activeWand.getStoredInventory().getContents()));
            }
            if (activeWand.isInventoryOpen()) {
                data.setOpenWand(true);
            }
        }
        data.setGaveWelcomeWand(gaveWelcomeWand);
        data.setExtraData(this.data);
        data.setProperties(properties.getConfiguration());
        Map<String, ConfigurationSection> classProperties = new HashMap<>();
        for (Map.Entry<String, MageClass> entry : classes.entrySet()) {
            classProperties.put(entry.getKey(), entry.getValue().getConfiguration());
        }
        data.setClassProperties(classProperties);
        String activeClassKey = activeClass == null ? null : activeClass.getTemplate().getKey();
        data.setActiveClass(activeClassKey);
    } catch (Exception ex) {
        controller.getPlugin().getLogger().log(Level.WARNING, "Failed to save player data for " + playerName, ex);
        return false;
    }
    return true;
}
Also used : HashMap(java.util.HashMap) Wand(com.elmakers.mine.bukkit.wand.Wand) LostWand(com.elmakers.mine.bukkit.api.wand.LostWand) UndoData(com.elmakers.mine.bukkit.api.data.UndoData) ItemStack(org.bukkit.inventory.ItemStack) Map(java.util.Map) HashMap(java.util.HashMap) BrushData(com.elmakers.mine.bukkit.api.data.BrushData) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 14 with Wand

use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.

the class Mage method checkOffhandWand.

@Nullable
private Wand checkOffhandWand(ItemStack itemInHand) {
    Player player = getPlayer();
    if (isLoading() || player == null)
        return null;
    ItemStack offhandWandItem = offhandWand != null ? offhandWand.getItem() : null;
    if (InventoryUtils.isSameInstance(offhandWandItem, itemInHand))
        return offhandWand;
    if (!Wand.isWand(itemInHand))
        itemInHand = null;
    if ((itemInHand != null && offhandWandItem == null) || (offhandWandItem != null && itemInHand == null) || (itemInHand != null && offhandWandItem != null && !itemInHand.equals(offhandWandItem))) {
        if (offhandWand != null) {
            offhandWand.deactivate();
        }
        if (itemInHand != null && controller.hasWandPermission(player)) {
            Wand newActiveWand = controller.getWand(itemInHand);
            if (!newActiveWand.activateOffhand(this)) {
                setOffhandWand(null);
            }
        }
    }
    return offhandWand;
}
Also used : Player(org.bukkit.entity.Player) Wand(com.elmakers.mine.bukkit.wand.Wand) LostWand(com.elmakers.mine.bukkit.api.wand.LostWand) ItemStack(org.bukkit.inventory.ItemStack) Nullable(javax.annotation.Nullable)

Example 15 with Wand

use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.

the class MageClass method updated.

@Override
public void updated() {
    updateMaxMana(mage);
    Wand activeWand = mage.getActiveWand();
    if (activeWand != null) {
        activeWand.updated();
    }
    mage.updatePassiveEffects();
}
Also used : Wand(com.elmakers.mine.bukkit.wand.Wand)

Aggregations

Wand (com.elmakers.mine.bukkit.wand.Wand)36 Player (org.bukkit.entity.Player)24 ItemStack (org.bukkit.inventory.ItemStack)23 EventHandler (org.bukkit.event.EventHandler)17 LostWand (com.elmakers.mine.bukkit.api.wand.LostWand)11 Mage (com.elmakers.mine.bukkit.magic.Mage)11 PlayerInventory (org.bukkit.inventory.PlayerInventory)6 Spell (com.elmakers.mine.bukkit.api.spell.Spell)5 Nullable (javax.annotation.Nullable)5 LostWand (com.elmakers.mine.bukkit.wand.LostWand)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Inventory (org.bukkit.inventory.Inventory)4 GUIAction (com.elmakers.mine.bukkit.api.action.GUIAction)3 Messages (com.elmakers.mine.bukkit.api.magic.Messages)3 Location (org.bukkit.Location)3 Block (org.bukkit.block.Block)3 Entity (org.bukkit.entity.Entity)3 Item (org.bukkit.entity.Item)3