implemented saving framework, messaging utils

This commit is contained in:
aPunch 2012-01-15 21:15:32 -06:00
parent dbecb5763d
commit 1533cd6eff
5 changed files with 403 additions and 0 deletions

View File

@ -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.");
}
}

View File

@ -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<String> getKeys(String string);
public List<Integer> getIntegerKeys(String string);
}

View File

@ -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<String> getKeys(String string) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<Integer> getIntegerKeys(String string) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -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<String> getKeys(String string) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<Integer> 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());
}
}
}

View File

@ -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);
}
}