Search in sources :

Example 1 with Invitation

use of com.alpsbte.plotsystem.utils.Invitation 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)

Aggregations

Builder (com.alpsbte.plotsystem.core.system.Builder)1 Invitation (com.alpsbte.plotsystem.utils.Invitation)1 ItemBuilder (com.alpsbte.plotsystem.utils.items.builder.ItemBuilder)1 LoreBuilder (com.alpsbte.plotsystem.utils.items.builder.LoreBuilder)1 SQLException (java.sql.SQLException)1 AnvilGUI (net.wesjd.anvilgui.AnvilGUI)1 ItemStack (org.bukkit.inventory.ItemStack)1