-
-
Notifications
You must be signed in to change notification settings - Fork 414
A Complete Portal Module #8210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NotSoDelayed
wants to merge
10
commits into
SkriptLang:dev/feature
Choose a base branch
from
NotSoDelayed:feature/portal-module
base: dev/feature
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
A Complete Portal Module #8210
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
52fa632
event portal type
NotSoDelayed ca4f6c5
Merge remote-tracking branch 'upstream/dev/feature' into feature/even…
NotSoDelayed 51a084e
end gateway support, refractor on event values, tests
NotSoDelayed a09c05c
module setup + relocate existing syntaxes
NotSoDelayed a495fd1
Portal module + optimize
NotSoDelayed 3778b04
more portal events, event values, tests
NotSoDelayed 356d872
add more skript docs
NotSoDelayed 4a830d7
more tests, cleanups
NotSoDelayed 920696a
a little more skript docs
NotSoDelayed 6520034
have junit test name matches involved junit test class
NotSoDelayed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 0 additions & 100 deletions
100
src/main/java/ch/njol/skript/expressions/ExprPortal.java
This file was deleted.
Oops, something went wrong.
76 changes: 76 additions & 0 deletions
76
src/main/java/org/skriptlang/skript/bukkit/portal/PortalModule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package org.skriptlang.skript.bukkit.portal; | ||
|
|
||
| import org.bukkit.Location; | ||
| import org.bukkit.PortalType; | ||
| import org.bukkit.block.Block; | ||
| import org.bukkit.block.BlockState; | ||
| import org.bukkit.entity.Entity; | ||
| import org.bukkit.event.entity.EntityPortalEnterEvent; | ||
| import org.bukkit.event.entity.EntityPortalExitEvent; | ||
| import org.bukkit.event.world.PortalCreateEvent; | ||
| import org.bukkit.util.Vector; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import ch.njol.skript.Skript; | ||
| import ch.njol.skript.lang.util.SimpleEvent; | ||
| import ch.njol.skript.registrations.EventConverter; | ||
| import ch.njol.skript.registrations.EventValues; | ||
| import org.skriptlang.skript.addon.AddonModule; | ||
| import org.skriptlang.skript.addon.SkriptAddon; | ||
|
|
||
| public class PortalModule implements AddonModule { | ||
|
|
||
| @Override | ||
| public void load(SkriptAddon addon) { | ||
| try { | ||
| Skript.getAddonInstance().loadClasses("org.skriptlang.skript.bukkit.portal", "elements"); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
|
|
||
| Skript.registerEvent("Portal Create", SimpleEvent.class, PortalCreateEvent.class, "portal creat(e|ion)") | ||
| .description("Called when a portal is created, either by a player or mob lighting an obsidian frame on fire, or by a nether portal creating its teleportation target in the nether/overworld.", | ||
| "In Minecraft 1.14+, you can use <a href='#ExprEntity'>the player</a> in this event.", "Please note that there may not always be a player (or other entity) in this event.") | ||
| .examples("on portal create:") | ||
| .since("1.0, 2.5.3 (event-entity support), INSERT VERSION (event-portaltype support)"); | ||
| EventValues.registerEventValue(PortalCreateEvent.class, Block[].class, event -> event.getBlocks().stream() | ||
| .map(BlockState::getBlock) | ||
| .toArray(Block[]::new)); | ||
| EventValues.registerEventValue(PortalCreateEvent.class, Entity.class, PortalCreateEvent::getEntity); | ||
| EventValues.registerEventValue(PortalCreateEvent.class, PortalType.class, event -> switch (event.getReason()) { | ||
| case END_PLATFORM -> PortalType.ENDER; | ||
| case FIRE, NETHER_PAIR -> PortalType.NETHER; | ||
| }); | ||
|
|
||
| Skript.registerEvent("Portal Enter", SimpleEvent.class, EntityPortalEnterEvent.class, "portal enter[ing]", "entering [a] portal") | ||
| .description("Called when an entity enters a nether portal or an end portal. Please note that this event will be fired many times for a nether portal.") | ||
| .examples( | ||
| "on portal enter:", | ||
| "\tbroadcast \"%event-entity% is entering a %event-portaltype% at %event-location%\"") | ||
| .since("1.0, INSERT VERSION (event values)"); | ||
| EventValues.registerEventValue(EntityPortalEnterEvent.class, Location.class, EntityPortalEnterEvent::getLocation); | ||
| EventValues.registerEventValue(EntityPortalEnterEvent.class, PortalType.class, EntityPortalEnterEvent::getPortalType); | ||
|
|
||
| Skript.registerEvent("Portal Exit", SimpleEvent.class, EntityPortalExitEvent.class, "portal exit[ing]", "exiting [a] portal") | ||
| .description("Called when an entity exits a nether portal or an end portal. Note that this event does not get called on players.") | ||
| .examples( | ||
| "on portal exit:", | ||
| "\tbroadcast \"%event-entity% is exiting a portal at %event-location%\"", | ||
| "\tadd 2 to vector y of event-vector") | ||
| .since("INSERT VERSION"); | ||
| EventValues.registerEventValue(EntityPortalExitEvent.class, Vector.class, EntityPortalExitEvent::getBefore, EventValues.TIME_PAST); | ||
| EventValues.registerEventValue(EntityPortalExitEvent.class, Vector.class, new EventConverter<>() { | ||
| @Override | ||
| public void set(EntityPortalExitEvent event, Vector vector) { | ||
| event.setAfter(vector); | ||
| } | ||
|
|
||
| @Override | ||
| public Vector convert(EntityPortalExitEvent event) { | ||
| return event.getAfter(); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| } | ||
75 changes: 75 additions & 0 deletions
75
src/main/java/org/skriptlang/skript/bukkit/portal/elements/EvtPortal.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,75 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| package org.skriptlang.skript.bukkit.portal.elements; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.destroystokyo.paper.event.entity.EntityTeleportEndGatewayEvent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.destroystokyo.paper.event.player.PlayerTeleportEndGatewayEvent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.bukkit.PortalType; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.bukkit.event.Event; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.bukkit.event.entity.EntityPortalEvent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.bukkit.event.player.PlayerPortalEvent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.jetbrains.annotations.Nullable; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ch.njol.skript.Skript; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ch.njol.skript.lang.Literal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ch.njol.skript.lang.SkriptEvent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ch.njol.skript.registrations.EventValues; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ch.njol.util.coll.CollectionUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public class EvtPortal extends SkriptEvent { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Class<? extends Event>[] events = CollectionUtils.array( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PlayerPortalEvent.class, EntityPortalEvent.class, PlayerTeleportEndGatewayEvent.class, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EntityTeleportEndGatewayEvent.class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Skript.registerEvent("Portal / End Gateway", EvtPortal.class, events, "[player] portal", "entity portal") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .description( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Called when a player or an entity uses a nether portal, end portal or end gateway. Note that events with keyword 'entity' does not apply to players.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "<a href='#EffCancelEvent'>Cancel the event</a> to prevent the entity from teleporting." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ).keywords( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "player", "entity" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ).examples( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "on portal:", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "\tbroadcast \"%player% has entered a %event-portaltype%!\"", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "on player portal:", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "\tplayer's world is world(\"wilderness\")", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "\tset world of event-location to player's world", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "\tadd 9000 to x-pos of event-location", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "on entity portal:", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "\tbroadcast \"A %type of event-entity% has entered a portal!" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ).since("1.0, 2.5.3 (entities), INSERT VERSION (location changers, end gateway)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+25
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
you should also use the """ text blocks here to clean it up. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EventValues.registerEventValue(EntityPortalEvent.class, PortalType.class, EntityPortalEvent::getPortalType); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EventValues.registerEventValue(PlayerPortalEvent.class, PortalType.class, event -> switch (event.getCause()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case END_GATEWAY -> PortalType.END_GATEWAY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case END_PORTAL -> PortalType.ENDER; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case NETHER_PORTAL -> PortalType.NETHER; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| default -> throw new UnsupportedOperationException(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EventValues.registerEventValue(EntityTeleportEndGatewayEvent.class, PortalType.class, event -> PortalType.END_GATEWAY); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EventValues.registerEventValue(PlayerTeleportEndGatewayEvent.class, PortalType.class, event -> PortalType.END_GATEWAY); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private boolean isPlayer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public boolean init(Literal<?>[] args, int matchedPattern, ParseResult parseResult) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isPlayer = matchedPattern == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public boolean check(Event event) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (isPlayer) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return event instanceof PlayerPortalEvent || event instanceof PlayerTeleportEndGatewayEvent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return event instanceof EntityPortalEvent || event instanceof EntityTeleportEndGatewayEvent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public String toString(@Nullable Event event, boolean debug) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return (isPlayer ? "player" : "entity") + " portal"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs explanation for what event-vector is