Search in sources :

Example 1 with Builder

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

the class EventListener method onPlayerJoinEvent.

@EventHandler
public void onPlayerJoinEvent(PlayerJoinEvent event) {
    // Teleport Player to the spawn
    event.getPlayer().teleport(Utils.getSpawnLocation());
    // User has joined for the first time
    // Adding user to the database
    Bukkit.getScheduler().runTaskAsynchronously(PlotSystem.getPlugin(), () -> {
        // Add Items
        if (!event.getPlayer().getInventory().contains(CompanionMenu.getMenuItem(event.getPlayer()))) {
            event.getPlayer().getInventory().setItem(8, CompanionMenu.getMenuItem(event.getPlayer()));
        }
        if (event.getPlayer().hasPermission("plotsystem.review") && !event.getPlayer().getInventory().contains(ReviewMenu.getMenuItem(event.getPlayer()))) {
            event.getPlayer().getInventory().setItem(7, ReviewMenu.getMenuItem(event.getPlayer()));
        }
        // Check if player even exists in database.
        try (ResultSet rs = DatabaseConnection.createStatement("SELECT * FROM plotsystem_builders WHERE uuid = ?").setValue(event.getPlayer().getUniqueId().toString()).executeQuery()) {
            if (!rs.first()) {
                DatabaseConnection.createStatement("INSERT INTO plotsystem_builders (uuid, name) VALUES (?, ?)").setValue(event.getPlayer().getUniqueId().toString()).setValue(event.getPlayer().getName()).executeUpdate();
            }
            DatabaseConnection.closeResultSet(rs);
        } catch (SQLException ex) {
            Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
        }
        // Inform player about update
        if (event.getPlayer().hasPermission("plotsystem.admin") && PlotSystem.UpdateChecker.updateAvailable() && PlotSystem.getPlugin().getConfigManager().getConfig().getBoolean(ConfigPaths.CHECK_FOR_UPDATES)) {
            event.getPlayer().sendMessage(Utils.getInfoMessageFormat("There is a new update for the Plot-System available. Check your console for more information!"));
            event.getPlayer().playSound(event.getPlayer().getLocation(), Utils.CreatePlotSound, 1f, 1f);
        }
        // Check if player has changed his name
        try {
            Builder builder = new Builder(event.getPlayer().getUniqueId());
            if (!builder.getName().equals(event.getPlayer().getName())) {
                DatabaseConnection.createStatement("UPDATE plotsystem_builders SET name = ? WHERE uuid = ?").setValue(event.getPlayer().getName()).setValue(event.getPlayer().getUniqueId().toString()).executeUpdate();
            }
        } catch (SQLException ex) {
            Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
        }
        // Informing player about new feedback
        try {
            List<Plot> plots = PlotManager.getPlots(new Builder(event.getPlayer().getUniqueId()), Status.completed, Status.unfinished);
            List<Plot> reviewedPlots = new ArrayList<>();
            for (Plot plot : plots) {
                if (plot.isReviewed() && !plot.getReview().isFeedbackSent() && plot.getPlotOwner().getPlayer().equals(event.getPlayer())) {
                    reviewedPlots.add(plot);
                    plot.getReview().setFeedbackSent(true);
                }
            }
            if (reviewedPlots.size() >= 1) {
                PlotHandler.sendFeedbackMessage(reviewedPlots, event.getPlayer());
                event.getPlayer().sendTitle("", "§6§l" + reviewedPlots.size() + " §a§lPlot" + (reviewedPlots.size() == 1 ? " " : "s ") + (reviewedPlots.size() == 1 ? "has" : "have") + " been reviewed!", 20, 150, 20);
            }
        } catch (Exception ex) {
            Bukkit.getLogger().log(Level.SEVERE, "An error occurred while trying to inform the player about his plot feedback!", ex);
        }
        // Informing player about unfinished plots
        try {
            List<Plot> plots = PlotManager.getPlots(new Builder(event.getPlayer().getUniqueId()), Status.unfinished);
            if (plots.size() >= 1) {
                PlotHandler.sendUnfinishedPlotReminderMessage(plots, event.getPlayer());
                event.getPlayer().sendMessage("");
            }
        } catch (Exception ex) {
            Bukkit.getLogger().log(Level.SEVERE, "An error occurred while trying to inform the player about his unfinished plots!", ex);
        }
        // Informing reviewer about new reviews
        if (event.getPlayer().hasPermission("plotsystem.review")) {
            try {
                List<Plot> unreviewedPlots = PlotManager.getPlots(Status.unreviewed);
                if (unreviewedPlots.size() != 0) {
                    PlotHandler.sendUnreviewedPlotsReminderMessage(unreviewedPlots, event.getPlayer());
                }
            } catch (Exception ex) {
                Bukkit.getLogger().log(Level.SEVERE, "An error occurred while trying to inform the player about unreviewed plots!", ex);
            }
        }
    });
}
Also used : SQLException(java.sql.SQLException) Builder(com.alpsbte.plotsystem.core.system.Builder) Plot(com.alpsbte.plotsystem.core.system.plot.Plot) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Builder

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

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

the class PlotActionsMenu method setItemClickEventsAsync.

@Override
protected void setItemClickEventsAsync() {
    // Set click event for submit or undo submit plot item
    getMenu().getSlot(10).setClickHandler((clickPlayer, clickInformation) -> {
        clickPlayer.closeInventory();
        try {
            clickPlayer.performCommand("plot " + (plot.getStatus().equals(Status.unreviewed) ? "undosubmit " : "submit ") + plot.getID());
        } catch (SQLException ex) {
            Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
        }
    });
    // Set click event for teleport to plot item
    getMenu().getSlot(hasFeedback ? 12 : 13).setClickHandler((clickPlayer, clickInformation) -> {
        clickPlayer.closeInventory();
        plot.getWorld().teleportPlayer(clickPlayer);
    });
    // Set click event for abandon plot item
    getMenu().getSlot(hasFeedback ? 14 : 16).setClickHandler((clickPlayer, clickInformation) -> {
        clickPlayer.closeInventory();
        clickPlayer.performCommand("plot abandon " + plot.getID());
    });
    // Set click event for feedback menu button
    if (hasFeedback) {
        getMenu().getSlot(16).setClickHandler((clickPlayer, clickInformation) -> {
            clickPlayer.closeInventory();
            clickPlayer.performCommand("plot feedback " + plot.getID());
        });
    }
    // Set click event for plot members item
    getMenu().getSlot(22).setClickHandler((clickPlayer, clickInformation) -> {
        try {
            if (!plot.isReviewed()) {
                if (plot.getStatus() == Status.unfinished) {
                    FileConfiguration config = PlotSystem.getPlugin().getConfigManager().getConfig();
                    if ((getMenuPlayer() == plot.getPlotOwner().getPlayer() || getMenuPlayer().hasPermission("plotsystem.admin")) && config.getBoolean(ConfigPaths.ENABLE_GROUP_SUPPORT)) {
                        clickPlayer.closeInventory();
                        new PlotMemberMenu(plot, clickPlayer);
                    } else if (plot.getPlotMembers().stream().anyMatch(m -> m.getUUID().equals(getMenuPlayer().getUniqueId()))) {
                        // Leave Plot
                        plot.removePlotMember(new Builder(clickPlayer.getUniqueId()));
                        clickPlayer.sendMessage(Utils.getInfoMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Info.LEFT_PLOT, Integer.toString(plot.getID()))));
                        clickPlayer.closeInventory();
                    }
                } else {
                    clickPlayer.closeInventory();
                    clickPlayer.sendMessage(Utils.getErrorMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Error.CAN_ONLY_MANAGE_MEMBERS_UNFINISHED)));
                }
            }
        } catch (SQLException ex) {
            Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
        }
    });
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) LangPaths(com.alpsbte.plotsystem.utils.io.language.LangPaths) Player(org.bukkit.entity.Player) Plot(com.alpsbte.plotsystem.core.system.plot.Plot) Level(java.util.logging.Level) PlotSystem(com.alpsbte.plotsystem.PlotSystem) Builder(com.alpsbte.plotsystem.core.system.Builder) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) SQLException(java.sql.SQLException) Utils(com.alpsbte.plotsystem.utils.Utils) LoreBuilder(com.alpsbte.plotsystem.utils.items.builder.LoreBuilder) Mask(org.ipvp.canvas.mask.Mask) ConfigPaths(com.alpsbte.plotsystem.utils.io.config.ConfigPaths) MenuItems(com.alpsbte.plotsystem.utils.items.MenuItems) ItemBuilder(com.alpsbte.plotsystem.utils.items.builder.ItemBuilder) Status(com.alpsbte.plotsystem.utils.enums.Status) LangUtil(com.alpsbte.plotsystem.utils.io.language.LangUtil) BinaryMask(org.ipvp.canvas.mask.BinaryMask) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) 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)

Example 4 with Builder

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

the class PlotMemberMenu method setItemClickEventsAsync.

@Override
protected void setItemClickEventsAsync() {
    // Set click event for member slots
    for (int i = 12; i < 15; i++) {
        int itemSlot = i;
        getMenu().getSlot(i).setClickHandler((clickPlayer, clickInformation) -> {
            if (!getMenu().getSlot(itemSlot).getItem(clickPlayer).equals(emptyMemberSlotItem)) {
                Builder builder = builders.get(itemSlot - 12);
                try {
                    plot.removePlotMember(builder);
                    clickPlayer.sendMessage(Utils.getInfoMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Info.REMOVED_PLOT_MEMBER, builder.getName(), Integer.toString(plot.getID()))));
                } catch (SQLException ex) {
                    Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
                }
                reloadMenuAsync();
            }
        });
    }
    // Set click event for add plot member item
    getMenu().getSlot(16).setClickHandler((clickPlayer, clickInformation) -> {
        clickPlayer.closeInventory();
        new AnvilGUI.Builder().onComplete((player, text) -> {
            try {
                if (Builder.getBuilderByName(text) != null) {
                    Builder builder = Builder.getBuilderByName(text);
                    if (builder.isOnline()) {
                        // Check if player is owner of plot
                        if (builder.getPlayer() == plot.getPlotOwner().getPlayer()) {
                            player.sendMessage(Utils.getErrorMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Error.PLAYER_IS_PLOT_OWNER)));
                            return AnvilGUI.Response.text(LangUtil.get(getMenuPlayer(), LangPaths.Note.Anvil.PLAYER_IS_OWNER));
                        }
                        // Check if player is already a member of the plot
                        for (Builder item : plot.getPlotMembers()) {
                            if (builder.getPlayer() == item.getPlayer()) {
                                player.sendMessage(Utils.getErrorMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Error.PLAYER_IS_PLOT_MEMBER)));
                                return AnvilGUI.Response.text(LangUtil.get(getMenuPlayer(), LangPaths.Note.Anvil.PLAYER_ALREADY_ADDED));
                            }
                        }
                        new Invitation(builder.getPlayer(), plot);
                        return AnvilGUI.Response.close();
                    } else {
                        // Builder isn't online, thus can't be asked if he/she wants to be added
                        player.sendMessage(Utils.getErrorMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Error.PLAYER_IS_NOT_ONLINE)));
                        return AnvilGUI.Response.text(LangUtil.get(getMenuPlayer(), LangPaths.Note.Anvil.PLAYER_NOT_ONLINE));
                    }
                }
            } catch (SQLException ex) {
                Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
            }
            // Input was invalid or Player hasn't joined the server yet
            player.sendMessage(Utils.getErrorMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Error.PLAYER_NOT_FOUND)));
            return AnvilGUI.Response.text(LangUtil.get(getMenuPlayer(), LangPaths.Note.Anvil.INVALID_INPUT));
        }).text(LangUtil.get(getMenuPlayer(), LangPaths.Note.Anvil.ENTER_PLAYER_NAME)).itemLeft(new ItemStack(Material.NAME_TAG)).itemRight(new ItemStack(Material.SKULL)).title(LangUtil.get(getMenuPlayer(), LangPaths.MenuTitle.ENTER_PLAYER_NAME)).plugin(PlotSystem.getPlugin()).open(clickPlayer);
    });
    // Set click event for back item
    getMenu().getSlot(22).setClickHandler((clickPlayer, clickInformation) -> {
        try {
            new PlotActionsMenu(clickPlayer, plot);
        } catch (SQLException ex) {
            Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
        }
    });
}
Also used : AnvilGUI(net.wesjd.anvilgui.AnvilGUI) 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) Invitation(com.alpsbte.plotsystem.utils.Invitation) ItemStack(org.bukkit.inventory.ItemStack)

Example 5 with Builder

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

the class PlotMemberMenu method setMenuItemsAsync.

@Override
protected void setMenuItemsAsync() {
    // Set plot owner item
    try {
        getMenu().getSlot(10).setItem(new ItemBuilder(Utils.getPlayerHead(plot.getPlotOwner().getUUID())).setName("§6§l" + LangUtil.get(getMenuPlayer(), LangPaths.Plot.OWNER)).setLore(new LoreBuilder().addLine(plot.getPlotOwner().getName()).build()).build());
    } catch (SQLException ex) {
        Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
    }
    // Set plot member items
    try {
        builders = plot.getPlotMembers();
        for (int i = 12; i < 15; i++) {
            if (builders.size() >= (i - 11)) {
                Builder builder = builders.get(i - 12);
                getMenu().getSlot(i).setItem(new ItemBuilder(Utils.getPlayerHead(builder.getUUID())).setName("§b§l" + LangUtil.get(getMenuPlayer(), LangPaths.Plot.MEMBER)).setLore(new LoreBuilder().addLines(builder.getName(), "", Utils.getActionFormat(LangUtil.get(getMenuPlayer(), LangPaths.Note.Action.CLICK_TO_REMOVE_PLOT_MEMBER))).build()).build());
            }
        }
    } catch (SQLException ex) {
        Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
    }
    // Set add plot member item
    ItemStack whitePlus = Utils.getItemHead(Utils.CustomHead.ADD_BUTTON);
    getMenu().getSlot(16).setItem(new ItemBuilder(whitePlus).setName("§6§l" + LangUtil.get(getMenuPlayer(), LangPaths.MenuTitle.ADD_MEMBER_TO_PLOT)).setLore(new LoreBuilder().addLines(LangUtil.get(getMenuPlayer(), LangPaths.MenuDescription.ADD_MEMBER_TO_PLOT), "", Utils.getNoteFormat(LangUtil.get(getMenuPlayer(), LangPaths.Note.PLAYER_HAS_TO_BE_ONLINE))).build()).build());
    // Set back item
    getMenu().getSlot(22).setItem(MenuItems.backMenuItem(getMenuPlayer()));
}
Also used : ItemBuilder(com.alpsbte.plotsystem.utils.items.builder.ItemBuilder) 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) LoreBuilder(com.alpsbte.plotsystem.utils.items.builder.LoreBuilder) ItemStack(org.bukkit.inventory.ItemStack)

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