Search in sources :

Example 1 with PlotDifficulty

use of com.alpsbte.plotsystem.utils.enums.PlotDifficulty in project Plot-System by AlpsBTE.

the class CompanionMenu method setCityProjectItems.

/**
 * Sets city project items asynchronously in the menu
 * @throws SQLException When querying database
 */
private void setCityProjectItems() throws SQLException {
    for (int i = 0; i < cityProjects.size(); i++) {
        if (i <= 28) {
            CityProject cp = cityProjects.get(i);
            ItemStack cpItem = cp.getCountry().getHead();
            try {
                PlotDifficulty cpPlotDifficulty = selectedPlotDifficulty != null ? selectedPlotDifficulty : PlotManager.getPlotDifficultyForBuilder(cp.getID(), new Builder(getMenuPlayer().getUniqueId())).get();
                int plotsOpen = PlotManager.getPlots(cp.getID(), Status.unclaimed).size();
                int plotsInProgress = PlotManager.getPlots(cp.getID(), Status.unfinished, Status.unreviewed).size();
                int plotsCompleted = PlotManager.getPlots(cp.getID(), Status.completed).size();
                int plotsUnclaimed = PlotManager.getPlots(cp.getID(), cpPlotDifficulty, Status.unclaimed).size();
                getMenu().getSlot(9 + cityProjects.indexOf(cp)).setItem(new ItemBuilder(cpItem).setName("§b§l" + cp.getName()).setLore(new LoreBuilder().addLines(cp.getDescription(), "", "§6" + plotsOpen + " §7" + LangUtil.get(getMenuPlayer(), LangPaths.CityProject.PROJECT_OPEN), "§8---------------------", "§6" + plotsInProgress + " §7" + LangUtil.get(getMenuPlayer(), LangPaths.CityProject.PROJECT_IN_PROGRESS), "§6" + plotsCompleted + " §7" + LangUtil.get(getMenuPlayer(), LangPaths.CityProject.PROJECT_COMPLETED), "", plotsUnclaimed != 0 ? Utils.getFormattedDifficulty(cpPlotDifficulty) : "§f§l" + LangUtil.get(getMenuPlayer(), LangPaths.CityProject.PROJECT_NO_PLOTS)).build()).build());
            } catch (SQLException | ExecutionException | InterruptedException ex) {
                Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
                getMenu().getSlot(9 + cityProjects.indexOf(cp)).setItem(MenuItems.errorItem(getMenuPlayer()));
            }
        }
    }
}
Also used : ItemBuilder(com.alpsbte.plotsystem.utils.items.builder.ItemBuilder) SQLException(java.sql.SQLException) PlotDifficulty(com.alpsbte.plotsystem.utils.enums.PlotDifficulty) LoreBuilder(com.alpsbte.plotsystem.utils.items.builder.LoreBuilder) Builder(com.alpsbte.plotsystem.core.system.Builder) ItemBuilder(com.alpsbte.plotsystem.utils.items.builder.ItemBuilder) ItemStack(org.bukkit.inventory.ItemStack) LoreBuilder(com.alpsbte.plotsystem.utils.items.builder.LoreBuilder) ExecutionException(java.util.concurrent.ExecutionException) CityProject(com.alpsbte.plotsystem.core.system.CityProject)

Example 2 with PlotDifficulty

use of com.alpsbte.plotsystem.utils.enums.PlotDifficulty in project Plot-System by AlpsBTE.

the class CompanionMenu method setItemClickEventsAsync.

@Override
protected void setItemClickEventsAsync() {
    // Set click event for navigator item
    getMenu().getSlot(4).setClickHandler((clickPlayer, clickInformation) -> {
        clickPlayer.closeInventory();
        clickPlayer.performCommand(PlotSystem.getPlugin().getConfigManager().getConfig().getString(ConfigPaths.NAVIGATOR_COMMAND));
    });
    // Set click event for plots difficulty item
    getMenu().getSlot(7).setClickHandler(((clickPlayer, clickInformation) -> {
        selectedPlotDifficulty = (selectedPlotDifficulty == null ? PlotDifficulty.values()[0] : selectedPlotDifficulty.ordinal() != PlotDifficulty.values().length - 1 ? PlotDifficulty.values()[selectedPlotDifficulty.ordinal() + 1] : null);
        getMenu().getSlot(7).setItem(getSelectedDifficultyItem());
        clickPlayer.playSound(clickPlayer.getLocation(), Utils.Done, 1, 1);
        try {
            setCityProjectItems();
        } catch (SQLException ex) {
            Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
        }
    }));
    // Set click event for city project items
    for (int i = 0; i < cityProjects.size(); i++) {
        int itemSlot = i;
        getMenu().getSlot(9 + i).setClickHandler((clickPlayer, clickInformation) -> {
            if (!getMenu().getSlot(9 + itemSlot).getItem(clickPlayer).equals(MenuItems.errorItem(getMenuPlayer()))) {
                try {
                    clickPlayer.closeInventory();
                    Builder builder = new Builder(clickPlayer.getUniqueId());
                    int cityID = cityProjects.get(itemSlot).getID();
                    PlotDifficulty plotDifficultyForCity = selectedPlotDifficulty != null ? selectedPlotDifficulty : PlotManager.getPlotDifficultyForBuilder(cityID, builder).get();
                    if (PlotManager.getPlots(cityID, plotDifficultyForCity, Status.unclaimed).size() != 0) {
                        if (selectedPlotDifficulty != null && PlotSystem.getPlugin().getConfigManager().getConfig().getBoolean(ConfigPaths.ENABLE_SCORE_REQUIREMENT) && !PlotManager.hasPlotDifficultyScoreRequirement(builder, selectedPlotDifficulty)) {
                            clickPlayer.sendMessage(Utils.getErrorMessageFormat(LangUtil.get(clickPlayer, LangPaths.Message.Error.PLAYER_NEEDS_HIGHER_SCORE)));
                            clickPlayer.playSound(clickPlayer.getLocation(), Utils.ErrorSound, 1, 1);
                            return;
                        }
                        new DefaultPlotGenerator(cityID, plotDifficultyForCity, builder);
                    } else {
                        clickPlayer.sendMessage(Utils.getErrorMessageFormat(LangUtil.get(clickPlayer, LangPaths.Message.Error.NO_PLOTS_LEFT)));
                        clickPlayer.playSound(clickPlayer.getLocation(), Utils.ErrorSound, 1, 1);
                    }
                } catch (SQLException | ExecutionException | InterruptedException ex) {
                    Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
                    clickPlayer.sendMessage(Utils.getErrorMessageFormat(LangUtil.get(clickPlayer, LangPaths.Message.Error.ERROR_OCCURRED)));
                    clickPlayer.playSound(clickPlayer.getLocation(), Utils.ErrorSound, 1, 1);
                }
            } else {
                clickPlayer.playSound(clickPlayer.getLocation(), Utils.ErrorSound, 1, 1);
            }
        });
    }
    // Set click event for player slot items
    Bukkit.getScheduler().runTask(PlotSystem.getPlugin(), () -> {
        for (int i = 0; i < 3; i++) {
            if (slots[i] != null) {
                int itemSlot = i;
                getMenu().getSlot(46 + i).setClickHandler((clickPlayer, clickInformation) -> {
                    clickPlayer.closeInventory();
                    try {
                        new PlotActionsMenu(clickPlayer, slots[itemSlot]);
                    } catch (SQLException ex) {
                        clickPlayer.sendMessage(Utils.getErrorMessageFormat(LangUtil.get(clickPlayer, LangPaths.Message.Error.ERROR_OCCURRED)));
                        clickPlayer.playSound(clickPlayer.getLocation(), Utils.ErrorSound, 1, 1);
                        Bukkit.getLogger().log(Level.SEVERE, "An error occurred while opening the plot actions menu!", ex);
                    }
                });
            }
        }
    });
    // Set click event for builder utilities menu item
    getMenu().getSlot(50).setClickHandler(((clickPlayer, clickInformation) -> {
        clickPlayer.closeInventory();
        new BuilderUtilitiesMenu(clickPlayer);
    }));
    // Set click event for player plots menu item
    getMenu().getSlot(51).setClickHandler(((clickPlayer, clickInformation) -> {
        clickPlayer.closeInventory();
        clickPlayer.performCommand("plots " + clickPlayer.getName());
    }));
    // Set click event for player settings menu item
    getMenu().getSlot(52).setClickHandler(((clickPlayer, clickInformation) -> new SettingsMenu(clickPlayer)));
}
Also used : Player(org.bukkit.entity.Player) Slot(com.alpsbte.plotsystem.utils.enums.Slot) PlotDifficulty(com.alpsbte.plotsystem.utils.enums.PlotDifficulty) Level(java.util.logging.Level) SQLException(java.sql.SQLException) LoreBuilder(com.alpsbte.plotsystem.utils.items.builder.LoreBuilder) MenuItems(com.alpsbte.plotsystem.utils.items.MenuItems) LangUtil(com.alpsbte.plotsystem.utils.io.language.LangUtil) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) DefaultPlotGenerator(com.alpsbte.plotsystem.core.system.plot.generator.DefaultPlotGenerator) LangPaths(com.alpsbte.plotsystem.utils.io.language.LangPaths) Plot(com.alpsbte.plotsystem.core.system.plot.Plot) ItemStack(org.bukkit.inventory.ItemStack) PlotSystem(com.alpsbte.plotsystem.PlotSystem) ExecutionException(java.util.concurrent.ExecutionException) Builder(com.alpsbte.plotsystem.core.system.Builder) CityProject(com.alpsbte.plotsystem.core.system.CityProject) List(java.util.List) PlotManager(com.alpsbte.plotsystem.core.system.plot.PlotManager) Utils(com.alpsbte.plotsystem.utils.Utils) Mask(org.ipvp.canvas.mask.Mask) ConfigPaths(com.alpsbte.plotsystem.utils.io.config.ConfigPaths) ItemBuilder(com.alpsbte.plotsystem.utils.items.builder.ItemBuilder) Status(com.alpsbte.plotsystem.utils.enums.Status) BinaryMask(org.ipvp.canvas.mask.BinaryMask) SQLException(java.sql.SQLException) LoreBuilder(com.alpsbte.plotsystem.utils.items.builder.LoreBuilder) Builder(com.alpsbte.plotsystem.core.system.Builder) ItemBuilder(com.alpsbte.plotsystem.utils.items.builder.ItemBuilder) PlotDifficulty(com.alpsbte.plotsystem.utils.enums.PlotDifficulty) ExecutionException(java.util.concurrent.ExecutionException) DefaultPlotGenerator(com.alpsbte.plotsystem.core.system.plot.generator.DefaultPlotGenerator)

Aggregations

Builder (com.alpsbte.plotsystem.core.system.Builder)2 CityProject (com.alpsbte.plotsystem.core.system.CityProject)2 PlotDifficulty (com.alpsbte.plotsystem.utils.enums.PlotDifficulty)2 ItemBuilder (com.alpsbte.plotsystem.utils.items.builder.ItemBuilder)2 LoreBuilder (com.alpsbte.plotsystem.utils.items.builder.LoreBuilder)2 SQLException (java.sql.SQLException)2 ExecutionException (java.util.concurrent.ExecutionException)2 ItemStack (org.bukkit.inventory.ItemStack)2 PlotSystem (com.alpsbte.plotsystem.PlotSystem)1 Plot (com.alpsbte.plotsystem.core.system.plot.Plot)1 PlotManager (com.alpsbte.plotsystem.core.system.plot.PlotManager)1 DefaultPlotGenerator (com.alpsbte.plotsystem.core.system.plot.generator.DefaultPlotGenerator)1 Utils (com.alpsbte.plotsystem.utils.Utils)1 Slot (com.alpsbte.plotsystem.utils.enums.Slot)1 Status (com.alpsbte.plotsystem.utils.enums.Status)1 ConfigPaths (com.alpsbte.plotsystem.utils.io.config.ConfigPaths)1 LangPaths (com.alpsbte.plotsystem.utils.io.language.LangPaths)1 LangUtil (com.alpsbte.plotsystem.utils.io.language.LangUtil)1 MenuItems (com.alpsbte.plotsystem.utils.items.MenuItems)1 List (java.util.List)1