Search in sources :

Example 11 with Builder

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

the class Plot method addPlotMember.

public void addPlotMember(Builder member) throws SQLException {
    List<Builder> members = getPlotMembers();
    if (members.size() < 3 && members.stream().noneMatch(m -> m.getUUID().equals(member.getUUID()))) {
        Slot slot = member.getFreeSlot();
        if (slot != null) {
            members.add(member);
            setPlotMembers(members);
            member.setPlot(this.ID, slot);
            getPermissions().addBuilderPerms(member.getUUID());
        }
    }
}
Also used : FTPManager(com.alpsbte.plotsystem.utils.ftp.FTPManager) java.util(java.util) URISyntaxException(java.net.URISyntaxException) CompletableFuture(java.util.concurrent.CompletableFuture) Slot(com.alpsbte.plotsystem.utils.enums.Slot) PlotDifficulty(com.alpsbte.plotsystem.utils.enums.PlotDifficulty) Level(java.util.logging.Level) BlockVector(com.sk89q.worldedit.BlockVector) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) CoordinateConversion(com.alpsbte.plotsystem.utils.conversion.CoordinateConversion) DatabaseConnection(com.alpsbte.plotsystem.core.database.DatabaseConnection) Bukkit(org.bukkit.Bukkit) PlotWorld(com.alpsbte.plotsystem.core.system.plot.world.PlotWorld) Vector(com.sk89q.worldedit.Vector) Collectors(java.util.stream.Collectors) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) CityProject(com.alpsbte.plotsystem.core.system.CityProject) BlockVector2D(com.sk89q.worldedit.BlockVector2D) Builder(com.alpsbte.plotsystem.core.system.Builder) Paths(java.nio.file.Paths) Review(com.alpsbte.plotsystem.core.system.Review) LocalDate(java.time.LocalDate) OutOfProjectionBoundsException(com.alpsbte.plotsystem.utils.conversion.projection.OutOfProjectionBoundsException) Status(com.alpsbte.plotsystem.utils.enums.Status) NotNull(org.jetbrains.annotations.NotNull) Builder(com.alpsbte.plotsystem.core.system.Builder) Slot(com.alpsbte.plotsystem.utils.enums.Slot)

Example 12 with Builder

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

the class Plot method removePlotMember.

public void removePlotMember(Builder member) throws SQLException {
    List<Builder> members = getPlotMembers();
    if (!members.isEmpty() && members.stream().anyMatch(m -> m.getUUID().equals(member.getUUID()))) {
        members.remove(members.stream().filter(m -> m.getUUID().equals(member.getUUID())).findFirst().orElse(null));
        setPlotMembers(members);
        Slot slot = member.getSlot(this);
        if (slot != null) {
            member.removePlot(slot);
        }
        if (getWorld().isWorldGenerated())
            getPermissions().removeBuilderPerms(member.getUUID());
    }
}
Also used : FTPManager(com.alpsbte.plotsystem.utils.ftp.FTPManager) java.util(java.util) URISyntaxException(java.net.URISyntaxException) CompletableFuture(java.util.concurrent.CompletableFuture) Slot(com.alpsbte.plotsystem.utils.enums.Slot) PlotDifficulty(com.alpsbte.plotsystem.utils.enums.PlotDifficulty) Level(java.util.logging.Level) BlockVector(com.sk89q.worldedit.BlockVector) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) CoordinateConversion(com.alpsbte.plotsystem.utils.conversion.CoordinateConversion) DatabaseConnection(com.alpsbte.plotsystem.core.database.DatabaseConnection) Bukkit(org.bukkit.Bukkit) PlotWorld(com.alpsbte.plotsystem.core.system.plot.world.PlotWorld) Vector(com.sk89q.worldedit.Vector) Collectors(java.util.stream.Collectors) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) CityProject(com.alpsbte.plotsystem.core.system.CityProject) BlockVector2D(com.sk89q.worldedit.BlockVector2D) Builder(com.alpsbte.plotsystem.core.system.Builder) Paths(java.nio.file.Paths) Review(com.alpsbte.plotsystem.core.system.Review) LocalDate(java.time.LocalDate) OutOfProjectionBoundsException(com.alpsbte.plotsystem.utils.conversion.projection.OutOfProjectionBoundsException) Status(com.alpsbte.plotsystem.utils.enums.Status) NotNull(org.jetbrains.annotations.NotNull) Builder(com.alpsbte.plotsystem.core.system.Builder) Slot(com.alpsbte.plotsystem.utils.enums.Slot)

Example 13 with Builder

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

the class Plot method getPlotOwner.

@Override
public Builder getPlotOwner() throws SQLException {
    if (getStatus() != Status.unclaimed) {
        try (ResultSet rs = DatabaseConnection.createStatement("SELECT owner_uuid FROM plotsystem_plots WHERE id = ?").setValue(this.ID).executeQuery()) {
            if (rs.next()) {
                String s = rs.getString(1);
                DatabaseConnection.closeResultSet(rs);
                return new Builder(UUID.fromString(s));
            }
            DatabaseConnection.closeResultSet(rs);
        }
    }
    return null;
}
Also used : Builder(com.alpsbte.plotsystem.core.system.Builder) ResultSet(java.sql.ResultSet)

Example 14 with Builder

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

the class CompanionMenu method setPreviewItems.

@Override
protected void setPreviewItems() {
    // Set navigator item
    getMenu().getSlot(4).setItem(new ItemBuilder(Material.valueOf(PlotSystem.getPlugin().getConfigManager().getConfig().getString(ConfigPaths.NAVIGATOR_ITEM)), 1).setName("§6§l" + LangUtil.get(getMenuPlayer(), LangPaths.MenuTitle.NAVIGATOR)).setLore(new LoreBuilder().addLine(LangUtil.get(getMenuPlayer(), LangPaths.MenuDescription.NAVIGATOR)).build()).build());
    // Set loading item for plots difficulty item
    getMenu().getSlot(7).setItem(MenuItems.loadingItem(Material.SKULL_ITEM, (byte) 3, getMenuPlayer()));
    // Set builder utilities menu item
    getMenu().getSlot(50).setItem(BuilderUtilitiesMenu.getMenuItem(getMenuPlayer()));
    // Set player plots menu item
    getMenu().getSlot(51).setItem(PlayerPlotsMenu.getMenuItem(getMenuPlayer()));
    // Set player settings menu item
    getMenu().getSlot(52).setItem(new ItemBuilder(Material.REDSTONE_COMPARATOR).setName("§b§l" + LangUtil.get(getMenuPlayer(), LangPaths.MenuTitle.SETTINGS)).setLore(new LoreBuilder().addLine(LangUtil.get(getMenuPlayer(), LangPaths.MenuDescription.SETTINGS)).build()).build());
    // Set players slot items
    slots = new Plot[3];
    for (int i = 0; i < 3; i++) {
        try {
            Builder builder = new Builder(getMenuPlayer().getUniqueId());
            slots[i] = builder.getPlot(Slot.values()[i]);
            if (slots[i] != null) {
                getMenu().getSlot(46 + i).setItem(new ItemBuilder(Material.MAP, 1 + i).setName("§b§l" + LangUtil.get(getMenuPlayer(), LangPaths.MenuTitle.SLOT).toUpperCase() + " " + (i + 1)).setLore(new LoreBuilder().addLines("§7" + LangUtil.get(getMenuPlayer(), LangPaths.Plot.ID) + ": §f" + slots[i].getID(), "§7" + LangUtil.get(getMenuPlayer(), LangPaths.Plot.CITY) + ": §f" + slots[i].getCity().getName(), "§7" + LangUtil.get(getMenuPlayer(), LangPaths.Plot.DIFFICULTY) + ": §f" + slots[i].getDifficulty().name().charAt(0) + slots[i].getDifficulty().name().substring(1).toLowerCase(), "", "§6§l" + LangUtil.get(getMenuPlayer(), LangPaths.Plot.STATUS) + ": §7§l" + slots[i].getStatus().name().substring(0, 1).toUpperCase() + slots[i].getStatus().name().substring(1)).build()).build());
            } else {
                getMenu().getSlot(46 + i).setItem(new ItemBuilder(Material.EMPTY_MAP, 1 + i).setName("§b§l" + LangUtil.get(getMenuPlayer(), LangPaths.MenuTitle.SLOT).toUpperCase() + " " + (i + 1)).setLore(new LoreBuilder().addLines("§7" + LangUtil.get(getMenuPlayer(), LangPaths.MenuDescription.SLOT), "", // Cant translate because name is stored in the database
                "§6§l" + LangUtil.get(getMenuPlayer(), LangPaths.Plot.STATUS) + ": §7§lUnassigned").build()).build());
            }
        } catch (NullPointerException | SQLException ex) {
            Bukkit.getLogger().log(Level.SEVERE, "An error occurred while placing player slot items!", ex);
            getMenu().getSlot(46 + i).setItem(MenuItems.errorItem(getMenuPlayer()));
        }
    }
    super.setPreviewItems();
}
Also used : ItemBuilder(com.alpsbte.plotsystem.utils.items.builder.ItemBuilder) 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) LoreBuilder(com.alpsbte.plotsystem.utils.items.builder.LoreBuilder)

Example 15 with Builder

use of com.alpsbte.plotsystem.core.system.Builder 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)17 SQLException (java.sql.SQLException)12 ItemBuilder (com.alpsbte.plotsystem.utils.items.builder.ItemBuilder)9 LoreBuilder (com.alpsbte.plotsystem.utils.items.builder.LoreBuilder)9 ResultSet (java.sql.ResultSet)5 CityProject (com.alpsbte.plotsystem.core.system.CityProject)4 Plot (com.alpsbte.plotsystem.core.system.plot.Plot)4 PlotDifficulty (com.alpsbte.plotsystem.utils.enums.PlotDifficulty)4 Status (com.alpsbte.plotsystem.utils.enums.Status)4 ExecutionException (java.util.concurrent.ExecutionException)4 Level (java.util.logging.Level)4 Bukkit (org.bukkit.Bukkit)4 Player (org.bukkit.entity.Player)4 ItemStack (org.bukkit.inventory.ItemStack)4 Review (com.alpsbte.plotsystem.core.system.Review)3 Slot (com.alpsbte.plotsystem.utils.enums.Slot)3 LangUtil (com.alpsbte.plotsystem.utils.io.language.LangUtil)3 PlotSystem (com.alpsbte.plotsystem.PlotSystem)2 DatabaseConnection (com.alpsbte.plotsystem.core.database.DatabaseConnection)2 DefaultPlotGenerator (com.alpsbte.plotsystem.core.system.plot.generator.DefaultPlotGenerator)2