Skip to content

Commit c6d2daf

Browse files
committed
Add Portals API documentation
1 parent 967f4ac commit c6d2daf

File tree

4 files changed

+168
-3
lines changed

4 files changed

+168
-3
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
title: Events
3+
description: Custom events to hook into portal interactions.
4+
---
5+
6+
Portals provides custom events that allow developers to hook into portal interactions.
7+
8+
## Portal Entry Events
9+
10+
These events are fired when entities interact with portals.
11+
12+
### PreEntityPortalEnterEvent
13+
14+
Fired before an entity enters a portal and before any checks are performed.
15+
Checks include permission, cooldown, and entry cost.
16+
Canceling this event will prevent the entity from entering and using the portal.
17+
18+
```java
19+
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
20+
public void onPrePortalEnter(PreEntityPortalEnterEvent event) {
21+
Portal portal = event.getPortal();
22+
Entity entity = event.getEntity();
23+
24+
// Prevent certain entities from using portals
25+
if (entity.getType() == EntityType.CREEPER) {
26+
event.setCancelled(true);
27+
}
28+
}
29+
```
30+
31+
### EntityPortalEnterEvent
32+
33+
Fired when an entity enters a portal and all checks have succeeded.
34+
Checks include permission, cooldown, and entry cost.
35+
Canceling this event will prevent the entity from entering and using the portal.
36+
37+
```java
38+
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
39+
public void onPortalEnter(EntityPortalEnterEvent event) {
40+
Portal portal = event.getPortal();
41+
Entity entity = event.getEntity();
42+
43+
entity.sendMessage("Entering portal: " + portal.getName());
44+
}
45+
```
46+
47+
### EntityPortalExitEvent
48+
49+
Fired when an entity exits a portal.
50+
51+
```java
52+
@EventHandler(priority = EventPriority.MONITOR)
53+
public void onPortalExit(EntityPortalExitEvent event) {
54+
Portal portal = event.getPortal();
55+
Entity entity = event.getEntity();
56+
57+
entity.sendMessage("You left the portal: " + portal.getName());
58+
}
59+
```
60+
61+
## Warmup Events
62+
63+
Warmup events are fired when portals have a warmup duration configured.
64+
These events allow you to track and modify warmup behavior.
65+
66+
### EntityPortalWarmupEvent
67+
68+
Fired when an entity enters a portal and begins the warmup period.
69+
70+
```java
71+
@EventHandler(priority = EventPriority.MONITOR)
72+
public void onWarmupStart(EntityPortalWarmupEvent event) {
73+
Portal portal = event.getPortal();
74+
Entity entity = event.getEntity();
75+
Duration warmup = event.getWarmup();
76+
77+
entity.sendMessage("Stay in the portal for " + warmup.getSeconds() + " seconds…");
78+
}
79+
```
80+
81+
### EntityPortalWarmupCancelEvent
82+
83+
Fired when a entity leaves the portal before the warmup completes, cancelling the pending action.
84+
85+
```java
86+
@EventHandler(priority = EventPriority.MONITOR)
87+
public void onWarmupCancel(EntityPortalWarmupCancelEvent event) {
88+
Portal portal = event.getPortal();
89+
Entity entity = event.getEntity();
90+
Duration remaining = event.getRemaining();
91+
92+
entity.sendMessage("You left the portal " + remaining.getSeconds() + " seconds early!");
93+
}
94+
```

content/docs/portals/api/index.mdx

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
title: API
3+
description: API documentation for the Portals plugin.
4+
---
5+
6+
import { latestVersion } from "@/lib/api"
7+
export const version = await latestVersion("portals")
8+
export const javadocs = `https://repo.thenextlvl.net/javadoc/releases/net/thenextlvl/portals/${version}`
9+
10+
Javadocs for the API can be found <a href={javadocs} target="_blank">here</a>.
11+
12+
## Getting Started
13+
14+
### PortalProvider
15+
16+
The `PortalProvider` is the main interface for interacting with portals.
17+
You can retrieve an instance using:
18+
19+
```java
20+
PortalProvider provider = PortalProvider.provider();
21+
```
22+
23+
The provider offers methods to manage portals:
24+
25+
```java
26+
// Create a new portal
27+
Portal portal = provider.createPortal("my-portal", boundingBox);
28+
29+
// Delete a portal
30+
provider.deletePortal(portal);
31+
32+
// Get a portal by name
33+
Optional<Portal> portal = provider.getPortal("my-portal");
34+
35+
// Get all portals
36+
Stream<Portal> portals = provider.getPortals();
37+
```
38+
39+
### PortalConfig
40+
41+
The `PortalConfig` provides a view of the plugin configuration.
42+
You can retrieve an instance using:
43+
44+
```java
45+
PortalConfig config = PortalConfig.config();
46+
```
47+
48+
### BoundingBox
49+
50+
A `BoundingBox` defines the physical region of a portal.
51+
You can create one using:
52+
53+
```java
54+
BoundingBox box = BoundingBox.of(world, minPosition, maxPosition);
55+
```
56+
57+
### SelectionProvider
58+
59+
The `SelectionProvider` provides selection functionality for players (e.g., WorldEdit selections).
60+
It can also be extended to provide your own custom selection provider.
61+
62+
An instance can be obtained via the Bukkit services manager if one is available:
63+
64+
```java
65+
SelectionProvider selection = Bukkit.getServicesManager().load(SelectionProvider.class);
66+
if (selection != null) {
67+
// Selection provider is available (e.g., WorldEdit is installed)
68+
Optional<BoundingBox> box = selection.getSelection(player);
69+
}
70+
```

content/docs/portals/meta.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"permissions",
2020
"configuration",
2121
"---For Developers---",
22-
"api/repository",
23-
"api/index"
22+
"repository",
23+
"api/index",
24+
"api/events"
2425
]
2526
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Add the Portals API to your project
55

66
import { Tab, Tabs } from "fumadocs-ui/components/tabs"
77
import { DynamicCodeBlock } from "fumadocs-ui/components/dynamic-codeblock"
8-
import { latestVersion } from "@/lib/api"
8+
import { latestVersion } from "@/lib/api.ts"
99
export const version = await latestVersion("portals")
1010

1111
## Add our Repository

0 commit comments

Comments
 (0)