From 9b279a49b6018223003f5c2bf8094d8b0e76287d Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Wed, 29 Mar 2023 04:14:37 +0800 Subject: [PATCH 01/12] Enhance --- .../njol/skript/conditions/CondIsSheared.java | 53 ++++++++++++++++ .../java/ch/njol/skript/effects/EffShear.java | 62 +++++++++++++------ 2 files changed, 95 insertions(+), 20 deletions(-) create mode 100644 src/main/java/ch/njol/skript/conditions/CondIsSheared.java diff --git a/src/main/java/ch/njol/skript/conditions/CondIsSheared.java b/src/main/java/ch/njol/skript/conditions/CondIsSheared.java new file mode 100644 index 00000000000..6f05cf61e44 --- /dev/null +++ b/src/main/java/ch/njol/skript/conditions/CondIsSheared.java @@ -0,0 +1,53 @@ +/** + * 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.conditions; + +import ch.njol.skript.Skript; +import ch.njol.skript.conditions.base.PropertyCondition; +import io.papermc.paper.entity.Shearable; +import org.bukkit.entity.Cow; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Sheep; + +public class CondIsSheared extends PropertyCondition { + + private static final boolean interfaceMethod = Skript.classExists("io.papermc.paper.entity.Shearable"); + + static { + register(CondIsSheared.class, "sheared", "livingentity"); + } + + @Override + public boolean check(LivingEntity entity) { + if (interfaceMethod) { + if (entity instanceof Cow) // As sheared mooshroom is a cow + return true; + return !((Shearable) entity).readyToBeSheared(); + } + if (entity instanceof Sheep) { + return ((Sheep) entity).isSheared(); + } + return false; + } + + @Override + protected String getPropertyName() { + return "sheared"; + } +} diff --git a/src/main/java/ch/njol/skript/effects/EffShear.java b/src/main/java/ch/njol/skript/effects/EffShear.java index 467aebeb70a..ee6148f24d8 100644 --- a/src/main/java/ch/njol/skript/effects/EffShear.java +++ b/src/main/java/ch/njol/skript/effects/EffShear.java @@ -18,11 +18,6 @@ */ package ch.njol.skript.effects; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Sheep; -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; @@ -32,46 +27,73 @@ import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; +import io.papermc.paper.entity.Shearable; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.MushroomCow; +import org.bukkit.entity.Sheep; +import org.bukkit.entity.Snowman; +import org.bukkit.event.Event; +import org.eclipse.jdt.annotation.Nullable; + +import java.util.Random; -/** - * @author Peter Güttinger - */ @Name("Shear") @Description("Shears or 'un-shears' a sheep. Please note that no wool is dropped, this only sets the 'sheared' state of the sheep.") @Examples({"on rightclick on a sheep holding a sword:", " shear the clicked sheep"}) @Since("2.0") public class EffShear extends Effect { + + private static final boolean interfaceMethod = Skript.classExists("io.papermc.paper.entity.Shearable"); + private static final boolean snowmanMethod = Skript.methodExists(Snowman.class, "setDerp", boolean.class); + private static final boolean mooshroomMethod = Skript.methodExists(MushroomCow.class, "setVariant", MushroomCow.Variant.class); + static { Skript.registerEffect(EffShear.class, - "shear %livingentities%", + (interfaceMethod ? "shear %livingentities% [nodrops:(without drops)]" : "shear %livingentities%"), "un[-]shear %livingentities%"); } @SuppressWarnings("null") - private Expression sheep; + private Expression entity; private boolean shear; - - @SuppressWarnings({"unchecked", "null"}) + private boolean drops; + @Override - public boolean init(final Expression[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { - sheep = (Expression) exprs[0]; + @SuppressWarnings("unchecked") + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + entity = (Expression) exprs[0]; shear = matchedPattern == 0; + drops = !parseResult.hasTag("nodrops"); return true; } @Override - protected void execute(final Event e) { - for (final LivingEntity en : sheep.getArray(e)) { - if (en instanceof Sheep) { - ((Sheep) en).setSheared(shear); + protected void execute(Event event) { + for (LivingEntity entity : entity.getArray(event)) { + if (shear && interfaceMethod) { + if (drops && entity instanceof Shearable) { + ((Shearable) entity).shear(); + } + } + if (entity instanceof Sheep) { + ((Sheep) entity).setSheared(shear); + } else if (mooshroomMethod) { + if (!shear && entity instanceof MushroomCow) { + int rng = new Random().nextInt(MushroomCow.Variant.values().length); + ((MushroomCow) entity).setVariant(MushroomCow.Variant.values()[rng]); + } + } else if (snowmanMethod) { + if (!shear && entity instanceof Snowman) { + ((Snowman) entity).setDerp(false); + } } } } @Override - public String toString(final @Nullable Event e, final boolean debug) { - return (shear ? "" : "un") + "shear " + sheep.toString(e, debug); + public String toString(@Nullable Event event, boolean debug) { + return (shear ? "" : "un") + "shear " + entity.toString(event, debug) + (interfaceMethod && drops ? " with drops" : ""); } } From f282275becc0d258c254426a38908c9c4d31584b Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Fri, 31 Mar 2023 01:11:50 +0800 Subject: [PATCH 02/12] Enhance (finish) --- .../java/ch/njol/skript/effects/EffShear.java | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffShear.java b/src/main/java/ch/njol/skript/effects/EffShear.java index ee6148f24d8..64287763c2a 100644 --- a/src/main/java/ch/njol/skript/effects/EffShear.java +++ b/src/main/java/ch/njol/skript/effects/EffShear.java @@ -27,44 +27,50 @@ import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; + import io.papermc.paper.entity.Shearable; + import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.MushroomCow; import org.bukkit.entity.Sheep; import org.bukkit.entity.Snowman; import org.bukkit.event.Event; import org.eclipse.jdt.annotation.Nullable; -import java.util.Random; - @Name("Shear") -@Description("Shears or 'un-shears' a sheep. Please note that no wool is dropped, this only sets the 'sheared' state of the sheep.") -@Examples({"on rightclick on a sheep holding a sword:", - " shear the clicked sheep"}) -@Since("2.0") +@Description({ + "Shears or un-shears a shearable entity with drops by shearing and a 'sheared' sound. Using with 'force' will force this effect despite the entity's 'shear state'.", + "\nPlease note that..:", + "\n- If your server is not running with Paper 1.19.4 or higher, this effect will only change its 'shear state', and the 'force' effect is unavailable", + "\n- Force-shearing or un-shearing on a sheared mushroom cow is not possible" +}) +@Examples({ + "on rightclick on a sheep holding a sword:", + "\tshear the clicked sheep", + "\tchance of 10%", + "\tforce shear the clicked sheep" +}) +@Since("2.0, INSERT VERSION (shearable)") public class EffShear extends Effect { private static final boolean interfaceMethod = Skript.classExists("io.papermc.paper.entity.Shearable"); - private static final boolean snowmanMethod = Skript.methodExists(Snowman.class, "setDerp", boolean.class); - private static final boolean mooshroomMethod = Skript.methodExists(MushroomCow.class, "setVariant", MushroomCow.Variant.class); static { Skript.registerEffect(EffShear.class, - (interfaceMethod ? "shear %livingentities% [nodrops:(without drops)]" : "shear %livingentities%"), + (interfaceMethod ? "[:force] shear %livingentities%" : "shear %livingentities%"), "un[-]shear %livingentities%"); } @SuppressWarnings("null") private Expression entity; + private boolean force; private boolean shear; - private boolean drops; @Override @SuppressWarnings("unchecked") public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { entity = (Expression) exprs[0]; + force = parseResult.hasTag("force"); shear = matchedPattern == 0; - drops = !parseResult.hasTag("nodrops"); return true; } @@ -72,28 +78,25 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye protected void execute(Event event) { for (LivingEntity entity : entity.getArray(event)) { if (shear && interfaceMethod) { - if (drops && entity instanceof Shearable) { - ((Shearable) entity).shear(); - } + if (!(entity instanceof Shearable)) + continue; + Shearable shearable = ((Shearable) entity); + if (!force && !shearable.readyToBeSheared()) + continue; + shearable.shear(); + continue; } if (entity instanceof Sheep) { ((Sheep) entity).setSheared(shear); - } else if (mooshroomMethod) { - if (!shear && entity instanceof MushroomCow) { - int rng = new Random().nextInt(MushroomCow.Variant.values().length); - ((MushroomCow) entity).setVariant(MushroomCow.Variant.values()[rng]); - } - } else if (snowmanMethod) { - if (!shear && entity instanceof Snowman) { - ((Snowman) entity).setDerp(false); - } + } else if (entity instanceof Snowman) { + ((Snowman) entity).setDerp(shear); } } } @Override public String toString(@Nullable Event event, boolean debug) { - return (shear ? "" : "un") + "shear " + entity.toString(event, debug) + (interfaceMethod && drops ? " with drops" : ""); + return (shear ? "" : "un") + "shear " + entity.toString(event, debug); } } From 1ac574daf86198d728213c1701f02645f629b9b6 Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Fri, 31 Mar 2023 01:28:52 +0800 Subject: [PATCH 03/12] Enhance (finish x2) --- .../ch/njol/skript/conditions/CondIsSheared.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsSheared.java b/src/main/java/ch/njol/skript/conditions/CondIsSheared.java index 6f05cf61e44..d214db8d12a 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsSheared.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsSheared.java @@ -24,25 +24,29 @@ import org.bukkit.entity.Cow; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Sheep; +import org.bukkit.entity.Snowman; public class CondIsSheared extends PropertyCondition { private static final boolean interfaceMethod = Skript.classExists("io.papermc.paper.entity.Shearable"); static { - register(CondIsSheared.class, "sheared", "livingentity"); + register(CondIsSheared.class, "(sheared|shorn)", "livingentity"); } @Override public boolean check(LivingEntity entity) { + if (entity instanceof Cow) // As sheared mooshroom cow is a Cow which does not implements Shearable + return true; if (interfaceMethod) { - if (entity instanceof Cow) // As sheared mooshroom is a cow - return true; + if (!(entity instanceof Shearable)) + return false; return !((Shearable) entity).readyToBeSheared(); } - if (entity instanceof Sheep) { + if (entity instanceof Sheep) return ((Sheep) entity).isSheared(); - } + if (entity instanceof Snowman) + return ((Snowman) entity).isDerp(); return false; } From 6f4c390c41d4e1969eb01c1f04a7256cf3c17155 Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Fri, 31 Mar 2023 01:35:10 +0800 Subject: [PATCH 04/12] Docs --- .../java/ch/njol/skript/conditions/CondIsSheared.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsSheared.java b/src/main/java/ch/njol/skript/conditions/CondIsSheared.java index d214db8d12a..a501ebfa776 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsSheared.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsSheared.java @@ -20,12 +20,23 @@ import ch.njol.skript.Skript; import ch.njol.skript.conditions.base.PropertyCondition; +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 io.papermc.paper.entity.Shearable; import org.bukkit.entity.Cow; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Sheep; import org.bukkit.entity.Snowman; +@Name("Entity Is Sheared") +@Description("Checks whether an entity is sheared.") +@Examples({ + "if targeted entity of player is sheared:", + "\tsend \"This entity has nothing left to shear!\" to player" +}) +@Since("INSERT VERSION") public class CondIsSheared extends PropertyCondition { private static final boolean interfaceMethod = Skript.classExists("io.papermc.paper.entity.Shearable"); From a1103a9e8b623baf9b4d0056b35ef794dc31ca6a Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Sat, 8 Apr 2023 20:56:55 +0800 Subject: [PATCH 05/12] Eclipse -> Jetbrains annotation --- src/main/java/ch/njol/skript/effects/EffShear.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/effects/EffShear.java b/src/main/java/ch/njol/skript/effects/EffShear.java index 64287763c2a..8460a3c844d 100644 --- a/src/main/java/ch/njol/skript/effects/EffShear.java +++ b/src/main/java/ch/njol/skript/effects/EffShear.java @@ -34,7 +34,7 @@ import org.bukkit.entity.Sheep; import org.bukkit.entity.Snowman; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; @Name("Shear") @Description({ From 1c2e3866f1233facbb7b0d7da90967e6dfe3de0f Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Mon, 10 Apr 2023 09:21:39 +0800 Subject: [PATCH 06/12] Requested change --- src/main/java/ch/njol/skript/conditions/CondIsSheared.java | 6 ++++-- src/main/java/ch/njol/skript/effects/EffShear.java | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsSheared.java b/src/main/java/ch/njol/skript/conditions/CondIsSheared.java index a501ebfa776..41d3b2cd3f9 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsSheared.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsSheared.java @@ -23,6 +23,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 io.papermc.paper.entity.Shearable; import org.bukkit.entity.Cow; @@ -31,12 +32,13 @@ import org.bukkit.entity.Snowman; @Name("Entity Is Sheared") -@Description("Checks whether an entity is sheared.") +@Description("Checks whether an entity is sheared. For below 1.19.4 users, this condition only works on sheeps and snowmen.") @Examples({ "if targeted entity of player is sheared:", "\tsend \"This entity has nothing left to shear!\" to player" }) @Since("INSERT VERSION") +@RequiredPlugins("Paper 1.19.4+ (shearable)") public class CondIsSheared extends PropertyCondition { private static final boolean interfaceMethod = Skript.classExists("io.papermc.paper.entity.Shearable"); @@ -47,7 +49,7 @@ public class CondIsSheared extends PropertyCondition { @Override public boolean check(LivingEntity entity) { - if (entity instanceof Cow) // As sheared mooshroom cow is a Cow which does not implements Shearable + if (entity instanceof Cow) // As sheared mushroom cow is a Cow which does not implements Shearable return true; if (interfaceMethod) { if (!(entity instanceof Shearable)) diff --git a/src/main/java/ch/njol/skript/effects/EffShear.java b/src/main/java/ch/njol/skript/effects/EffShear.java index 8460a3c844d..29571bd9362 100644 --- a/src/main/java/ch/njol/skript/effects/EffShear.java +++ b/src/main/java/ch/njol/skript/effects/EffShear.java @@ -56,7 +56,7 @@ public class EffShear extends Effect { static { Skript.registerEffect(EffShear.class, - (interfaceMethod ? "[:force] shear %livingentities%" : "shear %livingentities%"), + (interfaceMethod ? "[:force] " : "") + "shear %livingentities%", "un[-]shear %livingentities%"); } From f442c2340c1fb6fa21e5c1d8bacd85753ae37b3b Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Mon, 10 Apr 2023 09:22:33 +0800 Subject: [PATCH 07/12] Requested change --- src/main/java/ch/njol/skript/conditions/CondIsSheared.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsSheared.java b/src/main/java/ch/njol/skript/conditions/CondIsSheared.java index 41d3b2cd3f9..23844ee13b9 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsSheared.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsSheared.java @@ -67,4 +67,5 @@ public boolean check(LivingEntity entity) { protected String getPropertyName() { return "sheared"; } + } From d2a9779f2f891350934faee8270805750437aaaa Mon Sep 17 00:00:00 2001 From: DelayedGaming <72163224+DelayedGaming@users.noreply.github.com> Date: Mon, 10 Apr 2023 11:33:11 +0800 Subject: [PATCH 08/12] Requested change Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> --- src/main/java/ch/njol/skript/conditions/CondIsSheared.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsSheared.java b/src/main/java/ch/njol/skript/conditions/CondIsSheared.java index 23844ee13b9..9ec8a95d76f 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsSheared.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsSheared.java @@ -44,7 +44,7 @@ public class CondIsSheared extends PropertyCondition { private static final boolean interfaceMethod = Skript.classExists("io.papermc.paper.entity.Shearable"); static { - register(CondIsSheared.class, "(sheared|shorn)", "livingentity"); + register(CondIsSheared.class, "(sheared|shorn)", "livingentities"); } @Override From 9548ea29d395248911c5d5dad1ce0cfd66b81690 Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Sun, 16 Apr 2023 00:53:10 +0800 Subject: [PATCH 09/12] Camel case static final field --- src/main/java/ch/njol/skript/effects/EffShear.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffShear.java b/src/main/java/ch/njol/skript/effects/EffShear.java index 29571bd9362..8f8e479d48d 100644 --- a/src/main/java/ch/njol/skript/effects/EffShear.java +++ b/src/main/java/ch/njol/skript/effects/EffShear.java @@ -52,11 +52,11 @@ @Since("2.0, INSERT VERSION (shearable)") public class EffShear extends Effect { - private static final boolean interfaceMethod = Skript.classExists("io.papermc.paper.entity.Shearable"); + private static final boolean INTERFACE_METHOD = Skript.classExists("io.papermc.paper.entity.Shearable"); static { Skript.registerEffect(EffShear.class, - (interfaceMethod ? "[:force] " : "") + "shear %livingentities%", + (INTERFACE_METHOD ? "[:force] " : "") + "shear %livingentities%", "un[-]shear %livingentities%"); } @@ -77,7 +77,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override protected void execute(Event event) { for (LivingEntity entity : entity.getArray(event)) { - if (shear && interfaceMethod) { + if (shear && INTERFACE_METHOD) { if (!(entity instanceof Shearable)) continue; Shearable shearable = ((Shearable) entity); From d04c4e5e2728dd2d52124a0a30c6f0496ef4b813 Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Sun, 23 Apr 2023 23:03:40 +0800 Subject: [PATCH 10/12] Requested change and minor correction on comment --- src/main/java/ch/njol/skript/conditions/CondIsSheared.java | 6 +++--- src/main/java/ch/njol/skript/effects/EffShear.java | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsSheared.java b/src/main/java/ch/njol/skript/conditions/CondIsSheared.java index 9ec8a95d76f..ee67a09af22 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsSheared.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsSheared.java @@ -32,13 +32,13 @@ import org.bukkit.entity.Snowman; @Name("Entity Is Sheared") -@Description("Checks whether an entity is sheared. For below 1.19.4 users, this condition only works on sheeps and snowmen.") +@Description("Checks whether entities are sheared. This condition only works on sheep and snowmen for versions below 1.19.4.") @Examples({ "if targeted entity of player is sheared:", "\tsend \"This entity has nothing left to shear!\" to player" }) @Since("INSERT VERSION") -@RequiredPlugins("Paper 1.19.4+ (shearable)") +@RequiredPlugins("MC 1.13+ (sheep & snowmen), Paper 1.19.4+ (all shearable entities)") public class CondIsSheared extends PropertyCondition { private static final boolean interfaceMethod = Skript.classExists("io.papermc.paper.entity.Shearable"); @@ -49,7 +49,7 @@ public class CondIsSheared extends PropertyCondition { @Override public boolean check(LivingEntity entity) { - if (entity instanceof Cow) // As sheared mushroom cow is a Cow which does not implements Shearable + if (entity instanceof Cow) // As sheared mushroom cow is a Cow which does not implement Shearable return true; if (interfaceMethod) { if (!(entity instanceof Shearable)) diff --git a/src/main/java/ch/njol/skript/effects/EffShear.java b/src/main/java/ch/njol/skript/effects/EffShear.java index 8f8e479d48d..7b2129bf831 100644 --- a/src/main/java/ch/njol/skript/effects/EffShear.java +++ b/src/main/java/ch/njol/skript/effects/EffShear.java @@ -22,6 +22,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; @@ -49,7 +50,8 @@ "\tchance of 10%", "\tforce shear the clicked sheep" }) -@Since("2.0, INSERT VERSION (shearable)") +@Since("2.0 (sheep & snowmen), INSERT VERSION (all shearable entities)") +@RequiredPlugins("Paper 1.19.4+ (all shearable entities)") public class EffShear extends Effect { private static final boolean INTERFACE_METHOD = Skript.classExists("io.papermc.paper.entity.Shearable"); From 64a314c17135cf0482e059e50574d2ba0e14bda2 Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Sat, 29 Apr 2023 19:56:59 +0800 Subject: [PATCH 11/12] Remove un-needed null warning suppression --- src/main/java/ch/njol/skript/effects/EffShear.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffShear.java b/src/main/java/ch/njol/skript/effects/EffShear.java index 7b2129bf831..b992aae7200 100644 --- a/src/main/java/ch/njol/skript/effects/EffShear.java +++ b/src/main/java/ch/njol/skript/effects/EffShear.java @@ -61,8 +61,7 @@ public class EffShear extends Effect { (INTERFACE_METHOD ? "[:force] " : "") + "shear %livingentities%", "un[-]shear %livingentities%"); } - - @SuppressWarnings("null") + private Expression entity; private boolean force; private boolean shear; From ce6ebabeada40416c82ca9cc9c24b84a7d26fc07 Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Sat, 29 Apr 2023 21:38:49 +0800 Subject: [PATCH 12/12] Requested change + fix docs --- .../njol/skript/conditions/CondIsSheared.java | 22 ++++++++++--------- .../java/ch/njol/skript/effects/EffShear.java | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsSheared.java b/src/main/java/ch/njol/skript/conditions/CondIsSheared.java index ee67a09af22..f667f292899 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsSheared.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsSheared.java @@ -30,18 +30,19 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Sheep; import org.bukkit.entity.Snowman; +import org.bukkit.event.entity.CreatureSpawnEvent; @Name("Entity Is Sheared") -@Description("Checks whether entities are sheared. This condition only works on sheep and snowmen for versions below 1.19.4.") +@Description("Checks whether entities are sheared. This condition only works on cows, sheep and snowmen for versions below 1.19.4.") @Examples({ "if targeted entity of player is sheared:", "\tsend \"This entity has nothing left to shear!\" to player" }) @Since("INSERT VERSION") -@RequiredPlugins("MC 1.13+ (sheep & snowmen), Paper 1.19.4+ (all shearable entities)") +@RequiredPlugins("MC 1.13+ (cows, sheep & snowmen), Paper 1.19.4+ (all shearable entities)") public class CondIsSheared extends PropertyCondition { - private static final boolean interfaceMethod = Skript.classExists("io.papermc.paper.entity.Shearable"); + private static final boolean INTERFACE_METHOD = Skript.classExists("io.papermc.paper.entity.Shearable"); static { register(CondIsSheared.class, "(sheared|shorn)", "livingentities"); @@ -49,17 +50,18 @@ public class CondIsSheared extends PropertyCondition { @Override public boolean check(LivingEntity entity) { - if (entity instanceof Cow) // As sheared mushroom cow is a Cow which does not implement Shearable - return true; - if (interfaceMethod) { - if (!(entity instanceof Shearable)) + if (entity instanceof Cow) { + return entity.getEntitySpawnReason() == CreatureSpawnEvent.SpawnReason.SHEARED; + } else if (INTERFACE_METHOD) { + if (!(entity instanceof Shearable)) { return false; + } return !((Shearable) entity).readyToBeSheared(); - } - if (entity instanceof Sheep) + } else if (entity instanceof Sheep) { return ((Sheep) entity).isSheared(); - if (entity instanceof Snowman) + } else if (entity instanceof Snowman) { return ((Snowman) entity).isDerp(); + } return false; } diff --git a/src/main/java/ch/njol/skript/effects/EffShear.java b/src/main/java/ch/njol/skript/effects/EffShear.java index b992aae7200..5bb6bf3d991 100644 --- a/src/main/java/ch/njol/skript/effects/EffShear.java +++ b/src/main/java/ch/njol/skript/effects/EffShear.java @@ -50,7 +50,7 @@ "\tchance of 10%", "\tforce shear the clicked sheep" }) -@Since("2.0 (sheep & snowmen), INSERT VERSION (all shearable entities)") +@Since("2.0 (cows, sheep & snowmen), INSERT VERSION (all shearable entities)") @RequiredPlugins("Paper 1.19.4+ (all shearable entities)") public class EffShear extends Effect {