Skip to content
Open
Show file tree
Hide file tree
Changes from 9 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import ch.njol.skript.Skript;
import ch.njol.skript.doc.*;
import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.EventRestrictedSyntax;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import com.destroystokyo.paper.event.player.PlayerElytraBoostEvent;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
Expand All @@ -18,7 +20,7 @@
prevent the used firework from being consumed
""")
@Since("2.10")
public class CondElytraBoostConsume extends Condition {
public class CondElytraBoostConsume extends Condition implements EventRestrictedSyntax {

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

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

@Override
public Class<? extends Event>[] supportedEvents() {
return CollectionUtils.array(PlayerElytraBoostEvent.class);
}

@Override
public boolean check(Event event) {
if (!(event instanceof PlayerElytraBoostEvent boostEvent))
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/ch/njol/skript/conditions/CondLeashWillDrop.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ch.njol.skript.conditions;

import ch.njol.skript.lang.EventRestrictedSyntax;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.event.Event;
import org.bukkit.event.entity.EntityUnleashEvent;
import org.jetbrains.annotations.Nullable;
Expand All @@ -23,7 +25,7 @@
@Keywords("lead")
@Events("Leash / Unleash")
@Since("2.10")
public class CondLeashWillDrop extends Condition {
public class CondLeashWillDrop extends Condition implements EventRestrictedSyntax {

static {
// TODO - remove this when Spigot support is dropped
Expand All @@ -33,14 +35,15 @@ public class CondLeashWillDrop extends Condition {

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

@Override
public Class<? extends Event>[] supportedEvents() {
return CollectionUtils.array(EntityUnleashEvent.class);
}

@Override
public boolean check(Event event) {
if (!(event instanceof EntityUnleashEvent unleashEvent))
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/ch/njol/skript/conditions/CondResourcePack.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ch.njol.skript.conditions;

import ch.njol.skript.lang.EventRestrictedSyntax;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.event.Event;
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
import org.bukkit.event.player.PlayerResourcePackStatusEvent.Status;
Expand All @@ -25,7 +27,7 @@
""")
@Since("2.4")
@Events("resource pack request response")
public class CondResourcePack extends Condition {
public class CondResourcePack extends Condition implements EventRestrictedSyntax {

static {
Skript.registerCondition(CondResourcePack.class,
Expand All @@ -39,14 +41,15 @@ public class CondResourcePack extends Condition {
@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
if (!getParser().isCurrentEvent(PlayerResourcePackStatusEvent.class)) {
Skript.error("The resource pack condition can't be used outside of a resource pack response event");
return false;
}
states = (Expression<Status>) exprs[0];
setNegated(matchedPattern == 1);
return true;
}

@Override
public Class<? extends Event>[] supportedEvents() {
return CollectionUtils.array(PlayerResourcePackStatusEvent.class);
}

@Override
public boolean check(Event e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import ch.njol.skript.doc.RequiredPlugins;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.EventRestrictedSyntax;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.event.Event;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.jetbrains.annotations.Nullable;
Expand All @@ -25,7 +27,7 @@
@RequiredPlugins("Minecraft 1.16+")
@Since("2.7")
@Events("respawn")
public class CondRespawnLocation extends Condition {
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)");
Expand All @@ -35,15 +37,16 @@ public class CondRespawnLocation extends Condition {

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

@Override
public Class<? extends Event>[] supportedEvents() {
return CollectionUtils.array(PlayerRespawnEvent.class);
}

@Override
public boolean check(Event event) {
if (event instanceof PlayerRespawnEvent) {
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/ch/njol/skript/conditions/CondWillHatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.EventRestrictedSyntax;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.event.Event;
import org.bukkit.event.player.PlayerEggThrowEvent;
import org.jetbrains.annotations.Nullable;
Expand All @@ -23,7 +25,7 @@
""")
@Events("Egg Throw")
@Since("2.7")
public class CondWillHatch extends Condition {
public class CondWillHatch extends Condition implements EventRestrictedSyntax {

static {
Skript.registerCondition(CondWillHatch.class,
Expand All @@ -33,14 +35,15 @@ public class CondWillHatch extends Condition {

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

@Override
public Class<? extends Event>[] supportedEvents() {
return CollectionUtils.array(PlayerEggThrowEvent.class);
}

@Override
public boolean check(Event event) {
if (!(event instanceof PlayerEggThrowEvent))
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/ch/njol/skript/effects/EffCancelCooldown.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ch.njol.skript.effects;

import ch.njol.skript.lang.EventRestrictedSyntax;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -30,7 +32,7 @@
set the player's display name to arg-1
""")
@Since("2.2-dev34")
public class EffCancelCooldown extends Effect {
public class EffCancelCooldown extends Effect implements EventRestrictedSyntax {

static {
Skript.registerEffect(EffCancelCooldown.class,
Expand All @@ -42,14 +44,15 @@ public class EffCancelCooldown extends Effect {

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

@Override
public Class<? extends Event>[] supportedEvents() {
return CollectionUtils.array(ScriptCommandEvent.class);
}

@Override
protected void execute(Event e) {
if (!(e instanceof ScriptCommandEvent))
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/ch/njol/skript/effects/EffDropLeash.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ch.njol.skript.effects;

import ch.njol.skript.lang.EventRestrictedSyntax;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.event.Event;
import org.bukkit.event.entity.EntityUnleashEvent;
import org.jetbrains.annotations.Nullable;
Expand All @@ -23,7 +25,7 @@
@Keywords("lead")
@Events("Leash / Unleash")
@Since("2.10")
public class EffDropLeash extends Effect {
public class EffDropLeash extends Effect implements EventRestrictedSyntax {

static {
Skript.registerEffect(EffDropLeash.class,
Expand All @@ -36,14 +38,15 @@ public class EffDropLeash extends Effect {

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

@Override
public Class<? extends Event>[] supportedEvents() {
return CollectionUtils.array(EntityUnleashEvent.class);
}

@Override
protected void execute(Event event) {
if (!(event instanceof EntityUnleashEvent unleashEvent))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import ch.njol.skript.Skript;
import ch.njol.skript.doc.*;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.EventRestrictedSyntax;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import com.destroystokyo.paper.event.player.PlayerElytraBoostEvent;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
Expand All @@ -18,7 +20,7 @@
prevent the used firework from being consume
""")
@Since("2.10")
public class EffElytraBoostConsume extends Effect {
public class EffElytraBoostConsume extends Effect implements EventRestrictedSyntax {

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

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

@Override
public Class<? extends Event>[] supportedEvents() {
return CollectionUtils.array(PlayerElytraBoostEvent.class);
}

@Override
protected void execute(Event event) {
if (!(event instanceof PlayerElytraBoostEvent boostEvent))
Expand All @@ -53,5 +56,4 @@ public String toString(@Nullable Event event, boolean debug) {
return "allow the boosting firework to be consumed";
return "prevent the boosting firework from being consumed";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.Arrays;
import java.util.Iterator;

import ch.njol.skript.lang.EventRestrictedSyntax;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.server.ServerListPingEvent;
Expand All @@ -28,35 +30,33 @@
hide {vanished::*} from the server list
""")
@Since("2.3")
public class EffHidePlayerFromServerList extends Effect {
public class EffHidePlayerFromServerList extends Effect implements EventRestrictedSyntax {

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

private static final boolean PAPER_EVENT_EXISTS = Skript.classExists("com.destroystokyo.paper.event.server.PaperServerListPingEvent");

@SuppressWarnings("null")
private Expression<Player> players;

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

@Override
public Class<? extends Event>[] supportedEvents() {
return CollectionUtils.array(ServerListPingEvent.class, PaperServerListPingEvent.class);
}

@Override
@SuppressWarnings("removal")
protected void execute(Event e) {
Expand Down
Loading