Plugin loads fine :)
This commit is contained in:
@@ -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,14 +18,12 @@ public class VaultManager
|
||||
{
|
||||
|
||||
private Main plugin;
|
||||
Config config = new Config();
|
||||
private Commands commands = new Commands();
|
||||
String title;
|
||||
|
||||
|
||||
public void checkFile(Player player)
|
||||
{
|
||||
String name = player.getName().toLowerCase();
|
||||
|
||||
|
||||
File file = new File(plugin.getDataFolder() + File.separator + "vaults" + name + ".yml");
|
||||
if(!file.exists())
|
||||
{
|
||||
@@ -34,7 +31,7 @@ public class VaultManager
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to save player's vault.
|
||||
* Serialize his inventory.
|
||||
@@ -44,24 +41,24 @@ 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();
|
||||
String ser = Serialization.toBase64(inv);
|
||||
File file = new File(plugin.getDataFolder() + File.separator + "vaults" + name + ".yml");
|
||||
FileConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
|
||||
// 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());
|
||||
}
|
||||
playerFile.save(file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to load player's vault.
|
||||
* Deserialize his inventory
|
||||
@@ -81,16 +78,16 @@ public class VaultManager
|
||||
player.openInventory(inv);
|
||||
player.sendMessage(title + " Opening " + ChatColor.GREEN + " " + number);
|
||||
return;
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage(title + " That doesn't exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void deleteVault(CommandSender sender, String target, int number) throws IOException
|
||||
{
|
||||
String name = target.toLowerCase();
|
||||
@@ -103,7 +100,7 @@ public class VaultManager
|
||||
sender.sendMessage(title + "Deleting " + ChatColor.GREEN + " " + number);
|
||||
playerFile.save(file);
|
||||
return;
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user