API
Your plugin can open and close Reticle menus, ask which menu a player has open, listen to what players do in menus, and build menus in Java with click callbacks. Everything lives in org.mineacademy.reticle.api.
Adding Reticle to your project
Reticle is not in a public Maven repository. Install the jar you downloaded into your local repository once, with a pom of its own:
mvn install:install-file -Dfile=Reticle-0.1.0.jar -DgroupId=org.mineacademy -DartifactId=Reticle -Dversion=0.1.0 -Dpackaging=jar -DgeneratePom=trueWithout -DgeneratePom=true, Maven takes the pom packed in the jar, which lists Reticle's own build dependencies, and your build then fails to find them.
Then declare it as the sample plugin does, with the version of your jar:
<repositories>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.21.10-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mineacademy</groupId>
<artifactId>Reticle</artifactId>
<version>0.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>In plugin.yml, depend on Reticle so that it loads first:
depend: [Reticle]Opening and closing
ReticleAPI holds static methods:
| Method | What it does |
|---|---|
open(Player player, String menu) | Opens the menu for the player on his next tick, in the mode his client supports. Throws when no menu has that name |
close(Player player) | Closes his menu on his next tick, the chest version included |
isViewing(Player player) | Whether he has a menu open |
findOpenMenu(Player player) | The name of his open menu, or null |
getMenuNames() | The names of all loaded menus, from files and from code |
menu(String name) | Starts a menu in code, see Building a menu in code |
ReticleAPI.open(player, "shop");open makes the same checks as the command, so a player who is falling, sits in a vehicle or cannot open a menu for another reason gets Reticle's message and no menu. It does not check the menu's Permission, which is up to you. Both open and close hand their work to the player's own thread, so you may call them from any thread, and isViewing right after open still answers false.
Events
All three live in org.mineacademy.reticle.api.event and fire on the player's thread, in every mode.
| Event | Cancellable | Getters | Fires |
|---|---|---|---|
MenuOpenEvent | yes | getPlayer(), getMenu() | Before a menu opens by command, through the API, from the editor or by an open action in another menu. Cancel it and nothing opens |
MenuClickEvent | yes | getPlayer(), getMenu(), getElement() | When a click lands on an element, before its actions and its callback. Cancel it and none of them run |
MenuCloseEvent | no | getPlayer(), getMenu() | When the player's menu closes, for whatever reason |
An open action fires MenuOpenEvent in every mode, and going back fires no event. In the chest menu MenuCloseEvent comes only when the player leaves Reticle's chests. On an input, MenuClickEvent fires for the click that opens the dialog.
@EventHandler
public void onClick(MenuClickEvent event) {
if (event.getMenu().equals("shop") && event.getElement().equals("sword") && !event.getPlayer().hasPermission("shop.sword"))
event.setCancelled(true);
}Building a menu in code
ReticleAPI.menu(name) starts a builder. Each element type has a builder of its own, so only the keys that type allows compile. This is Reticle's sample plugin:
public final class ReticleSample extends JavaPlugin {
@Override
public void onEnable() {
ReticleAPI.menu("sample")
.size(240, 168)
.title("<b>Made in code")
.command("sample")
.button("hello", 16, 40, 208, 32, button -> button
.text("Say hello")
.icon(Material.BELL)
.onClick(click -> click.getPlayer().sendMessage("Hello from code, " + click.getPlayer().getName() + "!")))
.input("name", 16, 80, 208, 32, input -> input
.text("Your name")
.maxLength(16)
.onClick(click -> click.getPlayer().sendMessage("Nice to meet you, " + click.getInput() + ".")))
.button("close", 16, 120, 208, 32, button -> button
.text("Close")
.actions("close"))
.register(this);
}
}| Builder | Methods |
|---|---|
| The menu | size(width, height), title(text), titleScale(scale), theme(name), permission(node), command(names...), refresh(ticks), then panel, text, button, item, input and map, each with (id, x, y, width, height, setup), and finally register(plugin) |
| Every element | background(color) |
| Text, button, item, input | hover(color), actions(actions...), onClick(callback) |
| Text, button, input | text(text), textScale(scale), align(alignment), color(color) |
| Button | subtitle(text) |
| Button, item | icon(Material), iconBackground(color) |
| Input | maxLength(letters) |
| Map | shape(name), zoom(pixelsPerBlock), markers(kinds...), frame(color), compass(on), rotate(on), the last on HUDs only |
The values mean what the keys mean in menu files, and actions use the same form, such as "open: shop". An element with only an onClick callback is clickable too.
onClick receives a MenuClick:
| Getter | Holds |
|---|---|
getPlayer() | The player who clicked |
getMenu() | The menu's name |
getElement() | The element's id |
getInput() | For an input, the text the player typed; otherwise null |
The callback runs on the player's thread after the element's own actions, in every mode. For an input it runs once the player presses Done in the dialog. Reticle does not check the typed text for you, so treat getInput() like anything else a player types.
register(plugin) puts the menu through the same checks as a file and throws with the message a broken file would print, such as 'Size' in menu 'sample' must be between 32x32 and 480x270, got 500x168. It returns a ReticleMenu with getName(), open(player) and unregister(). Names take lowercase letters, digits, _ and -, at most 32 of them. Call register from onEnable, as the sample does.
A menu built in code:
- works like a file menu:
/reticle listshows it, its commands open it, andopenactions lead to it; - never shows in the editor, which also refuses to save a menu under its name;
- goes away when your plugin disables or when you call
unregister(); - takes the place of your own earlier menu of the same name when you register again, and players who have it open see the new one.
HUDs
HUDs have static methods of their own in ReticleAPI:
| Method | What it does |
|---|---|
showHud(Player player, String hud) | Shows the HUD to the player on his next tick, also one with Auto_Show: false. His permission for the HUD still applies, and a cancelled HudShowEvent keeps it hidden |
hideHud(Player player, String hud) | Hides it, and Reticle remembers that by the HUD's name across joins until it is shown again |
updateHud(Player player, String hud) | Reads the HUD's placeholders now instead of at its next Refresh, and sends only the texts that changed |
isHudShown(Player player, String hud) | Whether the HUD is among his shown HUDs. It also answers true while he gets its fallback boss bar |
getHudNames() | The names of all loaded HUDs, from files and from code |
hud(String name) | Starts a HUD in code |
Each of them throws when no HUD has that name. Like open, showHud, hideHud and updateHud hand their work to the player's own thread, so you may call them from any thread. That work runs on his next tick, so a HudShowEvent or HudHideEvent listener may call them too.
ReticleAPI.showHud(player, "quest");Two events in org.mineacademy.reticle.api.event fire on the player's thread, both with getPlayer() and getHud():
| Event | Cancellable | Fires |
|---|---|---|
HudShowEvent | yes | Before a HUD starts to show for a player: when he joins, when a command, the editor or a plugin shows it, and when he gains its permission. Cancel it and the HUD stays hidden until it is shown again |
HudHideEvent | no | When a HUD stops showing for him: a hide, /reticle hud off, a lost permission, or the HUD going away on /reticle reload |
Leaving the server fires neither event.
ReticleAPI.hud(name) builds a HUD with the HUD keys and the panel, text, item and map builders of Building a menu in code:
ReticleAPI.hud("score")
.anchor("top_right")
.offset(6, 6)
.size(90, 21)
.refresh(20)
.fallback("<gold>Score %myplugin_score%")
.text("score", 6, 6, 78, 9, text -> text
.text("Score %myplugin_score%")
.align("left"))
.register(this);| Builder | Methods |
|---|---|
| The HUD | anchor(name), offset(x, y), size(width, height), title(text), titleScale(scale), theme(name), permission(node), order(order), autoShow(show), refresh(ticks), fallback(text), then panel, text, item and map with (id, x, y, width, height, setup), and finally register(plugin) |
register(plugin) puts the HUD through the same checks as a file and throws with the message a broken file would print; onClick, hover and actions are refused, since nothing on a HUD can be clicked. It returns a ReticleHud with getName(), show(player), hide(player), update(player), isShown(player) and unregister(). A HUD built in code goes away when your plugin disables, never shows in the editor, and wins over a file of the same name in huds/, as menus do below.
Maps
Maps have these static methods in ReticleAPI:
| Method | What it does |
|---|---|
zoomMap(Player player, double pixelsPerBlock) | Sets the zoom of all his minimaps to one of the HUD steps, as /reticle map zoom does. Throws for a number that is not a step |
resetMapZoom(Player player) | Sets his minimaps back to the Zoom of each map |
setMapShape(Player player, String shape) | Makes all his minimaps square or round, as /reticle map shape does, or gives each its own Shape again with null |
setMapCorner(Player player, String corner) | Moves every HUD of his that holds a map to top_left, top_right, bottom_left or bottom_right, or back to its own Anchor with null |
setMapRotate(Player player, Boolean rotate) | Turns his minimaps with him with true, keeps north up with false, or gives each map its own Rotate again with null |
setWaypoint(Player player, String name, Location location, String color) | Sets his waypoint of that name, or moves it. color is one of the eight marker colors, or null for blue. Plugins are not held to Max_Waypoints |
removeWaypoint(Player player, String name) | Removes his waypoint of that name |
getWaypoints(Player player) | His waypoints by name. Call it on the player's own thread, it throws on any other |
addPin(String name, Location location, String color) | Adds a pin that every player sees, and returns false when a pin of that name exists. color null gives orange |
removePin(String name) | Removes the pin, and returns false when no pin has that name |
getPins() | The pins by name |
Names hold letters, digits, _ and -, at most 24 of them, and setWaypoint and addPin throw for any other name or color, as setMapShape and setMapCorner throw for an unknown shape or corner. zoomMap, resetMapZoom, setMapShape, setMapCorner, setMapRotate, setWaypoint and removeWaypoint hand their work to the player's own thread, so you may call them from any thread. Reticle remembers the zoom, shape, corner and heading in the player's data, as the commands do. The locations that getWaypoints and getPins return hold the world and the x and z of the marker, at the lowest height of that world.
A map built in code takes the same keys as in a file:
ReticleAPI.hud("radar")
.anchor("top_right")
.offset(6, 56)
.size(64, 64)
.map("map", 0, 0, 64, 64, map -> map
.shape("round")
.zoom(1)
.markers("pins", "players", "mobs")
.background("#1C1C1E")
.frame("#E5E5EA")
.compass(true)
.rotate(true))
.register(this);A click on a menu map fires MenuClickEvent with the map's element name, and cancelling it keeps the map where it was.
When a file has the same name
Your menu wins over a file of the same name, so a server owner's files can never stop your plugin from enabling. Reticle then skips menus/<name>.yml and prints one line, at startup and after every /reticle reload:
Ignoring menus/sample.yml: the plugin ReticleSample registers a menu with that name.The owner renames his file to use both menus. When your menu goes away, the file loads again.
Two plugins cannot share a name: when another plugin has registered it, register throws A menu named 'sample' is already registered by OtherPlugin.
