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