-
-
Notifications
You must be signed in to change notification settings - Fork 454
Post Respawn Event #8770
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
base: dev/feature
Are you sure you want to change the base?
Post Respawn Event #8770
Changes from 7 commits
d9c5c84
7769165
5ac4b1a
95db3cd
9ebf637
572cdd4
c98987c
4d2a236
4459fa7
40775b7
5aa4243
c3faaf4
7d00f07
6a68bf5
9cd9a10
d8c2a78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,5 @@ | ||||||
| package ch.njol.skript.conditions; | ||||||
| package org.skriptlang.skript.bukkit.entity.player.elements.conditions; | ||||||
|
|
||||||
| import ch.njol.skript.Skript; | ||||||
| import ch.njol.skript.doc.Events; | ||||||
| import ch.njol.skript.doc.Name; | ||||||
| import ch.njol.skript.doc.Description; | ||||||
|
|
@@ -13,9 +12,11 @@ | |||||
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||||||
| import ch.njol.util.Kleenean; | ||||||
| import ch.njol.util.coll.CollectionUtils; | ||||||
| import io.papermc.paper.event.player.AbstractRespawnEvent; | ||||||
| import org.bukkit.event.Event; | ||||||
| import org.bukkit.event.player.PlayerRespawnEvent; | ||||||
| import org.jetbrains.annotations.Nullable; | ||||||
| import org.skriptlang.skript.registration.SyntaxInfo; | ||||||
| import org.skriptlang.skript.registration.SyntaxRegistry; | ||||||
|
|
||||||
| @Name("Is Bed/Anchor Spawn") | ||||||
| @Description("Checks what the respawn location of a player in the respawn event is.") | ||||||
|
|
@@ -29,8 +30,11 @@ | |||||
| @Events("respawn") | ||||||
| public class CondRespawnLocation extends Condition implements EventRestrictedSyntax { | ||||||
|
|
||||||
| static { | ||||||
| Skript.registerCondition(CondRespawnLocation.class, "[the] respawn location (was|is)[1:(n'| no)t] [a] (:bed|respawn anchor)"); | ||||||
| public static void register(SyntaxRegistry syntaxRegistry) { | ||||||
| syntaxRegistry.register(SyntaxRegistry.CONDITION, SyntaxInfo.builder(CondRespawnLocation.class) | ||||||
| .supplier(CondRespawnLocation::new) | ||||||
| .addPattern("[the] respawn location (was|is)[1:(n'| no)t] [a] (:bed|respawn anchor)") | ||||||
|
Member
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
I think the longer pattern is worth the much better readability. |
||||||
| .build()); | ||||||
| } | ||||||
|
|
||||||
| private boolean bedSpawn; | ||||||
|
|
@@ -44,15 +48,15 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye | |||||
|
|
||||||
| @Override | ||||||
| public Class<? extends Event>[] supportedEvents() { | ||||||
| return CollectionUtils.array(PlayerRespawnEvent.class); | ||||||
| return CollectionUtils.array(AbstractRespawnEvent.class); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public boolean check(Event event) { | ||||||
| if (event instanceof PlayerRespawnEvent) { | ||||||
| PlayerRespawnEvent respawnEvent = (PlayerRespawnEvent) event; | ||||||
| if (event instanceof AbstractRespawnEvent respawnEvent) { | ||||||
| return (bedSpawn ? respawnEvent.isBedSpawn() : respawnEvent.isAnchorSpawn()) != isNegated(); | ||||||
| } | ||||||
|
|
||||||
| return false; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,9 +1,11 @@ | ||||||
| package ch.njol.skript.expressions; | ||||||
| package org.skriptlang.skript.bukkit.entity.player.elements.expressions; | ||||||
|
|
||||||
| import ch.njol.skript.lang.EventRestrictedSyntax; | ||||||
| import org.bukkit.Location; | ||||||
| import org.bukkit.event.Event; | ||||||
| import org.bukkit.event.player.PlayerRespawnEvent; | ||||||
| import io.papermc.paper.event.player.AbstractRespawnEvent; | ||||||
| import com.destroystokyo.paper.event.player.PlayerPostRespawnEvent; | ||||||
| import org.jetbrains.annotations.Nullable; | ||||||
|
|
||||||
| import ch.njol.skript.Skript; | ||||||
|
|
@@ -14,10 +16,10 @@ | |||||
| import ch.njol.skript.doc.Name; | ||||||
| import ch.njol.skript.doc.Since; | ||||||
| import ch.njol.skript.lang.Expression; | ||||||
| import ch.njol.skript.lang.ExpressionType; | ||||||
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||||||
| import ch.njol.skript.lang.util.SimpleExpression; | ||||||
| import ch.njol.skript.log.ErrorQuality; | ||||||
| import org.skriptlang.skript.registration.DefaultSyntaxInfos; | ||||||
| import org.skriptlang.skript.registration.SyntaxRegistry; | ||||||
| import ch.njol.util.Kleenean; | ||||||
| import ch.njol.util.coll.CollectionUtils; | ||||||
|
|
||||||
|
|
@@ -30,27 +32,31 @@ | |||||
| @Since("2.2-dev35") | ||||||
| public class ExprRespawnLocation extends SimpleExpression<Location> implements EventRestrictedSyntax { | ||||||
|
Member
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. This should probably become a EventValueExpression and the respawn location an eventvalue. Not required for this PR but would be nice. |
||||||
|
|
||||||
| static { | ||||||
| Skript.registerExpression(ExprRespawnLocation.class, Location.class, ExpressionType.SIMPLE, "[the] respawn location"); | ||||||
| public static void register(SyntaxRegistry syntaxRegistry) { | ||||||
| syntaxRegistry.register(SyntaxRegistry.EXPRESSION, DefaultSyntaxInfos.Expression.builder(ExprRespawnLocation.class, Location.class) | ||||||
| .supplier(ExprRespawnLocation::new) | ||||||
| .addPattern("[the] respawn location") | ||||||
| .build()); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||||||
|
Contributor
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
Contributor
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. This isn't required
Contributor
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. no it isn't its just something that could be changed - hence why its a comment review not a requested changes review |
||||||
| return true; | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public Class<? extends Event>[] supportedEvents() { | ||||||
| return CollectionUtils.array(PlayerRespawnEvent.class); | ||||||
| return CollectionUtils.array(AbstractRespawnEvent.class); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| @Nullable | ||||||
| protected Location[] get(Event event) { | ||||||
|
MrScopes marked this conversation as resolved.
Outdated
|
||||||
| if (!(event instanceof PlayerRespawnEvent)) | ||||||
| if (!(event instanceof AbstractRespawnEvent respawnEvent)) { | ||||||
| return null; | ||||||
| } | ||||||
|
|
||||||
| return CollectionUtils.array(((PlayerRespawnEvent)event).getRespawnLocation()); | ||||||
| return CollectionUtils.array(respawnEvent.getRespawnLocation()); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
|
|
@@ -65,23 +71,33 @@ public Class<? extends Location> getReturnType() { | |||||
|
|
||||||
| @Override | ||||||
| public String toString(final @Nullable Event event, final boolean debug) { | ||||||
|
MrScopes marked this conversation as resolved.
Outdated
|
||||||
| return "the respawn location " + ((event != null) ? ": " + ((PlayerRespawnEvent)event).getRespawnLocation() : ""); | ||||||
| return "the respawn location " + ((event != null) ? ": " + ((AbstractRespawnEvent)event).getRespawnLocation() : ""); | ||||||
| } | ||||||
|
|
||||||
| @Nullable | ||||||
|
MrScopes marked this conversation as resolved.
Outdated
|
||||||
| @Override | ||||||
| public Class<?>[] acceptChange(Changer.ChangeMode mode) { | ||||||
| if (mode == ChangeMode.SET) | ||||||
| return CollectionUtils.array(Location.class); | ||||||
| return null; | ||||||
| public Class<?> @Nullable [] acceptChange(ChangeMode mode) { | ||||||
| if (mode != ChangeMode.SET) | ||||||
| return null; | ||||||
|
|
||||||
| if (getParser().isCurrentEvent(PlayerPostRespawnEvent.class)) { | ||||||
| Skript.error("The respawn location cannot be changed after the player has respawned."); | ||||||
| return null; | ||||||
| } | ||||||
|
|
||||||
| return CollectionUtils.array(Location.class); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public void change(Event event, @Nullable Object[] delta, Changer.ChangeMode mode) { | ||||||
|
MrScopes marked this conversation as resolved.
Outdated
|
||||||
| if (!(event instanceof PlayerRespawnEvent)) | ||||||
| if (delta == null || (!(event instanceof PlayerRespawnEvent respawnEvent))) | ||||||
| return; | ||||||
|
|
||||||
| Location respawnLocation = (Location) delta[0]; | ||||||
| if (respawnLocation == null) | ||||||
| return; | ||||||
|
|
||||||
| if (delta != null) ((PlayerRespawnEvent)event).setRespawnLocation((Location)delta[0]); | ||||||
| respawnEvent.setRespawnLocation(respawnLocation); | ||||||
| } | ||||||
|
MrScopes marked this conversation as resolved.
|
||||||
|
|
||||||
| } | ||||||
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.
Should be placed at the beginning of the list (alphabetical order)