From a437ca9ac96e0610c99a724c187920f12ebecf3c Mon Sep 17 00:00:00 2001 From: Fusezion Date: Wed, 29 Mar 2023 20:33:00 -0400 Subject: [PATCH 01/48] Update aliases I guess? --- skript-aliases | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skript-aliases b/skript-aliases index fb9c3044e55..e99be898254 160000 --- a/skript-aliases +++ b/skript-aliases @@ -1 +1 @@ -Subproject commit fb9c3044e555667b4dc5558467608bd55fa32df0 +Subproject commit e99be898254965b0207992f66a3289ab6744106e From 296a944b5214b8fe5a555d9dc66f7df96f43d7ce Mon Sep 17 00:00:00 2001 From: Fusezion Date: Wed, 29 Mar 2023 20:55:42 -0400 Subject: [PATCH 02/48] Revert "Update aliases I guess?" This reverts commit a437ca9ac96e0610c99a724c187920f12ebecf3c. --- skript-aliases | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skript-aliases b/skript-aliases index e99be898254..fb9c3044e55 160000 --- a/skript-aliases +++ b/skript-aliases @@ -1 +1 @@ -Subproject commit e99be898254965b0207992f66a3289ab6744106e +Subproject commit fb9c3044e555667b4dc5558467608bd55fa32df0 From 2cdf76d74398fff429550876b8b63274f1d33167 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Fri, 7 Apr 2023 08:38:37 -0400 Subject: [PATCH 03/48] Adding Events :paperclip: Added EntityEnterLoveModeEvent :pig: Added EntityBreedEvent :sparkles: Added EventValues for these events --- .../classes/data/BukkitEventValues.java | 31 +++++++++++++++++++ .../ch/njol/skript/events/SimpleEvents.java | 20 +++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java index 314fd98bab7..95d4a576b01 100644 --- a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java +++ b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java @@ -80,11 +80,13 @@ import org.bukkit.event.entity.AreaEffectCloudApplyEvent; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; +import org.bukkit.event.entity.EntityBreedEvent; import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.EntityEnterLoveModeEvent; import org.bukkit.event.entity.EntityEvent; import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.event.entity.EntityTameEvent; @@ -1562,5 +1564,34 @@ public Location get(LootGenerateEvent event) { } }, EventValues.TIME_NOW); } + + EventValues.registerEventValue(EntityBreedEvent.class, ItemStack.class, new Getter() { + @Override + @Nullable + public ItemStack get(EntityBreedEvent event) { + return event.getBredWith(); + } + }, EventValues.TIME_NOW); + + if (Skript.classExists("org.bukkit.event.entity.EntityEnterLoveModeEvent")) { + + EventValues.registerEventValue(EntityEnterLoveModeEvent.class, LivingEntity.class, new Getter() { + @Override + @Nullable + public LivingEntity get(EntityEnterLoveModeEvent event) { + return event.getEntity(); + } + }, EventValues.TIME_NOW); + + EventValues.registerEventValue(EntityEnterLoveModeEvent.class, HumanEntity.class, new Getter() { + @Override + @Nullable + public HumanEntity get(EntityEnterLoveModeEvent event) { + return event.getHumanEntity(); + } + }, EventValues.TIME_NOW); + + } + } } diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index 6e1aa2b7004..c8583f7eb8e 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -39,7 +39,9 @@ import org.bukkit.event.entity.AreaEffectCloudApplyEvent; import org.bukkit.event.entity.CreeperPowerEvent; import org.bukkit.event.entity.EntityBreakDoorEvent; +import org.bukkit.event.entity.EntityBreedEvent; import org.bukkit.event.entity.EntityCombustEvent; +import org.bukkit.event.entity.EntityEnterLoveModeEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityPortalEnterEvent; import org.bukkit.event.entity.EntityPortalEvent; @@ -708,7 +710,23 @@ public class SimpleEvents { .since("2.7") .requiredPlugins("Paper 1.16+"); } - + Skript.registerEvent("Entity Breed", SimpleEvent.class, EntityBreedEvent.class, "[entity] breed[ing]") + .description("Called whenever 2 breedable entities begin to conceive a child.") + .examples( + "on breeding:", + "\tsend \"When a %mother% and %father% love each other they make %offspring%\" to breeder" + ) + .since("INSERT VERSION"); + if (Skript.classExists("org.bukkit.event.entity.EntityEnterLoveModeEvent")) { + Skript.registerEvent("Love Mode Enter", SimpleEvent.class, EntityEnterLoveModeEvent.class, "[entity] enter[s] love mode", "[entity] love mode [enter]") + .description("Called whenever an entity enters a state of being in love.") + .examples( + "on love mode enter:", + "\tcancel event # No one is allowed love here" + ) + .since("INSERT VERSION") + .requiredPlugins("MC 1.16+"); + } } } From 9b3afd9fd63beead058195898af512dac5110647 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Fri, 7 Apr 2023 08:42:01 -0400 Subject: [PATCH 04/48] Breeding Event Expressions :family: Added family expression for Father, Mother, Child, and Breeder :sparkles: Added breeding experience to experience class *update class to current standards --- .../expressions/ExprBreedingFamily.java | 96 +++++++++++++++++++ .../skript/expressions/ExprExperience.java | 93 +++++++++--------- 2 files changed, 144 insertions(+), 45 deletions(-) create mode 100644 src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java diff --git a/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java b/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java new file mode 100644 index 00000000000..c49585cdc96 --- /dev/null +++ b/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java @@ -0,0 +1,96 @@ +/** + * 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.expressions; + +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.Expression; +import ch.njol.skript.lang.ExpressionType; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.skript.lang.util.SimpleExpression; +import ch.njol.util.Kleenean; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.Event; +import org.bukkit.event.entity.EntityBreedEvent; +import org.eclipse.jdt.annotation.Nullable; + +@Name("Breeding Family") +@Description("Represents a family within a breeding event") +@Examples({ + "on breeding:", + "\tsend \"When a %mother% and %father% love each other they make a %offspring%\" to breeder" +}) +@Since("INSERT VERSION") +public class ExprBreedingFamily extends SimpleExpression { + + static { + Skript.registerExpression(ExprBreedingFamily.class, LivingEntity.class, ExpressionType.SIMPLE, + "[breed[ing]] mother", + "[breed[ing]] father", + "[breed[ing]] (offspring|child)", + "breeder"); + } + + private int pattern; + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + if (!getParser().isCurrentEvent(EntityBreedEvent.class)) { + Skript.error("This expression can only be used within a Entity Breed event."); + return false; + } + pattern = matchedPattern; + return true; + } + + @Override + protected @Nullable LivingEntity[] get(Event event) { + if (!(event instanceof EntityBreedEvent)) + return new LivingEntity[0]; + EntityBreedEvent breedEvent = (EntityBreedEvent) event; + if (pattern == 0) { + return new LivingEntity[]{breedEvent.getMother()}; + } else if (pattern == 1) { + return new LivingEntity[]{breedEvent.getFather()}; + } else if (pattern == 2) { + return new LivingEntity[]{breedEvent.getEntity()}; + } else if (pattern == 3) { + return new LivingEntity[]{breedEvent.getBreeder()}; + } + return new LivingEntity[0]; + } + + @Override + public boolean isSingle() { + return true; + } + + @Override + public Class getReturnType() { + return LivingEntity.class; + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "breeding family"; + } +} diff --git a/src/main/java/ch/njol/skript/expressions/ExprExperience.java b/src/main/java/ch/njol/skript/expressions/ExprExperience.java index b654f870068..5548fa36f4c 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExperience.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExperience.java @@ -20,6 +20,7 @@ import org.bukkit.event.Event; import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.entity.EntityBreedEvent; import org.bukkit.event.player.PlayerExpChangeEvent; import org.eclipse.jdt.annotation.Nullable; @@ -49,18 +50,23 @@ "\tclear dropped experience", "on break of diamond ore:", "\tif tool of player = diamond pickaxe:", - "\t\tadd 100 to dropped experience"}) -@Since("2.1, 2.5.3 (block break event), 2.7 (experience change event)") -@Events({"experience spawn", "break / mine", "experience change"}) + "\t\tadd 100 to dropped experience", + "on breed:", + "\tevent-father is a cow", + "\tset dropped experience to 10" +}) +@Since("2.1, 2.5.3 (block break event), 2.7 (experience change event), INSERT VERSION (breeding event)") +@Events({"experience spawn", "break / mine", "experience change", "entity breeding"}) public class ExprExperience extends SimpleExpression { + static { Skript.registerExpression(ExprExperience.class, Experience.class, ExpressionType.SIMPLE, "[the] (spawned|dropped|) [e]xp[erience] [orb[s]]"); } - + @Override - public boolean init(final Expression[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { - if (!getParser().isCurrentEvent(ExperienceSpawnEvent.class, BlockBreakEvent.class, PlayerExpChangeEvent.class)) { - Skript.error("The experience expression can only be used in experience spawn, block break and player experience change events"); + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + if (!getParser().isCurrentEvent(ExperienceSpawnEvent.class, BlockBreakEvent.class, PlayerExpChangeEvent.class, EntityBreedEvent.class)) { + Skript.error("The experience expression can only be used in experience spawn, block break, player experience change and entity breeding events"); return false; } return true; @@ -68,51 +74,53 @@ public boolean init(final Expression[] exprs, final int matchedPattern, final @Override @Nullable - protected Experience[] get(final Event e) { - if (e instanceof ExperienceSpawnEvent) - return new Experience[] {new Experience(((ExperienceSpawnEvent) e).getSpawnedXP())}; - else if (e instanceof BlockBreakEvent) - return new Experience[] {new Experience(((BlockBreakEvent) e).getExpToDrop())}; - else if (e instanceof PlayerExpChangeEvent) - return new Experience[] {new Experience(((PlayerExpChangeEvent) e).getAmount())}; + protected Experience[] get(Event event) { + if (event instanceof ExperienceSpawnEvent) + return new Experience[] {new Experience(((ExperienceSpawnEvent) event).getSpawnedXP())}; + else if (event instanceof BlockBreakEvent) + return new Experience[] {new Experience(((BlockBreakEvent) event).getExpToDrop())}; + else if (event instanceof PlayerExpChangeEvent) + return new Experience[] {new Experience(((PlayerExpChangeEvent) event).getAmount())}; + else if (event instanceof EntityBreedEvent) + return new Experience[] {new Experience(((EntityBreedEvent) event).getExperience())}; else return new Experience[0]; } @Override @Nullable - public Class[] acceptChange(final ChangeMode mode) { + public Class[] acceptChange(ChangeMode mode) { switch (mode) { + case SET: case ADD: - case DELETE: case REMOVE: - case REMOVE_ALL: - return new Class[] {Experience[].class, Number[].class}; - case SET: - return new Class[] {Experience.class, Number.class}; + case DELETE: case RESET: - return null; + return new Class[] {Experience[].class, Integer[].class}; } return null; } @Override - public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) { - double eventExp; - if (e instanceof ExperienceSpawnEvent) { - eventExp = ((ExperienceSpawnEvent) e).getSpawnedXP(); - } else if (e instanceof BlockBreakEvent) { - eventExp = ((BlockBreakEvent) e).getExpToDrop(); - } else if (e instanceof PlayerExpChangeEvent) { - eventExp = ((PlayerExpChangeEvent) e).getAmount(); + public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { + int eventExp; + if (event instanceof ExperienceSpawnEvent) { + eventExp = ((ExperienceSpawnEvent) event).getSpawnedXP(); + } else if (event instanceof BlockBreakEvent) { + eventExp = ((BlockBreakEvent) event).getExpToDrop(); + } else if (event instanceof PlayerExpChangeEvent) { + eventExp = ((PlayerExpChangeEvent) event).getAmount(); + } else if (event instanceof EntityBreedEvent) { + eventExp = ((EntityBreedEvent) event).getExperience(); } else { return; } + if (delta == null) { eventExp = 0; } else { for (Object obj : delta) { - double value = obj instanceof Experience ? ((Experience) obj).getXP() : ((Number) obj).doubleValue(); + int value = obj instanceof Experience ? ((Experience) obj).getXP() : (Integer) obj; switch (mode) { case ADD: eventExp += value; @@ -121,26 +129,21 @@ public void change(final Event e, final @Nullable Object[] delta, final ChangeMo eventExp = value; break; case REMOVE: - case REMOVE_ALL: eventExp -= value; break; - case RESET: - case DELETE: - assert false; - break; } } } - - eventExp = Math.max(0, Math.round(eventExp)); - int roundedEventExp = (int) eventExp; - if (e instanceof ExperienceSpawnEvent) { - ((ExperienceSpawnEvent) e).setSpawnedXP(roundedEventExp); - } else if (e instanceof BlockBreakEvent) { - ((BlockBreakEvent) e).setExpToDrop(roundedEventExp); - } else if (e instanceof PlayerExpChangeEvent) { - ((PlayerExpChangeEvent) e).setAmount(roundedEventExp); + eventExp = Math.max(0, eventExp); + if (event instanceof ExperienceSpawnEvent) { + ((ExperienceSpawnEvent) event).setSpawnedXP(eventExp); + } else if (event instanceof BlockBreakEvent) { + ((BlockBreakEvent) event).setExpToDrop(eventExp); + } else if (event instanceof PlayerExpChangeEvent) { + ((PlayerExpChangeEvent) event).setAmount(eventExp); + } else if (event instanceof EntityBreedEvent) { + ((EntityBreedEvent) event).setExperience(eventExp); } } @@ -155,7 +158,7 @@ public Class getReturnType() { } @Override - public String toString(final @Nullable Event e, final boolean debug) { + public String toString(@Nullable Event event, boolean debug) { return "the experience"; } From 27e13925d4a6c1c95613ed392681492568e23344 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Fri, 7 Apr 2023 08:43:14 -0400 Subject: [PATCH 05/48] More Breeding Related Syntax :sparkles: Added condition for checking ageable :sparkles: Added condition for checking breedable :sparkles: Added effect for toggle breedable :sparkles: Added effect for locking age :sparkles: Added expression for love ticks --- .../ch/njol/skript/conditions/CondCanAge.java | 54 ++++++++++++ .../njol/skript/conditions/CondCanBreed.java | 55 ++++++++++++ .../njol/skript/conditions/CondIsInLove.java | 54 ++++++++++++ .../ch/njol/skript/effects/EffBreedable.java | 72 +++++++++++++++ .../ch/njol/skript/effects/EffLockAge.java | 72 +++++++++++++++ .../njol/skript/expressions/ExprLoveTime.java | 87 +++++++++++++++++++ 6 files changed, 394 insertions(+) create mode 100644 src/main/java/ch/njol/skript/conditions/CondCanAge.java create mode 100644 src/main/java/ch/njol/skript/conditions/CondCanBreed.java create mode 100644 src/main/java/ch/njol/skript/conditions/CondIsInLove.java create mode 100644 src/main/java/ch/njol/skript/effects/EffBreedable.java create mode 100644 src/main/java/ch/njol/skript/effects/EffLockAge.java create mode 100644 src/main/java/ch/njol/skript/expressions/ExprLoveTime.java diff --git a/src/main/java/ch/njol/skript/conditions/CondCanAge.java b/src/main/java/ch/njol/skript/conditions/CondCanAge.java new file mode 100644 index 00000000000..fb4dbb1bd35 --- /dev/null +++ b/src/main/java/ch/njol/skript/conditions/CondCanAge.java @@ -0,0 +1,54 @@ +/** + * 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.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 org.bukkit.entity.Breedable; +import org.bukkit.entity.LivingEntity; + +@Name("Can Age") +@Description("Tells whether or not an entity will be able to age/grow up") +@Examples({ + "on right click on living entity:", + "\tif entity can't age:", + "\t\tsend \"This entity is forever non aging\" to player" +}) +@Since("INSERT VERSION") +public class CondCanAge extends PropertyCondition { + + static { + register(CondCanAge.class, PropertyType.CAN, "age", "livingentities"); + } + + @Override + public boolean check(LivingEntity livingEntity) { + if (livingEntity instanceof Breedable) + return !((Breedable) livingEntity).getAgeLock(); + return false; + } + + @Override + protected String getPropertyName() { + return "age"; + } +} diff --git a/src/main/java/ch/njol/skript/conditions/CondCanBreed.java b/src/main/java/ch/njol/skript/conditions/CondCanBreed.java new file mode 100644 index 00000000000..2176a278eab --- /dev/null +++ b/src/main/java/ch/njol/skript/conditions/CondCanBreed.java @@ -0,0 +1,55 @@ +/** + * 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.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 org.bukkit.entity.Breedable; +import org.bukkit.entity.LivingEntity; + +@Name("Can Breed") +@Description("Checks whether or not a living entity is breedable.") +@Examples({ + "on right click on living entity with bucket:", + "\tif event-entity can't breed:", + "\t\tsend \"Turns out %event-entity% is not breedable, what a let down\" to player" +}) +@Since("INSERT VERSION") +public class CondCanBreed extends PropertyCondition { + + static { + register(CondCanBreed.class, PropertyType.CAN, "breed", "livingentities"); + } + + @Override + public boolean check(LivingEntity livingEntity) { + if (livingEntity instanceof Breedable) { + return ((Breedable) livingEntity).canBreed(); + } + return false; + } + + @Override + protected String getPropertyName() { + return "breed"; + } +} diff --git a/src/main/java/ch/njol/skript/conditions/CondIsInLove.java b/src/main/java/ch/njol/skript/conditions/CondIsInLove.java new file mode 100644 index 00000000000..aa50775a073 --- /dev/null +++ b/src/main/java/ch/njol/skript/conditions/CondIsInLove.java @@ -0,0 +1,54 @@ +/** + * 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.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 org.bukkit.entity.Animals; +import org.bukkit.entity.LivingEntity; + +@Name("In Love") +@Description("Whether or not an animal is currently in love") +@Examples({ + "on right click on living entity:", + "\tif event-entity is in love:", + "\t\tsend \"&c&oOhhh, he's in love <3\" to player" +}) +@Since("INSERT VERSION") +public class CondIsInLove extends PropertyCondition { + + static { + register(CondIsInLove.class, "in love", "livingentities"); + } + + @Override + public boolean check(LivingEntity livingEntity) { + if(livingEntity instanceof Animals) + return ((Animals) livingEntity).isLoveMode(); + return false; + } + + @Override + protected String getPropertyName() { + return "in love"; + } +} diff --git a/src/main/java/ch/njol/skript/effects/EffBreedable.java b/src/main/java/ch/njol/skript/effects/EffBreedable.java new file mode 100644 index 00000000000..ce28db00a34 --- /dev/null +++ b/src/main/java/ch/njol/skript/effects/EffBreedable.java @@ -0,0 +1,72 @@ +/** + * 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.ParseResult; +import ch.njol.util.Kleenean; +import org.bukkit.entity.Breedable; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.Event; +import org.eclipse.jdt.annotation.Nullable; + +@Name("Breedable") +@Description("Picks whether or not an entity will be able to breed.") +@Examples({ + "on spawn of animal:", + "\tmake entity unbreedable" +}) +@Since("INSERT VERSION") +public class EffBreedable extends Effect { + + static { + Skript.registerEffect(EffBreedable.class, + "make %living entities% [negate:(not |non(-| )|un)]breedable"); + } + + boolean canBreed; + Expression entities; + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + canBreed = !parseResult.hasTag("negate"); + return true; + } + + @Override + protected void execute(Event event) { + for (LivingEntity livingEntity : entities.getArray(event)) { + if (livingEntity instanceof Breedable) { + ((Breedable) livingEntity).setBreed(canBreed); + } + } + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "make " + entities.toString(event,debug) + (canBreed ? " " : " non-") + "breedable"; + } + +} diff --git a/src/main/java/ch/njol/skript/effects/EffLockAge.java b/src/main/java/ch/njol/skript/effects/EffLockAge.java new file mode 100644 index 00000000000..fd496b38e8e --- /dev/null +++ b/src/main/java/ch/njol/skript/effects/EffLockAge.java @@ -0,0 +1,72 @@ +/** + * 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.ParseResult; +import ch.njol.util.Kleenean; +import org.bukkit.entity.Breedable; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.Event; +import org.eclipse.jdt.annotation.Nullable; + +@Name("Lock Age") +@Description("Picks whether or not an entity will be able to age or mate.") +@Examples({ + "on spawn of animal:", + "\tlock age of entity" +}) +@Since("INSERT VERSION") +public class EffLockAge extends Effect { + + static { + Skript.registerEffect(EffLockAge.class, "(lock|:unlock) age of %living entities%"); + } + + Expression entities; + boolean unlock; + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + entities = (Expression) exprs[0]; + unlock = parseResult.hasTag("unlock"); + return true; + } + + @Override + protected void execute(Event event) { + for (LivingEntity livingEntity : entities.getArray(event)) { + if (livingEntity instanceof Breedable) { + ((Breedable) livingEntity).setAgeLock(!unlock); + } + } + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return (unlock ? "unlock" : "lock") + " age of " + entities.toString(event,debug); + } + +} diff --git a/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java b/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java new file mode 100644 index 00000000000..32375afba8c --- /dev/null +++ b/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java @@ -0,0 +1,87 @@ +/** + * 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.expressions; + +import ch.njol.skript.classes.Changer.ChangeMode; +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.expressions.base.SimplePropertyExpression; +import ch.njol.skript.util.Timespan; +import ch.njol.util.coll.CollectionUtils; +import org.bukkit.entity.Animals; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.Event; +import org.eclipse.jdt.annotation.Nullable; + +@Name("Love Time") +@Description({ + "The amount of time an living entity has been in love for. Setting to 30 seconds is equal to using breeding item", + "returns '0 seconds' if null or invalid entity"}) +@Examples({ + "on right click:", + "\tsend \"%event-enttiy% has been in love for %love time of event-entity%!\" to player" +}) +@Since("INSERT VERSION") +public class ExprLoveTime extends SimplePropertyExpression { + + static { + register(ExprLoveTime.class, Timespan.class, "love time", "livingentities"); + } + + @Override + @Nullable + public Timespan convert(LivingEntity livingEntity) { + int loveTicks = 0; + if (livingEntity instanceof Animals) + loveTicks = ((Animals) livingEntity).getLoveModeTicks(); + return Timespan.fromTicks_i(loveTicks); + } + + @Override + @Nullable + public Class[] acceptChange(ChangeMode mode) { + if (mode == ChangeMode.SET) + return CollectionUtils.array(Timespan.class); + return null; + } + + @Override + public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { + if (delta == null) + return; + long ticks = ((Timespan) delta[0]).getTicks_i(); + for (LivingEntity livingEntity : getExpr().getArray(event)) { + if (livingEntity instanceof Animals) + ((Animals) livingEntity).setLoveModeTicks((int) ticks); + } + } + + @Override + public Class getReturnType() { + return Timespan.class; + } + + @Override + protected String getPropertyName() { + return "love time"; + } + +} From 07ced16e4aa3a6a1cc2f73e5c18bdb99da3ec65d Mon Sep 17 00:00:00 2001 From: Fusezion Date: Fri, 7 Apr 2023 09:29:49 -0400 Subject: [PATCH 06/48] Pattern Fixes & Class Exist checks :bug: Fixed issue with `livingentities` :bug: Added class exist checks for Breedable instances :sparkles: Added RequirePlugins annotation to select classes --- src/main/java/ch/njol/skript/conditions/CondCanAge.java | 6 +++++- src/main/java/ch/njol/skript/conditions/CondCanBreed.java | 6 +++++- src/main/java/ch/njol/skript/effects/EffBreedable.java | 7 +++++-- src/main/java/ch/njol/skript/effects/EffLockAge.java | 5 ++++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondCanAge.java b/src/main/java/ch/njol/skript/conditions/CondCanAge.java index fb4dbb1bd35..bdf6442d0c7 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanAge.java +++ b/src/main/java/ch/njol/skript/conditions/CondCanAge.java @@ -18,10 +18,12 @@ */ package ch.njol.skript.conditions; +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.RequiredPlugins; import ch.njol.skript.doc.Since; import org.bukkit.entity.Breedable; import org.bukkit.entity.LivingEntity; @@ -34,10 +36,12 @@ "\t\tsend \"This entity is forever non aging\" to player" }) @Since("INSERT VERSION") +@RequiredPlugins("MC 1.16+") public class CondCanAge extends PropertyCondition { static { - register(CondCanAge.class, PropertyType.CAN, "age", "livingentities"); + if (Skript.classExists("org.bukkit.entity.Breedable")) + register(CondCanAge.class, PropertyType.CAN, "age", "livingentities"); } @Override diff --git a/src/main/java/ch/njol/skript/conditions/CondCanBreed.java b/src/main/java/ch/njol/skript/conditions/CondCanBreed.java index 2176a278eab..f429176e623 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanBreed.java +++ b/src/main/java/ch/njol/skript/conditions/CondCanBreed.java @@ -18,10 +18,12 @@ */ package ch.njol.skript.conditions; +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.RequiredPlugins; import ch.njol.skript.doc.Since; import org.bukkit.entity.Breedable; import org.bukkit.entity.LivingEntity; @@ -34,10 +36,12 @@ "\t\tsend \"Turns out %event-entity% is not breedable, what a let down\" to player" }) @Since("INSERT VERSION") +@RequiredPlugins("MC 1.16+") public class CondCanBreed extends PropertyCondition { static { - register(CondCanBreed.class, PropertyType.CAN, "breed", "livingentities"); + if (Skript.classExists("org.bukkit.entity.Breedable")) + register(CondCanBreed.class, PropertyType.CAN, "breed", "livingentities"); } @Override diff --git a/src/main/java/ch/njol/skript/effects/EffBreedable.java b/src/main/java/ch/njol/skript/effects/EffBreedable.java index ce28db00a34..f8f79a59756 100644 --- a/src/main/java/ch/njol/skript/effects/EffBreedable.java +++ b/src/main/java/ch/njol/skript/effects/EffBreedable.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; @@ -39,11 +40,12 @@ "\tmake entity unbreedable" }) @Since("INSERT VERSION") +@RequiredPlugins("MC 1.16+") public class EffBreedable extends Effect { static { - Skript.registerEffect(EffBreedable.class, - "make %living entities% [negate:(not |non(-| )|un)]breedable"); + if (Skript.classExists("org.bukkit.entity.Breedable")) + Skript.registerEffect(EffBreedable.class, "make %livingentities% [negate:(not |non(-| )|un)]breedable"); } boolean canBreed; @@ -52,6 +54,7 @@ public class EffBreedable extends Effect { @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { canBreed = !parseResult.hasTag("negate"); + entities = (Expression) exprs[0]; return true; } diff --git a/src/main/java/ch/njol/skript/effects/EffLockAge.java b/src/main/java/ch/njol/skript/effects/EffLockAge.java index fd496b38e8e..7e13806967f 100644 --- a/src/main/java/ch/njol/skript/effects/EffLockAge.java +++ b/src/main/java/ch/njol/skript/effects/EffLockAge.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; @@ -39,10 +40,12 @@ "\tlock age of entity" }) @Since("INSERT VERSION") +@RequiredPlugins("MC 1.16+") public class EffLockAge extends Effect { static { - Skript.registerEffect(EffLockAge.class, "(lock|:unlock) age of %living entities%"); + if (Skript.classExists("org.bukkit.entity.Breedable")) + Skript.registerEffect(EffLockAge.class, "(lock|:unlock) age of %livingentities%"); } Expression entities; From 6ab1dba43db05833112fabdeefd5459de7a26b61 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Fri, 7 Apr 2023 10:22:46 -0400 Subject: [PATCH 07/48] Test, Test, Test :clipboard: Added test for ExprLoveTime & CondIsInLove :clipboard: Addes test for EffBreedable & CondCanBreed :clipboard: Added test fpr EffLockAge & CondCanAge --- .../tests/syntaxes/conditions/CondIsInLove.sk | 20 +++++++++++++++++++ .../tests/syntaxes/effects/EffBreedable.sk | 11 ++++++++++ .../tests/syntaxes/effects/EffLockAge.sk | 11 ++++++++++ 3 files changed, 42 insertions(+) create mode 100644 src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk create mode 100644 src/test/skript/tests/syntaxes/effects/EffBreedable.sk create mode 100644 src/test/skript/tests/syntaxes/effects/EffLockAge.sk diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk b/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk new file mode 100644 index 00000000000..4f7870a42cd --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk @@ -0,0 +1,20 @@ +test "in love valid entity" when running minecraft "1.16.5": + delete all cows + set {_spawn} to spawn of world "world" + spawn adult cow at {_spawn} + set {_cow} to last spawned cow + assert love time of {_cow} is 0 seconds with "Cow love time was not 0 seconds after spawning" + assert {_cow} is not in love with "Cow is in love after spawning" + set love time of {_cow} to 10 seconds + assert {_cow} is in love with "Cow is not in love after setting love time" + delete all cows + +test "in love invalid entity" when running minecraft "1.16.5": + delete all zombies + set {_spawn} to spawn of world "world" + spawn adult zombie at {_spawn} + set {_zombie} to last spawned zombie + assert love time of {_zombie} is 0 seconds with "Zombie was in love Test1" + set love time of {_zombie} to 10 minutes + assert love time of {_zombie} is 0 seconds with "Zombie was in love Test2" + delete all zombies diff --git a/src/test/skript/tests/syntaxes/effects/EffBreedable.sk b/src/test/skript/tests/syntaxes/effects/EffBreedable.sk new file mode 100644 index 00000000000..f1cdb22121b --- /dev/null +++ b/src/test/skript/tests/syntaxes/effects/EffBreedable.sk @@ -0,0 +1,11 @@ +test "breedable" when running minecraft "1.16.5": + delete all chickens + set {_spawn} to spawn of world "world" + spawn baby chicken at {_spawn} + set {_chicken} to last spawned chicken + assert {_chicken} can't breed with "Chicken could breed before growing up" + make {_chicken} breedable + assert {_chicken} can breed with "Chicken can't breed after growing up" + make {_chicken} non-breedable + assert {_chicken} can't breed with "Chicken can breed after growing up and preventing" + delete all chickens diff --git a/src/test/skript/tests/syntaxes/effects/EffLockAge.sk b/src/test/skript/tests/syntaxes/effects/EffLockAge.sk new file mode 100644 index 00000000000..3373cfa78b2 --- /dev/null +++ b/src/test/skript/tests/syntaxes/effects/EffLockAge.sk @@ -0,0 +1,11 @@ +test "locking age" when running minecraft "1.16.5": + delete all pigs + set {_spawn} to spawn of world "world" + spawn baby pig at {_spawn} + set {_pig} to last spawned pig + assert {_pig} can age with "Baby pig can't age before locking Test1" + lock age of {_pig} + assert {_pig} can't age with "Baby pig can still age after locking" + unlock age of {_pig} + assert {_pig} can age with "Baby pig can't age after unlocking Test2" + delete all pigs From c6acbe9d2aea5525e5fdea79145374677596683b Mon Sep 17 00:00:00 2001 From: Fusezion Date: Fri, 7 Apr 2023 10:58:46 -0400 Subject: [PATCH 08/48] :purple_heart: Formatting --- src/main/java/ch/njol/skript/conditions/CondCanAge.java | 1 + src/main/java/ch/njol/skript/conditions/CondCanBreed.java | 1 + src/main/java/ch/njol/skript/conditions/CondIsInLove.java | 1 + src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java | 1 + 4 files changed, 4 insertions(+) diff --git a/src/main/java/ch/njol/skript/conditions/CondCanAge.java b/src/main/java/ch/njol/skript/conditions/CondCanAge.java index bdf6442d0c7..490b5761d58 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanAge.java +++ b/src/main/java/ch/njol/skript/conditions/CondCanAge.java @@ -55,4 +55,5 @@ public boolean check(LivingEntity livingEntity) { protected String getPropertyName() { return "age"; } + } diff --git a/src/main/java/ch/njol/skript/conditions/CondCanBreed.java b/src/main/java/ch/njol/skript/conditions/CondCanBreed.java index f429176e623..142cdc3780b 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanBreed.java +++ b/src/main/java/ch/njol/skript/conditions/CondCanBreed.java @@ -56,4 +56,5 @@ public boolean check(LivingEntity livingEntity) { protected String getPropertyName() { return "breed"; } + } diff --git a/src/main/java/ch/njol/skript/conditions/CondIsInLove.java b/src/main/java/ch/njol/skript/conditions/CondIsInLove.java index aa50775a073..86529fab466 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsInLove.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsInLove.java @@ -51,4 +51,5 @@ public boolean check(LivingEntity livingEntity) { protected String getPropertyName() { return "in love"; } + } diff --git a/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java b/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java index c49585cdc96..871592b99b0 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java +++ b/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java @@ -93,4 +93,5 @@ public Class getReturnType() { public String toString(@Nullable Event event, boolean debug) { return "breeding family"; } + } From 243d402cd0937b144ebfb6f2aae3f384bcdf0a64 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Fri, 7 Apr 2023 12:28:39 -0400 Subject: [PATCH 09/48] Added Adult Syntax :sparkles: Added Condition for checking is adult :sparkles: Added Effect to make an entity a baby or adult :clipboard: Added test for these syntaxes :large_blue_circle: 1.16 for any mob, below that is animals only --- .../njol/skript/conditions/CondIsAdult.java | 61 ++++++++++++++ .../ch/njol/skript/effects/EffMakeAdult.java | 84 +++++++++++++++++++ .../tests/syntaxes/effects/EffMakeAdult.sk | 23 +++++ 3 files changed, 168 insertions(+) create mode 100644 src/main/java/ch/njol/skript/conditions/CondIsAdult.java create mode 100644 src/main/java/ch/njol/skript/effects/EffMakeAdult.java create mode 100644 src/test/skript/tests/syntaxes/effects/EffMakeAdult.sk diff --git a/src/main/java/ch/njol/skript/conditions/CondIsAdult.java b/src/main/java/ch/njol/skript/conditions/CondIsAdult.java new file mode 100644 index 00000000000..deaa2c99ffa --- /dev/null +++ b/src/main/java/ch/njol/skript/conditions/CondIsAdult.java @@ -0,0 +1,61 @@ +/** + * 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 ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.Since; +import org.bukkit.entity.Ageable; +import org.bukkit.entity.Animals; +import org.bukkit.entity.LivingEntity; + +@Name("Is An Adult") +@Description("Tells whether or not a living entity is an adult.") +@Examples({ + "on spawn:", + "\tif event-entity is not an adult:", + "\t\tmake event-entity an adult" +}) +@Since("INSERT VERSION") +public class CondIsAdult extends PropertyCondition { + + + static boolean HAS_MOB_SUPPORT = Skript.isRunningMinecraft(1,16,5); + + static { + register(CondIsAdult.class, "[an] adult", "livingentities"); + } + + @Override + public boolean check(LivingEntity livingEntity) { + if (livingEntity instanceof Ageable) + if (HAS_MOB_SUPPORT || livingEntity instanceof Animals) + return ((Ageable) livingEntity).isAdult(); + return false; + } + + @Override + protected String getPropertyName() { + return "an adult"; + } + +} diff --git a/src/main/java/ch/njol/skript/effects/EffMakeAdult.java b/src/main/java/ch/njol/skript/effects/EffMakeAdult.java new file mode 100644 index 00000000000..3163c2064d0 --- /dev/null +++ b/src/main/java/ch/njol/skript/effects/EffMakeAdult.java @@ -0,0 +1,84 @@ +/** + * 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.RequiredPlugins; +import ch.njol.skript.doc.Since; +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; +import org.bukkit.entity.Ageable; +import org.bukkit.entity.Animals; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.Event; +import org.eclipse.jdt.annotation.Nullable; + +@Name("Make Adult") +@Description("Force an entity to become an adult or a baby, requires MC 1.16 for any mob") +@Examples({ + "on spawn of mob:", + "\tif entity is not an adult:", + "\t\tmake entity an adult", +}) +@Since("INSERT VERSION") +@RequiredPlugins("1.13+ for animal, 1.16+ for mobs") +public class EffMakeAdult extends Effect { + + + static boolean HAS_MOB_SUPPORT = Skript.isRunningMinecraft(1,16,5); + + static { + Skript.registerEffect(EffMakeAdult.class, "make %livingentities% [a[n]] (adult|:baby)"); + } + + boolean makeBaby; + Expression entities; + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + entities = (Expression) exprs[0]; + makeBaby = parseResult.hasTag("baby"); + return true; + } + + @Override + protected void execute(Event event) { + for (LivingEntity livingEntity : entities.getArray(event)) { + if (livingEntity instanceof Ageable) + if (!HAS_MOB_SUPPORT && !(livingEntity instanceof Animals)) + continue; + if (makeBaby) { + ((Ageable) livingEntity).setBaby(); + } else { + ((Ageable) livingEntity).setAdult(); + } + } + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "make " + entities + (makeBaby ? " a baby" : " an adult"); + } + +} diff --git a/src/test/skript/tests/syntaxes/effects/EffMakeAdult.sk b/src/test/skript/tests/syntaxes/effects/EffMakeAdult.sk new file mode 100644 index 00000000000..2f9bce0093c --- /dev/null +++ b/src/test/skript/tests/syntaxes/effects/EffMakeAdult.sk @@ -0,0 +1,23 @@ +test "effect make adult 1" when running minecraft "1.16.5": + delete all zombies + set {_spawn} to spawn of world "world" + spawn baby zombie at {_spawn} + set {_zombie} to last spawned zombie + assert {_zombie} is not an adult with "Spawned zombie was an adult" + make {_zombie} an adult + assert {_zombie} is an adult with "Spawned zombie is still a baby zombie" + make {_zombie} a baby + assert {_zombie} is not an adult with "Spawned zombie didn't become a baby zombie" + delete all zombies + +test "effect make adult 2": + delete all sheep + set {_spawn} to spawn of world "world" + spawn baby sheep at {_spawn} + set {_sheep} to last spawned sheep + assert {_sheep} is not an adult with "Spawned sheep was an adult" + make {_sheep} an adult + assert {_sheep} is an adult with "Spawned sheep is still a baby sheep" + make {_sheep} a baby + assert {_sheep} is not an adult with "Spawned sheep didn't become a baby sheep" + delete all sheep From 8bcbffb5ca7b78ff874bd127a1f65914084ef3ce Mon Sep 17 00:00:00 2001 From: Fusezion Date: Fri, 7 Apr 2023 19:38:40 -0400 Subject: [PATCH 10/48] Apply suggestions from code review Thanks for all these formatting changes it's just what I wanted when waking up Co-authored-by: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com> --- .../njol/skript/classes/data/BukkitEventValues.java | 5 +---- .../java/ch/njol/skript/conditions/CondCanAge.java | 2 +- .../java/ch/njol/skript/conditions/CondCanBreed.java | 2 +- .../java/ch/njol/skript/conditions/CondIsAdult.java | 3 +-- .../java/ch/njol/skript/conditions/CondIsInLove.java | 4 ++-- .../java/ch/njol/skript/effects/EffBreedable.java | 8 ++++---- src/main/java/ch/njol/skript/effects/EffLockAge.java | 4 ++-- .../java/ch/njol/skript/effects/EffMakeAdult.java | 12 ++++++------ .../java/ch/njol/skript/events/SimpleEvents.java | 2 +- .../njol/skript/expressions/ExprBreedingFamily.java | 3 ++- .../ch/njol/skript/expressions/ExprLoveTime.java | 3 ++- 11 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java index 95d4a576b01..6e8378c3c7b 100644 --- a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java +++ b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java @@ -1564,7 +1564,7 @@ public Location get(LootGenerateEvent event) { } }, EventValues.TIME_NOW); } - + // EntityBreedEvent EventValues.registerEventValue(EntityBreedEvent.class, ItemStack.class, new Getter() { @Override @Nullable @@ -1574,7 +1574,6 @@ public ItemStack get(EntityBreedEvent event) { }, EventValues.TIME_NOW); if (Skript.classExists("org.bukkit.event.entity.EntityEnterLoveModeEvent")) { - EventValues.registerEventValue(EntityEnterLoveModeEvent.class, LivingEntity.class, new Getter() { @Override @Nullable @@ -1582,7 +1581,6 @@ public LivingEntity get(EntityEnterLoveModeEvent event) { return event.getEntity(); } }, EventValues.TIME_NOW); - EventValues.registerEventValue(EntityEnterLoveModeEvent.class, HumanEntity.class, new Getter() { @Override @Nullable @@ -1590,7 +1588,6 @@ public HumanEntity get(EntityEnterLoveModeEvent event) { return event.getHumanEntity(); } }, EventValues.TIME_NOW); - } } diff --git a/src/main/java/ch/njol/skript/conditions/CondCanAge.java b/src/main/java/ch/njol/skript/conditions/CondCanAge.java index 490b5761d58..4e1e2b50183 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanAge.java +++ b/src/main/java/ch/njol/skript/conditions/CondCanAge.java @@ -29,7 +29,7 @@ import org.bukkit.entity.LivingEntity; @Name("Can Age") -@Description("Tells whether or not an entity will be able to age/grow up") +@Description("Returns whether or not an entity will be able to age/grow up") @Examples({ "on right click on living entity:", "\tif entity can't age:", diff --git a/src/main/java/ch/njol/skript/conditions/CondCanBreed.java b/src/main/java/ch/njol/skript/conditions/CondCanBreed.java index 142cdc3780b..44bba127e95 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanBreed.java +++ b/src/main/java/ch/njol/skript/conditions/CondCanBreed.java @@ -29,7 +29,7 @@ import org.bukkit.entity.LivingEntity; @Name("Can Breed") -@Description("Checks whether or not a living entity is breedable.") +@Description("Returns whether or not a living entity is breedable.") @Examples({ "on right click on living entity with bucket:", "\tif event-entity can't breed:", diff --git a/src/main/java/ch/njol/skript/conditions/CondIsAdult.java b/src/main/java/ch/njol/skript/conditions/CondIsAdult.java index deaa2c99ffa..fff290f1648 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsAdult.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsAdult.java @@ -29,7 +29,7 @@ import org.bukkit.entity.LivingEntity; @Name("Is An Adult") -@Description("Tells whether or not a living entity is an adult.") +@Description("Returns whether or not a living entity is an adult.") @Examples({ "on spawn:", "\tif event-entity is not an adult:", @@ -38,7 +38,6 @@ @Since("INSERT VERSION") public class CondIsAdult extends PropertyCondition { - static boolean HAS_MOB_SUPPORT = Skript.isRunningMinecraft(1,16,5); static { diff --git a/src/main/java/ch/njol/skript/conditions/CondIsInLove.java b/src/main/java/ch/njol/skript/conditions/CondIsInLove.java index 86529fab466..43defd35b40 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsInLove.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsInLove.java @@ -26,7 +26,7 @@ import org.bukkit.entity.Animals; import org.bukkit.entity.LivingEntity; -@Name("In Love") +@Name("Entity In Love") @Description("Whether or not an animal is currently in love") @Examples({ "on right click on living entity:", @@ -42,7 +42,7 @@ public class CondIsInLove extends PropertyCondition { @Override public boolean check(LivingEntity livingEntity) { - if(livingEntity instanceof Animals) + if (livingEntity instanceof Animals) return ((Animals) livingEntity).isLoveMode(); return false; } diff --git a/src/main/java/ch/njol/skript/effects/EffBreedable.java b/src/main/java/ch/njol/skript/effects/EffBreedable.java index f8f79a59756..c22d85ad36e 100644 --- a/src/main/java/ch/njol/skript/effects/EffBreedable.java +++ b/src/main/java/ch/njol/skript/effects/EffBreedable.java @@ -33,7 +33,7 @@ import org.bukkit.event.Event; import org.eclipse.jdt.annotation.Nullable; -@Name("Breedable") +@Name("Make Breedable") @Description("Picks whether or not an entity will be able to breed.") @Examples({ "on spawn of animal:", @@ -48,8 +48,8 @@ public class EffBreedable extends Effect { Skript.registerEffect(EffBreedable.class, "make %livingentities% [negate:(not |non(-| )|un)]breedable"); } - boolean canBreed; - Expression entities; + private boolean canBreed; + private Expression entities; @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { @@ -69,7 +69,7 @@ protected void execute(Event event) { @Override public String toString(@Nullable Event event, boolean debug) { - return "make " + entities.toString(event,debug) + (canBreed ? " " : " non-") + "breedable"; + return "make " + entities.toString(event, debug) + (canBreed ? " " : " non-") + "breedable"; } } diff --git a/src/main/java/ch/njol/skript/effects/EffLockAge.java b/src/main/java/ch/njol/skript/effects/EffLockAge.java index 7e13806967f..10acbdd6314 100644 --- a/src/main/java/ch/njol/skript/effects/EffLockAge.java +++ b/src/main/java/ch/njol/skript/effects/EffLockAge.java @@ -48,8 +48,8 @@ public class EffLockAge extends Effect { Skript.registerEffect(EffLockAge.class, "(lock|:unlock) age of %livingentities%"); } - Expression entities; - boolean unlock; + private Expression entities; + private boolean unlock; @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { diff --git a/src/main/java/ch/njol/skript/effects/EffMakeAdult.java b/src/main/java/ch/njol/skript/effects/EffMakeAdult.java index 3163c2064d0..89922993816 100644 --- a/src/main/java/ch/njol/skript/effects/EffMakeAdult.java +++ b/src/main/java/ch/njol/skript/effects/EffMakeAdult.java @@ -42,18 +42,17 @@ "\t\tmake entity an adult", }) @Since("INSERT VERSION") -@RequiredPlugins("1.13+ for animal, 1.16+ for mobs") +@RequiredPlugins("1.16+ (Mobs)") public class EffMakeAdult extends Effect { - - static boolean HAS_MOB_SUPPORT = Skript.isRunningMinecraft(1,16,5); + private final static boolean HAS_MOB_SUPPORT = Skript.isRunningMinecraft(1,16,5); static { Skript.registerEffect(EffMakeAdult.class, "make %livingentities% [a[n]] (adult|:baby)"); } - boolean makeBaby; - Expression entities; + private boolean makeBaby; + private Expression entities; @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { @@ -65,7 +64,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override protected void execute(Event event) { for (LivingEntity livingEntity : entities.getArray(event)) { - if (livingEntity instanceof Ageable) + if (livingEntity instanceof Ageable) { if (!HAS_MOB_SUPPORT && !(livingEntity instanceof Animals)) continue; if (makeBaby) { @@ -73,6 +72,7 @@ protected void execute(Event event) { } else { ((Ageable) livingEntity).setAdult(); } + } } } diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index c8583f7eb8e..a86b9b59481 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -711,7 +711,7 @@ public class SimpleEvents { .requiredPlugins("Paper 1.16+"); } Skript.registerEvent("Entity Breed", SimpleEvent.class, EntityBreedEvent.class, "[entity] breed[ing]") - .description("Called whenever 2 breedable entities begin to conceive a child.") + .description("Called whenever two breedable entities begin to conceive a child.") .examples( "on breeding:", "\tsend \"When a %mother% and %father% love each other they make %offspring%\" to breeder" diff --git a/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java b/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java index 871592b99b0..043dfb01240 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java +++ b/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java @@ -55,7 +55,7 @@ public class ExprBreedingFamily extends SimpleExpression { @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { if (!getParser().isCurrentEvent(EntityBreedEvent.class)) { - Skript.error("This expression can only be used within a Entity Breed event."); + Skript.error("'breeding family' expression can only be used within an Entity Breed event."); return false; } pattern = matchedPattern; @@ -66,6 +66,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye protected @Nullable LivingEntity[] get(Event event) { if (!(event instanceof EntityBreedEvent)) return new LivingEntity[0]; + EntityBreedEvent breedEvent = (EntityBreedEvent) event; if (pattern == 0) { return new LivingEntity[]{breedEvent.getMother()}; diff --git a/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java b/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java index 32375afba8c..957f6e7ac20 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java +++ b/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java @@ -34,7 +34,8 @@ @Name("Love Time") @Description({ "The amount of time an living entity has been in love for. Setting to 30 seconds is equal to using breeding item", - "returns '0 seconds' if null or invalid entity"}) + "Returns '0 seconds' if null or invalid entity" +}) @Examples({ "on right click:", "\tsend \"%event-enttiy% has been in love for %love time of event-entity%!\" to player" From 50748f5a4e7bfb4f736070a0b920e5085611b0af Mon Sep 17 00:00:00 2001 From: Fusezion Date: Fri, 7 Apr 2023 21:45:20 -0400 Subject: [PATCH 11/48] ExprLoveTime -> ExprLoveTicks :sparkles: Renamed expression to ExprLoveTicks :sparkles: Added support for ticks via integers :clipboard: Added a new test for using integers :clipboard: Removed unneeded test condition --- .../{ExprLoveTime.java => ExprLoveTicks.java} | 53 +++++++++++++++---- .../tests/syntaxes/conditions/CondIsInLove.sk | 34 ++++++++---- 2 files changed, 67 insertions(+), 20 deletions(-) rename src/main/java/ch/njol/skript/expressions/{ExprLoveTime.java => ExprLoveTicks.java} (62%) diff --git a/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java b/src/main/java/ch/njol/skript/expressions/ExprLoveTicks.java similarity index 62% rename from src/main/java/ch/njol/skript/expressions/ExprLoveTime.java rename to src/main/java/ch/njol/skript/expressions/ExprLoveTicks.java index 957f6e7ac20..4ffc8bb528c 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java +++ b/src/main/java/ch/njol/skript/expressions/ExprLoveTicks.java @@ -31,20 +31,20 @@ import org.bukkit.event.Event; import org.eclipse.jdt.annotation.Nullable; -@Name("Love Time") +@Name("Love Ticks") @Description({ "The amount of time an living entity has been in love for. Setting to 30 seconds is equal to using breeding item", "Returns '0 seconds' if null or invalid entity" }) @Examples({ "on right click:", - "\tsend \"%event-enttiy% has been in love for %love time of event-entity%!\" to player" + "\tsend \"%event-enttiy% has been in love for %love ticks of event-entity%!\" to player" }) @Since("INSERT VERSION") -public class ExprLoveTime extends SimplePropertyExpression { +public class ExprLoveTicks extends SimplePropertyExpression { static { - register(ExprLoveTime.class, Timespan.class, "love time", "livingentities"); + register(ExprLoveTicks.class, Timespan.class, "love ticks", "livingentities"); } @Override @@ -59,19 +59,50 @@ public Timespan convert(LivingEntity livingEntity) { @Override @Nullable public Class[] acceptChange(ChangeMode mode) { - if (mode == ChangeMode.SET) - return CollectionUtils.array(Timespan.class); + switch (mode) { + case SET: + case RESET: + return CollectionUtils.array(Integer.class, Timespan.class); + case ADD: + case REMOVE: + return CollectionUtils.array(Integer[].class, Timespan[].class); + } return null; } @Override public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { - if (delta == null) - return; - long ticks = ((Timespan) delta[0]).getTicks_i(); + int ticks = 0; + if (delta != null) { + for (Object obj : delta) { + switch (mode) { + case ADD: + ticks += obj instanceof Timespan ? (int) ((Timespan) obj).getTicks_i() : (int) obj; + break; + case REMOVE: + ticks -= obj instanceof Timespan ? (int) ((Timespan) obj).getTicks_i() : (int) obj; + break; + case SET: + ticks = obj instanceof Timespan ? (int) ((Timespan) obj).getTicks_i() : (int) obj; + break; + } + } + } + ticks = Math.max(ticks, 0); for (LivingEntity livingEntity : getExpr().getArray(event)) { - if (livingEntity instanceof Animals) - ((Animals) livingEntity).setLoveModeTicks((int) ticks); + if (livingEntity instanceof Animals) { + Animals animal = ((Animals) livingEntity); + switch (mode) { + case REMOVE: + case ADD: + animal.setLoveModeTicks(animal.getLoveModeTicks() + ticks); + break; + case SET: + case RESET: + animal.setLoveModeTicks(ticks); + break; + } + } } } diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk b/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk index 4f7870a42cd..27d2ee6751a 100644 --- a/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk +++ b/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk @@ -1,20 +1,36 @@ -test "in love valid entity" when running minecraft "1.16.5": +test "in love valid entity (timespan)": delete all cows set {_spawn} to spawn of world "world" spawn adult cow at {_spawn} set {_cow} to last spawned cow - assert love time of {_cow} is 0 seconds with "Cow love time was not 0 seconds after spawning" + assert love ticks of {_cow} is 0 seconds with "Cow love ticks was not 0 seconds after spawning" assert {_cow} is not in love with "Cow is in love after spawning" - set love time of {_cow} to 10 seconds - assert {_cow} is in love with "Cow is not in love after setting love time" + set love ticks of {_cow} to 10 seconds + assert {_cow} is in love with "Cow is not in love after setting love ticks" delete all cows -test "in love invalid entity" when running minecraft "1.16.5": +test "in love valid entity (ticks)": + delete all cows + set {_spawn} to spawn of world "world" + spawn adult cow at {_spawn} + set {_cow} to last spawned cow + assert love ticks of {_cow} is 0 seconds with "Cow love ticks was not 0 seconds after spawning" + assert {_cow} is not in love with "Cow is in love after spawning" + set love ticks of {_cow} to 15000 + assert {_cow} is in love with "Cow is not in love after setting love ticks" + assert love ticks of {_cow} > 10 minutes with "Cow love ticks were below 10 minutes, tick conversion failed" + reset love ticks of {_cow} + assert {_cow} is not in love with "Cow was still in love after resetting ticks" + add 10 seconds and 300 to love ticks of {_cow} + assert {_cow} is in love with "Cow wasn't in love adding using add changer" + delete all cows + +test "in love invalid entity": delete all zombies set {_spawn} to spawn of world "world" spawn adult zombie at {_spawn} set {_zombie} to last spawned zombie - assert love time of {_zombie} is 0 seconds with "Zombie was in love Test1" - set love time of {_zombie} to 10 minutes - assert love time of {_zombie} is 0 seconds with "Zombie was in love Test2" - delete all zombies + assert love ticks of {_zombie} is 0 seconds with "Zombie was in love Test1" + set love ticks of {_zombie} to 10 minutes + assert love ticks of {_zombie} is 0 seconds with "Zombie was in love Test2" + delete all zombies \ No newline at end of file From 93059ae411a908f0ecfee5192a30a798c29424a8 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Fri, 7 Apr 2023 21:46:41 -0400 Subject: [PATCH 12/48] Update ExprBreedingFamily.java :sparkles: Changed expression for father, mother and offspring a bit :sparkles: Converted get to a switch statement --- .../expressions/ExprBreedingFamily.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java b/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java index 043dfb01240..7d7a7f3b9cc 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java +++ b/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java @@ -37,16 +37,16 @@ @Description("Represents a family within a breeding event") @Examples({ "on breeding:", - "\tsend \"When a %mother% and %father% love each other they make a %offspring%\" to breeder" + "\tsend \"When a %breeding mother% and %breeding father% love each other they make a %bred offspring%\" to breeder" }) @Since("INSERT VERSION") public class ExprBreedingFamily extends SimpleExpression { static { Skript.registerExpression(ExprBreedingFamily.class, LivingEntity.class, ExpressionType.SIMPLE, - "[breed[ing]] mother", - "[breed[ing]] father", - "[breed[ing]] (offspring|child)", + "breed[ing] mother", + "breed[ing] father", + "[bred] (offspring|child)", "breeder"); } @@ -68,16 +68,18 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye return new LivingEntity[0]; EntityBreedEvent breedEvent = (EntityBreedEvent) event; - if (pattern == 0) { - return new LivingEntity[]{breedEvent.getMother()}; - } else if (pattern == 1) { - return new LivingEntity[]{breedEvent.getFather()}; - } else if (pattern == 2) { - return new LivingEntity[]{breedEvent.getEntity()}; - } else if (pattern == 3) { - return new LivingEntity[]{breedEvent.getBreeder()}; + switch (pattern) { + case 0: + return new LivingEntity[]{breedEvent.getMother()}; + case 1: + return new LivingEntity[]{breedEvent.getFather()}; + case 2: + return new LivingEntity[]{breedEvent.getEntity()}; + case 3: + return new LivingEntity[]{breedEvent.getBreeder()}; + default: + return new LivingEntity[0]; } - return new LivingEntity[0]; } @Override From 912a300bcb91582f62cfabb9db96e969f880b9cc Mon Sep 17 00:00:00 2001 From: Fusezion Date: Fri, 7 Apr 2023 21:48:20 -0400 Subject: [PATCH 13/48] Update ExprExperience.java :bug: Fixed an issue where set allowed more than one value :bug: Fixed a typo in examples :sparkles: Added a spacer to examples --- .../njol/skript/expressions/ExprExperience.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprExperience.java b/src/main/java/ch/njol/skript/expressions/ExprExperience.java index 5548fa36f4c..03416e0546f 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExperience.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExperience.java @@ -18,6 +18,7 @@ */ package ch.njol.skript.expressions; +import ch.njol.util.coll.CollectionUtils; import org.bukkit.event.Event; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.entity.EntityBreedEvent; @@ -44,15 +45,19 @@ */ @Name("Experience") @Description("How much experience was spawned in an experience spawn or block break event. Can be changed.") -@Examples({"on experience spawn:", +@Examples({ + "on experience spawn:", "\tadd 5 to the spawned experience", + "", "on break of coal ore:", "\tclear dropped experience", + "", "on break of diamond ore:", "\tif tool of player = diamond pickaxe:", "\t\tadd 100 to dropped experience", + "", "on breed:", - "\tevent-father is a cow", + "\tbreeding father is a cow", "\tset dropped experience to 10" }) @Since("2.1, 2.5.3 (block break event), 2.7 (experience change event), INSERT VERSION (breeding event)") @@ -92,11 +97,12 @@ else if (event instanceof EntityBreedEvent) public Class[] acceptChange(ChangeMode mode) { switch (mode) { case SET: - case ADD: - case REMOVE: case DELETE: case RESET: - return new Class[] {Experience[].class, Integer[].class}; + return CollectionUtils.array(ExprExperience.class, Integer.class); + case ADD: + case REMOVE: + return CollectionUtils.array(ExprExperience[].class, Integer[].class); } return null; } From 09d1999fa8270f2c7f918b6330f7bbc0733d0297 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Fri, 7 Apr 2023 21:50:46 -0400 Subject: [PATCH 14/48] Added comment to CondIsAdult and EffMakeAdult Co-Authored-By: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com> --- src/main/java/ch/njol/skript/conditions/CondIsAdult.java | 1 + src/main/java/ch/njol/skript/effects/EffMakeAdult.java | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsAdult.java b/src/main/java/ch/njol/skript/conditions/CondIsAdult.java index fff290f1648..2e3e8ee2110 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsAdult.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsAdult.java @@ -38,6 +38,7 @@ @Since("INSERT VERSION") public class CondIsAdult extends PropertyCondition { + // This is required since before 1.16 the `isAdult` method only supported Animals static boolean HAS_MOB_SUPPORT = Skript.isRunningMinecraft(1,16,5); static { diff --git a/src/main/java/ch/njol/skript/effects/EffMakeAdult.java b/src/main/java/ch/njol/skript/effects/EffMakeAdult.java index 89922993816..075581046ef 100644 --- a/src/main/java/ch/njol/skript/effects/EffMakeAdult.java +++ b/src/main/java/ch/njol/skript/effects/EffMakeAdult.java @@ -45,6 +45,8 @@ @RequiredPlugins("1.16+ (Mobs)") public class EffMakeAdult extends Effect { + + // This is required since before 1.16 the `setBaby`/'setAdult' method only supported Animals private final static boolean HAS_MOB_SUPPORT = Skript.isRunningMinecraft(1,16,5); static { From 34d5453099271a45d124069583e99d53b1cb6231 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Sat, 8 Apr 2023 07:29:43 -0400 Subject: [PATCH 15/48] Syntax description notes Just adds some notes in descriptions to bring more light to animal exclusive syntax Co-Authored-By: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com> --- src/main/java/ch/njol/skript/conditions/CondIsAdult.java | 2 +- src/main/java/ch/njol/skript/conditions/CondIsInLove.java | 2 +- src/main/java/ch/njol/skript/effects/EffBreedable.java | 5 ++++- src/main/java/ch/njol/skript/effects/EffMakeAdult.java | 2 +- src/main/java/ch/njol/skript/expressions/ExprLoveTicks.java | 3 ++- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsAdult.java b/src/main/java/ch/njol/skript/conditions/CondIsAdult.java index 2e3e8ee2110..2cf284fb955 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsAdult.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsAdult.java @@ -29,7 +29,7 @@ import org.bukkit.entity.LivingEntity; @Name("Is An Adult") -@Description("Returns whether or not a living entity is an adult.") +@Description("Returns whether or not an animal is an adult, requires 1.16.5 for mobs") @Examples({ "on spawn:", "\tif event-entity is not an adult:", diff --git a/src/main/java/ch/njol/skript/conditions/CondIsInLove.java b/src/main/java/ch/njol/skript/conditions/CondIsInLove.java index 43defd35b40..c06c8edd8a3 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsInLove.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsInLove.java @@ -27,7 +27,7 @@ import org.bukkit.entity.LivingEntity; @Name("Entity In Love") -@Description("Whether or not an animal is currently in love") +@Description("Whether or not an animal is currently in a love state") @Examples({ "on right click on living entity:", "\tif event-entity is in love:", diff --git a/src/main/java/ch/njol/skript/effects/EffBreedable.java b/src/main/java/ch/njol/skript/effects/EffBreedable.java index c22d85ad36e..5e1836b0d99 100644 --- a/src/main/java/ch/njol/skript/effects/EffBreedable.java +++ b/src/main/java/ch/njol/skript/effects/EffBreedable.java @@ -34,7 +34,10 @@ import org.eclipse.jdt.annotation.Nullable; @Name("Make Breedable") -@Description("Picks whether or not an entity will be able to breed.") +@Description({ + "Picks whether or not an entity will be able to breed.", + "Doesn't work on all entities only animals" +}) @Examples({ "on spawn of animal:", "\tmake entity unbreedable" diff --git a/src/main/java/ch/njol/skript/effects/EffMakeAdult.java b/src/main/java/ch/njol/skript/effects/EffMakeAdult.java index 075581046ef..7d68069adaa 100644 --- a/src/main/java/ch/njol/skript/effects/EffMakeAdult.java +++ b/src/main/java/ch/njol/skript/effects/EffMakeAdult.java @@ -35,7 +35,7 @@ import org.eclipse.jdt.annotation.Nullable; @Name("Make Adult") -@Description("Force an entity to become an adult or a baby, requires MC 1.16 for any mob") +@Description("Force a animal to become an adult or baby, requires MC 1.16 for any mob") @Examples({ "on spawn of mob:", "\tif entity is not an adult:", diff --git a/src/main/java/ch/njol/skript/expressions/ExprLoveTicks.java b/src/main/java/ch/njol/skript/expressions/ExprLoveTicks.java index 4ffc8bb528c..bc5179cfb88 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprLoveTicks.java +++ b/src/main/java/ch/njol/skript/expressions/ExprLoveTicks.java @@ -33,7 +33,8 @@ @Name("Love Ticks") @Description({ - "The amount of time an living entity has been in love for. Setting to 30 seconds is equal to using breeding item", + "The amount of time an animal has been in love for. Setting to 30 seconds is equal to using breeding item.", + "Only works on animals, not all living entities", "Returns '0 seconds' if null or invalid entity" }) @Examples({ From 0b894ccc8b53530d943169703a20d96b6af9de83 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Sat, 8 Apr 2023 07:46:38 -0400 Subject: [PATCH 16/48] Update ExprLoveTicks and SimpleEvents :bug: fix accidental forgotten example :red_circle: remove integer support from love ticks expression :clipboard: remove a test from CondIsInLove.sk Co-Authored-By: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com> --- .../java/ch/njol/skript/events/SimpleEvents.java | 2 +- .../njol/skript/expressions/ExprLoveTicks.java | 12 ++++++------ .../tests/syntaxes/conditions/CondIsInLove.sk | 16 ---------------- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index a86b9b59481..282bd2a7871 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -714,7 +714,7 @@ public class SimpleEvents { .description("Called whenever two breedable entities begin to conceive a child.") .examples( "on breeding:", - "\tsend \"When a %mother% and %father% love each other they make %offspring%\" to breeder" + "\tsend \"When a %breeding mother% and %breeding father% love each other they make %offspring%\" to breeder" ) .since("INSERT VERSION"); if (Skript.classExists("org.bukkit.event.entity.EntityEnterLoveModeEvent")) { diff --git a/src/main/java/ch/njol/skript/expressions/ExprLoveTicks.java b/src/main/java/ch/njol/skript/expressions/ExprLoveTicks.java index bc5179cfb88..de2f0cf36f2 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprLoveTicks.java +++ b/src/main/java/ch/njol/skript/expressions/ExprLoveTicks.java @@ -63,10 +63,10 @@ public Class[] acceptChange(ChangeMode mode) { switch (mode) { case SET: case RESET: - return CollectionUtils.array(Integer.class, Timespan.class); + return CollectionUtils.array(Timespan.class); case ADD: case REMOVE: - return CollectionUtils.array(Integer[].class, Timespan[].class); + return CollectionUtils.array(Timespan[].class); } return null; } @@ -78,13 +78,13 @@ public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { for (Object obj : delta) { switch (mode) { case ADD: - ticks += obj instanceof Timespan ? (int) ((Timespan) obj).getTicks_i() : (int) obj; + ticks += ((Timespan) obj).getTicks_i(); break; case REMOVE: - ticks -= obj instanceof Timespan ? (int) ((Timespan) obj).getTicks_i() : (int) obj; + ticks -= ((Timespan) obj).getTicks_i(); break; case SET: - ticks = obj instanceof Timespan ? (int) ((Timespan) obj).getTicks_i() : (int) obj; + ticks = (int) ((Timespan) obj).getTicks_i(); break; } } @@ -114,7 +114,7 @@ public Class getReturnType() { @Override protected String getPropertyName() { - return "love time"; + return "love ticks"; } } diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk b/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk index 27d2ee6751a..011eb060a83 100644 --- a/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk +++ b/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk @@ -9,22 +9,6 @@ test "in love valid entity (timespan)": assert {_cow} is in love with "Cow is not in love after setting love ticks" delete all cows -test "in love valid entity (ticks)": - delete all cows - set {_spawn} to spawn of world "world" - spawn adult cow at {_spawn} - set {_cow} to last spawned cow - assert love ticks of {_cow} is 0 seconds with "Cow love ticks was not 0 seconds after spawning" - assert {_cow} is not in love with "Cow is in love after spawning" - set love ticks of {_cow} to 15000 - assert {_cow} is in love with "Cow is not in love after setting love ticks" - assert love ticks of {_cow} > 10 minutes with "Cow love ticks were below 10 minutes, tick conversion failed" - reset love ticks of {_cow} - assert {_cow} is not in love with "Cow was still in love after resetting ticks" - add 10 seconds and 300 to love ticks of {_cow} - assert {_cow} is in love with "Cow wasn't in love adding using add changer" - delete all cows - test "in love invalid entity": delete all zombies set {_spawn} to spawn of world "world" From 0b10f7da12b95968e9cfa9a77b5064e880937502 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Sat, 8 Apr 2023 19:32:49 -0400 Subject: [PATCH 17/48] Fix ExprLoveTicks & Update Test :bug: Fixed an issue with ExprLoveTicks not working correctly :clipboard: Updated test to include more checks for add, remove and reset --- .../skript/expressions/ExprLoveTicks.java | 23 +++++++------------ .../tests/syntaxes/conditions/CondIsInLove.sk | 12 ++++++++-- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprLoveTicks.java b/src/main/java/ch/njol/skript/expressions/ExprLoveTicks.java index de2f0cf36f2..dd8a73516d8 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprLoveTicks.java +++ b/src/main/java/ch/njol/skript/expressions/ExprLoveTicks.java @@ -76,33 +76,26 @@ public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { int ticks = 0; if (delta != null) { for (Object obj : delta) { - switch (mode) { - case ADD: - ticks += ((Timespan) obj).getTicks_i(); - break; - case REMOVE: - ticks -= ((Timespan) obj).getTicks_i(); - break; - case SET: - ticks = (int) ((Timespan) obj).getTicks_i(); - break; - } + ticks += ((Timespan) obj).getTicks_i(); } } - ticks = Math.max(ticks, 0); for (LivingEntity livingEntity : getExpr().getArray(event)) { if (livingEntity instanceof Animals) { Animals animal = ((Animals) livingEntity); + int loveTicks = animal.getLoveModeTicks(); switch (mode) { - case REMOVE: case ADD: - animal.setLoveModeTicks(animal.getLoveModeTicks() + ticks); + loveTicks += ticks; + break; + case REMOVE: + loveTicks -= ticks; break; case SET: case RESET: - animal.setLoveModeTicks(ticks); + loveTicks = ticks; break; } + animal.setLoveModeTicks(Math.max(loveTicks, 0)); } } } diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk b/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk index 011eb060a83..6d7c1b7adb4 100644 --- a/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk +++ b/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk @@ -1,4 +1,4 @@ -test "in love valid entity (timespan)": +test "in love valid entity": delete all cows set {_spawn} to spawn of world "world" spawn adult cow at {_spawn} @@ -7,6 +7,14 @@ test "in love valid entity (timespan)": assert {_cow} is not in love with "Cow is in love after spawning" set love ticks of {_cow} to 10 seconds assert {_cow} is in love with "Cow is not in love after setting love ticks" + add 10 seconds to love ticks of {_cow} + assert love ticks of {_cow} > 10 seconds with "Cow love ticks didn't go up after adding" + remove 1 minute from love ticks of {_cow} + assert {_cow} is not in love with "Cow is in love after removing more love than possible" + add 10 minutes to love ticks of {_cow} + assert {_cow} is in love with "Cow didn't enter love mode after adding love ticks" + reset love ticks of {_cow} + assert {_cow} is not in love with "Cow was still in love even after resetting love ticks" delete all cows test "in love invalid entity": @@ -17,4 +25,4 @@ test "in love invalid entity": assert love ticks of {_zombie} is 0 seconds with "Zombie was in love Test1" set love ticks of {_zombie} to 10 minutes assert love ticks of {_zombie} is 0 seconds with "Zombie was in love Test2" - delete all zombies \ No newline at end of file + delete all zombies From 14b7962285d174beb1dca0e2234184374ee33194 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Sun, 9 Apr 2023 23:23:10 -0400 Subject: [PATCH 18/48] LoveTicks -> LoveTime Co-Authored-By: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com> --- .../{ExprLoveTicks.java => ExprLoveTime.java} | 10 +++---- .../tests/syntaxes/conditions/CondIsInLove.sk | 30 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) rename src/main/java/ch/njol/skript/expressions/{ExprLoveTicks.java => ExprLoveTime.java} (90%) diff --git a/src/main/java/ch/njol/skript/expressions/ExprLoveTicks.java b/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java similarity index 90% rename from src/main/java/ch/njol/skript/expressions/ExprLoveTicks.java rename to src/main/java/ch/njol/skript/expressions/ExprLoveTime.java index dd8a73516d8..adee35e5078 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprLoveTicks.java +++ b/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java @@ -31,7 +31,7 @@ import org.bukkit.event.Event; import org.eclipse.jdt.annotation.Nullable; -@Name("Love Ticks") +@Name("Love Time") @Description({ "The amount of time an animal has been in love for. Setting to 30 seconds is equal to using breeding item.", "Only works on animals, not all living entities", @@ -39,13 +39,13 @@ }) @Examples({ "on right click:", - "\tsend \"%event-enttiy% has been in love for %love ticks of event-entity%!\" to player" + "\tsend \"%event-enttiy% has been in love for %love time of event-entity%!\" to player" }) @Since("INSERT VERSION") -public class ExprLoveTicks extends SimplePropertyExpression { +public class ExprLoveTime extends SimplePropertyExpression { static { - register(ExprLoveTicks.class, Timespan.class, "love ticks", "livingentities"); + register(ExprLoveTime.class, Timespan.class, "love time", "livingentities"); } @Override @@ -107,7 +107,7 @@ public Class getReturnType() { @Override protected String getPropertyName() { - return "love ticks"; + return "love time"; } } diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk b/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk index 6d7c1b7adb4..eb3df35c0e6 100644 --- a/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk +++ b/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk @@ -1,28 +1,28 @@ -test "in love valid entity": +test "CondIsInLove - Valid Entity": delete all cows set {_spawn} to spawn of world "world" spawn adult cow at {_spawn} set {_cow} to last spawned cow - assert love ticks of {_cow} is 0 seconds with "Cow love ticks was not 0 seconds after spawning" + assert love time of {_cow} is 0 seconds with "Cow love time was not 0 seconds after spawning" assert {_cow} is not in love with "Cow is in love after spawning" - set love ticks of {_cow} to 10 seconds - assert {_cow} is in love with "Cow is not in love after setting love ticks" - add 10 seconds to love ticks of {_cow} - assert love ticks of {_cow} > 10 seconds with "Cow love ticks didn't go up after adding" - remove 1 minute from love ticks of {_cow} + set love time of {_cow} to 10 seconds + assert {_cow} is in love with "Cow is not in love after setting love time" + add 10 seconds to love time of {_cow} + assert love time of {_cow} > 10 seconds with "Cow love time didn't go up after adding" + remove 1 minute from love time of {_cow} assert {_cow} is not in love with "Cow is in love after removing more love than possible" - add 10 minutes to love ticks of {_cow} - assert {_cow} is in love with "Cow didn't enter love mode after adding love ticks" - reset love ticks of {_cow} - assert {_cow} is not in love with "Cow was still in love even after resetting love ticks" + add 10 minutes to love time of {_cow} + assert {_cow} is in love with "Cow didn't enter love mode after adding love time" + reset love time of {_cow} + assert {_cow} is not in love with "Cow was still in love even after resetting love time" delete all cows -test "in love invalid entity": +test "CondIsInLove - Invalid Entity": delete all zombies set {_spawn} to spawn of world "world" spawn adult zombie at {_spawn} set {_zombie} to last spawned zombie - assert love ticks of {_zombie} is 0 seconds with "Zombie was in love Test1" - set love ticks of {_zombie} to 10 minutes - assert love ticks of {_zombie} is 0 seconds with "Zombie was in love Test2" + assert love time of {_zombie} is 0 seconds with "Zombie was in love Test1" + set love time of {_zombie} to 10 minutes + assert love time of {_zombie} is 0 seconds with "Zombie was in love Test2" delete all zombies From 442602a25f0922c9594492d35c60201e7db8a655 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Tue, 18 Apr 2023 20:30:54 -0400 Subject: [PATCH 19/48] Apply suggestions from code review Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> --- .../njol/skript/conditions/CondCanBreed.java | 7 +++-- .../njol/skript/conditions/CondIsAdult.java | 10 +++---- .../njol/skript/conditions/CondIsInLove.java | 6 ++--- .../ch/njol/skript/effects/EffBreedable.java | 6 ++--- .../ch/njol/skript/effects/EffLockAge.java | 4 +-- .../ch/njol/skript/effects/EffMakeAdult.java | 7 +++-- .../ch/njol/skript/events/SimpleEvents.java | 26 +++++++++---------- .../expressions/ExprBreedingFamily.java | 10 +++---- .../skript/expressions/ExprExperience.java | 4 +-- .../njol/skript/expressions/ExprLoveTime.java | 6 ++--- 10 files changed, 42 insertions(+), 44 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondCanBreed.java b/src/main/java/ch/njol/skript/conditions/CondCanBreed.java index 44bba127e95..664fb4e9452 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanBreed.java +++ b/src/main/java/ch/njol/skript/conditions/CondCanBreed.java @@ -32,8 +32,8 @@ @Description("Returns whether or not a living entity is breedable.") @Examples({ "on right click on living entity with bucket:", - "\tif event-entity can't breed:", - "\t\tsend \"Turns out %event-entity% is not breedable, what a let down\" to player" + "\tevent-entity can't breed", + "\tsend \"Turns out %event-entity% is not breedable, what a let down\" to player" }) @Since("INSERT VERSION") @RequiredPlugins("MC 1.16+") @@ -46,9 +46,8 @@ public class CondCanBreed extends PropertyCondition { @Override public boolean check(LivingEntity livingEntity) { - if (livingEntity instanceof Breedable) { + if (livingEntity instanceof Breedable) return ((Breedable) livingEntity).canBreed(); - } return false; } diff --git a/src/main/java/ch/njol/skript/conditions/CondIsAdult.java b/src/main/java/ch/njol/skript/conditions/CondIsAdult.java index 2cf284fb955..c87c71e9d41 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsAdult.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsAdult.java @@ -29,17 +29,17 @@ import org.bukkit.entity.LivingEntity; @Name("Is An Adult") -@Description("Returns whether or not an animal is an adult, requires 1.16.5 for mobs") +@Description("Returns whether or not animals are an adult, requires 1.16.5+ for mobs") @Examples({ "on spawn:", - "\tif event-entity is not an adult:", - "\t\tmake event-entity an adult" + "\tevent-entity is not an adult", + "\tmake event-entity an adult" }) @Since("INSERT VERSION") public class CondIsAdult extends PropertyCondition { - // This is required since before 1.16 the `isAdult` method only supported Animals - static boolean HAS_MOB_SUPPORT = Skript.isRunningMinecraft(1,16,5); + // This is required since before 1.16 the 'isAdult' method only supported Animals + private static final boolean HAS_MOB_SUPPORT = Skript.isRunningMinecraft(1, 16, 5); static { register(CondIsAdult.class, "[an] adult", "livingentities"); diff --git a/src/main/java/ch/njol/skript/conditions/CondIsInLove.java b/src/main/java/ch/njol/skript/conditions/CondIsInLove.java index c06c8edd8a3..704b8172b04 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsInLove.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsInLove.java @@ -27,11 +27,11 @@ import org.bukkit.entity.LivingEntity; @Name("Entity In Love") -@Description("Whether or not an animal is currently in a love state") +@Description("Whether or not animals are currently in a love state") @Examples({ "on right click on living entity:", - "\tif event-entity is in love:", - "\t\tsend \"&c&oOhhh, he's in love <3\" to player" + "\tevent-entity is in love", + "\tsend \"&c&oOhhh, this entity in love <3\" to player" }) @Since("INSERT VERSION") public class CondIsInLove extends PropertyCondition { diff --git a/src/main/java/ch/njol/skript/effects/EffBreedable.java b/src/main/java/ch/njol/skript/effects/EffBreedable.java index 5e1836b0d99..cbe18eb4941 100644 --- a/src/main/java/ch/njol/skript/effects/EffBreedable.java +++ b/src/main/java/ch/njol/skript/effects/EffBreedable.java @@ -35,12 +35,12 @@ @Name("Make Breedable") @Description({ - "Picks whether or not an entity will be able to breed.", - "Doesn't work on all entities only animals" + "Picks whether or not entities will be able to breed.", + "Only works on animals, not all living entities" }) @Examples({ "on spawn of animal:", - "\tmake entity unbreedable" + "\tmake entity unbreedable" }) @Since("INSERT VERSION") @RequiredPlugins("MC 1.16+") diff --git a/src/main/java/ch/njol/skript/effects/EffLockAge.java b/src/main/java/ch/njol/skript/effects/EffLockAge.java index 10acbdd6314..5edd62610ac 100644 --- a/src/main/java/ch/njol/skript/effects/EffLockAge.java +++ b/src/main/java/ch/njol/skript/effects/EffLockAge.java @@ -34,10 +34,10 @@ import org.eclipse.jdt.annotation.Nullable; @Name("Lock Age") -@Description("Picks whether or not an entity will be able to age or mate.") +@Description("Picks whether or not entities will be able to age or mate.") @Examples({ "on spawn of animal:", - "\tlock age of entity" + "\tlock age of entity" }) @Since("INSERT VERSION") @RequiredPlugins("MC 1.16+") diff --git a/src/main/java/ch/njol/skript/effects/EffMakeAdult.java b/src/main/java/ch/njol/skript/effects/EffMakeAdult.java index 7d68069adaa..3dbb1643a04 100644 --- a/src/main/java/ch/njol/skript/effects/EffMakeAdult.java +++ b/src/main/java/ch/njol/skript/effects/EffMakeAdult.java @@ -38,16 +38,15 @@ @Description("Force a animal to become an adult or baby, requires MC 1.16 for any mob") @Examples({ "on spawn of mob:", - "\tif entity is not an adult:", - "\t\tmake entity an adult", + "\tentity is not an adult", + "\tmake entity an adult", }) @Since("INSERT VERSION") @RequiredPlugins("1.16+ (Mobs)") public class EffMakeAdult extends Effect { - // This is required since before 1.16 the `setBaby`/'setAdult' method only supported Animals - private final static boolean HAS_MOB_SUPPORT = Skript.isRunningMinecraft(1,16,5); + private static final boolean HAS_MOB_SUPPORT = Skript.isRunningMinecraft(1, 16, 5); static { Skript.registerEffect(EffMakeAdult.class, "make %livingentities% [a[n]] (adult|:baby)"); diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index 282bd2a7871..c1e4ce19a48 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -711,21 +711,21 @@ public class SimpleEvents { .requiredPlugins("Paper 1.16+"); } Skript.registerEvent("Entity Breed", SimpleEvent.class, EntityBreedEvent.class, "[entity] breed[ing]") - .description("Called whenever two breedable entities begin to conceive a child.") - .examples( - "on breeding:", - "\tsend \"When a %breeding mother% and %breeding father% love each other they make %offspring%\" to breeder" - ) - .since("INSERT VERSION"); - if (Skript.classExists("org.bukkit.event.entity.EntityEnterLoveModeEvent")) { - Skript.registerEvent("Love Mode Enter", SimpleEvent.class, EntityEnterLoveModeEvent.class, "[entity] enter[s] love mode", "[entity] love mode [enter]") - .description("Called whenever an entity enters a state of being in love.") + .description("Called whenever two breedable entities begin to conceive a child.") .examples( - "on love mode enter:", - "\tcancel event # No one is allowed love here" + "on breeding:", + "\tsend \"When a %breeding mother% and %breeding father% love each other they make %offspring%\" to breeder" ) - .since("INSERT VERSION") - .requiredPlugins("MC 1.16+"); + .since("INSERT VERSION"); + if (Skript.classExists("org.bukkit.event.entity.EntityEnterLoveModeEvent")) { + Skript.registerEvent("Love Mode Enter", SimpleEvent.class, EntityEnterLoveModeEvent.class, "[entity] enter[s] love mode", "[entity] love mode [enter]") + .description("Called whenever an entity enters a state of being in love.") + .examples( + "on love mode enter:", + "\tcancel event # No one is allowed love here" + ) + .since("INSERT VERSION") + .requiredPlugins("MC 1.16+"); } } diff --git a/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java b/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java index 7d7a7f3b9cc..02ba2c7dec7 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java +++ b/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java @@ -37,17 +37,17 @@ @Description("Represents a family within a breeding event") @Examples({ "on breeding:", - "\tsend \"When a %breeding mother% and %breeding father% love each other they make a %bred offspring%\" to breeder" + "\tsend \"When a %breeding mother% and %breeding father% love each other they make a %bred offspring%\" to breeder" }) @Since("INSERT VERSION") public class ExprBreedingFamily extends SimpleExpression { static { Skript.registerExpression(ExprBreedingFamily.class, LivingEntity.class, ExpressionType.SIMPLE, - "breed[ing] mother", - "breed[ing] father", - "[bred] (offspring|child)", - "breeder"); + "breed[ing] mother", + "breed[ing] father", + "[bred] (offspring|child)", + "breeder"); } private int pattern; diff --git a/src/main/java/ch/njol/skript/expressions/ExprExperience.java b/src/main/java/ch/njol/skript/expressions/ExprExperience.java index 03416e0546f..0784d50b659 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExperience.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExperience.java @@ -57,8 +57,8 @@ "\t\tadd 100 to dropped experience", "", "on breed:", - "\tbreeding father is a cow", - "\tset dropped experience to 10" + "\tbreeding father is a cow", + "\tset dropped experience to 10" }) @Since("2.1, 2.5.3 (block break event), 2.7 (experience change event), INSERT VERSION (breeding event)") @Events({"experience spawn", "break / mine", "experience change", "entity breeding"}) diff --git a/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java b/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java index adee35e5078..12c5af312b9 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java +++ b/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java @@ -33,13 +33,13 @@ @Name("Love Time") @Description({ - "The amount of time an animal has been in love for. Setting to 30 seconds is equal to using breeding item.", + "The amount of time animals have been in love for. Setting to 30 seconds is equal to using breeding item.", "Only works on animals, not all living entities", - "Returns '0 seconds' if null or invalid entity" + "Returns '0 seconds' if null or invalid entities" }) @Examples({ "on right click:", - "\tsend \"%event-enttiy% has been in love for %love time of event-entity%!\" to player" + "\tsend \"%event-enttiy% has been in love for %love time of event-entity%!\" to player" }) @Since("INSERT VERSION") public class ExprLoveTime extends SimplePropertyExpression { From babb7b1cd339f7b157d32bd610bb3834bbfbfdcf Mon Sep 17 00:00:00 2001 From: Fusezion Date: Tue, 18 Apr 2023 20:43:17 -0400 Subject: [PATCH 20/48] Change CondIsAdult condition checks Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> --- src/main/java/ch/njol/skript/conditions/CondIsAdult.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsAdult.java b/src/main/java/ch/njol/skript/conditions/CondIsAdult.java index c87c71e9d41..a78bab601b4 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsAdult.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsAdult.java @@ -47,9 +47,10 @@ public class CondIsAdult extends PropertyCondition { @Override public boolean check(LivingEntity livingEntity) { - if (livingEntity instanceof Ageable) - if (HAS_MOB_SUPPORT || livingEntity instanceof Animals) - return ((Ageable) livingEntity).isAdult(); + if (!(livingEntity instanceof Ageable)) + return false; + if (HAS_MOB_SUPPORT || livingEntity instanceof Animals) + return ((Ageable) livingEntity).isAdult(); return false; } From 60a0500dddee29f52ea440083eac33a20950e0cf Mon Sep 17 00:00:00 2001 From: Fusezion Date: Tue, 18 Apr 2023 21:08:12 -0400 Subject: [PATCH 21/48] Apply requested code review changes Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> --- src/main/java/ch/njol/skript/conditions/CondCanAge.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondCanAge.java b/src/main/java/ch/njol/skript/conditions/CondCanAge.java index 4e1e2b50183..00f8de9af4e 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanAge.java +++ b/src/main/java/ch/njol/skript/conditions/CondCanAge.java @@ -32,8 +32,8 @@ @Description("Returns whether or not an entity will be able to age/grow up") @Examples({ "on right click on living entity:", - "\tif entity can't age:", - "\t\tsend \"This entity is forever non aging\" to player" + "\tentity can't age", + "\tsend \"This entity is forever non aging\" to player" }) @Since("INSERT VERSION") @RequiredPlugins("MC 1.16+") From a8deec7d9122698de8fa5af33f15d8cef494590e Mon Sep 17 00:00:00 2001 From: Fusezion Date: Tue, 18 Apr 2023 21:14:30 -0400 Subject: [PATCH 22/48] Apply more requested changes --- src/main/java/ch/njol/skript/conditions/CondIsAdult.java | 2 ++ src/main/java/ch/njol/skript/conditions/CondIsInLove.java | 2 +- src/main/java/ch/njol/skript/expressions/ExprLoveTime.java | 5 ++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsAdult.java b/src/main/java/ch/njol/skript/conditions/CondIsAdult.java index a78bab601b4..17fb8fe8030 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsAdult.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsAdult.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 org.bukkit.entity.Ageable; import org.bukkit.entity.Animals; @@ -36,6 +37,7 @@ "\tmake event-entity an adult" }) @Since("INSERT VERSION") +@RequiredPlugins("MC 1.16.5+ (Mobs)") public class CondIsAdult extends PropertyCondition { // This is required since before 1.16 the 'isAdult' method only supported Animals diff --git a/src/main/java/ch/njol/skript/conditions/CondIsInLove.java b/src/main/java/ch/njol/skript/conditions/CondIsInLove.java index 704b8172b04..c496e64b6eb 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsInLove.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsInLove.java @@ -37,7 +37,7 @@ public class CondIsInLove extends PropertyCondition { static { - register(CondIsInLove.class, "in love", "livingentities"); + register(CondIsInLove.class, "in lov(e|ing) [state]", "livingentities"); } @Override diff --git a/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java b/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java index 12c5af312b9..930dcd6de6e 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java +++ b/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java @@ -67,8 +67,9 @@ public Class[] acceptChange(ChangeMode mode) { case ADD: case REMOVE: return CollectionUtils.array(Timespan[].class); + default: + return null; } - return null; } @Override @@ -94,6 +95,8 @@ public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { case RESET: loveTicks = ticks; break; + default: + break; } animal.setLoveModeTicks(Math.max(loveTicks, 0)); } From 9d981206cdf185ebdf7a98bf9afb73aa3ff5f7ed Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sun, 22 Sep 2024 12:46:13 +0200 Subject: [PATCH 23/48] update conds --- .../ch/njol/skript/conditions/CondCanAge.java | 32 +++----------- .../njol/skript/conditions/CondCanBreed.java | 33 ++++----------- .../njol/skript/conditions/CondIsAdult.java | 42 ++++--------------- .../njol/skript/conditions/CondIsChild.java | 38 +++++++++++++++++ .../njol/skript/conditions/CondIsInLove.java | 28 +++---------- 5 files changed, 64 insertions(+), 109 deletions(-) create mode 100644 src/main/java/ch/njol/skript/conditions/CondIsChild.java diff --git a/src/main/java/ch/njol/skript/conditions/CondCanAge.java b/src/main/java/ch/njol/skript/conditions/CondCanAge.java index 00f8de9af4e..a2b234f2db9 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanAge.java +++ b/src/main/java/ch/njol/skript/conditions/CondCanAge.java @@ -1,21 +1,3 @@ -/** - * 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; @@ -23,20 +5,18 @@ 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 org.bukkit.entity.Breedable; import org.bukkit.entity.LivingEntity; @Name("Can Age") -@Description("Returns whether or not an entity will be able to age/grow up") +@Description("Returns whether or not an entity will be able to age/grow up.") @Examples({ - "on right click on living entity:", + "on breeding:", "\tentity can't age", - "\tsend \"This entity is forever non aging\" to player" + "\tbroadcast \"An immortal has been born!\" to player" }) @Since("INSERT VERSION") -@RequiredPlugins("MC 1.16+") public class CondCanAge extends PropertyCondition { static { @@ -45,9 +25,9 @@ public class CondCanAge extends PropertyCondition { } @Override - public boolean check(LivingEntity livingEntity) { - if (livingEntity instanceof Breedable) - return !((Breedable) livingEntity).getAgeLock(); + public boolean check(LivingEntity entity) { + if (entity instanceof Breedable breedable) + return !breedable.getAgeLock(); return false; } diff --git a/src/main/java/ch/njol/skript/conditions/CondCanBreed.java b/src/main/java/ch/njol/skript/conditions/CondCanBreed.java index 664fb4e9452..c19fe1cf3a9 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanBreed.java +++ b/src/main/java/ch/njol/skript/conditions/CondCanBreed.java @@ -1,21 +1,3 @@ -/** - * 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; @@ -23,20 +5,18 @@ 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 org.bukkit.entity.Breedable; import org.bukkit.entity.LivingEntity; @Name("Can Breed") -@Description("Returns whether or not a living entity is breedable.") +@Description("Returns whether or not a living entity can be bred.") @Examples({ - "on right click on living entity with bucket:", + "on right click on living entity:", "\tevent-entity can't breed", - "\tsend \"Turns out %event-entity% is not breedable, what a let down\" to player" + "\tsend \"Turns out %event-entity% is not breedable. Must be a Skript user!\" to player" }) @Since("INSERT VERSION") -@RequiredPlugins("MC 1.16+") public class CondCanBreed extends PropertyCondition { static { @@ -45,9 +25,10 @@ public class CondCanBreed extends PropertyCondition { } @Override - public boolean check(LivingEntity livingEntity) { - if (livingEntity instanceof Breedable) - return ((Breedable) livingEntity).canBreed(); + public boolean check(LivingEntity entity) { + if (entity instanceof Breedable breedable) + return breedable.canBreed(); + return false; } diff --git a/src/main/java/ch/njol/skript/conditions/CondIsAdult.java b/src/main/java/ch/njol/skript/conditions/CondIsAdult.java index 17fb8fe8030..a9d0199e4c6 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsAdult.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsAdult.java @@ -1,58 +1,32 @@ -/** - * 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 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 org.bukkit.entity.Ageable; -import org.bukkit.entity.Animals; import org.bukkit.entity.LivingEntity; -@Name("Is An Adult") -@Description("Returns whether or not animals are an adult, requires 1.16.5+ for mobs") +@Name("Is Adult") +@Description("Returns whether or not a living entity is an adult.") @Examples({ - "on spawn:", + "on drink:", "\tevent-entity is not an adult", - "\tmake event-entity an adult" + "\tkill event-entity" }) @Since("INSERT VERSION") -@RequiredPlugins("MC 1.16.5+ (Mobs)") public class CondIsAdult extends PropertyCondition { - // This is required since before 1.16 the 'isAdult' method only supported Animals - private static final boolean HAS_MOB_SUPPORT = Skript.isRunningMinecraft(1, 16, 5); - static { register(CondIsAdult.class, "[an] adult", "livingentities"); } @Override - public boolean check(LivingEntity livingEntity) { - if (!(livingEntity instanceof Ageable)) - return false; - if (HAS_MOB_SUPPORT || livingEntity instanceof Animals) - return ((Ageable) livingEntity).isAdult(); + public boolean check(LivingEntity entity) { + if (entity instanceof Ageable ageable) + return ageable.isAdult(); + return false; } diff --git a/src/main/java/ch/njol/skript/conditions/CondIsChild.java b/src/main/java/ch/njol/skript/conditions/CondIsChild.java new file mode 100644 index 00000000000..c62fc407724 --- /dev/null +++ b/src/main/java/ch/njol/skript/conditions/CondIsChild.java @@ -0,0 +1,38 @@ +package ch.njol.skript.conditions; + +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 org.bukkit.entity.Ageable; +import org.bukkit.entity.LivingEntity; + +@Name("Is Child") +@Description("Returns whether or not a living entity is a child.") +@Examples({ + "on drink:", + "\tevent-entity is a child", + "\tkill event-entity" +}) +@Since("INSERT VERSION") +public class CondIsChild extends PropertyCondition { + + static { + register(CondIsChild.class, "[a] child", "livingentities"); + } + + @Override + public boolean check(LivingEntity entity) { + if (entity instanceof Ageable ageable) + return !ageable.isAdult(); + + return false; + } + + @Override + protected String getPropertyName() { + return "a child"; + } + +} diff --git a/src/main/java/ch/njol/skript/conditions/CondIsInLove.java b/src/main/java/ch/njol/skript/conditions/CondIsInLove.java index c496e64b6eb..6c2e166924a 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsInLove.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsInLove.java @@ -1,21 +1,3 @@ -/** - * 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.conditions.base.PropertyCondition; @@ -26,12 +8,12 @@ import org.bukkit.entity.Animals; import org.bukkit.entity.LivingEntity; -@Name("Entity In Love") -@Description("Whether or not animals are currently in a love state") +@Name("Is In Love") +@Description("Whether or not the animals are currently in the love state.") @Examples({ - "on right click on living entity:", - "\tevent-entity is in love", - "\tsend \"&c&oOhhh, this entity in love <3\" to player" + "on spawn of living entity:", + "\tif entity is in love:", + "" }) @Since("INSERT VERSION") public class CondIsInLove extends PropertyCondition { From 29847db81d23509e2ae932360752a478fc4120e1 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sun, 22 Sep 2024 13:17:19 +0200 Subject: [PATCH 24/48] update exprs --- .../expressions/ExprBreedingFamily.java | 59 ++---- .../skript/expressions/ExprExperience.java | 169 +++++++----------- .../njol/skript/expressions/ExprLoveTime.java | 96 ++++------ 3 files changed, 118 insertions(+), 206 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java b/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java index 02ba2c7dec7..a49b6e679e2 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java +++ b/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java @@ -1,21 +1,3 @@ -/** - * 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.expressions; import ch.njol.skript.Skript; @@ -34,52 +16,49 @@ import org.eclipse.jdt.annotation.Nullable; @Name("Breeding Family") -@Description("Represents a family within a breeding event") +@Description("Represents family members within a breeding event.") @Examples({ "on breeding:", - "\tsend \"When a %breeding mother% and %breeding father% love each other they make a %bred offspring%\" to breeder" + "\tsend \"When a %breeding mother% and %breeding father% love each other very much, " + + "they make a %bred offspring%\" to breeder" }) @Since("INSERT VERSION") public class ExprBreedingFamily extends SimpleExpression { static { Skript.registerExpression(ExprBreedingFamily.class, LivingEntity.class, ExpressionType.SIMPLE, - "breed[ing] mother", - "breed[ing] father", - "[bred] (offspring|child)", - "breeder"); + "[the] breed[ing] mother", + "[the] breed[ing] father", + "[the] [bred] (offspring|child)", + "[the] breeder"); } private int pattern; @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + public boolean init(Expression[] expressions, int matchedPattern, + Kleenean isDelayed, ParseResult parseResult) { if (!getParser().isCurrentEvent(EntityBreedEvent.class)) { Skript.error("'breeding family' expression can only be used within an Entity Breed event."); return false; } + pattern = matchedPattern; return true; } @Override protected @Nullable LivingEntity[] get(Event event) { - if (!(event instanceof EntityBreedEvent)) + if (!(event instanceof EntityBreedEvent breedEvent)) return new LivingEntity[0]; - - EntityBreedEvent breedEvent = (EntityBreedEvent) event; - switch (pattern) { - case 0: - return new LivingEntity[]{breedEvent.getMother()}; - case 1: - return new LivingEntity[]{breedEvent.getFather()}; - case 2: - return new LivingEntity[]{breedEvent.getEntity()}; - case 3: - return new LivingEntity[]{breedEvent.getBreeder()}; - default: - return new LivingEntity[0]; - } + + return switch (pattern) { + case 0 -> new LivingEntity[]{breedEvent.getMother()}; + case 1 -> new LivingEntity[]{breedEvent.getFather()}; + case 2 -> new LivingEntity[]{breedEvent.getEntity()}; + case 3 -> new LivingEntity[]{breedEvent.getBreeder()}; + default -> new LivingEntity[0]; + }; } @Override diff --git a/src/main/java/ch/njol/skript/expressions/ExprExperience.java b/src/main/java/ch/njol/skript/expressions/ExprExperience.java index 0784d50b659..b8436b17628 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExperience.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExperience.java @@ -1,37 +1,8 @@ -/** - * 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.expressions; -import ch.njol.util.coll.CollectionUtils; -import org.bukkit.event.Event; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.entity.EntityBreedEvent; -import org.bukkit.event.player.PlayerExpChangeEvent; -import org.eclipse.jdt.annotation.Nullable; - import ch.njol.skript.Skript; import ch.njol.skript.classes.Changer.ChangeMode; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Events; -import ch.njol.skript.doc.Examples; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.Since; +import ch.njol.skript.doc.*; import ch.njol.skript.events.bukkit.ExperienceSpawnEvent; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.ExpressionType; @@ -39,117 +10,109 @@ import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.skript.util.Experience; import ch.njol.util.Kleenean; +import ch.njol.util.coll.CollectionUtils; +import org.bukkit.event.Event; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.entity.EntityBreedEvent; +import org.bukkit.event.player.PlayerExpChangeEvent; +import org.eclipse.jdt.annotation.Nullable; -/** - * @author Peter Güttinger - */ @Name("Experience") @Description("How much experience was spawned in an experience spawn or block break event. Can be changed.") @Examples({ - "on experience spawn:", + "on experience spawn:", "\tadd 5 to the spawned experience", - "", - "on break of coal ore:", + "", + "on break of coal ore:", "\tclear dropped experience", - "", - "on break of diamond ore:", + "", + "on break of diamond ore:", "\tif tool of player = diamond pickaxe:", - "\t\tadd 100 to dropped experience", - "", - "on breed:", - "\tbreeding father is a cow", - "\tset dropped experience to 10" + "\t\tadd 100 to dropped experience", + "", + "on breed:", + "\tbreeding father is a cow", + "\tset dropped experience to 10" }) @Since("2.1, 2.5.3 (block break event), 2.7 (experience change event), INSERT VERSION (breeding event)") @Events({"experience spawn", "break / mine", "experience change", "entity breeding"}) public class ExprExperience extends SimpleExpression { static { - Skript.registerExpression(ExprExperience.class, Experience.class, ExpressionType.SIMPLE, "[the] (spawned|dropped|) [e]xp[erience] [orb[s]]"); + Skript.registerExpression(ExprExperience.class, Experience.class, ExpressionType.SIMPLE, + "[the] (spawned|dropped|) [e]xp[erience] [orb[s]]"); } @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - if (!getParser().isCurrentEvent(ExperienceSpawnEvent.class, BlockBreakEvent.class, PlayerExpChangeEvent.class, EntityBreedEvent.class)) { - Skript.error("The experience expression can only be used in experience spawn, block break, player experience change and entity breeding events"); + if (!getParser().isCurrentEvent(ExperienceSpawnEvent.class, BlockBreakEvent.class, + PlayerExpChangeEvent.class, EntityBreedEvent.class)) { + Skript.error("The experience expression can only be used in experience spawn, " + + "block break, player experience change and entity breeding events"); return false; } + return true; } @Override - @Nullable - protected Experience[] get(Event event) { - if (event instanceof ExperienceSpawnEvent) - return new Experience[] {new Experience(((ExperienceSpawnEvent) event).getSpawnedXP())}; - else if (event instanceof BlockBreakEvent) - return new Experience[] {new Experience(((BlockBreakEvent) event).getExpToDrop())}; - else if (event instanceof PlayerExpChangeEvent) - return new Experience[] {new Experience(((PlayerExpChangeEvent) event).getAmount())}; - else if (event instanceof EntityBreedEvent) - return new Experience[] {new Experience(((EntityBreedEvent) event).getExperience())}; - else - return new Experience[0]; + protected @Nullable Experience[] get(Event event) { + return switch (event) { + case ExperienceSpawnEvent experienceSpawnEvent -> + new Experience[]{new Experience(experienceSpawnEvent.getSpawnedXP())}; + case BlockBreakEvent blockBreakEvent -> + new Experience[]{new Experience(blockBreakEvent.getExpToDrop())}; + case PlayerExpChangeEvent playerExpChangeEvent -> + new Experience[]{new Experience(playerExpChangeEvent.getAmount())}; + case EntityBreedEvent entityBreedEvent -> + new Experience[]{new Experience(entityBreedEvent.getExperience())}; + default -> new Experience[0]; + }; } @Override @Nullable public Class[] acceptChange(ChangeMode mode) { - switch (mode) { - case SET: - case DELETE: - case RESET: - return CollectionUtils.array(ExprExperience.class, Integer.class); - case ADD: - case REMOVE: - return CollectionUtils.array(ExprExperience[].class, Integer[].class); - } - return null; + return switch (mode) { + case SET, DELETE, RESET -> CollectionUtils.array(Experience.class, Integer.class); + case ADD, REMOVE -> CollectionUtils.array(Experience[].class, Integer[].class); + default -> null; + }; } @Override - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { - int eventExp; - if (event instanceof ExperienceSpawnEvent) { - eventExp = ((ExperienceSpawnEvent) event).getSpawnedXP(); - } else if (event instanceof BlockBreakEvent) { - eventExp = ((BlockBreakEvent) event).getExpToDrop(); - } else if (event instanceof PlayerExpChangeEvent) { - eventExp = ((PlayerExpChangeEvent) event).getAmount(); - } else if (event instanceof EntityBreedEvent) { - eventExp = ((EntityBreedEvent) event).getExperience(); - } else { - return; + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { + int exp = 0; + + switch (event) { + case ExperienceSpawnEvent experienceSpawnEvent -> exp = experienceSpawnEvent.getSpawnedXP(); + case BlockBreakEvent blockBreakEvent -> exp = blockBreakEvent.getExpToDrop(); + case PlayerExpChangeEvent playerExpChangeEvent -> exp = playerExpChangeEvent.getAmount(); + case EntityBreedEvent entityBreedEvent -> exp = entityBreedEvent.getExperience(); + + default -> { + return; + } } - if (delta == null) { - eventExp = 0; - } else { - for (Object obj : delta) { - int value = obj instanceof Experience ? ((Experience) obj).getXP() : (Integer) obj; + if (delta != null) { + for (Object object : delta) { + int value = object instanceof Experience experience ? experience.getXP() : (int) object; switch (mode) { - case ADD: - eventExp += value; - break; - case SET: - eventExp = value; - break; - case REMOVE: - eventExp -= value; - break; + case ADD -> exp += value; + case SET -> exp = value; + case REMOVE -> exp -= value; } } } - eventExp = Math.max(0, eventExp); - if (event instanceof ExperienceSpawnEvent) { - ((ExperienceSpawnEvent) event).setSpawnedXP(eventExp); - } else if (event instanceof BlockBreakEvent) { - ((BlockBreakEvent) event).setExpToDrop(eventExp); - } else if (event instanceof PlayerExpChangeEvent) { - ((PlayerExpChangeEvent) event).setAmount(eventExp); - } else if (event instanceof EntityBreedEvent) { - ((EntityBreedEvent) event).setExperience(eventExp); + exp = Math.max(0, exp); + switch (event) { + case ExperienceSpawnEvent experienceSpawnEvent -> experienceSpawnEvent.setSpawnedXP(exp); + case BlockBreakEvent blockBreakEvent -> blockBreakEvent.setExpToDrop(exp); + case PlayerExpChangeEvent playerExpChangeEvent -> playerExpChangeEvent.setAmount(exp); + case EntityBreedEvent entityBreedEvent -> entityBreedEvent.setExperience(exp); + default -> {} } } diff --git a/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java b/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java index 930dcd6de6e..66669a36a15 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java +++ b/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java @@ -1,21 +1,3 @@ -/** - * 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.expressions; import ch.njol.skript.classes.Changer.ChangeMode; @@ -33,73 +15,61 @@ @Name("Love Time") @Description({ - "The amount of time animals have been in love for. Setting to 30 seconds is equal to using breeding item.", - "Only works on animals, not all living entities", - "Returns '0 seconds' if null or invalid entities" + "The amount of time the animals have been in love for. " + + "Using a value of 30 seconds is equivalent to using an item to breed them.", + "Only works on animals that can be bred and returns '0 seconds' for animals that can't be bred." }) @Examples({ "on right click:", - "\tsend \"%event-enttiy% has been in love for %love time of event-entity%!\" to player" + "\tsend \"%event-entity% has been in love for %love time of event-entity% more than you!\" to player" }) @Since("INSERT VERSION") public class ExprLoveTime extends SimplePropertyExpression { static { - register(ExprLoveTime.class, Timespan.class, "love time", "livingentities"); + register(ExprLoveTime.class, Timespan.class, "love[d] time", "livingentities"); } @Override - @Nullable - public Timespan convert(LivingEntity livingEntity) { - int loveTicks = 0; - if (livingEntity instanceof Animals) - loveTicks = ((Animals) livingEntity).getLoveModeTicks(); - return Timespan.fromTicks_i(loveTicks); + public @Nullable Timespan convert(LivingEntity entity) { + if (entity instanceof Animals animal) + return new Timespan(Timespan.TimePeriod.TICK, animal.getLoveModeTicks()); + + return new Timespan(0); } @Override - @Nullable - public Class[] acceptChange(ChangeMode mode) { - switch (mode) { - case SET: - case RESET: - return CollectionUtils.array(Timespan.class); - case ADD: - case REMOVE: - return CollectionUtils.array(Timespan[].class); - default: - return null; - } + public @Nullable Class[] acceptChange(ChangeMode mode) { + return switch (mode) { + case SET -> CollectionUtils.array(Timespan.class); + case ADD, REMOVE -> CollectionUtils.array(Timespan[].class); + case RESET -> CollectionUtils.array(); + default -> null; + }; } @Override - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { - int ticks = 0; + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { + int changeTicks = 0; + if (delta != null) { - for (Object obj : delta) { - ticks += ((Timespan) obj).getTicks_i(); + for (Object object : delta) { + changeTicks += (int) ((Timespan) object).getAs(Timespan.TimePeriod.TICK); } } + for (LivingEntity livingEntity : getExpr().getArray(event)) { - if (livingEntity instanceof Animals) { - Animals animal = ((Animals) livingEntity); - int loveTicks = animal.getLoveModeTicks(); - switch (mode) { - case ADD: - loveTicks += ticks; - break; - case REMOVE: - loveTicks -= ticks; - break; - case SET: - case RESET: - loveTicks = ticks; - break; - default: - break; - } - animal.setLoveModeTicks(Math.max(loveTicks, 0)); + if (!(livingEntity instanceof Animals animal)) + continue; + + int loveTicks = animal.getLoveModeTicks(); + switch (mode) { + case ADD -> loveTicks += changeTicks; + case REMOVE -> loveTicks -= changeTicks; + case SET -> loveTicks = changeTicks; + case RESET -> loveTicks = 0; } + animal.setLoveModeTicks(Math.max(loveTicks, 0)); } } From 803c718e3e577c6cd15e7cd570b71ded146d749e Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sun, 22 Sep 2024 13:27:35 +0200 Subject: [PATCH 25/48] update effs --- .../ch/njol/skript/effects/EffBreedable.java | 54 ++++++---------- .../ch/njol/skript/effects/EffLockAge.java | 51 ++++++--------- .../ch/njol/skript/effects/EffMakeAdult.java | 62 ++++++------------- 3 files changed, 58 insertions(+), 109 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffBreedable.java b/src/main/java/ch/njol/skript/effects/EffBreedable.java index cbe18eb4941..6ce99ea025a 100644 --- a/src/main/java/ch/njol/skript/effects/EffBreedable.java +++ b/src/main/java/ch/njol/skript/effects/EffBreedable.java @@ -1,28 +1,9 @@ -/** - * 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.RequiredPlugins; import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Expression; @@ -31,48 +12,51 @@ import org.bukkit.entity.Breedable; import org.bukkit.entity.LivingEntity; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; @Name("Make Breedable") -@Description({ - "Picks whether or not entities will be able to breed.", - "Only works on animals, not all living entities" -}) +@Description("Sets whether or not entities will be able to breed. Only works on animals.") @Examples({ "on spawn of animal:", "\tmake entity unbreedable" }) @Since("INSERT VERSION") -@RequiredPlugins("MC 1.16+") public class EffBreedable extends Effect { static { if (Skript.classExists("org.bukkit.entity.Breedable")) - Skript.registerEffect(EffBreedable.class, "make %livingentities% [negate:(not |non(-| )|un)]breedable"); + Skript.registerEffect(EffBreedable.class, + "make %livingentities% breedable", + "unsterilize %livingentities%", + "make %livingentities% (not |non(-| )|un)breedable", + "sterilize %livingentities%"); } - private boolean canBreed; + private boolean sterilize; private Expression entities; @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - canBreed = !parseResult.hasTag("negate"); - entities = (Expression) exprs[0]; + @SuppressWarnings("unchecked") + public boolean init(Expression[] expressions, int matchedPattern, + Kleenean isDelayed, ParseResult parseResult) { + sterilize = matchedPattern > 1; + entities = (Expression) expressions[0]; return true; } @Override protected void execute(Event event) { - for (LivingEntity livingEntity : entities.getArray(event)) { - if (livingEntity instanceof Breedable) { - ((Breedable) livingEntity).setBreed(canBreed); - } + for (LivingEntity entity : entities.getArray(event)) { + if (!(entity instanceof Breedable breedable)) + continue; + + breedable.setBreed(!sterilize); } } @Override public String toString(@Nullable Event event, boolean debug) { - return "make " + entities.toString(event, debug) + (canBreed ? " " : " non-") + "breedable"; + return "make " + entities.toString(event, debug) + (sterilize ? " non-" : " ") + "breedable"; } } diff --git a/src/main/java/ch/njol/skript/effects/EffLockAge.java b/src/main/java/ch/njol/skript/effects/EffLockAge.java index 5edd62610ac..a121cc9b733 100644 --- a/src/main/java/ch/njol/skript/effects/EffLockAge.java +++ b/src/main/java/ch/njol/skript/effects/EffLockAge.java @@ -1,28 +1,9 @@ -/** - * 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.RequiredPlugins; import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Expression; @@ -31,39 +12,47 @@ import org.bukkit.entity.Breedable; import org.bukkit.entity.LivingEntity; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; -@Name("Lock Age") -@Description("Picks whether or not entities will be able to age or mate.") +@Name("Allow Aging") +@Description("Sets whether or not living entities will be able to age.") @Examples({ "on spawn of animal:", "\tlock age of entity" }) @Since("INSERT VERSION") -@RequiredPlugins("MC 1.16+") public class EffLockAge extends Effect { static { if (Skript.classExists("org.bukkit.entity.Breedable")) - Skript.registerEffect(EffLockAge.class, "(lock|:unlock) age of %livingentities%"); + Skript.registerEffect(EffLockAge.class, + "lock age of %livingentities%", + "prevent aging of %livingentities%", + "prevent %livingentities% from aging", + "unlock age of %livingentities%", + "allow aging of %livingentities%", + "allow %livingentities% to age"); } - private Expression entities; private boolean unlock; + private Expression entities; @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - entities = (Expression) exprs[0]; - unlock = parseResult.hasTag("unlock"); + @SuppressWarnings("unchecked") + public boolean init(Expression[] expressions, int matchedPattern, + Kleenean isDelayed, ParseResult parseResult) { + entities = (Expression) expressions[0]; + unlock = matchedPattern > 2; return true; } @Override protected void execute(Event event) { for (LivingEntity livingEntity : entities.getArray(event)) { - if (livingEntity instanceof Breedable) { - ((Breedable) livingEntity).setAgeLock(!unlock); - } + if (!(livingEntity instanceof Breedable breedable)) + continue; + + breedable.setAgeLock(!unlock); } } diff --git a/src/main/java/ch/njol/skript/effects/EffMakeAdult.java b/src/main/java/ch/njol/skript/effects/EffMakeAdult.java index 3dbb1643a04..431b52191d9 100644 --- a/src/main/java/ch/njol/skript/effects/EffMakeAdult.java +++ b/src/main/java/ch/njol/skript/effects/EffMakeAdult.java @@ -1,85 +1,61 @@ -/** - * 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.RequiredPlugins; import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; import org.bukkit.entity.Ageable; -import org.bukkit.entity.Animals; import org.bukkit.entity.LivingEntity; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; -@Name("Make Adult") -@Description("Force a animal to become an adult or baby, requires MC 1.16 for any mob") +@Name("Make Adult/Baby") +@Description("Force a animal to become an adult or baby.") @Examples({ "on spawn of mob:", - "\tentity is not an adult", - "\tmake entity an adult", + "\tentity is not an adult", + "\tmake entity an adult", }) @Since("INSERT VERSION") -@RequiredPlugins("1.16+ (Mobs)") public class EffMakeAdult extends Effect { - // This is required since before 1.16 the `setBaby`/'setAdult' method only supported Animals - private static final boolean HAS_MOB_SUPPORT = Skript.isRunningMinecraft(1, 16, 5); - static { Skript.registerEffect(EffMakeAdult.class, "make %livingentities% [a[n]] (adult|:baby)"); } - private boolean makeBaby; + private boolean baby; private Expression entities; @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - entities = (Expression) exprs[0]; - makeBaby = parseResult.hasTag("baby"); + public boolean init(Expression[] expressions, int matchedPattern, + Kleenean isDelayed, ParseResult parseResult) { + baby = parseResult.hasTag("baby"); + entities = (Expression) expressions[0]; return true; } @Override protected void execute(Event event) { - for (LivingEntity livingEntity : entities.getArray(event)) { - if (livingEntity instanceof Ageable) { - if (!HAS_MOB_SUPPORT && !(livingEntity instanceof Animals)) - continue; - if (makeBaby) { - ((Ageable) livingEntity).setBaby(); - } else { - ((Ageable) livingEntity).setAdult(); - } + for (LivingEntity entity : entities.getArray(event)) { + if (!(entity instanceof Ageable ageable)) + continue; + + if (baby) { + ageable.setBaby(); + } else { + ageable.setAdult(); } } } @Override public String toString(@Nullable Event event, boolean debug) { - return "make " + entities + (makeBaby ? " a baby" : " an adult"); + return "make " + entities + (baby ? " a baby" : " an adult"); } } From fe00590b1010ca1113aedaff5ce73a9d1dd70e89 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sun, 22 Sep 2024 13:30:31 +0200 Subject: [PATCH 26/48] update event values --- .../skript/classes/data/BukkitEventValues.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java index 150cf743305..29eea072478 100644 --- a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java +++ b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java @@ -1757,26 +1757,24 @@ public Location get(LootGenerateEvent event) { } // EntityBreedEvent - EventValues.registerEventValue(EntityBreedEvent.class, ItemStack.class, new Getter() { + EventValues.registerEventValue(EntityBreedEvent.class, ItemStack.class, new Getter<>() { @Override - @Nullable - public ItemStack get(EntityBreedEvent event) { + public @Nullable ItemStack get(EntityBreedEvent event) { return event.getBredWith(); } }, EventValues.TIME_NOW); if (Skript.classExists("org.bukkit.event.entity.EntityEnterLoveModeEvent")) { - EventValues.registerEventValue(EntityEnterLoveModeEvent.class, LivingEntity.class, new Getter() { + EventValues.registerEventValue(EntityEnterLoveModeEvent.class, LivingEntity.class, new Getter<>() { @Override - @Nullable public LivingEntity get(EntityEnterLoveModeEvent event) { return event.getEntity(); } }, EventValues.TIME_NOW); - EventValues.registerEventValue(EntityEnterLoveModeEvent.class, HumanEntity.class, new Getter() { + + EventValues.registerEventValue(EntityEnterLoveModeEvent.class, HumanEntity.class, new Getter<>() { @Override - @Nullable - public HumanEntity get(EntityEnterLoveModeEvent event) { + public @Nullable HumanEntity get(EntityEnterLoveModeEvent event) { return event.getHumanEntity(); } }, EventValues.TIME_NOW); From 91b9ee1933742ec8b042ff1486a03ed2fd3e7a04 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sun, 22 Sep 2024 13:47:05 +0200 Subject: [PATCH 27/48] update annot --- src/main/java/ch/njol/skript/expressions/ExprExperience.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprExperience.java b/src/main/java/ch/njol/skript/expressions/ExprExperience.java index b8436b17628..be972e907c9 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExperience.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExperience.java @@ -15,7 +15,7 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.entity.EntityBreedEvent; import org.bukkit.event.player.PlayerExpChangeEvent; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; @Name("Experience") @Description("How much experience was spawned in an experience spawn or block break event. Can be changed.") From 50187703b5c4b53a3f0620a0609f828d92ff4069 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sun, 22 Sep 2024 13:58:43 +0200 Subject: [PATCH 28/48] update annotations --- .../skript/effects/{EffLockAge.java => EffAllowAging.java} | 4 ++-- .../ch/njol/skript/expressions/ExprBreedingFamily.java | 6 +++--- .../java/ch/njol/skript/expressions/ExprExperience.java | 7 ++++--- src/main/java/ch/njol/skript/expressions/ExprLoveTime.java | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) rename src/main/java/ch/njol/skript/effects/{EffLockAge.java => EffAllowAging.java} (95%) diff --git a/src/main/java/ch/njol/skript/effects/EffLockAge.java b/src/main/java/ch/njol/skript/effects/EffAllowAging.java similarity index 95% rename from src/main/java/ch/njol/skript/effects/EffLockAge.java rename to src/main/java/ch/njol/skript/effects/EffAllowAging.java index a121cc9b733..d35f4dad066 100644 --- a/src/main/java/ch/njol/skript/effects/EffLockAge.java +++ b/src/main/java/ch/njol/skript/effects/EffAllowAging.java @@ -21,11 +21,11 @@ "\tlock age of entity" }) @Since("INSERT VERSION") -public class EffLockAge extends Effect { +public class EffAllowAging extends Effect { static { if (Skript.classExists("org.bukkit.entity.Breedable")) - Skript.registerEffect(EffLockAge.class, + Skript.registerEffect(EffAllowAging.class, "lock age of %livingentities%", "prevent aging of %livingentities%", "prevent %livingentities% from aging", diff --git a/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java b/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java index a49b6e679e2..41fb67f06cc 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java +++ b/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java @@ -13,7 +13,7 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.event.Event; import org.bukkit.event.entity.EntityBreedEvent; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; @Name("Breeding Family") @Description("Represents family members within a breeding event.") @@ -27,8 +27,8 @@ public class ExprBreedingFamily extends SimpleExpression { static { Skript.registerExpression(ExprBreedingFamily.class, LivingEntity.class, ExpressionType.SIMPLE, - "[the] breed[ing] mother", - "[the] breed[ing] father", + "[the] breeding mother", + "[the] breeding father", "[the] [bred] (offspring|child)", "[the] breeder"); } diff --git a/src/main/java/ch/njol/skript/expressions/ExprExperience.java b/src/main/java/ch/njol/skript/expressions/ExprExperience.java index be972e907c9..fa66a081dfe 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExperience.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExperience.java @@ -74,15 +74,16 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Nullable public Class[] acceptChange(ChangeMode mode) { return switch (mode) { - case SET, DELETE, RESET -> CollectionUtils.array(Experience.class, Integer.class); + case SET, DELETE -> CollectionUtils.array(Experience.class, Integer.class); case ADD, REMOVE -> CollectionUtils.array(Experience[].class, Integer[].class); + case RESET -> CollectionUtils.array(); default -> null; }; } @Override public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { - int exp = 0; + int exp; switch (event) { case ExperienceSpawnEvent experienceSpawnEvent -> exp = experienceSpawnEvent.getSpawnedXP(); @@ -101,7 +102,7 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { switch (mode) { case ADD -> exp += value; case SET -> exp = value; - case REMOVE -> exp -= value; + case REMOVE, REMOVE_ALL -> exp -= value; } } } diff --git a/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java b/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java index 66669a36a15..8505b9bcbf0 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java +++ b/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java @@ -11,7 +11,7 @@ import org.bukkit.entity.Animals; import org.bukkit.entity.LivingEntity; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; @Name("Love Time") @Description({ From 28c1ac3e0fb19032a9585a05b0401dbb270d5aab Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sun, 22 Sep 2024 14:02:34 +0200 Subject: [PATCH 29/48] update CondIsInLove --- .../java/ch/njol/skript/conditions/CondIsInLove.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsInLove.java b/src/main/java/ch/njol/skript/conditions/CondIsInLove.java index 6c2e166924a..ed83b302a35 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsInLove.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsInLove.java @@ -13,7 +13,7 @@ @Examples({ "on spawn of living entity:", "\tif entity is in love:", - "" + "broadcast \"That was quick!\"" }) @Since("INSERT VERSION") public class CondIsInLove extends PropertyCondition { @@ -23,9 +23,10 @@ public class CondIsInLove extends PropertyCondition { } @Override - public boolean check(LivingEntity livingEntity) { - if (livingEntity instanceof Animals) - return ((Animals) livingEntity).isLoveMode(); + public boolean check(LivingEntity entity) { + if (entity instanceof Animals animals) + return animals.isLoveMode(); + return false; } From f0a12da702cf3c666fbbfd07648207929666bcbc Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sun, 22 Sep 2024 14:22:49 +0200 Subject: [PATCH 30/48] renames --- .../conditions/{CondIsChild.java => CondIsBaby.java} | 12 ++++++------ .../java/ch/njol/skript/conditions/CondIsInLove.java | 2 +- .../{EffMakeAdult.java => EffMakeAdultOrBaby.java} | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) rename src/main/java/ch/njol/skript/conditions/{CondIsChild.java => CondIsBaby.java} (69%) rename src/main/java/ch/njol/skript/effects/{EffMakeAdult.java => EffMakeAdultOrBaby.java} (90%) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsChild.java b/src/main/java/ch/njol/skript/conditions/CondIsBaby.java similarity index 69% rename from src/main/java/ch/njol/skript/conditions/CondIsChild.java rename to src/main/java/ch/njol/skript/conditions/CondIsBaby.java index c62fc407724..a159b0e6c1a 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsChild.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsBaby.java @@ -8,18 +8,18 @@ import org.bukkit.entity.Ageable; import org.bukkit.entity.LivingEntity; -@Name("Is Child") -@Description("Returns whether or not a living entity is a child.") +@Name("Is Baby") +@Description("Returns whether or not a living entity is a baby.") @Examples({ "on drink:", - "\tevent-entity is a child", + "\tevent-entity is a baby", "\tkill event-entity" }) @Since("INSERT VERSION") -public class CondIsChild extends PropertyCondition { +public class CondIsBaby extends PropertyCondition { static { - register(CondIsChild.class, "[a] child", "livingentities"); + register(CondIsBaby.class, "[a] (child|baby)", "livingentities"); } @Override @@ -32,7 +32,7 @@ public boolean check(LivingEntity entity) { @Override protected String getPropertyName() { - return "a child"; + return "a baby"; } } diff --git a/src/main/java/ch/njol/skript/conditions/CondIsInLove.java b/src/main/java/ch/njol/skript/conditions/CondIsInLove.java index ed83b302a35..d6768b68e41 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsInLove.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsInLove.java @@ -9,7 +9,7 @@ import org.bukkit.entity.LivingEntity; @Name("Is In Love") -@Description("Whether or not the animals are currently in the love state.") +@Description("Checks whether or not a living entity is in love.") @Examples({ "on spawn of living entity:", "\tif entity is in love:", diff --git a/src/main/java/ch/njol/skript/effects/EffMakeAdult.java b/src/main/java/ch/njol/skript/effects/EffMakeAdultOrBaby.java similarity index 90% rename from src/main/java/ch/njol/skript/effects/EffMakeAdult.java rename to src/main/java/ch/njol/skript/effects/EffMakeAdultOrBaby.java index 431b52191d9..5e025932d7b 100644 --- a/src/main/java/ch/njol/skript/effects/EffMakeAdult.java +++ b/src/main/java/ch/njol/skript/effects/EffMakeAdultOrBaby.java @@ -22,10 +22,10 @@ "\tmake entity an adult", }) @Since("INSERT VERSION") -public class EffMakeAdult extends Effect { +public class EffMakeAdultOrBaby extends Effect { static { - Skript.registerEffect(EffMakeAdult.class, "make %livingentities% [a[n]] (adult|:baby)"); + Skript.registerEffect(EffMakeAdultOrBaby.class, "make %livingentities% [a[n]] (adult|:baby)"); } private boolean baby; From 987ff80117a136cd9740133d956df576900c833e Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sun, 22 Sep 2024 14:28:04 +0200 Subject: [PATCH 31/48] updates --- .../ch/njol/skript/conditions/CondCanAge.java | 5 ++--- .../ch/njol/skript/conditions/CondCanBreed.java | 5 ++--- .../ch/njol/skript/conditions/CondIsAdult.java | 2 +- .../ch/njol/skript/conditions/CondIsBaby.java | 2 +- .../ch/njol/skript/effects/EffAllowAging.java | 15 +++++++-------- .../ch/njol/skript/effects/EffBreedable.java | 11 +++++------ .../ch/njol/skript/events/SimpleEvents.java | 17 +++++++---------- 7 files changed, 25 insertions(+), 32 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondCanAge.java b/src/main/java/ch/njol/skript/conditions/CondCanAge.java index a2b234f2db9..e5a95c2fee4 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanAge.java +++ b/src/main/java/ch/njol/skript/conditions/CondCanAge.java @@ -10,7 +10,7 @@ import org.bukkit.entity.LivingEntity; @Name("Can Age") -@Description("Returns whether or not an entity will be able to age/grow up.") +@Description("Checks whether or not an entity will be able to age/grow up.") @Examples({ "on breeding:", "\tentity can't age", @@ -20,8 +20,7 @@ public class CondCanAge extends PropertyCondition { static { - if (Skript.classExists("org.bukkit.entity.Breedable")) - register(CondCanAge.class, PropertyType.CAN, "age", "livingentities"); + register(CondCanAge.class, PropertyType.CAN, "age", "livingentities"); } @Override diff --git a/src/main/java/ch/njol/skript/conditions/CondCanBreed.java b/src/main/java/ch/njol/skript/conditions/CondCanBreed.java index c19fe1cf3a9..ef7f6e94077 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanBreed.java +++ b/src/main/java/ch/njol/skript/conditions/CondCanBreed.java @@ -10,7 +10,7 @@ import org.bukkit.entity.LivingEntity; @Name("Can Breed") -@Description("Returns whether or not a living entity can be bred.") +@Description("Checks whether or not a living entity can be bred.") @Examples({ "on right click on living entity:", "\tevent-entity can't breed", @@ -20,8 +20,7 @@ public class CondCanBreed extends PropertyCondition { static { - if (Skript.classExists("org.bukkit.entity.Breedable")) - register(CondCanBreed.class, PropertyType.CAN, "breed", "livingentities"); + register(CondCanBreed.class, PropertyType.CAN, "breed", "livingentities"); } @Override diff --git a/src/main/java/ch/njol/skript/conditions/CondIsAdult.java b/src/main/java/ch/njol/skript/conditions/CondIsAdult.java index a9d0199e4c6..f477759f2aa 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsAdult.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsAdult.java @@ -9,7 +9,7 @@ import org.bukkit.entity.LivingEntity; @Name("Is Adult") -@Description("Returns whether or not a living entity is an adult.") +@Description("Checks whether or not a living entity is an adult.") @Examples({ "on drink:", "\tevent-entity is not an adult", diff --git a/src/main/java/ch/njol/skript/conditions/CondIsBaby.java b/src/main/java/ch/njol/skript/conditions/CondIsBaby.java index a159b0e6c1a..c0b5a5ad878 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsBaby.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsBaby.java @@ -9,7 +9,7 @@ import org.bukkit.entity.LivingEntity; @Name("Is Baby") -@Description("Returns whether or not a living entity is a baby.") +@Description("Checks whether or not a living entity is a baby.") @Examples({ "on drink:", "\tevent-entity is a baby", diff --git a/src/main/java/ch/njol/skript/effects/EffAllowAging.java b/src/main/java/ch/njol/skript/effects/EffAllowAging.java index d35f4dad066..86172db5d54 100644 --- a/src/main/java/ch/njol/skript/effects/EffAllowAging.java +++ b/src/main/java/ch/njol/skript/effects/EffAllowAging.java @@ -24,14 +24,13 @@ public class EffAllowAging extends Effect { static { - if (Skript.classExists("org.bukkit.entity.Breedable")) - Skript.registerEffect(EffAllowAging.class, - "lock age of %livingentities%", - "prevent aging of %livingentities%", - "prevent %livingentities% from aging", - "unlock age of %livingentities%", - "allow aging of %livingentities%", - "allow %livingentities% to age"); + Skript.registerEffect(EffAllowAging.class, + "lock age of %livingentities%", + "prevent aging of %livingentities%", + "prevent %livingentities% from aging", + "unlock age of %livingentities%", + "allow aging of %livingentities%", + "allow %livingentities% to age"); } private boolean unlock; diff --git a/src/main/java/ch/njol/skript/effects/EffBreedable.java b/src/main/java/ch/njol/skript/effects/EffBreedable.java index 6ce99ea025a..9010035104f 100644 --- a/src/main/java/ch/njol/skript/effects/EffBreedable.java +++ b/src/main/java/ch/njol/skript/effects/EffBreedable.java @@ -24,12 +24,11 @@ public class EffBreedable extends Effect { static { - if (Skript.classExists("org.bukkit.entity.Breedable")) - Skript.registerEffect(EffBreedable.class, - "make %livingentities% breedable", - "unsterilize %livingentities%", - "make %livingentities% (not |non(-| )|un)breedable", - "sterilize %livingentities%"); + Skript.registerEffect(EffBreedable.class, + "make %livingentities% breedable", + "unsterilize %livingentities%", + "make %livingentities% (not |non(-| )|un)breedable", + "sterilize %livingentities%"); } private boolean sterilize; diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index 68010684427..3f6d94632a9 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -739,16 +739,13 @@ public class SimpleEvents { "\tsend \"When a %breeding mother% and %breeding father% love each other they make %offspring%\" to breeder" ) .since("INSERT VERSION"); - if (Skript.classExists("org.bukkit.event.entity.EntityEnterLoveModeEvent")) { - Skript.registerEvent("Love Mode Enter", SimpleEvent.class, EntityEnterLoveModeEvent.class, "[entity] enter[s] love mode", "[entity] love mode [enter]") - .description("Called whenever an entity enters a state of being in love.") - .examples( - "on love mode enter:", - "\tcancel event # No one is allowed love here" - ) - .since("INSERT VERSION") - .requiredPlugins("MC 1.16+"); - } + Skript.registerEvent("Love Mode Enter", SimpleEvent.class, EntityEnterLoveModeEvent.class, "[entity] enter[s] love mode", "[entity] love mode [enter]") + .description("Called whenever an entity enters a state of being in love.") + .examples( + "on love mode enter:", + "\tcancel event # No one is allowed love here" + ) + .since("INSERT VERSION"); Skript.registerEvent("Player Pickup Arrow", SimpleEvent.class, PlayerPickupArrowEvent.class, "[player] (pick[ing| ]up [an] arrow|arrow pick[ing| ]up)") .description("Called when a player picks up an arrow from the ground.") From 11dbd44f68b6b680710f4e7a6b1650f4c87d907b Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sun, 22 Sep 2024 23:56:25 +0200 Subject: [PATCH 32/48] update tests --- .../skript/expressions/ExprExperience.java | 33 ++++++++++--------- .../tests/syntaxes/conditions/CondIsInLove.sk | 22 ++++++------- .../tests/syntaxes/effects/EffAllowAging.sk | 11 +++++++ .../tests/syntaxes/effects/EffBreedable.sk | 8 ++--- .../tests/syntaxes/effects/EffLockAge.sk | 11 ------- .../tests/syntaxes/effects/EffMakeAdult.sk | 16 ++++----- 6 files changed, 52 insertions(+), 49 deletions(-) create mode 100644 src/test/skript/tests/syntaxes/effects/EffAllowAging.sk delete mode 100644 src/test/skript/tests/syntaxes/effects/EffLockAge.sk diff --git a/src/main/java/ch/njol/skript/expressions/ExprExperience.java b/src/main/java/ch/njol/skript/expressions/ExprExperience.java index fa66a081dfe..60cb4cb58b1 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExperience.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExperience.java @@ -85,15 +85,16 @@ public Class[] acceptChange(ChangeMode mode) { public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { int exp; - switch (event) { - case ExperienceSpawnEvent experienceSpawnEvent -> exp = experienceSpawnEvent.getSpawnedXP(); - case BlockBreakEvent blockBreakEvent -> exp = blockBreakEvent.getExpToDrop(); - case PlayerExpChangeEvent playerExpChangeEvent -> exp = playerExpChangeEvent.getAmount(); - case EntityBreedEvent entityBreedEvent -> exp = entityBreedEvent.getExperience(); - - default -> { - return; - } + if (event instanceof ExperienceSpawnEvent experienceSpawnEvent) { + exp = experienceSpawnEvent.getSpawnedXP(); + } else if (event instanceof BlockBreakEvent blockBreakEvent) { + exp = blockBreakEvent.getExpToDrop(); + } else if (event instanceof PlayerExpChangeEvent playerExpChangeEvent) { + exp = playerExpChangeEvent.getAmount(); + } else if (event instanceof EntityBreedEvent entityBreedEvent) { + exp = entityBreedEvent.getExperience(); + } else { + return; } if (delta != null) { @@ -108,12 +109,14 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { } exp = Math.max(0, exp); - switch (event) { - case ExperienceSpawnEvent experienceSpawnEvent -> experienceSpawnEvent.setSpawnedXP(exp); - case BlockBreakEvent blockBreakEvent -> blockBreakEvent.setExpToDrop(exp); - case PlayerExpChangeEvent playerExpChangeEvent -> playerExpChangeEvent.setAmount(exp); - case EntityBreedEvent entityBreedEvent -> entityBreedEvent.setExperience(exp); - default -> {} + if (event instanceof ExperienceSpawnEvent experienceSpawnEvent) { + experienceSpawnEvent.setSpawnedXP(exp); + } else if (event instanceof BlockBreakEvent blockBreakEvent) { + blockBreakEvent.setExpToDrop(exp); + } else if (event instanceof PlayerExpChangeEvent playerExpChangeEvent) { + playerExpChangeEvent.setAmount(exp); + } else if (event instanceof EntityBreedEvent entityBreedEvent) { + entityBreedEvent.setExperience(exp); } } diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk b/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk index eb3df35c0e6..df8fb4472a6 100644 --- a/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk +++ b/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk @@ -1,28 +1,28 @@ -test "CondIsInLove - Valid Entity": +test "valid entity is in love": delete all cows set {_spawn} to spawn of world "world" spawn adult cow at {_spawn} set {_cow} to last spawned cow - assert love time of {_cow} is 0 seconds with "Cow love time was not 0 seconds after spawning" - assert {_cow} is not in love with "Cow is in love after spawning" + assert love time of {_cow} is 0 seconds with "cow love time was not 0 seconds after spawning" + assert {_cow} is not in love with "cow is in love after spawning" set love time of {_cow} to 10 seconds - assert {_cow} is in love with "Cow is not in love after setting love time" + assert {_cow} is in love with "cow is not in love after setting love time" add 10 seconds to love time of {_cow} - assert love time of {_cow} > 10 seconds with "Cow love time didn't go up after adding" + assert love time of {_cow} > 10 seconds with "cow love time didn't go up after adding" remove 1 minute from love time of {_cow} - assert {_cow} is not in love with "Cow is in love after removing more love than possible" + assert {_cow} is not in love with "cow is in love after removing more love than possible" add 10 minutes to love time of {_cow} - assert {_cow} is in love with "Cow didn't enter love mode after adding love time" + assert {_cow} is in love with "cow didn't enter love mode after adding love time" reset love time of {_cow} - assert {_cow} is not in love with "Cow was still in love even after resetting love time" + assert {_cow} is not in love with "cow was still in love even after resetting love time" delete all cows -test "CondIsInLove - Invalid Entity": +test "invalid entity is in love": delete all zombies set {_spawn} to spawn of world "world" spawn adult zombie at {_spawn} set {_zombie} to last spawned zombie - assert love time of {_zombie} is 0 seconds with "Zombie was in love Test1" + assert love time of {_zombie} is 0 seconds with "zombie was in love on spawn" set love time of {_zombie} to 10 minutes - assert love time of {_zombie} is 0 seconds with "Zombie was in love Test2" + assert love time of {_zombie} is 0 seconds with "zombie was in love after set" delete all zombies diff --git a/src/test/skript/tests/syntaxes/effects/EffAllowAging.sk b/src/test/skript/tests/syntaxes/effects/EffAllowAging.sk new file mode 100644 index 00000000000..feaaa722191 --- /dev/null +++ b/src/test/skript/tests/syntaxes/effects/EffAllowAging.sk @@ -0,0 +1,11 @@ +test "allow aging": + delete all pigs + set {_spawn} to spawn of world "world" + spawn baby pig at {_spawn} + set {_pig} to last spawned pig + assert {_pig} can age with "baby pig can't age before locking" + lock age of {_pig} + assert {_pig} can't age with "baby pig can still age after locking" + unlock age of {_pig} + assert {_pig} can age with "baby pig can't age after unlocking" + delete all pigs diff --git a/src/test/skript/tests/syntaxes/effects/EffBreedable.sk b/src/test/skript/tests/syntaxes/effects/EffBreedable.sk index f1cdb22121b..9eda1d1b698 100644 --- a/src/test/skript/tests/syntaxes/effects/EffBreedable.sk +++ b/src/test/skript/tests/syntaxes/effects/EffBreedable.sk @@ -1,11 +1,11 @@ -test "breedable" when running minecraft "1.16.5": +test "breedable": delete all chickens set {_spawn} to spawn of world "world" spawn baby chicken at {_spawn} set {_chicken} to last spawned chicken - assert {_chicken} can't breed with "Chicken could breed before growing up" + assert {_chicken} can't breed with "chicken could breed before growing up" make {_chicken} breedable - assert {_chicken} can breed with "Chicken can't breed after growing up" + assert {_chicken} can breed with "chicken can't breed after growing up" make {_chicken} non-breedable - assert {_chicken} can't breed with "Chicken can breed after growing up and preventing" + assert {_chicken} can't breed with "chicken can breed after growing up and preventing" delete all chickens diff --git a/src/test/skript/tests/syntaxes/effects/EffLockAge.sk b/src/test/skript/tests/syntaxes/effects/EffLockAge.sk deleted file mode 100644 index 3373cfa78b2..00000000000 --- a/src/test/skript/tests/syntaxes/effects/EffLockAge.sk +++ /dev/null @@ -1,11 +0,0 @@ -test "locking age" when running minecraft "1.16.5": - delete all pigs - set {_spawn} to spawn of world "world" - spawn baby pig at {_spawn} - set {_pig} to last spawned pig - assert {_pig} can age with "Baby pig can't age before locking Test1" - lock age of {_pig} - assert {_pig} can't age with "Baby pig can still age after locking" - unlock age of {_pig} - assert {_pig} can age with "Baby pig can't age after unlocking Test2" - delete all pigs diff --git a/src/test/skript/tests/syntaxes/effects/EffMakeAdult.sk b/src/test/skript/tests/syntaxes/effects/EffMakeAdult.sk index 2f9bce0093c..f26b286d4ad 100644 --- a/src/test/skript/tests/syntaxes/effects/EffMakeAdult.sk +++ b/src/test/skript/tests/syntaxes/effects/EffMakeAdult.sk @@ -1,23 +1,23 @@ -test "effect make adult 1" when running minecraft "1.16.5": +test "make mob adult": delete all zombies set {_spawn} to spawn of world "world" spawn baby zombie at {_spawn} set {_zombie} to last spawned zombie - assert {_zombie} is not an adult with "Spawned zombie was an adult" + assert {_zombie} is not an adult with "spawned zombie was an adult" make {_zombie} an adult - assert {_zombie} is an adult with "Spawned zombie is still a baby zombie" + assert {_zombie} is an adult with "spawned zombie is still a baby zombie" make {_zombie} a baby - assert {_zombie} is not an adult with "Spawned zombie didn't become a baby zombie" + assert {_zombie} is not an adult with "spawned zombie didn't become a baby zombie" delete all zombies -test "effect make adult 2": +test "make animal adult": delete all sheep set {_spawn} to spawn of world "world" spawn baby sheep at {_spawn} set {_sheep} to last spawned sheep - assert {_sheep} is not an adult with "Spawned sheep was an adult" + assert {_sheep} is not an adult with "spawned sheep was an adult" make {_sheep} an adult - assert {_sheep} is an adult with "Spawned sheep is still a baby sheep" + assert {_sheep} is an adult with "spawned sheep is still a baby sheep" make {_sheep} a baby - assert {_sheep} is not an adult with "Spawned sheep didn't become a baby sheep" + assert {_sheep} is not an adult with "spawned sheep didn't become a baby sheep" delete all sheep From 7715a6548b871debb2dae03d1a1009b78a161798 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sun, 22 Sep 2024 23:56:56 +0200 Subject: [PATCH 33/48] oops --- .../syntaxes/effects/{EffMakeAdult.sk => EffMakeAdultOrBaby.sk} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/test/skript/tests/syntaxes/effects/{EffMakeAdult.sk => EffMakeAdultOrBaby.sk} (100%) diff --git a/src/test/skript/tests/syntaxes/effects/EffMakeAdult.sk b/src/test/skript/tests/syntaxes/effects/EffMakeAdultOrBaby.sk similarity index 100% rename from src/test/skript/tests/syntaxes/effects/EffMakeAdult.sk rename to src/test/skript/tests/syntaxes/effects/EffMakeAdultOrBaby.sk From 24e3c2b88264d32617a23a95f72eb9c253df6659 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sun, 22 Sep 2024 23:58:05 +0200 Subject: [PATCH 34/48] fix --- .../classes/data/BukkitEventValues.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java index db8afb4bc6a..e1b7caa6add 100644 --- a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java +++ b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java @@ -1811,21 +1811,19 @@ public Location get(LootGenerateEvent event) { } }, EventValues.TIME_NOW); - if (Skript.classExists("org.bukkit.event.entity.EntityEnterLoveModeEvent")) { - EventValues.registerEventValue(EntityEnterLoveModeEvent.class, LivingEntity.class, new Getter<>() { - @Override - public LivingEntity get(EntityEnterLoveModeEvent event) { - return event.getEntity(); - } - }, EventValues.TIME_NOW); + EventValues.registerEventValue(EntityEnterLoveModeEvent.class, LivingEntity.class, new Getter<>() { + @Override + public LivingEntity get(EntityEnterLoveModeEvent event) { + return event.getEntity(); + } + }, EventValues.TIME_NOW); - EventValues.registerEventValue(EntityEnterLoveModeEvent.class, HumanEntity.class, new Getter<>() { - @Override - public @Nullable HumanEntity get(EntityEnterLoveModeEvent event) { - return event.getHumanEntity(); - } - }, EventValues.TIME_NOW); - } + EventValues.registerEventValue(EntityEnterLoveModeEvent.class, HumanEntity.class, new Getter<>() { + @Override + public @Nullable HumanEntity get(EntityEnterLoveModeEvent event) { + return event.getHumanEntity(); + } + }, EventValues.TIME_NOW); // EntityResurrectEvent EventValues.registerEventValue(EntityResurrectEvent.class, Slot.class, new Getter() { From 05e7627960d346fe254801180241fb4d6a159244 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sun, 22 Sep 2024 23:59:27 +0200 Subject: [PATCH 35/48] grr --- .../skript/expressions/ExprExperience.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprExperience.java b/src/main/java/ch/njol/skript/expressions/ExprExperience.java index 60cb4cb58b1..29c3a7f58ba 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExperience.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExperience.java @@ -17,6 +17,8 @@ import org.bukkit.event.player.PlayerExpChangeEvent; import org.jetbrains.annotations.Nullable; +import java.util.Objects; + @Name("Experience") @Description("How much experience was spawned in an experience spawn or block break event. Can be changed.") @Examples({ @@ -57,17 +59,21 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override protected @Nullable Experience[] get(Event event) { - return switch (event) { - case ExperienceSpawnEvent experienceSpawnEvent -> - new Experience[]{new Experience(experienceSpawnEvent.getSpawnedXP())}; - case BlockBreakEvent blockBreakEvent -> - new Experience[]{new Experience(blockBreakEvent.getExpToDrop())}; - case PlayerExpChangeEvent playerExpChangeEvent -> - new Experience[]{new Experience(playerExpChangeEvent.getAmount())}; - case EntityBreedEvent entityBreedEvent -> - new Experience[]{new Experience(entityBreedEvent.getExperience())}; - default -> new Experience[0]; - }; + Experience[] exp; + + if (event instanceof ExperienceSpawnEvent experienceSpawnEvent) { + exp = new Experience[]{new Experience(experienceSpawnEvent.getSpawnedXP())}; + } else if (event instanceof BlockBreakEvent blockBreakEvent) { + exp = new Experience[]{new Experience(blockBreakEvent.getExpToDrop())}; + } else if (event instanceof PlayerExpChangeEvent playerExpChangeEvent) { + exp = new Experience[]{new Experience(playerExpChangeEvent.getAmount())}; + } else if (event instanceof EntityBreedEvent entityBreedEvent) { + exp = new Experience[]{new Experience(entityBreedEvent.getExperience())}; + } else { + exp = new Experience[0]; + } + + return exp; } @Override From 8b7106f003c3ad7468f46ab746c2200bc0afd0cc Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Mon, 23 Sep 2024 00:02:33 +0200 Subject: [PATCH 36/48] gahr --- src/main/java/ch/njol/skript/conditions/CondCanBreed.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondCanBreed.java b/src/main/java/ch/njol/skript/conditions/CondCanBreed.java index ef7f6e94077..f289ab4199a 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanBreed.java +++ b/src/main/java/ch/njol/skript/conditions/CondCanBreed.java @@ -20,7 +20,7 @@ public class CondCanBreed extends PropertyCondition { static { - register(CondCanBreed.class, PropertyType.CAN, "breed", "livingentities"); + register(CondCanBreed.class, PropertyType.CAN, "(breed|be bred)", "livingentities"); } @Override From d4be4e991ba3f500df48ee374cc78cde864892fc Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Mon, 23 Sep 2024 00:14:32 +0200 Subject: [PATCH 37/48] add breeding trigger event --- .../java/ch/njol/skript/events/EvtBreed.java | 66 +++++++++++++++++++ .../ch/njol/skript/events/SimpleEvents.java | 7 -- 2 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 src/main/java/ch/njol/skript/events/EvtBreed.java diff --git a/src/main/java/ch/njol/skript/events/EvtBreed.java b/src/main/java/ch/njol/skript/events/EvtBreed.java new file mode 100644 index 00000000000..4b07f76f8d7 --- /dev/null +++ b/src/main/java/ch/njol/skript/events/EvtBreed.java @@ -0,0 +1,66 @@ +package ch.njol.skript.events; + +import ch.njol.skript.Skript; +import ch.njol.skript.entity.EntityType; +import ch.njol.skript.lang.Literal; +import ch.njol.skript.lang.SkriptEvent; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.skript.lang.util.SimpleEvent; +import org.bukkit.entity.Entity; +import org.bukkit.event.Event; +import org.bukkit.event.entity.EntityBreedEvent; +import org.jetbrains.annotations.Nullable; + +public class EvtBreed extends SkriptEvent { + + static { + Skript.registerEvent("Entity Breed", SimpleEvent.class, EntityBreedEvent.class, + "[entity] breed[ing] [of %-entitytypes%]") + .description("Called whenever two animals begin to conceive a child. The type can be specified.") + .examples( + "on breeding of llamas:", + "\tsend \"When a %breeding mother% and %breeding father% love each " + + "other very much they make %offspring%\" to breeder" + ) + .since("INSERT VERSION"); + } + + private @Nullable Literal entitiesLiteral; + private EntityType @Nullable [] entities; + + @Override + @SuppressWarnings("unchecked") + public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { + if (args[0] != null) { + entitiesLiteral = ((Literal) args[0]); + entities = entitiesLiteral.getAll(); + } + return true; + } + + @Override + public boolean check(Event event) { + if (!(event instanceof EntityBreedEvent breedEvent)) { + return false; + } + + return checkEntity(breedEvent.getEntity()); + } + + private boolean checkEntity(Entity entity) { + if (entities != null) { + for (EntityType entityType : entities) { + if (entityType.isInstance(entity)) + return true; + } + return false; + } + return true; + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "on breeding" + (entitiesLiteral == null ? "" : " of " + entitiesLiteral); + } + +} diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index 3f6d94632a9..ad7b5556200 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -732,13 +732,6 @@ public class SimpleEvents { .requiredPlugins("Paper 1.16+"); } - Skript.registerEvent("Entity Breed", SimpleEvent.class, EntityBreedEvent.class, "[entity] breed[ing]") - .description("Called whenever two breedable entities begin to conceive a child.") - .examples( - "on breeding:", - "\tsend \"When a %breeding mother% and %breeding father% love each other they make %offspring%\" to breeder" - ) - .since("INSERT VERSION"); Skript.registerEvent("Love Mode Enter", SimpleEvent.class, EntityEnterLoveModeEvent.class, "[entity] enter[s] love mode", "[entity] love mode [enter]") .description("Called whenever an entity enters a state of being in love.") .examples( From 06dd041a7c644bca988dc563c9ea26e5447483bb Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Mon, 23 Sep 2024 23:04:21 +0200 Subject: [PATCH 38/48] more --- .../expressions/ExprBreedingFamily.java | 6 +-- .../tests/syntaxes/events/EvtBreedTest.java | 53 +++++++++++++++++++ src/test/skript/junit/EvtBreed.sk | 27 ++++++++++ .../tests/syntaxes/conditions/CondIsInLove.sk | 2 - .../tests/syntaxes/effects/EffAllowAging.sk | 1 - .../tests/syntaxes/effects/EffBreedable.sk | 1 - .../syntaxes/effects/EffMakeAdultOrBaby.sk | 6 +-- .../syntaxes/expressions/ExprLoveTime.sk | 19 +++++++ 8 files changed, 104 insertions(+), 11 deletions(-) create mode 100644 src/test/java/org/skriptlang/skript/test/tests/syntaxes/events/EvtBreedTest.java create mode 100644 src/test/skript/junit/EvtBreed.sk create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprLoveTime.sk diff --git a/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java b/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java index 41fb67f06cc..de8ab0f5297 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java +++ b/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java @@ -39,16 +39,16 @@ public class ExprBreedingFamily extends SimpleExpression { public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { if (!getParser().isCurrentEvent(EntityBreedEvent.class)) { - Skript.error("'breeding family' expression can only be used within an Entity Breed event."); + Skript.error("The 'breeding family' expression can only be used in an breed event."); return false; } - + pattern = matchedPattern; return true; } @Override - protected @Nullable LivingEntity[] get(Event event) { + protected @Nullable LivingEntity [] get(Event event) { if (!(event instanceof EntityBreedEvent breedEvent)) return new LivingEntity[0]; diff --git a/src/test/java/org/skriptlang/skript/test/tests/syntaxes/events/EvtBreedTest.java b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/events/EvtBreedTest.java new file mode 100644 index 00000000000..be6eb6da784 --- /dev/null +++ b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/events/EvtBreedTest.java @@ -0,0 +1,53 @@ +package org.skriptlang.skript.test.tests.syntaxes.events; + +import ch.njol.skript.test.runner.SkriptJUnitTest; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Pig; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.easymock.EasyMock; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class EvtBreedTest extends SkriptJUnitTest { + + static { + setShutdownDelay(1); + } + + private Pig child; + private Pig mother; + private Pig father; + private Player player; + + @Before + public void before() { + child = spawnTestPig(); + child.setCustomName("child"); + mother = spawnTestPig(); + mother.setCustomName("mother"); + father = spawnTestPig(); + father.setCustomName("father"); + + player = EasyMock.niceMock(Player.class); + EasyMock.expect(player.getName()).andReturn("Efnilite"); + EasyMock.replay(player); + } + + @Test + public void test() { + Bukkit.getPluginManager().callEvent( + new org.bukkit.event.entity.EntityBreedEvent( + child, mother, father, player, new ItemStack(Material.CARROT), 0)); + } + + @After + public void after() { + child.remove(); + mother.remove(); + father.remove(); + } + +} diff --git a/src/test/skript/junit/EvtBreed.sk b/src/test/skript/junit/EvtBreed.sk new file mode 100644 index 00000000000..c585102965f --- /dev/null +++ b/src/test/skript/junit/EvtBreed.sk @@ -0,0 +1,27 @@ +test "EvtBreedJUnit" when running JUnit: + set {_tests::1} to "correct breeder" + set {_tests::2} to "correct breeding mother" + set {_tests::3} to "correct breeding father" + set {_tests::4} to "correct bred child" + set {_tests::5} to "item is carrot" + + ensure junit test "org.skriptlang.skript.test.tests.syntaxes.events.EvtBreedTest" completes {_tests::*} + +on breed of pig: + set {_test} to "org.skriptlang.skript.test.tests.syntaxes.events.EvtBreedTest" + junit test is {_test} + + if breeder is player named "Efnilite": + complete objective "correct breeder" for {_test} + + if breeding mother is pig named "mother": + complete objective "correct breeding mother" for {_test} + + if breeding father is pig named "father": + complete objective "correct breeding father" for {_test} + + if bred child is pig named "child": + complete objective "correct bred child" for {_test} + + if event-item is a carrot: + complete objective "item is carrot" for {_test} \ No newline at end of file diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk b/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk index df8fb4472a6..2a23f4860e8 100644 --- a/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk +++ b/src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk @@ -1,5 +1,4 @@ test "valid entity is in love": - delete all cows set {_spawn} to spawn of world "world" spawn adult cow at {_spawn} set {_cow} to last spawned cow @@ -18,7 +17,6 @@ test "valid entity is in love": delete all cows test "invalid entity is in love": - delete all zombies set {_spawn} to spawn of world "world" spawn adult zombie at {_spawn} set {_zombie} to last spawned zombie diff --git a/src/test/skript/tests/syntaxes/effects/EffAllowAging.sk b/src/test/skript/tests/syntaxes/effects/EffAllowAging.sk index feaaa722191..e79a3f06e18 100644 --- a/src/test/skript/tests/syntaxes/effects/EffAllowAging.sk +++ b/src/test/skript/tests/syntaxes/effects/EffAllowAging.sk @@ -1,5 +1,4 @@ test "allow aging": - delete all pigs set {_spawn} to spawn of world "world" spawn baby pig at {_spawn} set {_pig} to last spawned pig diff --git a/src/test/skript/tests/syntaxes/effects/EffBreedable.sk b/src/test/skript/tests/syntaxes/effects/EffBreedable.sk index 9eda1d1b698..6010f26cff4 100644 --- a/src/test/skript/tests/syntaxes/effects/EffBreedable.sk +++ b/src/test/skript/tests/syntaxes/effects/EffBreedable.sk @@ -1,5 +1,4 @@ test "breedable": - delete all chickens set {_spawn} to spawn of world "world" spawn baby chicken at {_spawn} set {_chicken} to last spawned chicken diff --git a/src/test/skript/tests/syntaxes/effects/EffMakeAdultOrBaby.sk b/src/test/skript/tests/syntaxes/effects/EffMakeAdultOrBaby.sk index f26b286d4ad..749a8159edc 100644 --- a/src/test/skript/tests/syntaxes/effects/EffMakeAdultOrBaby.sk +++ b/src/test/skript/tests/syntaxes/effects/EffMakeAdultOrBaby.sk @@ -1,9 +1,8 @@ test "make mob adult": - delete all zombies set {_spawn} to spawn of world "world" spawn baby zombie at {_spawn} set {_zombie} to last spawned zombie - assert {_zombie} is not an adult with "spawned zombie was an adult" + assert {_zombie} is a baby with "spawned zombie was an adult" make {_zombie} an adult assert {_zombie} is an adult with "spawned zombie is still a baby zombie" make {_zombie} a baby @@ -11,11 +10,10 @@ test "make mob adult": delete all zombies test "make animal adult": - delete all sheep set {_spawn} to spawn of world "world" spawn baby sheep at {_spawn} set {_sheep} to last spawned sheep - assert {_sheep} is not an adult with "spawned sheep was an adult" + assert {_sheep} is a baby with "spawned sheep was an adult" make {_sheep} an adult assert {_sheep} is an adult with "spawned sheep is still a baby sheep" make {_sheep} a baby diff --git a/src/test/skript/tests/syntaxes/expressions/ExprLoveTime.sk b/src/test/skript/tests/syntaxes/expressions/ExprLoveTime.sk new file mode 100644 index 00000000000..bb1eef126b9 --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprLoveTime.sk @@ -0,0 +1,19 @@ +test "love time": + spawn pig at spawn of world "world" + set {_pig} to last spawned pig + + assert love time of {_pig} is 0 seconds + + set love time of {_pig} to 10 seconds + assert love time of {_pig} is 10 seconds + + add 10 seconds to love time of {_pig} + assert love time of {_pig} is 20 seconds + + remove 1 minute from love time of {_pig} + assert love time of {_pig} is 0 seconds + + reset love time of {_pig} + assert love time of {_pig} is 0 seconds + + delete all pigs \ No newline at end of file From 9ab4f4aa03b4256b6415fd19b16703df7b806c42 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Mon, 23 Sep 2024 23:07:26 +0200 Subject: [PATCH 39/48] MORE --- src/main/java/ch/njol/skript/events/EvtBreed.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/events/EvtBreed.java b/src/main/java/ch/njol/skript/events/EvtBreed.java index 4b07f76f8d7..4dbbbeb99f6 100644 --- a/src/main/java/ch/njol/skript/events/EvtBreed.java +++ b/src/main/java/ch/njol/skript/events/EvtBreed.java @@ -5,7 +5,6 @@ import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; import ch.njol.skript.lang.SkriptParser.ParseResult; -import ch.njol.skript.lang.util.SimpleEvent; import org.bukkit.entity.Entity; import org.bukkit.event.Event; import org.bukkit.event.entity.EntityBreedEvent; @@ -14,7 +13,7 @@ public class EvtBreed extends SkriptEvent { static { - Skript.registerEvent("Entity Breed", SimpleEvent.class, EntityBreedEvent.class, + Skript.registerEvent("Entity Breed", EvtBreed.class, EntityBreedEvent.class, "[entity] breed[ing] [of %-entitytypes%]") .description("Called whenever two animals begin to conceive a child. The type can be specified.") .examples( From 555c053567a36d14962c65fde1585c1948e73f2c Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Mon, 23 Sep 2024 23:14:05 +0200 Subject: [PATCH 40/48] MORE!!!! --- src/test/skript/junit/EvtBreed.sk | 20 +++++++++++++++---- .../syntaxes/expressions/ExprLoveTime.sk | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/test/skript/junit/EvtBreed.sk b/src/test/skript/junit/EvtBreed.sk index c585102965f..057511061ba 100644 --- a/src/test/skript/junit/EvtBreed.sk +++ b/src/test/skript/junit/EvtBreed.sk @@ -11,16 +11,28 @@ on breed of pig: set {_test} to "org.skriptlang.skript.test.tests.syntaxes.events.EvtBreedTest" junit test is {_test} - if breeder is player named "Efnilite": + if: + breeder is a player + breeder's name is "Efnilite" + then: complete objective "correct breeder" for {_test} - if breeding mother is pig named "mother": + if: + breeding mother is pig + breeding mother's name is "mother" + then: complete objective "correct breeding mother" for {_test} - if breeding father is pig named "father": + if: + breeding father is pig + breeding father's name is "father" + then: complete objective "correct breeding father" for {_test} - if bred child is pig named "child": + if: + bred child is pig + bred child's name is "child" + then: complete objective "correct bred child" for {_test} if event-item is a carrot: diff --git a/src/test/skript/tests/syntaxes/expressions/ExprLoveTime.sk b/src/test/skript/tests/syntaxes/expressions/ExprLoveTime.sk index bb1eef126b9..04988a641d4 100644 --- a/src/test/skript/tests/syntaxes/expressions/ExprLoveTime.sk +++ b/src/test/skript/tests/syntaxes/expressions/ExprLoveTime.sk @@ -16,4 +16,4 @@ test "love time": reset love time of {_pig} assert love time of {_pig} is 0 seconds - delete all pigs \ No newline at end of file + delete all pigs From fb105b40b6d291730f4b12e1723378f0444a05d4 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Mon, 23 Sep 2024 23:25:56 +0200 Subject: [PATCH 41/48] MORE!!!!!! --- src/test/skript/junit/EvtBreed.sk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/skript/junit/EvtBreed.sk b/src/test/skript/junit/EvtBreed.sk index 057511061ba..52a4091666e 100644 --- a/src/test/skript/junit/EvtBreed.sk +++ b/src/test/skript/junit/EvtBreed.sk @@ -18,13 +18,13 @@ on breed of pig: complete objective "correct breeder" for {_test} if: - breeding mother is pig + breeding mother is a pig breeding mother's name is "mother" then: complete objective "correct breeding mother" for {_test} if: - breeding father is pig + breeding father is a pig breeding father's name is "father" then: complete objective "correct breeding father" for {_test} @@ -36,4 +36,4 @@ on breed of pig: complete objective "correct bred child" for {_test} if event-item is a carrot: - complete objective "item is carrot" for {_test} \ No newline at end of file + complete objective "item is carrot" for {_test} From d74ddc96f2ee2bf97b73281e8c6213a79ccea015 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Mon, 23 Sep 2024 23:31:37 +0200 Subject: [PATCH 42/48] stupid copilot --- .../skript/tests/syntaxes/expressions/ExprLoveTime.sk | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/skript/tests/syntaxes/expressions/ExprLoveTime.sk b/src/test/skript/tests/syntaxes/expressions/ExprLoveTime.sk index 04988a641d4..3e02d51377b 100644 --- a/src/test/skript/tests/syntaxes/expressions/ExprLoveTime.sk +++ b/src/test/skript/tests/syntaxes/expressions/ExprLoveTime.sk @@ -2,18 +2,18 @@ test "love time": spawn pig at spawn of world "world" set {_pig} to last spawned pig - assert love time of {_pig} is 0 seconds + assert love time of {_pig} is 0 seconds with "love time wasn't 0 seconds by default" set love time of {_pig} to 10 seconds - assert love time of {_pig} is 10 seconds + assert love time of {_pig} is 10 seconds with "love time wasn't set to 10 seconds" add 10 seconds to love time of {_pig} - assert love time of {_pig} is 20 seconds + assert love time of {_pig} is 20 seconds with "love time wasn't increased by 10 seconds" remove 1 minute from love time of {_pig} - assert love time of {_pig} is 0 seconds + assert love time of {_pig} is 0 seconds with "love time wasn't decreased by 1 minute" reset love time of {_pig} - assert love time of {_pig} is 0 seconds + assert love time of {_pig} is 0 seconds with "love time wasn't reset" delete all pigs From d43733a4573d34a6cbf43f9f7ec3ca3b8a8b030b Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Mon, 23 Sep 2024 23:38:52 +0200 Subject: [PATCH 43/48] g --- src/main/java/ch/njol/skript/expressions/ExprExperience.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprExperience.java b/src/main/java/ch/njol/skript/expressions/ExprExperience.java index 29c3a7f58ba..70c57147436 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExperience.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExperience.java @@ -17,8 +17,6 @@ import org.bukkit.event.player.PlayerExpChangeEvent; import org.jetbrains.annotations.Nullable; -import java.util.Objects; - @Name("Experience") @Description("How much experience was spawned in an experience spawn or block break event. Can be changed.") @Examples({ @@ -77,8 +75,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye } @Override - @Nullable - public Class[] acceptChange(ChangeMode mode) { + public @Nullable Class[] acceptChange(ChangeMode mode) { return switch (mode) { case SET, DELETE -> CollectionUtils.array(Experience.class, Integer.class); case ADD, REMOVE -> CollectionUtils.array(Experience[].class, Integer[].class); From eff120d5d501a0b43bc856699f0bfc314e70e1b8 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Fri, 27 Sep 2024 01:07:04 +0200 Subject: [PATCH 44/48] fixes --- src/main/java/ch/njol/skript/conditions/CondCanAge.java | 7 ++----- src/main/java/ch/njol/skript/conditions/CondCanBreed.java | 5 +---- src/main/java/ch/njol/skript/conditions/CondIsAdult.java | 5 +---- src/main/java/ch/njol/skript/conditions/CondIsBaby.java | 6 ++---- src/main/java/ch/njol/skript/conditions/CondIsInLove.java | 2 +- src/main/java/ch/njol/skript/effects/EffAllowAging.java | 2 +- src/main/java/ch/njol/skript/effects/EffBreedable.java | 2 +- .../java/ch/njol/skript/effects/EffMakeAdultOrBaby.java | 5 ++++- src/main/java/ch/njol/skript/events/EvtBreed.java | 8 ++------ src/main/java/ch/njol/skript/events/SimpleEvents.java | 3 +-- .../java/ch/njol/skript/expressions/ExprExperience.java | 7 ++++--- 11 files changed, 20 insertions(+), 32 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondCanAge.java b/src/main/java/ch/njol/skript/conditions/CondCanAge.java index e5a95c2fee4..fe5e9848eb1 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanAge.java +++ b/src/main/java/ch/njol/skript/conditions/CondCanAge.java @@ -1,6 +1,5 @@ package ch.njol.skript.conditions; -import ch.njol.skript.Skript; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; @@ -20,14 +19,12 @@ public class CondCanAge extends PropertyCondition { static { - register(CondCanAge.class, PropertyType.CAN, "age", "livingentities"); + register(CondCanAge.class, PropertyType.CAN, "(age|grow (up|old[er]))", "livingentities"); } @Override public boolean check(LivingEntity entity) { - if (entity instanceof Breedable breedable) - return !breedable.getAgeLock(); - return false; + return entity instanceof Breedable breedable && !breedable.getAgeLock(); } @Override diff --git a/src/main/java/ch/njol/skript/conditions/CondCanBreed.java b/src/main/java/ch/njol/skript/conditions/CondCanBreed.java index f289ab4199a..1aafe7653bf 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanBreed.java +++ b/src/main/java/ch/njol/skript/conditions/CondCanBreed.java @@ -25,10 +25,7 @@ public class CondCanBreed extends PropertyCondition { @Override public boolean check(LivingEntity entity) { - if (entity instanceof Breedable breedable) - return breedable.canBreed(); - - return false; + return entity instanceof Breedable breedable && breedable.canBreed(); } @Override diff --git a/src/main/java/ch/njol/skript/conditions/CondIsAdult.java b/src/main/java/ch/njol/skript/conditions/CondIsAdult.java index f477759f2aa..72f5140b8ea 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsAdult.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsAdult.java @@ -24,10 +24,7 @@ public class CondIsAdult extends PropertyCondition { @Override public boolean check(LivingEntity entity) { - if (entity instanceof Ageable ageable) - return ageable.isAdult(); - - return false; + return entity instanceof Ageable ageable && ageable.isAdult(); } @Override diff --git a/src/main/java/ch/njol/skript/conditions/CondIsBaby.java b/src/main/java/ch/njol/skript/conditions/CondIsBaby.java index c0b5a5ad878..1e09e96a9a1 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsBaby.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsBaby.java @@ -19,15 +19,13 @@ public class CondIsBaby extends PropertyCondition { static { - register(CondIsBaby.class, "[a] (child|baby)", "livingentities"); + register(CondIsBaby.class, "a (child|baby)", "livingentities"); } @Override public boolean check(LivingEntity entity) { - if (entity instanceof Ageable ageable) - return !ageable.isAdult(); + return entity instanceof Ageable ageable && !ageable.isAdult(); - return false; } @Override diff --git a/src/main/java/ch/njol/skript/conditions/CondIsInLove.java b/src/main/java/ch/njol/skript/conditions/CondIsInLove.java index d6768b68e41..fec461c3e94 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsInLove.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsInLove.java @@ -19,7 +19,7 @@ public class CondIsInLove extends PropertyCondition { static { - register(CondIsInLove.class, "in lov(e|ing) [state]", "livingentities"); + register(CondIsInLove.class, "in lov(e|ing) [state|mode]", "livingentities"); } @Override diff --git a/src/main/java/ch/njol/skript/effects/EffAllowAging.java b/src/main/java/ch/njol/skript/effects/EffAllowAging.java index 86172db5d54..33d44ac3a42 100644 --- a/src/main/java/ch/njol/skript/effects/EffAllowAging.java +++ b/src/main/java/ch/njol/skript/effects/EffAllowAging.java @@ -37,9 +37,9 @@ public class EffAllowAging extends Effect { private Expression entities; @Override - @SuppressWarnings("unchecked") public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + //noinspection unchecked entities = (Expression) expressions[0]; unlock = matchedPattern > 2; return true; diff --git a/src/main/java/ch/njol/skript/effects/EffBreedable.java b/src/main/java/ch/njol/skript/effects/EffBreedable.java index 9010035104f..4a6c524e9dd 100644 --- a/src/main/java/ch/njol/skript/effects/EffBreedable.java +++ b/src/main/java/ch/njol/skript/effects/EffBreedable.java @@ -35,10 +35,10 @@ public class EffBreedable extends Effect { private Expression entities; @Override - @SuppressWarnings("unchecked") public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { sterilize = matchedPattern > 1; + //noinspection unchecked entities = (Expression) expressions[0]; return true; } diff --git a/src/main/java/ch/njol/skript/effects/EffMakeAdultOrBaby.java b/src/main/java/ch/njol/skript/effects/EffMakeAdultOrBaby.java index 5e025932d7b..da8f27ce383 100644 --- a/src/main/java/ch/njol/skript/effects/EffMakeAdultOrBaby.java +++ b/src/main/java/ch/njol/skript/effects/EffMakeAdultOrBaby.java @@ -25,7 +25,9 @@ public class EffMakeAdultOrBaby extends Effect { static { - Skript.registerEffect(EffMakeAdultOrBaby.class, "make %livingentities% [a[n]] (adult|:baby)"); + Skript.registerEffect(EffMakeAdultOrBaby.class, + "make %livingentities% [a[n]] (adult|:baby)", + "force %livingentities% to be[come] a[n] (adult|:baby)"); } private boolean baby; @@ -35,6 +37,7 @@ public class EffMakeAdultOrBaby extends Effect { public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { baby = parseResult.hasTag("baby"); + //noinspection unchecked entities = (Expression) expressions[0]; return true; } diff --git a/src/main/java/ch/njol/skript/events/EvtBreed.java b/src/main/java/ch/njol/skript/events/EvtBreed.java index 4dbbbeb99f6..06a67a46b2c 100644 --- a/src/main/java/ch/njol/skript/events/EvtBreed.java +++ b/src/main/java/ch/njol/skript/events/EvtBreed.java @@ -28,9 +28,9 @@ public class EvtBreed extends SkriptEvent { private EntityType @Nullable [] entities; @Override - @SuppressWarnings("unchecked") public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { if (args[0] != null) { + //noinspection unchecked entitiesLiteral = ((Literal) args[0]); entities = entitiesLiteral.getAll(); } @@ -39,11 +39,7 @@ public boolean init(Literal[] args, int matchedPattern, ParseResult parseResu @Override public boolean check(Event event) { - if (!(event instanceof EntityBreedEvent breedEvent)) { - return false; - } - - return checkEntity(breedEvent.getEntity()); + return event instanceof EntityBreedEvent breedEvent && checkEntity(breedEvent.getEntity()); } private boolean checkEntity(Entity entity) { diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index ad7b5556200..0b0601f3e25 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -51,7 +51,6 @@ import org.bukkit.event.entity.AreaEffectCloudApplyEvent; import org.bukkit.event.entity.CreeperPowerEvent; import org.bukkit.event.entity.EntityBreakDoorEvent; -import org.bukkit.event.entity.EntityBreedEvent; import org.bukkit.event.entity.EntityCombustEvent; import org.bukkit.event.entity.EntityEnterLoveModeEvent; import org.bukkit.event.entity.EntityDismountEvent; @@ -740,7 +739,7 @@ public class SimpleEvents { ) .since("INSERT VERSION"); - Skript.registerEvent("Player Pickup Arrow", SimpleEvent.class, PlayerPickupArrowEvent.class, "[player] (pick[ing| ]up [an] arrow|arrow pick[ing| ]up)") + Skript.registerEvent("Player Pickup Arrow", SimpleEvent.class, PlayerPickupArrowEvent.class, "[player] (pick[ing| ]up [an] arrow|arrow pick[ing| ]up)") .description("Called when a player picks up an arrow from the ground.") .examples( "on arrow pickup:", diff --git a/src/main/java/ch/njol/skript/expressions/ExprExperience.java b/src/main/java/ch/njol/skript/expressions/ExprExperience.java index 70c57147436..22437910cee 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprExperience.java +++ b/src/main/java/ch/njol/skript/expressions/ExprExperience.java @@ -44,7 +44,8 @@ public class ExprExperience extends SimpleExpression { } @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + public boolean init(Expression[] expressions, int matchedPattern, + Kleenean isDelayed, ParseResult parseResult) { if (!getParser().isCurrentEvent(ExperienceSpawnEvent.class, BlockBreakEvent.class, PlayerExpChangeEvent.class, EntityBreedEvent.class)) { Skript.error("The experience expression can only be used in experience spawn, " + @@ -56,7 +57,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye } @Override - protected @Nullable Experience[] get(Event event) { + protected Experience @Nullable [] get(Event event) { Experience[] exp; if (event instanceof ExperienceSpawnEvent experienceSpawnEvent) { @@ -75,7 +76,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye } @Override - public @Nullable Class[] acceptChange(ChangeMode mode) { + public Class @Nullable [] acceptChange(ChangeMode mode) { return switch (mode) { case SET, DELETE -> CollectionUtils.array(Experience.class, Integer.class); case ADD, REMOVE -> CollectionUtils.array(Experience[].class, Integer[].class); From 43d3769efbee4d563ecd5a3a6d7323c7cdd4fdb6 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Fri, 27 Sep 2024 01:12:16 +0200 Subject: [PATCH 45/48] agag --- src/main/java/ch/njol/skript/effects/EffAllowAging.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffAllowAging.java b/src/main/java/ch/njol/skript/effects/EffAllowAging.java index 33d44ac3a42..7d1eb9b1523 100644 --- a/src/main/java/ch/njol/skript/effects/EffAllowAging.java +++ b/src/main/java/ch/njol/skript/effects/EffAllowAging.java @@ -18,7 +18,7 @@ @Description("Sets whether or not living entities will be able to age.") @Examples({ "on spawn of animal:", - "\tlock age of entity" + "\tallow aging of entity" }) @Since("INSERT VERSION") public class EffAllowAging extends Effect { @@ -57,7 +57,7 @@ protected void execute(Event event) { @Override public String toString(@Nullable Event event, boolean debug) { - return (unlock ? "unlock" : "lock") + " age of " + entities.toString(event,debug); + return (unlock ? "allow" : "prevent") + " aging of " + entities.toString(event,debug); } } From ef65bea7931384cd981dbe4cd132a6cd022d25b5 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Wed, 16 Oct 2024 23:14:17 +0200 Subject: [PATCH 46/48] move to module --- .../classes/data/BukkitEventValues.java | 22 -------- .../ch/njol/skript/events/SimpleEvents.java | 8 --- .../bukkit/breeding/BreedingModule.java | 52 +++++++++++++++++++ .../bukkit/breeding/elements}/CondCanAge.java | 2 +- .../breeding/elements}/CondCanBreed.java | 2 +- .../breeding/elements}/CondIsAdult.java | 2 +- .../bukkit/breeding/elements}/CondIsBaby.java | 2 +- .../breeding/elements}/CondIsInLove.java | 2 +- .../breeding/elements}/EffAllowAging.java | 2 +- .../breeding/elements}/EffBreedable.java | 2 +- .../elements}/EffMakeAdultOrBaby.java | 2 +- .../bukkit/breeding/elements}/EvtBreed.java | 2 +- .../elements}/ExprBreedingFamily.java | 2 +- .../breeding/elements}/ExprLoveTime.java | 2 +- 14 files changed, 63 insertions(+), 41 deletions(-) create mode 100644 src/main/java/org/skriptlang/skript/bukkit/breeding/BreedingModule.java rename src/main/java/{ch/njol/skript/conditions => org/skriptlang/skript/bukkit/breeding/elements}/CondCanAge.java (94%) rename src/main/java/{ch/njol/skript/conditions => org/skriptlang/skript/bukkit/breeding/elements}/CondCanBreed.java (94%) rename src/main/java/{ch/njol/skript/conditions => org/skriptlang/skript/bukkit/breeding/elements}/CondIsAdult.java (93%) rename src/main/java/{ch/njol/skript/conditions => org/skriptlang/skript/bukkit/breeding/elements}/CondIsBaby.java (93%) rename src/main/java/{ch/njol/skript/conditions => org/skriptlang/skript/bukkit/breeding/elements}/CondIsInLove.java (94%) rename src/main/java/{ch/njol/skript/effects => org/skriptlang/skript/bukkit/breeding/elements}/EffAllowAging.java (96%) rename src/main/java/{ch/njol/skript/effects => org/skriptlang/skript/bukkit/breeding/elements}/EffBreedable.java (96%) rename src/main/java/{ch/njol/skript/effects => org/skriptlang/skript/bukkit/breeding/elements}/EffMakeAdultOrBaby.java (96%) rename src/main/java/{ch/njol/skript/events => org/skriptlang/skript/bukkit/breeding/elements}/EvtBreed.java (96%) rename src/main/java/{ch/njol/skript/expressions => org/skriptlang/skript/bukkit/breeding/elements}/ExprBreedingFamily.java (97%) rename src/main/java/{ch/njol/skript/expressions => org/skriptlang/skript/bukkit/breeding/elements}/ExprLoveTime.java (97%) diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java index 2f7e0910ce1..5f361e512a4 100644 --- a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java +++ b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java @@ -1804,28 +1804,6 @@ public Location get(LootGenerateEvent event) { }, EventValues.TIME_NOW); } - // EntityBreedEvent - EventValues.registerEventValue(EntityBreedEvent.class, ItemStack.class, new Getter<>() { - @Override - public @Nullable ItemStack get(EntityBreedEvent event) { - return event.getBredWith(); - } - }, EventValues.TIME_NOW); - - EventValues.registerEventValue(EntityEnterLoveModeEvent.class, LivingEntity.class, new Getter<>() { - @Override - public LivingEntity get(EntityEnterLoveModeEvent event) { - return event.getEntity(); - } - }, EventValues.TIME_NOW); - - EventValues.registerEventValue(EntityEnterLoveModeEvent.class, HumanEntity.class, new Getter<>() { - @Override - public @Nullable HumanEntity get(EntityEnterLoveModeEvent event) { - return event.getHumanEntity(); - } - }, EventValues.TIME_NOW); - // EntityResurrectEvent EventValues.registerEventValue(EntityResurrectEvent.class, Slot.class, new Getter() { @Override diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index 4e52918930e..9b736cf983c 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -732,14 +732,6 @@ public class SimpleEvents { .requiredPlugins("Paper 1.16+"); } - Skript.registerEvent("Love Mode Enter", SimpleEvent.class, EntityEnterLoveModeEvent.class, "[entity] enter[s] love mode", "[entity] love mode [enter]") - .description("Called whenever an entity enters a state of being in love.") - .examples( - "on love mode enter:", - "\tcancel event # No one is allowed love here" - ) - .since("INSERT VERSION"); - Skript.registerEvent("Player Pickup Arrow", SimpleEvent.class, PlayerPickupArrowEvent.class, "[player] (pick[ing| ]up [an] arrow|arrow pick[ing| ]up)") .description("Called when a player picks up an arrow from the ground.") .examples( diff --git a/src/main/java/org/skriptlang/skript/bukkit/breeding/BreedingModule.java b/src/main/java/org/skriptlang/skript/bukkit/breeding/BreedingModule.java new file mode 100644 index 00000000000..bead36b885e --- /dev/null +++ b/src/main/java/org/skriptlang/skript/bukkit/breeding/BreedingModule.java @@ -0,0 +1,52 @@ +package org.skriptlang.skript.bukkit.breeding; + +import ch.njol.skript.Skript; +import ch.njol.skript.lang.util.SimpleEvent; +import ch.njol.skript.registrations.EventValues; +import ch.njol.skript.util.Getter; +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.entity.EntityBreedEvent; +import org.bukkit.event.entity.EntityEnterLoveModeEvent; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.Nullable; + +import java.io.IOException; + +public class BreedingModule { + + public static void load() throws IOException { + Skript.getAddonInstance().loadClasses("org.skriptlang.skript.bukkit.breeding", "elements"); + + Skript.registerEvent("Love Mode Enter", SimpleEvent.class, EntityEnterLoveModeEvent.class, + "[entity] enter[s] love mode", "[entity] love mode [enter]") + .description("Called whenever an entity enters a state of being in love.") + .examples( + "on love mode enter:", + "\tcancel event # No one is allowed love here" + ) + .since("INSERT VERSION"); + + EventValues.registerEventValue(EntityBreedEvent.class, ItemStack.class, new Getter<>() { + @Override + public @Nullable ItemStack get(EntityBreedEvent event) { + return event.getBredWith(); + } + }, EventValues.TIME_NOW); + + EventValues.registerEventValue(EntityEnterLoveModeEvent.class, LivingEntity.class, new Getter<>() { + @Override + public LivingEntity get(EntityEnterLoveModeEvent event) { + return event.getEntity(); + } + }, EventValues.TIME_NOW); + + EventValues.registerEventValue(EntityEnterLoveModeEvent.class, HumanEntity.class, new Getter<>() { + @Override + public @Nullable HumanEntity get(EntityEnterLoveModeEvent event) { + return event.getHumanEntity(); + } + }, EventValues.TIME_NOW); + } + +} diff --git a/src/main/java/ch/njol/skript/conditions/CondCanAge.java b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/CondCanAge.java similarity index 94% rename from src/main/java/ch/njol/skript/conditions/CondCanAge.java rename to src/main/java/org/skriptlang/skript/bukkit/breeding/elements/CondCanAge.java index fe5e9848eb1..8047e31883b 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanAge.java +++ b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/CondCanAge.java @@ -1,4 +1,4 @@ -package ch.njol.skript.conditions; +package org.skriptlang.skript.bukkit.breeding.elements; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; diff --git a/src/main/java/ch/njol/skript/conditions/CondCanBreed.java b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/CondCanBreed.java similarity index 94% rename from src/main/java/ch/njol/skript/conditions/CondCanBreed.java rename to src/main/java/org/skriptlang/skript/bukkit/breeding/elements/CondCanBreed.java index 1aafe7653bf..ee473c6498b 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanBreed.java +++ b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/CondCanBreed.java @@ -1,4 +1,4 @@ -package ch.njol.skript.conditions; +package org.skriptlang.skript.bukkit.breeding.elements; import ch.njol.skript.Skript; import ch.njol.skript.conditions.base.PropertyCondition; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsAdult.java b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/CondIsAdult.java similarity index 93% rename from src/main/java/ch/njol/skript/conditions/CondIsAdult.java rename to src/main/java/org/skriptlang/skript/bukkit/breeding/elements/CondIsAdult.java index 72f5140b8ea..90036e04d82 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsAdult.java +++ b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/CondIsAdult.java @@ -1,4 +1,4 @@ -package ch.njol.skript.conditions; +package org.skriptlang.skript.bukkit.breeding.elements; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsBaby.java b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/CondIsBaby.java similarity index 93% rename from src/main/java/ch/njol/skript/conditions/CondIsBaby.java rename to src/main/java/org/skriptlang/skript/bukkit/breeding/elements/CondIsBaby.java index 1e09e96a9a1..278b6da80ae 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsBaby.java +++ b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/CondIsBaby.java @@ -1,4 +1,4 @@ -package ch.njol.skript.conditions; +package org.skriptlang.skript.bukkit.breeding.elements; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsInLove.java b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/CondIsInLove.java similarity index 94% rename from src/main/java/ch/njol/skript/conditions/CondIsInLove.java rename to src/main/java/org/skriptlang/skript/bukkit/breeding/elements/CondIsInLove.java index fec461c3e94..659a02961b2 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsInLove.java +++ b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/CondIsInLove.java @@ -1,4 +1,4 @@ -package ch.njol.skript.conditions; +package org.skriptlang.skript.bukkit.breeding.elements; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; diff --git a/src/main/java/ch/njol/skript/effects/EffAllowAging.java b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/EffAllowAging.java similarity index 96% rename from src/main/java/ch/njol/skript/effects/EffAllowAging.java rename to src/main/java/org/skriptlang/skript/bukkit/breeding/elements/EffAllowAging.java index 7d1eb9b1523..4745125adbf 100644 --- a/src/main/java/ch/njol/skript/effects/EffAllowAging.java +++ b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/EffAllowAging.java @@ -1,4 +1,4 @@ -package ch.njol.skript.effects; +package org.skriptlang.skript.bukkit.breeding.elements; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; diff --git a/src/main/java/ch/njol/skript/effects/EffBreedable.java b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/EffBreedable.java similarity index 96% rename from src/main/java/ch/njol/skript/effects/EffBreedable.java rename to src/main/java/org/skriptlang/skript/bukkit/breeding/elements/EffBreedable.java index 4a6c524e9dd..c0c0cb0ac19 100644 --- a/src/main/java/ch/njol/skript/effects/EffBreedable.java +++ b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/EffBreedable.java @@ -1,4 +1,4 @@ -package ch.njol.skript.effects; +package org.skriptlang.skript.bukkit.breeding.elements; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; diff --git a/src/main/java/ch/njol/skript/effects/EffMakeAdultOrBaby.java b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/EffMakeAdultOrBaby.java similarity index 96% rename from src/main/java/ch/njol/skript/effects/EffMakeAdultOrBaby.java rename to src/main/java/org/skriptlang/skript/bukkit/breeding/elements/EffMakeAdultOrBaby.java index da8f27ce383..de3d98c8aa3 100644 --- a/src/main/java/ch/njol/skript/effects/EffMakeAdultOrBaby.java +++ b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/EffMakeAdultOrBaby.java @@ -1,4 +1,4 @@ -package ch.njol.skript.effects; +package org.skriptlang.skript.bukkit.breeding.elements; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; diff --git a/src/main/java/ch/njol/skript/events/EvtBreed.java b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/EvtBreed.java similarity index 96% rename from src/main/java/ch/njol/skript/events/EvtBreed.java rename to src/main/java/org/skriptlang/skript/bukkit/breeding/elements/EvtBreed.java index 06a67a46b2c..e268aaf7d66 100644 --- a/src/main/java/ch/njol/skript/events/EvtBreed.java +++ b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/EvtBreed.java @@ -1,4 +1,4 @@ -package ch.njol.skript.events; +package org.skriptlang.skript.bukkit.breeding.elements; import ch.njol.skript.Skript; import ch.njol.skript.entity.EntityType; diff --git a/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/ExprBreedingFamily.java similarity index 97% rename from src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java rename to src/main/java/org/skriptlang/skript/bukkit/breeding/elements/ExprBreedingFamily.java index de8ab0f5297..4785a671357 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprBreedingFamily.java +++ b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/ExprBreedingFamily.java @@ -1,4 +1,4 @@ -package ch.njol.skript.expressions; +package org.skriptlang.skript.bukkit.breeding.elements; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; diff --git a/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/ExprLoveTime.java similarity index 97% rename from src/main/java/ch/njol/skript/expressions/ExprLoveTime.java rename to src/main/java/org/skriptlang/skript/bukkit/breeding/elements/ExprLoveTime.java index 8505b9bcbf0..ffca5d64a38 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprLoveTime.java +++ b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/ExprLoveTime.java @@ -1,4 +1,4 @@ -package ch.njol.skript.expressions; +package org.skriptlang.skript.bukkit.breeding.elements; import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.doc.Description; From 786f4cdb369deae582abef2eda86218b1cc4ca37 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Wed, 16 Oct 2024 23:14:46 +0200 Subject: [PATCH 47/48] load --- src/main/java/ch/njol/skript/Skript.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/ch/njol/skript/Skript.java b/src/main/java/ch/njol/skript/Skript.java index 0bd0a4877b7..addee87ac5c 100644 --- a/src/main/java/ch/njol/skript/Skript.java +++ b/src/main/java/ch/njol/skript/Skript.java @@ -94,6 +94,7 @@ import org.junit.runner.Result; import org.junit.runner.notification.Failure; import org.skriptlang.skript.bukkit.SkriptMetrics; +import org.skriptlang.skript.bukkit.breeding.BreedingModule; import org.skriptlang.skript.bukkit.displays.DisplayModule; import org.skriptlang.skript.lang.comparator.Comparator; import org.skriptlang.skript.lang.comparator.Comparators; @@ -555,6 +556,7 @@ public void onEnable() { getAddonInstance().loadClasses("org.skriptlang.skript.bukkit", "misc"); // todo: become proper module once registry api is merged DisplayModule.load(); + BreedingModule.load(); } catch (final Exception e) { exception(e, "Could not load required .class files: " + e.getLocalizedMessage()); setEnabled(false); From 1dccd2b2d8f2b9091ac95cb392f42c9d72c40768 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:19:19 +0200 Subject: [PATCH 48/48] fix imports --- .../java/ch/njol/skript/classes/data/BukkitEventValues.java | 2 -- src/main/java/ch/njol/skript/events/SimpleEvents.java | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java index 5f361e512a4..189cbab9de7 100644 --- a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java +++ b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java @@ -95,13 +95,11 @@ import org.bukkit.event.entity.AreaEffectCloudApplyEvent; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; -import org.bukkit.event.entity.EntityBreedEvent; import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.event.entity.EntityEnterLoveModeEvent; import org.bukkit.event.entity.EntityDropItemEvent; import org.bukkit.event.entity.EntityEvent; import org.bukkit.event.entity.EntityPickupItemEvent; diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index 9b736cf983c..1e9a96ac515 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -52,7 +52,6 @@ import org.bukkit.event.entity.CreeperPowerEvent; import org.bukkit.event.entity.EntityBreakDoorEvent; import org.bukkit.event.entity.EntityCombustEvent; -import org.bukkit.event.entity.EntityEnterLoveModeEvent; import org.bukkit.event.entity.EntityDismountEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityMountEvent; @@ -732,7 +731,7 @@ public class SimpleEvents { .requiredPlugins("Paper 1.16+"); } - Skript.registerEvent("Player Pickup Arrow", SimpleEvent.class, PlayerPickupArrowEvent.class, "[player] (pick[ing| ]up [an] arrow|arrow pick[ing| ]up)") + Skript.registerEvent("Player Pickup Arrow", SimpleEvent.class, PlayerPickupArrowEvent.class, "[player] (pick[ing| ]up [an] arrow|arrow pick[ing| ]up)") .description("Called when a player picks up an arrow from the ground.") .examples( "on arrow pickup:",