From 99b849c66bd493d53733714dda0ac1f8e0813147 Mon Sep 17 00:00:00 2001 From: OfficialDonut Date: Tue, 11 Sep 2018 18:31:47 -0400 Subject: [PATCH 01/12] EffDoIf --- .../java/ch/njol/skript/effects/EffDoIf.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/main/java/ch/njol/skript/effects/EffDoIf.java diff --git a/src/main/java/ch/njol/skript/effects/EffDoIf.java b/src/main/java/ch/njol/skript/effects/EffDoIf.java new file mode 100644 index 00000000000..5d2c958f3cf --- /dev/null +++ b/src/main/java/ch/njol/skript/effects/EffDoIf.java @@ -0,0 +1,49 @@ +package ch.njol.skript.effects; + +import org.bukkit.event.Event; + +import ch.njol.skript.Skript; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.Since; +import ch.njol.skript.lang.Condition; +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.util.Kleenean; + +@Name("Do If") +@Description("Execute an effect if a condition is true.") +@Examples("on join:\n\tgive diamond to player if player has permission \"rank.vip\"") +@Since("INSERT VERSION") +public class EffDoIf extends Effect { + + private Effect effect; + private Condition condition; + + static { + Skript.registerEffect(EffDoIf.class, "[(do|execute)] <.+> if <.+>"); + } + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + String eff = parseResult.regexes.get(0).group(); + String cond = parseResult.regexes.get(1).group(); + effect = Effect.parse(eff, "Can't understand this effect: " + eff); + condition = Condition.parse(cond, "Can't understand this condition: " + cond); + return effect != null && condition != null; + } + + @Override + protected void execute(Event event) { + if (condition.check(event)) + effect.run(event); + } + + @Override + public String toString(Event event, boolean debug) { + return "do " + effect.toString(event, debug) + " if " + condition.toString(event, debug); + } + +} From 3defbf7c1df26993fb16692e00cae544da288f56 Mon Sep 17 00:00:00 2001 From: Donut Date: Tue, 11 Sep 2018 18:55:26 -0400 Subject: [PATCH 02/12] Update EffDoIf.java --- .../java/ch/njol/skript/effects/EffDoIf.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/ch/njol/skript/effects/EffDoIf.java b/src/main/java/ch/njol/skript/effects/EffDoIf.java index 5d2c958f3cf..d17ead18a0c 100644 --- a/src/main/java/ch/njol/skript/effects/EffDoIf.java +++ b/src/main/java/ch/njol/skript/effects/EffDoIf.java @@ -1,3 +1,22 @@ +/** + * This file is part of Skript. + * + * Skript is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Skript is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Skript. If not, see . + * + * + * Copyright 2011-2017 Peter Güttinger and contributors + */ package ch.njol.skript.effects; import org.bukkit.event.Event; From a899a7b8ecd2d5cab0e4d97dc6f0f803fd39eed2 Mon Sep 17 00:00:00 2001 From: Donut Date: Tue, 11 Sep 2018 19:06:33 -0400 Subject: [PATCH 03/12] Update EffDoIf.java --- src/main/java/ch/njol/skript/effects/EffDoIf.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/ch/njol/skript/effects/EffDoIf.java b/src/main/java/ch/njol/skript/effects/EffDoIf.java index d17ead18a0c..30efb4a71c8 100644 --- a/src/main/java/ch/njol/skript/effects/EffDoIf.java +++ b/src/main/java/ch/njol/skript/effects/EffDoIf.java @@ -45,6 +45,7 @@ public class EffDoIf extends Effect { Skript.registerEffect(EffDoIf.class, "[(do|execute)] <.+> if <.+>"); } + @SuppressWarnings({"unchecked", "null"}) @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { String eff = parseResult.regexes.get(0).group(); From 5196cd4f5528f08ceec934a4f905422936ca0db3 Mon Sep 17 00:00:00 2001 From: Donut Date: Tue, 11 Sep 2018 19:25:12 -0400 Subject: [PATCH 04/12] Update EffDoIf.java --- .../java/ch/njol/skript/effects/EffDoIf.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffDoIf.java b/src/main/java/ch/njol/skript/effects/EffDoIf.java index 30efb4a71c8..81a075fb13a 100644 --- a/src/main/java/ch/njol/skript/effects/EffDoIf.java +++ b/src/main/java/ch/njol/skript/effects/EffDoIf.java @@ -20,6 +20,7 @@ package ch.njol.skript.effects; import org.bukkit.event.Event; +import org.eclipse.jdt.annotation.Nullable; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; @@ -34,17 +35,21 @@ @Name("Do If") @Description("Execute an effect if a condition is true.") -@Examples("on join:\n\tgive diamond to player if player has permission \"rank.vip\"") +@Examples({"on join:", + "\tgive a diamond to the player if the player has permission \"rank.vip\""}) @Since("INSERT VERSION") public class EffDoIf extends Effect { + static { + Skript.registerEffect(EffDoIf.class, "<.+> if <.+>"); + } + + @SuppressWarnings({"unchecked", "null"}) private Effect effect; + + @SuppressWarnings({"unchecked", "null"}) private Condition condition; - static { - Skript.registerEffect(EffDoIf.class, "[(do|execute)] <.+> if <.+>"); - } - @SuppressWarnings({"unchecked", "null"}) @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { @@ -52,7 +57,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye String cond = parseResult.regexes.get(1).group(); effect = Effect.parse(eff, "Can't understand this effect: " + eff); condition = Condition.parse(cond, "Can't understand this condition: " + cond); - return effect != null && condition != null; + return effect != null || condition != null; } @Override @@ -62,8 +67,8 @@ protected void execute(Event event) { } @Override - public String toString(Event event, boolean debug) { - return "do " + effect.toString(event, debug) + " if " + condition.toString(event, debug); + public String toString(@Nullable Event event, boolean debug) { + return effect.toString(event, debug) + " if " + condition.toString(event, debug); } } From c2d0d0ba510a6c0f347f0adb103e03daa9333233 Mon Sep 17 00:00:00 2001 From: Donut Date: Tue, 11 Sep 2018 19:26:59 -0400 Subject: [PATCH 05/12] Update EffDoIf.java --- src/main/java/ch/njol/skript/effects/EffDoIf.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/effects/EffDoIf.java b/src/main/java/ch/njol/skript/effects/EffDoIf.java index 81a075fb13a..26ea5b42ec9 100644 --- a/src/main/java/ch/njol/skript/effects/EffDoIf.java +++ b/src/main/java/ch/njol/skript/effects/EffDoIf.java @@ -57,7 +57,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye String cond = parseResult.regexes.get(1).group(); effect = Effect.parse(eff, "Can't understand this effect: " + eff); condition = Condition.parse(cond, "Can't understand this condition: " + cond); - return effect != null || condition != null; + return effect != null && condition != null; } @Override From bffcb93743ddf920b49fb76c2821497eeb61f758 Mon Sep 17 00:00:00 2001 From: Donut Date: Tue, 11 Sep 2018 20:28:43 -0400 Subject: [PATCH 06/12] Guarantee no nesting --- src/main/java/ch/njol/skript/effects/EffDoIf.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/ch/njol/skript/effects/EffDoIf.java b/src/main/java/ch/njol/skript/effects/EffDoIf.java index 26ea5b42ec9..6e2f9b52580 100644 --- a/src/main/java/ch/njol/skript/effects/EffDoIf.java +++ b/src/main/java/ch/njol/skript/effects/EffDoIf.java @@ -57,6 +57,10 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye String cond = parseResult.regexes.get(1).group(); effect = Effect.parse(eff, "Can't understand this effect: " + eff); condition = Condition.parse(cond, "Can't understand this condition: " + cond); + if (effect instanceof EffDoIf) { + Skript.error("Do if effects may not be nested!"); + return false; + } return effect != null && condition != null; } From b6959609753b38d7b8621bcb4c5258675de56867 Mon Sep 17 00:00:00 2001 From: Donut Date: Tue, 11 Sep 2018 21:03:46 -0400 Subject: [PATCH 07/12] Update EffDoIf.java --- src/main/java/ch/njol/skript/effects/EffDoIf.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffDoIf.java b/src/main/java/ch/njol/skript/effects/EffDoIf.java index 6e2f9b52580..2bdd70bd75d 100644 --- a/src/main/java/ch/njol/skript/effects/EffDoIf.java +++ b/src/main/java/ch/njol/skript/effects/EffDoIf.java @@ -56,23 +56,23 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye String eff = parseResult.regexes.get(0).group(); String cond = parseResult.regexes.get(1).group(); effect = Effect.parse(eff, "Can't understand this effect: " + eff); - condition = Condition.parse(cond, "Can't understand this condition: " + cond); if (effect instanceof EffDoIf) { Skript.error("Do if effects may not be nested!"); return false; } + condition = Condition.parse(cond, "Can't understand this condition: " + cond); return effect != null && condition != null; } @Override - protected void execute(Event event) { - if (condition.check(event)) - effect.run(event); + protected void execute(Event e) { + if (condition.check(e)) + effect.run(e); } @Override - public String toString(@Nullable Event event, boolean debug) { - return effect.toString(event, debug) + " if " + condition.toString(event, debug); + public String toString(@Nullable Event e, boolean debug) { + return effect.toString(e, debug) + " if " + condition.toString(e, debug); } } From e767b0869fc9a7020f43355f4f6267ac83659ee3 Mon Sep 17 00:00:00 2001 From: Donut Date: Tue, 2 Oct 2018 18:51:21 -0400 Subject: [PATCH 08/12] Fixed EffExit not working --- .../java/ch/njol/skript/effects/EffDoIf.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffDoIf.java b/src/main/java/ch/njol/skript/effects/EffDoIf.java index 2bdd70bd75d..fa5828322a4 100644 --- a/src/main/java/ch/njol/skript/effects/EffDoIf.java +++ b/src/main/java/ch/njol/skript/effects/EffDoIf.java @@ -65,10 +65,18 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye } @Override - protected void execute(Event e) { - if (condition.check(e)) - effect.run(e); - } + protected void execute(Event e) { + walk(e); + } + + @Override + public TriggerItem walk(Event e) { + if (condition.check(e)) { + effect.setNext(getNext()); + return effect; + } + return getNext(); + } @Override public String toString(@Nullable Event e, boolean debug) { From 595339145018cae05d6637740d51c8179f58fe66 Mon Sep 17 00:00:00 2001 From: Donut Date: Tue, 2 Oct 2018 21:10:05 -0400 Subject: [PATCH 09/12] Forgot import --- src/main/java/ch/njol/skript/effects/EffDoIf.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/ch/njol/skript/effects/EffDoIf.java b/src/main/java/ch/njol/skript/effects/EffDoIf.java index fa5828322a4..08de5dc1a22 100644 --- a/src/main/java/ch/njol/skript/effects/EffDoIf.java +++ b/src/main/java/ch/njol/skript/effects/EffDoIf.java @@ -31,6 +31,7 @@ import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.lang.TriggerItem; import ch.njol.util.Kleenean; @Name("Do If") From bfad58b5e5715038b49e225e0e3bc5ab57d63e97 Mon Sep 17 00:00:00 2001 From: Donut Date: Tue, 2 Oct 2018 21:17:44 -0400 Subject: [PATCH 10/12] Travis fixes --- src/main/java/ch/njol/skript/effects/EffDoIf.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffDoIf.java b/src/main/java/ch/njol/skript/effects/EffDoIf.java index 08de5dc1a22..5d036f34f7e 100644 --- a/src/main/java/ch/njol/skript/effects/EffDoIf.java +++ b/src/main/java/ch/njol/skript/effects/EffDoIf.java @@ -45,13 +45,13 @@ public class EffDoIf extends Effect { Skript.registerEffect(EffDoIf.class, "<.+> if <.+>"); } - @SuppressWarnings({"unchecked", "null"}) + @SuppressWarnings("null"}) private Effect effect; - @SuppressWarnings({"unchecked", "null"}) + @SuppressWarnings("null") private Condition condition; - @SuppressWarnings({"unchecked", "null"}) + @SuppressWarnings("null") @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { String eff = parseResult.regexes.get(0).group(); @@ -70,6 +70,7 @@ protected void execute(Event e) { walk(e); } + @SuppressWarnings("null") @Override public TriggerItem walk(Event e) { if (condition.check(e)) { From afb12c514e7fb7eaff58bdafb51b69a20df3b5b4 Mon Sep 17 00:00:00 2001 From: Donut Date: Tue, 2 Oct 2018 21:21:43 -0400 Subject: [PATCH 11/12] Typo --- src/main/java/ch/njol/skript/effects/EffDoIf.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/effects/EffDoIf.java b/src/main/java/ch/njol/skript/effects/EffDoIf.java index 5d036f34f7e..1ade394ad8c 100644 --- a/src/main/java/ch/njol/skript/effects/EffDoIf.java +++ b/src/main/java/ch/njol/skript/effects/EffDoIf.java @@ -45,7 +45,7 @@ public class EffDoIf extends Effect { Skript.registerEffect(EffDoIf.class, "<.+> if <.+>"); } - @SuppressWarnings("null"}) + @SuppressWarnings("null") private Effect effect; @SuppressWarnings("null") From 686454c2795a4cde5f3a6a92b2bc3146d5e2f199 Mon Sep 17 00:00:00 2001 From: Donut Date: Tue, 2 Oct 2018 23:12:16 -0400 Subject: [PATCH 12/12] Fix execute method --- src/main/java/ch/njol/skript/effects/EffDoIf.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffDoIf.java b/src/main/java/ch/njol/skript/effects/EffDoIf.java index 1ade394ad8c..22752da1844 100644 --- a/src/main/java/ch/njol/skript/effects/EffDoIf.java +++ b/src/main/java/ch/njol/skript/effects/EffDoIf.java @@ -33,6 +33,7 @@ import ch.njol.skript.lang.SkriptParser; import ch.njol.skript.lang.TriggerItem; import ch.njol.util.Kleenean; +import org.eclipse.jdt.annotation.Nullable; @Name("Do If") @Description("Execute an effect if a condition is true.") @@ -66,11 +67,9 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye } @Override - protected void execute(Event e) { - walk(e); - } - - @SuppressWarnings("null") + protected void execute(Event e) {} + + @Nullable @Override public TriggerItem walk(Event e) { if (condition.check(e)) {