This commit is contained in:
drtshock
2014-01-20 12:22:09 -07:00
parent 0362170e9b
commit 2d6ac31c2c
19 changed files with 660 additions and 641 deletions
@@ -25,18 +25,7 @@ import com.drtshock.playervaults.util.Metrics;
import com.drtshock.playervaults.util.Updater;
import com.drtshock.playervaults.vaultmanagement.VaultManager;
import com.drtshock.playervaults.vaultmanagement.VaultViewInfo;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
@@ -45,6 +34,11 @@ import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.io.*;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
public class PlayerVaults extends JavaPlugin {
public static PlayerVaults PLUGIN;
@@ -94,7 +88,7 @@ public class PlayerVaults extends JavaPlugin {
new File(DIRECTORY + File.separator + "backups").mkdirs();
VM = new VaultManager(this);
if(getConfig().getBoolean("cleanup.enable", false)) {
if (getConfig().getBoolean("cleanup.enable", false)) {
getServer().getScheduler().runTaskAsynchronously(this, new Cleanup(getConfig().getInt("cleanup.lastEdit", 30)));
}
}
@@ -16,12 +16,10 @@
*/
package com.drtshock.playervaults.commands;
import com.drtshock.playervaults.vaultmanagement.VaultOperations;
import com.drtshock.playervaults.vaultmanagement.VaultViewInfo;
import com.drtshock.playervaults.PlayerVaults;
import com.drtshock.playervaults.util.Lang;
import java.util.Set;
import com.drtshock.playervaults.vaultmanagement.VaultOperations;
import com.drtshock.playervaults.vaultmanagement.VaultViewInfo;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -17,8 +17,8 @@
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.
* 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 {
@@ -48,8 +48,7 @@ public class SignSetInfo {
}
/**
* Get whether or not the sign will open their own vault or another
* person's.
* Get whether or not the sign will open their own vault or another person's.
*
* @return Whether or not it is a 'self' sign.
*/
@@ -17,13 +17,10 @@
package com.drtshock.playervaults.listeners;
import com.drtshock.playervaults.PlayerVaults;
import com.drtshock.playervaults.vaultmanagement.VaultOperations;
import com.drtshock.playervaults.vaultmanagement.VaultViewInfo;
import com.drtshock.playervaults.util.Lang;
import com.drtshock.playervaults.vaultmanagement.VaultManager;
import java.io.IOException;
import com.drtshock.playervaults.vaultmanagement.VaultOperations;
import com.drtshock.playervaults.vaultmanagement.VaultViewInfo;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -40,13 +37,11 @@ import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
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.player.*;
import org.bukkit.inventory.Inventory;
import java.io.IOException;
public class Listeners implements Listener {
public PlayerVaults plugin;
@@ -54,6 +49,7 @@ public class Listeners implements Listener {
public Listeners(PlayerVaults playerVaults) {
this.plugin = playerVaults;
}
VaultManager vm = new VaultManager(plugin);
public void saveVault(Player player) {
@@ -203,8 +199,7 @@ public class Listeners implements Listener {
}
/**
* Check if the location given is a sign, and if so, remove it from the
* signs.yml file
* Check if the location given is a sign, and if so, remove it from the signs.yml file
*
* @param location The location to check
*/
@@ -17,11 +17,11 @@ public class Cleanup extends BukkitRunnable {
@Override
public void run() {
File file = new File(PlayerVaults.DIRECTORY);
if(!file.exists()) return;
if (!file.exists()) return;
long time = System.currentTimeMillis();
for(File f : file.listFiles()) {
if(time - f.lastModified() > diff) {
for (File f : file.listFiles()) {
if (time - f.lastModified() > diff) {
f.delete();
PlayerVaults.PLUGIN.getLogger().info("Deleting vault file: " + f.getName());
}
@@ -52,6 +52,7 @@ public enum Lang {
/**
* Lang enum constructor.
*
* @param path The string path.
* @param start The default string.
*/
@@ -62,6 +63,7 @@ public enum Lang {
/**
* Set the {@code YamlConfiguration} to use.
*
* @param config The config to set.
*/
public static void setFile(YamlConfiguration config) {
@@ -77,6 +79,7 @@ public enum Lang {
/**
* Get the default value of the path.
*
* @return The default value of the path.
*/
public String getDefault() {
@@ -85,6 +88,7 @@ public enum Lang {
/**
* Get the path to the string.
*
* @return The path to the string.
*/
public String getPath() {
@@ -34,23 +34,12 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.scheduler.BukkitTask;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.io.*;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.logging.Level;
import java.util.zip.GZIPOutputStream;
@@ -148,6 +137,7 @@ public class Metrics {
* website. Plotters can be added to the graph object returned.
*
* @param name The name of the graph
*
* @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given
*/
public Graph createGraph(final String name) {
@@ -488,6 +478,7 @@ public class Metrics {
* GZip compress a string of bytes
*
* @param input
*
* @return
*/
public static byte[] gzip(String input) {
@@ -529,6 +520,7 @@ public class Metrics {
* @param json
* @param key
* @param value
*
* @throws UnsupportedEncodingException
*/
private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException {
@@ -561,6 +553,7 @@ public class Metrics {
* Escape a string to create a valid JSON string
*
* @param text
*
* @return
*/
private static String escapeJSON(String text) {
@@ -607,6 +600,7 @@ public class Metrics {
* Encode text as UTF-8
*
* @param text the text to encode
*
* @return the encoded text, as UTF-8
*/
private static String urlEncode(final String text) throws UnsupportedEncodingException {
@@ -1,5 +1,11 @@
package com.drtshock.playervaults.util;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
@@ -9,24 +15,18 @@ import java.util.logging.Level;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
/**
* Check dev.bukkit.org to find updates for a given plugin, and download the updates if needed.
* <p/>
* <b>VERY, VERY IMPORTANT</b>: Because there are no standards for adding auto-update toggles in your plugin's config, this system provides NO CHECK WITH YOUR CONFIG to make sure the user has allowed auto-updating.
* <br>
* It is a <b>BUKKIT POLICY</b> that you include a boolean value in your config that prevents the auto-updater from running <b>AT ALL</b>.
* <br>
* If you fail to include this option in your config, your plugin will be <b>REJECTED</b> when you attempt to submit it to dev.bukkit.org.
* <b>VERY, VERY IMPORTANT</b>: Because there are no standards for adding auto-update toggles in your plugin's config,
* this system provides NO CHECK WITH YOUR CONFIG to make sure the user has allowed auto-updating. <br> It is a
* <b>BUKKIT POLICY</b> that you include a boolean value in your config that prevents the auto-updater from running
* <b>AT ALL</b>. <br> If you fail to include this option in your config, your plugin will be <b>REJECTED</b> when you
* attempt to submit it to dev.bukkit.org.
* <p/>
* An example of a good configuration option would be something similar to 'auto-update: true' - if this value is set to false you may NOT run the auto-updater.
* <br>
* If you are unsure about these rules, please read the plugin submission guidelines: http://goo.gl/8iU5l
* An example of a good configuration option would be something similar to 'auto-update: true' - if this value is set to
* false you may NOT run the auto-updater. <br> If you are unsure about these rules, please read the plugin submission
* guidelines: http://goo.gl/8iU5l
*
* @author Gravity
*/
@@ -92,7 +92,8 @@ public class Updater {
*/
FAIL_DBO,
/**
* When running the version check, the file on DBO did not contain the a version in the format 'vVersion' such as 'v1.0'.
* When running the version check, the file on DBO did not contain the a version in the format 'vVersion' such
* as 'v1.0'.
*/
FAIL_NOVERSION,
/**
@@ -130,10 +131,11 @@ public class Updater {
/**
* Initialize the updater
*
* @param plugin The plugin that is checking for an update.
* @param id The dev.bukkit.org id of the project
* @param file The file that the plugin is running from, get this by doing this.getFile() from within your main class.
* @param type Specify the type of update this will be. See {@link UpdateType}
* @param plugin The plugin that is checking for an update.
* @param id The dev.bukkit.org id of the project
* @param file The file that the plugin is running from, get this by doing this.getFile() from within your main
* class.
* @param type Specify the type of update this will be. See {@link UpdateType}
* @param announce True if the program should announce the progress of new updates in console
*/
public Updater(Plugin plugin, int id, File file, Updater.UpdateType type, boolean announce) {
@@ -230,8 +232,8 @@ public class Updater {
}
/**
* As the result of Updater output depends on the thread's completion, it is necessary to wait for the thread to finish
* before allowing anyone to check the result.
* As the result of Updater output depends on the thread's completion, it is necessary to wait for the thread to
* finish before allowing anyone to check the result.
*/
private void waitForThread() {
if (thread != null && thread.isAlive()) {
@@ -378,7 +380,8 @@ public class Updater {
}
/**
* Check if the name of a jar is one of the plugins currently installed, used for extracting the correct files out of a zip.
* Check if the name of a jar is one of the plugins currently installed, used for extracting the correct files out
* of a zip.
*/
private boolean pluginFile(String name) {
for (File file : new File("plugins").listFiles()) {
@@ -390,7 +393,8 @@ public class Updater {
}
/**
* Check to see if the program should continue by evaluation whether the plugin is already updated, or shouldn't be updated
* Check to see if the program should continue by evaluation whether the plugin is already updated, or shouldn't be
* updated
*/
private boolean versionCheck(String title) {
if (type != Updater.UpdateType.NO_VERSION_CHECK) {
@@ -18,17 +18,15 @@ package com.drtshock.playervaults.vaultmanagement;
import com.drtshock.playervaults.PlayerVaults;
import com.drtshock.playervaults.util.Lang;
import java.io.File;
import java.io.IOException;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.ChatColor;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.io.File;
import java.io.IOException;
/**
* A class that handles all economy operations.
*/
@@ -48,6 +46,7 @@ public class EconomyOperations {
*
* @param player The player to pay.
* @param number The vault number to open.
*
* @return The transaction success.
*/
public static boolean payToOpen(Player player, int number) {
@@ -71,6 +70,7 @@ public class EconomyOperations {
* Have a player pay to create a vault.
*
* @param player The player to pay.
*
* @return The transaction success
*/
public static boolean payToCreate(Player player) {
@@ -92,6 +92,7 @@ public class EconomyOperations {
*
* @param player The player to receive the money.
* @param number The vault number to delete.
*
* @return The transaction success.
*/
public static boolean refundOnDelete(Player player, int number) {
@@ -16,13 +16,6 @@
*/
package com.drtshock.playervaults.vaultmanagement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
@@ -33,11 +26,13 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.*;
import java.util.Map.Entry;
/**
* Fancy JSON serialization mostly by evilmidget38.
*
* @author evilmidget38, gomeow
*
*/
public class Serialization {
@@ -20,8 +20,7 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
/**
* Represents a VaultHolder to assist in detection of Player Vaults from other
* plugins.
* Represents a VaultHolder to assist in detection of Player Vaults from other plugins.
*/
public class VaultHolder implements InventoryHolder {
@@ -18,23 +18,20 @@ package com.drtshock.playervaults.vaultmanagement;
import com.drtshock.playervaults.PlayerVaults;
import com.drtshock.playervaults.util.Lang;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
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 java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* A class for managing actual IO to the files, loading inventories, and saving
* them.
* A class for managing actual IO to the files, loading inventories, and saving them.
*/
public class VaultManager {
@@ -43,6 +40,7 @@ public class VaultManager {
public VaultManager(PlayerVaults instance) {
this.plugin = instance;
}
private final String directory = "plugins" + File.separator + "PlayerVaults" + File.separator + "vaults";
/**
@@ -51,6 +49,7 @@ public class VaultManager {
* @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 inventory, String player, int number) throws IOException {
@@ -92,7 +91,7 @@ public class VaultManager {
if (playerFile.getConfigurationSection("vault" + number) == null) {
VaultHolder vaultHolder = new VaultHolder(number);
Player player = Bukkit.getPlayer(holder);
if(player == null) {
if (player == null) {
return null;
}
if (EconomyOperations.payToCreate(player)) {
@@ -145,12 +144,12 @@ public class VaultManager {
}
/**
* Get an inventory from file. Returns null if the inventory doesn't exist.
* SHOULD ONLY BE USED INTERNALLY
* Get an inventory from file. Returns null if the inventory doesn't exist. SHOULD ONLY BE USED INTERNALLY
*
* @param playerFile the YamlConfiguration file.
* @param size the size of the vault.
* @param number the vault number.
*
* @return inventory if exists, otherwise null.
*/
private Inventory getInventory(YamlConfiguration playerFile, int size, int number) {
@@ -167,11 +166,11 @@ public class VaultManager {
}
/**
* Gets an inventory without storing references to it. Used for dropping a
* players inventories on death.
* 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(String holder, int number) {
@@ -199,12 +198,13 @@ public class VaultManager {
* @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 holder, int number) throws IOException {
String name = holder.toLowerCase();
File file = new File(directory + File.separator + name.toLowerCase() + ".yml");
if(!file.exists()) {
if (!file.exists()) {
return;
}
FileConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
@@ -223,6 +223,7 @@ public class VaultManager {
* 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 getPlayerVaultFile(String holder) {
@@ -247,6 +248,7 @@ public class VaultManager {
*
* @param holder The vault holder of whose file to save.
* @param yaml The config to save.
*
* @throws IOException Uh oh!
*/
public void saveFile(String holder, YamlConfiguration yaml) throws IOException {
@@ -18,23 +18,22 @@ package com.drtshock.playervaults.vaultmanagement;
import com.drtshock.playervaults.PlayerVaults;
import com.drtshock.playervaults.util.Lang;
import java.io.IOException;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import java.io.IOException;
public class VaultOperations {
/**
* Check whether or not the player has permission to open the requested
* vault.
* 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) {
@@ -53,8 +52,8 @@ public class VaultOperations {
* Get the max size vault a player is allowed to have.
*
* @param player that is having his permissions checked.
* @return max size as integer. If no max size is set then it will default
* to 54.
*
* @return max size as integer. If no max size is set then it will default to 54.
*/
public static int getMaxVaultSize(Player player) {
if (player == null) {
@@ -73,6 +72,7 @@ public class VaultOperations {
*
* @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 player, String arg) {
@@ -107,6 +107,7 @@ public class VaultOperations {
* @param player The player to open to.
* @param holder 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 player, String holder, String arg) {
@@ -17,8 +17,7 @@
package com.drtshock.playervaults.vaultmanagement;
/**
* A class that stores information about a vault viewing including the holder of
* the vault, and the vault number.
* A class that stores information about a vault viewing including the holder of the vault, and the vault number.
*/
public class VaultViewInfo {