use of org.bukkit.configuration.ConfigurationSection in project MagicPlugin by elBukkit.
the class ChangeWorldAction method prepare.
@Override
public void prepare(CastContext context, ConfigurationSection parameters) {
super.prepare(context, parameters);
World world = context.getWorld();
Location playerLocation = context.getLocation();
targetLocation = null;
if (world == null) {
return;
}
String worldName = world.getName();
if (parameters.contains("target_world")) {
World targetWorld = getWorld(context, parameters.getString("target_world"), parameters.getBoolean("load", true), null);
if (targetWorld == null) {
return;
}
if (targetWorld.getEnvironment() == World.Environment.THE_END) {
targetLocation = targetWorld.getSpawnLocation();
} else {
double scale = parameters.getDouble("scale", 1);
targetLocation = new Location(targetWorld, playerLocation.getX() * scale, playerLocation.getY(), playerLocation.getZ() * scale);
}
} else if (parameters.contains("worlds")) {
ConfigurationSection worldMap = ConfigurationUtils.getConfigurationSection(parameters, "worlds");
if (worldMap == null || !worldMap.contains(worldName)) {
return;
}
ConfigurationSection worldNode = ConfigurationUtils.getConfigurationSection(worldMap, worldName);
boolean useSpawnLocations = worldNode.getBoolean("use_spawns", false);
Vector minLocation = ConfigurationUtils.getVector(worldNode, "bounds_min");
Vector maxLocation = ConfigurationUtils.getVector(worldNode, "bounds_max");
World targetWorld = getWorld(context, worldNode.getString("target"), worldNode.getBoolean("load", true), worldNode.getBoolean("copy", false) ? world : null);
if (targetWorld != null) {
String envName = worldNode.getString("environment");
if (envName != null && !envName.isEmpty()) {
try {
World.Environment env = World.Environment.valueOf(envName.toUpperCase());
NMSUtils.setEnvironment(targetWorld, env);
} catch (Exception ex) {
context.getLogger().warning("Unknown environment type: " + envName);
}
}
double scale = worldNode.getDouble("scale", 1);
if (useSpawnLocations) {
Location currentSpawn = playerLocation.getWorld().getSpawnLocation();
playerLocation.setX(playerLocation.getX() - currentSpawn.getX());
playerLocation.setZ(playerLocation.getZ() - currentSpawn.getZ());
}
targetLocation = new Location(targetWorld, playerLocation.getX() * scale, playerLocation.getY(), playerLocation.getZ() * scale);
if (useSpawnLocations) {
Location targetSpawn = targetWorld.getSpawnLocation();
targetLocation.setX(targetLocation.getX() + targetSpawn.getX());
targetLocation.setZ(targetLocation.getZ() + targetSpawn.getZ());
}
if (minLocation != null) {
if (targetLocation.getX() < minLocation.getX())
targetLocation.setX(minLocation.getX());
if (targetLocation.getZ() < minLocation.getZ())
targetLocation.setZ(minLocation.getZ());
}
if (maxLocation != null) {
if (targetLocation.getX() > maxLocation.getX())
targetLocation.setX(maxLocation.getX());
if (targetLocation.getZ() > maxLocation.getZ())
targetLocation.setZ(maxLocation.getZ());
}
}
} 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);
}
}
}
}
use of org.bukkit.configuration.ConfigurationSection in project MagicPlugin by elBukkit.
the class SpellShopAction method initialize.
@Override
public void initialize(Spell spell, ConfigurationSection parameters) {
super.initialize(spell, parameters);
spells.clear();
if (parameters.contains("spells")) {
if (parameters.isConfigurationSection("spells")) {
ConfigurationSection spellSection = ConfigurationUtils.getConfigurationSection(parameters, "spells");
Collection<String> spellKeys = spellSection.getKeys(false);
for (String spellKey : spellKeys) {
spells.put(spellKey, spellSection.getDouble(spellKey));
}
} else {
Collection<String> spellList = ConfigurationUtils.getStringList(parameters, "spells");
if (spellList != null) {
for (String spellKey : spellList) {
spells.put(spellKey, null);
}
}
}
}
}
use of org.bukkit.configuration.ConfigurationSection in project MagicPlugin by elBukkit.
the class MagicCitizensTrait method describeParameters.
protected void describeParameters(CommandSender sender) {
Collection<String> keys = parameters.getKeys(false);
if (keys.size() == 0) {
sender.sendMessage(ChatColor.GRAY + " (None)");
}
for (String key : keys) {
String value = null;
if (parameters.isConfigurationSection(key)) {
ConfigurationSection child = parameters.getConfigurationSection(key);
value = "(" + child.getKeys(false).size() + " values)";
} else {
value = parameters.getString(key);
}
sender.sendMessage(ChatColor.LIGHT_PURPLE + " " + key + ": " + value);
}
}
use of org.bukkit.configuration.ConfigurationSection in project MagicPlugin by elBukkit.
the class ConfigurationMageDataStore method save.
public static void save(MageController controller, MageData mage, ConfigurationSection saveFile) {
saveFile.set("id", mage.getId());
saveFile.set("name", mage.getName());
saveFile.set("last_cast", mage.getLastCast());
saveFile.set("cooldown_expiration", mage.getCooldownExpiration());
saveFile.set("last_death_location", ConfigurationUtils.fromLocation(mage.getLastDeathLocation()));
Location location = mage.getLocation();
if (location != null) {
saveFile.set("location", ConfigurationUtils.fromLocation(location));
}
saveFile.set("destination_warp", mage.getDestinationWarp());
saveFile.set("fall_protection_count", mage.getFallProtectionCount());
saveFile.set("fall_protection", mage.getFallProtectionDuration());
BrushData brush = mage.getBrushData();
if (brush != null) {
ConfigurationSection brushNode = saveFile.createSection("brush");
try {
Location cloneSource = brush.getCloneLocation();
if (cloneSource != null) {
brushNode.set("clone_location", ConfigurationUtils.fromLocation(cloneSource));
}
Location cloneTarget = brush.getCloneTarget();
if (cloneTarget != null) {
brushNode.set("clone_target", ConfigurationUtils.fromLocation(cloneTarget));
}
Location materialTarget = brush.getMaterialTarget();
if (materialTarget != null) {
brushNode.set("material_target", ConfigurationUtils.fromLocation(materialTarget));
}
brushNode.set("map_id", brush.getMapId());
brushNode.set("material", ConfigurationUtils.fromMaterial(brush.getMaterial()));
brushNode.set("data", brush.getMaterialData());
brushNode.set("schematic", brush.getSchematicName());
brushNode.set("scale", brush.getScale());
brushNode.set("erase", brush.isFillWithAir());
} catch (Exception ex) {
controller.getLogger().warning("Failed to save brush data: " + ex.getMessage());
ex.printStackTrace();
}
}
UndoData undoData = mage.getUndoData();
if (undoData != null) {
List<Map<String, Object>> nodeList = new ArrayList<>();
List<UndoList> undoList = undoData.getBlockList();
for (UndoList list : undoList) {
MemoryConfiguration listNode = new MemoryConfiguration();
list.save(listNode);
nodeList.add(listNode.getValues(true));
}
saveFile.set("undo", nodeList);
}
ConfigurationSection spellNode = saveFile.createSection("spells");
Collection<SpellData> spellData = mage.getSpellData();
if (spellData != null) {
for (SpellData spell : spellData) {
ConfigurationSection node = spellNode.createSection(spell.getKey().getKey());
node.set("cast_count", spell.getCastCount());
node.set("last_cast", spell.getLastCast());
node.set("last_earn", spell.getLastEarn());
node.set("cooldown_expiration", spell.getCooldownExpiration());
node.set("active", spell.isActive() ? true : null);
ConfigurationSection extra = spell.getExtraData();
if (extra != null) {
ConfigurationUtils.addConfigurations(node, extra);
}
}
}
Map<String, ItemStack> boundWands = mage.getBoundWands();
if (boundWands != null && boundWands.size() > 0) {
ConfigurationSection wandSection = saveFile.createSection("wands");
for (Map.Entry<String, ItemStack> wandEntry : boundWands.entrySet()) {
String key = wandEntry.getKey();
if (key == null || key.isEmpty())
continue;
controller.serialize(wandSection, key, wandEntry.getValue());
}
}
Map<Integer, ItemStack> respawnArmor = mage.getRespawnArmor();
if (respawnArmor != null) {
ConfigurationSection armorSection = saveFile.createSection("respawn_armor");
for (Map.Entry<Integer, ItemStack> entry : respawnArmor.entrySet()) {
controller.serialize(armorSection, Integer.toString(entry.getKey()), entry.getValue());
}
}
Map<Integer, ItemStack> respawnInventory = mage.getRespawnInventory();
if (respawnInventory != null) {
ConfigurationSection inventorySection = saveFile.createSection("respawn_inventory");
for (Map.Entry<Integer, ItemStack> entry : respawnInventory.entrySet()) {
controller.serialize(inventorySection, Integer.toString(entry.getKey()), entry.getValue());
}
}
List<ItemStack> storedInventory = mage.getStoredInventory();
if (storedInventory != null) {
saveFile.set("inventory", storedInventory);
}
saveFile.set("experience", mage.getStoredExperience());
saveFile.set("level", mage.getStoredLevel());
saveFile.set("open_wand", mage.isOpenWand());
saveFile.set("gave_welcome_wand", mage.getGaveWelcomeWand());
ConfigurationSection extraData = mage.getExtraData();
if (extraData != null) {
ConfigurationSection dataSection = saveFile.createSection("data");
ConfigurationUtils.addConfigurations(dataSection, extraData);
}
ConfigurationSection properties = mage.getProperties();
if (properties != null) {
ConfigurationSection propertiesSection = saveFile.createSection("properties");
ConfigurationUtils.addConfigurations(propertiesSection, properties);
}
Map<String, ConfigurationSection> classProperties = mage.getClassProperties();
if (classProperties != null) {
ConfigurationSection classesSection = saveFile.createSection("classes");
for (Map.Entry<String, ConfigurationSection> entry : classProperties.entrySet()) {
ConfigurationSection classSection = classesSection.createSection(entry.getKey());
ConfigurationUtils.addConfigurations(classSection, entry.getValue());
}
}
saveFile.set("active_class", mage.getActiveClass());
}
use of org.bukkit.configuration.ConfigurationSection in project MagicPlugin by elBukkit.
the class TreeAction method initialize.
@Override
public void initialize(Spell spell, ConfigurationSection parameters) {
super.initialize(spell, parameters);
if (parameters.contains("biomes")) {
ConfigurationSection biomeConfig = ConfigurationUtils.getConfigurationSection(parameters, "biomes");
biomeMap = new HashMap<>();
Collection<String> biomeKeys = biomeConfig.getKeys(false);
for (String biomeKey : biomeKeys) {
try {
Biome biome = Biome.valueOf(biomeKey.toUpperCase());
List<String> treeTypes = ConfigurationUtils.getStringList(biomeConfig, biomeKey);
for (String typeKey : treeTypes) {
try {
TreeType treeType = TreeType.valueOf(typeKey.toUpperCase());
List<TreeType> biomeTypes = biomeMap.get(biome);
if (biomeTypes == null) {
biomeTypes = new ArrayList<>();
biomeMap.put(biome, biomeTypes);
}
biomeTypes.add(treeType);
} catch (Exception treeEx) {
Bukkit.getLogger().warning("Invalid tree type: " + typeKey);
}
}
} catch (Exception biomeEx) {
Bukkit.getLogger().warning("Invalid biome: " + biomeKey);
}
}
}
}
Aggregations