From 7b727c3d6b81f9e7d3d39759216ff80e335e946e Mon Sep 17 00:00:00 2001 From: aPunch Date: Sun, 15 Jan 2012 21:15:32 -0600 Subject: [PATCH] implemented saving framework, messaging utils --- src/net/citizensnpcs/Citizens.java | 6 + src/net/citizensnpcs/storage/Storage.java | 53 ++++++ .../storage/database/DatabaseStorage.java | 147 +++++++++++++++ .../storage/flatfile/YamlStorage.java | 176 ++++++++++++++++++ src/net/citizensnpcs/util/Messaging.java | 21 +++ 5 files changed, 403 insertions(+) create mode 100644 src/net/citizensnpcs/storage/Storage.java create mode 100644 src/net/citizensnpcs/storage/database/DatabaseStorage.java create mode 100644 src/net/citizensnpcs/storage/flatfile/YamlStorage.java create mode 100644 src/net/citizensnpcs/util/Messaging.java diff --git a/src/net/citizensnpcs/Citizens.java b/src/net/citizensnpcs/Citizens.java index ba08480ad..eec99a1a2 100644 --- a/src/net/citizensnpcs/Citizens.java +++ b/src/net/citizensnpcs/Citizens.java @@ -2,6 +2,7 @@ package net.citizensnpcs; import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.npc.CitizensNPCManager; +import net.citizensnpcs.util.Messaging; import org.bukkit.plugin.java.JavaPlugin; @@ -9,10 +10,15 @@ public class Citizens extends JavaPlugin { @Override public void onDisable() { + Messaging.log("v" + getDescription().getVersion() + " disabled."); } @Override public void onEnable() { CitizensAPI.setNPCManager(new CitizensNPCManager()); + + // TODO wait to load until after all plugins using CitizensAPI are + // loaded + Messaging.log("v" + getDescription().getVersion() + " enabled."); } } \ No newline at end of file diff --git a/src/net/citizensnpcs/storage/Storage.java b/src/net/citizensnpcs/storage/Storage.java new file mode 100644 index 000000000..1aede3fd4 --- /dev/null +++ b/src/net/citizensnpcs/storage/Storage.java @@ -0,0 +1,53 @@ +package net.citizensnpcs.storage; + +import java.util.Collection; +import java.util.List; + +public interface Storage { + + public void load(); + + public void save(); + + public void removeKey(String key); + + public String getString(String key); + + public String getString(String key, String value); + + public void setString(String key, String value); + + public int getInt(String key); + + public int getInt(String key, int value); + + public void setInt(String key, int value); + + public double getDouble(String key); + + public double getDouble(String key, double value); + + public void setDouble(String key, double value); + + public long getLong(String key); + + public long getLong(String key, long value); + + public void setLong(String key, long value); + + public boolean getBoolean(String key); + + public boolean getBoolean(String key, boolean value); + + public void setBoolean(String key, boolean value); + + public Object getRaw(String string); + + public void setRaw(String path, Object value); + + public boolean keyExists(String path); + + public Collection getKeys(String string); + + public List getIntegerKeys(String string); +} \ No newline at end of file diff --git a/src/net/citizensnpcs/storage/database/DatabaseStorage.java b/src/net/citizensnpcs/storage/database/DatabaseStorage.java new file mode 100644 index 000000000..0d5a4bfe2 --- /dev/null +++ b/src/net/citizensnpcs/storage/database/DatabaseStorage.java @@ -0,0 +1,147 @@ +package net.citizensnpcs.storage.database; + +import java.util.Collection; +import java.util.List; + +import net.citizensnpcs.storage.Storage; + +public class DatabaseStorage implements Storage { + + @Override + public void load() { + // TODO Auto-generated method stub + + } + + @Override + public void save() { + // TODO Auto-generated method stub + + } + + @Override + public void removeKey(String key) { + // TODO Auto-generated method stub + + } + + @Override + public String getString(String key) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getString(String key, String value) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setString(String key, String value) { + // TODO Auto-generated method stub + + } + + @Override + public int getInt(String key) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int getInt(String key, int value) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void setInt(String key, int value) { + // TODO Auto-generated method stub + + } + + @Override + public double getDouble(String key) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public double getDouble(String key, double value) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void setDouble(String key, double value) { + // TODO Auto-generated method stub + + } + + @Override + public long getLong(String key) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public long getLong(String key, long value) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void setLong(String key, long value) { + // TODO Auto-generated method stub + + } + + @Override + public boolean getBoolean(String key) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean getBoolean(String key, boolean value) { + // TODO Auto-generated method stub + return false; + } + + @Override + public void setBoolean(String key, boolean value) { + // TODO Auto-generated method stub + + } + + @Override + public Object getRaw(String string) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setRaw(String path, Object value) { + // TODO Auto-generated method stub + + } + + @Override + public boolean keyExists(String path) { + // TODO Auto-generated method stub + return false; + } + + @Override + public Collection getKeys(String string) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List getIntegerKeys(String string) { + // TODO Auto-generated method stub + return null; + } +} \ No newline at end of file diff --git a/src/net/citizensnpcs/storage/flatfile/YamlStorage.java b/src/net/citizensnpcs/storage/flatfile/YamlStorage.java new file mode 100644 index 000000000..f1c205806 --- /dev/null +++ b/src/net/citizensnpcs/storage/flatfile/YamlStorage.java @@ -0,0 +1,176 @@ +package net.citizensnpcs.storage.flatfile; + +import java.io.File; +import java.io.IOException; +import java.util.Collection; +import java.util.List; +import java.util.logging.Level; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; + +import net.citizensnpcs.storage.Storage; +import net.citizensnpcs.util.Messaging; + +public class YamlStorage implements Storage { + private final FileConfiguration config; + private final File file; + + public YamlStorage(String fileName) { + config = new YamlConfiguration(); + file = new File(fileName); + if (!file.exists()) { + create(); + save(); + } else + load(); + } + + @Override + public void load() { + // TODO Auto-generated method stub + + } + + @Override + public void save() { + // TODO Auto-generated method stub + + } + + @Override + public void removeKey(String key) { + // TODO Auto-generated method stub + + } + + @Override + public String getString(String key) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getString(String key, String value) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setString(String key, String value) { + // TODO Auto-generated method stub + + } + + @Override + public int getInt(String key) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int getInt(String key, int value) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void setInt(String key, int value) { + // TODO Auto-generated method stub + + } + + @Override + public double getDouble(String key) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public double getDouble(String key, double value) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void setDouble(String key, double value) { + // TODO Auto-generated method stub + + } + + @Override + public long getLong(String key) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public long getLong(String key, long value) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void setLong(String key, long value) { + // TODO Auto-generated method stub + + } + + @Override + public boolean getBoolean(String key) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean getBoolean(String key, boolean value) { + // TODO Auto-generated method stub + return false; + } + + @Override + public void setBoolean(String key, boolean value) { + // TODO Auto-generated method stub + + } + + @Override + public Object getRaw(String string) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setRaw(String path, Object value) { + // TODO Auto-generated method stub + + } + + @Override + public boolean keyExists(String path) { + // TODO Auto-generated method stub + return false; + } + + @Override + public Collection getKeys(String string) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List getIntegerKeys(String string) { + // TODO Auto-generated method stub + return null; + } + + private void create() { + try { + Messaging.log("Creating file: " + file.getName()); + file.getParentFile().mkdirs(); + file.createNewFile(); + } catch (IOException ex) { + Messaging.log(Level.SEVERE, "Could not create file: " + file.getName()); + } + } +} \ No newline at end of file diff --git a/src/net/citizensnpcs/util/Messaging.java b/src/net/citizensnpcs/util/Messaging.java new file mode 100644 index 000000000..20030e8ec --- /dev/null +++ b/src/net/citizensnpcs/util/Messaging.java @@ -0,0 +1,21 @@ +package net.citizensnpcs.util; + +import java.util.logging.Level; + +import org.bukkit.Bukkit; + +public class Messaging { + + public static void log(Level level, Object msg) { + Bukkit.getLogger().log(level, "[Citizens] " + msg); + } + + public static void log(Object msg) { + log(Level.INFO, msg); + } + + public static void debug(Object msg) { + // TODO add debug setting + log(msg); + } +} \ No newline at end of file