Skip to content

Commit 529b0a7

Browse files
committed
Revert "Replace the manual isCurrentEvent checks in favor of ERS (#8529)"
This reverts commit 06b54ed.
1 parent 28c879f commit 529b0a7

51 files changed

Lines changed: 377 additions & 414 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/ch/njol/skript/conditions/CondElytraBoostConsume.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
import ch.njol.skript.Skript;
44
import ch.njol.skript.doc.*;
55
import ch.njol.skript.lang.Condition;
6-
import ch.njol.skript.lang.EventRestrictedSyntax;
76
import ch.njol.skript.lang.Expression;
87
import ch.njol.skript.lang.SkriptParser.ParseResult;
98
import ch.njol.util.Kleenean;
10-
import ch.njol.util.coll.CollectionUtils;
119
import com.destroystokyo.paper.event.player.PlayerElytraBoostEvent;
1210
import org.bukkit.event.Event;
1311
import org.jetbrains.annotations.Nullable;
@@ -20,7 +18,7 @@
2018
prevent the used firework from being consumed
2119
""")
2220
@Since("2.10")
23-
public class CondElytraBoostConsume extends Condition implements EventRestrictedSyntax {
21+
public class CondElytraBoostConsume extends Condition {
2422

2523
static {
2624
if (Skript.classExists("com.destroystokyo.paper.event.player.PlayerElytraBoostEvent")) {
@@ -34,15 +32,14 @@ public class CondElytraBoostConsume extends Condition implements EventRestricted
3432

3533
@Override
3634
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
35+
if (!getParser().isCurrentEvent(PlayerElytraBoostEvent.class)) {
36+
Skript.error("This condition can only be used in an 'elytra boost' event.");
37+
return false;
38+
}
3739
checkConsume = matchedPattern == 0;
3840
return true;
3941
}
4042

41-
@Override
42-
public Class<? extends Event>[] supportedEvents() {
43-
return CollectionUtils.array(PlayerElytraBoostEvent.class);
44-
}
45-
4643
@Override
4744
public boolean check(Event event) {
4845
if (!(event instanceof PlayerElytraBoostEvent boostEvent))

src/main/java/ch/njol/skript/conditions/CondLeashWillDrop.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package ch.njol.skript.conditions;
22

3-
import ch.njol.skript.lang.EventRestrictedSyntax;
4-
import ch.njol.util.coll.CollectionUtils;
53
import org.bukkit.event.Event;
64
import org.bukkit.event.entity.EntityUnleashEvent;
75
import org.jetbrains.annotations.Nullable;
@@ -25,7 +23,7 @@
2523
@Keywords("lead")
2624
@Events("Leash / Unleash")
2725
@Since("2.10")
28-
public class CondLeashWillDrop extends Condition implements EventRestrictedSyntax {
26+
public class CondLeashWillDrop extends Condition {
2927

3028
static {
3129
// TODO - remove this when Spigot support is dropped
@@ -35,15 +33,14 @@ public class CondLeashWillDrop extends Condition implements EventRestrictedSynta
3533

3634
@Override
3735
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
36+
if (!getParser().isCurrentEvent(EntityUnleashEvent.class)) {
37+
Skript.error("The 'leash will drop' condition can only be used in an 'unleash' event");
38+
return false;
39+
}
3840
setNegated(parseResult.hasTag("not"));
3941
return true;
4042
}
4143

42-
@Override
43-
public Class<? extends Event>[] supportedEvents() {
44-
return CollectionUtils.array(EntityUnleashEvent.class);
45-
}
46-
4744
@Override
4845
public boolean check(Event event) {
4946
if (!(event instanceof EntityUnleashEvent unleashEvent))

src/main/java/ch/njol/skript/conditions/CondResourcePack.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package ch.njol.skript.conditions;
22

3-
import ch.njol.skript.lang.EventRestrictedSyntax;
4-
import ch.njol.util.coll.CollectionUtils;
53
import org.bukkit.event.Event;
64
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
75
import org.bukkit.event.player.PlayerResourcePackStatusEvent.Status;
@@ -27,7 +25,7 @@
2725
""")
2826
@Since("2.4")
2927
@Events("resource pack request response")
30-
public class CondResourcePack extends Condition implements EventRestrictedSyntax {
28+
public class CondResourcePack extends Condition {
3129

3230
static {
3331
Skript.registerCondition(CondResourcePack.class,
@@ -41,15 +39,14 @@ public class CondResourcePack extends Condition implements EventRestrictedSyntax
4139
@SuppressWarnings({"unchecked", "null"})
4240
@Override
4341
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
42+
if (!getParser().isCurrentEvent(PlayerResourcePackStatusEvent.class)) {
43+
Skript.error("The resource pack condition can't be used outside of a resource pack response event");
44+
return false;
45+
}
4446
states = (Expression<Status>) exprs[0];
4547
setNegated(matchedPattern == 1);
4648
return true;
4749
}
48-
49-
@Override
50-
public Class<? extends Event>[] supportedEvents() {
51-
return CollectionUtils.array(PlayerResourcePackStatusEvent.class);
52-
}
5350

5451
@Override
5552
public boolean check(Event e) {

src/main/java/ch/njol/skript/conditions/CondRespawnLocation.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
import ch.njol.skript.doc.RequiredPlugins;
99
import ch.njol.skript.doc.Since;
1010
import ch.njol.skript.lang.Condition;
11-
import ch.njol.skript.lang.EventRestrictedSyntax;
1211
import ch.njol.skript.lang.Expression;
1312
import ch.njol.skript.lang.SkriptParser.ParseResult;
1413
import ch.njol.util.Kleenean;
15-
import ch.njol.util.coll.CollectionUtils;
1614
import org.bukkit.event.Event;
1715
import org.bukkit.event.player.PlayerRespawnEvent;
1816
import org.jetbrains.annotations.Nullable;
@@ -27,7 +25,7 @@
2725
@RequiredPlugins("Minecraft 1.16+")
2826
@Since("2.7")
2927
@Events("respawn")
30-
public class CondRespawnLocation extends Condition implements EventRestrictedSyntax {
28+
public class CondRespawnLocation extends Condition {
3129

3230
static {
3331
Skript.registerCondition(CondRespawnLocation.class, "[the] respawn location (was|is)[1:(n'| no)t] [a] (:bed|respawn anchor)");
@@ -37,16 +35,15 @@ public class CondRespawnLocation extends Condition implements EventRestrictedSyn
3735

3836
@Override
3937
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
38+
if (!getParser().isCurrentEvent(PlayerRespawnEvent.class)) {
39+
Skript.error("The 'respawn location' condition may only be used in a respawn event");
40+
return false;
41+
}
4042
setNegated(parseResult.mark == 1);
4143
bedSpawn = parseResult.hasTag("bed");
4244
return true;
4345
}
4446

45-
@Override
46-
public Class<? extends Event>[] supportedEvents() {
47-
return CollectionUtils.array(PlayerRespawnEvent.class);
48-
}
49-
5047
@Override
5148
public boolean check(Event event) {
5249
if (event instanceof PlayerRespawnEvent) {

src/main/java/ch/njol/skript/conditions/CondWillHatch.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
import ch.njol.skript.doc.Name;
88
import ch.njol.skript.doc.Since;
99
import ch.njol.skript.lang.Condition;
10-
import ch.njol.skript.lang.EventRestrictedSyntax;
1110
import ch.njol.skript.lang.Expression;
1211
import ch.njol.skript.lang.SkriptParser.ParseResult;
1312
import ch.njol.util.Kleenean;
14-
import ch.njol.util.coll.CollectionUtils;
1513
import org.bukkit.event.Event;
1614
import org.bukkit.event.player.PlayerEggThrowEvent;
1715
import org.jetbrains.annotations.Nullable;
@@ -25,7 +23,7 @@
2523
""")
2624
@Events("Egg Throw")
2725
@Since("2.7")
28-
public class CondWillHatch extends Condition implements EventRestrictedSyntax {
26+
public class CondWillHatch extends Condition {
2927

3028
static {
3129
Skript.registerCondition(CondWillHatch.class,
@@ -35,15 +33,14 @@ public class CondWillHatch extends Condition implements EventRestrictedSyntax {
3533

3634
@Override
3735
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
36+
if (!getParser().isCurrentEvent(PlayerEggThrowEvent.class)) {
37+
Skript.error("You can't use the 'egg will hatch' condition outside of a Player Egg Throw event.");
38+
return false;
39+
}
3840
setNegated(!parseResult.hasTag("will"));
3941
return true;
4042
}
4143

42-
@Override
43-
public Class<? extends Event>[] supportedEvents() {
44-
return CollectionUtils.array(PlayerEggThrowEvent.class);
45-
}
46-
4744
@Override
4845
public boolean check(Event event) {
4946
if (!(event instanceof PlayerEggThrowEvent))

src/main/java/ch/njol/skript/effects/EffCancelCooldown.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package ch.njol.skript.effects;
22

3-
import ch.njol.skript.lang.EventRestrictedSyntax;
4-
import ch.njol.util.coll.CollectionUtils;
53
import org.bukkit.event.Event;
64
import org.jetbrains.annotations.Nullable;
75

@@ -32,7 +30,7 @@
3230
set the player's display name to arg-1
3331
""")
3432
@Since("2.2-dev34")
35-
public class EffCancelCooldown extends Effect implements EventRestrictedSyntax {
33+
public class EffCancelCooldown extends Effect {
3634

3735
static {
3836
Skript.registerEffect(EffCancelCooldown.class,
@@ -44,15 +42,14 @@ public class EffCancelCooldown extends Effect implements EventRestrictedSyntax {
4442

4543
@Override
4644
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
45+
if (!getParser().isCurrentEvent(ScriptCommandEvent.class)) {
46+
Skript.error("The cancel cooldown effect may only be used in a command", ErrorQuality.SEMANTIC_ERROR);
47+
return false;
48+
}
4749
cancel = matchedPattern == 0;
4850
return true;
4951
}
5052

51-
@Override
52-
public Class<? extends Event>[] supportedEvents() {
53-
return CollectionUtils.array(ScriptCommandEvent.class);
54-
}
55-
5653
@Override
5754
protected void execute(Event e) {
5855
if (!(e instanceof ScriptCommandEvent))

src/main/java/ch/njol/skript/effects/EffDropLeash.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package ch.njol.skript.effects;
22

3-
import ch.njol.skript.lang.EventRestrictedSyntax;
4-
import ch.njol.util.coll.CollectionUtils;
53
import org.bukkit.event.Event;
64
import org.bukkit.event.entity.EntityUnleashEvent;
75
import org.jetbrains.annotations.Nullable;
@@ -25,7 +23,7 @@
2523
@Keywords("lead")
2624
@Events("Leash / Unleash")
2725
@Since("2.10")
28-
public class EffDropLeash extends Effect implements EventRestrictedSyntax {
26+
public class EffDropLeash extends Effect {
2927

3028
static {
3129
Skript.registerEffect(EffDropLeash.class,
@@ -38,15 +36,14 @@ public class EffDropLeash extends Effect implements EventRestrictedSyntax {
3836

3937
@Override
4038
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
39+
if (!getParser().isCurrentEvent(EntityUnleashEvent.class)) {
40+
Skript.error("The 'drop leash' effect can only be used in an 'unleash' event");
41+
return false;
42+
}
4143
allowLeashDrop = matchedPattern == 0;
4244
return true;
4345
}
4446

45-
@Override
46-
public Class<? extends Event>[] supportedEvents() {
47-
return CollectionUtils.array(EntityUnleashEvent.class);
48-
}
49-
5047
@Override
5148
protected void execute(Event event) {
5249
if (!(event instanceof EntityUnleashEvent unleashEvent))

src/main/java/ch/njol/skript/effects/EffElytraBoostConsume.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
import ch.njol.skript.Skript;
44
import ch.njol.skript.doc.*;
55
import ch.njol.skript.lang.Effect;
6-
import ch.njol.skript.lang.EventRestrictedSyntax;
76
import ch.njol.skript.lang.Expression;
87
import ch.njol.skript.lang.SkriptParser.ParseResult;
98
import ch.njol.util.Kleenean;
10-
import ch.njol.util.coll.CollectionUtils;
119
import com.destroystokyo.paper.event.player.PlayerElytraBoostEvent;
1210
import org.bukkit.event.Event;
1311
import org.jetbrains.annotations.Nullable;
@@ -20,7 +18,7 @@
2018
prevent the used firework from being consume
2119
""")
2220
@Since("2.10")
23-
public class EffElytraBoostConsume extends Effect implements EventRestrictedSyntax {
21+
public class EffElytraBoostConsume extends Effect {
2422

2523
static {
2624
if (Skript.classExists("com.destroystokyo.paper.event.player.PlayerElytraBoostEvent")) {
@@ -34,15 +32,14 @@ public class EffElytraBoostConsume extends Effect implements EventRestrictedSynt
3432

3533
@Override
3634
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
35+
if (!getParser().isCurrentEvent(PlayerElytraBoostEvent.class)) {
36+
Skript.error("This effect can only be used in an 'elytra boost' event.");
37+
return false;
38+
}
3739
consume = matchedPattern == 1;
3840
return true;
3941
}
4042

41-
@Override
42-
public Class<? extends Event>[] supportedEvents() {
43-
return CollectionUtils.array(PlayerElytraBoostEvent.class);
44-
}
45-
4643
@Override
4744
protected void execute(Event event) {
4845
if (!(event instanceof PlayerElytraBoostEvent boostEvent))

src/main/java/ch/njol/skript/effects/EffHidePlayerFromServerList.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import java.util.Arrays;
44
import java.util.Iterator;
55

6-
import ch.njol.skript.lang.EventRestrictedSyntax;
7-
import ch.njol.util.coll.CollectionUtils;
86
import org.bukkit.entity.Player;
97
import org.bukkit.event.Event;
108
import org.bukkit.event.server.ServerListPingEvent;
@@ -30,33 +28,35 @@
3028
hide {vanished::*} from the server list
3129
""")
3230
@Since("2.3")
33-
public class EffHidePlayerFromServerList extends Effect implements EventRestrictedSyntax {
31+
public class EffHidePlayerFromServerList extends Effect {
3432

3533
static {
3634
Skript.registerEffect(EffHidePlayerFromServerList.class,
3735
"hide %players% (in|on|from) [the] server list",
3836
"hide %players%'[s] info[rmation] (in|on|from) [the] server list");
3937
}
4038

39+
private static final boolean PAPER_EVENT_EXISTS = Skript.classExists("com.destroystokyo.paper.event.server.PaperServerListPingEvent");
40+
4141
@SuppressWarnings("null")
4242
private Expression<Player> players;
4343

4444
@SuppressWarnings({"unchecked", "null"})
4545
@Override
4646
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
47-
if (isDelayed == Kleenean.TRUE) {
47+
boolean isServerPingEvent = getParser().isCurrentEvent(ServerListPingEvent.class) ||
48+
(PAPER_EVENT_EXISTS && getParser().isCurrentEvent(PaperServerListPingEvent.class));
49+
if (!isServerPingEvent) {
50+
Skript.error("The hide player from server list effect can't be used outside of a server list ping event");
51+
return false;
52+
} else if (isDelayed == Kleenean.TRUE) {
4853
Skript.error("Can't hide players from the server list anymore after the server list ping event has already passed");
4954
return false;
5055
}
5156
players = (Expression<Player>) exprs[0];
5257
return true;
5358
}
5459

55-
@Override
56-
public Class<? extends Event>[] supportedEvents() {
57-
return CollectionUtils.array(ServerListPingEvent.class, PaperServerListPingEvent.class);
58-
}
59-
6060
@Override
6161
@SuppressWarnings("removal")
6262
protected void execute(Event e) {

0 commit comments

Comments
 (0)