Plugin loads fine :)
This commit is contained in:
@@ -3,7 +3,6 @@ package me.shock.playervaults;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import me.shock.playervaults.util.Config;
|
||||
import me.shock.playervaults.util.VaultManager;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
@@ -15,9 +14,7 @@ import org.bukkit.entity.Player;
|
||||
public class Commands implements CommandExecutor
|
||||
{
|
||||
|
||||
Main plugin;
|
||||
Config config = new Config();
|
||||
private VaultManager vm = new VaultManager();
|
||||
VaultManager vm = new VaultManager();
|
||||
String pv = ChatColor.DARK_RED + "[" + ChatColor.WHITE + "PlayerVaults" +
|
||||
ChatColor.DARK_RED + "]" + ChatColor.WHITE + ": ";
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package me.shock.playervaults;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import me.shock.playervaults.util.Config;
|
||||
import me.shock.playervaults.util.VaultManager;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
@@ -33,7 +32,6 @@ public class Listeners implements Listener
|
||||
this.plugin = instance;
|
||||
}
|
||||
VaultManager vm = new VaultManager();
|
||||
Config config = new Config();
|
||||
Commands commands = new Commands();
|
||||
|
||||
|
||||
@@ -148,9 +146,6 @@ public class Listeners implements Listener
|
||||
* Storage_minecart and Powered minecart aren't blocks ;)- added to EntityInteractEvent
|
||||
*/
|
||||
|| block.getType() == Material.BURNING_FURNACE
|
||||
//|| block.getType() == Material.STORAGE_MINECART
|
||||
//|| block.getType() == Material.MINECART
|
||||
//|| block.getType() == Material.POWERED_MINECART
|
||||
|| block.getType() == Material.BREWING_STAND
|
||||
|| block.getType() == Material.BEACON)
|
||||
{
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
package me.shock.playervaults;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import me.shock.playervaults.Listeners;
|
||||
import me.shock.playervaults.util.Config;
|
||||
import me.shock.playervaults.util.Metrics;
|
||||
import me.shock.playervaults.util.Updater;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.craftbukkit.libs.jline.internal.Log;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@@ -17,9 +23,9 @@ public class Main extends JavaPlugin {
|
||||
|
||||
public Main plugin;
|
||||
public Logger log;
|
||||
Config config = new Config();
|
||||
public static boolean update = false;
|
||||
public static String name = "";
|
||||
Commands commands = new Commands();
|
||||
|
||||
public void onEnable()
|
||||
{
|
||||
@@ -27,11 +33,11 @@ public class Main extends JavaPlugin {
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
pm.registerEvents(new Listeners(this), this);
|
||||
getCommand("pv").setExecutor(new Commands());
|
||||
config.loadConfig();
|
||||
config.loadLang();
|
||||
loadConfig();
|
||||
loadLang();
|
||||
startMetrics();
|
||||
|
||||
if(config.updateCheck())
|
||||
if(updateCheck())
|
||||
{
|
||||
Updater updater = new Updater(this, "playervaults", this.getFile(), Updater.UpdateType.NO_DOWNLOAD, false);
|
||||
update = updater.getResult() == Updater.UpdateResult.UPDATE_AVAILABLE;
|
||||
@@ -58,4 +64,166 @@ public class Main extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public void loadConfig()
|
||||
{
|
||||
/**
|
||||
* Check to see if there's a config.
|
||||
* If not then create a new one.
|
||||
*/
|
||||
File config = new File(getDataFolder() + File.separator + "config.yml");
|
||||
if(!config.exists())
|
||||
{
|
||||
try{
|
||||
getDataFolder().mkdir();
|
||||
config.createNewFile();
|
||||
} catch (IOException e) {
|
||||
Log.error("[PlayerVaults] Couldn't create config");
|
||||
}
|
||||
/**
|
||||
* Write the config file here.
|
||||
* New, genius way to write it :)
|
||||
*/
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream(new File(getDataFolder() + File.separator + "config.yml"));
|
||||
InputStream is = getResource("config.yml");
|
||||
byte[] linebuffer = new byte[4096];
|
||||
int lineLength = 0;
|
||||
while((lineLength = is.read(linebuffer)) > 0)
|
||||
{
|
||||
fos.write(linebuffer, 0, lineLength);
|
||||
}
|
||||
fos.close();
|
||||
} catch (IOException e) {
|
||||
Log.error("[PlayerVaults] Couldn't write config: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void loadLang()
|
||||
{
|
||||
/**
|
||||
* Check to see if there's a config.
|
||||
* If not then create a new one.
|
||||
*/
|
||||
File lang = new File(getDataFolder() + File.separator + "lang.yml");
|
||||
if(!lang.exists())
|
||||
{
|
||||
try{
|
||||
getDataFolder().mkdir();
|
||||
lang.createNewFile();
|
||||
} catch (IOException e) {
|
||||
Log.error("[PlayerVaults] Couldn't create language file.");
|
||||
}
|
||||
/**
|
||||
* Write the config file here.
|
||||
* New, genius way to write it :)
|
||||
*/
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream(new File(getDataFolder() + File.separator + "lang.yml"));
|
||||
InputStream is = getResource("lang.yml");
|
||||
byte[] linebuffer = new byte[4096];
|
||||
int lineLength = 0;
|
||||
while((lineLength = is.read(linebuffer)) > 0)
|
||||
{
|
||||
fos.write(linebuffer, 0, lineLength);
|
||||
}
|
||||
fos.close();
|
||||
} catch (IOException e) {
|
||||
Log.error("[PlayerVaults] Couldn't write Language file: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private YamlConfiguration lang() {
|
||||
File file = new File(getDataFolder() + "/lang.yml");
|
||||
YamlConfiguration lang = YamlConfiguration.loadConfiguration(file);
|
||||
return lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Methods to get values from the config.
|
||||
* public so any class / plugin can get them.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @return updateCheck
|
||||
*/
|
||||
public boolean updateCheck() {
|
||||
return getConfig().getBoolean("check-update");
|
||||
}
|
||||
|
||||
public boolean debugMode() {
|
||||
return getConfig().getBoolean("debug-mode");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return disabled worlds.
|
||||
*/
|
||||
public List<?> disabledWorlds() {
|
||||
return getConfig().getList("disabled-worlds");
|
||||
}
|
||||
|
||||
/**
|
||||
* Values for the lang.yml
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @return title used in all messages.
|
||||
*/
|
||||
public String title() {
|
||||
return lang().getString("title-name");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string for opening vault.
|
||||
*/
|
||||
public String openVault() {
|
||||
return lang().getString("open-vault");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string for opening someone else's vault.
|
||||
*/
|
||||
public String openOtherVault() {
|
||||
return lang().getString("open-other-vault");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string for invalid args.
|
||||
*/
|
||||
public String invalidArgs() {
|
||||
return lang().getString("invalid-args");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string for deleting a vault.
|
||||
*/
|
||||
public String deleteVault() {
|
||||
return lang().getString("delete-vault");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string for deleting someone else's vault.
|
||||
*/
|
||||
public String deleteOtherVault() {
|
||||
return lang().getString("delete-other-vault");
|
||||
}
|
||||
|
||||
|
||||
public HashMap<?, ?> inVault() {
|
||||
return commands.inVault;
|
||||
}
|
||||
|
||||
public Logger getLog() {
|
||||
return getServer().getLogger();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,191 +0,0 @@
|
||||
package me.shock.playervaults.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import me.shock.playervaults.Main;
|
||||
|
||||
public class Config
|
||||
{
|
||||
|
||||
private Main plugin;
|
||||
|
||||
public void loadConfig()
|
||||
{
|
||||
Logger log = plugin.getServer().getLogger();
|
||||
|
||||
/**
|
||||
* Check to see if there's a config.
|
||||
* If not then create a new one.
|
||||
*/
|
||||
File config = new File(plugin.getDataFolder() + "/config.yml");
|
||||
if(!config.exists())
|
||||
{
|
||||
try{
|
||||
plugin.getDataFolder().mkdir();
|
||||
config.createNewFile();
|
||||
} catch (IOException e) {
|
||||
log.log(Level.SEVERE, "[PlayerVaults] Couldn't create config");
|
||||
}
|
||||
/**
|
||||
* Write the config file here.
|
||||
* New, genius way to write it :)
|
||||
*/
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream(new File(plugin.getDataFolder() + File.separator + "config.yml"));
|
||||
InputStream is = plugin.getResource("config.yml");
|
||||
byte[] linebuffer = new byte[4096];
|
||||
int lineLength = 0;
|
||||
while((lineLength = is.read(linebuffer)) > 0)
|
||||
{
|
||||
fos.write(linebuffer, 0, lineLength);
|
||||
}
|
||||
fos.close();
|
||||
|
||||
log.log(Level.INFO, "[PlayerVaults] Wrote new config");
|
||||
|
||||
} catch (IOException e) {
|
||||
log.log(Level.SEVERE, "[PlayerVaults] Couldn't write config: " + e);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
log.log(Level.INFO, "[PlayerVaults] Config found.");
|
||||
}
|
||||
}
|
||||
|
||||
public void loadLang()
|
||||
{
|
||||
Logger log = plugin.getServer().getLogger();
|
||||
|
||||
/**
|
||||
* Check to see if there's a config.
|
||||
* If not then create a new one.
|
||||
*/
|
||||
File config = new File(plugin.getDataFolder() + "/lang.yml");
|
||||
if(!config.exists())
|
||||
{
|
||||
try{
|
||||
plugin.getDataFolder().mkdir();
|
||||
config.createNewFile();
|
||||
} catch (IOException e) {
|
||||
log.log(Level.SEVERE, "[PlayerVaults] Couldn't create language file.");
|
||||
}
|
||||
/**
|
||||
* Write the config file here.
|
||||
* New, genius way to write it :)
|
||||
*/
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream(new File(plugin.getDataFolder() + File.separator + "config.yml"));
|
||||
InputStream is = plugin.getResource("lang.yml");
|
||||
byte[] linebuffer = new byte[4096];
|
||||
int lineLength = 0;
|
||||
while((lineLength = is.read(linebuffer)) > 0)
|
||||
{
|
||||
fos.write(linebuffer, 0, lineLength);
|
||||
}
|
||||
fos.close();
|
||||
|
||||
log.log(Level.INFO, "[PlayerVaults] Wrote new language file");
|
||||
|
||||
} catch (IOException e) {
|
||||
log.log(Level.SEVERE, "[PlayerVaults] Couldn't write Language file: " + e);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
log.log(Level.INFO, "[PlayerVaults] Language file found.");
|
||||
}
|
||||
}
|
||||
|
||||
private YamlConfiguration lang() {
|
||||
File file = new File(plugin.getDataFolder() + "lang.yml");
|
||||
YamlConfiguration lang = YamlConfiguration.loadConfiguration(file);
|
||||
return lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Methods to get values from the config.
|
||||
* public so any class / plugin can get them.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @return updateCheck
|
||||
*/
|
||||
public boolean updateCheck() {
|
||||
return plugin.getConfig().getBoolean("check-update");
|
||||
}
|
||||
|
||||
public boolean debugMode() {
|
||||
return plugin.getConfig().getBoolean("debug-mode");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return disabled worlds.
|
||||
*/
|
||||
public List<?> disabledWorlds() {
|
||||
return plugin.getConfig().getList("disabled-worlds");
|
||||
}
|
||||
|
||||
/**
|
||||
* Values for the lang.yml
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @return title used in all messages.
|
||||
*/
|
||||
public String title() {
|
||||
return lang().getString("title-name");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string for opening vault.
|
||||
*/
|
||||
public String openVault() {
|
||||
return lang().getString("open-vault");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string for opening someone else's vault.
|
||||
*/
|
||||
public String openOtherVault() {
|
||||
return lang().getString("open-other-vault");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string for invalid args.
|
||||
*/
|
||||
public String invalidArgs() {
|
||||
return lang().getString("invalid-args");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string for deleting a vault.
|
||||
*/
|
||||
public String deleteVault() {
|
||||
return lang().getString("delete-vault");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string for deleting someone else's vault.
|
||||
*/
|
||||
public String deleteOtherVault() {
|
||||
return lang().getString("delete-other-vault");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import me.shock.playervaults.Commands;
|
||||
import me.shock.playervaults.Main;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
@@ -19,8 +18,6 @@ public class VaultManager
|
||||
{
|
||||
|
||||
private Main plugin;
|
||||
Config config = new Config();
|
||||
private Commands commands = new Commands();
|
||||
String title;
|
||||
|
||||
public void checkFile(Player player)
|
||||
@@ -44,7 +41,7 @@ public class VaultManager
|
||||
*/
|
||||
public void saveVault(Inventory inv, Player player, int number) throws IOException
|
||||
{
|
||||
if(commands.inVault.containsKey(player.getName()))
|
||||
if(plugin.inVault().containsKey(player.getName()))
|
||||
{
|
||||
// Get the player's file and serialize the inventory.
|
||||
String name = player.getName().toLowerCase();
|
||||
@@ -54,7 +51,7 @@ public class VaultManager
|
||||
|
||||
// Prepare to save D:
|
||||
playerFile.set("vault" + number + "", ser);
|
||||
if(config.debugMode())
|
||||
if(plugin.debugMode())
|
||||
{
|
||||
plugin.getLogger().log(Level.INFO, "[PlayerVaults] Saved " + " " + number + " for " + player.getName());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user