use of org.bukkit.configuration.ConfigurationSection 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 org.bukkit.configuration.ConfigurationSection 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 org.bukkit.configuration.ConfigurationSection in project MagicPlugin by elBukkit.
the class MageClass method getEffectiveConfiguration.
public ConfigurationSection getEffectiveConfiguration(boolean includeMage) {
ConfigurationSection effectiveConfiguration = ConfigurationUtils.cloneConfiguration(getConfiguration());
ConfigurationSection templateConfiguration = ConfigurationUtils.cloneConfiguration(template.getConfiguration());
for (String key : templateConfiguration.getKeys(false)) {
MagicPropertyType propertyRoute = propertyRoutes.get(key);
if (propertyRoute != null && propertyRoute != type) {
templateConfiguration.set(key, null);
}
}
ConfigurationUtils.overlayConfigurations(effectiveConfiguration, templateConfiguration);
if (parent != null) {
ConfigurationSection parentConfiguration = parent.getEffectiveConfiguration(includeMage);
ConfigurationUtils.overlayConfigurations(effectiveConfiguration, parentConfiguration);
} else if (includeMage) {
// If we have a parent, it has already incorporated Mage data
ConfigurationSection mageConfiguration = mageProperties.getConfiguration();
ConfigurationUtils.overlayConfigurations(effectiveConfiguration, mageConfiguration);
}
return effectiveConfiguration;
}
use of org.bukkit.configuration.ConfigurationSection in project MagicPlugin by elBukkit.
the class MageCommandExecutor method onTabComplete.
@Override
public Collection<String> onTabComplete(CommandSender sender, String commandName, String[] args) {
List<String> options = new ArrayList<>();
if (args.length == 1) {
addIfPermissible(sender, options, "Magic.commands.mage.", "add");
addIfPermissible(sender, options, "Magic.commands.mage.", "remove");
addIfPermissible(sender, options, "Magic.commands.mage.", "configure");
addIfPermissible(sender, options, "Magic.commands.mage.", "describe");
addIfPermissible(sender, options, "Magic.commands.mage.", "upgrade");
addIfPermissible(sender, options, "Magic.commands.mage.", "getdata");
addIfPermissible(sender, options, "Magic.commands.mage.", "setdata");
addIfPermissible(sender, options, "Magic.commands.mage.", "check");
addIfPermissible(sender, options, "Magic.commands.mage.", "debug");
addIfPermissible(sender, options, "Magic.commands.mage.", "reset");
addIfPermissible(sender, options, "Magic.commands.mage.", "unbind");
addIfPermissible(sender, options, "Magic.commands.mage.", "activate");
addIfPermissible(sender, options, "Magic.commands.mage.", "unlock");
addIfPermissible(sender, options, "Magic.commands.mage.", "lock");
addIfPermissible(sender, options, "Magic.commands.mage.", "levelspells");
addIfPermissible(sender, options, "Magic.commands.mage.", "attribute");
} else if (args.length == 2 && sender.hasPermission("Magic.commands.mage.others")) {
options.addAll(api.getPlayerNames());
}
if (args.length == 3 || args.length == 2) {
CommandSender target = args.length == 2 ? sender : DeprecatedUtils.getPlayer(args[1]);
String subCommand = args[0];
String subCommandPNode = "Magic.commands.mage." + subCommand;
if (subCommand.equalsIgnoreCase("setdata") || subCommand.equalsIgnoreCase("getdata")) {
if (target != null) {
Mage mage = controller.getMage(target);
ConfigurationSection data = mage.getData();
options.addAll(data.getKeys(false));
}
}
if (subCommand.equalsIgnoreCase("add")) {
Collection<SpellTemplate> spellList = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
for (SpellTemplate spell : spellList) {
addIfPermissible(sender, options, subCommandPNode, spell.getKey(), true);
}
addIfPermissible(sender, options, subCommandPNode, "brush", true);
}
if (subCommand.equalsIgnoreCase("remove")) {
if (target != null) {
Mage mage = controller.getMage(target);
MageClass mageClass = mage.getActiveClass();
if (mageClass != null) {
options.addAll(mageClass.getSpells());
}
}
options.add("brush");
}
if (subCommand.equalsIgnoreCase("configure") || subCommand.equalsIgnoreCase("describe") || subCommand.equalsIgnoreCase("upgrade")) {
for (String key : BaseMagicProperties.PROPERTY_KEYS) {
options.add(key);
}
for (String protection : api.getController().getDamageTypes()) {
options.add("protection." + protection);
}
}
if (subCommand.equalsIgnoreCase("attribute")) {
for (String attribute : api.getController().getAttributes()) {
options.add(attribute);
}
}
if (subCommand.equalsIgnoreCase("add")) {
Collection<SpellTemplate> spellList = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
for (SpellTemplate spell : spellList) {
addIfPermissible(sender, options, subCommandPNode, spell.getKey(), true);
}
addIfPermissible(sender, options, subCommandPNode, "brush", true);
}
if (args[0].equalsIgnoreCase("lock") || args[0].equalsIgnoreCase("unlock") || args[0].equalsIgnoreCase("activate")) {
options.addAll(api.getController().getMageClassKeys());
}
}
return options;
}
use of org.bukkit.configuration.ConfigurationSection in project MagicPlugin by elBukkit.
the class MageCommandExecutor method onMageSetData.
public boolean onMageSetData(CommandSender sender, Player player, String[] args) {
Mage mage = controller.getMage(player);
if (args.length == 1) {
ConfigurationSection data = mage.getData();
String key = args[0];
if (!data.contains(key)) {
sender.sendMessage(ChatColor.RED + "No data found with key " + ChatColor.AQUA + key + ChatColor.RED + " for " + ChatColor.DARK_AQUA + player.getDisplayName());
return true;
}
data.set(key, null);
sender.sendMessage(ChatColor.GOLD + "Removed data for key " + ChatColor.AQUA + key + ChatColor.GOLD + " for " + ChatColor.DARK_AQUA + player.getDisplayName());
return true;
}
if (args.length != 2) {
return false;
}
if (args[0].equals("*")) {
long value = 0;
try {
value = Long.parseLong(args[1]);
} catch (Exception ex) {
sender.sendMessage(ChatColor.RED + "Cast count must be a number");
return true;
}
Collection<Spell> spells = mage.getSpells();
for (Spell spell : spells) {
spell.setCastCount(value);
}
sender.sendMessage(ChatColor.GOLD + "Set all spell cast counts to " + ChatColor.AQUA + value + ChatColor.GOLD + " for " + ChatColor.DARK_AQUA + player.getDisplayName());
return true;
}
Spell spell = mage.getSpell(args[0]);
if (spell != null) {
long value = 0;
try {
value = Long.parseLong(args[1]);
} catch (Exception ex) {
sender.sendMessage(ChatColor.RED + "Cast count must be a number");
return true;
}
spell.setCastCount(value);
sender.sendMessage(ChatColor.GOLD + "Set " + ChatColor.AQUA + spell.getName() + ChatColor.GOLD + " cast count to " + ChatColor.AQUA + value + ChatColor.GOLD + " for " + ChatColor.DARK_AQUA + player.getDisplayName());
return true;
}
ConfigurationSection data = mage.getData();
String key = args[0];
String value = args[1];
data.set(key, value);
sender.sendMessage(ChatColor.GOLD + "Set " + ChatColor.AQUA + key + ChatColor.GOLD + " to " + ChatColor.AQUA + value + ChatColor.GOLD + " for " + ChatColor.DARK_AQUA + player.getDisplayName());
return true;
}
Aggregations