Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/main/java/ch/njol/skript/events/SimpleEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,6 @@ public class SimpleEvents {
.examples("on quit:",
"on disconnect:")
.since("1.0 (simple disconnection)");
Skript.registerEvent("Respawn", SimpleEvent.class, PlayerRespawnEvent.class, "[player] respawn[ing]")
.description("Called when a player respawns via death or entering the end portal in the end. You should prefer this event over the <a href='#death'>death event</a> as the player is technically alive when this event is called.")
.examples("on respawn:")
.since("1.0");
Skript.registerEvent("Sneak Toggle", SimpleEvent.class, PlayerToggleSneakEvent.class, "[player] toggl(e|ing) sneak", "[player] sneak toggl(e|ing)")
.description("Called when a player starts or stops sneaking. Use <a href='#CondIsSneaking'>is sneaking</a> to get whether the player was sneaking before the event was called.")
.examples("# make players that stop sneaking jump",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import ch.njol.skript.Skript;
import ch.njol.skript.lang.util.SimpleEvent;
import io.papermc.paper.event.player.AsyncChatEvent;
import com.destroystokyo.paper.event.player.PlayerPostRespawnEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.skriptlang.skript.addon.AddonModule;
import org.skriptlang.skript.addon.HierarchicalAddonModule;
import org.skriptlang.skript.addon.SkriptAddon;
import org.skriptlang.skript.bukkit.entity.player.elements.effects.*;
import org.skriptlang.skript.bukkit.entity.player.elements.events.*;
import org.skriptlang.skript.bukkit.entity.player.elements.expressions.*;
import org.skriptlang.skript.bukkit.entity.player.elements.conditions.*;
import org.skriptlang.skript.bukkit.lang.eventvalue.EventValueRegistry;
import org.skriptlang.skript.bukkit.registration.BukkitSyntaxInfos;
import org.skriptlang.skript.registration.SyntaxRegistry;
Expand Down Expand Up @@ -37,7 +40,9 @@ protected void loadSelf(SkriptAddon addon) {
ExprPlayerListHeaderFooter::register,
ExprPlayerListName::register,
ExprPlayerListPriority::register,
ExprQuitMessage::register
ExprQuitMessage::register,
ExprRespawnLocation::register,
CondRespawnLocation::register

Copy link
Copy Markdown
Member

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)

);
if (Skript.classExists("io.papermc.paper.event.player.PlayerPickBlockEvent")) {
register(addon,
Expand Down Expand Up @@ -65,6 +70,32 @@ protected void loadSelf(SkriptAddon addon) {
.addPattern("chat")
.addEvent(AsyncChatEvent.class)
.build());

syntaxRegistry.register(BukkitSyntaxInfos.Event.KEY, BukkitSyntaxInfos.Event.builder(SimpleEvent.class, "Respawn")
.addDescription("Called when a player respawns via death or entering the end portal in the end. You should prefer this event over the <a href='#death'>death event</a> as the player is technically alive when this event is called.")
.addExample("on respawn:")
.addSince("1.0")
.addPattern("[player] respawn[ing]")
.addEvent(PlayerRespawnEvent.class)
Comment thread
MrScopes marked this conversation as resolved.
.supplier(() -> new SimpleEvent("player respawn"))
.build());

syntaxRegistry.register(BukkitSyntaxInfos.Event.KEY, BukkitSyntaxInfos.Event.builder(SimpleEvent.class, "After Respawn")
.addDescription("Called after a player respawns via death or entering the end portal in the end. You should prefer this event over the <a href='#respawn'>respawn event</a> if you need to ensure your changes to the player stick after they respawn.")
.addExample("""
after respawn:
if respawn location is a bed:
broadcast "%player% respawned at their bed at %respawn location%"
else if respawn location is a respawn anchor:
broadcast "%player% respawned at their anchor at %respawn location%"
else:
broadcast "%player% respawned at %respawn location%"
""")
.addSince("INSERT VERSION")
.addPattern("after [player] respawn[ing]")
.addEvent(PlayerPostRespawnEvent.class)
Comment thread
MrScopes marked this conversation as resolved.
.supplier(() -> new SimpleEvent("after player respawn"))
.build());
}

@Override
Expand Down
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;
Expand All @@ -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.")
Expand All @@ -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)")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.addPattern("[the] respawn location (was|is)[1:(n'| no)t] [a] (:bed|respawn anchor)")
.addPattern("[the] respawn location (was|is|1:was not|1:wasn't|1:is not|1:isn't) [a] (:bed|respawn anchor)")

I think the longer pattern is worth the much better readability.

.build());
}

private boolean bedSpawn;
Expand All @@ -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;
}

Expand Down
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;
Expand All @@ -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;

Expand All @@ -30,27 +32,31 @@
@Since("2.2-dev35")
public class ExprRespawnLocation extends SimpleExpression<Location> implements EventRestrictedSyntax {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't required

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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) {
Comment thread
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
Expand All @@ -65,23 +71,33 @@ public Class<? extends Location> getReturnType() {

@Override
public String toString(final @Nullable Event event, final boolean debug) {
Comment thread
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
Comment thread
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) {
Comment thread
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);
}
Comment thread
MrScopes marked this conversation as resolved.

}
Loading