use of org.bukkit.configuration.ConfigurationSection in project MagicPlugin by elBukkit.
the class WandUpgradePath method upgradeTo.
protected void upgradeTo(com.elmakers.mine.bukkit.api.wand.Wand wand) {
wand.setPath(getKey());
boolean addedProperties = false;
ConfigurationSection wandProperties = new MemoryConfiguration();
int manaRegeneration = wand.getManaRegeneration();
if (this.manaRegeneration > 0 && maxManaRegeneration == 0 && this.manaRegeneration > manaRegeneration) {
addedProperties = true;
wandProperties.set("mana_regeneration", this.manaRegeneration);
}
int manaMax = wand.getManaMax();
if (this.maxMana > 0 && maxMaxMana == 0 && this.maxMana > manaMax) {
addedProperties = true;
wandProperties.set("mana_max", this.maxMana);
}
if (addedProperties) {
wand.upgrade(wandProperties);
}
}
use of org.bukkit.configuration.ConfigurationSection in project MagicPlugin by elBukkit.
the class PhaseSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Location targetLocation = null;
Target target = getTarget();
Entity e = target.getEntity();
LivingEntity entity = e != null && e instanceof LivingEntity ? (LivingEntity) e : null;
if (entity == null) {
return SpellResult.NO_TARGET;
}
if (entity != mage.getEntity() && controller.isMage(entity)) {
Mage mage = controller.getMage(entity);
if (mage.isSuperProtected()) {
return SpellResult.NO_TARGET;
}
}
Location playerLocation = entity.getLocation();
String worldName = playerLocation.getWorld().getName();
if (parameters.contains("target_world")) {
World targetWorld = getWorld(parameters.getString("target_world"), parameters.getBoolean("load", true));
if (targetWorld == null) {
return SpellResult.INVALID_WORLD;
}
float scale = (float) parameters.getDouble("scale", 1.0f);
if (targetWorld.getEnvironment() == World.Environment.THE_END) {
targetLocation = targetWorld.getSpawnLocation();
} else {
targetLocation = new Location(targetWorld, playerLocation.getX() * scale, playerLocation.getY(), playerLocation.getZ() * scale);
}
} else if (parameters.contains("worlds")) {
ConfigurationSection worldMap = parameters.getConfigurationSection("worlds");
if (!worldMap.contains(worldName)) {
return SpellResult.NO_TARGET;
}
ConfigurationSection worldNode = worldMap.getConfigurationSection(worldName);
World targetWorld = getWorld(worldNode.getString("target"), worldNode.getBoolean("load", true));
float scale = (float) worldNode.getDouble("scale", 1.0f);
if (targetWorld != null) {
targetLocation = new Location(targetWorld, playerLocation.getX() * scale, playerLocation.getY(), playerLocation.getZ() * scale);
}
} else {
if (worldName.contains("_the_end")) {
worldName = worldName.replace("_the_end", "");
World targetWorld = Bukkit.getWorld(worldName);
if (targetWorld != null) {
// No scaling here?
// Just send them to spawn... this is kind of to fix players finding the real spawn
// on my own server, but I'm not just sure how best to handle this anyway.
targetLocation = targetWorld.getSpawnLocation();
}
} else if (worldName.contains("_nether")) {
worldName = worldName.replace("_nether", "");
World targetWorld = Bukkit.getWorld(worldName);
if (targetWorld != null) {
targetLocation = new Location(targetWorld, playerLocation.getX() * 8, playerLocation.getY(), playerLocation.getZ() * 8);
}
} else {
worldName = worldName + "_nether";
World targetWorld = Bukkit.getWorld(worldName);
if (targetWorld != null) {
targetLocation = new Location(targetWorld, playerLocation.getX() / 8, Math.min(125, playerLocation.getY()), playerLocation.getZ() / 8);
}
}
}
if (targetLocation == null) {
return SpellResult.NO_TARGET;
}
retryCount = 0;
tryPhase(entity, targetLocation);
return SpellResult.CAST;
}
use of org.bukkit.configuration.ConfigurationSection in project MagicPlugin by elBukkit.
the class SimulateSpell method loadTemplate.
@Override
protected void loadTemplate(ConfigurationSection template) {
super.loadTemplate(template);
if (template.contains("levels")) {
ConfigurationSection levelTemplate = template.getConfigurationSection("levels");
Collection<String> levelKeys = levelTemplate.getKeys(false);
List<Integer> levels = new ArrayList<>(levelKeys.size());
for (String levelString : levelKeys) {
levels.add(Integer.parseInt(levelString));
}
if (levels.size() == 0)
return;
levelMap = new TreeMap<>();
Collections.sort(levels);
Integer[] levelsArray = levels.toArray(emptyList);
for (int level = 1; level <= levelsArray[levelsArray.length - 1]; level++) {
levelMap.put(level, new AutomatonLevel(level, levelsArray, template));
}
} else {
levelMap = new TreeMap<>();
levelMap.put(1, new AutomatonLevel(1, null, template));
}
}
use of org.bukkit.configuration.ConfigurationSection in project MagicPlugin by elBukkit.
the class Messages method load.
public void load(ConfigurationSection messages) {
configuration = messages;
Collection<String> keys = messages.getKeys(true);
for (String key : keys) {
if (key.equals("randomized")) {
ConfigurationSection randomSection = messages.getConfigurationSection(key);
Set<String> randomKeys = randomSection.getKeys(false);
for (String randomKey : randomKeys) {
randomized.put(randomKey, randomSection.getStringList(randomKey));
}
} else if (messages.isString(key)) {
String value = messages.getString(key);
value = ChatColor.translateAlternateColorCodes('&', StringEscapeUtils.unescapeHtml(value));
messageMap.put(key, value);
}
}
}
use of org.bukkit.configuration.ConfigurationSection in project MagicPlugin by elBukkit.
the class ActionHandler method load.
public void load(Spell spell, ConfigurationSection root, String key) {
undoable = false;
usesBrush = false;
requiresBuildPermission = false;
requiresBreakPermission = false;
ConfigurationSection handlerConfiguration = (spell != null) ? spell.getHandlerParameters(key) : null;
Collection<ConfigurationSection> actionNodes = ConfigurationUtils.getNodeList(root, key);
if (actionNodes == null) {
return;
}
for (ConfigurationSection actionConfiguration : actionNodes) {
if (!actionConfiguration.contains("class")) {
continue;
}
String actionClassName = actionConfiguration.getString("class");
try {
BaseSpellAction action = ActionFactory.construct(actionClassName);
actionConfiguration.set("class", null);
if (handlerConfiguration != null) {
ConfigurationUtils.addConfigurations(actionConfiguration, handlerConfiguration, false);
}
if (actionConfiguration.getKeys(false).size() == 0) {
actionConfiguration = null;
}
loadAction(action, actionConfiguration);
} catch (Exception ex) {
Bukkit.getLogger().warning("Error loading class " + actionClassName + " for spell " + spell.getName() + ": " + ex.getMessage());
}
}
}
Aggregations