Xakep_SDK / ViewAPI

Manages scoreboards and inventory menus
Download

ViewAPI

Simple api for creating scoreboards for players.

Usage

Sidebar

Optional<SidebarManager> sidebarManagerOpt = Sponge.getServiceManager().provide(SidebarManager.class);
if (sidebarManagerOpt.isPresent()) {
    SidebarManager sidebarManager = sidebarManagerOpt.get();
    Sidebar sidebar = sidebarManager.createSidebar(player);
    sidebar.setTitle(new StaticText(Text.of("Title!")));
    sidebar.addLine(new StaticText(Text.of("Hello world!")));
    sidebar.addLine(sidebar.getEmptyText());
    sidebar.addLine(new StaticText(Text.of("Simple line!")));
    sidebar.addLine(new DynamicText(Text.of("Some"), Text.of("Dynamic"), Text.of("Text"), Text.of("Here!")));
}

public class DynamicText implements SidebarText {
    private final Text[] texts;
    private int pos;

    public DynamicText(Text... texts) {
        this.texts = texts;
        this.pos = 0;
    }

    @Override
    public Text getText() {
        return texts[pos = ((pos + 1) % texts.length)];
    }

    @Override
    public void setText(Text text) {
        throw new UnsupportedOperationException();
    }
}

Menu

Menu menu = menuManager.createMenu("test", Text.of("Test menu"), 6);
for (int i = 0; i < 54; i++) {
    final int pos = i;
    menu.setItem(new AbstractMenuItem(ItemStack.of(ItemTypes.DIAMOND, 1)) {
        @Override
        public void onClick(Player player) {
            player.sendMessage(Text.of("Clicked slot=" + pos));
        }
    }, SlotIndex.of(pos));
}
menu.syncIcons();
menu.open(player);

Category: Developer Tools

Published on Sep 21, 2017

1387 views

78 total downloads

Licensed under Xakep_SDK License v1

Pages

Members