2017-05-20 23:52:52 +02:00
|
|
|
package us.tastybento.bskyblock;
|
2017-05-20 23:09:53 +02:00
|
|
|
|
2017-08-13 03:51:48 +02:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2017-06-11 01:08:21 +02:00
|
|
|
import org.bukkit.Material;
|
2017-05-20 23:09:53 +02:00
|
|
|
import org.bukkit.command.CommandSender;
|
2017-06-11 01:08:21 +02:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2017-07-06 19:21:38 +02:00
|
|
|
import org.bukkit.plugin.PluginManager;
|
2017-05-20 23:09:53 +02:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
2017-08-13 03:51:48 +02:00
|
|
|
|
2017-07-30 19:57:49 +02:00
|
|
|
import us.tastybento.bskyblock.commands.AdminCommand;
|
2017-06-11 01:08:21 +02:00
|
|
|
import us.tastybento.bskyblock.commands.IslandCommand;
|
2017-12-03 17:34:31 +01:00
|
|
|
import us.tastybento.bskyblock.config.BSBLocale;
|
2017-10-22 04:53:07 +02:00
|
|
|
import us.tastybento.bskyblock.config.LocaleManager;
|
2017-05-24 17:10:49 +02:00
|
|
|
import us.tastybento.bskyblock.config.PluginConfig;
|
2017-05-20 23:52:52 +02:00
|
|
|
import us.tastybento.bskyblock.config.Settings;
|
2017-05-21 08:03:17 +02:00
|
|
|
import us.tastybento.bskyblock.database.BSBDatabase;
|
2017-05-31 16:32:36 +02:00
|
|
|
import us.tastybento.bskyblock.database.managers.OfflineHistoryMessages;
|
|
|
|
import us.tastybento.bskyblock.database.managers.PlayersManager;
|
2017-11-21 01:05:52 +01:00
|
|
|
import us.tastybento.bskyblock.database.managers.island.IslandsManager;
|
2017-06-10 23:03:41 +02:00
|
|
|
import us.tastybento.bskyblock.generators.IslandWorld;
|
2017-07-06 19:21:38 +02:00
|
|
|
import us.tastybento.bskyblock.listeners.JoinLeaveListener;
|
2017-07-07 01:51:40 +02:00
|
|
|
import us.tastybento.bskyblock.listeners.NetherPortals;
|
2017-11-29 16:54:24 +01:00
|
|
|
import us.tastybento.bskyblock.listeners.PanelListener;
|
2017-07-07 07:00:21 +02:00
|
|
|
import us.tastybento.bskyblock.listeners.protection.IslandGuard;
|
|
|
|
import us.tastybento.bskyblock.listeners.protection.IslandGuard1_8;
|
|
|
|
import us.tastybento.bskyblock.listeners.protection.IslandGuard1_9;
|
|
|
|
import us.tastybento.bskyblock.listeners.protection.NetherEvents;
|
2017-12-10 09:19:20 +01:00
|
|
|
import us.tastybento.bskyblock.util.Util;
|
2017-05-20 23:52:52 +02:00
|
|
|
import us.tastybento.bskyblock.util.VaultHelper;
|
2017-12-10 09:19:20 +01:00
|
|
|
import us.tastybento.bskyblock.util.nms.NMSAbstraction;
|
2017-05-20 23:09:53 +02:00
|
|
|
|
|
|
|
/**
|
2017-05-20 23:52:52 +02:00
|
|
|
* Main BSkyBlock class - provides an island minigame in the sky
|
2017-05-20 23:09:53 +02:00
|
|
|
* @author Tastybento
|
|
|
|
* @author Poslovitch
|
|
|
|
*/
|
2017-11-29 16:54:24 +01:00
|
|
|
public class BSkyBlock extends JavaPlugin {
|
2017-06-12 01:30:34 +02:00
|
|
|
|
2017-05-20 23:52:52 +02:00
|
|
|
private static BSkyBlock plugin;
|
2017-10-23 04:08:34 +02:00
|
|
|
|
2017-05-20 23:09:53 +02:00
|
|
|
// Databases
|
|
|
|
private PlayersManager playersManager;
|
|
|
|
private IslandsManager islandsManager;
|
|
|
|
private OfflineHistoryMessages offlineHistoryMessages;
|
2017-06-12 01:30:34 +02:00
|
|
|
|
2017-05-20 23:09:53 +02:00
|
|
|
// Metrics
|
|
|
|
private Metrics metrics;
|
2017-05-24 17:10:49 +02:00
|
|
|
|
2017-12-11 20:15:48 +01:00
|
|
|
// Commands
|
2017-10-10 07:52:57 +02:00
|
|
|
private IslandCommand islandCommand;
|
2017-12-11 20:15:48 +01:00
|
|
|
private AdminCommand adminCommand;
|
2017-10-10 07:52:57 +02:00
|
|
|
|
2017-10-22 04:53:07 +02:00
|
|
|
protected LocaleManager localeManager;
|
|
|
|
|
2017-05-20 23:09:53 +02:00
|
|
|
@Override
|
|
|
|
public void onEnable(){
|
|
|
|
plugin = this;
|
2017-05-30 04:02:43 +02:00
|
|
|
|
2017-05-24 22:23:16 +02:00
|
|
|
// Load configuration and locales. If there are no errors, load the plugin.
|
2017-05-24 17:10:49 +02:00
|
|
|
if(PluginConfig.loadPluginConfig(this)){
|
2017-11-21 01:05:52 +01:00
|
|
|
|
2017-05-24 17:10:49 +02:00
|
|
|
playersManager = new PlayersManager(this);
|
|
|
|
islandsManager = new IslandsManager(this);
|
2017-05-30 04:02:43 +02:00
|
|
|
// Only load metrics if set to true in config
|
2017-12-11 20:15:48 +01:00
|
|
|
if(Settings.metrics) {
|
|
|
|
metrics = new Metrics(plugin);
|
2017-05-30 04:02:43 +02:00
|
|
|
registerCustomCharts();
|
|
|
|
}
|
2017-05-24 17:10:49 +02:00
|
|
|
|
|
|
|
offlineHistoryMessages = new OfflineHistoryMessages(this);
|
|
|
|
offlineHistoryMessages.load();
|
|
|
|
|
|
|
|
if (Settings.useEconomy && !VaultHelper.setupEconomy()) {
|
|
|
|
getLogger().warning("Could not set up economy! - Running without an economy.");
|
|
|
|
Settings.useEconomy = false;
|
|
|
|
}
|
2017-06-12 01:30:34 +02:00
|
|
|
|
2017-06-11 01:08:21 +02:00
|
|
|
VaultHelper.setupPermissions();
|
2017-05-24 17:10:49 +02:00
|
|
|
|
2017-10-10 07:52:57 +02:00
|
|
|
// Set up commands
|
2017-12-10 11:46:59 +01:00
|
|
|
islandCommand = new IslandCommand();
|
|
|
|
adminCommand = new AdminCommand();
|
2017-10-23 04:08:34 +02:00
|
|
|
|
2017-05-30 04:02:43 +02:00
|
|
|
// These items have to be loaded when the server has done 1 tick.
|
|
|
|
// Note Worlds are not loaded this early, so any Locations or World reference will be null
|
|
|
|
// at this point. Therefore, the 1 tick scheduler is required.
|
|
|
|
getServer().getScheduler().runTask(this, new Runnable() {
|
2017-05-24 17:10:49 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2017-06-10 23:03:41 +02:00
|
|
|
// Create the world if it does not exist
|
|
|
|
new IslandWorld(plugin);
|
2017-11-21 01:05:52 +01:00
|
|
|
|
|
|
|
getServer().getScheduler().runTask(plugin, new Runnable() {
|
2017-05-30 04:02:43 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2017-12-11 20:15:48 +01:00
|
|
|
// Load islands from database
|
2017-11-21 01:05:52 +01:00
|
|
|
islandsManager.load();
|
|
|
|
|
|
|
|
// TODO: load these from config.yml
|
|
|
|
Settings.chestItems = new ItemStack[] {
|
|
|
|
new ItemStack(Material.LAVA_BUCKET,1),
|
|
|
|
new ItemStack(Material.ICE,2),
|
|
|
|
new ItemStack(Material.MELON_SEEDS,1),
|
|
|
|
new ItemStack(Material.BONE,2),
|
|
|
|
new ItemStack(Material.COBBLESTONE,5),
|
|
|
|
new ItemStack(Material.SAPLING,2)
|
|
|
|
};
|
|
|
|
|
|
|
|
Settings.defaultLanguage = "en-US";
|
|
|
|
localeManager = new LocaleManager(plugin);
|
|
|
|
|
|
|
|
// Register Listeners
|
|
|
|
registerListeners();
|
|
|
|
/*
|
|
|
|
*DEBUG CODE
|
|
|
|
Island loadedIsland = islandsManager.getIsland(owner);
|
|
|
|
getLogger().info("Island name = " + loadedIsland.getName());
|
|
|
|
getLogger().info("Island locked = " + loadedIsland.getLocked());
|
|
|
|
//getLogger().info("Random set = " + randomSet);
|
|
|
|
getLogger().info("Island coops = " + loadedIsland.getCoops());
|
|
|
|
for (Entry<SettingsFlag, Boolean> flag: loadedIsland.getFlags().entrySet()) {
|
|
|
|
getLogger().info("Flag " + flag.getKey().name() + " = " + flag.getValue());
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
// Save islands & players data asynchronously every X minutes
|
|
|
|
Settings.databaseBackupPeriod = 10 * 60 * 20;
|
|
|
|
plugin.getServer().getScheduler().runTaskTimer(plugin, new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
playersManager.save(true);
|
|
|
|
islandsManager.save(true);
|
|
|
|
offlineHistoryMessages.save(true);
|
|
|
|
}
|
|
|
|
}, Settings.databaseBackupPeriod, Settings.databaseBackupPeriod);
|
2017-05-30 04:02:43 +02:00
|
|
|
}
|
2017-12-11 20:15:48 +01:00
|
|
|
});
|
2017-11-21 01:05:52 +01:00
|
|
|
}
|
2017-05-30 04:02:43 +02:00
|
|
|
});
|
2017-05-24 17:10:49 +02:00
|
|
|
}
|
2017-05-20 23:09:53 +02:00
|
|
|
}
|
2017-05-24 17:10:49 +02:00
|
|
|
|
2017-10-10 07:52:57 +02:00
|
|
|
public IslandCommand getIslandCommand() {
|
|
|
|
return islandCommand;
|
|
|
|
}
|
|
|
|
|
2017-12-11 20:15:48 +01:00
|
|
|
private void registerListeners() {
|
2017-07-07 07:00:21 +02:00
|
|
|
PluginManager manager = getServer().getPluginManager();
|
|
|
|
// Player join events
|
|
|
|
manager.registerEvents(new JoinLeaveListener(this), this);
|
|
|
|
manager.registerEvents(new NetherEvents(this), this);
|
|
|
|
manager.registerEvents(new NetherPortals(this), this);
|
|
|
|
manager.registerEvents(new IslandGuard(this), this);
|
|
|
|
manager.registerEvents(new IslandGuard1_8(this), this);
|
|
|
|
manager.registerEvents(new IslandGuard1_9(this), this);
|
2017-11-29 16:54:24 +01:00
|
|
|
manager.registerEvents(new PanelListener(this), this);
|
2017-07-07 07:00:21 +02:00
|
|
|
}
|
|
|
|
|
2017-05-20 23:09:53 +02:00
|
|
|
@Override
|
|
|
|
public void onDisable(){
|
|
|
|
// Save data
|
|
|
|
playersManager.shutdown();
|
|
|
|
islandsManager.shutdown();
|
2017-05-22 06:37:10 +02:00
|
|
|
//offlineHistoryMessages.shutdown();
|
2017-05-20 23:09:53 +02:00
|
|
|
}
|
2017-05-24 17:10:49 +02:00
|
|
|
|
2017-08-18 16:05:35 +02:00
|
|
|
private void registerCustomCharts(){
|
2017-05-20 23:09:53 +02:00
|
|
|
metrics.addCustomChart(new Metrics.SingleLineChart("islands_count") {
|
2017-05-24 17:10:49 +02:00
|
|
|
|
2017-05-20 23:09:53 +02:00
|
|
|
@Override
|
|
|
|
public int getValue() {
|
|
|
|
return islandsManager.getCount();
|
|
|
|
}
|
|
|
|
});
|
2017-05-24 17:10:49 +02:00
|
|
|
|
2017-05-20 23:09:53 +02:00
|
|
|
metrics.addCustomChart(new Metrics.SingleLineChart("created_islands") {
|
2017-05-24 17:10:49 +02:00
|
|
|
|
2017-05-20 23:09:53 +02:00
|
|
|
@Override
|
|
|
|
public int getValue() {
|
|
|
|
int created = islandsManager.metrics_getCreatedCount();
|
|
|
|
islandsManager.metrics_setCreatedCount(0);
|
|
|
|
return created;
|
|
|
|
}
|
|
|
|
});
|
2017-05-24 17:10:49 +02:00
|
|
|
|
2017-05-20 23:09:53 +02:00
|
|
|
metrics.addCustomChart(new Metrics.SimplePie("default_locale") {
|
2017-05-24 17:10:49 +02:00
|
|
|
|
2017-05-20 23:09:53 +02:00
|
|
|
@Override
|
|
|
|
public String getValue() {
|
|
|
|
return Settings.defaultLanguage;
|
|
|
|
}
|
|
|
|
});
|
2017-05-24 17:10:49 +02:00
|
|
|
|
2017-05-20 23:09:53 +02:00
|
|
|
metrics.addCustomChart(new Metrics.SimplePie("database") {
|
2017-05-24 17:10:49 +02:00
|
|
|
|
2017-05-20 23:09:53 +02:00
|
|
|
@Override
|
|
|
|
public String getValue() {
|
2017-05-21 08:03:17 +02:00
|
|
|
return BSBDatabase.getDatabase().toString();
|
2017-05-20 23:09:53 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-05-24 17:10:49 +02:00
|
|
|
|
2017-05-20 23:09:53 +02:00
|
|
|
/**
|
|
|
|
* Returns the player database
|
|
|
|
* @return the player database
|
|
|
|
*/
|
|
|
|
public PlayersManager getPlayers(){
|
|
|
|
return playersManager;
|
|
|
|
}
|
2017-05-24 17:10:49 +02:00
|
|
|
|
2017-05-20 23:09:53 +02:00
|
|
|
/**
|
|
|
|
* Returns the island database
|
|
|
|
* @return the island database
|
|
|
|
*/
|
|
|
|
public IslandsManager getIslands(){
|
|
|
|
return islandsManager;
|
|
|
|
}
|
2017-06-11 01:08:21 +02:00
|
|
|
|
|
|
|
public static BSkyBlock getPlugin() {
|
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
|
2017-10-22 04:53:07 +02:00
|
|
|
/**
|
2017-12-03 17:34:31 +01:00
|
|
|
* @param sender
|
|
|
|
* @return Locale object for sender
|
2017-10-22 04:53:07 +02:00
|
|
|
*/
|
2017-12-03 17:34:31 +01:00
|
|
|
public BSBLocale getLocale(CommandSender sender) {
|
|
|
|
return localeManager.getLocale(sender);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param uuid
|
|
|
|
* @return Locale object for UUID
|
|
|
|
*/
|
|
|
|
public BSBLocale getLocale(UUID uuid) {
|
|
|
|
return localeManager.getLocale(uuid);
|
2017-10-22 04:53:07 +02:00
|
|
|
}
|
|
|
|
|
2017-12-10 09:19:20 +01:00
|
|
|
public NMSAbstraction getNMSHandler() {
|
|
|
|
NMSAbstraction nmsHandler = null;
|
|
|
|
try {
|
|
|
|
nmsHandler = Util.getNMSHandler();
|
|
|
|
} catch(Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return nmsHandler;
|
|
|
|
}
|
2017-05-20 23:09:53 +02:00
|
|
|
}
|