mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-16 19:44:15 +02:00
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
package com.earth2me.essentials.storage;
|
package com.earth2me.essentials.storage;
|
||||||
|
|
||||||
import com.earth2me.essentials.api.IReload;
|
import com.earth2me.essentials.api.IReload;
|
||||||
@@ -7,18 +6,17 @@ import java.io.File;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
interface IStorageObjectMap<I> extends IReload
|
interface IStorageObjectMap<I> extends IReload
|
||||||
{
|
{
|
||||||
boolean objectExists(final String name);
|
boolean objectExists(final String name);
|
||||||
|
|
||||||
I getObject(final String name);
|
I getObject(final String name);
|
||||||
|
|
||||||
void removeObject(final String name) throws InvalidNameException;
|
void removeObject(final String name) throws InvalidNameException;
|
||||||
|
|
||||||
Set<String> getAllKeys();
|
Set<String> getAllKeys();
|
||||||
|
|
||||||
int getKeySize();
|
int getKeySize();
|
||||||
|
|
||||||
File getStorageFile(final String name) throws InvalidNameException;
|
File getStorageFile(final String name) throws InvalidNameException;
|
||||||
}
|
}
|
||||||
|
@@ -3,5 +3,5 @@ package com.earth2me.essentials.storage;
|
|||||||
|
|
||||||
public interface IStorageReader
|
public interface IStorageReader
|
||||||
{
|
{
|
||||||
<T extends StorageObject> T load(final Class<? extends T> clazz) throws ObjectLoadException;
|
<T extends StorageObject> T load(final Class<? extends T> clazz) throws ObjectLoadException;
|
||||||
}
|
}
|
||||||
|
@@ -38,7 +38,7 @@ public class Location
|
|||||||
this.yaw = yaw;
|
this.yaw = yaw;
|
||||||
this.pitch = pitch;
|
this.pitch = pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location(String worldname, double x, double y, double z)
|
public Location(String worldname, double x, double y, double z)
|
||||||
{
|
{
|
||||||
this.worldname = worldname;
|
this.worldname = worldname;
|
||||||
@@ -56,13 +56,16 @@ public class Location
|
|||||||
if (loc == null)
|
if (loc == null)
|
||||||
{
|
{
|
||||||
World world = null;
|
World world = null;
|
||||||
if (worldUID != null) {
|
if (worldUID != null)
|
||||||
|
{
|
||||||
world = Bukkit.getWorld(worldUID);
|
world = Bukkit.getWorld(worldUID);
|
||||||
}
|
}
|
||||||
if (world == null) {
|
if (world == null)
|
||||||
|
{
|
||||||
world = Bukkit.getWorld(worldname);
|
world = Bukkit.getWorld(worldname);
|
||||||
}
|
}
|
||||||
if (world == null) {
|
if (world == null)
|
||||||
|
{
|
||||||
throw new WorldNotLoadedException(worldname);
|
throw new WorldNotLoadedException(worldname);
|
||||||
}
|
}
|
||||||
loc = new org.bukkit.Location(world, getX(), getY(), getZ(), getYaw(), getPitch());
|
loc = new org.bukkit.Location(world, getX(), getY(), getZ(), getYaw(), getPitch());
|
||||||
@@ -100,12 +103,13 @@ public class Location
|
|||||||
{
|
{
|
||||||
return pitch;
|
return pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class WorldNotLoadedException extends Exception
|
public static class WorldNotLoadedException extends Exception
|
||||||
{
|
{
|
||||||
public WorldNotLoadedException(String worldname)
|
public WorldNotLoadedException(String worldname)
|
||||||
{
|
{
|
||||||
super("World "+worldname+" is not loaded.");
|
super("World " + worldname + " is not loaded.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -45,7 +45,8 @@ public class YamlStorageReader implements IStorageReader
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
T object = (T)yaml.load(reader);
|
T object = (T)yaml.load(reader);
|
||||||
if (object == null) {
|
if (object == null)
|
||||||
|
{
|
||||||
object = clazz.newInstance();
|
object = clazz.newInstance();
|
||||||
}
|
}
|
||||||
return object;
|
return object;
|
||||||
|
@@ -23,12 +23,12 @@ public class YamlStorageWriter implements IStorageWriter
|
|||||||
private transient static final Pattern NON_WORD_PATTERN = Pattern.compile("\\W");
|
private transient static final Pattern NON_WORD_PATTERN = Pattern.compile("\\W");
|
||||||
private transient final PrintWriter writer;
|
private transient final PrintWriter writer;
|
||||||
private transient static final Yaml YAML = new Yaml();
|
private transient static final Yaml YAML = new Yaml();
|
||||||
|
|
||||||
public YamlStorageWriter(final PrintWriter writer)
|
public YamlStorageWriter(final PrintWriter writer)
|
||||||
{
|
{
|
||||||
this.writer = writer;
|
this.writer = writer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(final StorageObject object)
|
public void save(final StorageObject object)
|
||||||
{
|
{
|
||||||
@@ -45,7 +45,7 @@ public class YamlStorageWriter implements IStorageWriter
|
|||||||
Logger.getLogger(YamlStorageWriter.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(YamlStorageWriter.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeToFile(final Object object, final int depth, final Class clazz) throws IllegalAccessException
|
private void writeToFile(final Object object, final int depth, final Class clazz) throws IllegalAccessException
|
||||||
{
|
{
|
||||||
for (Field field : clazz.getDeclaredFields())
|
for (Field field : clazz.getDeclaredFields())
|
||||||
@@ -54,7 +54,7 @@ public class YamlStorageWriter implements IStorageWriter
|
|||||||
if (Modifier.isPrivate(modifier) && !Modifier.isTransient(modifier) && !Modifier.isStatic(modifier))
|
if (Modifier.isPrivate(modifier) && !Modifier.isTransient(modifier) && !Modifier.isStatic(modifier))
|
||||||
{
|
{
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
|
|
||||||
final Object data = field.get(object);
|
final Object data = field.get(object);
|
||||||
if (writeKey(field, depth, data))
|
if (writeKey(field, depth, data))
|
||||||
{
|
{
|
||||||
@@ -85,7 +85,7 @@ public class YamlStorageWriter implements IStorageWriter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean writeKey(final Field field, final int depth, final Object data)
|
private boolean writeKey(final Field field, final int depth, final Object data)
|
||||||
{
|
{
|
||||||
final boolean commentPresent = writeComment(field, depth);
|
final boolean commentPresent = writeComment(field, depth);
|
||||||
@@ -109,7 +109,7 @@ public class YamlStorageWriter implements IStorageWriter
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean writeComment(final Field field, final int depth)
|
private boolean writeComment(final Field field, final int depth)
|
||||||
{
|
{
|
||||||
final boolean commentPresent = field.isAnnotationPresent(Comment.class);
|
final boolean commentPresent = field.isAnnotationPresent(Comment.class);
|
||||||
@@ -131,7 +131,7 @@ public class YamlStorageWriter implements IStorageWriter
|
|||||||
}
|
}
|
||||||
return commentPresent;
|
return commentPresent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeCollection(final Collection<Object> data, final int depth) throws IllegalAccessException
|
private void writeCollection(final Collection<Object> data, final int depth) throws IllegalAccessException
|
||||||
{
|
{
|
||||||
writer.println();
|
writer.println();
|
||||||
@@ -162,7 +162,7 @@ public class YamlStorageWriter implements IStorageWriter
|
|||||||
}
|
}
|
||||||
writer.println();
|
writer.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeMap(final Map<Object, Object> data, final int depth) throws IllegalArgumentException, IllegalAccessException
|
private void writeMap(final Map<Object, Object> data, final int depth) throws IllegalArgumentException, IllegalAccessException
|
||||||
{
|
{
|
||||||
writer.println();
|
writer.println();
|
||||||
@@ -199,7 +199,7 @@ public class YamlStorageWriter implements IStorageWriter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeIndention(final int depth)
|
private void writeIndention(final int depth)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < depth; i++)
|
for (int i = 0; i < depth; i++)
|
||||||
@@ -207,7 +207,7 @@ public class YamlStorageWriter implements IStorageWriter
|
|||||||
writer.print(" ");
|
writer.print(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeScalar(final Object data)
|
private void writeScalar(final Object data)
|
||||||
{
|
{
|
||||||
if (data instanceof String || data instanceof Boolean || data instanceof Number)
|
if (data instanceof String || data instanceof Boolean || data instanceof Number)
|
||||||
@@ -247,7 +247,7 @@ public class YamlStorageWriter implements IStorageWriter
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeKey(final Object data)
|
private void writeKey(final Object data)
|
||||||
{
|
{
|
||||||
if (data instanceof String || data instanceof Boolean || data instanceof Number)
|
if (data instanceof String || data instanceof Boolean || data instanceof Number)
|
||||||
@@ -285,12 +285,12 @@ public class YamlStorageWriter implements IStorageWriter
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeMaterial(final Object data)
|
private void writeMaterial(final Object data)
|
||||||
{
|
{
|
||||||
writer.print(data.toString().toLowerCase(Locale.ENGLISH));
|
writer.print(data.toString().toLowerCase(Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeMaterialData(final Object data)
|
private void writeMaterialData(final Object data)
|
||||||
{
|
{
|
||||||
final MaterialData matData = (MaterialData)data;
|
final MaterialData matData = (MaterialData)data;
|
||||||
@@ -301,7 +301,7 @@ public class YamlStorageWriter implements IStorageWriter
|
|||||||
writer.print(matData.getData());
|
writer.print(matData.getData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeItemStack(final Object data)
|
private void writeItemStack(final Object data)
|
||||||
{
|
{
|
||||||
final ItemStack itemStack = (ItemStack)data;
|
final ItemStack itemStack = (ItemStack)data;
|
||||||
@@ -314,7 +314,7 @@ public class YamlStorageWriter implements IStorageWriter
|
|||||||
writeEnchantmentLevel(entry);
|
writeEnchantmentLevel(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeEnchantmentLevel(Object data)
|
private void writeEnchantmentLevel(Object data)
|
||||||
{
|
{
|
||||||
final Entry<Enchantment, Integer> enchLevel = (Entry<Enchantment, Integer>)data;
|
final Entry<Enchantment, Integer> enchLevel = (Entry<Enchantment, Integer>)data;
|
||||||
@@ -322,7 +322,7 @@ public class YamlStorageWriter implements IStorageWriter
|
|||||||
writer.print(':');
|
writer.print(':');
|
||||||
writer.print(enchLevel.getValue());
|
writer.print(enchLevel.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeLocation(final Location entry, final int depth)
|
private void writeLocation(final Location entry, final int depth)
|
||||||
{
|
{
|
||||||
writer.println();
|
writer.println();
|
||||||
|
Reference in New Issue
Block a user