Interface Extension


public interface Extension
A plugin's place in the dashboard: a link in the sidebar, its pages, and the actions they run.
Extension extension = Dashboard.extension(this)
    .title("Shop")
    .title("fr", "Boutique")
    .icon("pack")
    .permission("shop.dashboard");

extension.page("sales", page -> page
    .title("Sales").title("fr", "Ventes")
    .render((view, viewer) -> view.stats(stats -> stats.add("Today", shop.salesToday()))));

extension.action("restock", context -> {
    shop.restock(context.string("item", ""), (int) context.integer("amount", 1));
    return Result.ok("Restocked");
});

Pages and actions can be added at any time; the dashboards that are open learn of them at once. Every method may be called from any thread.

  • Method Summary

    Modifier and Type
    Method
    Description
    action(String id, ActionHandler handler)
    An action the pages run, from a button or a form, and the plugin's own views from their script.
    assets(String folder)
    Where the plugin's web files are in its jar, for Page.view(String) and View.frame(String): dashboard until set.
    assets(Path folder)
    Web files from a folder on disk instead of the jar, read again at each request: while working on a view, a change shows on the next reload of the page.
    An action that answers later, when its future completes: to go and work on the thread of an entity or a region, or to wait for a database.
    channel(String channel, @Nullable String permission)
    The permission needed to receive a channel's data, on top of the extension's and the shown page's.
    icon(String icon)
    The icon in the sidebar: the name of one of the dashboard's icons (overview, regions, players, console, maintenance, config, pack, plug, server, clock, globe, send, backup, heat, save, info...), or the path data of a line drawing on a 24 by 24 grid ("M4 6h16 M4 12h16"), drawn with the dashboard's stroke.
    id()
     
    A page: made at the first call, the same one after.
    page(String id, Consumer<Page> setup)
    A page, set up at once.
    permission(@Nullable String permission)
    The permission a dashboard user needs to see this extension at all.
    permissions(String... permissions)
    Other permissions the pages check with Viewer.may(String).
     
    void
    push(String channel, @Nullable Object data)
    Sends data to this extension's own views that listen on a channel (prism.on(channel, ...) in their script).
    void
    Every dashboard showing a page of this extension draws it again.
    void
    Every dashboard showing that page draws it again: after a change the page shows, from wherever the change happened.
    title(String title)
    The name in the sidebar; the plugin's name until set.
    title(String language, String title)
    The name in one of the dashboard's languages, en or fr.
    void
    Takes the extension out of the dashboard, until Dashboard.extension(Plugin) is called again.
    int
     
  • Method Details

    • plugin

      Plugin plugin()
      Returns:
      the plugin it belongs to
    • id

      String id()
      Returns:
      its name in the dashboard's addresses: the plugin's name in lower case, with only letters, digits, - and _
    • title

      Extension title(String title)
      The name in the sidebar; the plugin's name until set.
      Parameters:
      title - the name, in English or in the plugin's own language
      Returns:
      this extension
    • title

      Extension title(String language, String title)
      The name in one of the dashboard's languages, en or fr.
      Parameters:
      language - the language's code
      title - the name in that language
      Returns:
      this extension
    • icon

      Extension icon(String icon)
      The icon in the sidebar: the name of one of the dashboard's icons (overview, regions, players, console, maintenance, config, pack, plug, server, clock, globe, send, backup, heat, save, info...), or the path data of a line drawing on a 24 by 24 grid ("M4 6h16 M4 12h16"), drawn with the dashboard's stroke.
      Parameters:
      icon - an icon's name, or path data
      Returns:
      this extension
    • permission

      Extension permission(@Nullable String permission)
      The permission a dashboard user needs to see this extension at all. Without one, the extension is for those who may manage the server (prism.dashboard.manage).
      Parameters:
      permission - a permission, or null to go back to the default
      Returns:
      this extension
    • permissions

      Extension permissions(String... permissions)
      Other permissions the pages check with Viewer.may(String). A dashboard session keeps the permissions its owner had when they asked for their link, for the time they are not online; only the permissions an extension declares can be kept that way.
      Parameters:
      permissions - permissions to keep
      Returns:
      this extension
    • assets

      Extension assets(String folder)
      Where the plugin's web files are in its jar, for Page.view(String) and View.frame(String): dashboard until set.
      Parameters:
      folder - a folder of the jar
      Returns:
      this extension
    • assets

      Extension assets(Path folder)
      Web files from a folder on disk instead of the jar, read again at each request: while working on a view, a change shows on the next reload of the page.
      Parameters:
      folder - a folder on disk
      Returns:
      this extension
    • page

      Page page(String id)
      A page: made at the first call, the same one after. The first page made is the one the sidebar opens; the others follow in the order they were made.
      Parameters:
      id - the page's name in addresses: 1 to 32 lower case letters, digits, - or _
      Returns:
      the page
    • page

      Extension page(String id, Consumer<Page> setup)
      A page, set up at once.
      Parameters:
      id - the page's name in addresses
      setup - what sets it up
      Returns:
      this extension
    • action

      Action action(String id, ActionHandler handler)
      An action the pages run, from a button or a form, and the plugin's own views from their script. It runs on the global region thread unless told otherwise (Action.on(Execution)). Registering an action of the same name again replaces it.
      Parameters:
      id - the action's name: 1 to 64 lower case letters, digits, -, _ or .
      handler - what it does
      Returns:
      the action, to set it up further
    • asyncAction

      Action asyncAction(String id, AsyncActionHandler handler)
      An action that answers later, when its future completes: to go and work on the thread of an entity or a region, or to wait for a database.
      Parameters:
      id - the action's name
      handler - what it does
      Returns:
      the action, to set it up further
    • refresh

      void refresh()
      Every dashboard showing a page of this extension draws it again.
    • refresh

      void refresh(String page)
      Every dashboard showing that page draws it again: after a change the page shows, from wherever the change happened. Calls close together are drawn once.
      Parameters:
      page - the page's name
    • push

      void push(String channel, @Nullable Object data)
      Sends data to this extension's own views that listen on a channel (prism.on(channel, ...) in their script). It goes only to the dashboards showing a page of this extension that their owner may see, whose views listen on that channel, and whose owner has the channel's permission when it has one (channel(String, String)).
      Parameters:
      channel - the channel's name
      data - what to send: anything Gson writes as JSON (maps, lists, records, strings, numbers), 256 KB at most
    • channel

      Extension channel(String channel, @Nullable String permission)
      The permission needed to receive a channel's data, on top of the extension's and the shown page's.
      Parameters:
      channel - the channel's name
      permission - a permission, or null for none of its own
      Returns:
      this extension
      Since:
      1.1.0
    • viewers

      int viewers()
      Returns:
      how many dashboards show a page of this extension now
    • unregister

      void unregister()
      Takes the extension out of the dashboard, until Dashboard.extension(Plugin) is called again.