Search in sources :

Example 6 with Builder

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

the class ReviewPlotMenu method setItemClickEventsAsync.

@Override
protected void setItemClickEventsAsync() {
    // Set click event for close item
    getMenu().getSlot(50).setClickHandler((clickPlayer, clickInformation) -> clickPlayer.closeInventory());
    // Set click event for plot info item
    getMenu().getSlot(4).setClickHandler((clickPlayer, clickInformation) -> {
        clickPlayer.closeInventory();
        try {
            new PlotActionsMenu(clickPlayer, plot);
        } catch (SQLException ex) {
            Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
        }
    });
    // Set click event for submit item
    getMenu().getSlot(48).setClickHandler((clickPlayer, clickInformation) -> {
        CompletableFuture.runAsync(() -> {
            try {
                StringBuilder score = new StringBuilder();
                int totalRating = 0;
                boolean isRejected = false;
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 6; j++) {
                        if (getMenu().getSlot(11 + (i * 9) + j).getItem(clickPlayer).getItemMeta().hasEnchant(Enchantment.ARROW_DAMAGE)) {
                            if (i == 3) {
                                score.append(j);
                            } else {
                                score.append(j).append(",");
                            }
                            totalRating += j;
                            if (j <= 0) {
                                isRejected = true;
                            }
                        }
                    }
                }
                if (totalRating <= 8)
                    isRejected = true;
                if (totalRating == 0 && !sentWarning) {
                    clickPlayer.sendMessage(Utils.getInfoMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Info.PLOT_WILL_GET_ABANDONED)));
                    clickPlayer.playSound(clickPlayer.getLocation(), Utils.CreatePlotSound, 1, 1);
                    sentWarning = true;
                    return;
                } else if (isRejected && !sentWarning) {
                    clickPlayer.sendMessage(Utils.getInfoMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Info.PLOT_WILL_GET_REJECTED)));
                    clickPlayer.playSound(clickPlayer.getLocation(), Utils.CreatePlotSound, 1, 1);
                    sentWarning = true;
                    return;
                } else if (totalRating == 0) {
                    plot.setStatus(Status.unfinished);
                    Bukkit.getScheduler().runTask(PlotSystem.getPlugin(), () -> clickPlayer.performCommand("plot abandon " + plot.getID()));
                    return;
                }
                if (plot.isReviewed()) {
                    plot.getReview().setRating(score.toString());
                    plot.getReview().setReviewer(clickPlayer.getUniqueId());
                } else {
                    new Review(plot.getID(), clickPlayer.getUniqueId(), score.toString());
                }
                double totalRatingWithMultiplier = totalRating * PlotManager.getMultiplierByDifficulty(plot.getDifficulty());
                totalRating = (int) Math.floor(totalRatingWithMultiplier);
                plot.setTotalScore(totalRating);
                String reviewerConfirmationMessage;
                clickPlayer.closeInventory();
                if (!isRejected) {
                    clickPlayer.sendMessage(Utils.getInfoMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Info.SAVING_PLOT)));
                    try {
                        if (!PlotManager.savePlotAsSchematic(plot)) {
                            clickPlayer.sendMessage(Utils.getErrorMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Error.ERROR_OCCURRED)));
                            Bukkit.getLogger().log(Level.WARNING, "Could not save finished plot schematic (ID: " + plot.getID() + ")!");
                            return;
                        }
                    } catch (IOException | SQLException | WorldEditException ex) {
                        Bukkit.getLogger().log(Level.WARNING, "Could not save finished plot schematic (ID: " + plot.getID() + ")!", ex);
                    }
                    plot.setStatus(Status.completed);
                    plot.getReview().setFeedbackSent(false);
                    plot.getReview().setFeedback("No Feedback");
                    plot.getPlotOwner().addCompletedBuild(1);
                    // Remove Plot from Owner
                    plot.getPlotOwner().removePlot(plot.getSlot());
                    if (plot.getPlotMembers().isEmpty()) {
                        // Plot was made alone
                        reviewerConfirmationMessage = Utils.getInfoMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Info.PLOT_MARKED_REVIEWED, Integer.toString(plot.getID()), plot.getPlotOwner().getName()));
                        // Builder gets 100% of score
                        plot.getPlotOwner().addScore(totalRating);
                    } else {
                        // Plot was made in a group
                        StringBuilder sb = new StringBuilder();
                        for (int i = 0; i < plot.getPlotMembers().size(); i++) {
                            sb.append(i == plot.getPlotMembers().size() - 1 ? plot.getPlotMembers().get(i).getName() : plot.getPlotMembers().get(i).getName() + ", ");
                        }
                        reviewerConfirmationMessage = Utils.getInfoMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Info.PLOT_MARKED_REVIEWED, Integer.toString(plot.getID()), sb.toString()));
                        // Score gets split between all participants
                        plot.getPlotOwner().addScore(plot.getSharedScore());
                        for (Builder builder : plot.getPlotMembers()) {
                            // Score gets split between all participants
                            builder.addScore(plot.getSharedScore());
                            builder.addCompletedBuild(1);
                            // Remove Slot from Member
                            builder.removePlot(builder.getSlot(plot));
                        }
                    }
                } else {
                    if (plot.getPlotMembers().size() != 0) {
                        // Plot was made alone
                        reviewerConfirmationMessage = Utils.getInfoMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Info.PLOT_REJECTED, Integer.toString(plot.getID()), plot.getPlotOwner().getName()));
                    } else {
                        // Plot was made in a group
                        StringBuilder sb = new StringBuilder();
                        for (int i = 0; i < plot.getPlotMembers().size(); i++) {
                            sb.append(i == plot.getPlotMembers().size() - 1 ? plot.getPlotMembers().get(i).getName() : plot.getPlotMembers().get(i).getName() + ", ");
                        }
                        reviewerConfirmationMessage = Utils.getInfoMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Info.PLOT_REJECTED, Integer.toString(plot.getID()), sb.toString()));
                    }
                    PlotHandler.undoSubmit(plot);
                }
                boolean finalIsRejected = isRejected;
                Bukkit.getScheduler().runTask(PlotSystem.getPlugin(), () -> {
                    for (Player player : plot.getWorld().getBukkitWorld().getPlayers()) {
                        player.teleport(Utils.getSpawnLocation());
                    }
                    // Delete plot world after reviewing
                    if (!finalIsRejected)
                        plot.getWorld().deleteWorld();
                    clickPlayer.sendMessage(reviewerConfirmationMessage);
                    clickPlayer.playSound(clickPlayer.getLocation(), Utils.FinishPlotSound, 1f, 1f);
                });
                for (Builder member : plot.getPlotMembers()) {
                    if (member.isOnline()) {
                        PlotHandler.sendFeedbackMessage(Collections.singletonList(plot), member.getPlayer());
                    }
                }
                if (plot.getPlotOwner().isOnline()) {
                    PlotHandler.sendFeedbackMessage(Collections.singletonList(plot), plot.getPlotOwner().getPlayer());
                    plot.getReview().setFeedbackSent(true);
                }
            } catch (SQLException ex) {
                Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
            }
        });
    });
    // Set click event for point selection items
    for (int i = 0; i < 54; i++) {
        int slot = i;
        int column = (slot % 9) + 1;
        int row = (slot - (slot % 9)) / 9 + 1;
        ItemMeta meta = getMenu().getSlot(slot).getItem(getMenuPlayer()).getItemMeta();
        if (column > 2 && column < 9 && row > 1 && row < 6) {
            // Go through the whole points row
            getMenu().getSlot(i).setClickHandler((clickPlayer, clickInformation) -> {
                for (int j = 0; j < 6; j++) {
                    if (getMenu().getSlot(slot - (column - 1) + j + 2).getItem(clickPlayer).getItemMeta().hasEnchant(Enchantment.ARROW_DAMAGE)) {
                        ItemStack itemPrevious = getMenu().getSlot(slot - (column - 1) + j + 2).getItem(clickPlayer);
                        ItemMeta metaPrevious = itemPrevious.getItemMeta();
                        metaPrevious.removeEnchant(Enchantment.ARROW_DAMAGE);
                        itemPrevious.setItemMeta(metaPrevious);
                        getMenu().getSlot(slot - (column - 1) + j + 2).setItem(itemPrevious);
                    }
                }
                meta.addEnchant(Enchantment.ARROW_DAMAGE, 1, true);
                ItemStack newItem = getMenu().getSlot(slot).getItem(clickPlayer);
                newItem.setItemMeta(meta);
                getMenu().getSlot(slot).setItem(newItem);
                sentWarning = false;
            });
        }
    }
}
Also used : Player(org.bukkit.entity.Player) 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) Review(com.alpsbte.plotsystem.core.system.Review) IOException(java.io.IOException) WorldEditException(com.sk89q.worldedit.WorldEditException) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 7 with Builder

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

the class SelectLanguageMenu method setItemClickEventsAsync.

@Override
protected void setItemClickEventsAsync() {
    // Set click event for language items
    for (int i = 0; i < LangUtil.languages.length; i++) {
        LangUtil.LanguageFile langFile = LangUtil.languages[i];
        getMenu().getSlot(i).setClickHandler((clickPlayer, clickInformation) -> {
            try {
                Builder builder = new Builder(getMenuPlayer().getUniqueId());
                builder.setLanguageTag(langFile.getTag());
                getMenuPlayer().playSound(getMenuPlayer().getLocation(), Utils.Done, 1f, 1f);
                getMenuPlayer().sendMessage(Utils.getInfoMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Info.CHANGED_LANGUAGE, langFile.getLangName())));
            } catch (SQLException ex) {
                Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
                getMenuPlayer().playSound(getMenuPlayer().getLocation(), Utils.ErrorSound, 1f, 1f);
            }
            getMenuPlayer().closeInventory();
        });
    }
    // Set click event for back item
    getMenu().getSlot(22).setClickHandler((clickPlayer, clickInformation) -> new SettingsMenu(clickPlayer));
    // Set click event for auto-detect language item
    getMenu().getSlot(25).setClickHandler((clickPlayer, clickInformation) -> {
        try {
            builder.setLanguageTag(isAutoDetectEnabled ? LangUtil.languages[0].getTag() : null);
            getMenuPlayer().playSound(getMenuPlayer().getLocation(), Utils.Done, 1f, 1f);
            reloadMenuAsync();
        } catch (SQLException ex) {
            Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
            getMenuPlayer().playSound(getMenuPlayer().getLocation(), Utils.ErrorSound, 1f, 1f);
        }
    });
}
Also used : SQLException(java.sql.SQLException) Builder(com.alpsbte.plotsystem.core.system.Builder) LoreBuilder(com.alpsbte.plotsystem.utils.items.builder.LoreBuilder) ItemBuilder(com.alpsbte.plotsystem.utils.items.builder.ItemBuilder) LangUtil(com.alpsbte.plotsystem.utils.io.language.LangUtil)

Example 8 with Builder

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

the class Plot method getPlotCreator.

@Override
public Builder getPlotCreator() throws SQLException {
    try (ResultSet rs = DatabaseConnection.createStatement("SELECT create_player 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 9 with Builder

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

the class Invitation method AcceptInvite.

public void AcceptInvite() throws SQLException {
    Builder builder = new Builder(invitee.getUniqueId());
    if (builder.getFreeSlot() != null) {
        plot.addPlotMember(new Builder(invitee.getUniqueId()));
        // Messages Receiver
        invitee.sendMessage(Utils.getInfoMessageFormat("Invitation to " + plot.getPlotOwner().getName() + "'s plot has been accepted!"));
        invitee.sendMessage(Utils.getInfoMessageFormat("Happy building! :)"));
        // Messages Sender
        plot.getPlotOwner().getPlayer().sendMessage(Utils.getInfoMessageFormat(invitee.getName() + " has accepted your Invite and has been added to your plot!"));
        plot.getPlotOwner().getPlayer().sendMessage(Utils.getInfoMessageFormat("Happy building! :)"));
        scheduler.cancelTask(taskID);
    } else {
        invitee.sendMessage(Utils.getErrorMessageFormat("All your slots are occupied! Please finish your current plots before creating a new one."));
    }
}
Also used : Builder(com.alpsbte.plotsystem.core.system.Builder) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 10 with Builder

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

the class PlotHandler method submitPlot.

public static void submitPlot(Plot plot) throws SQLException {
    plot.setStatus(Status.unreviewed);
    if (plot.getWorld().isWorldLoaded()) {
        for (Player player : plot.getWorld().getBukkitWorld().getPlayers()) {
            player.teleport(Utils.getSpawnLocation());
        }
    }
    plot.getPermissions().removeBuilderPerms(plot.getPlotOwner().getUUID()).save();
    if (plot.getPlotMembers().size() != 0) {
        for (Builder builder : plot.getPlotMembers()) {
            plot.getPermissions().removeBuilderPerms(builder.getUUID());
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Builder(com.alpsbte.plotsystem.core.system.Builder)

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