Started configuration loading and errors; changes to locales

Worked on PluginConfig.loadPluginConfig(). Changed the NotSetup
processing : when loading config, it will store errors and if there are,
it will run the plugin as "NotSetup" and send to users what is wrong and
why. Major parts are still remaining as it is a "preview" of an
unfinished and "waiting-for-improvements" work.
This commit is contained in:
Poslovitch 2017-05-24 17:10:49 +02:00
parent e00b925447
commit a69e053229
10 changed files with 322 additions and 261 deletions

View File

@ -69,7 +69,7 @@ general:
mute-death-messages: false
# Allow FTB Autonomous Activator to work (will allow a pseudo player [CoFH] to place and break blocks and hang items)
ftb-auto-activator: false
FTB-auto-activator: false
# Allow obsidian to be scooped up with an empty bucket back into lava
# This only works if there is a single block of obsidian (no obsidian within 10 blocks)
@ -123,16 +123,16 @@ world:
start-x: 0
start-z: 0
# Island height - Lowest is 5.
# It is the y coordinate of the bedrock block in the schematic
island-height: 120
# Sea height (don't changes this mid-game unless you delete the world)
# Minimum is 0, which means you are playing Skyblock!
# If sea height is less than about 10, then players will drop right through it
# if it exists. Makes for an interesting variation on skyblock.
sea-height: 0
# Island height - Lowest is 5.
# It is the y coordinate of the bedrock block in the schematic
island-height: 120
# Maximum number of islands in the world. Set to 0 for unlimited.
# If the number of islands is greater than this number, no new island will be created.
max-islands: 0

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import us.tastybento.bskyblock.config.BSBLocale;
import us.tastybento.bskyblock.config.PluginConfig;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.database.BSBDatabase;
import us.tastybento.bskyblock.database.IslandsManager;
@ -22,80 +23,85 @@ import us.tastybento.bskyblock.util.VaultHelper;
*/
public class BSkyBlock extends JavaPlugin{
private static BSkyBlock plugin;
private HashMap<String, BSBLocale> locales = new HashMap<String, BSBLocale>();
// Databases
private PlayersManager playersManager;
private IslandsManager islandsManager;
private OfflineHistoryMessages offlineHistoryMessages;
// Metrics
private Metrics metrics;
@Override
public void onEnable(){
plugin = this;
playersManager = new PlayersManager(this);
islandsManager = new IslandsManager(this);
playersManager.load();
islandsManager.load();
offlineHistoryMessages = new OfflineHistoryMessages(this);
offlineHistoryMessages.load();
if (Settings.useEconomy && !VaultHelper.setupEconomy()) {
getLogger().warning("Could not set up economy! - Running without an economy.");
Settings.useEconomy = false;
}
if (!VaultHelper.setupPermissions()) {
getLogger().severe("Cannot link with Vault for permissions! Disabling plugin!");
getServer().getPluginManager().disablePlugin(this);
return;
}
// Only load metrics if set to true in config
if(Settings.metrics) metrics = new Metrics(this);
// If metrics are loaded, register the custom data charts
if(metrics != null){
registerCustomCharts();
}
// Save islands & players data asynchronously every X minutes
plugin.getServer().getScheduler().runTaskTimer(this, new Runnable() {
@Override
public void run() {
playersManager.save(true);
islandsManager.save(true);
offlineHistoryMessages.save(true);
// Load configuration and locales if the config don't have errors.
if(PluginConfig.loadPluginConfig(this)){
playersManager = new PlayersManager(this);
islandsManager = new IslandsManager(this);
playersManager.load();
islandsManager.load();
offlineHistoryMessages = new OfflineHistoryMessages(this);
offlineHistoryMessages.load();
if (Settings.useEconomy && !VaultHelper.setupEconomy()) {
getLogger().warning("Could not set up economy! - Running without an economy.");
Settings.useEconomy = false;
}
}, Settings.databaseBackupPeriod, Settings.databaseBackupPeriod);
// Only load metrics if set to true in config
if(Settings.metrics) metrics = new Metrics(this);
// If metrics are loaded, register the custom data charts
if(metrics != null){
registerCustomCharts();
}
// Save islands & players data asynchronously every X minutes
plugin.getServer().getScheduler().runTaskTimer(this, new Runnable() {
@Override
public void run() {
playersManager.save(true);
islandsManager.save(true);
offlineHistoryMessages.save(true);
}
}, Settings.databaseBackupPeriod, Settings.databaseBackupPeriod);
}
}
@Override
public void onDisable(){
// Save data
playersManager.shutdown();
islandsManager.shutdown();
offlineHistoryMessages.shutdown();
plugin = null;
}
private void registerCustomCharts(){
metrics.addCustomChart(new Metrics.SingleLineChart("islands_count") {
@Override
public int getValue() {
return islandsManager.getCount();
}
});
metrics.addCustomChart(new Metrics.SingleLineChart("created_islands") {
@Override
public int getValue() {
int created = islandsManager.metrics_getCreatedCount();
@ -103,24 +109,24 @@ public class BSkyBlock extends JavaPlugin{
return created;
}
});
metrics.addCustomChart(new Metrics.SimplePie("default_locale") {
@Override
public String getValue() {
return Settings.defaultLanguage;
}
});
metrics.addCustomChart(new Metrics.SimplePie("database") {
@Override
public String getValue() {
return BSBDatabase.getDatabase().toString();
}
});
}
/**
* Returns BSkyBlock object instance
* @return BSkyBlock instance
@ -128,7 +134,7 @@ public class BSkyBlock extends JavaPlugin{
public static BSkyBlock getInstance(){
return plugin;
}
/**
* Returns an HashMap of locale identifier and the related object
* @return the locales
@ -136,7 +142,15 @@ public class BSkyBlock extends JavaPlugin{
public HashMap<String, BSBLocale> getLocales(){
return locales;
}
/**
* Set the available locales
* @param locales - the locales to set
*/
public void setLocales(HashMap<String, BSBLocale> locales){
this.locales = locales;
}
/**
* Returns the default locale
* @return the default locale
@ -144,7 +158,7 @@ public class BSkyBlock extends JavaPlugin{
public BSBLocale getLocale(){
return locales.get(Settings.defaultLanguage);
}
/**
* Returns the locale for the specified CommandSender
* @param sender - CommandSender to get the locale
@ -154,7 +168,7 @@ public class BSkyBlock extends JavaPlugin{
if(sender instanceof Player) return getLocale(((Player) sender).getUniqueId());
else return getLocale();
}
/**
* Returns the locale for the specified player
* @param player - Player to get the locale
@ -163,10 +177,10 @@ public class BSkyBlock extends JavaPlugin{
public BSBLocale getLocale(UUID player){
String locale = getPlayers().getPlayer(player).getLocale();
if(locale.isEmpty() || !locales.containsKey(locale)) return locales.get(Settings.defaultLanguage);
return locales.get(locale);
}
/**
* Returns the player database
* @return the player database
@ -174,7 +188,7 @@ public class BSkyBlock extends JavaPlugin{
public PlayersManager getPlayers(){
return playersManager;
}
/**
* Returns the island database
* @return the island database

View File

@ -38,7 +38,7 @@ public abstract class BSBCommand implements CommandExecutor, TabCompleter{
@Override
public void onExecute(CommandSender sender, String label, String[] args) {
// Generate help
String help = plugin.getLocale(sender).helpHeader + "\n";
String help = plugin.getLocale(sender).get("help.header") + "\n";
for(String argument : arguments.keySet()){
CommandArgumentHandler cah = getArgumentHandler(argument);

View File

@ -29,14 +29,14 @@ public class IslandCommand extends BSBCommand{
@Override
public boolean canExecute(CommandSender sender, String label) {
if(!(sender instanceof Player)){
Util.sendMessage(sender, plugin.getLocale(sender).errorUseInGame);
Util.sendMessage(sender, plugin.getLocale(sender).get("general.errors.use-in-game"));
return false;
}
Player player = (Player) sender;
// Basic permission check to even use /island
if(!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.create")){
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).errorNoPermission);
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).get("general.errors.no-permission"));
return false;
}
@ -113,8 +113,8 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
// TODO check if multiple homes
if(VaultHelper.hasPerm((Player) sender, "todo")) return new String[] {"[1-x]", plugin.getLocale(sender).islandHelpGoHomes};
return new String[] {null, plugin.getLocale(sender).islandHelpGo};
if(VaultHelper.hasPerm((Player) sender, "todo")) return new String[] {"[1-x]", plugin.getLocale(sender).get("help.island.go-homes")};
return new String[] {null, plugin.getLocale(sender).get("help.island.go")};
}
});
@ -140,7 +140,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {null, plugin.getLocale(sender).islandHelpSpawn};
return new String[] {null, plugin.getLocale(sender).get("help.island.spawn")};
}
});
@ -167,7 +167,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {"[schematic]", plugin.getLocale(sender).islandHelpCreate};
return new String[] {"[schematic]", plugin.getLocale(sender).get("help.island.create")};
}
});
@ -194,7 +194,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {"[player]", plugin.getLocale(sender).islandHelpInfo};
return new String[] {"[player]", plugin.getLocale(sender).get("help.island.info")};
}
});
@ -221,7 +221,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {"[on/off]", plugin.getLocale(sender).islandHelpControlPanel};
return new String[] {"[on/off]", plugin.getLocale(sender).get("help.island.control-panel")};
}
});
@ -248,7 +248,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {null, plugin.getLocale(sender).islandHelpReset};
return new String[] {null, plugin.getLocale(sender).get("help.island.reset")};
}
});
@ -275,7 +275,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {null, plugin.getLocale(sender).islandHelpSetHome};
return new String[] {null, plugin.getLocale(sender).get("help.island.sethome")};
}
});
@ -287,17 +287,17 @@ public class IslandCommand extends BSBCommand{
Player player = (Player) sender;
if(!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.name")){
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).errorNoPermission);
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).get("general.errors.no-permission"));
return false;
}
if(!plugin.getIslands().hasIsland(player.getUniqueId())){
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).errorNoIsland);
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).get("general.errors.no-island"));
return false;
}
if(!plugin.getIslands().isOwner(player.getUniqueId())){
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).errorNotLeader);
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).get("general.errors.not-leader"));
return false;
}
@ -322,11 +322,11 @@ public class IslandCommand extends BSBCommand{
// Check if the name isn't too short or too long
if(name.length() < Settings.nameMinLength){
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).errorTooShort.replace("[length]", String.valueOf(Settings.nameMinLength)));
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).get("general.errors.too-short").replace("[length]", String.valueOf(Settings.nameMinLength)));
return;
}
if(name.length() > Settings.nameMaxLength){
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).errorTooLong.replace("[length]", String.valueOf(Settings.nameMaxLength)));
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).get("general.errors.too-long").replace("[length]", String.valueOf(Settings.nameMaxLength)));
return;
}
@ -334,7 +334,7 @@ public class IslandCommand extends BSBCommand{
if(VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.name.format")) plugin.getIslands().getIsland(player.getUniqueId()).setName(ChatColor.translateAlternateColorCodes('&', name));
else plugin.getIslands().getIsland(player.getUniqueId()).setName(name);
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(player).generalSuccess);
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(player).get("general.success"));
}
@Override
@ -344,7 +344,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {"<name>", plugin.getLocale(sender).islandHelpName};
return new String[] {"<name>", plugin.getLocale(sender).get("help.island.name")};
}
});
@ -356,17 +356,17 @@ public class IslandCommand extends BSBCommand{
Player player = (Player) sender;
if(!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.name")){
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).errorNoPermission);
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).get("general.errors.no-permission"));
return false;
}
if(!plugin.getIslands().hasIsland(player.getUniqueId())){
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).errorNoIsland);
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).get("general.errors.no-island"));
return false;
}
if(!plugin.getIslands().isOwner(player.getUniqueId())){
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).errorNotLeader);
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).get("general.errors.not-leader"));
return false;
}
@ -379,7 +379,7 @@ public class IslandCommand extends BSBCommand{
// Resets the island name
plugin.getIslands().getIsland(player.getUniqueId()).setName(null);
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(player).generalSuccess);
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(player).get("general.success"));
}
@Override
@ -389,7 +389,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {null, plugin.getLocale(sender).islandHelpResetName};
return new String[] {null, plugin.getLocale(sender).get("help.island.resetname")};
}
});
@ -416,7 +416,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {null, plugin.getLocale(sender).islandHelpLimits};
return new String[] {null, plugin.getLocale(sender).get("help.island.limits")};
}
});
@ -443,7 +443,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {null, plugin.getLocale(sender).islandHelpTeam};
return new String[] {null, plugin.getLocale(sender).get("help.island.team")};
}
});
@ -470,7 +470,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {"<player>", plugin.getLocale(sender).islandHelpInvite};
return new String[] {"<player>", plugin.getLocale(sender).get("help.island.invite")};
}
});
@ -497,7 +497,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {"<player>", plugin.getLocale(sender).islandHelpUninvite};
return new String[] {"<player>", plugin.getLocale(sender).get("help.island.uninvite")};
}
});
@ -524,7 +524,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {null, plugin.getLocale(sender).islandHelpLeave};
return new String[] {null, plugin.getLocale(sender).get("help.island.leave")};
}
});
@ -551,7 +551,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {"<player>", plugin.getLocale(sender).islandHelpKick};
return new String[] {"<player>", plugin.getLocale(sender).get("help.island.kick")};
}
});
@ -578,7 +578,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {"[player]", plugin.getLocale(sender).islandHelpAccept};
return new String[] {"[player]", plugin.getLocale(sender).get("help.island.accept")};
}
});
@ -605,7 +605,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {"[player]", plugin.getLocale(sender).islandHelpReject};
return new String[] {"[player]", plugin.getLocale(sender).get("help.island.reject")};
}
});
@ -632,7 +632,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {"<player>", plugin.getLocale(sender).islandHelpMakeleader};
return new String[] {"<player>", plugin.getLocale(sender).get("help.island.makeleader")};
}
});
@ -659,7 +659,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {null, plugin.getLocale(sender).islandHelpTeamchat};
return new String[] {null, plugin.getLocale(sender).get("help.island.teamchat")};
}
});
@ -686,7 +686,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {null, plugin.getLocale(sender).islandHelpBiomes};
return new String[] {null, plugin.getLocale(sender).get("help.island.biomes")};
}
});
@ -713,7 +713,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {"<player>", plugin.getLocale(sender).islandHelpExpel};
return new String[] {"<player>", plugin.getLocale(sender).get("help.island.expel")};
}
});
@ -740,7 +740,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {null, plugin.getLocale(sender).islandHelpExpelall};
return new String[] {null, plugin.getLocale(sender).get("help.island.expelall")};
}
});
@ -767,7 +767,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {"<player>", plugin.getLocale(sender).islandHelpBan};
return new String[] {"<player>", plugin.getLocale(sender).get("help.island.ban")};
}
});
@ -794,7 +794,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {"<player>", plugin.getLocale(sender).islandHelpUnban};
return new String[] {"<player>", plugin.getLocale(sender).get("help.island.unban")};
}
});
@ -821,7 +821,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {null, plugin.getLocale(sender).islandHelpBanlist};
return new String[] {null, plugin.getLocale(sender).get("help.island.banlist")};
}
});
@ -848,7 +848,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {"<player>", plugin.getLocale(sender).islandHelpTrust};
return new String[] {"<player>", plugin.getLocale(sender).get("help.island.trust")};
}
});
@ -875,7 +875,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {"<player>", plugin.getLocale(sender).islandHelpUntrust};
return new String[] {"<player>", plugin.getLocale(sender).get("help.island.untrust")};
}
});
@ -902,7 +902,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {null, plugin.getLocale(sender).islandHelpTrustlist};
return new String[] {null, plugin.getLocale(sender).get("help.island.trustlist")};
}
});
@ -929,7 +929,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {"<player>", plugin.getLocale(sender).islandHelpCoop};
return new String[] {"<player>", plugin.getLocale(sender).get("help.island.coop")};
}
});
@ -956,7 +956,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {"<player>", plugin.getLocale(sender).islandHelpUncoop};
return new String[] {"<player>", plugin.getLocale(sender).get("help.island.uncoop")};
}
});
@ -983,7 +983,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {null, plugin.getLocale(sender).islandHelpCooplist};
return new String[] {null, plugin.getLocale(sender).get("help.island.cooplist")};
}
});
@ -995,12 +995,12 @@ public class IslandCommand extends BSBCommand{
Player player = (Player) sender;
if(!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.lock")){
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).errorNoPermission);
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).get("general.errors.no-permission"));
return false;
}
if(!plugin.getIslands().hasIsland(player.getUniqueId())){
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).errorNoIsland);
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).get("general.errors.no-island"));
return false;
}
@ -1015,9 +1015,9 @@ public class IslandCommand extends BSBCommand{
if(!island.isLocked()){
// TODO: Expel all visitors
// TODO: send offline messages
island.setLocked(false);
island.setLocked(true);
} else {
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(player).lockUnlocking);
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(player).get("island.lock.unlocking"));
// TODO: send offline messages
island.setLocked(false);
}
@ -1030,7 +1030,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {null, plugin.getLocale(sender).islandHelpLock};
return new String[] {null, plugin.getLocale(sender).get("help.island.lock")};
}
});
@ -1057,7 +1057,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {null, plugin.getLocale(sender).islandHelpSettings};
return new String[] {null, plugin.getLocale(sender).get("help.island.settings")};
}
});
@ -1084,7 +1084,7 @@ public class IslandCommand extends BSBCommand{
@Override
public String[] getHelp(CommandSender sender, String label){
return new String[] {"<id>", plugin.getLocale(sender).islandHelpLanguage};
return new String[] {"<id>", plugin.getLocale(sender).get("help.island.language")};
}
});
}

View File

@ -1,57 +0,0 @@
package us.tastybento.bskyblock.commands;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.util.Util;
/**
* This class runs when the config file is not set up enough, or is unsafe.
* It provides useful information to the admin on what is wrong.
*
* @author Tastybento
*/
public class NotSetup implements CommandExecutor{
public enum Reason {
DISTANCE, GENERATOR, WORLD_NAME, OUTDATED;
}
private BSkyBlock plugin;
private Reason reason;
/**
* Handles plugin operation if a critical config-related issue happened
*
* @param reason
*/
public NotSetup(BSkyBlock plugin, Reason reason){
this.reason = reason;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Util.sendMessage(sender, ChatColor.RED + plugin.getLocale(sender).notSetupHeader);
switch (reason) {
case DISTANCE:
Util.sendMessage(sender, ChatColor.RED + plugin.getLocale(sender).notSetupDistance);
break;
case GENERATOR:
Util.sendMessage(sender, ChatColor.RED + plugin.getLocale(sender).notSetupGenerator);
if(plugin.getServer().getPluginManager().isPluginEnabled("Multiverse-Core")) Util.sendMessage(sender, ChatColor.RED + plugin.getLocale(sender).notSetupGeneratorMultiverse);
break;
case WORLD_NAME:
Util.sendMessage(sender, ChatColor.RED + plugin.getLocale(sender).notSetupWorldname);
break;
case OUTDATED:
Util.sendMessage(sender, ChatColor.RED + plugin.getLocale(sender).notSetupOutdated);
break;
default:
break;
}
return true;
}
}

View File

@ -1,16 +1,17 @@
package us.tastybento.bskyblock.config;
import java.io.File;
import java.util.HashMap;
import java.util.Locale;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import us.tastybento.bskyblock.BSkyBlock;
/**
* Contains all the texts sent to players
* Contains all the texts sent to players.
* The locale object is instantiated at server launch, but the texts are only loaded when needed.
*
* @author Tastybento
* @author Poslovitch
@ -33,7 +34,6 @@ public class BSBLocale {
this.plugin = plugin;
this.localeID = localeID;
getLocale(localeID);
loadLocale();
localeObject = new Locale(localeID.substring(0, 2), localeID.substring(3, 5));
}
@ -104,95 +104,15 @@ public class BSBLocale {
}
/* Localization */
private HashMap<String, String> localization = new HashMap<String, String>();
// Not Setup
public String notSetupHeader;
public String notSetupDistance;
public String notSetupGenerator;
public String notSetupGeneratorMultiverse;
public String notSetupWorldname;
public String notSetupOutdated;
// General
public String generalSuccess;
// Errors
public String errorNoPermission;
public String errorUseInGame;
public String errorNoIsland;
public String errorNotLeader;
public String errorTooShort;
public String errorTooLong;
// Help
public String helpSyntaxColor;
public String helpCommentColor;
public String helpHeader;
public String islandHelpGo;
public String islandHelpGoHomes;
public String islandHelpSpawn;
public String islandHelpCreate;
public String islandHelpInfo;
public String islandHelpControlPanel;
public String islandHelpReset;
public String islandHelpSetHome;
public String islandHelpName;
public String islandHelpResetName;
public String islandHelpLimits;
public String islandHelpTeam;
public String islandHelpInvite;
public String islandHelpUninvite;
public String islandHelpLeave;
public String islandHelpKick;
public String islandHelpAccept;
public String islandHelpReject;
public String islandHelpMakeleader;
public String islandHelpTeamchat;
public String islandHelpBiomes;
public String islandHelpExpel;
public String islandHelpExpelall;
public String islandHelpBan;
public String islandHelpUnban;
public String islandHelpBanlist;
public String islandHelpTrust;
public String islandHelpUntrust;
public String islandHelpTrustlist;
public String islandHelpCoop;
public String islandHelpUncoop;
public String islandHelpCooplist;
public String islandHelpLock;
public String islandHelpSettings;
public String islandHelpLanguage;
// Lock
public String lockLocking;
public String lockUnlocking;
private void loadLocale(){
// Not Setup
notSetupHeader = ChatColor.translateAlternateColorCodes('&', locale.getString("not-setup.header", "More set up is required before the plugin can start...\nEdit config.yml. Then restart server."));
notSetupDistance = ChatColor.translateAlternateColorCodes('&', locale.getString("not-setup.distance", "Make sure you set island distance. If upgrading, set it to what it was before."));
notSetupGenerator = ChatColor.translateAlternateColorCodes('&',
locale.getString("not-setup.generator", "The world generator for the island world is not registered."
+ "\nPotential reasons are:"
+ "\n 1. If you are configuring the island world as the only server world\n Make sure you have added the world to bukkit.yml"
+ "\n 2. You reloaded instead of restarting the server. Reboot and try again."));
notSetupGeneratorMultiverse = ChatColor.translateAlternateColorCodes('&', locale.getString("not-setup.generator-multiverse", " 3. Your Multiverse plugin is out of date. Upgrade to the latest version."));
notSetupWorldname = ChatColor.translateAlternateColorCodes('&',
locale.getString("not-setup.world-name", "The world name in config.yml is different to the world name in islands.yml."
+ "\nIf this is intentional, we assume you are doing a full reset."
+ "\nIf so, delete islands.yml and the previous world."
+ "\nIf not, correct the world name in config.yml and restart. This is probably the case if you are upgrading."));
notSetupOutdated = ChatColor.translateAlternateColorCodes('&',
locale.getString("not-setup.config-outdated", "The config.yml file looks outdated."
+ "\nMake sure you updated your configuration after upgrading."
+ "\nIf this error is still happening, you probably edited the old config rather than editing the new one."
+ "\nIf so, please remove the current config.yml, work on config.new.yml and rename it to config.yml."));
// General
generalSuccess = ChatColor.translateAlternateColorCodes('&', locale.getString("general.success", "Success!"));
// Errors
errorNoPermission = ChatColor.translateAlternateColorCodes('&', locale.getString("general.errors.no-permission", "You don't have permission to execute this command."));
public String get(String id){
// If the text isn't loaded, load it.
if(!localization.containsKey(id)){
// Save the text to the HashMap.
// If the text doesn't exist in the locale file, save it as its id, to help debug.
localization.put(id, locale.getString(id, id));
}
return localization.get(id);
}
}

View File

@ -0,0 +1,76 @@
package us.tastybento.bskyblock.config;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import us.tastybento.bskyblock.BSkyBlock;
/**
* This class runs when the config file is not set up enough, or is unsafe.
* It provides useful information to the admin on what is wrong.
*
* @author Tastybento
* @author Poslovitch
*/
public class NotSetup implements CommandExecutor{
public enum ConfigError {
DIFFERENT_WORLDNAME(0, 001),
DIFFERENT_ISLAND_DISTANCE(0, 002),
PROTECTION_RANGE_HIGHER_THAN_ISLAND_DISTANCE(1, 101),
UNKNOWN_LANGUAGE(2, 201),
NOT_EVEN_ISLAND_DISTANCE(2, 202),
NOT_EVEN_PROTECTION_RANGE(2, 203),
PURGE_ISLAND_LEVEL_TOO_LOW(3, 301),
ISLAND_DISTANCE_TOO_LOW(3, 302),
PROTECTION_RANGE_TOO_LOW(3, 303),
ISLAND_HEIGHT_TOO_LOW(3, 304),
NETHER_SPAWN_RADIUS_TOO_LOW(3, 305),
NETHER_SPAWN_RADIUS_TOO_HIGH(3, 306);
/*
* Priority:
* 0 - CRITICAL
* 1 - HIGH
* 2 - MEDIUM
* 3 - LOW
*/
private int priority;
private int id;
ConfigError(int priority, int id){
this.priority = priority;
this.id = id;
}
public static ConfigError getById(int id){
for(ConfigError e : ConfigError.values()){
if(e.id == id) return e;
}
return null;
}
}
private BSkyBlock plugin;
private List<Error> errors;
/**
* Handles plugin operation if a critical config-related issue happened
*
* @param plugin
* @param errors
*/
public NotSetup(BSkyBlock plugin, List<Error> errors){
this.plugin = plugin;
this.errors = errors;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
return true;
}
}

View File

@ -1,5 +1,113 @@
package us.tastybento.bskyblock.config;
public class PluginConfig {
import java.util.HashMap;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.config.NotSetup.ConfigError;
/**
* Loads the plugin configuration and the locales.
* Also provides
*
* @author Tastybento
* @author Poslovitch
*/
public class PluginConfig {
/**
* Loads the plugin configuration and the locales.
* If there were errors, it setups the commands as "NotSetup" and generates a debug for admins to fix their configuration.
* @return true if there wasn't any error, otherwise false.
*/
public static boolean loadPluginConfig(BSkyBlock plugin){
// Check if the config exists. It shouldn't happen, but the stack trace helps to know why.
try{
plugin.getConfig();
} catch (Exception exception){
exception.printStackTrace();
}
// Initialize the errors list
HashMap<ConfigError, Object> errors = new HashMap<ConfigError, Object>();
//TODO config version
// The order in this file should match the order in config.yml so that it's easy to check that everything is covered
// ********************* General *********************
Settings.metrics = plugin.getConfig().getBoolean("general.metrics", true);
Settings.checkUpdates = plugin.getConfig().getBoolean("general.check-updates", true);
loadLocales(plugin);
Settings.defaultLanguage = plugin.getConfig().getString("general.default-language", "en-US");
if(!plugin.getLocales().containsKey(Settings.defaultLanguage)) errors.put(ConfigError.UNKNOWN_LANGUAGE, Settings.defaultLanguage);
Settings.useEconomy = plugin.getConfig().getBoolean("general.use-economy", true);
Settings.startingMoney = plugin.getConfig().getDouble("general.starting-money", 10.0);
Settings.useControlPanel = plugin.getConfig().getBoolean("general.use-control-panel", true);
// Purge
Settings.purgeMaxIslandLevel = plugin.getConfig().getInt("general.purge.max-island-level", 50);
if(Settings.purgeMaxIslandLevel < 0) errors.put(ConfigError.PURGE_ISLAND_LEVEL_TOO_LOW, Settings.purgeMaxIslandLevel);
Settings.purgeRemoveUserData = plugin.getConfig().getBoolean("general.purge.remove-user-data", false);
// TODO Database
Settings.recoverSuperFlat = plugin.getConfig().getBoolean("general.recover-super-flat", false);
Settings.muteDeathMessages = plugin.getConfig().getBoolean("general.mute-death-messages", false);
Settings.ftbAutoActivator = plugin.getConfig().getBoolean("general.FTB-auto-activator", false);
Settings.allowObsidianScooping = plugin.getConfig().getBoolean("general.allow-obsidian-scooping", true);
// Allow teleport
Settings.fallingAllowTeleport = plugin.getConfig().getBoolean("general.allow-teleport.falling", true);
Settings.fallingBlockedCommands = plugin.getConfig().getStringList("general.allow-teleport.falling-blocked-commands");
Settings.acidAllowTeleport = plugin.getConfig().getBoolean("general.allow-teleport.acid", true);
Settings.acidBlockedCommands = plugin.getConfig().getStringList("general.allow-teleport.acid-blocked-commands");
// ********************* World *********************
Settings.worldName = plugin.getConfig().getString("world.world-name", "BSkyBlock");
//TODO check if it is the same than before
Settings.islandDistance = plugin.getConfig().getInt("world.distance", 200);
// TODO check if it is the same than before
if(Settings.islandDistance % 2 != 0) errors.put(ConfigError.NOT_EVEN_ISLAND_DISTANCE, Settings.islandDistance);
if(Settings.islandDistance < 50) errors.put(ConfigError.ISLAND_DISTANCE_TOO_LOW, Settings.islandDistance);
Settings.islandProtectionRange = plugin.getConfig().getInt("world.protection-range", 100);
if(Settings.islandProtectionRange % 2 != 0) errors.put(ConfigError.NOT_EVEN_PROTECTION_RANGE, Settings.islandProtectionRange);
if(Settings.islandProtectionRange < 0) errors.put(ConfigError.PROTECTION_RANGE_TOO_LOW, Settings.islandProtectionRange);
if(Settings.islandProtectionRange > Settings.islandDistance) errors.put(ConfigError.PROTECTION_RANGE_HIGHER_THAN_ISLAND_DISTANCE, Settings.islandProtectionRange);
Settings.startX = plugin.getConfig().getInt("world.start-x", 0);
Settings.startZ = plugin.getConfig().getInt("world.start-z", 0);
Settings.islandHeight = plugin.getConfig().getInt("world.island-height", 120);
if(Settings.islandHeight < 5) errors.put(ConfigError.ISLAND_HEIGHT_TOO_LOW, Settings.islandHeight);
Settings.seaHeight = plugin.getConfig().getInt("world.sea-height", 0);
Settings.maxIslands = plugin.getConfig().getInt("world.max-islands", 0);
// Nether
Settings.netherGenerate = plugin.getConfig().getBoolean("world.nether.generate", true);
Settings.netherIslands = plugin.getConfig().getBoolean("world.nether.islands", true);
Settings.netherTrees = plugin.getConfig().getBoolean("world.nether.trees", true);
Settings.netherRoof = plugin.getConfig().getBoolean("world.nether.roof", true);
Settings.netherSpawnRadius = plugin.getConfig().getInt("world.nether.spawn-radius", 25);
if(!Settings.netherIslands){
// If the nether is vanilla
if(Settings.netherSpawnRadius < 0) errors.put(ConfigError.NETHER_SPAWN_RADIUS_TOO_LOW, Settings.netherSpawnRadius);
if(Settings.netherSpawnRadius > 100) errors.put(ConfigError.NETHER_SPAWN_RADIUS_TOO_HIGH, Settings.netherSpawnRadius);
}
// Entities
//TODO end loading
//TODO not setup error report
return true;
}
public static void loadLocales(BSkyBlock plugin){
//TODO Imperatively load en-US locale
}
}

View File

@ -50,7 +50,7 @@ public class Settings {
/* WORLD */
public static String worldName;
public static int islandDistance;
public static int protectionRange;
public static int islandProtectionRange;
public static int startX;
public static int startZ;
public static int seaHeight;

View File

@ -98,7 +98,7 @@ public class IslandsManager {
* @param owner UUID
*/
public Island createIsland(Location location, UUID owner){
Island island = new Island(location, owner, Settings.protectionRange);
Island island = new Island(location, owner, Settings.islandProtectionRange);
islands.put(location, island);
if (owner != null)
islandsByUUID.put(owner, island);