Search in sources :

Example 1 with CityProject

use of com.alpsbte.plotsystem.core.system.CityProject 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 CityProject

use of com.alpsbte.plotsystem.core.system.CityProject in project Plot-System by AlpsBTE.

the class Plot method getCity.

@Override
public CityProject getCity() throws SQLException {
    try (ResultSet rs = DatabaseConnection.createStatement("SELECT city_project_id FROM plotsystem_plots WHERE id = ?").setValue(this.ID).executeQuery()) {
        if (rs.next()) {
            int i = rs.getInt(1);
            DatabaseConnection.closeResultSet(rs);
            return new CityProject(i);
        }
        DatabaseConnection.closeResultSet(rs);
        return null;
    }
}
Also used : ResultSet(java.sql.ResultSet) CityProject(com.alpsbte.plotsystem.core.system.CityProject)

Aggregations

CityProject (com.alpsbte.plotsystem.core.system.CityProject)2 Builder (com.alpsbte.plotsystem.core.system.Builder)1 PlotDifficulty (com.alpsbte.plotsystem.utils.enums.PlotDifficulty)1 ItemBuilder (com.alpsbte.plotsystem.utils.items.builder.ItemBuilder)1 LoreBuilder (com.alpsbte.plotsystem.utils.items.builder.LoreBuilder)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ItemStack (org.bukkit.inventory.ItemStack)1