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.AdminCommand;
import us.tastybento.bskyblock.commands.IslandCommand; import us.tastybento.bskyblock.commands.IslandCommand;
import us.tastybento.bskyblock.config.PluginConfig;
import us.tastybento.bskyblock.database.BSBDatabase; import us.tastybento.bskyblock.database.BSBDatabase;
import us.tastybento.bskyblock.database.managers.PlayersManager; import us.tastybento.bskyblock.database.managers.PlayersManager;
import us.tastybento.bskyblock.database.managers.island.IslandsManager; import us.tastybento.bskyblock.database.managers.island.IslandsManager;
@ -40,79 +39,82 @@ public class BSkyBlock extends JavaPlugin {
private LocalesManager localesManager; private LocalesManager localesManager;
private AddonsManager addonsManager; private AddonsManager addonsManager;
private FlagsManager flagsManager; private FlagsManager flagsManager;
private IslandWorld islandWorldManager;
// Settings
Settings settings;
@Override @Override
public void onEnable(){ public void onEnable(){
plugin = this; plugin = this;
// Load config - EXPERIMENTAL // Load config - EXPERIMENTAL
Settings2 config = new Settings2(); settings = new Settings();
try { try {
//config.saveConfig(); // works, but will wipe out comments //config.saveConfig(); // works, but will wipe out comments
config = config.loadConfig(); settings = settings.loadSettings();
getLogger().info("DEBUG: island distance = " + config.getIslandDistance()); getLogger().info("DEBUG: island distance = " + settings.getIslandDistance());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
// Load configuration and locales. If there are no errors, load the plugin. playersManager = new PlayersManager(this);
if(PluginConfig.loadPluginConfig(this)){ islandsManager = new IslandsManager(this);
playersManager = new PlayersManager(this); // Load metrics
islandsManager = new IslandsManager(this); metrics = new Metrics(plugin);
registerCustomCharts();
// Load metrics // Set up commands
metrics = new Metrics(plugin); commandsManager = new CommandsManager();
registerCustomCharts(); new IslandCommand();
new AdminCommand();
// Set up commands // These items have to be loaded when the server has done 1 tick.
commandsManager = new CommandsManager(); // Note Worlds are not loaded this early, so any Locations or World reference will be null
new IslandCommand(); // at this point. Therefore, the 1 tick scheduler is required.
new AdminCommand(); getServer().getScheduler().runTask(this, new Runnable() {
// These items have to be loaded when the server has done 1 tick. @Override
// Note Worlds are not loaded this early, so any Locations or World reference will be null public void run() {
// at this point. Therefore, the 1 tick scheduler is required. // Create the world if it does not exist
getServer().getScheduler().runTask(this, new Runnable() { islandWorldManager = new IslandWorld(plugin);
@Override getServer().getScheduler().runTask(plugin, new Runnable() {
public void run() {
// Create the world if it does not exist
new IslandWorld(plugin);
getServer().getScheduler().runTask(plugin, new Runnable() { @Override
public void run() {
// Load islands from database
islandsManager.load();
@Override // TODO: load these from config.yml
public void run() { getSettings().setChestItems(new ItemStack[] {
// Load islands from database new ItemStack(Material.LAVA_BUCKET,1),
islandsManager.load(); 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)
});
// TODO: load these from config.yml //getSettings().setDefaultLanguage("en-US");
Settings.chestItems = new ItemStack[] { plugin.getLogger().info("DEBUG: ************************** Loading Locales **************************");
new ItemStack(Material.LAVA_BUCKET,1), localesManager = new LocalesManager(plugin);
new ItemStack(Material.ICE,2), //TODO localesManager.registerLocales(plugin);
new ItemStack(Material.MELON_SEEDS,1),
new ItemStack(Material.BONE,2),
new ItemStack(Material.COBBLESTONE,5),
new ItemStack(Material.SAPLING,2)
};
Settings.defaultLanguage = "en-US"; // Register Listeners
localesManager = new LocalesManager(plugin); registerListeners();
//TODO localesManager.registerLocales(plugin);
// Register Listeners // Load Flags
registerListeners(); flagsManager = new FlagsManager();
// Load Flags // Load addons
flagsManager = new FlagsManager(); addonsManager = new AddonsManager(plugin);
addonsManager.enableAddons();
// Load addons /*
addonsManager = new AddonsManager(plugin); *DEBUG CODE
addonsManager.enableAddons();
/*
*DEBUG CODE
Island loadedIsland = islandsManager.getIsland(owner); Island loadedIsland = islandsManager.getIsland(owner);
getLogger().info("Island name = " + loadedIsland.getName()); getLogger().info("Island name = " + loadedIsland.getName());
getLogger().info("Island locked = " + loadedIsland.getLocked()); getLogger().info("Island locked = " + loadedIsland.getLocked());
@ -121,24 +123,25 @@ public class BSkyBlock extends JavaPlugin {
for (Entry<SettingsFlag, Boolean> flag: loadedIsland.getFlags().entrySet()) { for (Entry<SettingsFlag, Boolean> flag: loadedIsland.getFlags().entrySet()) {
getLogger().info("Flag " + flag.getKey().name() + " = " + flag.getValue()); getLogger().info("Flag " + flag.getKey().name() + " = " + flag.getValue());
} }
*/ */
// Save islands & players data asynchronously every X minutes // Save islands & players data asynchronously every X minutes
Settings.databaseBackupPeriod = 10 * 60 * 20; getSettings().setDatabaseBackupPeriod(10 * 60 * 20);
plugin.getServer().getScheduler().runTaskTimer(plugin, new Runnable() { plugin.getServer().getScheduler().runTaskTimer(plugin, new Runnable() {
@Override @Override
public void run() { public void run() {
playersManager.save(true); playersManager.save(true);
islandsManager.save(true); islandsManager.save(true);
} }
}, Settings.databaseBackupPeriod, Settings.databaseBackupPeriod); }, getSettings().getDatabaseBackupPeriod(), getSettings().getDatabaseBackupPeriod());
} }
}); });
} }
}); });
}
} }
private void registerListeners() { private void registerListeners() {
PluginManager manager = getServer().getPluginManager(); PluginManager manager = getServer().getPluginManager();
// Player join events // Player join events
@ -177,7 +180,7 @@ public class BSkyBlock extends JavaPlugin {
@Override @Override
public String getValue() { public String getValue() {
return Settings.defaultLanguage; return getSettings().getDefaultLanguage();
} }
}); });
@ -185,7 +188,7 @@ public class BSkyBlock extends JavaPlugin {
@Override @Override
public String getValue() { public String getValue() {
return BSBDatabase.getDatabase().toString(); return BSBDatabase.getDatabase(plugin).toString();
} }
}); });
} }
@ -238,4 +241,19 @@ public class BSkyBlock extends JavaPlugin {
return flagsManager; 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 org.bukkit.entity.Player;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.api.events.command.CommandEvent; import us.tastybento.bskyblock.api.events.command.CommandEvent;
import us.tastybento.bskyblock.database.managers.PlayersManager; import us.tastybento.bskyblock.database.managers.PlayersManager;
import us.tastybento.bskyblock.database.managers.island.IslandsManager; import us.tastybento.bskyblock.database.managers.island.IslandsManager;
@ -59,6 +60,23 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
*/ */
private String usage; 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 * Sub-command constructor
* @param parent - the parent composite command * @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); Bukkit.getLogger().info("DEBUG: registering command " + label);
} }
/** /**
* This is the top-level command constructor for commands that have no parent. * This is the top-level command constructor for commands that have no parent.
* @param label - string for this command * @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 * 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()); return getPlugin().getIslands().getMembers(user.getUniqueId());
} }
public String getParameters() {
return parameters;
}
/** /**
* @return the parent command object * @return the parent command object
*/ */
@ -252,6 +257,14 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
return BSkyBlock.getInstance(); return BSkyBlock.getInstance();
} }
/**
* @return Settings object
*/
public Settings getSettings() {
return getPlugin().getSettings();
}
/** /**
* Returns the CompositeCommand object refering to this command label * Returns the CompositeCommand object refering to this command label
* @param label - command label or alias * @param label - command label or alias
@ -265,6 +278,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
return Optional.empty(); return Optional.empty();
} }
/** /**
* @return Map of sub commands for this command * @return Map of sub commands for this command
*/ */
@ -272,7 +286,6 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
return subCommands; return subCommands;
} }
/** /**
* Convenience method to obtain the user's team leader * Convenience method to obtain the user's team leader
* @param user * @param user
@ -282,41 +295,11 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
return getPlugin().getIslands().getTeamLeader(user.getUniqueId()); return getPlugin().getIslands().getTeamLeader(user.getUniqueId());
} }
public void setparameters(String parameters) {
this.setParameters(parameters);
}
@Override @Override
public String getUsage() { public String getUsage() {
return "/" + usage; 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 * Check if this command has a specific sub command
* @param subCommand * @param subCommand
@ -326,6 +309,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
return subCommands.containsKey(subCommand); return subCommands.containsKey(subCommand);
} }
/** /**
* Check if this command has any sub commands * Check if this command has any sub commands
* @return true if this command has subcommands * @return true if this command has subcommands
@ -368,11 +352,35 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
this.onlyPlayer = onlyPlayer; this.onlyPlayer = onlyPlayer;
} }
public void setparameters(String parameters) {
this.setParameters(parameters);
}
public void setParameters(String parameters) {
this.parameters = parameters;
}
@Override @Override
public void setPermission(String permission) { public void setPermission(String permission) {
this.permission = 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 @Override
public List<String> tabComplete(final CommandSender sender, final String alias, final String[] args) { public List<String> tabComplete(final CommandSender sender, final String alias, final String[] args) {
List<String> options = new ArrayList<>(); List<String> options = new ArrayList<>();

View File

@ -17,7 +17,6 @@ import org.bukkit.inventory.PlayerInventory;
import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.permissions.PermissionAttachmentInfo;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Settings;
/** /**
* BSB's user object. Wraps Player. * BSB's user object. Wraps Player.
@ -255,7 +254,7 @@ public class User {
if (!plugin.getPlayers().getLocale(this.playerUUID).isEmpty()) if (!plugin.getPlayers().getLocale(this.playerUUID).isEmpty())
return Locale.forLanguageTag(plugin.getPlayers().getLocale(this.playerUUID)); 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 java.sql.SQLException;
import us.tastybento.bskyblock.BSkyBlock; 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.flatfile.FlatFileDatabase;
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler; import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
@ -19,7 +19,7 @@ public interface ISettings<T> {
// ----------------Saver------------------- // ----------------Saver-------------------
@SuppressWarnings("unchecked") @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 // Get the handler
AbstractDatabaseHandler<T> configHandler = (AbstractDatabaseHandler<T>) new FlatFileDatabase().getHandler(BSkyBlock.getInstance(), instance.getClass()); AbstractDatabaseHandler<T> configHandler = (AbstractDatabaseHandler<T>) new FlatFileDatabase().getHandler(BSkyBlock.getInstance(), instance.getClass());
// Load every field in the config class // Load every field in the config class
@ -27,9 +27,9 @@ public interface ISettings<T> {
} }
// --------------- Loader ------------------ // --------------- Loader ------------------
@SuppressWarnings("unchecked") @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 // 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 // Load every field in the config class
return configHandler.loadObject("config"); 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.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import us.tastybento.bskyblock.api.events.PremadeEvent; import us.tastybento.bskyblock.api.events.PremadeEvent;
/** /**

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,6 +2,7 @@ package us.tastybento.bskyblock.commands;
import java.util.List; import java.util.List;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.commands.island.IslandAboutCommand; 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.IslandSethomeCommand;
import us.tastybento.bskyblock.commands.island.IslandSetnameCommand; import us.tastybento.bskyblock.commands.island.IslandSetnameCommand;
import us.tastybento.bskyblock.commands.island.teams.IslandTeamCommand; import us.tastybento.bskyblock.commands.island.teams.IslandTeamCommand;
import us.tastybento.bskyblock.Settings;
public class IslandCommand extends CompositeCommand { public class IslandCommand extends CompositeCommand {
public IslandCommand() { public IslandCommand() {
super(Settings.ISLANDCOMMAND, "is"); super(Constants.ISLANDCOMMAND, "is");
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -28,7 +28,7 @@ public class IslandCommand extends CompositeCommand {
this.setDescription("commands.island.help.description"); this.setDescription("commands.island.help.description");
this.setOnlyPlayer(true); this.setOnlyPlayer(true);
// Permission // Permission
this.setPermission(Settings.PERMPREFIX + "island"); this.setPermission(Constants.PERMPREFIX + "island");
// Set up subcommands // Set up subcommands
new IslandAboutCommand(this); new IslandAboutCommand(this);
new IslandCreateCommand(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.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.ConfigLoader;
/** /**
* @author ben * @author ben
@ -38,7 +37,6 @@ public class AdminReloadCommand extends CompositeCommand {
*/ */
@Override @Override
public boolean execute(User user, List<String> args) { public boolean execute(User user, List<String> args) {
new ConfigLoader();
return true; return true;
} }

View File

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

View File

@ -2,9 +2,9 @@ package us.tastybento.bskyblock.commands.island;
import java.util.List; import java.util.List;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.util.Util; import us.tastybento.bskyblock.util.Util;
/** /**
@ -40,7 +40,7 @@ public class CustomIslandMultiHomeHelp extends CompositeCommand {
String desc = getDescription().isEmpty() ? "" : user.getTranslation(getDescription()); String desc = getDescription().isEmpty() ? "" : user.getTranslation(getDescription());
// Player. Check perms // Player. Check perms
if (user.hasPermission(getPermission())) { 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) { if (maxHomes > 1) {
params = getParameters().isEmpty() ? "" : user.getTranslation(getParameters()); params = getParameters().isEmpty() ? "" : user.getTranslation(getParameters());
user.sendMessage("commands.help.syntax", "[usage]", usage, "[parameters]", params, "[description]", desc); 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.io.IOException;
import java.util.List; import java.util.List;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason; import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
import us.tastybento.bskyblock.commands.IslandCommand; import us.tastybento.bskyblock.commands.IslandCommand;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.database.managers.island.NewIsland; import us.tastybento.bskyblock.database.managers.island.NewIsland;
/** /**
@ -26,7 +26,7 @@ public class IslandCreateCommand extends CompositeCommand {
@Override @Override
public void setup() { public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.create"); this.setPermission(Constants.PERMPREFIX + "island.create");
this.setOnlyPlayer(true); this.setOnlyPlayer(true);
this.setDescription("commands.island.create.description"); this.setDescription("commands.island.create.description");
} }
@ -55,7 +55,7 @@ public class IslandCreateCommand extends CompositeCommand {
*/ */
protected void createIsland(User user) { protected void createIsland(User user) {
try { try {
NewIsland.builder() NewIsland.builder(getPlugin())
.player(user.getPlayer()) .player(user.getPlayer())
.reason(Reason.CREATE) .reason(Reason.CREATE)
.build(); .build();

View File

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

View File

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

View File

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

View File

@ -10,9 +10,9 @@ import java.util.stream.Collectors;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.Settings;
/** /**
* @author tastybento * @author tastybento
@ -26,7 +26,7 @@ public class IslandSetnameCommand extends CompositeCommand {
@Override @Override
public void setup() { public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.name"); this.setPermission(Constants.PERMPREFIX + "island.name");
this.setOnlyPlayer(true); this.setOnlyPlayer(true);
this.setParameters("commands.island.setname.parameters"); this.setParameters("commands.island.setname.parameters");
this.setDescription("commands.island.setname.description"); this.setDescription("commands.island.setname.description");
@ -59,17 +59,17 @@ public class IslandSetnameCommand extends CompositeCommand {
String name = args.stream().collect(Collectors.joining( " " )); String name = args.stream().collect(Collectors.joining( " " ));
// Check if the name isn't too short or too long // Check if the name isn't too short or too long
if (name.length() < Settings.nameMinLength) { if (name.length() < getSettings().getNameMinLength()) {
user.sendMessage("commands.island.setname.too-short", "[length]", String.valueOf(Settings.nameMinLength)); user.sendMessage("commands.island.setname.too-short", "[length]", String.valueOf(getSettings().getNameMinLength()));
return true; return true;
} }
if (name.length() > Settings.nameMaxLength) { if (name.length() > getSettings().getNameMaxLength()) {
user.sendMessage("commands.island.setname.too-long", "[length]", String.valueOf(Settings.nameMaxLength)); user.sendMessage("commands.island.setname.too-long", "[length]", String.valueOf(getSettings().getNameMaxLength()));
return true; return true;
} }
// Set the name // 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)); getIslands().getIsland(player.getUniqueId()).setName(ChatColor.translateAlternateColorCodes('&', name));
else getIslands().getIsland(playerUUID).setName(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.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.Settings;
/** /**
* A safe common space for team commands to share data * A safe common space for team commands to share data
@ -42,6 +41,6 @@ public abstract class AbstractIslandTeamCommand extends CompositeCommand {
* @param player * @param player
*/ */
protected void setResetWaitTime(final Player 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.apache.commons.lang.math.NumberUtils;
import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.permissions.PermissionAttachmentInfo;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent; import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.Settings;
public class IslandTeamCommand extends AbstractIslandTeamCommand { public class IslandTeamCommand extends AbstractIslandTeamCommand {
@ -23,7 +23,7 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand {
@Override @Override
public void setup() { public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.team"); this.setPermission(Constants.PERMPREFIX + "island.team");
this.setOnlyPlayer(true); this.setOnlyPlayer(true);
this.setDescription("commands.island.team.description"); this.setDescription("commands.island.team.description");
@ -50,15 +50,15 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand {
UUID teamLeaderUUID = getTeamLeader(user); UUID teamLeaderUUID = getTeamLeader(user);
Set<UUID> teamMembers = getMembers(user); Set<UUID> teamMembers = getMembers(user);
if (teamLeaderUUID.equals(playerUUID)) { if (teamLeaderUUID.equals(playerUUID)) {
int maxSize = Settings.maxTeamSize; int maxSize = getSettings().getMaxTeamSize();
for (PermissionAttachmentInfo perms : user.getEffectivePermissions()) { for (PermissionAttachmentInfo perms : user.getEffectivePermissions()) {
if (perms.getPermission().startsWith(Settings.PERMPREFIX + "team.maxsize.")) { if (perms.getPermission().startsWith(Constants.PERMPREFIX + "team.maxsize.")) {
if (perms.getPermission().contains(Settings.PERMPREFIX + "team.maxsize.*")) { if (perms.getPermission().contains(Constants.PERMPREFIX + "team.maxsize.*")) {
maxSize = Settings.maxTeamSize; maxSize = getSettings().getMaxTeamSize();
break; break;
} else { } else {
// Get the max value should there be more than one // 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 (spl.length > 1) {
if (!NumberUtils.isDigits(spl[1])) { if (!NumberUtils.isDigits(spl[1])) {
getPlugin().getLogger().severe("Player " + user.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring..."); 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.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent; import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand { public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
@ -21,7 +21,7 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
@Override @Override
public void setup() { public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.team"); this.setPermission(Constants.PERMPREFIX + "island.team");
this.setOnlyPlayer(true); this.setOnlyPlayer(true);
this.setDescription("commands.island.team.invite.accept.description"); this.setDescription("commands.island.team.invite.accept.description");
} }
@ -88,13 +88,13 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
// Set the cooldown // Set the cooldown
setResetWaitTime(user.getPlayer()); setResetWaitTime(user.getPlayer());
// Reset deaths // Reset deaths
if (Settings.teamJoinDeathReset) { if (getSettings().isTeamJoinDeathReset()) {
getPlayers().setDeaths(playerUUID, 0); getPlayers().setDeaths(playerUUID, 0);
} }
// Put player back into normal mode // Put player back into normal mode
user.setGameMode(GameMode.SURVIVAL); 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)); User inviter = User.getInstance(inviteList.get(playerUUID));
if (inviter != null) { if (inviter != null) {
inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", "[name]", user.getName()); 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.OfflinePlayer;
import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.permissions.PermissionAttachmentInfo;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent; import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.util.Util; import us.tastybento.bskyblock.util.Util;
public class IslandTeamInviteCommand extends AbstractIslandTeamCommand { public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
@ -25,7 +25,7 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
@Override @Override
public void setup() { public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.team"); this.setPermission(Constants.PERMPREFIX + "island.team");
this.setOnlyPlayer(true); this.setOnlyPlayer(true);
this.setDescription("commands.island.team.invite.description"); this.setDescription("commands.island.team.invite.description");
@ -84,16 +84,16 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
} }
Set<UUID> teamMembers = getMembers(user); Set<UUID> teamMembers = getMembers(user);
// Check if player has space on their team // Check if player has space on their team
int maxSize = Settings.maxTeamSize; int maxSize = getSettings().getMaxTeamSize();
// Dynamic team sizes with permissions // Dynamic team sizes with permissions
for (PermissionAttachmentInfo perms : user.getEffectivePermissions()) { for (PermissionAttachmentInfo perms : user.getEffectivePermissions()) {
if (perms.getPermission().startsWith(Settings.PERMPREFIX + "team.maxsize.")) { if (perms.getPermission().startsWith(Constants.PERMPREFIX + "team.maxsize.")) {
if (perms.getPermission().contains(Settings.PERMPREFIX + "team.maxsize.*")) { if (perms.getPermission().contains(Constants.PERMPREFIX + "team.maxsize.*")) {
maxSize = Settings.maxTeamSize; maxSize = getSettings().getMaxTeamSize();
break; break;
} else { } else {
// Get the max value should there be more than one // 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 (spl.length > 1) {
if (!NumberUtils.isDigits(spl[1])) { if (!NumberUtils.isDigits(spl[1])) {
getPlugin().getLogger().severe("Player " + user.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring..."); 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.List;
import java.util.UUID; import java.util.UUID;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent; import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.Settings;
public class IslandTeamInviteRejectCommand extends AbstractIslandTeamCommand { public class IslandTeamInviteRejectCommand extends AbstractIslandTeamCommand {
@ -16,7 +16,7 @@ public class IslandTeamInviteRejectCommand extends AbstractIslandTeamCommand {
@Override @Override
public void setup() { public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.team"); this.setPermission(Constants.PERMPREFIX + "island.team");
this.setOnlyPlayer(true); this.setOnlyPlayer(true);
this.setDescription("commands.island.team.invite.reject.description"); 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 java.util.List;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.Settings;
public class IslandTeamLeaveCommand extends AbstractIslandTeamCommand { public class IslandTeamLeaveCommand extends AbstractIslandTeamCommand {
@ -13,7 +13,7 @@ public class IslandTeamLeaveCommand extends AbstractIslandTeamCommand {
@Override @Override
public void setup() { public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.team"); this.setPermission(Constants.PERMPREFIX + "island.team");
this.setOnlyPlayer(true); this.setOnlyPlayer(true);
this.setDescription("commands.island.team.leave.description"); 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 java.util.List;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.Settings;
public class IslandTeamPromoteCommand extends AbstractIslandTeamCommand { public class IslandTeamPromoteCommand extends AbstractIslandTeamCommand {
@ -13,7 +13,7 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommand {
@Override @Override
public void setup() { public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.team"); this.setPermission(Constants.PERMPREFIX + "island.team");
this.setOnlyPlayer(true); this.setOnlyPlayer(true);
this.setParameters("commands.island.team.promote.parameters"); this.setParameters("commands.island.team.promote.parameters");
this.setDescription("commands.island.team.promote.description"); 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.apache.commons.lang.math.NumberUtils;
import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.permissions.PermissionAttachmentInfo;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent; import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.util.Util; import us.tastybento.bskyblock.util.Util;
@ -24,7 +24,7 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
@Override @Override
public void setup() { public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.team"); this.setPermission(Constants.PERMPREFIX + "island.team");
this.setOnlyPlayer(true); this.setOnlyPlayer(true);
this.setParameters("commands.island.team.setowner.parameters"); this.setParameters("commands.island.team.setowner.parameters");
this.setDescription("commands.island.team.setowner.description"); this.setDescription("commands.island.team.setowner.description");
@ -81,7 +81,7 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
if (target.isOnline()) { if (target.isOnline()) {
// Check if new leader has a lower range permission than the island size // Check if new leader has a lower range permission than the island size
boolean hasARangePerm = false; boolean hasARangePerm = false;
int range = Settings.islandProtectionRange; int range = getSettings().getIslandProtectionRange();
// Check for zero protection range // Check for zero protection range
Island islandByOwner = getIslands().getIsland(targetUUID); Island islandByOwner = getIslands().getIsland(targetUUID);
if (islandByOwner.getProtectionRange() == 0) { if (islandByOwner.getProtectionRange() == 0) {
@ -89,12 +89,12 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
islandByOwner.setProtectionRange(range); islandByOwner.setProtectionRange(range);
} }
for (PermissionAttachmentInfo perms : target.getEffectivePermissions()) { for (PermissionAttachmentInfo perms : target.getEffectivePermissions()) {
if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.range.")) { if (perms.getPermission().startsWith(Constants.PERMPREFIX + "island.range.")) {
if (perms.getPermission().contains(Settings.PERMPREFIX + "island.range.*")) { if (perms.getPermission().contains(Constants.PERMPREFIX + "island.range.*")) {
// Ignore // Ignore
break; break;
} else { } else {
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.range."); String[] spl = perms.getPermission().split(Constants.PERMPREFIX + "island.range.");
if (spl.length > 1) { if (spl.length > 1) {
if (!NumberUtils.isDigits(spl[1])) { if (!NumberUtils.isDigits(spl[1])) {
getPlugin().getLogger().severe("Player " + user.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring..."); 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; package us.tastybento.bskyblock.database;
import org.bukkit.plugin.Plugin; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.database.flatfile.FlatFileDatabase; import us.tastybento.bskyblock.database.flatfile.FlatFileDatabase;
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler; import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
import us.tastybento.bskyblock.database.mysql.MySQLDatabase; import us.tastybento.bskyblock.database.mysql.MySQLDatabase;
@ -14,9 +12,9 @@ public abstract class BSBDatabase {
* FLATFILE and MYSQL. Default is FLATFILE * FLATFILE and MYSQL. Default is FLATFILE
* @return Database type * @return Database type
*/ */
public static BSBDatabase getDatabase(){ public static BSBDatabase getDatabase(BSkyBlock plugin){
for(DatabaseType type : DatabaseType.values()){ for(DatabaseType type : DatabaseType.values()){
if(type == Settings.databaseType) return type.database; if(type == plugin.getSettings().getDatabaseType()) return type.database;
} }
return DatabaseType.FLATFILE.database; return DatabaseType.FLATFILE.database;
} }
@ -38,6 +36,6 @@ public abstract class BSBDatabase {
* @param dataObjectClass * @param dataObjectClass
* @return database handler * @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; package us.tastybento.bskyblock.database;
import us.tastybento.bskyblock.Settings;
public class DatabaseConnectionSettingsImpl { public class DatabaseConnectionSettingsImpl {
private String host; private String host;
private int port; private int port;
@ -25,14 +23,6 @@ public class DatabaseConnectionSettingsImpl {
this.password = password; 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 * @return the host
*/ */

View File

@ -1,14 +1,13 @@
package us.tastybento.bskyblock.database.flatfile; 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.BSBDatabase;
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler; import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
public class FlatFileDatabase extends BSBDatabase{ public class FlatFileDatabase extends BSBDatabase{
@Override @Override
public AbstractDatabaseHandler<?> getHandler(Plugin plugin, Class<?> type) { public AbstractDatabaseHandler<?> getHandler(BSkyBlock plugin, Class<?> type) {
return new FlatFileDatabaseHandler<>(plugin, type, new FlatFileDatabaseConnecter(plugin, null)); 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.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin; 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;
import us.tastybento.bskyblock.api.configuration.ConfigEntry.GameType; 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.config.StoreAt;
import us.tastybento.bskyblock.database.DatabaseConnecter; import us.tastybento.bskyblock.database.DatabaseConnecter;
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler; import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
@ -172,7 +171,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
if (!configEntry.path().isEmpty()) { if (!configEntry.path().isEmpty()) {
storageLocation = configEntry.path(); 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"); Bukkit.getLogger().info(field.getName() + " not applicable to this game type");
continue; continue;
} }

View File

@ -15,7 +15,7 @@ import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import us.tastybento.bskyblock.BSkyBlock; 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.BSBDatabase;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.database.objects.Players; import us.tastybento.bskyblock.database.objects.Players;
@ -40,7 +40,7 @@ public class PlayersManager{
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public PlayersManager(BSkyBlock plugin){ public PlayersManager(BSkyBlock plugin){
this.plugin = plugin; this.plugin = plugin;
database = BSBDatabase.getDatabase(); database = BSBDatabase.getDatabase(plugin);
// Set up the database handler to store and retrieve Players classes // Set up the database handler to store and retrieve Players classes
handler = (AbstractDatabaseHandler<Players>) database.getHandler(plugin, Players.class); handler = (AbstractDatabaseHandler<Players>) database.getHandler(plugin, Players.class);
playerCache = new HashMap<>(); playerCache = new HashMap<>();
@ -138,7 +138,7 @@ public class PlayersManager{
} else { } else {
if (DEBUG) if (DEBUG)
plugin.getLogger().info("DEBUG: new player"); plugin.getLogger().info("DEBUG: new player");
player = new Players(playerUUID); player = new Players(plugin, playerUUID);
} }
playerCache.put(playerUUID, player); playerCache.put(playerUUID, player);
return player; return player;
@ -506,7 +506,7 @@ public class PlayersManager{
addPlayer(targetUUID); addPlayer(targetUUID);
// Check if the target player has a permission bypass (admin.noban) // Check if the target player has a permission bypass (admin.noban)
Player target = plugin.getServer().getPlayer(targetUUID); 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; return false;
} }
Island island = plugin.getIslands().getIsland(playerUUID); 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 com.google.common.collect.HashBiMap;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.util.Util; import us.tastybento.bskyblock.util.Util;
@ -136,7 +135,7 @@ public class IslandCache {
public Island createIsland(Location location, UUID owner){ public Island createIsland(Location location, UUID owner){
if (DEBUG) if (DEBUG)
plugin.getLogger().info("DEBUG: adding island for " + owner + " at " + location); 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); islandsByLocation.put(location, island);
if (owner != null) if (owner != null)
islandsByUUID.put(owner, island); islandsByUUID.put(owner, island);

View File

@ -20,12 +20,11 @@ import org.bukkit.material.TrapDoor;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.database.BSBDatabase; import us.tastybento.bskyblock.database.BSBDatabase;
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler; import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.generators.IslandWorld;
import us.tastybento.bskyblock.util.DeleteIslandChunks; import us.tastybento.bskyblock.util.DeleteIslandChunks;
import us.tastybento.bskyblock.util.SafeSpotTeleport; import us.tastybento.bskyblock.util.SafeSpotTeleport;
import us.tastybento.bskyblock.util.Util; import us.tastybento.bskyblock.util.Util;
@ -50,7 +49,7 @@ public class IslandsManager {
* - Location to be checked * - Location to be checked
* @return true if safe, otherwise false * @return true if safe, otherwise false
*/ */
public static boolean isSafeLocation(final Location l) { public boolean isSafeLocation(final Location l) {
if (l == null) { if (l == null) {
return false; return false;
} }
@ -76,7 +75,7 @@ public class IslandsManager {
// In BSkyBlock, liquid may be unsafe // In BSkyBlock, liquid may be unsafe
if (ground.isLiquid() || space1.isLiquid() || space2.isLiquid()) { if (ground.isLiquid() || space1.isLiquid() || space2.isLiquid()) {
// Check if acid has no damage // Check if acid has no damage
if (Settings.acidDamage > 0D) { if (plugin.getSettings().getAcidDamage() > 0D) {
// Bukkit.getLogger().info("DEBUG: acid"); // Bukkit.getLogger().info("DEBUG: acid");
return false; return false;
} else if (ground.getType().equals(Material.STATIONARY_LAVA) || ground.getType().equals(Material.LAVA) } else if (ground.getType().equals(Material.STATIONARY_LAVA) || ground.getType().equals(Material.LAVA)
@ -141,7 +140,7 @@ public class IslandsManager {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public IslandsManager(BSkyBlock plugin){ public IslandsManager(BSkyBlock plugin){
this.plugin = plugin; this.plugin = plugin;
database = BSBDatabase.getDatabase(); database = BSBDatabase.getDatabase(plugin);
// Set up the database handler to store and retrieve Island classes // Set up the database handler to store and retrieve Island classes
handler = (AbstractDatabaseHandler<Island>) database.getHandler(plugin, Island.class); handler = (AbstractDatabaseHandler<Island>) database.getHandler(plugin, Island.class);
islandCache = new IslandCache(); islandCache = new IslandCache();
@ -248,7 +247,7 @@ public class IslandsManager {
public Island createIsland(Location location, UUID owner){ public Island createIsland(Location location, UUID owner){
if (DEBUG) if (DEBUG)
plugin.getLogger().info("DEBUG: adding island for " + owner + " at " + location); 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); //player.sendBlockChange(home, Material.GLOWSTONE, (byte)0);
User user = User.getInstance(player); User user = User.getInstance(player);
if (number == 1) { if (number == 1) {
user.sendMessage("commands.island.go.teleport", "[label]", Settings.ISLANDCOMMAND); user.sendMessage("commands.island.go.teleport", "[label]", Constants.ISLANDCOMMAND);
} else { } else {
user.sendMessage("commands.island.go.island.go.teleported", "[number]", String.valueOf(number)); 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)) { if (plugin.getPlayers().hasIsland(uuid) || plugin.getPlayers().inTeam(uuid)) {
islandTestLocations.add(plugin.getIslands().getIslandLocation(uuid)); islandTestLocations.add(plugin.getIslands().getIslandLocation(uuid));
// If new Nether // 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))); 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 // 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 // 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())) { if (islandTestLocation != null && islandTestLocation.getWorld() != null && islandTestLocation.getWorld().equals(loc.getWorld())) {
int protectionRange = Settings.islandProtectionRange; int protectionRange = plugin.getSettings().getIslandProtectionRange();
if (getIslandAt(islandTestLocation) != null) { if (getIslandAt(islandTestLocation) != null) {
// Get the protection range for this location if possible // Get the protection range for this location if possible
Island island = getProtectedIslandAt(islandTestLocation); Island island = getProtectedIslandAt(islandTestLocation);
@ -781,10 +780,10 @@ public class IslandsManager {
// Run through all the locations // Run through all the locations
for (Location islandTestLocation : islandTestLocations) { for (Location islandTestLocation : islandTestLocations) {
if (loc.getWorld().equals(islandTestLocation.getWorld())) { if (loc.getWorld().equals(islandTestLocation.getWorld())) {
if (loc.getX() >= islandTestLocation.getX() - Settings.islandProtectionRange if (loc.getX() >= islandTestLocation.getX() - plugin.getSettings().getIslandProtectionRange()
&& loc.getX() < islandTestLocation.getX() + Settings.islandProtectionRange && loc.getX() < islandTestLocation.getX() + plugin.getSettings().getIslandProtectionRange()
&& loc.getZ() >= islandTestLocation.getZ() - Settings.islandProtectionRange && loc.getZ() >= islandTestLocation.getZ() - plugin.getSettings().getIslandProtectionRange()
&& loc.getZ() < islandTestLocation.getZ() + Settings.islandProtectionRange) { && loc.getZ() < islandTestLocation.getZ() + plugin.getSettings().getIslandProtectionRange()) {
return true; return true;
} }
} }
@ -807,7 +806,7 @@ public class IslandsManager {
*/ */
private Location netherIsland(Location islandLocation) { private Location netherIsland(Location islandLocation) {
//plugin.getLogger().info("DEBUG: netherworld = " + ASkyBlock.getNetherWorld()); //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(); Island spawn = getSpawn();
if (spawn != null) { if (spawn != null) {
// go to island spawn // 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."); //plugin.getLogger().warning("During island deletion player " + player.getName() + " sent to spawn.");
} else { } else {
if (!player.performCommand(Settings.SPAWNCOMMAND)) { if (!player.performCommand(Constants.SPAWNCOMMAND)) {
plugin.getLogger().warning( plugin.getLogger().warning(
"During island deletion player " + player.getName() + " could not be sent to spawn so was dropped, sorry."); "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.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent; import us.tastybento.bskyblock.api.events.island.IslandEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason; 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.database.objects.Island;
import us.tastybento.bskyblock.generators.IslandWorld;
import us.tastybento.bskyblock.island.builders.IslandBuilder; import us.tastybento.bskyblock.island.builders.IslandBuilder;
import us.tastybento.bskyblock.island.builders.IslandBuilder.IslandType; import us.tastybento.bskyblock.island.builders.IslandBuilder.IslandType;
@ -23,13 +21,14 @@ import us.tastybento.bskyblock.island.builders.IslandBuilder.IslandType;
*/ */
public class NewIsland { public class NewIsland {
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
private final BSkyBlock plugin = BSkyBlock.getInstance(); private BSkyBlock plugin;
private Island island; private Island island;
private final Player player; private final Player player;
private final Reason reason; private final Reason reason;
private NewIsland(Island oldIsland, Player player, Reason reason) { private NewIsland(BSkyBlock plugin, Island oldIsland, Player player, Reason reason) {
super(); super();
this.plugin = plugin;
this.player = player; this.player = player;
this.reason = reason; this.reason = reason;
newIsland(); newIsland();
@ -48,10 +47,11 @@ public class NewIsland {
/** /**
* Start building a new island * Start building a new island
* @param plugin
* @return New island builder object * @return New island builder object
*/ */
public static Builder builder() { public static Builder builder(BSkyBlock plugin) {
return new Builder(); return new Builder(plugin);
} }
/** /**
@ -63,6 +63,12 @@ public class NewIsland {
private Island oldIsland; private Island oldIsland;
private Player player; private Player player;
private Reason reason; private Reason reason;
private BSkyBlock plugin;
public Builder(BSkyBlock plugin) {
this.plugin = plugin;
}
public Builder oldIsland(Island oldIsland) { public Builder oldIsland(Island oldIsland) {
this.oldIsland = oldIsland; this.oldIsland = oldIsland;
@ -82,7 +88,7 @@ public class NewIsland {
public Island build() throws IOException { public Island build() throws IOException {
if (player != null) { if (player != null) {
NewIsland newIsland = new NewIsland(oldIsland, player, reason); NewIsland newIsland = new NewIsland(plugin, oldIsland, player, reason);
return newIsland.getIsland(); return newIsland.getIsland();
} }
throw new IOException("Insufficient parameters. Must have a schematic and a player"); throw new IOException("Insufficient parameters. Must have a schematic and a player");
@ -132,22 +138,22 @@ public class NewIsland {
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) { if (!event.isCancelled()) {
// Create island // Create island
new IslandBuilder(island) new IslandBuilder(plugin, island)
.setPlayer(player) .setPlayer(player)
.setChestItems(Settings.chestItems) .setChestItems(plugin.getSettings().getChestItems())
.setType(IslandType.ISLAND) .setType(IslandType.ISLAND)
.build(); .build();
if (Settings.netherGenerate && Settings.netherIslands && IslandWorld.getNetherWorld() != null) { if (plugin.getSettings().isNetherGenerate() && plugin.getSettings().isNetherIslands() && plugin.getIslandWorldManager().getNetherWorld() != null) {
new IslandBuilder(island) new IslandBuilder(plugin,island)
.setPlayer(player) .setPlayer(player)
.setChestItems(Settings.chestItems) .setChestItems(plugin.getSettings().getChestItems())
.setType(IslandType.NETHER) .setType(IslandType.NETHER)
.build(); .build();
} }
if (Settings.endGenerate && Settings.endIslands && IslandWorld.getEndWorld() != null) { if (plugin.getSettings().isEndGenerate() && plugin.getSettings().isEndIslands() && plugin.getIslandWorldManager().getEndWorld() != null) {
new IslandBuilder(island) new IslandBuilder(plugin,island)
.setPlayer(player) .setPlayer(player)
.setChestItems(Settings.chestItems) .setChestItems(plugin.getSettings().getChestItems())
.setType(IslandType.END) .setType(IslandType.END)
.build(); .build();
} }
@ -188,7 +194,8 @@ public class NewIsland {
// Find the next free spot // Find the next free spot
if (last == null) { 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(); Location next = last.clone();
if (DEBUG) if (DEBUG)
@ -218,25 +225,25 @@ public class NewIsland {
Location nextPos = lastIsland; Location nextPos = lastIsland;
if (x < z) { if (x < z) {
if (-1 * x < z) { if (-1 * x < z) {
nextPos.setX(nextPos.getX() + Settings.islandDistance*2); nextPos.setX(nextPos.getX() + plugin.getSettings().getIslandDistance()*2);
return nextPos; return nextPos;
} }
nextPos.setZ(nextPos.getZ() + Settings.islandDistance*2); nextPos.setZ(nextPos.getZ() + plugin.getSettings().getIslandDistance()*2);
return nextPos; return nextPos;
} }
if (x > z) { if (x > z) {
if (-1 * x >= z) { if (-1 * x >= z) {
nextPos.setX(nextPos.getX() - Settings.islandDistance*2); nextPos.setX(nextPos.getX() - plugin.getSettings().getIslandDistance()*2);
return nextPos; return nextPos;
} }
nextPos.setZ(nextPos.getZ() - Settings.islandDistance*2); nextPos.setZ(nextPos.getZ() - plugin.getSettings().getIslandDistance()*2);
return nextPos; return nextPos;
} }
if (x <= 0) { if (x <= 0) {
nextPos.setZ(nextPos.getZ() + Settings.islandDistance*2); nextPos.setZ(nextPos.getZ() + plugin.getSettings().getIslandDistance()*2);
return nextPos; return nextPos;
} }
nextPos.setZ(nextPos.getZ() - Settings.islandDistance*2); nextPos.setZ(nextPos.getZ() - plugin.getSettings().getIslandDistance()*2);
return nextPos; return nextPos;
} }
} }

View File

@ -1,7 +1,6 @@
package us.tastybento.bskyblock.database.mysql; 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.BSBDatabase;
import us.tastybento.bskyblock.database.DatabaseConnectionSettingsImpl; import us.tastybento.bskyblock.database.DatabaseConnectionSettingsImpl;
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler; import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
@ -9,8 +8,14 @@ import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
public class MySQLDatabase extends BSBDatabase{ public class MySQLDatabase extends BSBDatabase{
@Override @Override
public AbstractDatabaseHandler<?> getHandler(Plugin plugin, Class<?> type) { public AbstractDatabaseHandler<?> getHandler(BSkyBlock plugin, Class<?> type) {
return new MySQLDatabaseHandler<>(plugin, type, new MySQLDatabaseConnecter(new DatabaseConnectionSettingsImpl())); 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; package us.tastybento.bskyblock.database.objects;
import us.tastybento.bskyblock.BSkyBlock;
/** /**
* Contains fields that must be in any data object * Contains fields that must be in any data object
* @author tastybento * @author tastybento
* *
*/ */
public abstract class DataObject { public interface DataObject {
default BSkyBlock getPlugin() {
return BSkyBlock.getInstance();
}
/** /**
* @return the uniqueId * @return the uniqueId
*/ */
public abstract String getUniqueId(); abstract String getUniqueId();
/** /**
* @param uniqueId the uniqueId to set * @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.block.BlockState;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent; 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.IslandLockEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent.IslandUnlockEvent; import us.tastybento.bskyblock.api.events.island.IslandEvent.IslandUnlockEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason; import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
import us.tastybento.bskyblock.api.flags.Flag; import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.util.Util; import us.tastybento.bskyblock.util.Util;
/** /**
@ -30,11 +30,10 @@ import us.tastybento.bskyblock.util.Util;
* @author Tastybento * @author Tastybento
* @author Poslovitch * @author Poslovitch
*/ */
public class Island extends DataObject { public class Island implements DataObject {
private String uniqueId = ""; private String uniqueId = "";
@Override
public String getUniqueId() { public String getUniqueId() {
// Island's have UUID's that are randomly assigned if they do not exist // Island's have UUID's that are randomly assigned if they do not exist
if (uniqueId.isEmpty()) { if (uniqueId.isEmpty()) {
@ -43,7 +42,6 @@ public class Island extends DataObject {
return uniqueId; return uniqueId;
} }
@Override
public void setUniqueId(String uniqueId) { public void setUniqueId(String uniqueId) {
this.uniqueId = uniqueId; this.uniqueId = uniqueId;
} }
@ -53,7 +51,7 @@ public class Island extends DataObject {
private Location center; private Location center;
// Island range // Island range
private int range = Settings.islandDistance; private int range;
// Coordinates of the island area // Coordinates of the island area
private int minX; private int minX;
@ -105,14 +103,14 @@ public class Island extends DataObject {
public Island() {} 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.members.add(owner);
this.owner = owner; this.owner = owner;
this.createdDate = System.currentTimeMillis(); this.createdDate = System.currentTimeMillis();
this.updatedDate = System.currentTimeMillis(); this.updatedDate = System.currentTimeMillis();
this.world = location.getWorld(); this.world = location.getWorld();
this.center = location; this.center = location;
this.range = Settings.islandDistance; this.range = plugin.getSettings().getIslandProtectionRange();
this.minX = center.getBlockX() - range; this.minX = center.getBlockX() - range;
this.minZ = center.getBlockZ() - range; this.minZ = center.getBlockZ() - range;
this.protectionRange = protectionRange; this.protectionRange = protectionRange;

View File

@ -9,14 +9,14 @@ import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.BSkyBlock;
/** /**
* Tracks the following info on the player * Tracks the following info on the player
* *
* @author tastybento * @author tastybento
*/ */
public class Players extends DataObject { public class Players implements DataObject {
private HashMap<Integer, Location> homeLocations; private HashMap<Integer, Location> homeLocations;
private String uniqueId; private String uniqueId;
private String playerName; private String playerName;
@ -31,15 +31,16 @@ public class Players extends DataObject {
public Players() {} public Players() {}
/** /**
* @param plugin
* @param uniqueId * @param uniqueId
* Constructor - initializes the state variables * Constructor - initializes the state variables
* *
*/ */
public Players(final UUID uniqueId) { public Players(BSkyBlock plugin, final UUID uniqueId) {
this.uniqueId = uniqueId.toString(); this.uniqueId = uniqueId.toString();
this.homeLocations = new HashMap<>(); this.homeLocations = new HashMap<>();
this.playerName = ""; this.playerName = "";
this.resetsLeft = Settings.resetLimit; this.resetsLeft = plugin.getSettings().getResetLimit();
this.locale = ""; this.locale = "";
this.kickedList = new HashMap<>(); this.kickedList = new HashMap<>();
this.playerName = Bukkit.getServer().getOfflinePlayer(uniqueId).getName(); this.playerName = Bukkit.getServer().getOfflinePlayer(uniqueId).getName();
@ -200,8 +201,8 @@ public class Players extends DataObject {
*/ */
public void setDeaths(int deaths) { public void setDeaths(int deaths) {
this.deaths = deaths; this.deaths = deaths;
if (this.deaths > Settings.deathsMax) { if (this.deaths > getPlugin().getSettings().getDeathsMax()) {
this.deaths = Settings.deathsMax; this.deaths = getPlugin().getSettings().getDeathsMax();
} }
} }
@ -210,8 +211,8 @@ public class Players extends DataObject {
*/ */
public void addDeath() { public void addDeath() {
this.deaths++; this.deaths++;
if (this.deaths > Settings.deathsMax) { if (this.deaths > getPlugin().getSettings().getDeathsMax()) {
this.deaths = Settings.deathsMax; this.deaths = getPlugin().getSettings().getDeathsMax();
} }
} }
@ -233,7 +234,7 @@ public class Players extends DataObject {
Calendar coolDownTime = Calendar.getInstance(); Calendar coolDownTime = Calendar.getInstance();
coolDownTime.setTime(kickedDate); coolDownTime.setTime(kickedDate);
// coolDownTime.add(Calendar.HOUR_OF_DAY, Settings.inviteWait); // 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 // Add the invite cooldown period
Calendar timeNow = Calendar.getInstance(); Calendar timeNow = Calendar.getInstance();
// plugin.getLogger().info("DEBUG: date now = " + timeNow); // 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.generator.ChunkGenerator;
import org.bukkit.util.noise.PerlinOctaveGenerator; import org.bukkit.util.noise.PerlinOctaveGenerator;
import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.BSkyBlock;
/** /**
* @author tastybento * @author tastybento
* Creates the world * Creates the world
*/ */
public class ChunkGeneratorWorld extends ChunkGenerator { public class ChunkGeneratorWorld extends ChunkGenerator {
BSkyBlock plugin;
Random rand = new Random(); Random rand = new Random();
PerlinOctaveGenerator gen; PerlinOctaveGenerator gen;
//BSkyBlock plugin = BSkyBlock.getPlugin();
/**
* @param plugin
*/
public ChunkGeneratorWorld(BSkyBlock plugin) {
super();
this.plugin = plugin;
}
@Override @Override
public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, ChunkGenerator.BiomeGrid biomeGrid) { 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); return generateNetherChunks(world, random, chunkX, chunkZ, biomeGrid);
} }
ChunkData result = createChunkData(world); ChunkData result = createChunkData(world);
if (Settings.seaHeight != 0) { if (plugin.getSettings().getSeaHeight() != 0) {
for (int x = 0; x < 16; x++) { for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) { 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); result.setBlock(x, y, z, Material.STATIONARY_WATER);
} }
} }
@ -64,7 +73,7 @@ public class ChunkGeneratorWorld extends ChunkGenerator {
if (!world.getEnvironment().equals(Environment.NETHER)) { if (!world.getEnvironment().equals(Environment.NETHER)) {
return result; return result;
} }
if (Settings.netherRoof) { if (plugin.getSettings().isNetherRoof()) {
// Make the roof - common across the world // Make the roof - common across the world
for (int x = 0; x < 16; x++) { for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) { for (int z = 0; z < 16; z++) {

View File

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

View File

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

View File

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

View File

@ -1,13 +1,14 @@
package us.tastybento.bskyblock.managers; 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.ArrayList;
import java.util.List; 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 { public final class FlagsManager {
private List<Flag> flags = new ArrayList<>(); 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.BSkyBlock;
import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.localization.BSBLocale; import us.tastybento.bskyblock.api.localization.BSBLocale;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.util.FileLister; import us.tastybento.bskyblock.util.FileLister;
/** /**
@ -23,7 +22,7 @@ public final class LocalesManager {
public LocalesManager(BSkyBlock plugin) { public LocalesManager(BSkyBlock plugin) {
this.plugin = 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)) if (locale != null && locale.contains(reference))
return locale.get(reference); return locale.get(reference);
// Return the default // Return the default
if (languages.get(Locale.forLanguageTag(Settings.defaultLanguage)).contains(reference)) { if (languages.get(Locale.forLanguageTag(plugin.getSettings().getDefaultLanguage())).contains(reference)) {
return languages.get(Locale.forLanguageTag(Settings.defaultLanguage)).get(reference); return languages.get(Locale.forLanguageTag(plugin.getSettings().getDefaultLanguage())).get(reference);
} }
return null; return null;
} }
@ -49,25 +48,38 @@ public final class LocalesManager {
* TODO: Make more robust. The file filter is fragile. * TODO: Make more robust. The file filter is fragile.
*/ */
public void loadLocales(String parent) { 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 // Describe the filter - we only want files that are correctly named
FilenameFilter ymlFilter = new FilenameFilter() { FilenameFilter ymlFilter = new FilenameFilter() {
@Override @Override
public boolean accept(File dir, String name) { public boolean accept(File dir, String name) {
//plugin.getLogger().info("DEBUG: filename = " + name + " parent = " + parent ); // Do BSkyBlock files
if (name.startsWith(parent) && name.toLowerCase().endsWith(".yml")) { if (parent.isEmpty()) {
// See if this is a valid locale if (name.toLowerCase().endsWith(".yml") && name.length() == 9) {
if (name.length() < 9) if (DEBUG)
return false; plugin.getLogger().info("DEBUG: bsb locale filename = " + name);
//Locale localeObject = Locale.forLanguageTag(name.substring(name.length() - 9, name.length() - 4)); return true;
}
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 // 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 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 it does exist, then new files will NOT be written!
if (!localeDir.exists()) { if (!localeDir.exists()) {
@ -90,9 +102,13 @@ public final class LocalesManager {
if (DEBUG) if (DEBUG)
plugin.getLogger().info("DEBUG: locale country found = " + localeObject.getCountry()); plugin.getLogger().info("DEBUG: locale country found = " + localeObject.getCountry());
if (languages.containsKey(localeObject)) { if (languages.containsKey(localeObject)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: this locale is known");
// Merge into current language // Merge into current language
languages.get(localeObject).merge(language); languages.get(localeObject).merge(language);
} else { } else {
if (DEBUG)
plugin.getLogger().info("DEBUG: this locale is not known - new language");
// New language // New language
languages.put(localeObject, new BSBLocale(localeObject, 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.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent; import us.tastybento.bskyblock.api.events.island.IslandEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason; 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.database.objects.Island;
import us.tastybento.bskyblock.generators.IslandWorld;
//import com.wasteofplastic.askyblock.nms.NMSAbstraction; //import com.wasteofplastic.askyblock.nms.NMSAbstraction;
@ -42,12 +40,12 @@ public class DeleteIslandChunks {
for (int x = minXChunk; x <= maxXChunk; x++) { for (int x = minXChunk; x <= maxXChunk; x++) {
for (int z = minZChunk; z<=maxZChunk; z++) { for (int z = minZChunk; z<=maxZChunk; z++) {
world.regenerateChunk(x, z); world.regenerateChunk(x, z);
if (Settings.netherIslands && Settings.netherGenerate) { if (plugin.getSettings().isNetherGenerate() && plugin.getSettings().isNetherIslands()) {
IslandWorld.getNetherWorld().regenerateChunk(x, z); plugin.getIslandWorldManager().getNetherWorld().regenerateChunk(x, z);
} }
if (Settings.endIslands && Settings.endGenerate) { if (plugin.getSettings().isEndGenerate() && plugin.getSettings().isEndIslands()) {
IslandWorld.getEndWorld().regenerateChunk(x, z); 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.BSkyBlock;
import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.generators.IslandWorld;
/** /**
* A set of utility methods * A set of utility methods
@ -37,7 +35,6 @@ import us.tastybento.bskyblock.generators.IslandWorld;
* @author Poslovitch * @author Poslovitch
*/ */
public class Util { public class Util {
private static BSkyBlock plugin = BSkyBlock.getInstance();
private static String serverVersion = null; private static String serverVersion = null;
@ -47,7 +44,7 @@ public class Util {
*/ */
public static String getServerVersion() { public static String getServerVersion() {
if (serverVersion == null) { if (serverVersion == null) {
String serverPackageName = plugin.getServer().getClass().getPackage().getName(); String serverPackageName = getPlugin().getServer().getClass().getPackage().getName();
serverVersion = serverPackageName.substring(serverPackageName.lastIndexOf('.') + 1); serverVersion = serverPackageName.substring(serverPackageName.lastIndexOf('.') + 1);
} }
return serverVersion; return serverVersion;
@ -135,8 +132,8 @@ public class Util {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static List<ItemStack> getPlayerInHandItems(Player player) { public static List<ItemStack> getPlayerInHandItems(Player player) {
List<ItemStack> result = new ArrayList<ItemStack>(2); List<ItemStack> result = new ArrayList<ItemStack>(2);
if (plugin.getServer().getVersion().contains("(MC: 1.7") if (getPlugin().getServer().getVersion().contains("(MC: 1.7")
|| plugin.getServer().getVersion().contains("(MC: 1.8")) { || getPlugin().getServer().getVersion().contains("(MC: 1.8")) {
if (player.getItemInHand() != null) if (player.getItemInHand() != null)
result.add(player.getItemInHand()); result.add(player.getItemInHand());
return result; return result;
@ -185,8 +182,8 @@ public class Util {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static boolean playerIsHolding(Player player, Material type) { public static boolean playerIsHolding(Player player, Material type) {
if (plugin.getServer().getVersion().contains("(MC: 1.7") if (getPlugin().getServer().getVersion().contains("(MC: 1.7")
|| plugin.getServer().getVersion().contains("(MC: 1.8")) { || getPlugin().getServer().getVersion().contains("(MC: 1.8")) {
if (player.getItemInHand() != null && player.getItemInHand().getType().equals(type)) { if (player.getItemInHand() != null && player.getItemInHand().getType().equals(type)) {
return true; return true;
} }
@ -209,13 +206,13 @@ public class Util {
*/ */
public static boolean inWorld(Location loc) { public static boolean inWorld(Location loc) {
if (loc != null) { if (loc != null) {
if (loc.getWorld().equals(IslandWorld.getIslandWorld())) { if (loc.getWorld().equals(getPlugin().getIslandWorldManager().getIslandWorld())) {
return true; return true;
} }
if (Settings.netherIslands && loc.getWorld().equals(IslandWorld.getNetherWorld())) { if (getPlugin().getSettings().isNetherIslands() && loc.getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) {
return true; return true;
} }
if (Settings.endIslands && loc.getWorld().equals(IslandWorld.getEndWorld())) { if (getPlugin().getSettings().isEndIslands() && loc.getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) {
return true; return true;
} }
} }
@ -320,7 +317,7 @@ public class Util {
} }
public static void runCommand(final Player player, final String string) { 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 @Override
public void run() { public void run() {
@ -364,7 +361,7 @@ public class Util {
// In ASkyBlock, liquid may be unsafe // In ASkyBlock, liquid may be unsafe
if (ground.isLiquid() || space1.isLiquid() || space2.isLiquid()) { if (ground.isLiquid() || space1.isLiquid() || space2.isLiquid()) {
// Check if acid has no damage // Check if acid has no damage
if (Settings.acidDamage > 0D) { if (getPlugin().getSettings().getAcidDamage() > 0D) {
// Bukkit.getLogger().info("DEBUG: acid"); // Bukkit.getLogger().info("DEBUG: acid");
return false; return false;
} else if (ground.getType().equals(Material.STATIONARY_LAVA) || ground.getType().equals(Material.LAVA) } 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 + "."); String[] spl = perms.getPermission().split(perm + ".");
if (spl.length > 1) { if (spl.length > 1) {
if (!NumberUtils.isDigits(spl[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 { } else {
permValue = Math.max(permValue, Integer.valueOf(spl[1])); permValue = Math.max(permValue, Integer.valueOf(spl[1]));
@ -443,4 +440,12 @@ public class Util {
return permValue; 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 org.mockito.Mockito;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent; import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.util.Util; import us.tastybento.bskyblock.util.Util;
public class TestBSkyBlock { public class TestBSkyBlock {
@ -56,7 +56,7 @@ public class TestBSkyBlock {
Mockito.when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger()); Mockito.when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
sender = mock(CommandSender.class); sender = mock(CommandSender.class);
player = mock(Player.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); plugin = mock(BSkyBlock.class);
//Mockito.when(plugin.getServer()).thenReturn(server); //Mockito.when(plugin.getServer()).thenReturn(server);
@ -81,7 +81,7 @@ public class TestBSkyBlock {
User user = User.getInstance(playerUUID); User user = User.getInstance(playerUUID);
CompositeCommand testCommand = new TestCommand(); CompositeCommand testCommand = new TestCommand();
testCommand.setOnlyPlayer(true); testCommand.setOnlyPlayer(true);
testCommand.setPermission(Settings.PERMPREFIX + "default.permission"); testCommand.setPermission(Constants.PERMPREFIX + "default.permission");
// Test basic execution // Test basic execution
assertTrue(testCommand.execute(user, new ArrayList<>())); assertTrue(testCommand.execute(user, new ArrayList<>()));
assertEquals("test",testCommand.getLabel()); assertEquals("test",testCommand.getLabel());
@ -89,7 +89,7 @@ public class TestBSkyBlock {
assertEquals("t", testCommand.getAliases().get(0)); assertEquals("t", testCommand.getAliases().get(0));
assertTrue(testCommand.isOnlyPlayer()); assertTrue(testCommand.isOnlyPlayer());
assertNull(testCommand.getParent()); 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 // Check commands and aliases match to correct class
for (Entry<String, CompositeCommand> command : testCommand.getSubCommands().entrySet()) { for (Entry<String, CompositeCommand> command : testCommand.getSubCommands().entrySet()) {
assertEquals(testCommand.getSubCommand(command.getKey()), Optional.of(command.getValue())); assertEquals(testCommand.getSubCommand(command.getKey()), Optional.of(command.getValue()));
@ -123,7 +123,7 @@ public class TestBSkyBlock {
// Test command arguments // Test command arguments
CompositeCommand argCmd = new Test3ArgsCommand(); CompositeCommand argCmd = new Test3ArgsCommand();
argCmd.setOnlyPlayer(true); 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"})); 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"}));
assertFalse(testCommand.execute(player, "test", new String[] {"sub2", "subsub", "subsubsub", "ben"})); assertFalse(testCommand.execute(player, "test", new String[] {"sub2", "subsub", "subsubsub", "ben"}));