mirror of
https://github.com/PaperMC/Paper.git
synced 2025-09-02 05:13:51 -07:00
Added new Configuration classes
By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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>());
|
||||
|
||||
|
Reference in New Issue
Block a user