Code Monkey home page Code Monkey logo

spigot-menu-api's Introduction

Spigot Menu API

Lightweight easy to use spigot menu api.

  • Easily create paginated menus
  • Create menus with no flicker updates
  • Never have to stare at ugly gui code again
// Main plugin class
public class MainClass extends JavaPlugin {
    
    public void onEnable() {
        MenuHandler.registerMenus(DepositCommand.class, this);
        MenuHandler.registerMenus(OnlineCommand.class, this);
    }
}


// Example command class
// Demonstrates how you can have menus linked.
public class ExampleCommand {
    @Command(names = {"example"}, playerOnly = true)
    public void exampleCommand(Player player) {
        MenuHandler.openMenu(player, "example");
    }

    @Menu(id = "example", title = "Test Menu", size = 36)
    public void exampleMenu(Player player, MenuConfig config) {
        config.button(Button.of(Item.of(Material.BAMBOO)
                .name("&f&lHELLO")
                .lore(
                        "",
                        "&chello",
                        ""
                )
        ).slot(2).action(() -> MenuHandler.openMenu(player, "example2"), ClickType.DROP, ClickType.RIGHT));
    }

    @Menu(id = "example2", title = "Test Menu", size = 36)
    public void exampleMenu2(Player player, MenuConfig config) {
        config.button(Button.of(Item.of(Material.BAMBOO)
                .name("&f&lHELLO")
                .lore(
                        "",
                        "&chello",
                        ""
                )
        ).slot(5).action(() -> MenuHandler.openMenu(player, "example"), ClickType.DROP, ClickType.RIGHT));
    }
}

// Deposit command class
// shows how you can insert 
// items into the menus
public class DepositCommand {
    @Command(names = {"deposit"}, playerOnly = true)
    public void depositCommand(Player player) {
        MenuHandler.openMenu(player, "deposit");
    }
    
    @Menu(id = "deposit", title = "Deposit", size = 9)
    public void depositMenu(Player player, MenuConfig config) {
        config.button(Button.of(Item.of(Material.BAMBOO)
                .name("&f&lInsert Your Note")
                .lore(
                        "",
                        "&ePut your note in the slot to the right.",
                        ""
                )
        ).slot(3));

        config.button(Button.of(Item.of(Material.AIR))
                .type(ButtonType.EMPTY).slot(4)
                .inserted(item -> {
                    if (item.getType() != Material.PAPER) {
                        // prevents the item from being put in the gui
                        return false;
                    }

                    if (!item.getItemMeta().getDisplayName().contains("Bank Note")) {
                        return false;
                    }

                    // item#whateverYouWant
                    return true;
                })
        );
    }
}

// Online command class
// Shows how paginated menus work
public class OnlineCommand {
    @Command(names = {"online"}, playerOnly = true)
    public void onlineCommand(Player player) {
        MenuHandler.openMenu(player, "online");
    }
    
    // Creates a menu of all the skulls 
    // of the online players and allows
    // you to teleport to whoever you want.
    
    @Menu(id = "online", title = "Online Players (%p/%mp)", size = 27)
    public void onlineMenu(Player player, MenuConfig config) {
        config.button(Button.of(Item.of(Material.ARROW)
                .name("&cPrevious Page")
                .lore(
                        "",
                        "&eGo to the previous page",
                        ""
                )
        ).slot(0).type(ButtonType.PREVIOUS_PAGINATION));

        config.button(Button.of(Item.of(Material.ARROW)
                .name("&aNext Page")
                .lore(
                        "",
                        "&eGo to the next page",
                        ""
                )
        ).slot(8).type(ButtonType.NEXT_PAGINATION));

        for (int slot = 1; slot < 8; slot++) {
            config.button(Button.of(Item.of(Material.BLACK_STAINED_GLASS_PANE).name(" ")).slot(slot));
        }

        config.paginateRange(9, 36);
        config.paginated(Bukkit.getOnlinePlayers().stream()
                .map(skull -> Button.of(Item.of(Material.PLAYER_HEAD)
                        .skull(skull)
                        .name(String.format("&a%s", skull.getName()))
                        .lore(
                                "",
                                String.format("&eClick to teleport to &a%s&e.", skull.getName()),
                                ""
                        )).action(ClickType.LEFT, () -> player.teleport(skull)))
                .collect(Collectors.toList()));
    }
}

spigot-menu-api's People

Contributors

ashtton avatar

Stargazers

SomeRandomDev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.