Use proper conventions.
This commit is contained in:
@@ -27,10 +27,10 @@ import com.drtshock.playervaults.util.VaultManager;
|
||||
|
||||
public class Listeners implements Listener {
|
||||
|
||||
public Main plugin;
|
||||
public PlayerVaults plugin;
|
||||
|
||||
public Listeners(Main instance) {
|
||||
this.plugin = instance;
|
||||
public Listeners(PlayerVaults playerVaults) {
|
||||
this.plugin = playerVaults;
|
||||
}
|
||||
|
||||
VaultManager vm = new VaultManager(plugin);
|
||||
@@ -41,15 +41,15 @@ public class Listeners implements Listener {
|
||||
* @param Player p
|
||||
*/
|
||||
public void saveVault(Player p) {
|
||||
if(Commands.inVault.containsKey(p.getName())) {
|
||||
if(Commands.IN_VAULT.containsKey(p.getName())) {
|
||||
Inventory inv = p.getOpenInventory().getTopInventory();
|
||||
VaultViewInfo info = Commands.inVault.get(p.getName());
|
||||
VaultViewInfo info = Commands.IN_VAULT.get(p.getName());
|
||||
try {
|
||||
vm.saveVault(inv, info.getHolder(), info.getNumber());
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Commands.inVault.remove(p.getName());
|
||||
Commands.IN_VAULT.remove(p.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,8 +68,8 @@ public class Listeners implements Listener {
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
vm.playerVaultFile(player.getName());
|
||||
if(player.isOp() && Main.update) {
|
||||
player.sendMessage(ChatColor.GREEN + "Version " + Main.name + " of PlayerVaults is up for download!");
|
||||
if(player.isOp() && PlayerVaults.UPDATE) {
|
||||
player.sendMessage(ChatColor.GREEN + "Version " + PlayerVaults.NAME + " of PlayerVaults is up for download!");
|
||||
player.sendMessage(ChatColor.GREEN + "http://dev.bukkit.org/server-mods/playervaults/ to view the changelog and download!");
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class Listeners implements Listener {
|
||||
public void onDeath(PlayerDeathEvent event) {
|
||||
Player player = event.getEntity();
|
||||
saveVault(player);
|
||||
if(Main.dropOnDeath && (!player.hasPermission("playervaults.ignore.drops"))) {
|
||||
if(PlayerVaults.DROP_ON_DEATH && (!player.hasPermission("playervaults.ignore.drops"))) {
|
||||
DropOnDeath.drop(event.getEntity());
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@ public class Listeners implements Listener {
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if(Commands.inVault.containsKey(player.getName()) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
if(Commands.IN_VAULT.containsKey(player.getName()) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Block block = event.getClickedBlock();
|
||||
|
||||
/**
|
||||
@@ -127,7 +127,7 @@ public class Listeners implements Listener {
|
||||
public void onInteractEntity(PlayerInteractEntityEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
EntityType type = event.getRightClicked().getType();
|
||||
if((type == EntityType.VILLAGER || type == EntityType.MINECART) && Commands.inVault.containsKey(player.getName())) {
|
||||
if((type == EntityType.VILLAGER || type == EntityType.MINECART) && Commands.IN_VAULT.containsKey(player.getName())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
+23
-23
@@ -17,20 +17,20 @@ import com.drtshock.playervaults.util.Lang;
|
||||
import com.drtshock.playervaults.util.Metrics;
|
||||
import com.drtshock.playervaults.util.Updater;
|
||||
|
||||
public class Main extends JavaPlugin {
|
||||
public class PlayerVaults extends JavaPlugin {
|
||||
|
||||
public static Main plugin;
|
||||
public static PlayerVaults PLUGIN;
|
||||
public Logger log;
|
||||
public static boolean update = false;
|
||||
public static String name = "";
|
||||
public static boolean UPDATE = false;
|
||||
public static String NAME = "";
|
||||
Commands commands;
|
||||
public static Economy econ = null;
|
||||
public static boolean dropOnDeath = false;
|
||||
public static int inventoriesToDrop = 0;
|
||||
public static boolean useVault = false;
|
||||
public static YamlConfiguration lang;
|
||||
public static File langFile;
|
||||
public static String directory = "plugins" + File.separator + "PlayerVaults" + File.separator + "vaults";
|
||||
public static Economy ECON = null;
|
||||
public static boolean DROP_ON_DEATH = false;
|
||||
public static int INVENTORIES_TO_DROP = 0;
|
||||
public static boolean USE_VAULT = false;
|
||||
public static YamlConfiguration LANG;
|
||||
public static File LANG_FILE;
|
||||
public static String DIRECTORY = "plugins" + File.separator + "PlayerVaults" + File.separator + "vaults";
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@@ -43,8 +43,8 @@ public class Main extends JavaPlugin {
|
||||
if(getConfig().getBoolean("check-update")) {
|
||||
try {
|
||||
if(u.getUpdate()) {
|
||||
update = true;
|
||||
name = u.getNewVersion();
|
||||
UPDATE = true;
|
||||
NAME = u.getNewVersion();
|
||||
}
|
||||
} catch(Exception e) {
|
||||
log.log(Level.WARNING, "PlayerVaults: Failed to check for updates.");
|
||||
@@ -60,11 +60,11 @@ public class Main extends JavaPlugin {
|
||||
setupEconomy();
|
||||
|
||||
if(getConfig().getBoolean("drop-on-death.enabled")) {
|
||||
dropOnDeath = true;
|
||||
inventoriesToDrop = getConfig().getInt("drop-on-death.inventories");
|
||||
DROP_ON_DEATH = true;
|
||||
INVENTORIES_TO_DROP = getConfig().getInt("drop-on-death.inventories");
|
||||
}
|
||||
|
||||
new File(directory + File.separator + "backups").mkdirs();
|
||||
new File(DIRECTORY + File.separator + "backups").mkdirs();
|
||||
|
||||
}
|
||||
|
||||
@@ -85,9 +85,9 @@ public class Main extends JavaPlugin {
|
||||
if(rsp == null) {
|
||||
return false;
|
||||
}
|
||||
econ = rsp.getProvider();
|
||||
useVault = true;
|
||||
return econ != null;
|
||||
ECON = rsp.getProvider();
|
||||
USE_VAULT = true;
|
||||
return ECON != null;
|
||||
}
|
||||
|
||||
public void loadConfig() {
|
||||
@@ -150,16 +150,16 @@ public class Main extends JavaPlugin {
|
||||
}
|
||||
YamlConfiguration conf = YamlConfiguration.loadConfiguration(lang);
|
||||
Lang.setFile(conf);
|
||||
Main.lang = conf;
|
||||
Main.langFile = lang;
|
||||
PlayerVaults.LANG = conf;
|
||||
PlayerVaults.LANG_FILE = lang;
|
||||
return conf;
|
||||
}
|
||||
|
||||
public YamlConfiguration getLang() {
|
||||
return lang;
|
||||
return LANG;
|
||||
}
|
||||
|
||||
public File getLangFile() {
|
||||
return langFile;
|
||||
return LANG_FILE;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import com.drtshock.playervaults.util.Lang;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
public static HashMap<String, VaultViewInfo> inVault = new HashMap<String, VaultViewInfo>();
|
||||
public static HashMap<String, VaultViewInfo> IN_VAULT = new HashMap<String, VaultViewInfo>();
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
@@ -25,11 +25,11 @@ public class Commands implements CommandExecutor {
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
if(VaultOperations.openOwnVault(p, args[0]))
|
||||
inVault.put(sender.getName(), new VaultViewInfo(sender.getName(), Integer.parseInt(args[0])));
|
||||
IN_VAULT.put(sender.getName(), new VaultViewInfo(sender.getName(), Integer.parseInt(args[0])));
|
||||
break;
|
||||
case 2:
|
||||
if(VaultOperations.openOtherVault(p, args[0], args[1]))
|
||||
inVault.put(sender.getName(), new VaultViewInfo(args[0], Integer.parseInt(args[1])));
|
||||
IN_VAULT.put(sender.getName(), new VaultViewInfo(args[0], Integer.parseInt(args[1])));
|
||||
break;
|
||||
default:
|
||||
Feedback.showHelp(sender, Feedback.Type.OPEN);
|
||||
|
||||
@@ -6,15 +6,15 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.drtshock.playervaults.Main;
|
||||
import com.drtshock.playervaults.PlayerVaults;
|
||||
import com.drtshock.playervaults.util.EconomyOperations;
|
||||
import com.drtshock.playervaults.util.Lang;
|
||||
import com.drtshock.playervaults.util.VaultManager;
|
||||
|
||||
public class VaultOperations {
|
||||
|
||||
private static Main plugin;
|
||||
private static VaultManager vm = new VaultManager(plugin);
|
||||
private static PlayerVaults PLUGIN;
|
||||
private static VaultManager VAULT_MANAGER = new VaultManager(PLUGIN);
|
||||
|
||||
public static boolean checkPerms(CommandSender cs, int number) {
|
||||
if(cs.hasPermission("playervaults.amount." + String.valueOf(number))) return true;
|
||||
@@ -44,7 +44,7 @@ public class VaultOperations {
|
||||
}
|
||||
if(checkPerms(sender, number)) {
|
||||
if(EconomyOperations.payToOpen(sender)) {
|
||||
vm.loadVault(sender, sender.getName(), number);
|
||||
VAULT_MANAGER.loadVault(sender, sender.getName(), number);
|
||||
sender.sendMessage(Lang.TITLE.toString() + Lang.OPEN_VAULT.toString().replace("%v", arg));
|
||||
return true;
|
||||
} else {
|
||||
@@ -79,7 +79,7 @@ public class VaultOperations {
|
||||
} catch(NumberFormatException nfe) {
|
||||
sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
|
||||
}
|
||||
vm.loadVault(sender, user, number);
|
||||
VAULT_MANAGER.loadVault(sender, user, number);
|
||||
sender.sendMessage(Lang.TITLE.toString() + Lang.OPEN_OTHER_VAULT.toString().replace("%v", arg).replace("%p", user));
|
||||
return true;
|
||||
} else {
|
||||
@@ -111,7 +111,7 @@ public class VaultOperations {
|
||||
}
|
||||
try {
|
||||
if(EconomyOperations.refundOnDelete(sender, number)) {
|
||||
vm.deleteVault(sender, sender.getName(), number);
|
||||
VAULT_MANAGER.deleteVault(sender, sender.getName(), number);
|
||||
return;
|
||||
}
|
||||
} catch(IOException e) {
|
||||
@@ -143,7 +143,7 @@ public class VaultOperations {
|
||||
sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
|
||||
}
|
||||
try {
|
||||
vm.deleteVault(sender, user, number);
|
||||
VAULT_MANAGER.deleteVault(sender, user, number);
|
||||
} catch(IOException e) {
|
||||
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT_ERROR);
|
||||
}
|
||||
|
||||
@@ -5,17 +5,17 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.drtshock.playervaults.Main;
|
||||
import com.drtshock.playervaults.PlayerVaults;
|
||||
|
||||
public class DropOnDeath {
|
||||
|
||||
public static Main plugin;
|
||||
public static PlayerVaults PLUGIN;
|
||||
|
||||
public DropOnDeath(Main instance) {
|
||||
DropOnDeath.plugin = instance;
|
||||
public DropOnDeath(PlayerVaults instance) {
|
||||
DropOnDeath.PLUGIN = instance;
|
||||
}
|
||||
|
||||
static VaultManager vm = new VaultManager(plugin);
|
||||
static VaultManager VAULT_MANAGER = new VaultManager(PLUGIN);
|
||||
|
||||
/**
|
||||
* Drops all items when a player dies.
|
||||
@@ -24,8 +24,8 @@ public class DropOnDeath {
|
||||
public static void drop(Player player) {
|
||||
Location loc = player.getLocation();
|
||||
|
||||
for(int count = 1; count <= Main.inventoriesToDrop; count++) {
|
||||
Inventory inv = vm.getVault(player, count);
|
||||
for(int count = 1; count <= PlayerVaults.INVENTORIES_TO_DROP; count++) {
|
||||
Inventory inv = VAULT_MANAGER.getVault(player, count);
|
||||
ItemStack[] stack = inv.getContents();
|
||||
for(ItemStack is:stack) {
|
||||
loc.getWorld().dropItemNaturally(loc, is);
|
||||
|
||||
@@ -11,19 +11,19 @@ import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.drtshock.playervaults.Main;
|
||||
import com.drtshock.playervaults.PlayerVaults;
|
||||
|
||||
public class EconomyOperations {
|
||||
|
||||
private static File configFile;
|
||||
private static YamlConfiguration bukkitConfig = new YamlConfiguration();
|
||||
private static File CONFIG_FILE;
|
||||
private static YamlConfiguration BUKKIT_CONFIG = new YamlConfiguration();
|
||||
|
||||
public static Main plugin;
|
||||
public static PlayerVaults PLUGIN;
|
||||
|
||||
public EconomyOperations(Main instance) throws FileNotFoundException, IOException, InvalidConfigurationException {
|
||||
plugin = instance;
|
||||
configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||
bukkitConfig.load(configFile);
|
||||
public EconomyOperations(PlayerVaults instance) throws FileNotFoundException, IOException, InvalidConfigurationException {
|
||||
PLUGIN = instance;
|
||||
CONFIG_FILE = new File(PLUGIN.getDataFolder(), "config.yml");
|
||||
BUKKIT_CONFIG.load(CONFIG_FILE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,11 +33,11 @@ public class EconomyOperations {
|
||||
* @return transaction success
|
||||
*/
|
||||
public static boolean payToOpen(Player player) {
|
||||
if(!bukkitConfig.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !Main.useVault)
|
||||
if(!BUKKIT_CONFIG.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !PlayerVaults.USE_VAULT)
|
||||
return true;
|
||||
|
||||
double cost = bukkitConfig.getDouble("economy.cost-to-open", 10);
|
||||
EconomyResponse resp = Main.econ.withdrawPlayer(player.getName(), cost);
|
||||
double cost = BUKKIT_CONFIG.getDouble("economy.cost-to-open", 10);
|
||||
EconomyResponse resp = PlayerVaults.ECON.withdrawPlayer(player.getName(), cost);
|
||||
if(resp.transactionSuccess()) {
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.COST_TO_OPEN.toString().replaceAll("%price", "" + cost));
|
||||
return true;
|
||||
@@ -53,11 +53,11 @@ public class EconomyOperations {
|
||||
* @return transaction success
|
||||
*/
|
||||
public static boolean payToCreate(Player player) {
|
||||
if(!bukkitConfig.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !Main.useVault)
|
||||
if(!BUKKIT_CONFIG.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !PlayerVaults.USE_VAULT)
|
||||
return true;
|
||||
|
||||
double cost = bukkitConfig.getDouble("economy.cost-to-create", 100);
|
||||
EconomyResponse resp = Main.econ.withdrawPlayer(player.getName(), cost);
|
||||
double cost = BUKKIT_CONFIG.getDouble("economy.cost-to-create", 100);
|
||||
EconomyResponse resp = PlayerVaults.ECON.withdrawPlayer(player.getName(), cost);
|
||||
if(resp.transactionSuccess()) {
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.COST_TO_CREATE.toString().replaceAll("%price", "" + cost));
|
||||
return true;
|
||||
@@ -75,7 +75,7 @@ public class EconomyOperations {
|
||||
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)
|
||||
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");
|
||||
@@ -90,8 +90,8 @@ public class EconomyOperations {
|
||||
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);
|
||||
double cost = BUKKIT_CONFIG.getDouble("economy.refund-on-delete");
|
||||
EconomyResponse resp = PlayerVaults.ECON.depositPlayer(player.getName(), cost);
|
||||
if(resp.transactionSuccess()) {
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.REFUND_AMOUNT.toString().replaceAll("%price", String.valueOf(cost)));
|
||||
return true;
|
||||
|
||||
@@ -23,7 +23,7 @@ public enum Lang {
|
||||
|
||||
private String path;
|
||||
private String def; // Default string
|
||||
private static YamlConfiguration lang;
|
||||
private static YamlConfiguration LANG;
|
||||
|
||||
Lang(String path, String start) {
|
||||
this.path = path;
|
||||
@@ -31,14 +31,14 @@ public enum Lang {
|
||||
}
|
||||
|
||||
public static void setFile(YamlConfiguration yc) {
|
||||
lang = 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));
|
||||
return ChatColor.translateAlternateColorCodes('&', LANG.getString(this.path, def)) + " ";
|
||||
return ChatColor.translateAlternateColorCodes('&', LANG.getString(this.path, def));
|
||||
}
|
||||
|
||||
public String getDefault() {
|
||||
|
||||
@@ -11,9 +11,9 @@ import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import com.drtshock.playervaults.Main;
|
||||
import com.drtshock.playervaults.PlayerVaults;
|
||||
|
||||
public class Updater extends Main {
|
||||
public class Updater extends PlayerVaults {
|
||||
|
||||
SortedMap<String, String> lang = new TreeMap<String, String>();
|
||||
String version;
|
||||
|
||||
@@ -13,13 +13,13 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import com.drtshock.playervaults.Main;
|
||||
import com.drtshock.playervaults.PlayerVaults;
|
||||
|
||||
public class VaultManager {
|
||||
|
||||
public Main plugin;
|
||||
public PlayerVaults plugin;
|
||||
|
||||
public VaultManager(Main instance) {
|
||||
public VaultManager(PlayerVaults instance) {
|
||||
this.plugin = instance;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user