Delete files

This commit is contained in:
fullwall 2012-02-12 15:20:08 +08:00
parent c609030ff7
commit 38ae2936af
4 changed files with 0 additions and 464 deletions

View File

@ -1,48 +0,0 @@
package net.citizensnpcs.command;
import com.google.common.base.Objects;
public class CommandIdentifier {
private final String modifier;
private final String command;
public CommandIdentifier(String command, String modifier) {
this.command = command;
this.modifier = modifier;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
CommandIdentifier other = (CommandIdentifier) obj;
if (command == null) {
if (other.command != null)
return false;
} else if (!command.equals(other.command))
return false;
if (modifier == null) {
if (other.modifier != null)
return false;
} else if (!modifier.equals(other.modifier))
return false;
return true;
}
public String getCommand() {
return command;
}
public String getModifier() {
return modifier;
}
@Override
public int hashCode() {
return Objects.hashCode(command, modifier);
}
}

View File

@ -1,143 +0,0 @@
package net.citizensnpcs.storage;
import java.util.List;
import net.citizensnpcs.api.DataKey;
public class DatabaseStorage implements Storage {
@Override
public DataKey getKey(String root) {
// TODO Auto-generated method stub
return null;
}
@Override
public void load() {
// TODO Auto-generated method stub
}
@Override
public void save() {
// TODO Auto-generated method stub
}
public class DatabaseKey extends DataKey {
@Override
public void copy(String to) {
// TODO Auto-generated method stub
}
@Override
public boolean getBoolean(String key) {
// TODO Auto-generated method stub
return false;
}
@Override
public double getDouble(String key) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getInt(String key) {
// TODO Auto-generated method stub
return 0;
}
@Override
public List<DataKey> getIntegerSubKeys() {
// TODO Auto-generated method stub
return null;
}
@Override
public long getLong(String key) {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object getRaw(String key) {
// TODO Auto-generated method stub
return null;
}
@Override
public DataKey getRelative(String relative) {
// TODO Auto-generated method stub
return null;
}
@Override
public String getString(String key) {
// TODO Auto-generated method stub
return null;
}
@Override
public Iterable<DataKey> getSubKeys() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean keyExists(String key) {
// TODO Auto-generated method stub
return false;
}
@Override
public String name() {
// TODO Auto-generated method stub
return null;
}
@Override
public void removeKey(String key) {
// TODO Auto-generated method stub
}
@Override
public void setBoolean(String key, boolean value) {
// TODO Auto-generated method stub
}
@Override
public void setDouble(String key, double value) {
// TODO Auto-generated method stub
}
@Override
public void setInt(String key, int value) {
// TODO Auto-generated method stub
}
@Override
public void setLong(String key, long value) {
// TODO Auto-generated method stub
}
@Override
public void setRaw(String path, Object value) {
// TODO Auto-generated method stub
}
@Override
public void setString(String key, String value) {
// TODO Auto-generated method stub
}
}
}

View File

@ -1,12 +0,0 @@
package net.citizensnpcs.storage;
import net.citizensnpcs.api.DataKey;
public interface Storage {
public DataKey getKey(String root);
public void load();
public void save();
}

View File

@ -1,261 +0,0 @@
package net.citizensnpcs.storage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import net.citizensnpcs.api.DataKey;
import net.citizensnpcs.util.Messaging;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
public class YamlStorage implements Storage {
private final FileConfiguration config;
private final File file;
public YamlStorage(String fileName, String header) {
config = new YamlConfiguration();
file = new File(fileName);
if (!file.exists()) {
create();
config.options().header(header);
save();
} else
load();
}
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());
}
}
@Override
public DataKey getKey(String root) {
return new YamlKey(root);
}
@Override
public void load() {
try {
config.load(file);
} catch (Exception ex) {
ex.printStackTrace();
}
}
private boolean pathExists(String key) {
return config.get(key) != null;
}
@Override
public void save() {
try {
config.save(file);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public class YamlKey extends DataKey {
private final String current;
public YamlKey(String root) {
current = root;
}
@Override
public void copy(String to) {
ConfigurationSection root = config.getConfigurationSection(current);
if (root == null)
return;
config.createSection(to, root.getValues(true));
}
@Override
public boolean getBoolean(String key) {
String path = getKeyExt(key);
if (pathExists(path)) {
if (config.getString(path) == null)
return config.getBoolean(path);
return Boolean.parseBoolean(config.getString(path));
}
return false;
}
@Override
public boolean getBoolean(String key, boolean def) {
return config.getBoolean(getKeyExt(key), def);
}
@Override
public double getDouble(String key) {
String path = getKeyExt(key);
if (pathExists(path)) {
if (config.getString(path) == null) {
if (config.get(path) instanceof Integer)
return config.getInt(path);
return config.getDouble(path);
}
return Double.parseDouble(config.getString(path));
}
return 0;
}
@Override
public double getDouble(String key, double def) {
return config.getDouble(getKeyExt(key), def);
}
@Override
public int getInt(String key) {
String path = getKeyExt(key);
if (pathExists(path)) {
if (config.getString(path) == null)
return config.getInt(path);
return Integer.parseInt(config.getString(path));
}
return 0;
}
@Override
public int getInt(String key, int def) {
return config.getInt(getKeyExt(key), def);
}
@Override
public List<DataKey> getIntegerSubKeys() {
List<DataKey> res = new ArrayList<DataKey>();
ConfigurationSection section = config.getConfigurationSection(current);
if (section == null)
return res;
List<Integer> keys = new ArrayList<Integer>();
for (String key : section.getKeys(false)) {
try {
keys.add(Integer.parseInt(key));
} catch (NumberFormatException ex) {
}
}
Collections.sort(keys);
for (int key : keys)
res.add(getRelative(Integer.toString(key)));
return res;
}
private String getKeyExt(String from) {
if (from.isEmpty())
return current;
if (from.charAt(0) == '.')
return current.isEmpty() ? from.substring(1, from.length()) : current + from;
return current.isEmpty() ? from : current + "." + from;
}
@Override
public long getLong(String key) {
String path = getKeyExt(key);
if (pathExists(path)) {
if (config.getString(path) == null) {
if (config.get(path) instanceof Integer)
return config.getInt(path);
return config.getLong(path);
}
return Long.parseLong(config.getString(path));
}
return 0;
}
@Override
public long getLong(String key, long def) {
return config.getLong(getKeyExt(key), def);
}
@Override
public Object getRaw(String key) {
return config.get(getKeyExt(key));
}
@Override
public DataKey getRelative(String relative) {
if (relative == null || relative.isEmpty())
return this;
return new YamlKey(getKeyExt(relative));
}
@Override
public String getString(String key) {
String path = getKeyExt(key);
if (pathExists(path)) {
return config.get(path).toString();
}
return "";
}
@Override
public Iterable<DataKey> getSubKeys() {
List<DataKey> res = new ArrayList<DataKey>();
ConfigurationSection section = config.getConfigurationSection(current);
if (section == null)
return res;
for (String key : section.getKeys(false)) {
res.add(getRelative(key));
}
return res;
}
@Override
public boolean keyExists(String key) {
return config.get(getKeyExt(key)) != null;
}
@Override
public String name() {
int last = current.lastIndexOf('.');
return current.substring(last == 0 ? 0 : last + 1);
}
@Override
public void removeKey(String key) {
config.set(getKeyExt(key), null);
save();
}
@Override
public void setBoolean(String key, boolean value) {
config.set(getKeyExt(key), value);
}
@Override
public void setDouble(String key, double value) {
config.set(getKeyExt(key), String.valueOf(value));
}
@Override
public void setInt(String key, int value) {
config.set(getKeyExt(key), value);
}
@Override
public void setLong(String key, long value) {
config.set(getKeyExt(key), value);
}
@Override
public void setRaw(String key, Object value) {
config.set(getKeyExt(key), value);
}
@Override
public void setString(String key, String value) {
config.set(getKeyExt(key), value);
}
}
}