Search in sources :

Example 1 with TeleportTask

use of com.elmakers.mine.bukkit.action.TeleportTask 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)

Aggregations

TeleportTask (com.elmakers.mine.bukkit.action.TeleportTask)1 BrushData (com.elmakers.mine.bukkit.api.data.BrushData)1 CastSourceLocation (com.elmakers.mine.bukkit.api.magic.CastSourceLocation)1 LostWand (com.elmakers.mine.bukkit.api.wand.LostWand)1 Wand (com.elmakers.mine.bukkit.wand.Wand)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Location (org.bukkit.Location)1 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)1 ItemStack (org.bukkit.inventory.ItemStack)1 Plugin (org.bukkit.plugin.Plugin)1