Added new Configuration classes

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot
2011-09-19 20:36:44 +01:00
parent e99e39ee62
commit 6c7412d365
31 changed files with 3454 additions and 9 deletions

View File

@@ -1,13 +1,15 @@
package org.bukkit.util;
import java.util.Map;
import org.bukkit.configuration.serialization.SerializableAs;
/**
* A vector with a hash function that floors the X, Y, Z components, a la
* BlockVector in WorldEdit. BlockVectors can be used in hash sets and
* hash maps. Be aware that BlockVectors are mutable, but it is important
* that BlockVectors are never changed once put into a hash set or hash map.
*
* @author sk89q
*/
@SerializableAs("BlockVector")
public class BlockVector extends Vector {
/**
@@ -109,4 +111,22 @@ public class BlockVector extends Vector {
v.z = z;
return v;
}
public static BlockVector deserialize(Map<String, Object> args) {
double x = 0;
double y = 0;
double z = 0;
if (args.containsKey("x")) {
x = (Double)args.get("x");
}
if (args.containsKey("y")) {
y = (Double)args.get("y");
}
if (args.containsKey("z")) {
z = (Double)args.get("z");
}
return new BlockVector(x, y, z);
}
}

View File

@@ -1,18 +1,21 @@
package org.bukkit.util;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Random;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.SerializableAs;
/**
* Represents a mutable vector. Because the components of Vectors are mutable,
* storing Vectors long term may be dangerous if passing code modifies the
* Vector later. If you want to keep around a Vector, it may be wise to call
* <code>clone()</code> in order to get a copy.
*
* @author sk89q
*/
public class Vector implements Cloneable {
@SerializableAs("Vector")
public class Vector implements Cloneable, ConfigurationSerializable {
private static final long serialVersionUID = -2657651106777219169L;
private static Random random = new Random();
@@ -635,4 +638,32 @@ public class Vector implements Cloneable {
public static Vector getRandom() {
return new Vector(random.nextDouble(), random.nextDouble(), random.nextDouble());
}
public Map<String, Object> serialize() {
Map<String, Object> result = new LinkedHashMap<String, Object>();
result.put("x", getX());
result.put("y", getY());
result.put("z", getZ());
return result;
}
public static Vector deserialize(Map<String, Object> args) {
double x = 0;
double y = 0;
double z = 0;
if (args.containsKey("x")) {
x = (Double)args.get("x");
}
if (args.containsKey("y")) {
y = (Double)args.get("y");
}
if (args.containsKey("z")) {
z = (Double)args.get("z");
}
return new Vector(x, y, z);
}
}

View File

@@ -7,6 +7,7 @@ import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.configuration.file.YamlConfiguration;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
@@ -52,12 +53,18 @@ import org.yaml.snakeyaml.representer.Representer;
* <p>This class is currently incomplete. It is not yet possible to get a node.
* </p>
*
* @deprecated See {@link YamlConfiguration}
*/
@Deprecated
public class Configuration extends ConfigurationNode {
private Yaml yaml;
private File file;
private String header = null;
/**
* @deprecated See {@link YamlConfiguration}
*/
@Deprecated
public Configuration(File file) {
super(new HashMap<String, Object>());