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 TypeMethodDescriptionaction(String id, ActionHandler handler) An action the pages run, from a button or a form, and the plugin's own views from their script.Where the plugin's web files are in its jar, forPage.view(String)andView.frame(String):dashboarduntil set.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.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.The permission needed to receive a channel's data, on top of the extension's and the shown page's.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.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 withViewer.may(String).plugin()voidSends data to this extension's own views that listen on a channel (prism.on(channel, ...)in their script).voidrefresh()Every dashboard showing a page of this extension draws it again.voidEvery dashboard showing that page draws it again: after a change the page shows, from wherever the change happened.The name in the sidebar; the plugin's name until set.The name in one of the dashboard's languages,enorfr.voidTakes the extension out of the dashboard, untilDashboard.extension(Plugin)is called again.intviewers()
-
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
-
title
-
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
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
Other permissions the pages check withViewer.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
Where the plugin's web files are in its jar, forPage.view(String)andView.frame(String):dashboarduntil set.- Parameters:
folder- a folder of the jar- Returns:
- this extension
-
assets
-
page
-
page
-
action
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
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 namehandler- 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
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
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 namedata- what to send: anything Gson writes as JSON (maps, lists, records, strings, numbers), 256 KB at most
-
channel
-
viewers
int viewers()- Returns:
- how many dashboards show a page of this extension now
-
unregister
void unregister()Takes the extension out of the dashboard, untilDashboard.extension(Plugin)is called again.
-