From 0a57fd4dc1a91a27f2e0d9376c31d41a1f16f983 Mon Sep 17 00:00:00 2001 From: Pikachu920 <28607612+Pikachu920@users.noreply.github.com> Date: Wed, 16 Mar 2022 23:30:53 -0500 Subject: [PATCH 01/13] Add EffPathfind --- .../ch/njol/skript/effects/EffPathfind.java | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 src/main/java/ch/njol/skript/effects/EffPathfind.java diff --git a/src/main/java/ch/njol/skript/effects/EffPathfind.java b/src/main/java/ch/njol/skript/effects/EffPathfind.java new file mode 100644 index 00000000000..325214d34dd --- /dev/null +++ b/src/main/java/ch/njol/skript/effects/EffPathfind.java @@ -0,0 +1,101 @@ +/** + * 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 Peter Güttinger, SkriptLang team and contributors + */ +package ch.njol.skript.effects; + +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.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.util.Kleenean; +import com.google.common.base.MoreObjects; +import org.bukkit.Location; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Mob; +import org.bukkit.event.Event; +import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.NotNull; + +@Name("Break Block") +@Description({"Breaks the block and spawns items as if a player had mined it", + "\nYou can add a tool, which will spawn items based on how that tool would break the block ", + "(ie: When using a hand to break stone, it drops nothing, whereas with a pickaxe it drops cobblestone)"}) +@Examples({"make all creepers pathfind towards player"}) +@Since("INSERT VERSION") +public class EffPathfind extends Effect { + + static { + if (Skript.methodExists(Mob.class, "getPathfinder")) + Skript.registerEffect(EffPathfind.class, + "make %livingentities% (pathfind|move) to[wards] %livingentity/location% [at speed %-number%]", + "make %livingentities% stop (pathfinding|moving)"); + } + + @SuppressWarnings("NotNullFieldNotInitialized") + private Expression entities; + + @Nullable + private Expression target; + + @Nullable + private Expression speed; + + @Override + @SuppressWarnings("unchecked") + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + entities = (Expression) exprs[0]; + target = matchedPattern == 0 ? exprs[1] : null; + speed = matchedPattern == 0 ? (Expression) exprs[2] : null; + return true; + } + + @Override + protected void execute(Event e) { + Object target = this.target != null ? this.target.getSingle(e) : null; + Number speed = this.speed != null ? this.speed.getSingle(e) : null; + for (LivingEntity entity : entities.getArray(e)) { + if (entity instanceof Mob) { + if (target instanceof LivingEntity) { + ((Mob) entity).getPathfinder().moveTo(((LivingEntity) target), speed != null ? speed.intValue() : 1); + } else if (target instanceof Location) { + ((Mob) entity).getPathfinder().moveTo(((Location) target), speed != null ? speed.intValue() : 1); + } else if (this.target == null) { + ((Mob) entity).getPathfinder().stopPathfinding(); + } + } + } + } + + @Override + public String toString(@Nullable Event e, boolean debug) { + if (target == null) { + return "make " + entities.toString(e, debug) + " stop pathfinding"; + } + + String repr = "make " + entities.toString(e, debug) + " pathfind towards " + target.toString(e, debug); + if (speed != null) { + repr += " at speed " + speed.toString(e, debug); + } + return repr; + } + +} From 41a7a2f6172b33ff9036cfd1c1b36efe45b7bbeb Mon Sep 17 00:00:00 2001 From: Pikachu920 <28607612+Pikachu920@users.noreply.github.com> Date: Wed, 16 Mar 2022 23:35:04 -0500 Subject: [PATCH 02/13] Remove redundant parentheses --- src/main/java/ch/njol/skript/effects/EffPathfind.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffPathfind.java b/src/main/java/ch/njol/skript/effects/EffPathfind.java index 325214d34dd..3fc8dee9490 100644 --- a/src/main/java/ch/njol/skript/effects/EffPathfind.java +++ b/src/main/java/ch/njol/skript/effects/EffPathfind.java @@ -75,9 +75,9 @@ protected void execute(Event e) { for (LivingEntity entity : entities.getArray(e)) { if (entity instanceof Mob) { if (target instanceof LivingEntity) { - ((Mob) entity).getPathfinder().moveTo(((LivingEntity) target), speed != null ? speed.intValue() : 1); + ((Mob) entity).getPathfinder().moveTo((LivingEntity) target, speed != null ? speed.intValue() : 1); } else if (target instanceof Location) { - ((Mob) entity).getPathfinder().moveTo(((Location) target), speed != null ? speed.intValue() : 1); + ((Mob) entity).getPathfinder().moveTo((Location) target, speed != null ? speed.intValue() : 1); } else if (this.target == null) { ((Mob) entity).getPathfinder().stopPathfinding(); } From 7cfcc3f9cb7d8425c0305650d7a201f37b1337d2 Mon Sep 17 00:00:00 2001 From: Pikachu920 <28607612+Pikachu920@users.noreply.github.com> Date: Wed, 16 Mar 2022 23:35:54 -0500 Subject: [PATCH 03/13] Add additional examples to EffPathfind --- src/main/java/ch/njol/skript/effects/EffPathfind.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/effects/EffPathfind.java b/src/main/java/ch/njol/skript/effects/EffPathfind.java index 3fc8dee9490..c367f7761f4 100644 --- a/src/main/java/ch/njol/skript/effects/EffPathfind.java +++ b/src/main/java/ch/njol/skript/effects/EffPathfind.java @@ -39,7 +39,9 @@ @Description({"Breaks the block and spawns items as if a player had mined it", "\nYou can add a tool, which will spawn items based on how that tool would break the block ", "(ie: When using a hand to break stone, it drops nothing, whereas with a pickaxe it drops cobblestone)"}) -@Examples({"make all creepers pathfind towards player"}) +@Examples({"make all creepers pathfind towards player", + "make all cows stop pathfinding", + "make event-entity pathfind towards player"}) @Since("INSERT VERSION") public class EffPathfind extends Effect { From f63e92c70281f6b097a59937ad76fd8f375d9c5d Mon Sep 17 00:00:00 2001 From: Pikachu920 <28607612+Pikachu920@users.noreply.github.com> Date: Wed, 16 Mar 2022 23:48:36 -0500 Subject: [PATCH 04/13] Fix copied documentation --- src/main/java/ch/njol/skript/effects/EffPathfind.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffPathfind.java b/src/main/java/ch/njol/skript/effects/EffPathfind.java index c367f7761f4..1a0c74e8230 100644 --- a/src/main/java/ch/njol/skript/effects/EffPathfind.java +++ b/src/main/java/ch/njol/skript/effects/EffPathfind.java @@ -27,18 +27,15 @@ import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser; import ch.njol.util.Kleenean; -import com.google.common.base.MoreObjects; import org.bukkit.Location; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Mob; import org.bukkit.event.Event; import org.eclipse.jdt.annotation.Nullable; -import org.jetbrains.annotations.NotNull; -@Name("Break Block") -@Description({"Breaks the block and spawns items as if a player had mined it", - "\nYou can add a tool, which will spawn items based on how that tool would break the block ", - "(ie: When using a hand to break stone, it drops nothing, whereas with a pickaxe it drops cobblestone)"}) +@Name("Pathfind") +@Description({"Make an entity pathfind towards a location or another entity. Not all entities can pathfind." + + "If the pathfinding target is another entity, the entities may or may not continuously follow the target."}) @Examples({"make all creepers pathfind towards player", "make all cows stop pathfinding", "make event-entity pathfind towards player"}) From 1917475bee936493f1bea874d30899368bd9e987 Mon Sep 17 00:00:00 2001 From: Pikachu920 <28607612+Pikachu920@users.noreply.github.com> Date: Wed, 16 Mar 2022 23:54:44 -0500 Subject: [PATCH 05/13] Add class existence check to EffPathFind registration --- src/main/java/ch/njol/skript/effects/EffPathfind.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/effects/EffPathfind.java b/src/main/java/ch/njol/skript/effects/EffPathfind.java index 1a0c74e8230..ca4b00afd0e 100644 --- a/src/main/java/ch/njol/skript/effects/EffPathfind.java +++ b/src/main/java/ch/njol/skript/effects/EffPathfind.java @@ -43,7 +43,7 @@ public class EffPathfind extends Effect { static { - if (Skript.methodExists(Mob.class, "getPathfinder")) + if (Skript.classExists("org.bukkit.entity.Mob") && Skript.methodExists(Mob.class, "getPathfinder")) Skript.registerEffect(EffPathfind.class, "make %livingentities% (pathfind|move) to[wards] %livingentity/location% [at speed %-number%]", "make %livingentities% stop (pathfinding|moving)"); From bbd8430227bf6eb78104576f1727071c99208b40 Mon Sep 17 00:00:00 2001 From: Ayham Al Ali Date: Thu, 30 Jun 2022 18:23:44 +0300 Subject: [PATCH 06/13] Update src/main/java/ch/njol/skript/effects/EffPathfind.java --- src/main/java/ch/njol/skript/effects/EffPathfind.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/effects/EffPathfind.java b/src/main/java/ch/njol/skript/effects/EffPathfind.java index ca4b00afd0e..c2f37bdab21 100644 --- a/src/main/java/ch/njol/skript/effects/EffPathfind.java +++ b/src/main/java/ch/njol/skript/effects/EffPathfind.java @@ -34,7 +34,7 @@ import org.eclipse.jdt.annotation.Nullable; @Name("Pathfind") -@Description({"Make an entity pathfind towards a location or another entity. Not all entities can pathfind." + +@Description({"Make an entity pathfind towards a location or another entity. Not all entities can pathfind. " + "If the pathfinding target is another entity, the entities may or may not continuously follow the target."}) @Examples({"make all creepers pathfind towards player", "make all cows stop pathfinding", From dcd608decf24df22efeec79f089ca6a9cb66ffaf Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Fri, 15 Jul 2022 22:43:06 -0600 Subject: [PATCH 07/13] Apply changes --- .../ch/njol/skript/effects/EffPathfind.java | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffPathfind.java b/src/main/java/ch/njol/skript/effects/EffPathfind.java index c2f37bdab21..5f290efe71e 100644 --- a/src/main/java/ch/njol/skript/effects/EffPathfind.java +++ b/src/main/java/ch/njol/skript/effects/EffPathfind.java @@ -18,6 +18,12 @@ */ package ch.njol.skript.effects; +import org.bukkit.Location; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Mob; +import org.bukkit.event.Event; +import org.eclipse.jdt.annotation.Nullable; + import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; @@ -25,20 +31,17 @@ import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Expression; -import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; -import org.bukkit.Location; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Mob; -import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; @Name("Pathfind") @Description({"Make an entity pathfind towards a location or another entity. Not all entities can pathfind. " + "If the pathfinding target is another entity, the entities may or may not continuously follow the target."}) -@Examples({"make all creepers pathfind towards player", +@Examples({ + "make all creepers pathfind towards player", "make all cows stop pathfinding", - "make event-entity pathfind towards player"}) + "make event-entity pathfind towards player" +}) @Since("INSERT VERSION") public class EffPathfind extends Effect { @@ -49,18 +52,17 @@ public class EffPathfind extends Effect { "make %livingentities% stop (pathfinding|moving)"); } - @SuppressWarnings("NotNullFieldNotInitialized") private Expression entities; @Nullable - private Expression target; + private Expression speed; @Nullable - private Expression speed; + private Expression target; @Override @SuppressWarnings("unchecked") - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { entities = (Expression) exprs[0]; target = matchedPattern == 0 ? exprs[1] : null; speed = matchedPattern == 0 ? (Expression) exprs[2] : null; @@ -68,32 +70,30 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye } @Override - protected void execute(Event e) { - Object target = this.target != null ? this.target.getSingle(e) : null; - Number speed = this.speed != null ? this.speed.getSingle(e) : null; - for (LivingEntity entity : entities.getArray(e)) { - if (entity instanceof Mob) { - if (target instanceof LivingEntity) { - ((Mob) entity).getPathfinder().moveTo((LivingEntity) target, speed != null ? speed.intValue() : 1); - } else if (target instanceof Location) { - ((Mob) entity).getPathfinder().moveTo((Location) target, speed != null ? speed.intValue() : 1); - } else if (this.target == null) { - ((Mob) entity).getPathfinder().stopPathfinding(); - } + protected void execute(Event event) { + Object target = this.target != null ? this.target.getSingle(event) : null; + int speed = this.speed != null ? this.speed.getSingle(event).intValue() : 1; + for (LivingEntity entity : entities.getArray(event)) { + if (!(entity instanceof Mob)) + continue; + if (target instanceof LivingEntity) { + ((Mob) entity).getPathfinder().moveTo((LivingEntity) target, speed); + } else if (target instanceof Location) { + ((Mob) entity).getPathfinder().moveTo((Location) target, speed); + } else if (this.target == null) { + ((Mob) entity).getPathfinder().stopPathfinding(); } } } @Override public String toString(@Nullable Event e, boolean debug) { - if (target == null) { + if (target == null) return "make " + entities.toString(e, debug) + " stop pathfinding"; - } String repr = "make " + entities.toString(e, debug) + " pathfind towards " + target.toString(e, debug); - if (speed != null) { + if (speed != null) repr += " at speed " + speed.toString(e, debug); - } return repr; } From 89f901a98781d19c003faf2472039f60e78db3ce Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Fri, 15 Jul 2022 23:00:30 -0600 Subject: [PATCH 08/13] Make pathfind a double --- src/main/java/ch/njol/skript/effects/EffPathfind.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/effects/EffPathfind.java b/src/main/java/ch/njol/skript/effects/EffPathfind.java index 5f290efe71e..f530359e260 100644 --- a/src/main/java/ch/njol/skript/effects/EffPathfind.java +++ b/src/main/java/ch/njol/skript/effects/EffPathfind.java @@ -72,7 +72,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override protected void execute(Event event) { Object target = this.target != null ? this.target.getSingle(event) : null; - int speed = this.speed != null ? this.speed.getSingle(event).intValue() : 1; + double speed = this.speed != null ? this.speed.getSingle(event).doubleValue() : 1; for (LivingEntity entity : entities.getArray(event)) { if (!(entity instanceof Mob)) continue; From 3d43b21d4b92dba1a1c0baad76846c97085d86da Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Sat, 16 Jul 2022 19:24:10 -0600 Subject: [PATCH 09/13] Clean up documentation --- .../java/ch/njol/skript/effects/EffPathfind.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffPathfind.java b/src/main/java/ch/njol/skript/effects/EffPathfind.java index f530359e260..519bd287ac1 100644 --- a/src/main/java/ch/njol/skript/effects/EffPathfind.java +++ b/src/main/java/ch/njol/skript/effects/EffPathfind.java @@ -36,11 +36,11 @@ @Name("Pathfind") @Description({"Make an entity pathfind towards a location or another entity. Not all entities can pathfind. " + - "If the pathfinding target is another entity, the entities may or may not continuously follow the target."}) + "If the pathfinding target is another entity, the entities may or may not continuously follow the target. This is a Paper Spigot exclusive."}) @Examples({ "make all creepers pathfind towards player", "make all cows stop pathfinding", - "make event-entity pathfind towards player" + "make event-entity pathfind towards player at speed 1" }) @Since("INSERT VERSION") public class EffPathfind extends Effect { @@ -72,7 +72,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override protected void execute(Event event) { Object target = this.target != null ? this.target.getSingle(event) : null; - double speed = this.speed != null ? this.speed.getSingle(event).doubleValue() : 1; + double speed = this.speed != null ? this.speed.getOptionalSingle(event).orElse(1).doubleValue() : 1; for (LivingEntity entity : entities.getArray(event)) { if (!(entity instanceof Mob)) continue; @@ -87,13 +87,12 @@ protected void execute(Event event) { } @Override - public String toString(@Nullable Event e, boolean debug) { + public String toString(@Nullable Event event, boolean debug) { if (target == null) - return "make " + entities.toString(e, debug) + " stop pathfinding"; - - String repr = "make " + entities.toString(e, debug) + " pathfind towards " + target.toString(e, debug); + return "make " + entities.toString(event, debug) + " stop pathfinding"; + String repr = "make " + entities.toString(event, debug) + " pathfind towards " + target.toString(event, debug); if (speed != null) - repr += " at speed " + speed.toString(e, debug); + repr += " at speed " + speed.toString(event, debug); return repr; } From f7fc4dc78eb9ccf9661ba34c4c0784f9b74d42af Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Mon, 18 Jul 2022 01:28:19 -0600 Subject: [PATCH 10/13] Add required plugin annotation --- src/main/java/ch/njol/skript/effects/EffPathfind.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/ch/njol/skript/effects/EffPathfind.java b/src/main/java/ch/njol/skript/effects/EffPathfind.java index 519bd287ac1..78cfe2af73f 100644 --- a/src/main/java/ch/njol/skript/effects/EffPathfind.java +++ b/src/main/java/ch/njol/skript/effects/EffPathfind.java @@ -28,6 +28,7 @@ import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.RequiredPlugins; import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Expression; @@ -43,6 +44,7 @@ "make event-entity pathfind towards player at speed 1" }) @Since("INSERT VERSION") +@RequiredPlugins("Paper Spigot") public class EffPathfind extends Effect { static { From 8780e13e1e260448febd11c3abcde7efc20a7097 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Mon, 18 Jul 2022 01:28:54 -0600 Subject: [PATCH 11/13] Add required plugin annotation --- src/main/java/ch/njol/skript/effects/EffPathfind.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/effects/EffPathfind.java b/src/main/java/ch/njol/skript/effects/EffPathfind.java index 78cfe2af73f..aeaf2ef2ae3 100644 --- a/src/main/java/ch/njol/skript/effects/EffPathfind.java +++ b/src/main/java/ch/njol/skript/effects/EffPathfind.java @@ -37,7 +37,7 @@ @Name("Pathfind") @Description({"Make an entity pathfind towards a location or another entity. Not all entities can pathfind. " + - "If the pathfinding target is another entity, the entities may or may not continuously follow the target. This is a Paper Spigot exclusive."}) + "If the pathfinding target is another entity, the entities may or may not continuously follow the target."}) @Examples({ "make all creepers pathfind towards player", "make all cows stop pathfinding", From 5d6152786e5c19941158a596ddeded338e2af0cd Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Mon, 18 Jul 2022 01:42:52 -0600 Subject: [PATCH 12/13] Add required plugin annotation --- src/main/java/ch/njol/skript/effects/EffPathfind.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/effects/EffPathfind.java b/src/main/java/ch/njol/skript/effects/EffPathfind.java index aeaf2ef2ae3..b6ebb1833bc 100644 --- a/src/main/java/ch/njol/skript/effects/EffPathfind.java +++ b/src/main/java/ch/njol/skript/effects/EffPathfind.java @@ -44,7 +44,7 @@ "make event-entity pathfind towards player at speed 1" }) @Since("INSERT VERSION") -@RequiredPlugins("Paper Spigot") +@RequiredPlugins("Paper 1.13+") public class EffPathfind extends Effect { static { From e2ca150e1d30b91ee9f4dc02f9c0cd4354868796 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Mon, 18 Jul 2022 02:25:03 -0600 Subject: [PATCH 13/13] Add required plugin annotation --- src/main/java/ch/njol/skript/effects/EffPathfind.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/effects/EffPathfind.java b/src/main/java/ch/njol/skript/effects/EffPathfind.java index b6ebb1833bc..eb53966d0f6 100644 --- a/src/main/java/ch/njol/skript/effects/EffPathfind.java +++ b/src/main/java/ch/njol/skript/effects/EffPathfind.java @@ -44,7 +44,7 @@ "make event-entity pathfind towards player at speed 1" }) @Since("INSERT VERSION") -@RequiredPlugins("Paper 1.13+") +@RequiredPlugins("Paper") public class EffPathfind extends Effect { static {