Converted to using the Settings loaded by the database handler.

Removed a lot of static references.

Constants have their own class.
This commit is contained in:
Tastybento 2018-01-06 15:23:01 -08:00
parent 2d447afa88
commit 92af75e602
55 changed files with 1447 additions and 1822 deletions

View File

@ -7,7 +7,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import us.tastybento.bskyblock.commands.AdminCommand;
import us.tastybento.bskyblock.commands.IslandCommand;
import us.tastybento.bskyblock.config.PluginConfig;
import us.tastybento.bskyblock.database.BSBDatabase;
import us.tastybento.bskyblock.database.managers.PlayersManager;
import us.tastybento.bskyblock.database.managers.island.IslandsManager;
@ -40,79 +39,82 @@ public class BSkyBlock extends JavaPlugin {
private LocalesManager localesManager;
private AddonsManager addonsManager;
private FlagsManager flagsManager;
private IslandWorld islandWorldManager;
// Settings
Settings settings;
@Override
public void onEnable(){
plugin = this;
// Load config - EXPERIMENTAL
Settings2 config = new Settings2();
settings = new Settings();
try {
//config.saveConfig(); // works, but will wipe out comments
config = config.loadConfig();
getLogger().info("DEBUG: island distance = " + config.getIslandDistance());
settings = settings.loadSettings();
getLogger().info("DEBUG: island distance = " + settings.getIslandDistance());
} catch (Exception e) {
e.printStackTrace();
}
// Load configuration and locales. If there are no errors, load the plugin.
if(PluginConfig.loadPluginConfig(this)){
playersManager = new PlayersManager(this);
islandsManager = new IslandsManager(this);
// Load metrics
metrics = new Metrics(plugin);
registerCustomCharts();
playersManager = new PlayersManager(this);
islandsManager = new IslandsManager(this);
// Set up commands
commandsManager = new CommandsManager();
new IslandCommand();
new AdminCommand();
// Load metrics
metrics = new Metrics(plugin);
registerCustomCharts();
// These items have to be loaded when the server has done 1 tick.
// Note Worlds are not loaded this early, so any Locations or World reference will be null
// at this point. Therefore, the 1 tick scheduler is required.
getServer().getScheduler().runTask(this, new Runnable() {
// Set up commands
commandsManager = new CommandsManager();
new IslandCommand();
new AdminCommand();
@Override
public void run() {
// Create the world if it does not exist
new IslandWorld(plugin);
getServer().getScheduler().runTask(plugin, new Runnable() {
// These items have to be loaded when the server has done 1 tick.
// Note Worlds are not loaded this early, so any Locations or World reference will be null
// at this point. Therefore, the 1 tick scheduler is required.
getServer().getScheduler().runTask(this, new Runnable() {
@Override
public void run() {
// Load islands from database
islandsManager.load();
@Override
public void run() {
// Create the world if it does not exist
islandWorldManager = new IslandWorld(plugin);
// TODO: load these from config.yml
Settings.chestItems = new ItemStack[] {
new ItemStack(Material.LAVA_BUCKET,1),
new ItemStack(Material.ICE,2),
new ItemStack(Material.MELON_SEEDS,1),
new ItemStack(Material.BONE,2),
new ItemStack(Material.COBBLESTONE,5),
new ItemStack(Material.SAPLING,2)
};
getServer().getScheduler().runTask(plugin, new Runnable() {
Settings.defaultLanguage = "en-US";
localesManager = new LocalesManager(plugin);
//TODO localesManager.registerLocales(plugin);
@Override
public void run() {
// Load islands from database
islandsManager.load();
// Register Listeners
registerListeners();
// TODO: load these from config.yml
getSettings().setChestItems(new ItemStack[] {
new ItemStack(Material.LAVA_BUCKET,1),
new ItemStack(Material.ICE,2),
new ItemStack(Material.MELON_SEEDS,1),
new ItemStack(Material.BONE,2),
new ItemStack(Material.COBBLESTONE,5),
new ItemStack(Material.SAPLING,2)
});
// Load Flags
flagsManager = new FlagsManager();
//getSettings().setDefaultLanguage("en-US");
plugin.getLogger().info("DEBUG: ************************** Loading Locales **************************");
localesManager = new LocalesManager(plugin);
//TODO localesManager.registerLocales(plugin);
// Load addons
addonsManager = new AddonsManager(plugin);
addonsManager.enableAddons();
// Register Listeners
registerListeners();
/*
*DEBUG CODE
// Load Flags
flagsManager = new FlagsManager();
// Load addons
addonsManager = new AddonsManager(plugin);
addonsManager.enableAddons();
/*
*DEBUG CODE
Island loadedIsland = islandsManager.getIsland(owner);
getLogger().info("Island name = " + loadedIsland.getName());
getLogger().info("Island locked = " + loadedIsland.getLocked());
@ -121,24 +123,25 @@ public class BSkyBlock extends JavaPlugin {
for (Entry<SettingsFlag, Boolean> flag: loadedIsland.getFlags().entrySet()) {
getLogger().info("Flag " + flag.getKey().name() + " = " + flag.getValue());
}
*/
// Save islands & players data asynchronously every X minutes
Settings.databaseBackupPeriod = 10 * 60 * 20;
plugin.getServer().getScheduler().runTaskTimer(plugin, new Runnable() {
*/
// Save islands & players data asynchronously every X minutes
getSettings().setDatabaseBackupPeriod(10 * 60 * 20);
plugin.getServer().getScheduler().runTaskTimer(plugin, new Runnable() {
@Override
public void run() {
playersManager.save(true);
islandsManager.save(true);
}
}, Settings.databaseBackupPeriod, Settings.databaseBackupPeriod);
}
});
}
});
}
@Override
public void run() {
playersManager.save(true);
islandsManager.save(true);
}
}, getSettings().getDatabaseBackupPeriod(), getSettings().getDatabaseBackupPeriod());
}
});
}
});
}
private void registerListeners() {
PluginManager manager = getServer().getPluginManager();
// Player join events
@ -177,7 +180,7 @@ public class BSkyBlock extends JavaPlugin {
@Override
public String getValue() {
return Settings.defaultLanguage;
return getSettings().getDefaultLanguage();
}
});
@ -185,7 +188,7 @@ public class BSkyBlock extends JavaPlugin {
@Override
public String getValue() {
return BSBDatabase.getDatabase().toString();
return BSBDatabase.getDatabase(plugin).toString();
}
});
}
@ -238,4 +241,19 @@ public class BSkyBlock extends JavaPlugin {
return flagsManager;
}
/**
* @return the settings
*/
public Settings getSettings() {
return settings;
}
/**
* @return the Island World Manager
*/
public IslandWorld getIslandWorldManager() {
return islandWorldManager;
}
}

View File

@ -0,0 +1,38 @@
package us.tastybento.bskyblock;
import us.tastybento.bskyblock.api.configuration.ConfigEntry.GameType;
/**
* All the plugin settings are here
* @author Tastybento
*/
public class Constants {
// ----------------- Constants -----------------
/*
public final static GameType GAMETYPE = GameType.ACIDISLAND;
// The spawn command (Essentials spawn for example)
public final static String SPAWNCOMMAND = "spawn";
// Permission prefix
public final static String PERMPREFIX = "acidisland.";
// The island command
public final static String ISLANDCOMMAND = "ai";
// The challenge command
public static final String CHALLENGECOMMAND = "aic";
// Admin command
public static final String ADMINCOMMAND = "acid";
*/
public final static GameType GAMETYPE = GameType.BSKYBLOCK;
// Permission prefix
public final static String PERMPREFIX = "bskyblock.";
// The island command
public final static String ISLANDCOMMAND = "island";
// The challenge command
public static final String CHALLENGECOMMAND = "bsc";
// The spawn command (Essentials spawn for example)
public final static String SPAWNCOMMAND = "spawn";
// Admin command
public static final String ADMINCOMMAND = "bsadmin";
}

View File

@ -1,25 +0,0 @@
/**
*
*/
package us.tastybento.bskyblock;
import org.bukkit.Bukkit;
/**
* @author ben
* Takes in inputs and turns them into an enum
*/
public class EnumAdapter {
/**
* Takes in inputs and turns them into an enum of type
* @param input
* @param type
* @return
*/
public Object adapt(Object input, Object type) {
Bukkit.getLogger().info("Ran the EnumAdapter: input is " + input + " and type = " + type);
return Enum.valueOf((Class)type, (String)input);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -17,6 +17,7 @@ import org.bukkit.command.PluginIdentifiableCommand;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.api.events.command.CommandEvent;
import us.tastybento.bskyblock.database.managers.PlayersManager;
import us.tastybento.bskyblock.database.managers.island.IslandsManager;
@ -59,6 +60,23 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
*/
private String usage;
/**
* Used only for testing....
*/
public CompositeCommand(BSkyBlock plugin, String label, String... string) {
super(label);
this.setAliases(new ArrayList<>(Arrays.asList(string)));
this.parent = null;
setUsage("");
this.subCommandLevel = 0; // Top level
this.subCommands = new LinkedHashMap<>();
this.setup();
if (!this.getSubCommand("help").isPresent() && !label.equals("help"))
new DefaultHelpCommand(this);
}
/**
* Sub-command constructor
* @param parent - the parent composite command
@ -83,7 +101,6 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
Bukkit.getLogger().info("DEBUG: registering command " + label);
}
/**
* This is the top-level command constructor for commands that have no parent.
* @param label - string for this command
@ -108,22 +125,6 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
}
/**
* Used only for testing....
*/
public CompositeCommand(BSkyBlock plugin, String label, String... string) {
super(label);
this.setAliases(new ArrayList<>(Arrays.asList(string)));
this.parent = null;
setUsage("");
this.subCommandLevel = 0; // Top level
this.subCommands = new LinkedHashMap<>();
this.setup();
if (!this.getSubCommand("help").isPresent() && !label.equals("help"))
new DefaultHelpCommand(this);
}
/*
* This method deals with the command execution. It traverses the tree of
@ -227,6 +228,10 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
return getPlugin().getIslands().getMembers(user.getUniqueId());
}
public String getParameters() {
return parameters;
}
/**
* @return the parent command object
*/
@ -246,12 +251,20 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
protected PlayersManager getPlayers() {
return getPlugin().getPlayers();
}
@Override
public BSkyBlock getPlugin() {
return BSkyBlock.getInstance();
}
/**
* @return Settings object
*/
public Settings getSettings() {
return getPlugin().getSettings();
}
/**
* Returns the CompositeCommand object refering to this command label
* @param label - command label or alias
@ -264,6 +277,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
}
return Optional.empty();
}
/**
* @return Map of sub commands for this command
@ -272,7 +286,6 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
return subCommands;
}
/**
* Convenience method to obtain the user's team leader
* @param user
@ -282,41 +295,11 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
return getPlugin().getIslands().getTeamLeader(user.getUniqueId());
}
public void setparameters(String parameters) {
this.setParameters(parameters);
}
@Override
public String getUsage() {
return "/" + usage;
}
/**
* This creates the full linking chain of commands
*/
@Override
public Command setUsage(String usage) {
// Go up the chain
CompositeCommand parent = this.getParent();
this.usage = this.getLabel() + " " + usage;
while (parent != null) {
this.usage = parent.getLabel() + " " + this.usage;
parent = parent.getParent();
}
this.usage = this.usage.trim();
return this;
}
public String getParameters() {
return parameters;
}
public void setParameters(String parameters) {
this.parameters = parameters;
}
/**
* Check if this command has a specific sub command
* @param subCommand
@ -326,6 +309,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
return subCommands.containsKey(subCommand);
}
/**
* Check if this command has any sub commands
* @return true if this command has subcommands
@ -368,11 +352,35 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
this.onlyPlayer = onlyPlayer;
}
public void setparameters(String parameters) {
this.setParameters(parameters);
}
public void setParameters(String parameters) {
this.parameters = parameters;
}
@Override
public void setPermission(String permission) {
this.permission = permission;
}
/**
* This creates the full linking chain of commands
*/
@Override
public Command setUsage(String usage) {
// Go up the chain
CompositeCommand parent = this.getParent();
this.usage = this.getLabel() + " " + usage;
while (parent != null) {
this.usage = parent.getLabel() + " " + this.usage;
parent = parent.getParent();
}
this.usage = this.usage.trim();
return this;
}
@Override
public List<String> tabComplete(final CommandSender sender, final String alias, final String[] args) {
List<String> options = new ArrayList<>();

View File

@ -17,7 +17,6 @@ import org.bukkit.inventory.PlayerInventory;
import org.bukkit.permissions.PermissionAttachmentInfo;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Settings;
/**
* BSB's user object. Wraps Player.
@ -255,7 +254,7 @@ public class User {
if (!plugin.getPlayers().getLocale(this.playerUUID).isEmpty())
return Locale.forLanguageTag(plugin.getPlayers().getLocale(this.playerUUID));
}
return Locale.forLanguageTag(Settings.defaultLanguage);
return Locale.forLanguageTag(plugin.getSettings().getDefaultLanguage());
}
}

View File

@ -5,7 +5,7 @@ import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Settings2;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.database.flatfile.FlatFileDatabase;
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
@ -19,7 +19,7 @@ public interface ISettings<T> {
// ----------------Saver-------------------
@SuppressWarnings("unchecked")
public default void saveConfig(T instance) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, IntrospectionException, SQLException {
default void saveConfig(T instance) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, IntrospectionException, SQLException {
// Get the handler
AbstractDatabaseHandler<T> configHandler = (AbstractDatabaseHandler<T>) new FlatFileDatabase().getHandler(BSkyBlock.getInstance(), instance.getClass());
// Load every field in the config class
@ -27,9 +27,9 @@ public interface ISettings<T> {
}
// --------------- Loader ------------------
@SuppressWarnings("unchecked")
public default Settings2 loadConfig() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, ClassNotFoundException, IntrospectionException, SQLException {
default Settings loadSettings() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, ClassNotFoundException, IntrospectionException, SQLException {
// Get the handler
AbstractDatabaseHandler<Settings2> configHandler = (AbstractDatabaseHandler<Settings2>) new FlatFileDatabase().getHandler(BSkyBlock.getInstance(), Settings2.class);
AbstractDatabaseHandler<Settings> configHandler = (AbstractDatabaseHandler<Settings>) new FlatFileDatabase().getHandler(BSkyBlock.getInstance(), Settings.class);
// Load every field in the config class
return configHandler.loadObject("config");
}

View File

@ -3,6 +3,7 @@ package us.tastybento.bskyblock.api.events.command;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Cancellable;
import us.tastybento.bskyblock.api.events.PremadeEvent;
/**

View File

@ -4,6 +4,7 @@ import java.util.List;
import java.util.UUID;
import org.bukkit.event.Cancellable;
import us.tastybento.bskyblock.api.events.PremadeEvent;
/**

View File

@ -1,10 +1,11 @@
package us.tastybento.bskyblock.api.flags;
import org.bukkit.event.Listener;
import us.tastybento.bskyblock.api.panels.PanelItem;
import java.util.Optional;
import org.bukkit.event.Listener;
import us.tastybento.bskyblock.api.panels.PanelItem;
public class Flag {
private String id;

View File

@ -1,10 +1,11 @@
package us.tastybento.bskyblock.api.flags;
import org.bukkit.event.Listener;
import us.tastybento.bskyblock.api.panels.PanelItem;
import java.util.Optional;
import org.bukkit.event.Listener;
import us.tastybento.bskyblock.api.panels.PanelItem;
public class FlagBuilder {
private String id;

View File

@ -1,11 +1,8 @@
package us.tastybento.bskyblock.api.localization;
import java.io.File;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.YamlConfiguration;
/**

View File

@ -2,7 +2,7 @@ package us.tastybento.bskyblock.commands;
import java.util.List;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.commands.admin.AdminReloadCommand;
@ -11,12 +11,12 @@ import us.tastybento.bskyblock.commands.admin.AdminVersionCommand;
public class AdminCommand extends CompositeCommand {
public AdminCommand() {
super(Settings.ADMINCOMMAND, "bsb");
super(Constants.ADMINCOMMAND, "bsb");
}
@Override
public void setup() {
this.setPermission(Settings.PERMPREFIX + "admin.*");
this.setPermission(Constants.PERMPREFIX + "admin.*");
this.setOnlyPlayer(false);
this.setDescription("admin.help.description");
new AdminVersionCommand(this);

View File

@ -2,6 +2,7 @@ package us.tastybento.bskyblock.commands;
import java.util.List;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.commands.island.IslandAboutCommand;
@ -12,12 +13,11 @@ import us.tastybento.bskyblock.commands.island.IslandResetnameCommand;
import us.tastybento.bskyblock.commands.island.IslandSethomeCommand;
import us.tastybento.bskyblock.commands.island.IslandSetnameCommand;
import us.tastybento.bskyblock.commands.island.teams.IslandTeamCommand;
import us.tastybento.bskyblock.Settings;
public class IslandCommand extends CompositeCommand {
public IslandCommand() {
super(Settings.ISLANDCOMMAND, "is");
super(Constants.ISLANDCOMMAND, "is");
}
/* (non-Javadoc)
@ -28,7 +28,7 @@ public class IslandCommand extends CompositeCommand {
this.setDescription("commands.island.help.description");
this.setOnlyPlayer(true);
// Permission
this.setPermission(Settings.PERMPREFIX + "island");
this.setPermission(Constants.PERMPREFIX + "island");
// Set up subcommands
new IslandAboutCommand(this);
new IslandCreateCommand(this);

View File

@ -7,7 +7,6 @@ import java.util.List;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.ConfigLoader;
/**
* @author ben
@ -38,7 +37,6 @@ public class AdminReloadCommand extends CompositeCommand {
*/
@Override
public boolean execute(User user, List<String> args) {
new ConfigLoader();
return true;
}

View File

@ -2,9 +2,9 @@ package us.tastybento.bskyblock.commands.admin;
import java.util.List;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.Settings;
public class AdminVersionCommand extends CompositeCommand {
@ -15,7 +15,7 @@ public class AdminVersionCommand extends CompositeCommand {
@Override
public void setup() {
// Permission
this.setPermission(Settings.PERMPREFIX + "admin.version");
this.setPermission(Constants.PERMPREFIX + "admin.version");
}
@Override

View File

@ -2,9 +2,9 @@ package us.tastybento.bskyblock.commands.island;
import java.util.List;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.util.Util;
/**
@ -40,7 +40,7 @@ public class CustomIslandMultiHomeHelp extends CompositeCommand {
String desc = getDescription().isEmpty() ? "" : user.getTranslation(getDescription());
// Player. Check perms
if (user.hasPermission(getPermission())) {
int maxHomes = Util.getPermValue(user.getPlayer(), Settings.PERMPREFIX + "island.maxhomes", Settings.maxHomes);
int maxHomes = Util.getPermValue(user.getPlayer(), Constants.PERMPREFIX + "island.maxhomes", getSettings().getMaxHomes());
if (maxHomes > 1) {
params = getParameters().isEmpty() ? "" : user.getTranslation(getParameters());
user.sendMessage("commands.help.syntax", "[usage]", usage, "[parameters]", params, "[description]", desc);

View File

@ -6,11 +6,11 @@ package us.tastybento.bskyblock.commands.island;
import java.io.IOException;
import java.util.List;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
import us.tastybento.bskyblock.commands.IslandCommand;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.database.managers.island.NewIsland;
/**
@ -26,7 +26,7 @@ public class IslandCreateCommand extends CompositeCommand {
@Override
public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.create");
this.setPermission(Constants.PERMPREFIX + "island.create");
this.setOnlyPlayer(true);
this.setDescription("commands.island.create.description");
}
@ -55,7 +55,7 @@ public class IslandCreateCommand extends CompositeCommand {
*/
protected void createIsland(User user) {
try {
NewIsland.builder()
NewIsland.builder(getPlugin())
.player(user.getPlayer())
.reason(Reason.CREATE)
.build();

View File

@ -8,10 +8,10 @@ import java.util.List;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.ChatColor;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.commands.IslandCommand;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.util.Util;
/**
@ -26,7 +26,7 @@ public class IslandGoCommand extends CompositeCommand {
@Override
public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.home");
this.setPermission(Constants.PERMPREFIX + "island.home");
this.setOnlyPlayer(true);
this.setDescription("commands.island.go.description");
new CustomIslandMultiHomeHelp(this);
@ -43,7 +43,7 @@ public class IslandGoCommand extends CompositeCommand {
}
if (!args.isEmpty() && NumberUtils.isDigits(args.get(0))) {
int homeValue = Integer.valueOf(args.get(0));
int maxHomes = Util.getPermValue(user.getPlayer(), Settings.PERMPREFIX + "island.maxhomes", Settings.maxHomes);
int maxHomes = Util.getPermValue(user.getPlayer(), Constants.PERMPREFIX + "island.maxhomes", getSettings().getMaxHomes());
if (homeValue > 1 && homeValue <= maxHomes) {
getIslands().homeTeleport(user.getPlayer(), homeValue);
return true;

View File

@ -6,10 +6,10 @@ import java.util.List;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.database.managers.island.NewIsland;
import us.tastybento.bskyblock.database.objects.Island;
@ -23,7 +23,7 @@ public class IslandResetCommand extends CompositeCommand {
@Override
public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.create");
this.setPermission(Constants.PERMPREFIX + "island.create");
this.setOnlyPlayer(true);
this.setDescription("commands.island.reset.description");
}
@ -56,7 +56,7 @@ public class IslandResetCommand extends CompositeCommand {
if (DEBUG)
getPlugin().getLogger().info("DEBUG: making new island ");
try {
NewIsland.builder()
NewIsland.builder(getPlugin())
.player(player)
.reason(Reason.RESET)
.oldIsland(oldIsland)

View File

@ -6,9 +6,9 @@ package us.tastybento.bskyblock.commands.island;
import java.util.List;
import java.util.UUID;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.Settings;
/**
* @author tastybento
@ -22,7 +22,7 @@ public class IslandResetnameCommand extends CompositeCommand {
@Override
public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.name");
this.setPermission(Constants.PERMPREFIX + "island.name");
this.setOnlyPlayer(true);
this.setDescription("commands.island.resetname.description");

View File

@ -3,9 +3,9 @@ package us.tastybento.bskyblock.commands.island;
import java.util.List;
import java.util.UUID;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.util.Util;
public class IslandSethomeCommand extends CompositeCommand {
@ -16,7 +16,7 @@ public class IslandSethomeCommand extends CompositeCommand {
@Override
public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.sethome");
this.setPermission(Constants.PERMPREFIX + "island.sethome");
this.setOnlyPlayer(true);
this.setDescription("commands.island.sethome.description");
new CustomIslandMultiHomeHelp(this);
@ -40,7 +40,7 @@ public class IslandSethomeCommand extends CompositeCommand {
user.sendMessage("commands.island.sethome.home-set");
} else {
// Dynamic home sizes with permissions
int maxHomes = Util.getPermValue(user.getPlayer(), Settings.PERMPREFIX + "island.maxhomes", Settings.maxHomes);
int maxHomes = Util.getPermValue(user.getPlayer(), Constants.PERMPREFIX + "island.maxhomes", getSettings().getMaxHomes());
if (maxHomes > 1) {
// Check the number given is a number
int number = 0;

View File

@ -10,9 +10,9 @@ import java.util.stream.Collectors;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.Settings;
/**
* @author tastybento
@ -26,7 +26,7 @@ public class IslandSetnameCommand extends CompositeCommand {
@Override
public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.name");
this.setPermission(Constants.PERMPREFIX + "island.name");
this.setOnlyPlayer(true);
this.setParameters("commands.island.setname.parameters");
this.setDescription("commands.island.setname.description");
@ -59,17 +59,17 @@ public class IslandSetnameCommand extends CompositeCommand {
String name = args.stream().collect(Collectors.joining( " " ));
// Check if the name isn't too short or too long
if (name.length() < Settings.nameMinLength) {
user.sendMessage("commands.island.setname.too-short", "[length]", String.valueOf(Settings.nameMinLength));
if (name.length() < getSettings().getNameMinLength()) {
user.sendMessage("commands.island.setname.too-short", "[length]", String.valueOf(getSettings().getNameMinLength()));
return true;
}
if (name.length() > Settings.nameMaxLength) {
user.sendMessage("commands.island.setname.too-long", "[length]", String.valueOf(Settings.nameMaxLength));
if (name.length() > getSettings().getNameMaxLength()) {
user.sendMessage("commands.island.setname.too-long", "[length]", String.valueOf(getSettings().getNameMaxLength()));
return true;
}
// Set the name
if (!player.hasPermission(Settings.PERMPREFIX + "island.name.format"))
if (!player.hasPermission(Constants.PERMPREFIX + "island.name.format"))
getIslands().getIsland(player.getUniqueId()).setName(ChatColor.translateAlternateColorCodes('&', name));
else getIslands().getIsland(playerUUID).setName(name);

View File

@ -13,7 +13,6 @@ import com.google.common.collect.HashBiMap;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.Settings;
/**
* A safe common space for team commands to share data
@ -42,6 +41,6 @@ public abstract class AbstractIslandTeamCommand extends CompositeCommand {
* @param player
*/
protected void setResetWaitTime(final Player player) {
resetWaitTime.put(player.getUniqueId(), Calendar.getInstance().getTimeInMillis() + Settings.resetWait * 1000);
resetWaitTime.put(player.getUniqueId(), Calendar.getInstance().getTimeInMillis() + getSettings().getResetWait() * 1000);
}
}

View File

@ -7,11 +7,11 @@ import java.util.UUID;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.permissions.PermissionAttachmentInfo;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.Settings;
public class IslandTeamCommand extends AbstractIslandTeamCommand {
@ -23,7 +23,7 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand {
@Override
public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.team");
this.setPermission(Constants.PERMPREFIX + "island.team");
this.setOnlyPlayer(true);
this.setDescription("commands.island.team.description");
@ -50,15 +50,15 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand {
UUID teamLeaderUUID = getTeamLeader(user);
Set<UUID> teamMembers = getMembers(user);
if (teamLeaderUUID.equals(playerUUID)) {
int maxSize = Settings.maxTeamSize;
int maxSize = getSettings().getMaxTeamSize();
for (PermissionAttachmentInfo perms : user.getEffectivePermissions()) {
if (perms.getPermission().startsWith(Settings.PERMPREFIX + "team.maxsize.")) {
if (perms.getPermission().contains(Settings.PERMPREFIX + "team.maxsize.*")) {
maxSize = Settings.maxTeamSize;
if (perms.getPermission().startsWith(Constants.PERMPREFIX + "team.maxsize.")) {
if (perms.getPermission().contains(Constants.PERMPREFIX + "team.maxsize.*")) {
maxSize = getSettings().getMaxTeamSize();
break;
} else {
// Get the max value should there be more than one
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "team.maxsize.");
String[] spl = perms.getPermission().split(Constants.PERMPREFIX + "team.maxsize.");
if (spl.length > 1) {
if (!NumberUtils.isDigits(spl[1])) {
getPlugin().getLogger().severe("Player " + user.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");

View File

@ -7,10 +7,10 @@ import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.database.objects.Island;
public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
@ -21,7 +21,7 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
@Override
public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.team");
this.setPermission(Constants.PERMPREFIX + "island.team");
this.setOnlyPlayer(true);
this.setDescription("commands.island.team.invite.accept.description");
}
@ -88,13 +88,13 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
// Set the cooldown
setResetWaitTime(user.getPlayer());
// Reset deaths
if (Settings.teamJoinDeathReset) {
if (getSettings().isTeamJoinDeathReset()) {
getPlayers().setDeaths(playerUUID, 0);
}
// Put player back into normal mode
user.setGameMode(GameMode.SURVIVAL);
user.sendMessage("commands.island.team.invite.accept.you-joined-island", "[label]", Settings.ISLANDCOMMAND);
user.sendMessage("commands.island.team.invite.accept.you-joined-island", "[label]", Constants.ISLANDCOMMAND);
User inviter = User.getInstance(inviteList.get(playerUUID));
if (inviter != null) {
inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", "[name]", user.getName());

View File

@ -11,10 +11,10 @@ import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.OfflinePlayer;
import org.bukkit.permissions.PermissionAttachmentInfo;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.util.Util;
public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
@ -25,7 +25,7 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
@Override
public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.team");
this.setPermission(Constants.PERMPREFIX + "island.team");
this.setOnlyPlayer(true);
this.setDescription("commands.island.team.invite.description");
@ -84,16 +84,16 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
}
Set<UUID> teamMembers = getMembers(user);
// Check if player has space on their team
int maxSize = Settings.maxTeamSize;
int maxSize = getSettings().getMaxTeamSize();
// Dynamic team sizes with permissions
for (PermissionAttachmentInfo perms : user.getEffectivePermissions()) {
if (perms.getPermission().startsWith(Settings.PERMPREFIX + "team.maxsize.")) {
if (perms.getPermission().contains(Settings.PERMPREFIX + "team.maxsize.*")) {
maxSize = Settings.maxTeamSize;
if (perms.getPermission().startsWith(Constants.PERMPREFIX + "team.maxsize.")) {
if (perms.getPermission().contains(Constants.PERMPREFIX + "team.maxsize.*")) {
maxSize = getSettings().getMaxTeamSize();
break;
} else {
// Get the max value should there be more than one
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "team.maxsize.");
String[] spl = perms.getPermission().split(Constants.PERMPREFIX + "team.maxsize.");
if (spl.length > 1) {
if (!NumberUtils.isDigits(spl[1])) {
getPlugin().getLogger().severe("Player " + user.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");

View File

@ -3,10 +3,10 @@ package us.tastybento.bskyblock.commands.island.teams;
import java.util.List;
import java.util.UUID;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.Settings;
public class IslandTeamInviteRejectCommand extends AbstractIslandTeamCommand {
@ -16,7 +16,7 @@ public class IslandTeamInviteRejectCommand extends AbstractIslandTeamCommand {
@Override
public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.team");
this.setPermission(Constants.PERMPREFIX + "island.team");
this.setOnlyPlayer(true);
this.setDescription("commands.island.team.invite.reject.description");
}

View File

@ -2,8 +2,8 @@ package us.tastybento.bskyblock.commands.island.teams;
import java.util.List;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.Settings;
public class IslandTeamLeaveCommand extends AbstractIslandTeamCommand {
@ -13,7 +13,7 @@ public class IslandTeamLeaveCommand extends AbstractIslandTeamCommand {
@Override
public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.team");
this.setPermission(Constants.PERMPREFIX + "island.team");
this.setOnlyPlayer(true);
this.setDescription("commands.island.team.leave.description");

View File

@ -2,8 +2,8 @@ package us.tastybento.bskyblock.commands.island.teams;
import java.util.List;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.Settings;
public class IslandTeamPromoteCommand extends AbstractIslandTeamCommand {
@ -13,7 +13,7 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommand {
@Override
public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.team");
this.setPermission(Constants.PERMPREFIX + "island.team");
this.setOnlyPlayer(true);
this.setParameters("commands.island.team.promote.parameters");
this.setDescription("commands.island.team.promote.description");

View File

@ -9,10 +9,10 @@ import java.util.UUID;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.permissions.PermissionAttachmentInfo;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.util.Util;
@ -24,7 +24,7 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
@Override
public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.team");
this.setPermission(Constants.PERMPREFIX + "island.team");
this.setOnlyPlayer(true);
this.setParameters("commands.island.team.setowner.parameters");
this.setDescription("commands.island.team.setowner.description");
@ -81,7 +81,7 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
if (target.isOnline()) {
// Check if new leader has a lower range permission than the island size
boolean hasARangePerm = false;
int range = Settings.islandProtectionRange;
int range = getSettings().getIslandProtectionRange();
// Check for zero protection range
Island islandByOwner = getIslands().getIsland(targetUUID);
if (islandByOwner.getProtectionRange() == 0) {
@ -89,12 +89,12 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
islandByOwner.setProtectionRange(range);
}
for (PermissionAttachmentInfo perms : target.getEffectivePermissions()) {
if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.range.")) {
if (perms.getPermission().contains(Settings.PERMPREFIX + "island.range.*")) {
if (perms.getPermission().startsWith(Constants.PERMPREFIX + "island.range.")) {
if (perms.getPermission().contains(Constants.PERMPREFIX + "island.range.*")) {
// Ignore
break;
} else {
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.range.");
String[] spl = perms.getPermission().split(Constants.PERMPREFIX + "island.range.");
if (spl.length > 1) {
if (!NumberUtils.isDigits(spl[1])) {
getPlugin().getLogger().severe("Player " + user.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");

View File

@ -1,69 +0,0 @@
package us.tastybento.bskyblock.config;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.bukkit.Bukkit;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.api.configuration.ConfigEntry;
import us.tastybento.bskyblock.api.configuration.ConfigEntry.GameType;
import us.tastybento.bskyblock.api.configuration.ConfigEntry.NoAdapter;
public class ConfigLoader {
public ConfigLoader() {
try {
getAnnotations(Settings.class);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void getAnnotations(Class<Settings> clazz) throws IllegalArgumentException, IllegalAccessException, NoSuchMethodException, SecurityException, InvocationTargetException, InstantiationException{
for(Field field : clazz.getDeclaredFields()){
Class<?> type = field.getType();
String name = field.getName();
ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class);
// If there is a config annotation then do something
if (configEntry != null) {
// Get the current value
Object currentvalue = field.get(null);
// Get the setting as defined in the config file
Object configValue = BSkyBlock.getInstance().getConfig().get(configEntry.path());
// If this setting is for use in this game
if (configEntry.specificTo().equals(GameType.BOTH) || configEntry.specificTo().equals(Settings.GAMETYPE)) {
// If there's a difference in the value. Note for non-primitives, this will be true
if (!currentvalue.equals(configValue)) {
Bukkit.getLogger().info(name + " changed value from " + currentvalue + " to " + configValue);
// If there's an adapter use it to convert from the YML object to the setting field
if (!configEntry.adapter().equals(NoAdapter.class)) {
// Create an instance of the adapter class
Object instance = configEntry.adapter().newInstance();
// Get the adapt method - it should be there.
Method method = configEntry.adapter().getMethod("adapt", Object.class, Object.class);
if (method != null) {
// It exists, so invoke it
configValue = method.invoke(instance, configValue, type);
if (configValue != null) {
// Set the field.
field.set(null, configValue);
}
}
} else if (configValue != null){
// No adapter - I hope this works!
field.set(null, configValue);
}
}
} else {
Bukkit.getLogger().info(name + " not applicable to this game type");
}
}
}
}
}

View File

@ -1,128 +0,0 @@
package us.tastybento.bskyblock.config;
import java.util.HashMap;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.config.NotSetup.ConfigError;
import us.tastybento.bskyblock.database.BSBDatabase.DatabaseType;
/**
* 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) {
plugin.saveDefaultConfig();
// Initialize the errors list
HashMap<ConfigError, Object> errors = new HashMap<>();
//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.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.useControlPanel = plugin.getConfig().getBoolean("general.use-control-panel", true);
// Purge
Settings.purgeRemoveUserData = plugin.getConfig().getBoolean("general.purge.remove-user-data", false);
// Database
String dbType = plugin.getConfig().getString("general.database.type","FLATFILE");
boolean found = false;
for (DatabaseType type: DatabaseType.values()) {
if (type.name().equals(dbType.toUpperCase())) {
Settings.databaseType = type;
found = true;
break;
}
}
if (!found) {
plugin.getLogger().severe("Database type not found! Using FLATFILE");
Settings.databaseType = DatabaseType.FLATFILE;
}
Settings.dbHost = plugin.getConfig().getString("general.database.host", "localhost");
Settings.dbPort = plugin.getConfig().getInt("general.database.port",3306);
Settings.dbName = plugin.getConfig().getString("general.database.name", "BSkyBlock");
Settings.dbUsername = plugin.getConfig().getString("general.database.username");
Settings.dbPassword = plugin.getConfig().getString("general.database.password");
//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_world");
//TODO check if it is the same than before
int distance = plugin.getConfig().getInt("world.distance", 208);
Settings.islandDistance = Math.round((long)distance/16) * 16;
if(distance < 48) errors.put(ConfigError.ISLAND_DISTANCE_TOO_LOW, Settings.islandDistance);
Settings.islandProtectionRange = plugin.getConfig().getInt("world.protection-range", 100);
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);
}
// TODO: add to config
Settings.endGenerate = true;
Settings.endIslands = false;
Settings.limitedBlocks = new HashMap<>();
Settings.defaultFlags = new HashMap<>();
// Team
Settings.maxTeamSize = plugin.getConfig().getInt("island.max-team-size", 4);
//Settings.leaveConfirmation = plugin.getConfig().getBoolean("require-confirmation.leave", true);
//Settings.leaveConfirmWait = plugin.getConfig().getLong("require-confirmation.leave-wait", 10) * 20;
//TODO end loading
//TODO not setup error report
return true;
}
public static void loadLocales(BSkyBlock plugin){
//TODO Imperatively load en-US locale
}
}

View File

@ -1,8 +1,6 @@
package us.tastybento.bskyblock.database;
import org.bukkit.plugin.Plugin;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.database.flatfile.FlatFileDatabase;
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
import us.tastybento.bskyblock.database.mysql.MySQLDatabase;
@ -14,9 +12,9 @@ public abstract class BSBDatabase {
* FLATFILE and MYSQL. Default is FLATFILE
* @return Database type
*/
public static BSBDatabase getDatabase(){
public static BSBDatabase getDatabase(BSkyBlock plugin){
for(DatabaseType type : DatabaseType.values()){
if(type == Settings.databaseType) return type.database;
if(type == plugin.getSettings().getDatabaseType()) return type.database;
}
return DatabaseType.FLATFILE.database;
}
@ -38,6 +36,6 @@ public abstract class BSBDatabase {
* @param dataObjectClass
* @return database handler
*/
public abstract AbstractDatabaseHandler<?> getHandler(Plugin plugin, Class<?> dataObjectClass);
public abstract AbstractDatabaseHandler<?> getHandler(BSkyBlock plugin, Class<?> dataObjectClass);
}

View File

@ -1,7 +1,5 @@
package us.tastybento.bskyblock.database;
import us.tastybento.bskyblock.Settings;
public class DatabaseConnectionSettingsImpl {
private String host;
private int port;
@ -25,14 +23,6 @@ public class DatabaseConnectionSettingsImpl {
this.password = password;
}
public DatabaseConnectionSettingsImpl() {
this.host = Settings.dbHost;
this.port = Settings.dbPort;
this.databaseName = Settings.dbName;
this.username = Settings.dbUsername;
this.password = Settings.dbPassword;
}
/**
* @return the host
*/

View File

@ -1,14 +1,13 @@
package us.tastybento.bskyblock.database.flatfile;
import org.bukkit.plugin.Plugin;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.database.BSBDatabase;
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
public class FlatFileDatabase extends BSBDatabase{
@Override
public AbstractDatabaseHandler<?> getHandler(Plugin plugin, Class<?> type) {
public AbstractDatabaseHandler<?> getHandler(BSkyBlock plugin, Class<?> type) {
return new FlatFileDatabaseHandler<>(plugin, type, new FlatFileDatabaseConnecter(plugin, null));
}

View File

@ -24,10 +24,9 @@ import org.bukkit.configuration.MemorySection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.configuration.ConfigEntry;
import us.tastybento.bskyblock.api.configuration.ConfigEntry.GameType;
import us.tastybento.bskyblock.api.configuration.ConfigEntry.NoAdapter;
import us.tastybento.bskyblock.config.StoreAt;
import us.tastybento.bskyblock.database.DatabaseConnecter;
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
@ -172,7 +171,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
if (!configEntry.path().isEmpty()) {
storageLocation = configEntry.path();
}
if (!configEntry.specificTo().equals(GameType.BOTH) && !configEntry.specificTo().equals(Settings.GAMETYPE)) {
if (!configEntry.specificTo().equals(GameType.BOTH) && !configEntry.specificTo().equals(Constants.GAMETYPE)) {
Bukkit.getLogger().info(field.getName() + " not applicable to this game type");
continue;
}

View File

@ -15,7 +15,7 @@ import org.bukkit.Location;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.database.BSBDatabase;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.database.objects.Players;
@ -40,7 +40,7 @@ public class PlayersManager{
@SuppressWarnings("unchecked")
public PlayersManager(BSkyBlock plugin){
this.plugin = plugin;
database = BSBDatabase.getDatabase();
database = BSBDatabase.getDatabase(plugin);
// Set up the database handler to store and retrieve Players classes
handler = (AbstractDatabaseHandler<Players>) database.getHandler(plugin, Players.class);
playerCache = new HashMap<>();
@ -138,7 +138,7 @@ public class PlayersManager{
} else {
if (DEBUG)
plugin.getLogger().info("DEBUG: new player");
player = new Players(playerUUID);
player = new Players(plugin, playerUUID);
}
playerCache.put(playerUUID, player);
return player;
@ -506,7 +506,7 @@ public class PlayersManager{
addPlayer(targetUUID);
// Check if the target player has a permission bypass (admin.noban)
Player target = plugin.getServer().getPlayer(targetUUID);
if (target != null && target.hasPermission(Settings.PERMPREFIX + "admin.noban")) {
if (target != null && target.hasPermission(Constants.PERMPREFIX + "admin.noban")) {
return false;
}
Island island = plugin.getIslands().getIsland(playerUUID);

View File

@ -17,7 +17,6 @@ import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.util.Util;
@ -136,7 +135,7 @@ public class IslandCache {
public Island createIsland(Location location, UUID owner){
if (DEBUG)
plugin.getLogger().info("DEBUG: adding island for " + owner + " at " + location);
Island island = new Island(location, owner, Settings.islandProtectionRange);
Island island = new Island(plugin, location, owner, plugin.getSettings().getIslandProtectionRange());
islandsByLocation.put(location, island);
if (owner != null)
islandsByUUID.put(owner, island);

View File

@ -20,12 +20,11 @@ import org.bukkit.material.TrapDoor;
import org.bukkit.util.Vector;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.database.BSBDatabase;
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.generators.IslandWorld;
import us.tastybento.bskyblock.util.DeleteIslandChunks;
import us.tastybento.bskyblock.util.SafeSpotTeleport;
import us.tastybento.bskyblock.util.Util;
@ -50,7 +49,7 @@ public class IslandsManager {
* - Location to be checked
* @return true if safe, otherwise false
*/
public static boolean isSafeLocation(final Location l) {
public boolean isSafeLocation(final Location l) {
if (l == null) {
return false;
}
@ -76,7 +75,7 @@ public class IslandsManager {
// In BSkyBlock, liquid may be unsafe
if (ground.isLiquid() || space1.isLiquid() || space2.isLiquid()) {
// Check if acid has no damage
if (Settings.acidDamage > 0D) {
if (plugin.getSettings().getAcidDamage() > 0D) {
// Bukkit.getLogger().info("DEBUG: acid");
return false;
} else if (ground.getType().equals(Material.STATIONARY_LAVA) || ground.getType().equals(Material.LAVA)
@ -141,7 +140,7 @@ public class IslandsManager {
@SuppressWarnings("unchecked")
public IslandsManager(BSkyBlock plugin){
this.plugin = plugin;
database = BSBDatabase.getDatabase();
database = BSBDatabase.getDatabase(plugin);
// Set up the database handler to store and retrieve Island classes
handler = (AbstractDatabaseHandler<Island>) database.getHandler(plugin, Island.class);
islandCache = new IslandCache();
@ -248,7 +247,7 @@ public class IslandsManager {
public Island createIsland(Location location, UUID owner){
if (DEBUG)
plugin.getLogger().info("DEBUG: adding island for " + owner + " at " + location);
return islandCache.createIsland(new Island(location, owner, Settings.islandProtectionRange));
return islandCache.createIsland(new Island(plugin, location, owner, plugin.getSettings().getIslandProtectionRange()));
}
/**
@ -625,7 +624,7 @@ public class IslandsManager {
//player.sendBlockChange(home, Material.GLOWSTONE, (byte)0);
User user = User.getInstance(player);
if (number == 1) {
user.sendMessage("commands.island.go.teleport", "[label]", Settings.ISLANDCOMMAND);
user.sendMessage("commands.island.go.teleport", "[label]", Constants.ISLANDCOMMAND);
} else {
user.sendMessage("commands.island.go.island.go.teleported", "[number]", String.valueOf(number));
}
@ -696,7 +695,7 @@ public class IslandsManager {
if (plugin.getPlayers().hasIsland(uuid) || plugin.getPlayers().inTeam(uuid)) {
islandTestLocations.add(plugin.getIslands().getIslandLocation(uuid));
// If new Nether
if (Settings.netherGenerate && Settings.netherIslands && IslandWorld.getNetherWorld() != null) {
if (plugin.getSettings().isNetherGenerate() && plugin.getSettings().isNetherIslands() && plugin.getIslandWorldManager().getNetherWorld() != null) {
islandTestLocations.add(netherIsland(plugin.getIslands().getIslandLocation(uuid)));
}
}
@ -713,7 +712,7 @@ public class IslandsManager {
// Must be in the same world as the locations being checked
// Note that getWorld can return null if a world has been deleted on the server
if (islandTestLocation != null && islandTestLocation.getWorld() != null && islandTestLocation.getWorld().equals(loc.getWorld())) {
int protectionRange = Settings.islandProtectionRange;
int protectionRange = plugin.getSettings().getIslandProtectionRange();
if (getIslandAt(islandTestLocation) != null) {
// Get the protection range for this location if possible
Island island = getProtectedIslandAt(islandTestLocation);
@ -781,10 +780,10 @@ public class IslandsManager {
// Run through all the locations
for (Location islandTestLocation : islandTestLocations) {
if (loc.getWorld().equals(islandTestLocation.getWorld())) {
if (loc.getX() >= islandTestLocation.getX() - Settings.islandProtectionRange
&& loc.getX() < islandTestLocation.getX() + Settings.islandProtectionRange
&& loc.getZ() >= islandTestLocation.getZ() - Settings.islandProtectionRange
&& loc.getZ() < islandTestLocation.getZ() + Settings.islandProtectionRange) {
if (loc.getX() >= islandTestLocation.getX() - plugin.getSettings().getIslandProtectionRange()
&& loc.getX() < islandTestLocation.getX() + plugin.getSettings().getIslandProtectionRange()
&& loc.getZ() >= islandTestLocation.getZ() - plugin.getSettings().getIslandProtectionRange()
&& loc.getZ() < islandTestLocation.getZ() + plugin.getSettings().getIslandProtectionRange()) {
return true;
}
}
@ -807,7 +806,7 @@ public class IslandsManager {
*/
private Location netherIsland(Location islandLocation) {
//plugin.getLogger().info("DEBUG: netherworld = " + ASkyBlock.getNetherWorld());
return islandLocation.toVector().toLocation(IslandWorld.getNetherWorld());
return islandLocation.toVector().toLocation(plugin.getIslandWorldManager().getNetherWorld());
}
/**
@ -870,10 +869,10 @@ public class IslandsManager {
Island spawn = getSpawn();
if (spawn != null) {
// go to island spawn
player.teleport(IslandWorld.getIslandWorld().getSpawnLocation());
player.teleport(plugin.getIslandWorldManager().getIslandWorld().getSpawnLocation());
//plugin.getLogger().warning("During island deletion player " + player.getName() + " sent to spawn.");
} else {
if (!player.performCommand(Settings.SPAWNCOMMAND)) {
if (!player.performCommand(Constants.SPAWNCOMMAND)) {
plugin.getLogger().warning(
"During island deletion player " + player.getName() + " could not be sent to spawn so was dropped, sorry.");
}

View File

@ -10,9 +10,7 @@ import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.generators.IslandWorld;
import us.tastybento.bskyblock.island.builders.IslandBuilder;
import us.tastybento.bskyblock.island.builders.IslandBuilder.IslandType;
@ -23,13 +21,14 @@ import us.tastybento.bskyblock.island.builders.IslandBuilder.IslandType;
*/
public class NewIsland {
private static final boolean DEBUG = false;
private final BSkyBlock plugin = BSkyBlock.getInstance();
private BSkyBlock plugin;
private Island island;
private final Player player;
private final Reason reason;
private NewIsland(Island oldIsland, Player player, Reason reason) {
private NewIsland(BSkyBlock plugin, Island oldIsland, Player player, Reason reason) {
super();
this.plugin = plugin;
this.player = player;
this.reason = reason;
newIsland();
@ -48,10 +47,11 @@ public class NewIsland {
/**
* Start building a new island
* @param plugin
* @return New island builder object
*/
public static Builder builder() {
return new Builder();
public static Builder builder(BSkyBlock plugin) {
return new Builder(plugin);
}
/**
@ -63,6 +63,12 @@ public class NewIsland {
private Island oldIsland;
private Player player;
private Reason reason;
private BSkyBlock plugin;
public Builder(BSkyBlock plugin) {
this.plugin = plugin;
}
public Builder oldIsland(Island oldIsland) {
this.oldIsland = oldIsland;
@ -82,7 +88,7 @@ public class NewIsland {
public Island build() throws IOException {
if (player != null) {
NewIsland newIsland = new NewIsland(oldIsland, player, reason);
NewIsland newIsland = new NewIsland(plugin, oldIsland, player, reason);
return newIsland.getIsland();
}
throw new IOException("Insufficient parameters. Must have a schematic and a player");
@ -132,22 +138,22 @@ public class NewIsland {
plugin.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
// Create island
new IslandBuilder(island)
new IslandBuilder(plugin, island)
.setPlayer(player)
.setChestItems(Settings.chestItems)
.setChestItems(plugin.getSettings().getChestItems())
.setType(IslandType.ISLAND)
.build();
if (Settings.netherGenerate && Settings.netherIslands && IslandWorld.getNetherWorld() != null) {
new IslandBuilder(island)
if (plugin.getSettings().isNetherGenerate() && plugin.getSettings().isNetherIslands() && plugin.getIslandWorldManager().getNetherWorld() != null) {
new IslandBuilder(plugin,island)
.setPlayer(player)
.setChestItems(Settings.chestItems)
.setChestItems(plugin.getSettings().getChestItems())
.setType(IslandType.NETHER)
.build();
}
if (Settings.endGenerate && Settings.endIslands && IslandWorld.getEndWorld() != null) {
new IslandBuilder(island)
if (plugin.getSettings().isEndGenerate() && plugin.getSettings().isEndIslands() && plugin.getIslandWorldManager().getEndWorld() != null) {
new IslandBuilder(plugin,island)
.setPlayer(player)
.setChestItems(Settings.chestItems)
.setChestItems(plugin.getSettings().getChestItems())
.setType(IslandType.END)
.build();
}
@ -188,7 +194,8 @@ public class NewIsland {
// Find the next free spot
if (last == null) {
last = new Location(IslandWorld.getIslandWorld(), Settings.islandXOffset + Settings.islandStartX, Settings.islandHeight, Settings.islandZOffset + Settings.islandStartZ);
last = new Location(plugin.getIslandWorldManager().getIslandWorld(), plugin.getSettings().getIslandXOffset() + plugin.getSettings().getIslandStartX(),
plugin.getSettings().getIslandHeight(), plugin.getSettings().getIslandZOffset() + plugin.getSettings().getIslandStartZ());
}
Location next = last.clone();
if (DEBUG)
@ -218,25 +225,25 @@ public class NewIsland {
Location nextPos = lastIsland;
if (x < z) {
if (-1 * x < z) {
nextPos.setX(nextPos.getX() + Settings.islandDistance*2);
nextPos.setX(nextPos.getX() + plugin.getSettings().getIslandDistance()*2);
return nextPos;
}
nextPos.setZ(nextPos.getZ() + Settings.islandDistance*2);
nextPos.setZ(nextPos.getZ() + plugin.getSettings().getIslandDistance()*2);
return nextPos;
}
if (x > z) {
if (-1 * x >= z) {
nextPos.setX(nextPos.getX() - Settings.islandDistance*2);
nextPos.setX(nextPos.getX() - plugin.getSettings().getIslandDistance()*2);
return nextPos;
}
nextPos.setZ(nextPos.getZ() - Settings.islandDistance*2);
nextPos.setZ(nextPos.getZ() - plugin.getSettings().getIslandDistance()*2);
return nextPos;
}
if (x <= 0) {
nextPos.setZ(nextPos.getZ() + Settings.islandDistance*2);
nextPos.setZ(nextPos.getZ() + plugin.getSettings().getIslandDistance()*2);
return nextPos;
}
nextPos.setZ(nextPos.getZ() - Settings.islandDistance*2);
nextPos.setZ(nextPos.getZ() - plugin.getSettings().getIslandDistance()*2);
return nextPos;
}
}

View File

@ -1,7 +1,6 @@
package us.tastybento.bskyblock.database.mysql;
import org.bukkit.plugin.Plugin;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.database.BSBDatabase;
import us.tastybento.bskyblock.database.DatabaseConnectionSettingsImpl;
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
@ -9,8 +8,14 @@ import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
public class MySQLDatabase extends BSBDatabase{
@Override
public AbstractDatabaseHandler<?> getHandler(Plugin plugin, Class<?> type) {
return new MySQLDatabaseHandler<>(plugin, type, new MySQLDatabaseConnecter(new DatabaseConnectionSettingsImpl()));
public AbstractDatabaseHandler<?> getHandler(BSkyBlock plugin, Class<?> type) {
return new MySQLDatabaseHandler<>(plugin, type, new MySQLDatabaseConnecter(new DatabaseConnectionSettingsImpl(
plugin.getSettings().getDbHost(),
plugin.getSettings().getDbPort(),
plugin.getSettings().getDbName(),
plugin.getSettings().getDbUsername(),
plugin.getSettings().getDbPassword()
)));
}
}

View File

@ -1,20 +1,26 @@
package us.tastybento.bskyblock.database.objects;
import us.tastybento.bskyblock.BSkyBlock;
/**
* Contains fields that must be in any data object
* @author tastybento
*
*/
public abstract class DataObject {
public interface DataObject {
default BSkyBlock getPlugin() {
return BSkyBlock.getInstance();
}
/**
* @return the uniqueId
*/
public abstract String getUniqueId();
abstract String getUniqueId();
/**
* @param uniqueId the uniqueId to set
*/
public abstract void setUniqueId(String uniqueId);
abstract void setUniqueId(String uniqueId);
}

View File

@ -13,13 +13,13 @@ import org.bukkit.World;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent.IslandLockEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent.IslandUnlockEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.util.Util;
/**
@ -30,11 +30,10 @@ import us.tastybento.bskyblock.util.Util;
* @author Tastybento
* @author Poslovitch
*/
public class Island extends DataObject {
public class Island implements DataObject {
private String uniqueId = "";
@Override
public String getUniqueId() {
// Island's have UUID's that are randomly assigned if they do not exist
if (uniqueId.isEmpty()) {
@ -43,7 +42,6 @@ public class Island extends DataObject {
return uniqueId;
}
@Override
public void setUniqueId(String uniqueId) {
this.uniqueId = uniqueId;
}
@ -53,7 +51,7 @@ public class Island extends DataObject {
private Location center;
// Island range
private int range = Settings.islandDistance;
private int range;
// Coordinates of the island area
private int minX;
@ -104,15 +102,15 @@ public class Island extends DataObject {
private Location spawnPoint;
public Island() {}
public Island(Location location, UUID owner, int protectionRange) {
public Island(BSkyBlock plugin, Location location, UUID owner, int protectionRange) {
this.members.add(owner);
this.owner = owner;
this.createdDate = System.currentTimeMillis();
this.updatedDate = System.currentTimeMillis();
this.world = location.getWorld();
this.center = location;
this.range = Settings.islandDistance;
this.range = plugin.getSettings().getIslandProtectionRange();
this.minX = center.getBlockX() - range;
this.minZ = center.getBlockZ() - range;
this.protectionRange = protectionRange;

View File

@ -9,14 +9,14 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.BSkyBlock;
/**
* Tracks the following info on the player
*
* @author tastybento
*/
public class Players extends DataObject {
public class Players implements DataObject {
private HashMap<Integer, Location> homeLocations;
private String uniqueId;
private String playerName;
@ -31,15 +31,16 @@ public class Players extends DataObject {
public Players() {}
/**
* @param plugin
* @param uniqueId
* Constructor - initializes the state variables
*
*/
public Players(final UUID uniqueId) {
public Players(BSkyBlock plugin, final UUID uniqueId) {
this.uniqueId = uniqueId.toString();
this.homeLocations = new HashMap<>();
this.playerName = "";
this.resetsLeft = Settings.resetLimit;
this.resetsLeft = plugin.getSettings().getResetLimit();
this.locale = "";
this.kickedList = new HashMap<>();
this.playerName = Bukkit.getServer().getOfflinePlayer(uniqueId).getName();
@ -200,8 +201,8 @@ public class Players extends DataObject {
*/
public void setDeaths(int deaths) {
this.deaths = deaths;
if (this.deaths > Settings.deathsMax) {
this.deaths = Settings.deathsMax;
if (this.deaths > getPlugin().getSettings().getDeathsMax()) {
this.deaths = getPlugin().getSettings().getDeathsMax();
}
}
@ -210,8 +211,8 @@ public class Players extends DataObject {
*/
public void addDeath() {
this.deaths++;
if (this.deaths > Settings.deathsMax) {
this.deaths = Settings.deathsMax;
if (this.deaths > getPlugin().getSettings().getDeathsMax()) {
this.deaths = getPlugin().getSettings().getDeathsMax();
}
}
@ -233,7 +234,7 @@ public class Players extends DataObject {
Calendar coolDownTime = Calendar.getInstance();
coolDownTime.setTime(kickedDate);
// coolDownTime.add(Calendar.HOUR_OF_DAY, Settings.inviteWait);
coolDownTime.add(Calendar.MINUTE, Settings.inviteWait);
coolDownTime.add(Calendar.MINUTE, getPlugin().getSettings().getInviteWait());
// Add the invite cooldown period
Calendar timeNow = Calendar.getInstance();
// plugin.getLogger().info("DEBUG: date now = " + timeNow);

View File

@ -11,16 +11,25 @@ import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.util.noise.PerlinOctaveGenerator;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.BSkyBlock;
/**
* @author tastybento
* Creates the world
*/
public class ChunkGeneratorWorld extends ChunkGenerator {
BSkyBlock plugin;
Random rand = new Random();
PerlinOctaveGenerator gen;
//BSkyBlock plugin = BSkyBlock.getPlugin();
/**
* @param plugin
*/
public ChunkGeneratorWorld(BSkyBlock plugin) {
super();
this.plugin = plugin;
}
@Override
public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, ChunkGenerator.BiomeGrid biomeGrid) {
@ -28,10 +37,10 @@ public class ChunkGeneratorWorld extends ChunkGenerator {
return generateNetherChunks(world, random, chunkX, chunkZ, biomeGrid);
}
ChunkData result = createChunkData(world);
if (Settings.seaHeight != 0) {
if (plugin.getSettings().getSeaHeight() != 0) {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
for (int y = 0; y < Settings.seaHeight; y++) {
for (int y = 0; y < plugin.getSettings().getSeaHeight(); y++) {
result.setBlock(x, y, z, Material.STATIONARY_WATER);
}
}
@ -64,7 +73,7 @@ public class ChunkGeneratorWorld extends ChunkGenerator {
if (!world.getEnvironment().equals(Environment.NETHER)) {
return result;
}
if (Settings.netherRoof) {
if (plugin.getSettings().isNetherRoof()) {
// Make the roof - common across the world
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {

View File

@ -6,11 +6,10 @@ import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Settings;
public class IslandWorld {
//private BSkyBlock plugin;
private BSkyBlock plugin;
private static World islandWorld;
private static World netherWorld;
private static World endWorld;
@ -19,37 +18,38 @@ public class IslandWorld {
* Generates the Skyblock worlds.
*/
public IslandWorld(BSkyBlock plugin) {
if (Settings.useOwnGenerator) {
this.plugin = plugin;
if (plugin.getSettings().isUseOwnGenerator()) {
// Do nothing
return;
}
if (plugin.getServer().getWorld(Settings.worldName) == null) {
if (plugin.getServer().getWorld(plugin.getSettings().getWorldName()) == null) {
Bukkit.getLogger().info("Creating " + plugin.getName() + "'s Island World...");
}
// Create the world if it does not exist
islandWorld = WorldCreator.name(Settings.worldName).type(WorldType.FLAT).environment(World.Environment.NORMAL).generator(new ChunkGeneratorWorld())
islandWorld = WorldCreator.name(plugin.getSettings().getWorldName()).type(WorldType.FLAT).environment(World.Environment.NORMAL).generator(new ChunkGeneratorWorld(plugin))
.createWorld();
// Make the nether if it does not exist
if (Settings.netherGenerate) {
if (plugin.getServer().getWorld(Settings.worldName + "_nether") == null) {
if (plugin.getSettings().isNetherGenerate()) {
if (plugin.getServer().getWorld(plugin.getSettings().getWorldName() + "_nether") == null) {
Bukkit.getLogger().info("Creating " + plugin.getName() + "'s Nether...");
}
if (!Settings.netherIslands) {
netherWorld = WorldCreator.name(Settings.worldName + "_nether").type(WorldType.NORMAL).environment(World.Environment.NETHER).createWorld();
if (!plugin.getSettings().isNetherIslands()) {
netherWorld = WorldCreator.name(plugin.getSettings().getWorldName() + "_nether").type(WorldType.NORMAL).environment(World.Environment.NETHER).createWorld();
} else {
netherWorld = WorldCreator.name(Settings.worldName + "_nether").type(WorldType.FLAT).generator(new ChunkGeneratorWorld())
netherWorld = WorldCreator.name(plugin.getSettings().getWorldName() + "_nether").type(WorldType.FLAT).generator(new ChunkGeneratorWorld(plugin))
.environment(World.Environment.NETHER).createWorld();
}
}
// Make the end if it does not exist
if (Settings.endGenerate) {
if (plugin.getServer().getWorld(Settings.worldName + "_the_end") == null) {
if (plugin.getSettings().isEndGenerate()) {
if (plugin.getServer().getWorld(plugin.getSettings().getWorldName() + "_the_end") == null) {
Bukkit.getLogger().info("Creating " + plugin.getName() + "'s End World...");
}
if (!Settings.endIslands) {
endWorld = WorldCreator.name(Settings.worldName + "_the_end").type(WorldType.NORMAL).environment(World.Environment.THE_END).createWorld();
if (!plugin.getSettings().isEndIslands()) {
endWorld = WorldCreator.name(plugin.getSettings().getWorldName() + "_the_end").type(WorldType.NORMAL).environment(World.Environment.THE_END).createWorld();
} else {
endWorld = WorldCreator.name(Settings.worldName + "_the_end").type(WorldType.FLAT).generator(new ChunkGeneratorWorld())
endWorld = WorldCreator.name(plugin.getSettings().getWorldName() + "_the_end").type(WorldType.FLAT).generator(new ChunkGeneratorWorld(plugin))
.environment(World.Environment.THE_END).createWorld();
}
}
@ -62,22 +62,22 @@ public class IslandWorld {
Bukkit.getLogger().info("Trying to register generator with Multiverse ");
try {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
"mv import " + Settings.worldName + " normal -g " + plugin.getName());
"mv import " + plugin.getSettings().getWorldName() + " normal -g " + plugin.getName());
if (!Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
"mv modify set generator " + plugin.getName() + " " + Settings.worldName)) {
"mv modify set generator " + plugin.getName() + " " + plugin.getSettings().getWorldName())) {
Bukkit.getLogger().severe("Multiverse is out of date! - Upgrade to latest version!");
}
if (netherWorld != null && Settings.netherGenerate && Settings.netherIslands) {
if (netherWorld != null && plugin.getSettings().isNetherGenerate() && plugin.getSettings().isNetherIslands()) {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
"mv import " + Settings.worldName + "_nether nether -g " + plugin.getName());
"mv import " + plugin.getSettings().getWorldName() + "_nether nether -g " + plugin.getName());
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
"mv modify set generator " + plugin.getName() + " " + Settings.worldName + "_nether");
"mv modify set generator " + plugin.getName() + " " + plugin.getSettings().getWorldName() + "_nether");
}
if (endWorld != null && Settings.endGenerate && Settings.endIslands) {
if (endWorld != null && plugin.getSettings().isEndGenerate() && plugin.getSettings().isEndIslands()) {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
"mv import " + Settings.worldName + "_the_end end -g " + plugin.getName());
"mv import " + plugin.getSettings().getWorldName() + "_the_end end -g " + plugin.getName());
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
"mv modify set generator " + plugin.getName() + " " + Settings.worldName + "_the_end");
"mv modify set generator " + plugin.getName() + " " + plugin.getSettings().getWorldName() + "_the_end");
}
} catch (Exception e) {
Bukkit.getLogger().severe("Not successfull! Disabling " + plugin.getName() + "!");
@ -92,9 +92,9 @@ public class IslandWorld {
/**
* @return the islandWorld
*/
public static World getIslandWorld() {
if (Settings.useOwnGenerator) {
return Bukkit.getServer().getWorld(Settings.worldName);
public World getIslandWorld() {
if (plugin.getSettings().isUseOwnGenerator()) {
return Bukkit.getServer().getWorld(plugin.getSettings().getWorldName());
}
return islandWorld;
}
@ -102,9 +102,9 @@ public class IslandWorld {
/**
* @return the netherWorld
*/
public static World getNetherWorld() {
if (Settings.useOwnGenerator) {
return Bukkit.getServer().getWorld(Settings.worldName + "_nether");
public World getNetherWorld() {
if (plugin.getSettings().isUseOwnGenerator()) {
return Bukkit.getServer().getWorld(plugin.getSettings().getWorldName() + "_nether");
}
return netherWorld;
}
@ -112,9 +112,9 @@ public class IslandWorld {
/**
* @return the endWorld
*/
public static World getEndWorld() {
if (Settings.useOwnGenerator) {
return Bukkit.getServer().getWorld(Settings.worldName + "_the_end");
public World getEndWorld() {
if (plugin.getSettings().isUseOwnGenerator()) {
return Bukkit.getServer().getWorld(plugin.getSettings().getWorldName() + "_the_end");
}
return endWorld;
}

View File

@ -16,11 +16,11 @@ import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Chest;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.configuration.ConfigEntry.GameType;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.generators.IslandWorld;
/**
* Fired when a team event happens.
@ -44,9 +44,11 @@ public class IslandBuilder {
//private List<Entity> companions = new ArrayList<>();
private UUID playerUUID;
private String playerName;
private BSkyBlock plugin;
public IslandBuilder(Island island) {
public IslandBuilder(BSkyBlock plugin, Island island) {
super();
this.plugin = plugin;
this.island = island;
this.world = island.getWorld();
}
@ -59,13 +61,13 @@ public class IslandBuilder {
this.type = type;
switch(type) {
case END:
this.world = IslandWorld.getEndWorld();
this.world = plugin.getIslandWorldManager().getEndWorld();
break;
case ISLAND:
this.world = IslandWorld.getIslandWorld();
this.world = plugin.getIslandWorldManager().getIslandWorld();
break;
case NETHER:
this.world = IslandWorld.getNetherWorld();
this.world = plugin.getIslandWorldManager().getNetherWorld();
break;
default:
this.world = island.getWorld();
@ -98,7 +100,7 @@ public class IslandBuilder {
public void build() {
// Switch on island type
if (type == IslandType.ISLAND) {
if (Settings.GAMETYPE == GameType.ACIDISLAND) {
if (Constants.GAMETYPE == GameType.ACIDISLAND) {
generateAcidIslandBlocks();
} else {
generateIslandBlocks();

View File

@ -10,8 +10,8 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.database.managers.PlayersManager;
import us.tastybento.bskyblock.database.objects.Island;
@ -46,8 +46,8 @@ public class JoinLeaveListener implements Listener {
// Load player
players.addPlayer(playerUUID);
// Reset resets if the admin changes it to or from unlimited
if (Settings.resetLimit < players.getResetsLeft(playerUUID) || (Settings.resetLimit >= 0 && players.getResetsLeft(playerUUID) < 0)) {
players.setResetsLeft(playerUUID, Settings.resetLimit);
if (plugin.getSettings().getResetLimit() < players.getResetsLeft(playerUUID) || (plugin.getSettings().getResetLimit() >= 0 && players.getResetsLeft(playerUUID) < 0)) {
players.setResetsLeft(playerUUID, plugin.getSettings().getResetLimit());
}
if (DEBUG)
plugin.getLogger().info("DEBUG: Setting player's name");
@ -62,7 +62,7 @@ public class JoinLeaveListener implements Listener {
} else {
plugin.getLogger().warning("Player that just logged in has no name! " + playerUUID.toString());
}
if (Settings.removeMobsOnLogin) {
if (plugin.getSettings().isRemoveMobsOnLogin()) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Removing mobs");
plugin.getIslands().removeMobs(player.getLocation());
@ -73,7 +73,7 @@ public class JoinLeaveListener implements Listener {
if (currentIsland != null && (currentIsland.isLocked() || plugin.getPlayers().isBanned(currentIsland.getOwner(),player.getUniqueId()))) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Current island is locked, or player is banned");
if (!currentIsland.getMembers().contains(playerUUID) && !player.hasPermission(Settings.PERMPREFIX + "mod.bypassprotect")) {
if (!currentIsland.getMembers().contains(playerUUID) && !player.hasPermission(Constants.PERMPREFIX + "mod.bypassprotect")) {
if (DEBUG)
plugin.getLogger().info("DEBUG: No bypass - teleporting");
user.sendMessage("locked.islandlocked");

View File

@ -1,13 +1,14 @@
package us.tastybento.bskyblock.managers;
import org.bukkit.Bukkit;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.panels.PanelItem;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.panels.PanelItem;
public final class FlagsManager {
private List<Flag> flags = new ArrayList<>();

View File

@ -8,7 +8,6 @@ import java.util.Locale;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.localization.BSBLocale;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.util.FileLister;
/**
@ -23,7 +22,7 @@ public final class LocalesManager {
public LocalesManager(BSkyBlock plugin) {
this.plugin = plugin;
this.loadLocales("BSB"); // Default
this.loadLocales(""); // Default
}
/**
@ -37,8 +36,8 @@ public final class LocalesManager {
if (locale != null && locale.contains(reference))
return locale.get(reference);
// Return the default
if (languages.get(Locale.forLanguageTag(Settings.defaultLanguage)).contains(reference)) {
return languages.get(Locale.forLanguageTag(Settings.defaultLanguage)).get(reference);
if (languages.get(Locale.forLanguageTag(plugin.getSettings().getDefaultLanguage())).contains(reference)) {
return languages.get(Locale.forLanguageTag(plugin.getSettings().getDefaultLanguage())).get(reference);
}
return null;
}
@ -49,25 +48,38 @@ public final class LocalesManager {
* TODO: Make more robust. The file filter is fragile.
*/
public void loadLocales(String parent) {
if (DEBUG) {
if (parent.isEmpty())
plugin.getLogger().info("DEBUG: loading locale for BSkyBlock");
else
plugin.getLogger().info("DEBUG: loading locale for " + parent);
}
// Describe the filter - we only want files that are correctly named
FilenameFilter ymlFilter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
//plugin.getLogger().info("DEBUG: filename = " + name + " parent = " + parent );
if (name.startsWith(parent) && name.toLowerCase().endsWith(".yml")) {
// See if this is a valid locale
if (name.length() < 9)
return false;
//Locale localeObject = Locale.forLanguageTag(name.substring(name.length() - 9, name.length() - 4));
return true;
// Do BSkyBlock files
if (parent.isEmpty()) {
if (name.toLowerCase().endsWith(".yml") && name.length() == 9) {
if (DEBUG)
plugin.getLogger().info("DEBUG: bsb locale filename = " + name);
return true;
}
return false;
} else {
// Addon locales
if (name.startsWith(parent) && name.toLowerCase().endsWith(".yml")) {
if (DEBUG)
plugin.getLogger().info("DEBUG: addon locale filename = " + name);
return true;
}
return false;
}
return false;
}
};
// Run through the files and store the locales
File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + "/" + parent);
File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER);
// If the folder does not exist, then make it and fill with the locale files from the jar
// If it does exist, then new files will NOT be written!
if (!localeDir.exists()) {
@ -90,9 +102,13 @@ public final class LocalesManager {
if (DEBUG)
plugin.getLogger().info("DEBUG: locale country found = " + localeObject.getCountry());
if (languages.containsKey(localeObject)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: this locale is known");
// Merge into current language
languages.get(localeObject).merge(language);
} else {
if (DEBUG)
plugin.getLogger().info("DEBUG: this locale is not known - new language");
// New language
languages.put(localeObject, new BSBLocale(localeObject, language));
}

View File

@ -6,9 +6,7 @@ import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.generators.IslandWorld;
//import com.wasteofplastic.askyblock.nms.NMSAbstraction;
@ -42,12 +40,12 @@ public class DeleteIslandChunks {
for (int x = minXChunk; x <= maxXChunk; x++) {
for (int z = minZChunk; z<=maxZChunk; z++) {
world.regenerateChunk(x, z);
if (Settings.netherIslands && Settings.netherGenerate) {
IslandWorld.getNetherWorld().regenerateChunk(x, z);
if (plugin.getSettings().isNetherGenerate() && plugin.getSettings().isNetherIslands()) {
plugin.getIslandWorldManager().getNetherWorld().regenerateChunk(x, z);
}
if (Settings.endIslands && Settings.endGenerate) {
IslandWorld.getEndWorld().regenerateChunk(x, z);
if (plugin.getSettings().isEndGenerate() && plugin.getSettings().isEndIslands()) {
plugin.getIslandWorldManager().getEndWorld().regenerateChunk(x, z);
}
}
}

View File

@ -27,8 +27,6 @@ import org.bukkit.plugin.Plugin;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.generators.IslandWorld;
/**
* A set of utility methods
@ -37,7 +35,6 @@ import us.tastybento.bskyblock.generators.IslandWorld;
* @author Poslovitch
*/
public class Util {
private static BSkyBlock plugin = BSkyBlock.getInstance();
private static String serverVersion = null;
@ -47,7 +44,7 @@ public class Util {
*/
public static String getServerVersion() {
if (serverVersion == null) {
String serverPackageName = plugin.getServer().getClass().getPackage().getName();
String serverPackageName = getPlugin().getServer().getClass().getPackage().getName();
serverVersion = serverPackageName.substring(serverPackageName.lastIndexOf('.') + 1);
}
return serverVersion;
@ -135,8 +132,8 @@ public class Util {
@SuppressWarnings("deprecation")
public static List<ItemStack> getPlayerInHandItems(Player player) {
List<ItemStack> result = new ArrayList<ItemStack>(2);
if (plugin.getServer().getVersion().contains("(MC: 1.7")
|| plugin.getServer().getVersion().contains("(MC: 1.8")) {
if (getPlugin().getServer().getVersion().contains("(MC: 1.7")
|| getPlugin().getServer().getVersion().contains("(MC: 1.8")) {
if (player.getItemInHand() != null)
result.add(player.getItemInHand());
return result;
@ -185,8 +182,8 @@ public class Util {
*/
@SuppressWarnings("deprecation")
public static boolean playerIsHolding(Player player, Material type) {
if (plugin.getServer().getVersion().contains("(MC: 1.7")
|| plugin.getServer().getVersion().contains("(MC: 1.8")) {
if (getPlugin().getServer().getVersion().contains("(MC: 1.7")
|| getPlugin().getServer().getVersion().contains("(MC: 1.8")) {
if (player.getItemInHand() != null && player.getItemInHand().getType().equals(type)) {
return true;
}
@ -209,13 +206,13 @@ public class Util {
*/
public static boolean inWorld(Location loc) {
if (loc != null) {
if (loc.getWorld().equals(IslandWorld.getIslandWorld())) {
if (loc.getWorld().equals(getPlugin().getIslandWorldManager().getIslandWorld())) {
return true;
}
if (Settings.netherIslands && loc.getWorld().equals(IslandWorld.getNetherWorld())) {
if (getPlugin().getSettings().isNetherIslands() && loc.getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) {
return true;
}
if (Settings.endIslands && loc.getWorld().equals(IslandWorld.getEndWorld())) {
if (getPlugin().getSettings().isEndIslands() && loc.getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) {
return true;
}
}
@ -320,7 +317,7 @@ public class Util {
}
public static void runCommand(final Player player, final String string) {
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
getPlugin().getServer().getScheduler().runTask(getPlugin(), new Runnable() {
@Override
public void run() {
@ -364,7 +361,7 @@ public class Util {
// In ASkyBlock, liquid may be unsafe
if (ground.isLiquid() || space1.isLiquid() || space2.isLiquid()) {
// Check if acid has no damage
if (Settings.acidDamage > 0D) {
if (getPlugin().getSettings().getAcidDamage() > 0D) {
// Bukkit.getLogger().info("DEBUG: acid");
return false;
} else if (ground.getType().equals(Material.STATIONARY_LAVA) || ground.getType().equals(Material.LAVA)
@ -427,7 +424,7 @@ public class Util {
String[] spl = perms.getPermission().split(perm + ".");
if (spl.length > 1) {
if (!NumberUtils.isDigits(spl[1])) {
plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
getPlugin().getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
} else {
permValue = Math.max(permValue, Integer.valueOf(spl[1]));
@ -443,4 +440,12 @@ public class Util {
return permValue;
}
/**
* @return the plugin
*/
public static BSkyBlock getPlugin() {
return BSkyBlock.getInstance();
}
}

View File

@ -26,11 +26,11 @@ import org.junit.Test;
import org.mockito.Mockito;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.util.Util;
public class TestBSkyBlock {
@ -56,7 +56,7 @@ public class TestBSkyBlock {
Mockito.when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
sender = mock(CommandSender.class);
player = mock(Player.class);
Mockito.when(player.hasPermission(Settings.PERMPREFIX + "default.permission")).thenReturn(true);
Mockito.when(player.hasPermission(Constants.PERMPREFIX + "default.permission")).thenReturn(true);
plugin = mock(BSkyBlock.class);
//Mockito.when(plugin.getServer()).thenReturn(server);
@ -81,7 +81,7 @@ public class TestBSkyBlock {
User user = User.getInstance(playerUUID);
CompositeCommand testCommand = new TestCommand();
testCommand.setOnlyPlayer(true);
testCommand.setPermission(Settings.PERMPREFIX + "default.permission");
testCommand.setPermission(Constants.PERMPREFIX + "default.permission");
// Test basic execution
assertTrue(testCommand.execute(user, new ArrayList<>()));
assertEquals("test",testCommand.getLabel());
@ -89,7 +89,7 @@ public class TestBSkyBlock {
assertEquals("t", testCommand.getAliases().get(0));
assertTrue(testCommand.isOnlyPlayer());
assertNull(testCommand.getParent());
assertEquals(Settings.PERMPREFIX + "default.permission", testCommand.getPermission());
assertEquals(Constants.PERMPREFIX + "default.permission", testCommand.getPermission());
// Check commands and aliases match to correct class
for (Entry<String, CompositeCommand> command : testCommand.getSubCommands().entrySet()) {
assertEquals(testCommand.getSubCommand(command.getKey()), Optional.of(command.getValue()));
@ -123,7 +123,7 @@ public class TestBSkyBlock {
// Test command arguments
CompositeCommand argCmd = new Test3ArgsCommand();
argCmd.setOnlyPlayer(true);
argCmd.setPermission(Settings.PERMPREFIX + "default.permission");
argCmd.setPermission(Constants.PERMPREFIX + "default.permission");
assertTrue(argCmd.execute(player, "args", new String[]{"give", "100", "ben"}));
assertFalse(testCommand.execute(player, "test", new String[] {"sub2", "subsub", "subsubsub"}));
assertFalse(testCommand.execute(player, "test", new String[] {"sub2", "subsub", "subsubsub", "ben"}));