Search in sources :

Example 46 with Island

use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.

the class IridiumSkyblock method onEnable.

/**
 * Plugin startup logic.
 */
@Override
public void onEnable() {
    super.onEnable();
    // Convert old IridiumSkyblock data
    DataConverter.copyLegacyData();
    // Initialize the commands
    this.commandManager = new CommandManager("iridiumskyblock");
    // Initialize the manager classes (bad) and create the world
    this.islandManager = new IslandManager();
    this.userManager = new UserManager();
    this.islandManager.createWorld(World.Environment.NORMAL, configuration.worldName);
    this.islandManager.createWorld(World.Environment.NETHER, configuration.worldName + "_nether");
    this.islandManager.createWorld(World.Environment.THE_END, configuration.worldName + "_the_end");
    this.databaseManager = new DatabaseManager();
    // Try to connect to the database
    try {
        databaseManager.init();
    } catch (SQLException exception) {
        // We don't want the plugin to start if the connection fails
        exception.printStackTrace();
        Bukkit.getPluginManager().disablePlugin(this);
        return;
    }
    this.missionManager = new MissionManager();
    this.shopManager = new ShopManager();
    shopManager.reloadCategories();
    this.schematicManager = new SchematicManager();
    // Initialize Vault economy support
    Bukkit.getScheduler().runTask(this, () -> this.economy = setupEconomy());
    this.stackerSupport = registerBlockStackerSupport();
    registerPlaceholderSupport();
    // Send island border to all players
    Bukkit.getOnlinePlayers().forEach(player -> getIslandManager().getIslandViaLocation(player.getLocation()).ifPresent(island -> PlayerUtils.sendBorder(player, island)));
    // Auto recalculate islands
    if (getConfiguration().islandRecalculateInterval > 0) {
        Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {

            ListIterator<Integer> islands = getDatabaseManager().getIslandTableManager().getEntries().stream().map(Island::getId).collect(Collectors.toList()).listIterator();

            @Override
            public void run() {
                if (!islands.hasNext()) {
                    islands = getDatabaseManager().getIslandTableManager().getEntries().stream().map(Island::getId).collect(Collectors.toList()).listIterator();
                } else {
                    getIslandManager().getIslandById(islands.next()).ifPresent(island -> getIslandManager().recalculateIsland(island));
                }
            }
        }, 0, getConfiguration().islandRecalculateInterval * 20L);
    }
    // Automatically update all inventories
    Bukkit.getScheduler().runTaskTimer(this, () -> Bukkit.getServer().getOnlinePlayers().forEach(player -> {
        InventoryHolder inventoryHolder = player.getOpenInventory().getTopInventory().getHolder();
        if (inventoryHolder instanceof GUI) {
            ((GUI) inventoryHolder).addContent(player.getOpenInventory().getTopInventory());
        }
    }), 0, 20);
    // Register worlds with multiverse
    if (Bukkit.getPluginManager().isPluginEnabled("Multiverse-Core")) {
        Bukkit.getScheduler().runTaskLater(this, () -> {
            registerMultiverse(islandManager.getWorld());
            registerMultiverse(islandManager.getNetherWorld());
            registerMultiverse(islandManager.getEndWorld());
        }, 1);
    }
    resetIslandMissions();
    if (!isTesting()) {
        Metrics metrics = new Metrics(this, 5825);
        metrics.addCustomChart(new SimplePie("database_type", () -> sql.driver.name()));
        if (getConfiguration().enableCheckVersion) {
            UpdateChecker.init(this, 62480).checkEveryXHours(24).setDownloadLink(62480).setColoredConsoleOutput(true).checkNow();
        }
    }
    getLogger().info("----------------------------------------");
    getLogger().info("");
    getLogger().info(getDescription().getName() + " Enabled!");
    getLogger().info("Version: " + getDescription().getVersion());
    getLogger().info("");
    getLogger().info("----------------------------------------");
}
Also used : Plugin(org.bukkit.plugin.Plugin) IridiumSkyblockAPI(com.iridium.iridiumskyblock.api.IridiumSkyblockAPI) java.util(java.util) Getter(lombok.Getter) ClipPlaceholderAPI(com.iridium.iridiumskyblock.placeholders.ClipPlaceholderAPI) IridiumCore(com.iridium.iridiumcore.IridiumCore) IridiumSkyblockReloadEvent(com.iridium.iridiumskyblock.api.IridiumSkyblockReloadEvent) SimplePie(org.bstats.charts.SimplePie) ChunkGenerator(org.bukkit.generator.ChunkGenerator) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) StandardCopyOption(java.nio.file.StandardCopyOption) BankItem(com.iridium.iridiumskyblock.bank.BankItem) MVDWPlaceholderAPI(com.iridium.iridiumskyblock.placeholders.MVDWPlaceholderAPI) SQLException(java.sql.SQLException) com.iridium.iridiumskyblock.managers(com.iridium.iridiumskyblock.managers) Color(com.iridium.iridiumcore.Color) World(org.bukkit.World) StackerSupport(com.iridium.iridiumskyblock.support.StackerSupport) UpdateChecker(de.jeff_media.updatechecker.UpdateChecker) NumberFormatter(com.iridium.iridiumcore.utils.NumberFormatter) ShopManager(com.iridium.iridiumskyblock.shop.ShopManager) CommandManager(com.iridium.iridiumskyblock.commands.CommandManager) Path(java.nio.file.Path) Bukkit(org.bukkit.Bukkit) RoseStackerSupport(com.iridium.iridiumskyblock.support.RoseStackerSupport) Economy(net.milkbowl.vault.economy.Economy) GUI(com.iridium.iridiumskyblock.gui.GUI) com.iridium.iridiumskyblock.configs(com.iridium.iridiumskyblock.configs) com.iridium.iridiumskyblock.listeners(com.iridium.iridiumskyblock.listeners) Files(java.nio.file.Files) Island(com.iridium.iridiumskyblock.database.Island) Metrics(org.bstats.bukkit.Metrics) IOException(java.io.IOException) EntityType(org.bukkit.entity.EntityType) Collectors(java.util.stream.Collectors) File(java.io.File) InventoryHolder(org.bukkit.inventory.InventoryHolder) Nullable(org.jetbrains.annotations.Nullable) WildStackerSupport(com.iridium.iridiumskyblock.support.WildStackerSupport) JavaPluginLoader(org.bukkit.plugin.java.JavaPluginLoader) PlayerUtils(com.iridium.iridiumskyblock.utils.PlayerUtils) NotNull(org.jetbrains.annotations.NotNull) RegisteredServiceProvider(org.bukkit.plugin.RegisteredServiceProvider) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) PluginManager(org.bukkit.plugin.PluginManager) InputStream(java.io.InputStream) SQLException(java.sql.SQLException) SimplePie(org.bstats.charts.SimplePie) Island(com.iridium.iridiumskyblock.database.Island) Metrics(org.bstats.bukkit.Metrics) CommandManager(com.iridium.iridiumskyblock.commands.CommandManager) ShopManager(com.iridium.iridiumskyblock.shop.ShopManager) GUI(com.iridium.iridiumskyblock.gui.GUI) InventoryHolder(org.bukkit.inventory.InventoryHolder)

Example 47 with Island

use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.

the class PlaceholderBuilder method applyIslandPlaceholders.

public PlaceholderBuilder applyIslandPlaceholders(Island island) {
    IslandUpgrade islandUpgrade = IridiumSkyblock.getInstance().getIslandManager().getIslandUpgrade(island, "member");
    int memberLimit = IridiumSkyblock.getInstance().getUpgrades().memberUpgrade.upgrades.get(islandUpgrade.getLevel()).amount;
    placeholderList.add(new Placeholder("island_name", island.getName()));
    placeholderList.add(new Placeholder("island_owner", island.getOwner().getName()));
    placeholderList.add(new Placeholder("island_value", IridiumSkyblock.getInstance().getNumberFormatter().format(island.getValue())));
    placeholderList.add(new Placeholder("island_rank", IridiumSkyblock.getInstance().getNumberFormatter().format(island.getRank())));
    placeholderList.add(new Placeholder("island_members", IridiumSkyblock.getInstance().getNumberFormatter().format(island.getMembers().size())));
    placeholderList.add(new Placeholder("island_members_limit", IridiumSkyblock.getInstance().getNumberFormatter().format(memberLimit)));
    placeholderList.add(new Placeholder("island_level", IridiumSkyblock.getInstance().getNumberFormatter().format(island.getLevel())));
    placeholderList.add(new Placeholder("island_create", island.getCreateTime().format(DateTimeFormatter.ofPattern(IridiumSkyblock.getInstance().getConfiguration().dateTimeFormat))));
    IridiumSkyblock.getInstance().getBlockValues().blockValues.keySet().stream().map(material -> new Placeholder(material.name() + "_AMOUNT", IridiumSkyblock.getInstance().getNumberFormatter().format(IridiumSkyblock.getInstance().getIslandManager().getIslandBlockAmount(island, material)))).forEach(placeholderList::add);
    return this;
}
Also used : IslandUpgrade(com.iridium.iridiumskyblock.database.IslandUpgrade) List(java.util.List) IslandUpgrade(com.iridium.iridiumskyblock.database.IslandUpgrade) User(com.iridium.iridiumskyblock.database.User) DateTimeFormatter(java.time.format.DateTimeFormatter) Island(com.iridium.iridiumskyblock.database.Island) Placeholder(com.iridium.iridiumcore.utils.Placeholder) ArrayList(java.util.ArrayList) Placeholder(com.iridium.iridiumcore.utils.Placeholder)

Example 48 with Island

use of com.iridium.iridiumskyblock.database.Island in project CombatLogX by SirBlobman.

the class ListenerIridiumSkyblock method doesTeamMatch.

private boolean doesTeamMatch(Player player1, Player player2) {
    UUID uuid1 = player1.getUniqueId();
    UUID uuid2 = player2.getUniqueId();
    if (uuid1.equals(uuid2))
        return true;
    Island island1 = getIsland(player1);
    if (island1 == null)
        return false;
    Island island2 = getIsland(player2);
    if (island2 == null)
        return false;
    int islandId1 = island1.getId();
    int islandId2 = island2.getId();
    return (islandId1 == islandId2);
}
Also used : UUID(java.util.UUID) Island(com.iridium.iridiumskyblock.database.Island)

Example 49 with Island

use of com.iridium.iridiumskyblock.database.Island in project CombatLogX by SirBlobman.

the class ListenerIridiumSkyblock method getIsland.

private Island getIsland(Player player) {
    if (player == null)
        return null;
    IridiumSkyblockAPI api = IridiumSkyblockAPI.getInstance();
    User user = api.getUser(player);
    Optional<Island> optionalIsland = user.getIsland();
    return optionalIsland.orElse(null);
}
Also used : User(com.iridium.iridiumskyblock.database.User) IridiumSkyblockAPI(com.iridium.iridiumskyblock.api.IridiumSkyblockAPI) Island(com.iridium.iridiumskyblock.database.Island)

Example 50 with Island

use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.

the class CommandManager method onCommand.

/**
 * Method which handles command execution for all sub-commands.
 * Automatically checks if a User can execute the command.
 * All parameters are provided by Bukkit.
 *
 * @param commandSender The sender which executes this command
 * @param cmd           The Bukkit {@link org.bukkit.command.Command} representation
 * @param label         The label of this command. Not used.
 * @param args          The arguments of this command
 * @return true if this command was executed successfully
 */
@Override
public boolean onCommand(@NotNull CommandSender commandSender, org.bukkit.command.@NotNull Command cmd, @NotNull String label, String[] args) {
    if (args.length == 0) {
        if (commandSender instanceof Player) {
            Player player = (Player) commandSender;
            User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
            Optional<Island> island = user.getIsland();
            if (island.isPresent()) {
                if (IridiumSkyblock.getInstance().getConfiguration().islandMenu) {
                    player.openInventory(new InventoryConfigGUI(IridiumSkyblock.getInstance().getInventories().islandMenu, player.getOpenInventory().getTopInventory()).getInventory());
                } else {
                    IridiumSkyblock.getInstance().getCommands().helpCommand.execute(player, new String[] {});
                }
            } else {
                IridiumSkyblock.getInstance().getCommands().createCommand.execute(player, new String[] {});
            }
        } else {
            IridiumSkyblock.getInstance().getCommands().helpCommand.execute(commandSender, new String[] {});
        }
        return true;
    }
    for (Command command : commands) {
        // We don't want to execute other commands or ones that are disabled
        if (!(command.aliases.contains(args[0]))) {
            continue;
        }
        Command executingCommand = findExecutingCommand(command, args);
        if (executionBlocked(executingCommand, commandSender)) {
            return false;
        }
        boolean success = executingCommand.execute(commandSender, args);
        if (success)
            executingCommand.getCooldownProvider().applyCooldown(commandSender);
        return true;
    }
    // Unknown command message
    commandSender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().unknownCommand.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    return false;
}
Also used : Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) Island(com.iridium.iridiumskyblock.database.Island) InventoryConfigGUI(com.iridium.iridiumskyblock.gui.InventoryConfigGUI)

Aggregations

Island (com.iridium.iridiumskyblock.database.Island)92 User (com.iridium.iridiumskyblock.database.User)76 Player (org.bukkit.entity.Player)60 EventHandler (org.bukkit.event.EventHandler)18 List (java.util.List)16 IridiumSkyblock (com.iridium.iridiumskyblock.IridiumSkyblock)15 OfflinePlayer (org.bukkit.OfflinePlayer)15 Collectors (java.util.stream.Collectors)14 IslandLog (com.iridium.iridiumskyblock.database.IslandLog)12 Optional (java.util.Optional)11 StringUtils (com.iridium.iridiumcore.utils.StringUtils)10 IslandBank (com.iridium.iridiumskyblock.database.IslandBank)10 Duration (java.time.Duration)10 Collections (java.util.Collections)9 CommandSender (org.bukkit.command.CommandSender)9 XMaterial (com.iridium.iridiumcore.dependencies.xseries.XMaterial)7 PlaceholderBuilder (com.iridium.iridiumskyblock.PlaceholderBuilder)6 BankItem (com.iridium.iridiumskyblock.bank.BankItem)6 IslandBooster (com.iridium.iridiumskyblock.database.IslandBooster)6 Bukkit (org.bukkit.Bukkit)6