From 9bc3e3bf1e1f547d681ff998a19370df8ec62e7a Mon Sep 17 00:00:00 2001 From: Moderocky Date: Fri, 6 Oct 2023 10:51:19 +0100 Subject: [PATCH 1/6] Support "is connected" pattern. --- .../njol/skript/conditions/CondIsOnline.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsOnline.java b/src/main/java/ch/njol/skript/conditions/CondIsOnline.java index af63f2b4a67..334020c0738 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsOnline.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsOnline.java @@ -33,32 +33,41 @@ * @author Peter Güttinger */ @Name("Is Online") -@Description("Checks whether a player is online.") +@Description("Checks whether a player is online. The 'connected' version will return false once this player leaves the server, even if they rejoin.") @Examples({"player is online", - "player-argument is offline"}) + "player-argument is offline", + "while player is connected:", + "\twait 60 seconds", + "\tsend \"hello!\" to player" +}) @Since("1.4") public class CondIsOnline extends PropertyCondition { static { - register(CondIsOnline.class, "(online|1¦offline)", "offlineplayers"); + register(CondIsOnline.class, "(online|:offline|:connected)", "offlineplayers"); } + private boolean connected; // https://github.com/SkriptLang/Skript/issues/6100 + @SuppressWarnings({"unchecked", "null"}) @Override public boolean init(final Expression[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { - setExpr((Expression) exprs[0]); - setNegated(matchedPattern == 1 ^ parseResult.mark == 1); + this.setExpr((Expression) exprs[0]); + this.setNegated(matchedPattern == 1 ^ parseResult.hasTag("offline")); + this.connected = parseResult.hasTag("connected"); return true; } @Override public boolean check(OfflinePlayer op) { + if (connected) + return op.isConnected(); return op.isOnline(); } @Override protected String getPropertyName() { - return "online"; + return connected ? "connected" : "online"; } } From d38b7bd28fa2426cc96a188998a0d03491ba42bd Mon Sep 17 00:00:00 2001 From: Moderocky Date: Fri, 6 Oct 2023 11:34:54 +0100 Subject: [PATCH 2/6] Move example down one line in case the world ends --- src/main/java/ch/njol/skript/conditions/CondIsOnline.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsOnline.java b/src/main/java/ch/njol/skript/conditions/CondIsOnline.java index 334020c0738..9aba811182e 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsOnline.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsOnline.java @@ -29,12 +29,10 @@ import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; -/** - * @author Peter Güttinger - */ @Name("Is Online") -@Description("Checks whether a player is online. The 'connected' version will return false once this player leaves the server, even if they rejoin.") -@Examples({"player is online", +@Description("Checks whether a player is online. The 'connected' pattern will return false once this player leaves the server, even if they rejoin.") +@Examples({ + "player is online", "player-argument is offline", "while player is connected:", "\twait 60 seconds", From f9e34bd4dd6bfc7ea4e72547eccf480ebd60ab75 Mon Sep 17 00:00:00 2001 From: Moderocky Date: Fri, 6 Oct 2023 11:57:43 +0100 Subject: [PATCH 3/6] Update src/main/java/ch/njol/skript/conditions/CondIsOnline.java Co-authored-by: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com> --- src/main/java/ch/njol/skript/conditions/CondIsOnline.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsOnline.java b/src/main/java/ch/njol/skript/conditions/CondIsOnline.java index 9aba811182e..6fea3320704 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsOnline.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsOnline.java @@ -49,7 +49,7 @@ public class CondIsOnline extends PropertyCondition { @SuppressWarnings({"unchecked", "null"}) @Override - public boolean init(final Expression[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { this.setExpr((Expression) exprs[0]); this.setNegated(matchedPattern == 1 ^ parseResult.hasTag("offline")); this.connected = parseResult.hasTag("connected"); From b0f78f26dd3162fa615520332a9ffac41d81fb8a Mon Sep 17 00:00:00 2001 From: Moderocky Date: Tue, 24 Oct 2023 08:15:04 +0100 Subject: [PATCH 4/6] Update src/main/java/ch/njol/skript/conditions/CondIsOnline.java Co-authored-by: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com> --- src/main/java/ch/njol/skript/conditions/CondIsOnline.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsOnline.java b/src/main/java/ch/njol/skript/conditions/CondIsOnline.java index 6fea3320704..9571a839a5f 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsOnline.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsOnline.java @@ -35,8 +35,8 @@ "player is online", "player-argument is offline", "while player is connected:", - "\twait 60 seconds", - "\tsend \"hello!\" to player" + "\twait 60 seconds", + "\tsend \"hello!\" to player" }) @Since("1.4") public class CondIsOnline extends PropertyCondition { From 39ba199412978d720b854f0a2092069a7cbe8e0e Mon Sep 17 00:00:00 2001 From: Moderocky Date: Sat, 13 Apr 2024 19:21:34 +0100 Subject: [PATCH 5/6] Update src/main/java/ch/njol/skript/conditions/CondIsOnline.java Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com> --- src/main/java/ch/njol/skript/conditions/CondIsOnline.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsOnline.java b/src/main/java/ch/njol/skript/conditions/CondIsOnline.java index 9571a839a5f..5f0e8e5b43d 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsOnline.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsOnline.java @@ -30,7 +30,7 @@ import ch.njol.util.Kleenean; @Name("Is Online") -@Description("Checks whether a player is online. The 'connected' pattern will return false once this player leaves the server, even if they rejoin.") +@Description("Checks whether a player is online. The 'connected' pattern will return false once this player leaves the server, even if they rejoin. Be aware that using the 'connected' pattern with a variable will not have this special behavior. Use the direct event-player or other non-variable expression for best results.") @Examples({ "player is online", "player-argument is offline", From 79261193d77ec14c5fad2e235d5d214910d77c2e Mon Sep 17 00:00:00 2001 From: Moderocky Date: Sat, 13 Apr 2024 19:22:06 +0100 Subject: [PATCH 6/6] Apply suggestions from code review Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com> --- src/main/java/ch/njol/skript/conditions/CondIsOnline.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsOnline.java b/src/main/java/ch/njol/skript/conditions/CondIsOnline.java index 5f0e8e5b43d..a783a3eca64 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsOnline.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsOnline.java @@ -36,7 +36,13 @@ "player-argument is offline", "while player is connected:", "\twait 60 seconds", - "\tsend \"hello!\" to player" + "\tsend \"hello!\" to player", + "", + "# The following will act like `{_player} is online`.", + "# Using variables with `is connected` will not behave the same as with non-variables.", + "while {_player} is connected:", + "\tbroadcast \"online!\"", + "\twait 1 tick" }) @Since("1.4") public class CondIsOnline extends PropertyCondition {