spacing :D
This commit is contained in:
@@ -9,27 +9,27 @@ import com.drtshock.playervaults.Main;
|
||||
|
||||
public class DropOnDeath {
|
||||
|
||||
public static Main plugin;
|
||||
public DropOnDeath(Main instance) {
|
||||
DropOnDeath.plugin = instance;
|
||||
}
|
||||
public static Main plugin;
|
||||
public DropOnDeath(Main instance) {
|
||||
DropOnDeath.plugin = instance;
|
||||
}
|
||||
|
||||
static VaultManager vm = new VaultManager(plugin);
|
||||
static VaultManager vm = new VaultManager(plugin);
|
||||
|
||||
/**
|
||||
* Drops all items when a player dies.
|
||||
* @param player
|
||||
*/
|
||||
public static void drop(Player player) {
|
||||
Location loc = player.getLocation();
|
||||
/**
|
||||
* Drops all items when a player dies.
|
||||
* @param player
|
||||
*/
|
||||
public static void drop(Player player) {
|
||||
Location loc = player.getLocation();
|
||||
|
||||
for(int count = 1; count <= Main.inventoriesToDrop; count++) {
|
||||
Inventory inv = vm.getVault(player, count);
|
||||
ItemStack[] stack = inv.getContents();
|
||||
for(ItemStack is : stack) {
|
||||
loc.getWorld().dropItemNaturally(loc, is);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int count = 1; count <= Main.inventoriesToDrop; count++) {
|
||||
Inventory inv = vm.getVault(player, count);
|
||||
ItemStack[] stack = inv.getContents();
|
||||
for(ItemStack is : stack) {
|
||||
loc.getWorld().dropItemNaturally(loc, is);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,86 +15,86 @@ import com.drtshock.playervaults.Main;
|
||||
|
||||
public class EconomyOperations {
|
||||
|
||||
private static File configFile;
|
||||
private static YamlConfiguration bukkitConfig = new YamlConfiguration();
|
||||
private static File configFile;
|
||||
private static YamlConfiguration bukkitConfig = new YamlConfiguration();
|
||||
|
||||
public static Main plugin;
|
||||
|
||||
public EconomyOperations(Main instance) throws FileNotFoundException, IOException, InvalidConfigurationException {
|
||||
plugin = instance;
|
||||
configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||
bukkitConfig.load(configFile);
|
||||
}
|
||||
/**
|
||||
* Have a player pay to open a vault.
|
||||
* Returns true if successful. Otherwise false.
|
||||
* @param player
|
||||
* @return transaction success
|
||||
*/
|
||||
public static boolean payToOpen(Player player) {
|
||||
if(!bukkitConfig.getBoolean("economy.enabled") || /*player.hasPermission("playervaults.free") || */!Main.useVault)
|
||||
return true;
|
||||
public static Main plugin;
|
||||
|
||||
double cost = bukkitConfig.getDouble("economy.cost-to-open", 10);
|
||||
EconomyResponse resp = Main.econ.withdrawPlayer(player.getName(), cost);
|
||||
if(resp.transactionSuccess()) {
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.COST_TO_OPEN.toString().replaceAll("%price", "" + cost));
|
||||
return true;
|
||||
}
|
||||
public EconomyOperations(Main instance) throws FileNotFoundException, IOException, InvalidConfigurationException {
|
||||
plugin = instance;
|
||||
configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||
bukkitConfig.load(configFile);
|
||||
}
|
||||
/**
|
||||
* Have a player pay to open a vault.
|
||||
* Returns true if successful. Otherwise false.
|
||||
* @param player
|
||||
* @return transaction success
|
||||
*/
|
||||
public static boolean payToOpen(Player player) {
|
||||
if(!bukkitConfig.getBoolean("economy.enabled") || /*player.hasPermission("playervaults.free") || */!Main.useVault)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Have a player pay to create a vault.
|
||||
* Returns true if successful. Otherwise false.
|
||||
* @param player
|
||||
* @return transaction success
|
||||
*/
|
||||
public static boolean payToCreate(Player player) {
|
||||
if(!bukkitConfig.getBoolean("economy.enabled") || /*player.hasPermission("playervaults.free") || */!Main.useVault)
|
||||
return true;
|
||||
double cost = bukkitConfig.getDouble("economy.cost-to-open", 10);
|
||||
EconomyResponse resp = Main.econ.withdrawPlayer(player.getName(), cost);
|
||||
if(resp.transactionSuccess()) {
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.COST_TO_OPEN.toString().replaceAll("%price", "" + cost));
|
||||
return true;
|
||||
}
|
||||
|
||||
double cost = bukkitConfig.getDouble("economy.cost-to-create", 100);
|
||||
EconomyResponse resp = Main.econ.withdrawPlayer(player.getName(), cost);
|
||||
if(resp.transactionSuccess()) {
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.COST_TO_CREATE.toString().replaceAll("%price", "" + cost));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Have a player pay to create a vault.
|
||||
* Returns true if successful. Otherwise false.
|
||||
* @param player
|
||||
* @return transaction success
|
||||
*/
|
||||
public static boolean payToCreate(Player player) {
|
||||
if(!bukkitConfig.getBoolean("economy.enabled") || /*player.hasPermission("playervaults.free") || */!Main.useVault)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
double cost = bukkitConfig.getDouble("economy.cost-to-create", 100);
|
||||
EconomyResponse resp = Main.econ.withdrawPlayer(player.getName(), cost);
|
||||
if(resp.transactionSuccess()) {
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.COST_TO_CREATE.toString().replaceAll("%price", "" + cost));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Have a player get his money back when vault is deleted.
|
||||
* Returns true if successful. Otherwise false.
|
||||
* @param player
|
||||
* @return transaction success.
|
||||
*/
|
||||
public static boolean refundOnDelete(Player player, int number) {
|
||||
String directory = "plugins" + File.separator + "PlayerVaults" + File.separator + "vaults";
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!bukkitConfig.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !Main.useVault)
|
||||
return true;
|
||||
String name = player.getName().toLowerCase();
|
||||
File file = new File(directory + File.separator + name.toLowerCase() + ".yml");
|
||||
YamlConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
|
||||
if(file.exists()) {
|
||||
if(playerFile.getString("vault"+number) == null) {
|
||||
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.VAULT_DOES_NOT_EXIST);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.VAULT_DOES_NOT_EXIST);
|
||||
return false;
|
||||
}
|
||||
double cost = bukkitConfig.getDouble("economy.refund-on-delete");
|
||||
EconomyResponse resp = Main.econ.depositPlayer(player.getName(), cost);
|
||||
if(resp.transactionSuccess()) {
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.REFUND_AMOUNT.toString().replaceAll("%price", String.valueOf(cost)));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Have a player get his money back when vault is deleted.
|
||||
* Returns true if successful. Otherwise false.
|
||||
* @param player
|
||||
* @return transaction success.
|
||||
*/
|
||||
public static boolean refundOnDelete(Player player, int number) {
|
||||
String directory = "plugins" + File.separator + "PlayerVaults" + File.separator + "vaults";
|
||||
|
||||
if(!bukkitConfig.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !Main.useVault)
|
||||
return true;
|
||||
String name = player.getName().toLowerCase();
|
||||
File file = new File(directory + File.separator + name.toLowerCase() + ".yml");
|
||||
YamlConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
|
||||
if(file.exists()) {
|
||||
if(playerFile.getString("vault"+number) == null) {
|
||||
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.VAULT_DOES_NOT_EXIST);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.VAULT_DOES_NOT_EXIST);
|
||||
return false;
|
||||
}
|
||||
double cost = bukkitConfig.getDouble("economy.refund-on-delete");
|
||||
EconomyResponse resp = Main.econ.depositPlayer(player.getName(), cost);
|
||||
if(resp.transactionSuccess()) {
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.REFUND_AMOUNT.toString().replaceAll("%price", String.valueOf(cost)));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,48 +4,48 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public enum Lang {
|
||||
TITLE("title-name", "&4[&fPlayerVaults&4]:"),
|
||||
OPEN_VAULT("open-vault", "&fOpening vault &a%v"),
|
||||
OPEN_OTHER_VAULT("open-other-vault", "&fOpening vault &a%v &fof &a%p"),
|
||||
OPEN_WORKBENCH("open-workbench", "&fOpening workbench"),
|
||||
INVALID_ARGS("invalid-args", "&cInvalid args!"),
|
||||
DELETE_VAULT("delete-vault", "&fDeleted vault &a%v"),
|
||||
DELETE_OTHER_VAULT("delete-other-vault", "&fDeleted vault &a%v &fof &a%p"),
|
||||
PLAYER_ONLY("player-only", "Sorry but that can only be run by a player!"),
|
||||
MUST_BE_NUMBER("must-be-number", "&cYou need to specify a number between 1-99"),
|
||||
DELETE_VAULT_ERROR("delete-vault-error", "&cError deleting vault :("),
|
||||
NO_PERMS("no-permissions", "&cYou don''t have permission for that!"),
|
||||
INSUFFICIENT_FUNDS("insufficient-funds", "&cYou don''t have enough money for that!"),
|
||||
REFUND_AMOUNT("refund-amount", "&fYou were refunded &a%price &ffor deleting that vault."),
|
||||
COST_TO_CREATE("cost-to-create", "&fYou were charged &c%price &ffor creating a vault."),
|
||||
COST_TO_OPEN("cost-to-open", "&fYou were charged &c%price &ffor opening that vault."),
|
||||
VAULT_DOES_NOT_EXIST("vault-does-not-exist", "&cThat vault does not exist!");
|
||||
TITLE("title-name", "&4[&fPlayerVaults&4]:"),
|
||||
OPEN_VAULT("open-vault", "&fOpening vault &a%v"),
|
||||
OPEN_OTHER_VAULT("open-other-vault", "&fOpening vault &a%v &fof &a%p"),
|
||||
OPEN_WORKBENCH("open-workbench", "&fOpening workbench"),
|
||||
INVALID_ARGS("invalid-args", "&cInvalid args!"),
|
||||
DELETE_VAULT("delete-vault", "&fDeleted vault &a%v"),
|
||||
DELETE_OTHER_VAULT("delete-other-vault", "&fDeleted vault &a%v &fof &a%p"),
|
||||
PLAYER_ONLY("player-only", "Sorry but that can only be run by a player!"),
|
||||
MUST_BE_NUMBER("must-be-number", "&cYou need to specify a number between 1-99"),
|
||||
DELETE_VAULT_ERROR("delete-vault-error", "&cError deleting vault :("),
|
||||
NO_PERMS("no-permissions", "&cYou don''t have permission for that!"),
|
||||
INSUFFICIENT_FUNDS("insufficient-funds", "&cYou don''t have enough money for that!"),
|
||||
REFUND_AMOUNT("refund-amount", "&fYou were refunded &a%price &ffor deleting that vault."),
|
||||
COST_TO_CREATE("cost-to-create", "&fYou were charged &c%price &ffor creating a vault."),
|
||||
COST_TO_OPEN("cost-to-open", "&fYou were charged &c%price &ffor opening that vault."),
|
||||
VAULT_DOES_NOT_EXIST("vault-does-not-exist", "&cThat vault does not exist!");
|
||||
|
||||
private String path;
|
||||
private String def; // Default string
|
||||
private static YamlConfiguration lang;
|
||||
private String path;
|
||||
private String def; // Default string
|
||||
private static YamlConfiguration lang;
|
||||
|
||||
Lang(String path, String start) {
|
||||
this.path = path;
|
||||
this.def = start;
|
||||
}
|
||||
Lang(String path, String start) {
|
||||
this.path = path;
|
||||
this.def = start;
|
||||
}
|
||||
|
||||
public static void setFile(YamlConfiguration yc) {
|
||||
lang = yc;
|
||||
}
|
||||
public static void setFile(YamlConfiguration yc) {
|
||||
lang = yc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if(this == TITLE)
|
||||
return ChatColor.translateAlternateColorCodes('&', lang.getString(this.path, def)) + " ";
|
||||
return ChatColor.translateAlternateColorCodes('&', lang.getString(this.path, def));
|
||||
}
|
||||
|
||||
public String getDefault() {
|
||||
return this.def;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
if(this == TITLE)
|
||||
return ChatColor.translateAlternateColorCodes('&', lang.getString(this.path, def)) + " ";
|
||||
return ChatColor.translateAlternateColorCodes('&', lang.getString(this.path, def));
|
||||
}
|
||||
|
||||
public String getDefault() {
|
||||
return this.def;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ public class Metrics {
|
||||
* The plugin configuration file
|
||||
*/
|
||||
private final YamlConfiguration configuration;
|
||||
|
||||
|
||||
/**
|
||||
* The plugin configuration file
|
||||
*/
|
||||
@@ -218,7 +218,7 @@ public class Metrics {
|
||||
* @return True if statistics measuring is running, otherwise false.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean start() {
|
||||
public boolean start() {
|
||||
synchronized (optOutLock) {
|
||||
// Did we opt out?
|
||||
if (isOptOut()) {
|
||||
@@ -290,23 +290,23 @@ public class Metrics {
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void enable() throws IOException {
|
||||
// This has to be synchronized or it can collide with the check in the task.
|
||||
synchronized (optOutLock) {
|
||||
// Check if the server owner has already set opt-out, if not, set it.
|
||||
if (isOptOut()) {
|
||||
configuration.set("opt-out", false);
|
||||
configuration.save(configurationFile);
|
||||
}
|
||||
// Check if the server owner has already set opt-out, if not, set it.
|
||||
if (isOptOut()) {
|
||||
configuration.set("opt-out", false);
|
||||
configuration.save(configurationFile);
|
||||
}
|
||||
|
||||
// Enable Task, if it is not running
|
||||
if (taskId < 0) {
|
||||
start();
|
||||
}
|
||||
// Enable Task, if it is not running
|
||||
if (taskId < 0) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,12 +19,12 @@ import org.json.JSONObject;
|
||||
|
||||
public class Serialization {
|
||||
|
||||
/*
|
||||
* All normal functions
|
||||
*/
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<String, Object> toMap(JSONObject object) throws JSONException {
|
||||
/*
|
||||
* All normal functions
|
||||
*/
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<String, Object> toMap(JSONObject object) throws JSONException {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
Iterator<String> keys = object.keys();
|
||||
while (keys.hasNext()) {
|
||||
@@ -33,7 +33,7 @@ public class Serialization {
|
||||
}
|
||||
return map;
|
||||
}
|
||||
private static Object fromJson(Object json) throws JSONException {
|
||||
private static Object fromJson(Object json) throws JSONException {
|
||||
if (json == JSONObject.NULL) {
|
||||
return null;
|
||||
} else if (json instanceof JSONObject) {
|
||||
@@ -44,54 +44,54 @@ public class Serialization {
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Object> toList(JSONArray array) throws JSONException {
|
||||
|
||||
public static List<Object> toList(JSONArray array) throws JSONException {
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
list.add(fromJson(array.get(i)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<String> toString(Inventory inv) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
List<ConfigurationSerializable> items = new ArrayList<ConfigurationSerializable>();
|
||||
for(ItemStack is:inv.getContents()) {
|
||||
items.add(is);
|
||||
}
|
||||
for(ConfigurationSerializable cs:items) {
|
||||
if(cs == null) {
|
||||
result.add("null");
|
||||
}
|
||||
else {
|
||||
result.add(new JSONObject(serialize(cs)).toString());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Inventory toInventory(List<String> stringItems, int number) {
|
||||
Inventory inv = Bukkit.createInventory(null, 54, ChatColor.RED + "Vault #" + number);
|
||||
List<ItemStack> contents = new ArrayList<ItemStack>();
|
||||
for(String piece:stringItems) {
|
||||
if(piece.equalsIgnoreCase("null")) {
|
||||
contents.add(null);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
ItemStack item = (ItemStack) deserialize(toMap(new JSONObject(piece)));
|
||||
contents.add(item);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
ItemStack[] items = new ItemStack[contents.size()];
|
||||
for(int x = 0; x < contents.size(); x++)
|
||||
items[x] = contents.get(x);
|
||||
inv.setContents(items);
|
||||
return inv;
|
||||
}
|
||||
|
||||
public static List<String> toString(Inventory inv) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
List<ConfigurationSerializable> items = new ArrayList<ConfigurationSerializable>();
|
||||
for(ItemStack is:inv.getContents()) {
|
||||
items.add(is);
|
||||
}
|
||||
for(ConfigurationSerializable cs:items) {
|
||||
if(cs == null) {
|
||||
result.add("null");
|
||||
}
|
||||
else {
|
||||
result.add(new JSONObject(serialize(cs)).toString());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Inventory toInventory(List<String> stringItems, int number) {
|
||||
Inventory inv = Bukkit.createInventory(null, 54, ChatColor.RED + "Vault #" + number);
|
||||
List<ItemStack> contents = new ArrayList<ItemStack>();
|
||||
for(String piece:stringItems) {
|
||||
if(piece.equalsIgnoreCase("null")) {
|
||||
contents.add(null);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
ItemStack item = (ItemStack) deserialize(toMap(new JSONObject(piece)));
|
||||
contents.add(item);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
ItemStack[] items = new ItemStack[contents.size()];
|
||||
for(int x = 0; x < contents.size(); x++)
|
||||
items[x] = contents.get(x);
|
||||
inv.setContents(items);
|
||||
return inv;
|
||||
}
|
||||
|
||||
public static Map<String, Object> serialize(ConfigurationSerializable cs) {
|
||||
Map<String, Object> serialized = recreateMap(cs.serialize());
|
||||
@@ -121,7 +121,7 @@ public class Serialization {
|
||||
}
|
||||
return ConfigurationSerialization.deserializeObject(map);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* All old methods for transferring
|
||||
*/
|
||||
|
||||
@@ -14,66 +14,66 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import com.drtshock.playervaults.Main;
|
||||
|
||||
public class Updater extends Main {
|
||||
|
||||
SortedMap<String, String> lang = new TreeMap<String, String>();
|
||||
String version;
|
||||
|
||||
public Updater(String version) {
|
||||
this.version = version;
|
||||
YamlConfiguration langConf = super.getLang();
|
||||
for(Lang item:Lang.values()) {
|
||||
if(langConf.getString(item.getPath()) == null) {
|
||||
langConf.set(item.getPath(), item.getDefault());
|
||||
}
|
||||
}
|
||||
try {
|
||||
langConf.save(super.getLangFile());
|
||||
} catch (IOException e) {
|
||||
log.log(Level.WARNING, "PlayerVaults: Failed to save lang.yml.");
|
||||
log.log(Level.WARNING, "PlayerVaults: Report this stack trace to drtshock and gomeow.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
String newVersion = "";
|
||||
|
||||
public String getNewVersion() {
|
||||
return this.newVersion;
|
||||
}
|
||||
public boolean getUpdate() throws Exception {
|
||||
String version = this.version;
|
||||
URL url = new URL("http://dev.bukkit.org/server-mods/playervaults/files.rss");
|
||||
InputStreamReader isr = null;
|
||||
try {
|
||||
isr = new InputStreamReader(url.openStream());
|
||||
}
|
||||
catch(UnknownHostException e) {
|
||||
return false; //Cannot connect
|
||||
}
|
||||
BufferedReader in = new BufferedReader(isr);
|
||||
String line;
|
||||
int lineNum = 0;
|
||||
while((line = in.readLine()) != null) {
|
||||
if(line.length() != line.replace("<title>", "").length()) {
|
||||
line = line.replaceAll("<title>", "").replaceAll("</title>", "").replaceAll(" ", "").substring(1); //Substring 1 for me, takes off the beginning v on my file name "v1.3.2"
|
||||
if(lineNum == 1) {
|
||||
this.newVersion = line;
|
||||
Integer newVer = Integer.parseInt(line.replace(".", ""));
|
||||
Integer oldVer = Integer.parseInt(version.replace(".", ""));
|
||||
if(oldVer < newVer) {
|
||||
return true; //They are using an old version
|
||||
}
|
||||
else if(oldVer > newVer) {
|
||||
return false; //They are using a FUTURE version!
|
||||
}
|
||||
else {
|
||||
return false; //They are up to date!
|
||||
}
|
||||
}
|
||||
lineNum = lineNum + 1;
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
SortedMap<String, String> lang = new TreeMap<String, String>();
|
||||
String version;
|
||||
|
||||
public Updater(String version) {
|
||||
this.version = version;
|
||||
YamlConfiguration langConf = super.getLang();
|
||||
for(Lang item:Lang.values()) {
|
||||
if(langConf.getString(item.getPath()) == null) {
|
||||
langConf.set(item.getPath(), item.getDefault());
|
||||
}
|
||||
}
|
||||
try {
|
||||
langConf.save(super.getLangFile());
|
||||
} catch (IOException e) {
|
||||
log.log(Level.WARNING, "PlayerVaults: Failed to save lang.yml.");
|
||||
log.log(Level.WARNING, "PlayerVaults: Report this stack trace to drtshock and gomeow.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
String newVersion = "";
|
||||
|
||||
public String getNewVersion() {
|
||||
return this.newVersion;
|
||||
}
|
||||
public boolean getUpdate() throws Exception {
|
||||
String version = this.version;
|
||||
URL url = new URL("http://dev.bukkit.org/server-mods/playervaults/files.rss");
|
||||
InputStreamReader isr = null;
|
||||
try {
|
||||
isr = new InputStreamReader(url.openStream());
|
||||
}
|
||||
catch(UnknownHostException e) {
|
||||
return false; //Cannot connect
|
||||
}
|
||||
BufferedReader in = new BufferedReader(isr);
|
||||
String line;
|
||||
int lineNum = 0;
|
||||
while((line = in.readLine()) != null) {
|
||||
if(line.length() != line.replace("<title>", "").length()) {
|
||||
line = line.replaceAll("<title>", "").replaceAll("</title>", "").replaceAll(" ", "").substring(1); //Substring 1 for me, takes off the beginning v on my file name "v1.3.2"
|
||||
if(lineNum == 1) {
|
||||
this.newVersion = line;
|
||||
Integer newVer = Integer.parseInt(line.replace(".", ""));
|
||||
Integer oldVer = Integer.parseInt(version.replace(".", ""));
|
||||
if(oldVer < newVer) {
|
||||
return true; //They are using an old version
|
||||
}
|
||||
else if(oldVer > newVer) {
|
||||
return false; //They are using a FUTURE version!
|
||||
}
|
||||
else {
|
||||
return false; //They are up to date!
|
||||
}
|
||||
}
|
||||
lineNum = lineNum + 1;
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -17,136 +17,136 @@ import com.drtshock.playervaults.Main;
|
||||
|
||||
public class VaultManager {
|
||||
|
||||
public Main plugin;
|
||||
public VaultManager(Main instance) {
|
||||
this.plugin = instance;
|
||||
}
|
||||
public Main plugin;
|
||||
public VaultManager(Main instance) {
|
||||
this.plugin = instance;
|
||||
}
|
||||
|
||||
private final String directory = "plugins" + File.separator + "PlayerVaults" + File.separator + "vaults";
|
||||
private final String directory = "plugins" + File.separator + "PlayerVaults" + File.separator + "vaults";
|
||||
|
||||
/**
|
||||
* Method to save player's vault.
|
||||
* Serialize his inventory.
|
||||
* Save the vaults.yml
|
||||
* @param player
|
||||
* @throws IOException
|
||||
*/
|
||||
public void saveVault(Inventory inv, String player, int number) throws IOException {
|
||||
YamlConfiguration yaml = playerVaultFile(player);
|
||||
yaml.set("vault" + number, null);
|
||||
List<String> list = Serialization.toString(inv);
|
||||
String[] ser = list.toArray(new String[list.size()]);
|
||||
for(int x = 0; x < ser.length; x++) {
|
||||
if(!ser[x].equalsIgnoreCase("null"))
|
||||
yaml.set("vault" + number + "." + x, ser[x]);
|
||||
}
|
||||
saveFile(player, yaml);
|
||||
}
|
||||
/**
|
||||
* Method to save player's vault.
|
||||
* Serialize his inventory.
|
||||
* Save the vaults.yml
|
||||
* @param player
|
||||
* @throws IOException
|
||||
*/
|
||||
public void saveVault(Inventory inv, String player, int number) throws IOException {
|
||||
YamlConfiguration yaml = playerVaultFile(player);
|
||||
yaml.set("vault" + number, null);
|
||||
List<String> list = Serialization.toString(inv);
|
||||
String[] ser = list.toArray(new String[list.size()]);
|
||||
for(int x = 0; x < ser.length; x++) {
|
||||
if(!ser[x].equalsIgnoreCase("null"))
|
||||
yaml.set("vault" + number + "." + x, ser[x]);
|
||||
}
|
||||
saveFile(player, yaml);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to load player's vault.
|
||||
* Deserialize his inventory
|
||||
*
|
||||
* TODO: Check to see if the path exists before we get it!
|
||||
*/
|
||||
public void loadVault(Player player, String holder, int number) {
|
||||
Inventory inv = null;
|
||||
YamlConfiguration playerFile = playerVaultFile(holder);
|
||||
if(playerFile.getConfigurationSection("vault" + number) == null) {
|
||||
inv = Bukkit.createInventory(player, 54, ChatColor.DARK_RED + "Vault #" + String.valueOf(number));
|
||||
}
|
||||
else {
|
||||
List<String> data = new ArrayList<String>();
|
||||
for(int x = 0; x < 54; x++) {
|
||||
String line = playerFile.getString("vault" + number + "." + x);
|
||||
if(line != null) {
|
||||
data.add(line);
|
||||
}
|
||||
else {
|
||||
data.add("null");
|
||||
}
|
||||
}
|
||||
inv = Serialization.toInventory(data, number);
|
||||
}
|
||||
player.openInventory(inv);
|
||||
}
|
||||
/**
|
||||
* Method to load player's vault.
|
||||
* Deserialize his inventory
|
||||
*
|
||||
* TODO: Check to see if the path exists before we get it!
|
||||
*/
|
||||
public void loadVault(Player player, String holder, int number) {
|
||||
Inventory inv = null;
|
||||
YamlConfiguration playerFile = playerVaultFile(holder);
|
||||
if(playerFile.getConfigurationSection("vault" + number) == null) {
|
||||
inv = Bukkit.createInventory(player, 54, ChatColor.DARK_RED + "Vault #" + String.valueOf(number));
|
||||
}
|
||||
else {
|
||||
List<String> data = new ArrayList<String>();
|
||||
for(int x = 0; x < 54; x++) {
|
||||
String line = playerFile.getString("vault" + number + "." + x);
|
||||
if(line != null) {
|
||||
data.add(line);
|
||||
}
|
||||
else {
|
||||
data.add("null");
|
||||
}
|
||||
}
|
||||
inv = Serialization.toInventory(data, number);
|
||||
}
|
||||
player.openInventory(inv);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an inventory without opening it.
|
||||
* Used for dropping a players inventories on death.
|
||||
* @param player
|
||||
* @param number
|
||||
* @return the inventory
|
||||
*/
|
||||
public Inventory getVault(Player player, int number) {
|
||||
YamlConfiguration playerFile = playerVaultFile(player.getName());
|
||||
List<String> data = playerFile.getStringList("vault" + number);
|
||||
if(data == null) {
|
||||
Inventory inv = Bukkit.createInventory(player, 54, ChatColor.GREEN + "Vault #" + String.valueOf(number));
|
||||
return inv;
|
||||
} else {
|
||||
Inventory inv = Serialization.toInventory(data, number);
|
||||
return inv;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Gets an inventory without opening it.
|
||||
* Used for dropping a players inventories on death.
|
||||
* @param player
|
||||
* @param number
|
||||
* @return the inventory
|
||||
*/
|
||||
public Inventory getVault(Player player, int number) {
|
||||
YamlConfiguration playerFile = playerVaultFile(player.getName());
|
||||
List<String> data = playerFile.getStringList("vault" + number);
|
||||
if(data == null) {
|
||||
Inventory inv = Bukkit.createInventory(player, 54, ChatColor.GREEN + "Vault #" + String.valueOf(number));
|
||||
return inv;
|
||||
} else {
|
||||
Inventory inv = Serialization.toInventory(data, number);
|
||||
return inv;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a players vault.
|
||||
* @param sender
|
||||
* @param target
|
||||
* @param number
|
||||
* @throws IOException
|
||||
*/
|
||||
public void deleteVault(CommandSender sender, String target, int number) throws IOException {
|
||||
String name = target.toLowerCase();
|
||||
File file = new File(directory + File.separator + name.toLowerCase() + ".yml");
|
||||
FileConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
|
||||
if(file.exists()) {
|
||||
playerFile.set("vault" + number, null);
|
||||
playerFile.save(file);
|
||||
}
|
||||
if(sender.getName().equalsIgnoreCase(target)) {
|
||||
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT.toString().replace("%v", String.valueOf(number)));
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_OTHER_VAULT.toString().replace("%v", String.valueOf(number)).replace("%p", target));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Deletes a players vault.
|
||||
* @param sender
|
||||
* @param target
|
||||
* @param number
|
||||
* @throws IOException
|
||||
*/
|
||||
public void deleteVault(CommandSender sender, String target, int number) throws IOException {
|
||||
String name = target.toLowerCase();
|
||||
File file = new File(directory + File.separator + name.toLowerCase() + ".yml");
|
||||
FileConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
|
||||
if(file.exists()) {
|
||||
playerFile.set("vault" + number, null);
|
||||
playerFile.save(file);
|
||||
}
|
||||
if(sender.getName().equalsIgnoreCase(target)) {
|
||||
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT.toString().replace("%v", String.valueOf(number)));
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_OTHER_VAULT.toString().replace("%v", String.valueOf(number)).replace("%p", target));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player's vault file.
|
||||
* Create if doesn't exist.
|
||||
* @param player
|
||||
* @return playerVaultFile file.
|
||||
*/
|
||||
public YamlConfiguration playerVaultFile(String player) {
|
||||
File folder = new File(directory);
|
||||
if(!folder.exists()) {
|
||||
folder.mkdir();
|
||||
}
|
||||
File file = new File(directory + File.separator + player.toLowerCase() + ".yml");
|
||||
if(!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
YamlConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
|
||||
return playerFile;
|
||||
}
|
||||
/**
|
||||
* Get the player's vault file.
|
||||
* Create if doesn't exist.
|
||||
* @param player
|
||||
* @return playerVaultFile file.
|
||||
*/
|
||||
public YamlConfiguration playerVaultFile(String player) {
|
||||
File folder = new File(directory);
|
||||
if(!folder.exists()) {
|
||||
folder.mkdir();
|
||||
}
|
||||
File file = new File(directory + File.separator + player.toLowerCase() + ".yml");
|
||||
if(!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
YamlConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
|
||||
return playerFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the players vault file.
|
||||
* @param name
|
||||
* @param yaml
|
||||
* @throws IOException
|
||||
*/
|
||||
public void saveFile(String name, YamlConfiguration yaml) throws IOException {
|
||||
File file = new File(directory + File.separator + name.toLowerCase() + ".yml");
|
||||
if (file.exists()) {
|
||||
file.renameTo(new File(directory + File.separator + "backups" + File.separator + name.toLowerCase() + ".yml"));
|
||||
}
|
||||
yaml.save(file);
|
||||
}
|
||||
/**
|
||||
* Save the players vault file.
|
||||
* @param name
|
||||
* @param yaml
|
||||
* @throws IOException
|
||||
*/
|
||||
public void saveFile(String name, YamlConfiguration yaml) throws IOException {
|
||||
File file = new File(directory + File.separator + name.toLowerCase() + ".yml");
|
||||
if (file.exists()) {
|
||||
file.renameTo(new File(directory + File.separator + "backups" + File.separator + name.toLowerCase() + ".yml"));
|
||||
}
|
||||
yaml.save(file);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user