Oh, so very much formatting and stuffs
This commit is contained in:
@@ -2,6 +2,7 @@ package com.drtshock.playervaults;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -23,14 +24,13 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
|||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
|
import org.bukkit.event.server.PluginDisableEvent;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
import com.drtshock.playervaults.commands.VaultViewInfo;
|
import com.drtshock.playervaults.commands.VaultViewInfo;
|
||||||
import com.drtshock.playervaults.util.DropOnDeath;
|
import com.drtshock.playervaults.util.DropOnDeath;
|
||||||
import com.drtshock.playervaults.util.Lang;
|
import com.drtshock.playervaults.util.Lang;
|
||||||
import com.drtshock.playervaults.util.VaultManager;
|
import com.drtshock.playervaults.util.VaultManager;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.event.server.PluginDisableEvent;
|
|
||||||
|
|
||||||
public class Listeners implements Listener {
|
public class Listeners implements Listener {
|
||||||
|
|
||||||
@@ -39,6 +39,7 @@ public class Listeners implements Listener {
|
|||||||
public Listeners(PlayerVaults playerVaults) {
|
public Listeners(PlayerVaults playerVaults) {
|
||||||
this.plugin = playerVaults;
|
this.plugin = playerVaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
VaultManager vm = new VaultManager(plugin);
|
VaultManager vm = new VaultManager(plugin);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,7 +91,7 @@ public class Listeners implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onJoin(PlayerJoinEvent event) {
|
public void onJoin(PlayerJoinEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
vm.playerVaultFile(player.getName());
|
vm.getPlayerVaultFile(player.getName());
|
||||||
if (player.isOp() && PlayerVaults.UPDATE) {
|
if (player.isOp() && PlayerVaults.UPDATE) {
|
||||||
player.sendMessage(ChatColor.GREEN + "Version " + PlayerVaults.NEWVERSION + " of PlayerVaults is up for download!");
|
player.sendMessage(ChatColor.GREEN + "Version " + PlayerVaults.NEWVERSION + " of PlayerVaults is up for download!");
|
||||||
player.sendMessage(ChatColor.GREEN + PlayerVaults.LINK + " to view the changelog and download!");
|
player.sendMessage(ChatColor.GREEN + PlayerVaults.LINK + " to view the changelog and download!");
|
||||||
@@ -127,10 +128,7 @@ public class Listeners implements Listener {
|
|||||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||||
if (PlayerVaults.IN_VAULT.containsKey(player.getName())) {
|
if (PlayerVaults.IN_VAULT.containsKey(player.getName())) {
|
||||||
Block block = event.getClickedBlock();
|
Block block = event.getClickedBlock();
|
||||||
|
// Different inventories that we don't want the player to open.
|
||||||
/**
|
|
||||||
* Different inventories that we don't want the player to open.
|
|
||||||
*/
|
|
||||||
if (block.getType() == Material.CHEST
|
if (block.getType() == Material.CHEST
|
||||||
|| block.getType() == Material.ENDER_CHEST
|
|| block.getType() == Material.ENDER_CHEST
|
||||||
|| block.getType() == Material.FURNACE
|
|| block.getType() == Material.FURNACE
|
||||||
@@ -190,7 +188,8 @@ public class Listeners implements Listener {
|
|||||||
owner = PlayerVaults.SIGNS.getString(world + ";;" + x + ";;" + y + ";;" + z + ".owner");
|
owner = PlayerVaults.SIGNS.getString(world + ";;" + x + ";;" + y + ";;" + z + ".owner");
|
||||||
}
|
}
|
||||||
int num = PlayerVaults.SIGNS.getInt(world + ";;" + x + ";;" + y + ";;" + z + ".chest");
|
int num = PlayerVaults.SIGNS.getInt(world + ";;" + x + ";;" + y + ";;" + z + ".chest");
|
||||||
PlayerVaults.VM.loadVault(player, (self) ? player.getName() : owner, num);
|
Inventory inv = PlayerVaults.VM.loadVault((self) ? player.getName() : owner, num);
|
||||||
|
player.openInventory(inv);
|
||||||
PlayerVaults.IN_VAULT.put(player.getName(), new VaultViewInfo((self) ? player.getName() : owner, num));
|
PlayerVaults.IN_VAULT.put(player.getName(), new VaultViewInfo((self) ? player.getName() : owner, num));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
player.sendMessage(Lang.TITLE.toString() + Lang.OPEN_WITH_SIGN.toString().replace("%v", String.valueOf(num)).replace("%p", (self) ? player.getName() : owner));
|
player.sendMessage(Lang.TITLE.toString() + Lang.OPEN_WITH_SIGN.toString().replace("%v", String.valueOf(num)).replace("%p", (self) ? player.getName() : owner));
|
||||||
@@ -217,11 +216,15 @@ public class Listeners implements Listener {
|
|||||||
blockChangeCheck(event.getBlock().getLocation());
|
blockChangeCheck(event.getBlock().getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void blockChangeCheck(Location l) {
|
/**
|
||||||
String world = l.getWorld().getName();
|
* Check if the location given is a sign, and if so, remove it from the signs.yml file
|
||||||
int x = l.getBlockX();
|
* @param location The location to check
|
||||||
int y = l.getBlockY();
|
*/
|
||||||
int z = l.getBlockZ();
|
public void blockChangeCheck(Location location) {
|
||||||
|
String world = location.getWorld().getName();
|
||||||
|
int x = location.getBlockX();
|
||||||
|
int y = location.getBlockY();
|
||||||
|
int z = location.getBlockZ();
|
||||||
if (plugin.getSigns().getKeys(false).contains(world + ";;" + x + ";;" + y + ";;" + z)) {
|
if (plugin.getSigns().getKeys(false).contains(world + ";;" + x + ";;" + y + ";;" + z)) {
|
||||||
plugin.getSigns().set(world + ";;" + x + ";;" + y + ";;" + z, null);
|
plugin.getSigns().set(world + ";;" + x + ";;" + y + ";;" + z, null);
|
||||||
plugin.saveSigns();
|
plugin.saveSigns();
|
||||||
@@ -229,8 +232,7 @@ public class Listeners implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Don't let a player open a trading inventory OR a minecart while he has
|
* Don't let a player open a trading inventory OR a minecart while he has his vault open.
|
||||||
* his vault open.
|
|
||||||
*/
|
*/
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInteractEntity(PlayerInteractEntityEvent event) {
|
public void onInteractEntity(PlayerInteractEntityEvent event) {
|
||||||
|
|||||||
@@ -81,6 +81,9 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
VM = new VaultManager(this);
|
VM = new VaultManager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start metrics
|
||||||
|
*/
|
||||||
public void startMetrics() {
|
public void startMetrics() {
|
||||||
try {
|
try {
|
||||||
Metrics metrics = new Metrics(this);
|
Metrics metrics = new Metrics(this);
|
||||||
@@ -90,6 +93,11 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup economy
|
||||||
|
*
|
||||||
|
* @return Whether or not economy exists.
|
||||||
|
*/
|
||||||
private boolean setupEconomy() {
|
private boolean setupEconomy() {
|
||||||
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||||
return false;
|
return false;
|
||||||
@@ -103,6 +111,9 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
return ECON != null;
|
return ECON != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the config.yml file.
|
||||||
|
*/
|
||||||
public void loadConfig() {
|
public void loadConfig() {
|
||||||
File config = new File(getDataFolder() + File.separator + "config.yml");
|
File config = new File(getDataFolder() + File.separator + "config.yml");
|
||||||
if (!config.exists()) {
|
if (!config.exists()) {
|
||||||
@@ -112,6 +123,9 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the signs.yml file.
|
||||||
|
*/
|
||||||
public void loadSigns() {
|
public void loadSigns() {
|
||||||
File signs = new File(getDataFolder(), "signs.yml");
|
File signs = new File(getDataFolder(), "signs.yml");
|
||||||
if (!signs.exists()) {
|
if (!signs.exists()) {
|
||||||
@@ -127,10 +141,18 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
PlayerVaults.SIGNS = YamlConfiguration.loadConfiguration(signs);
|
PlayerVaults.SIGNS = YamlConfiguration.loadConfiguration(signs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the signs.yml config.
|
||||||
|
*
|
||||||
|
* @return The signs.yml config.
|
||||||
|
*/
|
||||||
public YamlConfiguration getSigns() {
|
public YamlConfiguration getSigns() {
|
||||||
return PlayerVaults.SIGNS;
|
return PlayerVaults.SIGNS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the signs.yml file.
|
||||||
|
*/
|
||||||
public void saveSigns() {
|
public void saveSigns() {
|
||||||
try {
|
try {
|
||||||
PlayerVaults.SIGNS.save(PlayerVaults.SIGNS_FILE);
|
PlayerVaults.SIGNS.save(PlayerVaults.SIGNS_FILE);
|
||||||
@@ -141,6 +163,9 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the config.yml file.
|
||||||
|
*/
|
||||||
public void updateConfig() {
|
public void updateConfig() {
|
||||||
boolean checkUpdate = getConfig().getBoolean("check-update", true);
|
boolean checkUpdate = getConfig().getBoolean("check-update", true);
|
||||||
boolean ecoEnabled = getConfig().getBoolean("economy.enabled", false);
|
boolean ecoEnabled = getConfig().getBoolean("economy.enabled", false);
|
||||||
@@ -166,10 +191,20 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set an object in the config.yml
|
||||||
|
* @param path The path in the config.
|
||||||
|
* @param object What to be saved.
|
||||||
|
* @param conf Where to save the object.
|
||||||
|
*/
|
||||||
public <T> void setInConfig(String path, T object, YamlConfiguration conf) {
|
public <T> void setInConfig(String path, T object, YamlConfiguration conf) {
|
||||||
conf.set(path, object);
|
conf.set(path, object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the lang.yml file.
|
||||||
|
* @return The lang.yml config.
|
||||||
|
*/
|
||||||
public YamlConfiguration loadLang() {
|
public YamlConfiguration loadLang() {
|
||||||
File lang = new File(getDataFolder(), "lang.yml");
|
File lang = new File(getDataFolder(), "lang.yml");
|
||||||
if (!lang.exists()) {
|
if (!lang.exists()) {
|
||||||
@@ -197,10 +232,18 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the lang.yml config.
|
||||||
|
* @return The lang.yml config.
|
||||||
|
*/
|
||||||
public YamlConfiguration getLang() {
|
public YamlConfiguration getLang() {
|
||||||
return LANG;
|
return LANG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the lang.yml file.
|
||||||
|
* @return The lang.yml file.
|
||||||
|
*/
|
||||||
public File getLangFile() {
|
public File getLangFile() {
|
||||||
return LANG_FILE;
|
return LANG_FILE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.drtshock.playervaults.commands;
|
package com.drtshock.playervaults.commands;
|
||||||
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@@ -30,7 +29,8 @@ public class Commands implements CommandExecutor {
|
|||||||
PlayerVaults.IN_VAULT.put(sender.getName(), new VaultViewInfo(args[0], Integer.parseInt(args[1])));
|
PlayerVaults.IN_VAULT.put(sender.getName(), new VaultViewInfo(args[0], Integer.parseInt(args[1])));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Feedback.showHelp(sender, Feedback.Type.OPEN);
|
sender.sendMessage(Lang.TITLE + "/pv <number>");
|
||||||
|
sender.sendMessage(Lang.TITLE + "/pv <player> <number>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.PLAYER_ONLY);
|
else sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.PLAYER_ONLY);
|
||||||
@@ -49,7 +49,8 @@ public class Commands implements CommandExecutor {
|
|||||||
VaultOperations.deleteOtherVault(sender, args[0], args[1]);
|
VaultOperations.deleteOtherVault(sender, args[0], args[1]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Feedback.showHelp(sender, Feedback.Type.DELETE);
|
sender.sendMessage(Lang.TITLE + "/pvdel <number>");
|
||||||
|
sender.sendMessage(Lang.TITLE + "/pvdel <player> <number>");
|
||||||
}
|
}
|
||||||
} else if (cmd.getName().equalsIgnoreCase("workbench")) {
|
} else if (cmd.getName().equalsIgnoreCase("workbench")) {
|
||||||
if (sender.hasPermission("playervaults.workbench")) {
|
if (sender.hasPermission("playervaults.workbench")) {
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
package com.drtshock.playervaults.commands;
|
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import com.drtshock.playervaults.util.Lang;
|
|
||||||
|
|
||||||
public class Feedback {
|
|
||||||
public enum Type {
|
|
||||||
OPEN,
|
|
||||||
DELETE,
|
|
||||||
WORKBENCH, // For later versions
|
|
||||||
FURNACE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void noPerms(CommandSender sender) {
|
|
||||||
sender.sendMessage(Lang.TITLE + "" + Lang.NO_PERMS);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void showHelp(CommandSender sender, Type t) {
|
|
||||||
if(t == Type.OPEN) {
|
|
||||||
sender.sendMessage(Lang.TITLE + "/pv <number>");
|
|
||||||
sender.sendMessage(Lang.TITLE + "/pv <player> <number>");
|
|
||||||
}
|
|
||||||
else if(t == Type.DELETE) {
|
|
||||||
sender.sendMessage(Lang.TITLE + "/pvdel <number>");
|
|
||||||
sender.sendMessage(Lang.TITLE + "/pvdel <player> <number>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +1,56 @@
|
|||||||
package com.drtshock.playervaults.commands;
|
package com.drtshock.playervaults.commands;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class for setting signs. Stores information about the sign owner, number,
|
||||||
|
* and whether or not is opens a self vault or another person's vault.
|
||||||
|
*/
|
||||||
public class SignSetInfo {
|
public class SignSetInfo {
|
||||||
|
|
||||||
private String o;
|
private String owner;
|
||||||
private int i;
|
private int number;
|
||||||
private boolean self = false;
|
private boolean self = false;
|
||||||
|
|
||||||
public SignSetInfo(String o, int i) {
|
/**
|
||||||
this.o = o;
|
* Construct a SignSetInfo object for another person.
|
||||||
this.i = i;
|
* @param s The vault owner.
|
||||||
|
* @param i The vault number.
|
||||||
|
*/
|
||||||
|
public SignSetInfo(String s, int i) {
|
||||||
|
this.owner = s;
|
||||||
|
this.number = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a SignSetInfo object for opening to self.
|
||||||
|
* @param i The vault number.
|
||||||
|
*/
|
||||||
public SignSetInfo(int i) {
|
public SignSetInfo(int i) {
|
||||||
this.i = i;
|
this.number = i;
|
||||||
this.self = true;
|
this.self = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get whether or not the sign will open their own vault or another person's.
|
||||||
|
* @return Whether or not it is a 'self' sign.
|
||||||
|
*/
|
||||||
public boolean isSelf() {
|
public boolean isSelf() {
|
||||||
return this.self;
|
return this.self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the owner of the vault.
|
||||||
|
* @return The owner of the vault.
|
||||||
|
*/
|
||||||
public String getOwner() {
|
public String getOwner() {
|
||||||
return this.o;
|
return this.owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the vault number.
|
||||||
|
* @return The vault number.
|
||||||
|
*/
|
||||||
public int getChest() {
|
public int getChest() {
|
||||||
return this.i;
|
return this.number;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.io.IOException;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
import com.drtshock.playervaults.PlayerVaults;
|
import com.drtshock.playervaults.PlayerVaults;
|
||||||
import com.drtshock.playervaults.util.EconomyOperations;
|
import com.drtshock.playervaults.util.EconomyOperations;
|
||||||
@@ -12,22 +13,27 @@ import com.drtshock.playervaults.util.Lang;
|
|||||||
|
|
||||||
public class VaultOperations {
|
public class VaultOperations {
|
||||||
|
|
||||||
public static boolean checkPerms(CommandSender cs, int number) {
|
/**
|
||||||
if(cs.hasPermission("playervaults.amount." + String.valueOf(number))) return true;
|
* Check whether or not the player has permission to open the requested vault.
|
||||||
|
* @param sender The person to check.
|
||||||
|
* @param number The vault number.
|
||||||
|
* @return Whether or not they have permission.
|
||||||
|
*/
|
||||||
|
public static boolean checkPerms(CommandSender sender, int number) {
|
||||||
|
if (sender.hasPermission("playervaults.amount." + String.valueOf(number))) return true;
|
||||||
for(int x = number; x <= 99; x++) {
|
for(int x = number; x <= 99; x++) {
|
||||||
if(cs.hasPermission("playervaults.amount." + String.valueOf(x))) return true;
|
if (sender.hasPermission("playervaults.amount." + String.valueOf(x))) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a player's own vault.
|
* Open a player's own vault.
|
||||||
* Return true if allowed. Otherwise false.
|
* @param player The player to open to.
|
||||||
* @param Sender sender
|
* @param arg The vault number to open.
|
||||||
* @param String arg
|
* @return Whether or not the player was allowed to open it.
|
||||||
* @return success
|
|
||||||
*/
|
*/
|
||||||
public static boolean openOwnVault(Player sender, String arg) {
|
public static boolean openOwnVault(Player player, String arg) {
|
||||||
if (arg.matches("^[0-9]{1,2}$")) {
|
if (arg.matches("^[0-9]{1,2}$")) {
|
||||||
int number = 0;
|
int number = 0;
|
||||||
try {
|
try {
|
||||||
@@ -35,37 +41,37 @@ public class VaultOperations {
|
|||||||
if (number == 0)
|
if (number == 0)
|
||||||
return false;
|
return false;
|
||||||
} catch(NumberFormatException nfe) {
|
} catch(NumberFormatException nfe) {
|
||||||
sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
|
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(checkPerms(sender, number)) {
|
if (checkPerms(player, number)) {
|
||||||
if(EconomyOperations.payToOpen(sender)) {
|
if (EconomyOperations.payToOpen(player)) {
|
||||||
PlayerVaults.VM.loadVault(sender, sender.getName(), number);
|
Inventory inv = PlayerVaults.VM.loadVault(player.getName(), number);
|
||||||
sender.sendMessage(Lang.TITLE.toString() + Lang.OPEN_VAULT.toString().replace("%v", arg));
|
player.openInventory(inv);
|
||||||
|
player.sendMessage(Lang.TITLE.toString() + Lang.OPEN_VAULT.toString().replace("%v", arg));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(Lang.TITLE.toString() + Lang.INSUFFICIENT_FUNDS);
|
player.sendMessage(Lang.TITLE.toString() + Lang.INSUFFICIENT_FUNDS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Feedback.noPerms(sender);
|
player.sendMessage(Lang.TITLE.toString() + Lang.NO_PERMS);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(Lang.TITLE.toString() + Lang.MUST_BE_NUMBER);
|
player.sendMessage(Lang.TITLE.toString() + Lang.MUST_BE_NUMBER);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open another player's vault.
|
* Open another player's vault.
|
||||||
* Return true if allowed. Otherwise false.
|
* @param player The player to open to.
|
||||||
* @param Sender sender
|
* @param user The user to whom the requested vault belongs.
|
||||||
* @param String user
|
* @param arg The vault number to open.
|
||||||
* @param String arg
|
* @return Whether or not the player was allowed to open it.
|
||||||
* @return success
|
|
||||||
*/
|
*/
|
||||||
public static boolean openOtherVault(Player sender, String user, String arg) {
|
public static boolean openOtherVault(Player player, String user, String arg) {
|
||||||
if(sender.hasPermission("playervaults.admin")) {
|
if (player.hasPermission("playervaults.admin")) {
|
||||||
if (arg.matches("^[0-9]{1,2}$")) {
|
if (arg.matches("^[0-9]{1,2}$")) {
|
||||||
int number = 0;
|
int number = 0;
|
||||||
try {
|
try {
|
||||||
@@ -73,26 +79,27 @@ public class VaultOperations {
|
|||||||
if (number == 0)
|
if (number == 0)
|
||||||
return false;
|
return false;
|
||||||
} catch(NumberFormatException nfe) {
|
} catch(NumberFormatException nfe) {
|
||||||
sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
|
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
|
||||||
}
|
}
|
||||||
PlayerVaults.VM.loadVault(sender, user, number);
|
Inventory inv = PlayerVaults.VM.loadVault(user, number);
|
||||||
sender.sendMessage(Lang.TITLE.toString() + Lang.OPEN_OTHER_VAULT.toString().replace("%v", arg).replace("%p", user));
|
player.openInventory(inv);
|
||||||
|
player.sendMessage(Lang.TITLE.toString() + Lang.OPEN_OTHER_VAULT.toString().replace("%v", arg).replace("%p", user));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(Lang.TITLE.toString() + Lang.MUST_BE_NUMBER);
|
player.sendMessage(Lang.TITLE.toString() + Lang.MUST_BE_NUMBER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Feedback.noPerms(sender);
|
player.sendMessage(Lang.TITLE.toString() + Lang.NO_PERMS);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a player's own vault.
|
* Delete a player's own vault.
|
||||||
* Return true if allowed. Otherwise false.
|
* @param player The player to delete.
|
||||||
* @param Sender sender
|
* @param user The user to whom the deleted vault belongs.
|
||||||
* @param String arg
|
* @param arg The vault number to delete.
|
||||||
*/
|
*/
|
||||||
public static void deleteOwnVault(Player sender, String arg) {
|
public static void deleteOwnVault(Player sender, String arg) {
|
||||||
if (arg.matches("^[0-9]{1,2}$")) {
|
if (arg.matches("^[0-9]{1,2}$")) {
|
||||||
@@ -119,11 +126,10 @@ public class VaultOperations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete another player's vault.
|
* Delete a player's own vault.
|
||||||
* Return true if allowed. Otherwise false.
|
* @param player The player to delete.
|
||||||
* @param Sender sender
|
* @param user The user to whom the deleted vault belongs.
|
||||||
* @param String user
|
* @param arg The vault number to delete.
|
||||||
* @param String arg
|
|
||||||
*/
|
*/
|
||||||
public static void deleteOtherVault(CommandSender sender, String user, String arg) {
|
public static void deleteOtherVault(CommandSender sender, String user, String arg) {
|
||||||
if (sender.hasPermission("playervaults.delete")) {
|
if (sender.hasPermission("playervaults.delete")) {
|
||||||
@@ -147,7 +153,9 @@ public class VaultOperations {
|
|||||||
sender.sendMessage(Lang.TITLE.toString() + Lang.MUST_BE_NUMBER);
|
sender.sendMessage(Lang.TITLE.toString() + Lang.MUST_BE_NUMBER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else Feedback.noPerms(sender);
|
else {
|
||||||
|
sender.sendMessage(Lang.TITLE.toString() + Lang.NO_PERMS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,43 @@
|
|||||||
package com.drtshock.playervaults.commands;
|
package com.drtshock.playervaults.commands;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class that stores information about a vault viewing including the holder of the vault,
|
||||||
|
* and the vault number.
|
||||||
|
*/
|
||||||
public class VaultViewInfo {
|
public class VaultViewInfo {
|
||||||
|
|
||||||
String s;
|
String holder;
|
||||||
int i;
|
int number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make a VaultViewObject
|
||||||
|
* @param s The holder of the vault.
|
||||||
|
* @param i The vault number.
|
||||||
|
*/
|
||||||
public VaultViewInfo(String s, int i) {
|
public VaultViewInfo(String s, int i) {
|
||||||
this.s = s;
|
this.holder = s;
|
||||||
this.i = i;
|
this.number = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the holder of the vault.
|
||||||
|
* @return The holder of the vault.
|
||||||
|
*/
|
||||||
public String getHolder() {
|
public String getHolder() {
|
||||||
return this.s;
|
return this.holder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the vault number.
|
||||||
|
* @return The vault number.
|
||||||
|
*/
|
||||||
public int getNumber() {
|
public int getNumber() {
|
||||||
return this.i;
|
return this.number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.s + " " + this.i;
|
return this.holder + " " + this.number;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,25 +7,19 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
|
|
||||||
import com.drtshock.playervaults.PlayerVaults;
|
import com.drtshock.playervaults.PlayerVaults;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class that contains a method to drop the contents of a player's vault when they die.
|
||||||
|
*/
|
||||||
public class DropOnDeath {
|
public class DropOnDeath {
|
||||||
|
|
||||||
public static PlayerVaults PLUGIN;
|
|
||||||
|
|
||||||
public DropOnDeath(PlayerVaults instance) {
|
|
||||||
DropOnDeath.PLUGIN = instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
static VaultManager VAULT_MANAGER = new VaultManager(PLUGIN);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drops all items when a player dies.
|
* Drops all items when a player dies.
|
||||||
* @param player
|
* @param player The player to drop the inventory of.
|
||||||
*/
|
*/
|
||||||
public static void drop(Player player) {
|
public static void drop(Player player) {
|
||||||
Location loc = player.getLocation();
|
Location loc = player.getLocation();
|
||||||
|
|
||||||
for(int count = 1; count <= PlayerVaults.INVENTORIES_TO_DROP; count++) {
|
for(int count = 1; count <= PlayerVaults.INVENTORIES_TO_DROP; count++) {
|
||||||
Inventory inv = VAULT_MANAGER.getVault(player, count);
|
Inventory inv = PlayerVaults.VM.getVault(player.getName(), count);
|
||||||
ItemStack[] stack = inv.getContents();
|
ItemStack[] stack = inv.getContents();
|
||||||
for(ItemStack is:stack) {
|
for(ItemStack is:stack) {
|
||||||
loc.getWorld().dropItemNaturally(loc, is);
|
loc.getWorld().dropItemNaturally(loc, is);
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import com.drtshock.playervaults.PlayerVaults;
|
import com.drtshock.playervaults.PlayerVaults;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class that handles all economy operations.
|
||||||
|
*/
|
||||||
public class EconomyOperations {
|
public class EconomyOperations {
|
||||||
|
|
||||||
private static File CONFIG_FILE;
|
private static File CONFIG_FILE;
|
||||||
@@ -28,9 +31,8 @@ public class EconomyOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Have a player pay to open a vault.
|
* Have a player pay to open a vault.
|
||||||
* Returns true if successful. Otherwise false.
|
* @param player The player to pay.
|
||||||
* @param player
|
* @return The transaction success.
|
||||||
* @return transaction success
|
|
||||||
*/
|
*/
|
||||||
public static boolean payToOpen(Player player) {
|
public static boolean payToOpen(Player player) {
|
||||||
if (!BUKKIT_CONFIG.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !PlayerVaults.USE_VAULT)
|
if (!BUKKIT_CONFIG.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !PlayerVaults.USE_VAULT)
|
||||||
@@ -48,9 +50,8 @@ public class EconomyOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Have a player pay to create a vault.
|
* Have a player pay to create a vault.
|
||||||
* Returns true if successful. Otherwise false.
|
* @param player The player to pay.
|
||||||
* @param player
|
* @return The transaction success
|
||||||
* @return transaction success
|
|
||||||
*/
|
*/
|
||||||
public static boolean payToCreate(Player player) {
|
public static boolean payToCreate(Player player) {
|
||||||
if (!BUKKIT_CONFIG.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !PlayerVaults.USE_VAULT)
|
if (!BUKKIT_CONFIG.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !PlayerVaults.USE_VAULT)
|
||||||
@@ -68,15 +69,14 @@ public class EconomyOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Have a player get his money back when vault is deleted.
|
* Have a player get his money back when vault is deleted.
|
||||||
* Returns true if successful. Otherwise false.
|
* @param player The player to receive the money.
|
||||||
* @param player
|
* @return The transaction success.
|
||||||
* @return transaction success.
|
|
||||||
*/
|
*/
|
||||||
public static boolean refundOnDelete(Player player, int number) {
|
public static boolean refundOnDelete(Player player, int number) {
|
||||||
String directory = "plugins" + File.separator + "PlayerVaults" + File.separator + "vaults";
|
String directory = "plugins" + File.separator + "PlayerVaults" + File.separator + "vaults";
|
||||||
|
if (!BUKKIT_CONFIG.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !PlayerVaults.USE_VAULT) {
|
||||||
if(!BUKKIT_CONFIG.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !PlayerVaults.USE_VAULT)
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
String name = player.getName().toLowerCase();
|
String name = player.getName().toLowerCase();
|
||||||
File file = new File(directory + File.separator + name.toLowerCase() + ".yml");
|
File file = new File(directory + File.separator + name.toLowerCase() + ".yml");
|
||||||
YamlConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
|
YamlConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ package com.drtshock.playervaults.util;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An enum for requesting strings from the language file.
|
||||||
|
*/
|
||||||
public enum Lang {
|
public enum Lang {
|
||||||
TITLE("title-name", "&4[&fPlayerVaults&4]:"),
|
TITLE("title-name", "&4[&fPlayerVaults&4]:"),
|
||||||
OPEN_VAULT("open-vault", "&fOpening vault &a%v"),
|
OPEN_VAULT("open-vault", "&fOpening vault &a%v"),
|
||||||
@@ -26,16 +29,25 @@ public enum Lang {
|
|||||||
OPEN_WITH_SIGN("open-with-sign", "&fOpening vault &a%v &fof &a%p");
|
OPEN_WITH_SIGN("open-with-sign", "&fOpening vault &a%v &fof &a%p");
|
||||||
|
|
||||||
private String path;
|
private String path;
|
||||||
private String def; // Default string
|
private String def;
|
||||||
private static YamlConfiguration LANG;
|
private static YamlConfiguration LANG;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lang enum constructor.
|
||||||
|
* @param path The string path.
|
||||||
|
* @param start The default string.
|
||||||
|
*/
|
||||||
Lang(String path, String start) {
|
Lang(String path, String start) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.def = start;
|
this.def = start;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setFile(YamlConfiguration yc) {
|
/**
|
||||||
LANG = yc;
|
* Set the {@code YamlConfiguration} to use.
|
||||||
|
* @param config The config to set.
|
||||||
|
*/
|
||||||
|
public static void setFile(YamlConfiguration config) {
|
||||||
|
LANG = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -45,10 +57,18 @@ public enum Lang {
|
|||||||
return ChatColor.translateAlternateColorCodes('&', LANG.getString(this.path, def));
|
return ChatColor.translateAlternateColorCodes('&', LANG.getString(this.path, def));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the default value of the path.
|
||||||
|
* @return The default value of the path.
|
||||||
|
*/
|
||||||
public String getDefault() {
|
public String getDefault() {
|
||||||
return this.def;
|
return this.def;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the path to the string.
|
||||||
|
* @return The path to the string.
|
||||||
|
*/
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
return this.path;
|
return this.path;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,11 +17,12 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
public class Serialization {
|
/**
|
||||||
|
* Fancy JSON serialization mostly by evilmidget38.
|
||||||
/*
|
* @author evilmidget38, gomeow
|
||||||
* All normal functions
|
*
|
||||||
*/
|
*/
|
||||||
|
public class Serialization {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static Map<String, Object> toMap(JSONObject object) throws JSONException {
|
public static Map<String, Object> toMap(JSONObject object) throws JSONException {
|
||||||
@@ -116,8 +117,6 @@ public class Serialization {
|
|||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
public static ConfigurationSerializable deserialize(Map<String, Object> map) {
|
public static ConfigurationSerializable deserialize(Map<String, Object> map) {
|
||||||
for(Entry<String, Object> entry:map.entrySet()) {
|
for(Entry<String, Object> entry:map.entrySet()) {
|
||||||
// Check if any of its sub-maps are ConfigurationSerializable. They need to be done
|
|
||||||
// first.
|
|
||||||
if (entry.getValue() instanceof Map && ((Map) entry.getValue()).containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
|
if (entry.getValue() instanceof Map && ((Map) entry.getValue()).containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
|
||||||
entry.setValue(deserialize((Map) entry.getValue()));
|
entry.setValue(deserialize((Map) entry.getValue()));
|
||||||
}
|
}
|
||||||
@@ -125,8 +124,4 @@ public class Serialization {
|
|||||||
return ConfigurationSerialization.deserializeObject(map);
|
return ConfigurationSerialization.deserializeObject(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* All old methods for transferring
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
import com.drtshock.playervaults.PlayerVaults;
|
import com.drtshock.playervaults.PlayerVaults;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class for updating the lang.yml and checking for updates at DBO.
|
||||||
|
*/
|
||||||
public class Updater extends PlayerVaults {
|
public class Updater extends PlayerVaults {
|
||||||
|
|
||||||
SortedMap<String, String> lang = new TreeMap<String, String>();
|
SortedMap<String, String> lang = new TreeMap<String, String>();
|
||||||
@@ -35,7 +38,13 @@ public class Updater extends PlayerVaults {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getUpdate(String v) throws IOException {
|
/**
|
||||||
|
* Check whether or not there is a new update.
|
||||||
|
* @param currentVersion The current running version.
|
||||||
|
* @return Whether or not an update is available.
|
||||||
|
* @throws IOException Oh no!
|
||||||
|
*/
|
||||||
|
public boolean getUpdate(String currentVersion) throws IOException {
|
||||||
JSONObject json;
|
JSONObject json;
|
||||||
try {
|
try {
|
||||||
json = getInfo();
|
json = getInfo();
|
||||||
@@ -44,7 +53,7 @@ public class Updater extends PlayerVaults {
|
|||||||
PlayerVaults.NEWVERSION = version;
|
PlayerVaults.NEWVERSION = version;
|
||||||
String goodLink = new BufferedReader(new InputStreamReader(new URL("http://is.gd/create.php?format=simple&url=" + link).openStream())).readLine();
|
String goodLink = new BufferedReader(new InputStreamReader(new URL("http://is.gd/create.php?format=simple&url=" + link).openStream())).readLine();
|
||||||
PlayerVaults.LINK = goodLink;
|
PlayerVaults.LINK = goodLink;
|
||||||
if(!version.equalsIgnoreCase(v)) {
|
if (!version.equalsIgnoreCase(currentVersion)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch(JSONException e) {
|
} catch(JSONException e) {
|
||||||
@@ -53,6 +62,11 @@ public class Updater extends PlayerVaults {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the information about versions from DBO.
|
||||||
|
* @return The information in JSON.
|
||||||
|
* @throws IOException Oh no!
|
||||||
|
*/
|
||||||
public JSONObject getInfo() throws IOException {
|
public JSONObject getInfo() throws IOException {
|
||||||
URL url = new URL("http://api.bukget.org/3/plugins/bukkit/playervaults/latest");
|
URL url = new URL("http://api.bukget.org/3/plugins/bukkit/playervaults/latest");
|
||||||
BufferedReader in = null;
|
BufferedReader in = null;
|
||||||
@@ -67,7 +81,7 @@ public class Updater extends PlayerVaults {
|
|||||||
in.close();
|
in.close();
|
||||||
return json;
|
return json;
|
||||||
} catch(JSONException e) {
|
} catch(JSONException e) {
|
||||||
}
|
throw new IOException("Oh no!");
|
||||||
return null;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,12 +10,14 @@ import org.bukkit.ChatColor;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
import com.drtshock.playervaults.PlayerVaults;
|
import com.drtshock.playervaults.PlayerVaults;
|
||||||
import com.drtshock.playervaults.commands.VaultViewInfo;
|
import com.drtshock.playervaults.commands.VaultViewInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class for managing actual IO to the files, loading inventories, and saving them.
|
||||||
|
*/
|
||||||
public class VaultManager {
|
public class VaultManager {
|
||||||
|
|
||||||
public PlayerVaults plugin;
|
public PlayerVaults plugin;
|
||||||
@@ -23,19 +25,20 @@ public class VaultManager {
|
|||||||
public VaultManager(PlayerVaults instance) {
|
public VaultManager(PlayerVaults instance) {
|
||||||
this.plugin = 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
|
* Saves the inventory to the specified player and vault number.
|
||||||
* vaults.yml
|
* @param inventory The inventory to be saved.
|
||||||
*
|
* @param player The player of whose file to save to.
|
||||||
* @param player
|
* @param number The vault number.
|
||||||
* @throws IOException
|
* @throws IOException Uh oh!
|
||||||
*/
|
*/
|
||||||
public void saveVault(Inventory inv, String player, int number) throws IOException {
|
public void saveVault(Inventory inventory, String player, int number) throws IOException {
|
||||||
YamlConfiguration yaml = playerVaultFile(player);
|
YamlConfiguration yaml = getPlayerVaultFile(player);
|
||||||
yaml.set("vault" + number, null);
|
yaml.set("vault" + number, null);
|
||||||
List<String> list = Serialization.toString(inv);
|
List<String> list = Serialization.toString(inventory);
|
||||||
String[] ser = list.toArray(new String[list.size()]);
|
String[] ser = list.toArray(new String[list.size()]);
|
||||||
for(int x = 0; x < ser.length; x++) {
|
for(int x = 0; x < ser.length; x++) {
|
||||||
if (!ser[x].equalsIgnoreCase("null")) {
|
if (!ser[x].equalsIgnoreCase("null")) {
|
||||||
@@ -46,19 +49,19 @@ public class VaultManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to load player's vault. Deserialize his inventory
|
* Load the player's vault and return it.
|
||||||
*
|
* @param holder The holder of the vault.
|
||||||
* TODO: Check to see if the path exists before we get it!
|
* @param number The vault number.
|
||||||
*/
|
*/
|
||||||
public void loadVault(Player player, String holder, int number) {
|
public Inventory loadVault(String holder, int number) {
|
||||||
VaultViewInfo info = new VaultViewInfo(holder, number);
|
VaultViewInfo info = new VaultViewInfo(holder, number);
|
||||||
Inventory inv = null;
|
Inventory inv = null;
|
||||||
if (PlayerVaults.OPENINVENTORIES.containsKey(info.toString())) {
|
if (PlayerVaults.OPENINVENTORIES.containsKey(info.toString())) {
|
||||||
inv = PlayerVaults.OPENINVENTORIES.get(info.toString());
|
inv = PlayerVaults.OPENINVENTORIES.get(info.toString());
|
||||||
} else {
|
} else {
|
||||||
YamlConfiguration playerFile = playerVaultFile(holder);
|
YamlConfiguration playerFile = getPlayerVaultFile(holder);
|
||||||
if (playerFile.getConfigurationSection("vault" + number) == null) {
|
if (playerFile.getConfigurationSection("vault" + number) == null) {
|
||||||
inv = Bukkit.createInventory(player, 54, ChatColor.DARK_RED + "Vault #" + String.valueOf(number));
|
inv = Bukkit.createInventory(null, 54, ChatColor.DARK_RED + "Vault #" + String.valueOf(number));
|
||||||
} else {
|
} else {
|
||||||
List<String> data = new ArrayList<String>();
|
List<String> data = new ArrayList<String>();
|
||||||
for(int x = 0; x < 54; x++) {
|
for(int x = 0; x < 54; x++) {
|
||||||
@@ -73,22 +76,20 @@ public class VaultManager {
|
|||||||
}
|
}
|
||||||
PlayerVaults.OPENINVENTORIES.put(info.toString(), inv);
|
PlayerVaults.OPENINVENTORIES.put(info.toString(), inv);
|
||||||
}
|
}
|
||||||
player.openInventory(inv);
|
return inv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an inventory without opening it. Used for dropping a players
|
* Gets an inventory without storing references to it. Used for dropping a players inventories on death.
|
||||||
* inventories on death.
|
* @param holder The holder of the vault.
|
||||||
*
|
* @param number The vault number.
|
||||||
* @param player
|
* @return The inventory of the specified holder and vault number.
|
||||||
* @param number
|
|
||||||
* @return the inventory
|
|
||||||
*/
|
*/
|
||||||
public Inventory getVault(Player player, int number) {
|
public Inventory getVault(String holder, int number) {
|
||||||
YamlConfiguration playerFile = playerVaultFile(player.getName());
|
YamlConfiguration playerFile = getPlayerVaultFile(holder);
|
||||||
List<String> data = playerFile.getStringList("vault" + number);
|
List<String> data = playerFile.getStringList("vault" + number);
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
Inventory inv = Bukkit.createInventory(player, 54, ChatColor.GREEN + "Vault #" + String.valueOf(number));
|
Inventory inv = Bukkit.createInventory(null, 54, ChatColor.GREEN + "Vault #" + String.valueOf(number));
|
||||||
return inv;
|
return inv;
|
||||||
} else {
|
} else {
|
||||||
Inventory inv = Serialization.toInventory(data, number);
|
Inventory inv = Serialization.toInventory(data, number);
|
||||||
@@ -98,43 +99,42 @@ public class VaultManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a players vault.
|
* Deletes a players vault.
|
||||||
*
|
* @param sender The sender of whom to send messages to.
|
||||||
* @param sender
|
* @param holder The vault holder.
|
||||||
* @param target
|
* @param number The vault number.
|
||||||
* @param number
|
* @throws IOException Uh oh!
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
public void deleteVault(CommandSender sender, String target, int number) throws IOException {
|
public void deleteVault(CommandSender sender, String holder, int number) throws IOException {
|
||||||
String name = target.toLowerCase();
|
String name = holder.toLowerCase();
|
||||||
File file = new File(directory + File.separator + name.toLowerCase() + ".yml");
|
File file = new File(directory + File.separator + name.toLowerCase() + ".yml");
|
||||||
FileConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
|
FileConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
playerFile.set("vault" + number, null);
|
playerFile.set("vault" + number, null);
|
||||||
playerFile.save(file);
|
playerFile.save(file);
|
||||||
}
|
}
|
||||||
if (sender.getName().equalsIgnoreCase(target)) {
|
if (sender.getName().equalsIgnoreCase(holder)) {
|
||||||
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT.toString().replace("%v", String.valueOf(number)));
|
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT.toString().replace("%v", String.valueOf(number)));
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_OTHER_VAULT.toString().replace("%v", String.valueOf(number)).replace("%p", target));
|
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_OTHER_VAULT.toString().replace("%v", String.valueOf(number)).replace("%p", holder));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the player's vault file. Create if doesn't exist.
|
* Get the holder's vault file. Create if doesn't exist.
|
||||||
*
|
* @param holder The vault holder.
|
||||||
* @param player
|
* @return The holder's vault config file.
|
||||||
* @return playerVaultFile file.
|
|
||||||
*/
|
*/
|
||||||
public YamlConfiguration playerVaultFile(String player) {
|
public YamlConfiguration getPlayerVaultFile(String holder) {
|
||||||
File folder = new File(directory);
|
File folder = new File(directory);
|
||||||
if (!folder.exists()) {
|
if (!folder.exists()) {
|
||||||
folder.mkdir();
|
folder.mkdir();
|
||||||
}
|
}
|
||||||
File file = new File(directory + File.separator + player.toLowerCase() + ".yml");
|
File file = new File(directory + File.separator + holder.toLowerCase() + ".yml");
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
try {
|
try {
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
|
// Who cares?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
YamlConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
|
YamlConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
|
||||||
@@ -143,15 +143,14 @@ public class VaultManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the players vault file.
|
* Save the players vault file.
|
||||||
*
|
* @param holder The vault holder of whose file to save.
|
||||||
* @param name
|
* @param yaml The config to save.
|
||||||
* @param yaml
|
* @throws IOException Uh oh!
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
public void saveFile(String name, YamlConfiguration yaml) throws IOException {
|
public void saveFile(String holder, YamlConfiguration yaml) throws IOException {
|
||||||
File file = new File(directory + File.separator + name.toLowerCase() + ".yml");
|
File file = new File(directory + File.separator + holder.toLowerCase() + ".yml");
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
file.renameTo(new File(directory + File.separator + "backups" + File.separator + name.toLowerCase() + ".yml"));
|
file.renameTo(new File(directory + File.separator + "backups" + File.separator + holder.toLowerCase() + ".yml"));
|
||||||
}
|
}
|
||||||
yaml.save(file);
|
yaml.save(file);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package org.json;
|
|||||||
* @version 2010-12-24
|
* @version 2010-12-24
|
||||||
*/
|
*/
|
||||||
public class JSONException extends Exception {
|
public class JSONException extends Exception {
|
||||||
|
|
||||||
private static final long serialVersionUID = 0;
|
private static final long serialVersionUID = 0;
|
||||||
private Throwable cause;
|
private Throwable cause;
|
||||||
|
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ import java.util.Set;
|
|||||||
* @version 2012-12-01
|
* @version 2012-12-01
|
||||||
*/
|
*/
|
||||||
public class JSONObject {
|
public class JSONObject {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum number of keys in the key pool.
|
* The maximum number of keys in the key pool.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ package org.json;
|
|||||||
* of using the Object's <code>toString()</code> method and quoting the result.
|
* of using the Object's <code>toString()</code> method and quoting the result.
|
||||||
*/
|
*/
|
||||||
public interface JSONString {
|
public interface JSONString {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The <code>toJSONString</code> method allows a class to produce its own JSON
|
* The <code>toJSONString</code> method allows a class to produce its own JSON
|
||||||
* serialization.
|
* serialization.
|
||||||
|
|||||||
Reference in New Issue
Block a user