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