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;
}
Aggregations