|
| 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 | +``` |
0 commit comments