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 mute-death-messages: false
# Allow FTB Autonomous Activator to work (will allow a pseudo player [CoFH] to place and break blocks and hang items) # 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 # 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) # 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-x: 0
start-z: 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) # Sea height (don't changes this mid-game unless you delete the world)
# Minimum is 0, which means you are playing Skyblock! # 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 sea height is less than about 10, then players will drop right through it
# if it exists. Makes for an interesting variation on skyblock. # if it exists. Makes for an interesting variation on skyblock.
sea-height: 0 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. # 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. # If the number of islands is greater than this number, no new island will be created.
max-islands: 0 max-islands: 0

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import us.tastybento.bskyblock.config.BSBLocale; import us.tastybento.bskyblock.config.BSBLocale;
import us.tastybento.bskyblock.config.PluginConfig;
import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.database.BSBDatabase; import us.tastybento.bskyblock.database.BSBDatabase;
import us.tastybento.bskyblock.database.IslandsManager; import us.tastybento.bskyblock.database.IslandsManager;
@ -36,6 +37,15 @@ public class BSkyBlock extends JavaPlugin{
@Override @Override
public void onEnable(){ public void onEnable(){
plugin = this; plugin = this;
if (!VaultHelper.setupPermissions()) {
getLogger().severe("Cannot link with Vault for permissions! Disabling plugin!");
getServer().getPluginManager().disablePlugin(this);
return;
}
// Load configuration and locales if the config don't have errors.
if(PluginConfig.loadPluginConfig(this)){
playersManager = new PlayersManager(this); playersManager = new PlayersManager(this);
islandsManager = new IslandsManager(this); islandsManager = new IslandsManager(this);
@ -49,11 +59,6 @@ public class BSkyBlock extends JavaPlugin{
getLogger().warning("Could not set up economy! - Running without an economy."); getLogger().warning("Could not set up economy! - Running without an economy.");
Settings.useEconomy = false; 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 // Only load metrics if set to true in config
if(Settings.metrics) metrics = new Metrics(this); if(Settings.metrics) metrics = new Metrics(this);
@ -74,6 +79,7 @@ public class BSkyBlock extends JavaPlugin{
} }
}, Settings.databaseBackupPeriod, Settings.databaseBackupPeriod); }, Settings.databaseBackupPeriod, Settings.databaseBackupPeriod);
} }
}
@Override @Override
public void onDisable(){ public void onDisable(){
@ -137,6 +143,14 @@ public class BSkyBlock extends JavaPlugin{
return locales; 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 * Returns the default locale
* @return the default locale * @return the default locale

View File

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

View File

@ -29,14 +29,14 @@ public class IslandCommand extends BSBCommand{
@Override @Override
public boolean canExecute(CommandSender sender, String label) { public boolean canExecute(CommandSender sender, String label) {
if(!(sender instanceof Player)){ 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; return false;
} }
Player player = (Player) sender; Player player = (Player) sender;
// Basic permission check to even use /island // Basic permission check to even use /island
if(!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.create")){ 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; return false;
} }
@ -113,8 +113,8 @@ public class IslandCommand extends BSBCommand{
@Override @Override
public String[] getHelp(CommandSender sender, String label){ public String[] getHelp(CommandSender sender, String label){
// TODO check if multiple homes // TODO check if multiple homes
if(VaultHelper.hasPerm((Player) sender, "todo")) return new String[] {"[1-x]", plugin.getLocale(sender).islandHelpGoHomes}; 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).islandHelpGo}; return new String[] {null, plugin.getLocale(sender).get("help.island.go")};
} }
}); });
@ -140,7 +140,7 @@ public class IslandCommand extends BSBCommand{
@Override @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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; Player player = (Player) sender;
if(!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.name")){ 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; return false;
} }
if(!plugin.getIslands().hasIsland(player.getUniqueId())){ 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; return false;
} }
if(!plugin.getIslands().isOwner(player.getUniqueId())){ 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; return false;
} }
@ -322,11 +322,11 @@ public class IslandCommand extends BSBCommand{
// Check if the name isn't too short or too long // Check if the name isn't too short or too long
if(name.length() < Settings.nameMinLength){ 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; return;
} }
if(name.length() > Settings.nameMaxLength){ 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; 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)); 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); 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 @Override
@ -344,7 +344,7 @@ public class IslandCommand extends BSBCommand{
@Override @Override
public String[] getHelp(CommandSender sender, String label){ 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; Player player = (Player) sender;
if(!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.name")){ 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; return false;
} }
if(!plugin.getIslands().hasIsland(player.getUniqueId())){ 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; return false;
} }
if(!plugin.getIslands().isOwner(player.getUniqueId())){ 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; return false;
} }
@ -379,7 +379,7 @@ public class IslandCommand extends BSBCommand{
// Resets the island name // Resets the island name
plugin.getIslands().getIsland(player.getUniqueId()).setName(null); 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 @Override
@ -389,7 +389,7 @@ public class IslandCommand extends BSBCommand{
@Override @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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; Player player = (Player) sender;
if(!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.lock")){ 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; return false;
} }
if(!plugin.getIslands().hasIsland(player.getUniqueId())){ 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; return false;
} }
@ -1015,9 +1015,9 @@ public class IslandCommand extends BSBCommand{
if(!island.isLocked()){ if(!island.isLocked()){
// TODO: Expel all visitors // TODO: Expel all visitors
// TODO: send offline messages // TODO: send offline messages
island.setLocked(false); island.setLocked(true);
} else { } 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 // TODO: send offline messages
island.setLocked(false); island.setLocked(false);
} }
@ -1030,7 +1030,7 @@ public class IslandCommand extends BSBCommand{
@Override @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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 @Override
public String[] getHelp(CommandSender sender, String label){ 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; package us.tastybento.bskyblock.config;
import java.io.File; import java.io.File;
import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import us.tastybento.bskyblock.BSkyBlock; 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 Tastybento
* @author Poslovitch * @author Poslovitch
@ -33,7 +34,6 @@ public class BSBLocale {
this.plugin = plugin; this.plugin = plugin;
this.localeID = localeID; this.localeID = localeID;
getLocale(localeID); getLocale(localeID);
loadLocale();
localeObject = new Locale(localeID.substring(0, 2), localeID.substring(3, 5)); localeObject = new Locale(localeID.substring(0, 2), localeID.substring(3, 5));
} }
@ -104,95 +104,15 @@ public class BSBLocale {
} }
/* Localization */ /* Localization */
private HashMap<String, String> localization = new HashMap<String, String>();
// Not Setup public String get(String id){
public String notSetupHeader; // If the text isn't loaded, load it.
public String notSetupDistance; if(!localization.containsKey(id)){
public String notSetupGenerator; // Save the text to the HashMap.
public String notSetupGeneratorMultiverse; // If the text doesn't exist in the locale file, save it as its id, to help debug.
public String notSetupWorldname; localization.put(id, locale.getString(id, id));
public String notSetupOutdated; }
return localization.get(id);
// 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."));
} }
} }

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; package us.tastybento.bskyblock.config;
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 { 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 */ /* WORLD */
public static String worldName; public static String worldName;
public static int islandDistance; public static int islandDistance;
public static int protectionRange; public static int islandProtectionRange;
public static int startX; public static int startX;
public static int startZ; public static int startZ;
public static int seaHeight; public static int seaHeight;

View File

@ -98,7 +98,7 @@ public class IslandsManager {
* @param owner UUID * @param owner UUID
*/ */
public Island createIsland(Location location, UUID owner){ 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); islands.put(location, island);
if (owner != null) if (owner != null)
islandsByUUID.put(owner, island); islandsByUUID.put(owner, island);