Clean up a bunch of stuff
This commit is contained in:
@@ -2,17 +2,15 @@ package com.drtshock.playervaults;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.drtshock.playervaults.commands.Commands;
|
||||
import com.drtshock.playervaults.util.Lang;
|
||||
import com.drtshock.playervaults.util.Metrics;
|
||||
import com.drtshock.playervaults.util.Updater;
|
||||
|
||||
@@ -28,10 +26,9 @@ public class Main extends JavaPlugin {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
log = getServer().getLogger();
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
pm.registerEvents(new Listeners(this), this);
|
||||
getCommand("pv").setExecutor(new Commands());
|
||||
getCommand("pvdel").setExecutor(new Commands());
|
||||
getServer().getPluginManager().registerEvents(new Listeners(this), this);
|
||||
getCommand("pv").setExecutor(commands);
|
||||
getCommand("pvdel").setExecutor(commands);
|
||||
loadConfig();
|
||||
loadLang();
|
||||
startMetrics();
|
||||
@@ -46,69 +43,44 @@ public class Main extends JavaPlugin {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
//saveData();
|
||||
}
|
||||
|
||||
|
||||
public void startMetrics() {
|
||||
try {
|
||||
Metrics metrics = new Metrics(this);
|
||||
metrics.start();
|
||||
} catch (IOException localIOException) {
|
||||
localIOException.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
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()) {
|
||||
saveDefaultConfig();
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
public YamlConfiguration loadLang() {
|
||||
File lang = new File(getDataFolder(), "lang.yml");
|
||||
if(!lang.exists()) {
|
||||
try{
|
||||
getDataFolder().mkdir();
|
||||
lang.createNewFile();
|
||||
InputStream defConfigStream = this.getResource("lang.yml");
|
||||
if (defConfigStream != null) {
|
||||
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
|
||||
defConfig.save(lang);
|
||||
return defConfig;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.warning("[PlayerVaults] Couldn't create language file.");
|
||||
}
|
||||
/**
|
||||
* Write the config file here.
|
||||
* New, genius way to write it :)
|
||||
*/
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream(lang);
|
||||
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.warning("[PlayerVaults] Couldn't write Language file: " + e);
|
||||
e.printStackTrace(); //So they notice
|
||||
log.severe("[PlayerVaults] Couldn't create language file.");
|
||||
log.severe("[PlayerVaults] This is a fatal error. Now disabling");
|
||||
this.setEnabled(false); //Without it loaded, we can't send them messages
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private YamlConfiguration lang() {
|
||||
File file = new File(getDataFolder() + File.separator + "lang.yml");
|
||||
YamlConfiguration lang = YamlConfiguration.loadConfiguration(file);
|
||||
return lang;
|
||||
YamlConfiguration conf = YamlConfiguration.loadConfiguration(lang);
|
||||
Lang.setFile(conf);
|
||||
return conf;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,68 +88,8 @@ public class Main extends JavaPlugin {
|
||||
* public so any class / plugin can get them.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @return updateCheck
|
||||
*/
|
||||
public boolean updateCheck() {
|
||||
return getConfig().getBoolean("check-update");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 Logger getLog() {
|
||||
return getServer().getLogger();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@ package com.drtshock.playervaults.commands;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.drtshock.playervaults.Main;
|
||||
import com.drtshock.playervaults.util.Lang;
|
||||
import com.drtshock.playervaults.util.VaultManager;
|
||||
|
||||
public class VaultOperations {
|
||||
@@ -15,8 +15,7 @@ public class VaultOperations {
|
||||
private static Main plugin;
|
||||
private static VaultManager vm = new VaultManager(plugin);
|
||||
|
||||
static String pv = ChatColor.DARK_RED + "[" + ChatColor.WHITE + "PlayerVaults" +
|
||||
ChatColor.DARK_RED + "]" + ChatColor.WHITE + ": ";
|
||||
static String pv = Lang.TITLE.toString();
|
||||
|
||||
|
||||
public static boolean checkPerms(CommandSender cs, int number) {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.drtshock.playervaults.util;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public enum Lang {
|
||||
TITLE("title-name"),
|
||||
OPEN_VAULT("open-vault"),
|
||||
OPEN_OTHER_VAULT("open-other-vault"),
|
||||
INVALID_ARGS("invalid-args"),
|
||||
DELETE_VAULT("delete-vault"),
|
||||
DELETE_OTHER_VAULT("delete-other-vault"),
|
||||
PLAYER_ONLY("player-only"),
|
||||
MUST_BE_NUMBER("must-be-number"),
|
||||
DELETE_VAULT_ERROR("delete-vault-error");
|
||||
|
||||
private String path = "";
|
||||
private static YamlConfiguration lang;
|
||||
|
||||
Lang(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public static void setFile(YamlConfiguration yc) {
|
||||
lang = yc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return lang.getString(this.path);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user