Save all lang files to disk. Allow switching between languages in the config file.
This will break anyone using the current lang.yml. They'll just need to move it to lang/english.yml
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
<directory>src/main/resources/</directory>
|
||||
<includes>
|
||||
<include>*.yml</include>
|
||||
<include>lang/*.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
@@ -16,22 +16,18 @@
|
||||
*/
|
||||
package com.drtshock.playervaults;
|
||||
|
||||
import com.drtshock.playervaults.commands.ConvertCommand;
|
||||
import com.drtshock.playervaults.commands.DeleteCommand;
|
||||
import com.drtshock.playervaults.commands.SignCommand;
|
||||
import com.drtshock.playervaults.commands.SignSetInfo;
|
||||
import com.drtshock.playervaults.commands.VaultCommand;
|
||||
import com.drtshock.playervaults.commands.*;
|
||||
import com.drtshock.playervaults.listeners.Listeners;
|
||||
import com.drtshock.playervaults.listeners.SignListener;
|
||||
import com.drtshock.playervaults.listeners.VaultPreloadListener;
|
||||
import com.drtshock.playervaults.tasks.Base64Conversion;
|
||||
import com.drtshock.playervaults.tasks.Cleanup;
|
||||
import com.drtshock.playervaults.tasks.UUIDConversion;
|
||||
import com.drtshock.playervaults.util.Lang;
|
||||
import com.drtshock.playervaults.translations.Lang;
|
||||
import com.drtshock.playervaults.translations.Language;
|
||||
import com.drtshock.playervaults.vaultmanagement.UUIDVaultManager;
|
||||
import com.drtshock.playervaults.vaultmanagement.VaultManager;
|
||||
import com.drtshock.playervaults.vaultmanagement.VaultViewInfo;
|
||||
import com.google.common.base.Charsets;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@@ -47,11 +43,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -62,8 +54,6 @@ public class PlayerVaults extends JavaPlugin {
|
||||
|
||||
private static PlayerVaults instance;
|
||||
public static boolean DEBUG = false;
|
||||
private boolean update = false;
|
||||
private String newVersion = "";
|
||||
private final HashMap<String, SignSetInfo> setSign = new HashMap<>();
|
||||
// Player name - VaultViewInfo
|
||||
private final HashMap<String, VaultViewInfo> inVault = new HashMap<>();
|
||||
@@ -255,65 +245,48 @@ public class PlayerVaults extends JavaPlugin {
|
||||
conf.set(path, object);
|
||||
}
|
||||
|
||||
private void loadLang() {
|
||||
File lang = new File(getDataFolder(), "lang.yml");
|
||||
OutputStream out = null;
|
||||
InputStream defLangStream = this.getResource("lang.yml");
|
||||
if (!lang.exists()) {
|
||||
try {
|
||||
getDataFolder().mkdir();
|
||||
lang.createNewFile();
|
||||
if (defLangStream != null) {
|
||||
out = new FileOutputStream(lang);
|
||||
int read;
|
||||
byte[] bytes = new byte[1024];
|
||||
public void loadLang() {
|
||||
File folder = new File(getDataFolder(), "lang");
|
||||
if (!folder.exists()) {
|
||||
folder.mkdir();
|
||||
}
|
||||
|
||||
while ((read = defLangStream.read(bytes)) != -1) {
|
||||
out.write(bytes, 0, read);
|
||||
}
|
||||
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(defLangStream, Charsets.UTF_8));
|
||||
Lang.setFile(defConfig);
|
||||
return;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); // So they notice
|
||||
getLogger().severe("[PlayerVaults] Couldn't create language file.");
|
||||
getLogger().severe("[PlayerVaults] This is a fatal error. Now disabling");
|
||||
this.setEnabled(false); // Without it loaded, we can't send them messages
|
||||
} finally {
|
||||
if (defLangStream != null) {
|
||||
try {
|
||||
defLangStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String definedLanguage = getConfig().getString("language", "english");
|
||||
|
||||
}
|
||||
// Save as default just incase.
|
||||
File english = null;
|
||||
File definedFile = null;
|
||||
|
||||
for (Language lang : Language.values()) {
|
||||
String fileName = lang.getFriendlyName() + ".yml";
|
||||
File file = new File(folder, fileName);
|
||||
if (lang == Language.ENGLISH) {
|
||||
english = file;
|
||||
}
|
||||
|
||||
if (!definedLanguage.equalsIgnoreCase(lang.getFriendlyName())) {
|
||||
definedFile = file;
|
||||
}
|
||||
|
||||
// Have Bukkit save the file.
|
||||
if (!file.exists()) {
|
||||
saveResource("lang/" + fileName, false);
|
||||
}
|
||||
}
|
||||
|
||||
YamlConfiguration conf = YamlConfiguration.loadConfiguration(lang);
|
||||
for (Lang item : Lang.values()) {
|
||||
if (conf.getString(item.getPath()) == null) {
|
||||
conf.set(item.getPath(), item.getDefault());
|
||||
}
|
||||
if (definedFile != null && !definedFile.exists()) {
|
||||
getLogger().severe("Failed to load language for " + definedLanguage + ". Defaulting to English.");
|
||||
definedFile = english;
|
||||
}
|
||||
|
||||
Lang.setFile(conf);
|
||||
try {
|
||||
conf.save(lang);
|
||||
} catch (IOException e) {
|
||||
getLogger().log(Level.WARNING, "PlayerVaults: Failed to save lang.yml.");
|
||||
getLogger().log(Level.WARNING, "PlayerVaults: Report this stack trace to drtshock and gomeow.");
|
||||
e.printStackTrace();
|
||||
if (definedFile == null) {
|
||||
getLogger().severe("Failed to load custom language settings. Loading plugin defaults. This should never happen, go ask for help.");
|
||||
return;
|
||||
}
|
||||
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(definedFile);
|
||||
Lang.setFile(config);
|
||||
getLogger().info("Loaded lang for " + definedLanguage);
|
||||
}
|
||||
|
||||
public HashMap<String, SignSetInfo> getSetSign() {
|
||||
@@ -328,14 +301,6 @@ public class PlayerVaults extends JavaPlugin {
|
||||
return this.openInventories;
|
||||
}
|
||||
|
||||
public boolean needsUpdate() {
|
||||
return this.update;
|
||||
}
|
||||
|
||||
public String getNewVersion() {
|
||||
return this.newVersion;
|
||||
}
|
||||
|
||||
public Economy getEconomy() {
|
||||
return this.economy;
|
||||
}
|
||||
@@ -351,6 +316,7 @@ public class PlayerVaults extends JavaPlugin {
|
||||
/**
|
||||
* Get the legacy UUID vault data folder.
|
||||
* Deprecated in favor of base64 data.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
@@ -374,6 +340,7 @@ public class PlayerVaults extends JavaPlugin {
|
||||
|
||||
/**
|
||||
* Tries to get a name from a given String that we hope is a UUID.
|
||||
*
|
||||
* @param potentialUUID - potential UUID to try to get the name for.
|
||||
* @return the player's name if we can find it, otherwise return what got passed to us.
|
||||
*/
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.drtshock.playervaults.commands;
|
||||
import com.drtshock.playervaults.PlayerVaults;
|
||||
import com.drtshock.playervaults.converters.BackpackConverter;
|
||||
import com.drtshock.playervaults.converters.Converter;
|
||||
import com.drtshock.playervaults.util.Lang;
|
||||
import com.drtshock.playervaults.translations.Lang;
|
||||
import com.drtshock.playervaults.vaultmanagement.VaultOperations;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.drtshock.playervaults.commands;
|
||||
|
||||
import com.drtshock.playervaults.util.Lang;
|
||||
import com.drtshock.playervaults.translations.Lang;
|
||||
import com.drtshock.playervaults.vaultmanagement.VaultOperations;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.drtshock.playervaults.commands;
|
||||
|
||||
import com.drtshock.playervaults.PlayerVaults;
|
||||
import com.drtshock.playervaults.util.Lang;
|
||||
import com.drtshock.playervaults.translations.Lang;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.drtshock.playervaults.commands;
|
||||
|
||||
import com.drtshock.playervaults.PlayerVaults;
|
||||
import com.drtshock.playervaults.util.Lang;
|
||||
import com.drtshock.playervaults.translations.Lang;
|
||||
import com.drtshock.playervaults.vaultmanagement.VaultManager;
|
||||
import com.drtshock.playervaults.vaultmanagement.VaultOperations;
|
||||
import com.drtshock.playervaults.vaultmanagement.VaultViewInfo;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.drtshock.playervaults.listeners;
|
||||
|
||||
import com.drtshock.playervaults.PlayerVaults;
|
||||
import com.drtshock.playervaults.util.Lang;
|
||||
import com.drtshock.playervaults.translations.Lang;
|
||||
import com.drtshock.playervaults.vaultmanagement.VaultManager;
|
||||
import com.drtshock.playervaults.vaultmanagement.VaultViewInfo;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -32,7 +32,6 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.drtshock.playervaults.listeners;
|
||||
|
||||
import com.drtshock.playervaults.PlayerVaults;
|
||||
import com.drtshock.playervaults.util.Lang;
|
||||
import com.drtshock.playervaults.vaultmanagement.UUIDVaultManager;
|
||||
import com.drtshock.playervaults.translations.Lang;
|
||||
import com.drtshock.playervaults.vaultmanagement.VaultManager;
|
||||
import com.drtshock.playervaults.vaultmanagement.VaultOperations;
|
||||
import com.drtshock.playervaults.vaultmanagement.VaultViewInfo;
|
||||
|
||||
+1
-2
@@ -14,7 +14,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.drtshock.playervaults.util;
|
||||
package com.drtshock.playervaults.translations;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
@@ -26,7 +26,6 @@ public enum Lang {
|
||||
TITLE("title-name", "&4[&fPlayerVaults&4]:"),
|
||||
OPEN_VAULT("open-vault", "&fOpening vault &a%v"),
|
||||
OPEN_OTHER_VAULT("open-other-vault", "&fOpening vault &a%v &fof &a%p"),
|
||||
OPEN_WORKBENCH("open-workbench", "&fOpening workbench"),
|
||||
INVALID_ARGS("invalid-args", "&cInvalid args!"),
|
||||
DELETE_VAULT("delete-vault", "&fDeleted vault &a%v"),
|
||||
DELETE_OTHER_VAULT("delete-other-vault", "&fDeleted vault &a%v &fof &a%p"),
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.drtshock.playervaults.translations;
|
||||
|
||||
public enum Language {
|
||||
ENGLISH("english"),
|
||||
BULGARIAN("bulgarian"),
|
||||
DUTH("dutch");
|
||||
|
||||
private String friendlyName;
|
||||
|
||||
Language(String friendlyName) {
|
||||
this.friendlyName = friendlyName;
|
||||
}
|
||||
|
||||
public String getFriendlyName() {
|
||||
return this.friendlyName;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.drtshock.playervaults.vaultmanagement;
|
||||
|
||||
import com.drtshock.playervaults.PlayerVaults;
|
||||
import com.drtshock.playervaults.util.Lang;
|
||||
import com.drtshock.playervaults.translations.Lang;
|
||||
import net.milkbowl.vault.economy.EconomyResponse;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.drtshock.playervaults.vaultmanagement;
|
||||
|
||||
import com.drtshock.playervaults.PlayerVaults;
|
||||
import com.drtshock.playervaults.util.Lang;
|
||||
import com.drtshock.playervaults.translations.Lang;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.drtshock.playervaults.vaultmanagement;
|
||||
|
||||
import com.drtshock.playervaults.PlayerVaults;
|
||||
import com.drtshock.playervaults.util.Lang;
|
||||
import com.drtshock.playervaults.translations.Lang;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.drtshock.playervaults.vaultmanagement;
|
||||
|
||||
import com.drtshock.playervaults.PlayerVaults;
|
||||
import com.drtshock.playervaults.util.Lang;
|
||||
import com.drtshock.playervaults.translations.Lang;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
@@ -7,6 +7,11 @@
|
||||
# Should probably only enabled this if you're working with drtshock to fix something.
|
||||
debug: false
|
||||
|
||||
# Lang files can be found in plugins/PlayerVaults/lang/
|
||||
# Set the below value to be one of the files in there without .yml
|
||||
# Currently can use: english, bulgarian, dutch
|
||||
language: english
|
||||
|
||||
# Signs
|
||||
# Do you want to enable signs?
|
||||
# You can checkout the project page for info on what this is if you don't know.
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
# %number is the vault number
|
||||
# %converted is the number of vaults converted (where applicable)
|
||||
# Made with love :)
|
||||
title-name: "&4[&fPlayerVaults&4]:"
|
||||
title-name: "&4[&fPlayerVaultsX&4]:"
|
||||
open-vault: "&fOpening vault &a%v"
|
||||
open-other-vault: "&fOpening vault &a%v &fof &a%p"
|
||||
open-workbench: "&fOpening workbench"
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
# Use & for color codes.
|
||||
# %p is where the player name will get inserted.
|
||||
# %v is where the vault number will get inserted.
|
||||
# %price is the price.
|
||||
# %number is the vault number
|
||||
# %converted is the number of vaults converted (where applicable)
|
||||
# Made with love :)
|
||||
title-name: "&4[&fPlayerVaultsX&4]:"
|
||||
open-vault: "&fOpening vault &a%v"
|
||||
open-other-vault: "&fOpening vault &a%v &fof &a%p"
|
||||
open-workbench: "&fOpening workbench"
|
||||
delete-vault: "&fDeleted vault &a%v"
|
||||
delete-other-vault: "&fDeleted vault &a%v &fof &a%p"
|
||||
player-only: "&cSorry but that can only be run by a player!"
|
||||
must-be-number: "&cYou need to specify a number between 1-99"
|
||||
invalid-args: "&cInvalid args!"
|
||||
delete-vault-error: "&cError deleting vault :("
|
||||
no-permissions: "&cYou don't have permission for that!"
|
||||
insufficient-funds: "&cYou don't have enough money for that!"
|
||||
refund-amount: "&fYou were refunded &a%price &ffor deleting that vault."
|
||||
cost-to-create: "&fYou were charged &c%price &ffor creating that vault."
|
||||
cost-to-open: "&fYou were charged &c%price &ffor opening that vault."
|
||||
vault-number: "&4Vault #%number"
|
||||
existing-vaults: "&f%p has vaults: &a%v"
|
||||
no-player-found: "&cCannot find player &a%p"
|
||||
plugin-not-found: "&cNo converter found for that plugin"
|
||||
conversion-complete: "&aConverted %converted players to PlayerVaults"
|
||||
conversion-background: "&fConversion has been forked to the background. See console for updates."
|
||||
vaults-locked: "&cVaults are currently locked while conversion occurs. Please try again in a moment!"
|
||||
help: "/pv <number>"
|
||||
blocked-item: "&6%m &cis blocked from vaults."
|
||||
Reference in New Issue
Block a user