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