diff --git a/src/main/java/ch/njol/skript/conditions/CondAllayCanDuplicate.java b/src/main/java/ch/njol/skript/conditions/CondAllayCanDuplicate.java index 683ee6b78f8..20601797057 100644 --- a/src/main/java/ch/njol/skript/conditions/CondAllayCanDuplicate.java +++ b/src/main/java/ch/njol/skript/conditions/CondAllayCanDuplicate.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -26,6 +27,18 @@ public boolean check(LivingEntity entity) { return entity instanceof Allay allay ? allay.canDuplicate() : false; } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean canDuplicate, ChangeMode mode) { + if (entity instanceof Allay allay) { + allay.setCanDuplicate(canDuplicate); + } + } + @Override protected String getPropertyName() { return "duplicate"; diff --git a/src/main/java/ch/njol/skript/conditions/CondCanFly.java b/src/main/java/ch/njol/skript/conditions/CondCanFly.java index 5a4c248a0e6..edc6be8a300 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanFly.java +++ b/src/main/java/ch/njol/skript/conditions/CondCanFly.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import org.bukkit.entity.Player; import ch.njol.skript.conditions.base.PropertyCondition; @@ -22,6 +23,22 @@ public class CondCanFly extends PropertyCondition { public boolean check(Player player) { return player.getAllowFlight(); } + + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET || mode == ChangeMode.RESET; + } + + @Override + protected void change(Player player, boolean allowFlight, ChangeMode mode) { + if (mode == ChangeMode.RESET) { + allowFlight = switch (player.getGameMode()) { + case CREATIVE, SPECTATOR -> true; + default -> false; + }; + } + player.setAllowFlight(allowFlight); + } @Override protected PropertyType getPropertyType() { diff --git a/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java b/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java index 17b0b82d8e9..2e8f8ef5387 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java +++ b/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -40,4 +41,14 @@ protected String getPropertyName() { return "pick up items"; } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + public void change(LivingEntity livingEntity, boolean canPickUpItems, ChangeMode mode) { + livingEntity.setCanPickupItems(canPickUpItems); + } + } diff --git a/src/main/java/ch/njol/skript/conditions/CondCanSee.java b/src/main/java/ch/njol/skript/conditions/CondCanSee.java index 1000dfc46c0..ad9d98ff906 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanSee.java +++ b/src/main/java/ch/njol/skript/conditions/CondCanSee.java @@ -1,6 +1,7 @@ package ch.njol.skript.conditions; import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.conditions.base.PropertyCondition.PropertyType; import ch.njol.skript.doc.*; @@ -11,6 +12,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.Event; +import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.Nullable; @Name("Can See") @@ -62,6 +64,33 @@ public boolean check(Event event) { ), isNegated()); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET || mode == ChangeMode.RESET; + } + + @Override + public void change(Event event, boolean canSee, ChangeMode mode) { + if (mode == ChangeMode.RESET) { + canSee = true; + } + Plugin plugin = Skript.getInstance(); + Entity[] entities = this.entities.getArray(event); + if (canSee) { + for (Player viewer : viewers.getArray(event)) { + for (Entity entity : entities) { + viewer.showEntity(plugin, entity); + } + } + } else { + for (Player viewer : viewers.getArray(event)) { + for (Entity entity : entities) { + viewer.hideEntity(plugin, entity); + } + } + } + } + @Override public String toString(@Nullable Event event, boolean debug) { return PropertyCondition.toString(this, PropertyType.CAN, event, debug, viewers, diff --git a/src/main/java/ch/njol/skript/conditions/CondCancelled.java b/src/main/java/ch/njol/skript/conditions/CondCancelled.java index 7096d814bac..780795d7421 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCancelled.java +++ b/src/main/java/ch/njol/skript/conditions/CondCancelled.java @@ -1,6 +1,7 @@ package ch.njol.skript.conditions; import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; import ch.njol.skript.doc.Name; @@ -41,6 +42,18 @@ public boolean check(Event e) { return (e instanceof Cancellable && ((Cancellable) e).isCancelled()) ^ isNegated(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + public void change(Event event, boolean cancelled, ChangeMode mode) { + if (event instanceof Cancellable cancellable) { + cancellable.setCancelled(cancelled); + } + } + @Override public String toString(@Nullable Event e, boolean debug) { return isNegated() ? "event is not cancelled" : "event is cancelled"; diff --git a/src/main/java/ch/njol/skript/conditions/CondElytraBoostConsume.java b/src/main/java/ch/njol/skript/conditions/CondElytraBoostConsume.java index e5ecfa662c4..bd8361d3444 100644 --- a/src/main/java/ch/njol/skript/conditions/CondElytraBoostConsume.java +++ b/src/main/java/ch/njol/skript/conditions/CondElytraBoostConsume.java @@ -1,6 +1,7 @@ package ch.njol.skript.conditions; import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.doc.*; import ch.njol.skript.lang.Condition; import ch.njol.skript.lang.EventRestrictedSyntax; @@ -50,6 +51,18 @@ public boolean check(Event event) { return boostEvent.shouldConsume() == checkConsume; } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + public void change(Event event, boolean consume, ChangeMode mode) { + if (event instanceof PlayerElytraBoostEvent boostEvent) { + boostEvent.setShouldConsume(consume); + } + } + @Override public String toString(@Nullable Event event, boolean debug) { return "the boosting firework will " + (checkConsume ? "" : "not") + " be consumed"; diff --git a/src/main/java/ch/njol/skript/conditions/CondEndermanStaredAt.java b/src/main/java/ch/njol/skript/conditions/CondEndermanStaredAt.java index 1981403325e..1f14d79af91 100644 --- a/src/main/java/ch/njol/skript/conditions/CondEndermanStaredAt.java +++ b/src/main/java/ch/njol/skript/conditions/CondEndermanStaredAt.java @@ -1,6 +1,7 @@ package ch.njol.skript.conditions; import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.*; import org.bukkit.entity.Enderman; @@ -27,6 +28,18 @@ public boolean check(LivingEntity entity) { return false; } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean hasBeenStaredAt, ChangeMode mode) { + if (entity instanceof Enderman enderman) { + enderman.setHasBeenStaredAt(hasBeenStaredAt); + } + } + @Override protected String getPropertyName() { return "stared at"; diff --git a/src/main/java/ch/njol/skript/conditions/CondEntityUnload.java b/src/main/java/ch/njol/skript/conditions/CondEntityUnload.java index d37264f0fb5..7f2fd4779a9 100644 --- a/src/main/java/ch/njol/skript/conditions/CondEntityUnload.java +++ b/src/main/java/ch/njol/skript/conditions/CondEntityUnload.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -29,6 +30,16 @@ public boolean check(LivingEntity entity) { return entity.getRemoveWhenFarAway(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean remove, ChangeMode mode) { + entity.setRemoveWhenFarAway(remove); + } + @Override protected String getPropertyName() { return "despawn on chunk unload"; diff --git a/src/main/java/ch/njol/skript/conditions/CondGlowingText.java b/src/main/java/ch/njol/skript/conditions/CondGlowingText.java index 693c84120a9..6879396c9cf 100644 --- a/src/main/java/ch/njol/skript/conditions/CondGlowingText.java +++ b/src/main/java/ch/njol/skript/conditions/CondGlowingText.java @@ -2,6 +2,7 @@ import ch.njol.skript.Skript; import ch.njol.skript.aliases.ItemType; +import ch.njol.skript.classes.Changer.ChangeMode; import org.bukkit.block.Block; import ch.njol.skript.conditions.base.PropertyCondition; @@ -40,6 +41,32 @@ public boolean check(Object obj) { return false; } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET || mode == ChangeMode.RESET; + } + + @Override + protected void change(Object object, boolean glowing, ChangeMode mode) { + if (object instanceof Block block) { + BlockState state = block.getState(); + if (state instanceof Sign sign) { + sign.setGlowingText(glowing); + sign.update(); + } + } else if (object instanceof ItemType itemType) { + ItemMeta meta = itemType.getItemMeta(); + if (meta instanceof BlockStateMeta blockStateMeta) { + BlockState state = blockStateMeta.getBlockState(); + if (state instanceof Sign sign) { + sign.setGlowingText(glowing); + blockStateMeta.setBlockState(sign); + itemType.setItemMeta(meta); + } + } + } + } + @Override protected PropertyType getPropertyType() { return PropertyType.HAVE; diff --git a/src/main/java/ch/njol/skript/conditions/CondGoatHasHorns.java b/src/main/java/ch/njol/skript/conditions/CondGoatHasHorns.java index 5547e39352e..0d619c80d6a 100644 --- a/src/main/java/ch/njol/skript/conditions/CondGoatHasHorns.java +++ b/src/main/java/ch/njol/skript/conditions/CondGoatHasHorns.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.*; import ch.njol.skript.effects.EffGoatHorns.GoatHorn; @@ -57,6 +58,23 @@ public boolean check(LivingEntity entity) { }; } + @Override + public boolean acceptChange(ChangeMode mode) { + return goatHorn != GoatHorn.ANY && mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean hasHorn, ChangeMode mode) { + if (entity instanceof Goat goat) { + if (goatHorn != GoatHorn.LEFT) { + goat.setRightHorn(hasHorn); + } + if (goatHorn != GoatHorn.RIGHT) { + goat.setLeftHorn(hasHorn); + } + } + } + @Override protected String getPropertyName() { return switch (goatHorn) { diff --git a/src/main/java/ch/njol/skript/conditions/CondIgnitionProcess.java b/src/main/java/ch/njol/skript/conditions/CondIgnitionProcess.java index def5aa8354d..ec44f1b6229 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIgnitionProcess.java +++ b/src/main/java/ch/njol/skript/conditions/CondIgnitionProcess.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import org.bukkit.entity.Creeper; import org.bukkit.entity.LivingEntity; @@ -13,6 +14,7 @@ import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; +import org.bukkit.event.Event; @Name("Ignition Process") @Description("Checks if a creeper is going to explode.") @@ -46,6 +48,18 @@ public boolean check(LivingEntity entity) { return entity instanceof Creeper creeper && creeper.isIgnited(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean ignited, ChangeMode mode) { + if (entity instanceof Creeper creeper) { + creeper.setIgnited(ignited); + } + } + @Override protected String getPropertyName() { return "going to explode"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIncendiary.java b/src/main/java/ch/njol/skript/conditions/CondIncendiary.java index c0fb705900e..86a9347bfc8 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIncendiary.java +++ b/src/main/java/ch/njol/skript/conditions/CondIncendiary.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import org.bukkit.entity.Entity; import org.bukkit.entity.Explosive; import org.bukkit.event.Event; @@ -65,6 +66,27 @@ public boolean check(Event e) { return entities.check(e, entity -> entity instanceof Explosive && ((Explosive) entity).isIncendiary(), isNegated()); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + public void change(Event event, boolean isIncendiary, ChangeMode mode) { + if (isEvent) { + if (event instanceof ExplosionPrimeEvent explosionPrimeEvent) { + explosionPrimeEvent.setFire(isIncendiary); + } + return; + } + + for (Entity entity : entities.getArray(event)) { + if (entity instanceof Explosive explosive) { + explosive.setIsIncendiary(isIncendiary); + } + } + } + @Override public String toString(@Nullable Event e, boolean debug) { if (isEvent) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsCharged.java b/src/main/java/ch/njol/skript/conditions/CondIsCharged.java index 29d5aa0a45e..48c438140b9 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsCharged.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsCharged.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -35,6 +36,20 @@ public boolean check(Entity entity) { return false; } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(Entity entity, boolean charged, ChangeMode mode) { + if (entity instanceof Creeper creeper) { + creeper.setPowered(charged); + } else if (entity instanceof WitherSkull witherSkull) { + witherSkull.setCharged(charged); + } + } + @Override protected String getPropertyName() { return "charged"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsChargingFireball.java b/src/main/java/ch/njol/skript/conditions/CondIsChargingFireball.java index 9c5b7817c0d..6e9953b5d57 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsChargingFireball.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsChargingFireball.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -28,6 +29,18 @@ public boolean check(LivingEntity entity) { return false; } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean charging, ChangeMode mode) { + if (entity instanceof Ghast ghast) { + ghast.setCharging(charging); + } + } + @Override protected String getPropertyName() { return "charging fireball"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsCommandBlockConditional.java b/src/main/java/ch/njol/skript/conditions/CondIsCommandBlockConditional.java index 05a33420198..d8d274c4c89 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsCommandBlockConditional.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsCommandBlockConditional.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -39,6 +40,19 @@ public boolean check(Block block) { return false; } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(Block block, boolean conditional, ChangeMode mode) { + if (block.getBlockData() instanceof CommandBlock commandBlock) { + commandBlock.setConditional(conditional); + block.setBlockData(commandBlock); + } + } + @Override protected String getPropertyName() { return "conditional"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsCustomNameVisible.java b/src/main/java/ch/njol/skript/conditions/CondIsCustomNameVisible.java index d09d3024dd2..93c6bdcc7bf 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsCustomNameVisible.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsCustomNameVisible.java @@ -1,6 +1,7 @@ package ch.njol.skript.conditions; import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -37,6 +38,16 @@ public boolean check(Entity entity) { return entity.isCustomNameVisible(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(Entity entity, boolean visible, ChangeMode mode) { + entity.setCustomNameVisible(visible); + } + @Override protected String getPropertyName() { return "custom name"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsDancing.java b/src/main/java/ch/njol/skript/conditions/CondIsDancing.java index 47122fa60f9..c4cba1d2164 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsDancing.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsDancing.java @@ -1,6 +1,7 @@ package ch.njol.skript.conditions; import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.*; import org.bukkit.entity.Allay; @@ -35,6 +36,31 @@ public boolean check(LivingEntity entity) { return false; } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean dancing, ChangeMode mode) { + switch (entity) { + case Allay allay -> { + if (dancing) { + allay.startDancing(); + } else { + allay.stopDancing(); + } + } + case Parrot ignored -> error("It is not possible to force whether a parrot is dancing."); + case Piglin piglin -> { + if (SUPPORTS_PIGLINS) { + piglin.setDancing(dancing); + } + } + default -> { } + } + } + @Override protected String getPropertyName() { return "dancing"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsDashing.java b/src/main/java/ch/njol/skript/conditions/CondIsDashing.java index 169241f2e95..864d00250d0 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsDashing.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsDashing.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -28,6 +29,18 @@ public boolean check(LivingEntity entity) { return false; } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean dashing, ChangeMode mode) { + if (entity instanceof Camel camel) { + camel.setDashing(dashing); + } + } + @Override protected String getPropertyName() { return "dashing"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsEating.java b/src/main/java/ch/njol/skript/conditions/CondIsEating.java index e538ab75d1c..4f9d32e1995 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsEating.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsEating.java @@ -1,6 +1,7 @@ package ch.njol.skript.conditions; import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.*; import org.bukkit.entity.AbstractHorse; @@ -32,6 +33,20 @@ public boolean check(LivingEntity entity) { return false; } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean eating, ChangeMode mode) { + if (entity instanceof Panda panda) { + panda.setEating(eating); + } else if (SUPPORTS_HORSES && entity instanceof AbstractHorse horse) { + horse.setEating(eating); + } + } + @Override protected String getPropertyName() { return "eating"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsFireResistant.java b/src/main/java/ch/njol/skript/conditions/CondIsFireResistant.java index ef39ace4a17..52e908dfebc 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsFireResistant.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsFireResistant.java @@ -2,6 +2,7 @@ import ch.njol.skript.Skript; import ch.njol.skript.aliases.ItemType; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -9,6 +10,7 @@ import ch.njol.skript.doc.RequiredPlugins; import ch.njol.skript.doc.Since; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.tag.DamageTypeTags; @Name("Is Fire Resistant") @Description("Checks whether an item is fire resistant.") @@ -28,6 +30,18 @@ public boolean check(ItemType item) { return item.getItemMeta().isFireResistant(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(ItemType item, boolean fireResistant, ChangeMode mode) { + ItemMeta meta = item.getItemMeta(); + meta.setDamageResistant(fireResistant ? DamageTypeTags.IS_FIRE : null); + item.setItemMeta(meta); + } + @Override public String getPropertyName() { return "fire resistant"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsFlying.java b/src/main/java/ch/njol/skript/conditions/CondIsFlying.java index ff7089f32dd..98dbf7510c3 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsFlying.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsFlying.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import org.bukkit.entity.Player; import ch.njol.skript.conditions.base.PropertyCondition; @@ -22,7 +23,17 @@ public class CondIsFlying extends PropertyCondition { public boolean check(Player player) { return player.isFlying(); } - + + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(Player player, boolean flying, ChangeMode mode) { + player.setFlying(flying); + } + @Override protected String getPropertyName() { return "flying"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsGliding.java b/src/main/java/ch/njol/skript/conditions/CondIsGliding.java index 6d15fcebc97..f785f0560ba 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsGliding.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsGliding.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; import ch.njol.skript.doc.Name; @@ -23,6 +24,16 @@ public boolean check(LivingEntity entity) { return entity.isGliding(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean gliding, ChangeMode mode) { + entity.setGliding(gliding); + } + @Override protected String getPropertyName() { return "gliding"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsInvisible.java b/src/main/java/ch/njol/skript/conditions/CondIsInvisible.java index 73937175528..352dbd4541f 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsInvisible.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsInvisible.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -33,6 +34,16 @@ public boolean check(LivingEntity livingEntity) { return livingEntity.isInvisible(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity livingEntity, boolean invisible, ChangeMode mode) { + livingEntity.setInvisible(invisible); + } + @Override protected String getPropertyName() { return "invisible"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsInvulnerable.java b/src/main/java/ch/njol/skript/conditions/CondIsInvulnerable.java index 01453024a53..85191c516f6 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsInvulnerable.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsInvulnerable.java @@ -1,6 +1,7 @@ package ch.njol.skript.conditions; import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.doc.*; import org.bukkit.GameMode; import org.bukkit.entity.Entity; @@ -33,7 +34,21 @@ public boolean check(Object object) { } return false; } - + + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(Object object, boolean invulnerable, ChangeMode mode) { + if (object instanceof Entity entity) { + entity.setInvulnerable(invulnerable); + } else if (SUPPORTS_GAMEMODE && object instanceof GameMode gameMode) { + error("It is not possible to change whether a game mode makes players invulnerable."); + } + } + @Override protected String getPropertyName() { return "invulnerable"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsJumping.java b/src/main/java/ch/njol/skript/conditions/CondIsJumping.java index e8af905d710..ebed825231c 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsJumping.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsJumping.java @@ -1,6 +1,7 @@ package ch.njol.skript.conditions; import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Name; import ch.njol.skript.doc.Description; @@ -42,6 +43,16 @@ public boolean check(LivingEntity livingEntity) { return livingEntity.isJumping(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity livingEntity, boolean jumping, ChangeMode mode) { + livingEntity.setJumping(jumping); + } + @Override protected String getPropertyName() { return "jumping"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsLeftHanded.java b/src/main/java/ch/njol/skript/conditions/CondIsLeftHanded.java index bd8473e53ed..019785e291e 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsLeftHanded.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsLeftHanded.java @@ -1,6 +1,7 @@ package ch.njol.skript.conditions; import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -59,6 +60,19 @@ public boolean check(LivingEntity livingEntity) { return false; } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity livingEntity, boolean value, ChangeMode mode) { + value = value == (hand == MainHand.LEFT); + if (CAN_USE_ENTITIES && livingEntity instanceof Mob mob) { + mob.setLeftHanded(value); + } + } + @Override protected String getPropertyName() { return (hand == MainHand.LEFT ? "left" : "right") + " handed"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsOp.java b/src/main/java/ch/njol/skript/conditions/CondIsOp.java index d2d0c61bf0e..224c13ae9ad 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsOp.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsOp.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -22,6 +23,16 @@ public boolean check(OfflinePlayer player) { return player.isOp(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(OfflinePlayer player, boolean op, ChangeMode mode) { + player.setOp(op); + } + @Override protected String getPropertyName() { return "op"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsPersistent.java b/src/main/java/ch/njol/skript/conditions/CondIsPersistent.java index cd30a683630..6fd661abedb 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsPersistent.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsPersistent.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -42,6 +43,21 @@ public boolean check(Object object) { return false; } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(Object object, boolean persistent, ChangeMode mode) { + if (object instanceof Entity entity) { + entity.setPersistent(persistent); + } else if (object instanceof Block block && block.getBlockData() instanceof Leaves leaves) { + leaves.setPersistent(persistent); + block.setBlockData(leaves); + } + } + @Override protected String getPropertyName() { return "persistent"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsPlayingDead.java b/src/main/java/ch/njol/skript/conditions/CondIsPlayingDead.java index 732a6f8774b..98dac3793aa 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsPlayingDead.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsPlayingDead.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -26,6 +27,18 @@ public boolean check(LivingEntity entity) { return (entity instanceof Axolotl axolotl) ? axolotl.isPlayingDead() : false; } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean playingDead, ChangeMode mode) { + if (entity instanceof Axolotl axolotl) { + axolotl.setPlayingDead(playingDead); + } + } + @Override protected String getPropertyName() { return "playing dead"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsRiptiding.java b/src/main/java/ch/njol/skript/conditions/CondIsRiptiding.java index c179fb534d7..b87ca2f04c9 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsRiptiding.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsRiptiding.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -21,7 +22,17 @@ public class CondIsRiptiding extends PropertyCondition { public boolean check(LivingEntity entity) { return entity.isRiptiding(); } - + + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean riptiding, ChangeMode mode) { + entity.setRiptiding(riptiding); + } + @Override protected String getPropertyName() { return "riptiding"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsSaddled.java b/src/main/java/ch/njol/skript/conditions/CondIsSaddled.java index 100809f3976..6d37163522d 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsSaddled.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsSaddled.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -46,6 +47,20 @@ public boolean check(LivingEntity entity) { return false; } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean saddled, ChangeMode mode) { + if (entity instanceof Steerable steerable) { + steerable.setSaddle(saddled); + } else if (entity instanceof AbstractHorse horse) { + horse.getInventory().setSaddle(saddled ? ItemStack.of(Material.SADDLE) : null); + } + } + @Override protected String getPropertyName() { return properly ? "properly saddled" : "saddled"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsScreaming.java b/src/main/java/ch/njol/skript/conditions/CondIsScreaming.java index 0f1d3224778..6115acb4b4b 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsScreaming.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsScreaming.java @@ -1,6 +1,7 @@ package ch.njol.skript.conditions; import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.*; import org.bukkit.entity.Enderman; @@ -38,6 +39,20 @@ public boolean check(LivingEntity entity) { return false; } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean screaming, ChangeMode mode) { + if (entity instanceof Goat goat) { + goat.setScreaming(screaming); + } else if (SUPPORTS_ENDERMAN && entity instanceof Enderman enderman) { + enderman.setScreaming(screaming); + } + } + @Override protected String getPropertyName() { return "screaming"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsSheared.java b/src/main/java/ch/njol/skript/conditions/CondIsSheared.java index 5abace07b06..10b0e826e29 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsSheared.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsSheared.java @@ -1,6 +1,7 @@ package ch.njol.skript.conditions; import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -44,6 +45,20 @@ public boolean check(LivingEntity entity) { return false; } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean sheared, ChangeMode mode) { + if (entity instanceof Sheep sheep) { + sheep.setSheared(sheared); + } else if (entity instanceof Snowman snowman) { + snowman.setDerp(sheared); + } + } + @Override protected String getPropertyName() { return "sheared"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsSilent.java b/src/main/java/ch/njol/skript/conditions/CondIsSilent.java index 520414c1ce5..56bbea08231 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsSilent.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsSilent.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import org.bukkit.entity.Entity; import ch.njol.skript.conditions.base.PropertyCondition; @@ -22,7 +23,17 @@ public class CondIsSilent extends PropertyCondition { public boolean check(Entity entity) { return entity.isSilent(); } - + + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(Entity entity, boolean silent, ChangeMode mode) { + entity.setSilent(silent); + } + @Override protected String getPropertyName() { return "silent"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsSneaking.java b/src/main/java/ch/njol/skript/conditions/CondIsSneaking.java index 74d159e3d48..76816373674 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsSneaking.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsSneaking.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import org.bukkit.entity.Player; import ch.njol.skript.conditions.base.PropertyCondition; @@ -28,7 +29,17 @@ public class CondIsSneaking extends PropertyCondition { public boolean check(Player player) { return player.isSneaking(); } - + + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(Player player, boolean sneaking, ChangeMode mode) { + player.setSneaking(sneaking); + } + @Override protected String getPropertyName() { return "sneaking"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsSprinting.java b/src/main/java/ch/njol/skript/conditions/CondIsSprinting.java index 7cd73b49e45..d1e9cf0773b 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsSprinting.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsSprinting.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -21,7 +22,17 @@ public class CondIsSprinting extends PropertyCondition { public boolean check(Player player) { return player.isSprinting(); } - + + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(Player player, boolean sprinting, ChangeMode mode) { + player.setSprinting(sprinting); + } + @Override protected String getPropertyName() { return "sprinting"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsTamed.java b/src/main/java/ch/njol/skript/conditions/CondIsTamed.java index 2e62f8cb0a0..a2989e87f80 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsTamed.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsTamed.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -24,6 +25,18 @@ public boolean check(Entity entity) { return (entity instanceof Tameable tameable) && tameable.isTamed(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(Entity entity, boolean tamed, ChangeMode mode) { + if (entity instanceof Tameable tameable) { + tameable.setTamed(tamed); + } + } + @Override protected String getPropertyName() { return "tamed"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsUnbreakable.java b/src/main/java/ch/njol/skript/conditions/CondIsUnbreakable.java index b8dd46e3a2a..ad13d126508 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsUnbreakable.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsUnbreakable.java @@ -1,6 +1,7 @@ package ch.njol.skript.conditions; import ch.njol.skript.aliases.ItemType; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -9,6 +10,7 @@ import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; +import org.bukkit.inventory.meta.ItemMeta; @Name("Is Unbreakable") @Description("Checks whether an item is unbreakable.") @@ -39,7 +41,20 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye public boolean check(ItemType item) { return item.getItemMeta().isUnbreakable() ^ breakable; } - + + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(ItemType item, boolean unbreakable, ChangeMode mode) { + unbreakable = unbreakable != breakable; + ItemMeta itemMeta = item.getItemMeta(); + itemMeta.setUnbreakable(unbreakable); + item.setItemMeta(itemMeta); + } + @Override protected String getPropertyName() { return breakable ? "breakable" : "unbreakable"; diff --git a/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java b/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java index 3709bbde497..585cfe50bfa 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java @@ -1,11 +1,13 @@ package ch.njol.skript.conditions; import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; import ch.njol.skript.doc.Name; import ch.njol.skript.doc.RequiredPlugins; import ch.njol.skript.doc.Since; +import ch.njol.skript.effects.EffEnforceWhitelist; import ch.njol.skript.lang.Condition; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; @@ -55,6 +57,31 @@ public boolean check(Event event) { return players.check(event, OfflinePlayer::isWhitelisted, isNegated()); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + public void change(Event event, boolean whitelist, ChangeMode mode) { + if (isServer) { + if (isEnforce) { + Bukkit.setWhitelistEnforced(whitelist); + } else { + Bukkit.setWhitelist(whitelist); + } + } else { + // players + assert players != null; + for (OfflinePlayer player : players.getArray(event)) { + player.setWhitelisted(whitelist); + } + } + if (whitelist) { + EffEnforceWhitelist.reloadWhitelist(); + } + } + @Override public String toString(@Nullable Event event, boolean debug) { String negation = isNegated() ? "not" : ""; diff --git a/src/main/java/ch/njol/skript/conditions/CondItemDespawn.java b/src/main/java/ch/njol/skript/conditions/CondItemDespawn.java index a3e38015eaa..564adf302ba 100644 --- a/src/main/java/ch/njol/skript/conditions/CondItemDespawn.java +++ b/src/main/java/ch/njol/skript/conditions/CondItemDespawn.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -26,6 +27,16 @@ public boolean check(Item item) { return !item.isUnlimitedLifetime(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(Item item, boolean limitedLifetime, ChangeMode mode) { + item.setUnlimitedLifetime(!limitedLifetime); + } + @Override protected String getPropertyName() { return "naturally despawn"; diff --git a/src/main/java/ch/njol/skript/conditions/CondItemEnchantmentGlint.java b/src/main/java/ch/njol/skript/conditions/CondItemEnchantmentGlint.java index aa93247cf8c..aeeca30ff34 100644 --- a/src/main/java/ch/njol/skript/conditions/CondItemEnchantmentGlint.java +++ b/src/main/java/ch/njol/skript/conditions/CondItemEnchantmentGlint.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import org.bukkit.inventory.meta.ItemMeta; import ch.njol.skript.Skript; @@ -10,6 +11,9 @@ import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; +import java.util.Arrays; +import java.util.stream.Stream; + @Name("Item Has Enchantment Glint Override") @Description("Checks whether an item has the enchantment glint overridden, or is forced to glint or not.") @Example(""" @@ -30,38 +34,59 @@ public class CondItemEnchantmentGlint extends PropertyCondition { static { if (Skript.methodExists(ItemMeta.class, "getEnchantmentGlintOverride")) { - register(CondItemEnchantmentGlint.class, PropertyType.HAVE, "enchantment glint overrid(den|e)", "itemtypes"); - register(CondItemEnchantmentGlint.class, PropertyType.BE, "forced to [:not] glint", "itemtypes"); + Skript.registerCondition(CondItemEnchantmentGlint.class, Stream.concat( + Arrays.stream(getPatterns(PropertyType.HAVE, "enchantment glint overrid(den|e)", "itemtypes")), + Arrays.stream(getPatterns(PropertyType.BE, "forced to [:not] glint", "itemtypes")) + ).toArray(String[]::new)); } } - private int matchedPattern; - private boolean glint; + private boolean override; + private boolean glintNegated; @Override public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - this.matchedPattern = matchedPattern; - glint = !parseResult.hasTag("not"); - return super.init(expressions, matchedPattern, isDelayed, parseResult); + override = matchedPattern <= 1; + glintNegated = parseResult.hasTag("not"); + //noinspection unchecked + setExpr((Expression) expressions[0]); + setNegated(matchedPattern % 2 == 1); + return true; } @Override public boolean check(ItemType itemType) { ItemMeta meta = itemType.getItemMeta(); // enchantment glint override - if (matchedPattern == 0) + if (override) return meta.hasEnchantmentGlintOverride(); // forced to glint if (!meta.hasEnchantmentGlintOverride()) return false; - return meta.getEnchantmentGlintOverride(); + return meta.getEnchantmentGlintOverride() != glintNegated; + } + + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(ItemType itemType, boolean glint, ChangeMode mode) { + ItemMeta meta = itemType.getItemMeta(); + if (override) { + meta.setEnchantmentGlintOverride(glint ? true : null); + } else { + meta.setEnchantmentGlintOverride(glint != glintNegated); + } + itemType.setItemMeta(meta); } @Override protected String getPropertyName() { - if (matchedPattern == 0) + if (override) return "enchantment glint overridden"; - return "forced to " + (glint ? "" : "not ") + "glint"; + return "forced to " + (glintNegated ? "not " : "") + "glint"; } } diff --git a/src/main/java/ch/njol/skript/conditions/CondLeashWillDrop.java b/src/main/java/ch/njol/skript/conditions/CondLeashWillDrop.java index d9bf5a2c336..eb6f568bcec 100644 --- a/src/main/java/ch/njol/skript/conditions/CondLeashWillDrop.java +++ b/src/main/java/ch/njol/skript/conditions/CondLeashWillDrop.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.lang.EventRestrictedSyntax; import ch.njol.util.coll.CollectionUtils; import org.bukkit.event.Event; @@ -51,6 +52,18 @@ public boolean check(Event event) { return unleashEvent.isDropLeash() ^ isNegated(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + public void change(Event event, boolean dropLeash, ChangeMode mode) { + if (event instanceof EntityUnleashEvent unleashEvent) { + unleashEvent.setDropLeash(dropLeash); + } + } + @Override public String toString(@Nullable Event event, boolean debug) { return "the leash will" + (isNegated() ? " not" : "") + " be dropped"; diff --git a/src/main/java/ch/njol/skript/conditions/CondPandaIsOnBack.java b/src/main/java/ch/njol/skript/conditions/CondPandaIsOnBack.java index 2b941910aa3..0e3221a611c 100644 --- a/src/main/java/ch/njol/skript/conditions/CondPandaIsOnBack.java +++ b/src/main/java/ch/njol/skript/conditions/CondPandaIsOnBack.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -26,6 +27,18 @@ public boolean check(LivingEntity entity) { return entity instanceof Panda panda && panda.isOnBack(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean onBack, ChangeMode mode) { + if (entity instanceof Panda panda) { + panda.setOnBack(onBack); + } + } + @Override protected String getPropertyName() { return "on their back"; diff --git a/src/main/java/ch/njol/skript/conditions/CondPandaIsRolling.java b/src/main/java/ch/njol/skript/conditions/CondPandaIsRolling.java index 5e76fe769d1..b2aa3142970 100644 --- a/src/main/java/ch/njol/skript/conditions/CondPandaIsRolling.java +++ b/src/main/java/ch/njol/skript/conditions/CondPandaIsRolling.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -26,6 +27,18 @@ public boolean check(LivingEntity entity) { return entity instanceof Panda panda && panda.isRolling(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean rolling, ChangeMode mode) { + if (entity instanceof Panda panda) { + panda.setRolling(rolling); + } + } + @Override protected String getPropertyName() { return "rolling"; diff --git a/src/main/java/ch/njol/skript/conditions/CondPandaIsSneezing.java b/src/main/java/ch/njol/skript/conditions/CondPandaIsSneezing.java index 83a4c38524b..f011185b42a 100644 --- a/src/main/java/ch/njol/skript/conditions/CondPandaIsSneezing.java +++ b/src/main/java/ch/njol/skript/conditions/CondPandaIsSneezing.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -26,6 +27,18 @@ public boolean check(LivingEntity entity) { return entity instanceof Panda panda && panda.isSneezing(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean sneezing, ChangeMode mode) { + if (entity instanceof Panda panda) { + panda.setSneezing(sneezing); + } + } + @Override protected String getPropertyName() { return "sneezing"; diff --git a/src/main/java/ch/njol/skript/conditions/CondPvP.java b/src/main/java/ch/njol/skript/conditions/CondPvP.java index 254b802dbab..93931e8ee50 100644 --- a/src/main/java/ch/njol/skript/conditions/CondPvP.java +++ b/src/main/java/ch/njol/skript/conditions/CondPvP.java @@ -1,6 +1,7 @@ package ch.njol.skript.conditions; import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; import ch.njol.skript.doc.Name; @@ -29,26 +30,41 @@ public class CondPvP extends Condition { @SuppressWarnings("null") private Expression worlds; - private boolean enabled; @SuppressWarnings({"unchecked", "null"}) @Override public boolean init(final Expression[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { worlds = (Expression) exprs[0]; - enabled = matchedPattern == 0; + setNegated(matchedPattern == 1); return true; } @Override public boolean check(Event event) { if (PVP_GAME_RULE_EXISTS) - return worlds.check(event, world -> world.getGameRuleValue(GameRule.PVP) == enabled, isNegated()); - return worlds.check(event, world -> world.getPVP() == enabled, isNegated()); + return worlds.check(event, world -> world.getGameRuleValue(GameRule.PVP), isNegated()); + return worlds.check(event, world -> world.getPVP(), isNegated()); } - + + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + public void change(Event event, boolean enable, ChangeMode mode) { + for (World world : worlds.getArray(event)) { + if (PVP_GAME_RULE_EXISTS) { + world.setGameRule(GameRule.PVP, enable); + } else { + world.setPVP(enable); + } + } + } + @Override public String toString(@Nullable Event event, boolean debug) { - return "PvP is " + (enabled ? "enabled" : "disabled") + " in " + worlds.toString(event, debug); + return "PvP is " + (isNegated() ? "disabled" : "enabled") + " in " + worlds.toString(event, debug); } } diff --git a/src/main/java/ch/njol/skript/conditions/CondStriderIsShivering.java b/src/main/java/ch/njol/skript/conditions/CondStriderIsShivering.java index d779a52eec6..505430a69d0 100644 --- a/src/main/java/ch/njol/skript/conditions/CondStriderIsShivering.java +++ b/src/main/java/ch/njol/skript/conditions/CondStriderIsShivering.java @@ -1,5 +1,6 @@ package ch.njol.skript.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -26,6 +27,18 @@ public boolean check(LivingEntity entity) { return entity instanceof Strider strider && strider.isShivering(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean shivering, ChangeMode mode) { + if (entity instanceof Strider strider) { + strider.setShivering(shivering); + } + } + @Override protected String getPropertyName() { return "shivering"; diff --git a/src/main/java/ch/njol/skript/conditions/CondTooltip.java b/src/main/java/ch/njol/skript/conditions/CondTooltip.java index dab29e198b2..0610f43d8f9 100644 --- a/src/main/java/ch/njol/skript/conditions/CondTooltip.java +++ b/src/main/java/ch/njol/skript/conditions/CondTooltip.java @@ -2,6 +2,7 @@ import ch.njol.skript.Skript; import ch.njol.skript.aliases.ItemType; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; import ch.njol.skript.doc.Name; @@ -59,6 +60,28 @@ public boolean check(Event event) { return items.check(event, item -> item.getItemMeta().hasItemFlag(ItemFlag.HIDE_ADDITIONAL_TOOLTIP), isNegated()); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + public void change(Event event, boolean hideTooltip, ChangeMode mode) { + for (ItemType item : items.getArray(event)) { + ItemMeta meta = item.getItemMeta(); + if (entire) { + meta.setHideTooltip(hideTooltip); + } else { + if (hideTooltip) { + meta.addItemFlags(ItemFlag.HIDE_ADDITIONAL_TOOLTIP); + } else { + meta.removeItemFlags(ItemFlag.HIDE_ADDITIONAL_TOOLTIP); + } + } + item.setItemMeta(meta); + } + } + @Override public String toString(@Nullable Event event, boolean debug) { return "the " + (entire ? "entire" : "additional") + " tooltip of " + items.toString(event, debug) + " is " + (isNegated() ? "hidden" : "shown"); diff --git a/src/main/java/ch/njol/skript/conditions/CondWillHatch.java b/src/main/java/ch/njol/skript/conditions/CondWillHatch.java index 8349215bc01..2746be55143 100644 --- a/src/main/java/ch/njol/skript/conditions/CondWillHatch.java +++ b/src/main/java/ch/njol/skript/conditions/CondWillHatch.java @@ -1,6 +1,7 @@ package ch.njol.skript.conditions; 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.Example; @@ -51,6 +52,18 @@ public boolean check(Event event) { return ((PlayerEggThrowEvent) event).isHatching() ^ isNegated(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + public void change(Event event, boolean hatch, ChangeMode mode) { + if (event instanceof PlayerEggThrowEvent playerEggThrowEvent) { + playerEggThrowEvent.setHatching(hatch); + } + } + @Override public String toString(@Nullable Event event, boolean debug) { return "the egg " + (isNegated() ? "will" : "will not") + " hatch"; diff --git a/src/main/java/ch/njol/skript/conditions/base/PropertyCondition.java b/src/main/java/ch/njol/skript/conditions/base/PropertyCondition.java index 76a598e3ef9..a3ae8c4be7a 100644 --- a/src/main/java/ch/njol/skript/conditions/base/PropertyCondition.java +++ b/src/main/java/ch/njol/skript/conditions/base/PropertyCondition.java @@ -2,6 +2,7 @@ import ch.njol.skript.Skript; import ch.njol.skript.SkriptAPIException; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.lang.Condition; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; @@ -180,6 +181,22 @@ public final boolean test(T value) { return check(value); } + @Override + public void change(Event event, boolean value, ChangeMode mode) { + for (T what : expr.getArray(event)) { + change(what, value, mode); + } + } + + /** + * Changes the value of the property this condition represents for a property holder. + * @param what The property holder. + * @param value The new value. + * This is always false for {@link ChangeMode#DELETE} and {@link ChangeMode#RESET}. + * @param mode The type of change to perform. + */ + protected void change(T what, boolean value, ChangeMode mode) { } + protected abstract String getPropertyName(); protected PropertyType getPropertyType() { diff --git a/src/main/java/ch/njol/skript/effects/EffFireResistant.java b/src/main/java/ch/njol/skript/effects/EffFireResistant.java index 73c172f82d2..fd261e5e2b9 100644 --- a/src/main/java/ch/njol/skript/effects/EffFireResistant.java +++ b/src/main/java/ch/njol/skript/effects/EffFireResistant.java @@ -13,6 +13,7 @@ import ch.njol.util.Kleenean; import org.bukkit.event.Event; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.tag.DamageTypeTags; import org.jetbrains.annotations.Nullable; @Name("Make Fire Resistant") @@ -45,7 +46,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye protected void execute(Event event) { for (ItemType item : this.items.getArray(event)) { ItemMeta meta = item.getItemMeta(); - meta.setFireResistant(!not); + meta.setDamageResistant(not ? null : DamageTypeTags.IS_FIRE); item.setItemMeta(meta); } } diff --git a/src/main/java/ch/njol/skript/expressions/ExprWhether.java b/src/main/java/ch/njol/skript/expressions/ExprWhether.java deleted file mode 100644 index 48256b566e2..00000000000 --- a/src/main/java/ch/njol/skript/expressions/ExprWhether.java +++ /dev/null @@ -1,58 +0,0 @@ -package ch.njol.skript.expressions; - -import ch.njol.skript.Skript; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Example; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.Since; -import ch.njol.skript.lang.Condition; -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.event.Event; -import org.jetbrains.annotations.UnknownNullability; - -@Name("Whether") -@Description("A shorthand for returning the result of a condition (true or false). This is functionally identical to using `true if else false`.") -@Example("set {fly} to whether player can fly") -@Example("broadcast \"Flying: %whether player is flying%\"") -@Since("2.9.0") -public class ExprWhether extends SimpleExpression { - - static { - Skript.registerExpression(ExprWhether.class, Boolean.class, ExpressionType.PATTERN_MATCHES_EVERYTHING, - "whether <.+>"); - } - - private @UnknownNullability Condition condition; - - @Override - public boolean init(Expression[] expressions, int pattern, Kleenean delayed, ParseResult result) { - String input = result.regexes.get(0).group(); - this.condition = Condition.parse(input, "Can't understand this condition: " + input); - return condition != null; - } - - @Override - protected Boolean[] get(Event event) { - return new Boolean[] {condition.check(event)}; - } - - @Override - public Class getReturnType() { - return Boolean.class; - } - - @Override - public boolean isSingle() { - return true; - } - - @Override - public String toString(Event event, boolean debug) { - return "whether " + condition.toString(event, debug); - } - -} diff --git a/src/main/java/ch/njol/skript/expressions/ExprWithFireResistance.java b/src/main/java/ch/njol/skript/expressions/ExprWithFireResistance.java index e0f5fddddeb..49d186dbbb1 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprWithFireResistance.java +++ b/src/main/java/ch/njol/skript/expressions/ExprWithFireResistance.java @@ -14,6 +14,7 @@ import ch.njol.util.Kleenean; import org.bukkit.event.Event; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.tag.DamageTypeTags; import org.jetbrains.annotations.Nullable; @Name("With Fire Resistance") @@ -48,7 +49,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye protected ItemType[] get(Event event, ItemType[] source) { return get(source.clone(), item -> { ItemMeta meta = item.getItemMeta(); - meta.setFireResistant(!out); + meta.setDamageResistant(out ? null : DamageTypeTags.IS_FIRE); item.setItemMeta(meta); return item; }); diff --git a/src/main/java/ch/njol/skript/lang/Condition.java b/src/main/java/ch/njol/skript/lang/Condition.java index 5e77d6d0633..a3b91db6c7c 100644 --- a/src/main/java/ch/njol/skript/lang/Condition.java +++ b/src/main/java/ch/njol/skript/lang/Condition.java @@ -1,6 +1,7 @@ package ch.njol.skript.lang; import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.config.Node; import ch.njol.skript.lang.simplification.Simplifiable; @@ -97,6 +98,24 @@ public final boolean run(Event event) { return check(event); } + /** + * Checks whether this condition can be changed using a specific change mode. + * @param mode The change mode to consider. + * @return Whether this condition can be changed using {@code mode}. + */ + public boolean acceptChange(ChangeMode mode) { + return false; + } + + /** + * Changes the value this condition checks for some holders (to be determined by the implementation). + * @param event Event providing context. + * @param value The new value. + * This is always false for {@link ChangeMode#DELETE} and {@link ChangeMode#RESET}. + * @param mode The type of change to perform. + */ + public void change(Event event, boolean value, ChangeMode mode) { } + /** * Sets the negation state of this condition. This will change the behaviour of {@link Expression#check(Event, Predicate, boolean)}. */ diff --git a/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/conditions/CondCanAge.java b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/conditions/CondCanAge.java index 6ceae669a55..4d7d8331627 100644 --- a/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/conditions/CondCanAge.java +++ b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/conditions/CondCanAge.java @@ -1,10 +1,12 @@ package org.skriptlang.skript.bukkit.breeding.elements.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; import ch.njol.skript.doc.Name; import ch.njol.skript.doc.Since; +import org.bukkit.entity.Ageable; import org.bukkit.entity.Breedable; import org.bukkit.entity.LivingEntity; import org.skriptlang.skript.registration.SyntaxRegistry; @@ -35,7 +37,19 @@ public static void register(SyntaxRegistry registry) { @Override public boolean check(LivingEntity entity) { - return entity instanceof Breedable breedable && !breedable.getAgeLock(); + return entity instanceof Ageable ageable && !ageable.getAgeLock(); + } + + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean canAge, ChangeMode mode) { + if (entity instanceof Ageable ageable) { + ageable.setAgeLock(!canAge); + } } @Override diff --git a/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/conditions/CondCanBreed.java b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/conditions/CondCanBreed.java index 6310d13ec3c..a42c28f856b 100644 --- a/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/conditions/CondCanBreed.java +++ b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/conditions/CondCanBreed.java @@ -1,5 +1,6 @@ package org.skriptlang.skript.bukkit.breeding.elements.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -38,6 +39,18 @@ public boolean check(LivingEntity entity) { return entity instanceof Breedable breedable && breedable.canBreed(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean breed, ChangeMode mode) { + if (entity instanceof Breedable breedable) { + breedable.setBreed(breed); + } + } + @Override protected PropertyType getPropertyType() { return PropertyType.CAN; diff --git a/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/conditions/CondIsAdult.java b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/conditions/CondIsAdult.java index 5a1970dac66..be5897dfd37 100644 --- a/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/conditions/CondIsAdult.java +++ b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/conditions/CondIsAdult.java @@ -1,5 +1,6 @@ package org.skriptlang.skript.bukkit.breeding.elements.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -38,6 +39,22 @@ public boolean check(LivingEntity entity) { return entity instanceof Ageable ageable && ageable.isAdult(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean adult, ChangeMode mode) { + if (entity instanceof Ageable ageable) { + if (adult) { + ageable.setAdult(); + } else { + ageable.setBaby(); + } + } + } + @Override protected String getPropertyName() { return "an adult"; diff --git a/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/conditions/CondIsBaby.java b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/conditions/CondIsBaby.java index 04a847c1c9a..a597b2bf3d1 100644 --- a/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/conditions/CondIsBaby.java +++ b/src/main/java/org/skriptlang/skript/bukkit/breeding/elements/conditions/CondIsBaby.java @@ -1,5 +1,6 @@ package org.skriptlang.skript.bukkit.breeding.elements.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -38,6 +39,22 @@ public boolean check(LivingEntity entity) { return entity instanceof Ageable ageable && !ageable.isAdult(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(LivingEntity entity, boolean baby, ChangeMode mode) { + if (entity instanceof Ageable ageable) { + if (baby) { + ageable.setBaby(); + } else { + ageable.setAdult(); + } + } + } + @Override protected String getPropertyName() { return "a baby"; diff --git a/src/main/java/org/skriptlang/skript/bukkit/brewing/elements/conditions/CondBrewingConsume.java b/src/main/java/org/skriptlang/skript/bukkit/brewing/elements/conditions/CondBrewingConsume.java index b46747f3237..fd31772b7c0 100644 --- a/src/main/java/org/skriptlang/skript/bukkit/brewing/elements/conditions/CondBrewingConsume.java +++ b/src/main/java/org/skriptlang/skript/bukkit/brewing/elements/conditions/CondBrewingConsume.java @@ -1,5 +1,6 @@ package org.skriptlang.skript.bukkit.brewing.elements.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.doc.*; import ch.njol.skript.lang.Condition; import ch.njol.skript.lang.EventRestrictedSyntax; @@ -41,11 +42,9 @@ public static void register(SyntaxRegistry registry) { ); } - private boolean willConsume; - @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - willConsume = matchedPattern == 0; + setNegated(matchedPattern == 1); return true; } @@ -58,12 +57,24 @@ public Class[] supportedEvents() { public boolean check(Event event) { if (!(event instanceof BrewingStandFuelEvent brewingStandFuelEvent)) return false; - return brewingStandFuelEvent.isConsuming() == willConsume; + return brewingStandFuelEvent.isConsuming(); + } + + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + public void change(Event event, boolean consume, ChangeMode mode) { + if (event instanceof BrewingStandFuelEvent brewingStandFuelEvent) { + brewingStandFuelEvent.setConsuming(consume); + } } @Override public String toString(@Nullable Event event, boolean debug) { - return "the brewing stand will" + (willConsume ? "" : " not") + " consume the fuel"; + return "the brewing stand will" + (isNegated() ? " not" : "") + " consume the fuel"; } } diff --git a/src/main/java/org/skriptlang/skript/bukkit/entity/displays/text/elements/conditions/CondTextDisplayHasDropShadow.java b/src/main/java/org/skriptlang/skript/bukkit/entity/displays/text/elements/conditions/CondTextDisplayHasDropShadow.java index 12948675586..86245b748c9 100644 --- a/src/main/java/org/skriptlang/skript/bukkit/entity/displays/text/elements/conditions/CondTextDisplayHasDropShadow.java +++ b/src/main/java/org/skriptlang/skript/bukkit/entity/displays/text/elements/conditions/CondTextDisplayHasDropShadow.java @@ -1,5 +1,6 @@ package org.skriptlang.skript.bukkit.entity.displays.text.elements.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -51,6 +52,18 @@ public boolean check(Display value) { return value instanceof TextDisplay textDisplay && textDisplay.isShadowed(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(Display display, boolean shadowed, ChangeMode mode) { + if (display instanceof TextDisplay textDisplay) { + textDisplay.setShadowed(shadowed); + } + } + @Override protected PropertyType getPropertyType() { return PropertyType.HAVE; diff --git a/src/main/java/org/skriptlang/skript/bukkit/entity/displays/text/elements/conditions/CondTextDisplaySeeThroughBlocks.java b/src/main/java/org/skriptlang/skript/bukkit/entity/displays/text/elements/conditions/CondTextDisplaySeeThroughBlocks.java index 1d0a07bdb0e..f5899fd5a12 100644 --- a/src/main/java/org/skriptlang/skript/bukkit/entity/displays/text/elements/conditions/CondTextDisplaySeeThroughBlocks.java +++ b/src/main/java/org/skriptlang/skript/bukkit/entity/displays/text/elements/conditions/CondTextDisplaySeeThroughBlocks.java @@ -1,5 +1,6 @@ package org.skriptlang.skript.bukkit.entity.displays.text.elements.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -37,6 +38,18 @@ public boolean check(Display value) { return value instanceof TextDisplay textDisplay && textDisplay.isSeeThrough(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(Display display, boolean seeThrough, ChangeMode mode) { + if (display instanceof TextDisplay textDisplay) { + textDisplay.setSeeThrough(seeThrough); + } + } + @Override protected String getPropertyName() { return "visible through blocks"; diff --git a/src/main/java/org/skriptlang/skript/bukkit/entity/interactions/elements/conditions/CondIsResponsive.java b/src/main/java/org/skriptlang/skript/bukkit/entity/interactions/elements/conditions/CondIsResponsive.java index 709112c1c93..2733cc434ff 100644 --- a/src/main/java/org/skriptlang/skript/bukkit/entity/interactions/elements/conditions/CondIsResponsive.java +++ b/src/main/java/org/skriptlang/skript/bukkit/entity/interactions/elements/conditions/CondIsResponsive.java @@ -1,5 +1,6 @@ package org.skriptlang.skript.bukkit.entity.interactions.elements.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -43,6 +44,20 @@ public boolean check(Entity entity) { } return false; } + + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(Entity entity, boolean responsive, ChangeMode mode) { + responsive = responsive == this.responsive; + if (entity instanceof Interaction interaction) { + interaction.setResponsive(responsive); + } + } + @Override protected String getPropertyName() { return responsive ? "responsive" : "unresponsive"; diff --git a/src/main/java/org/skriptlang/skript/bukkit/fishing/elements/conditions/CondFishingLure.java b/src/main/java/org/skriptlang/skript/bukkit/fishing/elements/conditions/CondFishingLure.java index 895fe50de79..3dc3ec7ad72 100644 --- a/src/main/java/org/skriptlang/skript/bukkit/fishing/elements/conditions/CondFishingLure.java +++ b/src/main/java/org/skriptlang/skript/bukkit/fishing/elements/conditions/CondFishingLure.java @@ -1,6 +1,7 @@ package org.skriptlang.skript.bukkit.fishing.elements.conditions; import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.doc.*; import ch.njol.skript.lang.Condition; import ch.njol.skript.lang.Expression; @@ -53,6 +54,19 @@ public boolean check(Event event) { return fishEvent.getHook().getApplyLure() ^ isNegated(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET || mode == ChangeMode.RESET; + } + + @Override + public void change(Event event, boolean applyLure, ChangeMode mode) { + applyLure = applyLure || mode == ChangeMode.RESET; + if (event instanceof PlayerFishEvent fishEvent) { + fishEvent.getHook().setApplyLure(applyLure); + } + } + @Override public String toString(@Nullable Event event, boolean debug) { return "lure enchantment bonus " + (isNegated() ? "is" : "isn't") + " applied"; diff --git a/src/main/java/org/skriptlang/skript/bukkit/potion/elements/conditions/CondIsPotionAmbient.java b/src/main/java/org/skriptlang/skript/bukkit/potion/elements/conditions/CondIsPotionAmbient.java index 94fba734de0..cec7421aed9 100644 --- a/src/main/java/org/skriptlang/skript/bukkit/potion/elements/conditions/CondIsPotionAmbient.java +++ b/src/main/java/org/skriptlang/skript/bukkit/potion/elements/conditions/CondIsPotionAmbient.java @@ -1,5 +1,6 @@ package org.skriptlang.skript.bukkit.potion.elements.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -33,6 +34,16 @@ public boolean check(SkriptPotionEffect potionEffect) { return potionEffect.ambient(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(SkriptPotionEffect potionEffect, boolean ambient, ChangeMode mode) { + potionEffect.ambient(ambient); + } + @Override protected String getPropertyName() { return "ambient"; diff --git a/src/main/java/org/skriptlang/skript/bukkit/potion/elements/conditions/CondPotionHasIcon.java b/src/main/java/org/skriptlang/skript/bukkit/potion/elements/conditions/CondPotionHasIcon.java index f3ccccab7f2..4a3e619ce6d 100644 --- a/src/main/java/org/skriptlang/skript/bukkit/potion/elements/conditions/CondPotionHasIcon.java +++ b/src/main/java/org/skriptlang/skript/bukkit/potion/elements/conditions/CondPotionHasIcon.java @@ -1,5 +1,6 @@ package org.skriptlang.skript.bukkit.potion.elements.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -30,6 +31,16 @@ public boolean check(SkriptPotionEffect potionEffect) { return potionEffect.icon(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(SkriptPotionEffect potionEffect, boolean icon, ChangeMode mode) { + potionEffect.icon(icon); + } + @Override protected PropertyType getPropertyType() { return PropertyType.HAVE; diff --git a/src/main/java/org/skriptlang/skript/bukkit/potion/elements/conditions/CondPotionHasParticles.java b/src/main/java/org/skriptlang/skript/bukkit/potion/elements/conditions/CondPotionHasParticles.java index a0c1d94c9b2..4ed5ae7ecc5 100644 --- a/src/main/java/org/skriptlang/skript/bukkit/potion/elements/conditions/CondPotionHasParticles.java +++ b/src/main/java/org/skriptlang/skript/bukkit/potion/elements/conditions/CondPotionHasParticles.java @@ -1,5 +1,6 @@ package org.skriptlang.skript.bukkit.potion.elements.conditions; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; @@ -30,6 +31,16 @@ public boolean check(SkriptPotionEffect potionEffect) { return potionEffect.particles(); } + @Override + public boolean acceptChange(ChangeMode mode) { + return mode == ChangeMode.SET; + } + + @Override + protected void change(SkriptPotionEffect potionEffect, boolean particles, ChangeMode mode) { + potionEffect.particles(particles); + } + @Override protected PropertyType getPropertyType() { return PropertyType.HAVE; diff --git a/src/main/java/org/skriptlang/skript/common/CommonModule.java b/src/main/java/org/skriptlang/skript/common/CommonModule.java index 762ec04c158..764a53246f2 100644 --- a/src/main/java/org/skriptlang/skript/common/CommonModule.java +++ b/src/main/java/org/skriptlang/skript/common/CommonModule.java @@ -33,7 +33,8 @@ protected void loadSelf(SkriptAddon addon) { ExprColorFromHexCode::register, ExprHexCode::register, ExprRecursiveSize::register, - ExprReplace::register + ExprReplace::register, + ExprWhether::register ); } diff --git a/src/main/java/org/skriptlang/skript/common/elements/expressions/ExprWhether.java b/src/main/java/org/skriptlang/skript/common/elements/expressions/ExprWhether.java new file mode 100644 index 00000000000..fb8880eb09c --- /dev/null +++ b/src/main/java/org/skriptlang/skript/common/elements/expressions/ExprWhether.java @@ -0,0 +1,78 @@ +package org.skriptlang.skript.common.elements.expressions; + +import ch.njol.skript.classes.Changer.ChangeMode; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Example; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.Since; +import ch.njol.skript.lang.Condition; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.skript.lang.util.SimpleExpression; +import ch.njol.util.Kleenean; +import org.bukkit.event.Event; +import org.jetbrains.annotations.Nullable; +import org.skriptlang.skript.registration.SyntaxInfo; +import org.skriptlang.skript.registration.SyntaxRegistry; + +@Name("Whether") +@Description(""" + A shorthand for returning the result of a condition (true or false). + This is functionally identical to using 'true if else false'. + """) +@Example("set {fly} to whether player can fly") +@Example("broadcast \"Flying: %whether player is flying%\"") +@Since("2.9.0") +public class ExprWhether extends SimpleExpression { + + public static void register(SyntaxRegistry syntaxRegistry) { + syntaxRegistry.register(SyntaxRegistry.EXPRESSION, + SyntaxInfo.Expression.builder(ExprWhether.class, Boolean.class) + .supplier(ExprWhether::new) + .addPattern("whether <.+>") + .build()); + } + + private Condition condition; + + @Override + public boolean init(Expression[] expressions, int pattern, Kleenean delayed, ParseResult result) { + String input = result.regexes.getFirst().group(); + this.condition = Condition.parse(input, "Can't understand this condition: " + input); + return condition != null; + } + + @Override + protected Boolean[] get(Event event) { + return new Boolean[]{condition.check(event)}; + } + + @Override + public Class @Nullable [] acceptChange(ChangeMode mode) { + if (condition.acceptChange(mode)) { + return new Class[]{Boolean.class}; + } + return null; + } + + @Override + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { + condition.change(event, delta != null && ((boolean) delta[0] != condition.isNegated()), mode); + } + + @Override + public Class getReturnType() { + return Boolean.class; + } + + @Override + public boolean isSingle() { + return true; + } + + @Override + public String toString(Event event, boolean debug) { + return "whether " + condition.toString(event, debug); + } + +} diff --git a/src/test/skript/tests/bukkit/breeding/CondCanAge.sk b/src/test/skript/tests/bukkit/breeding/CondCanAge.sk new file mode 100644 index 00000000000..9fbefcd5018 --- /dev/null +++ b/src/test/skript/tests/bukkit/breeding/CondCanAge.sk @@ -0,0 +1,14 @@ +test "CondCanAge": + spawn a pig at the event-location: + set {_entity} to the event-entity + + set whether {_entity} can age to true + assert {_entity} can age with "setting to true failed" + set whether {_entity} can age to false + assert {_entity} can not age with "setting to false failed" + set whether {_entity} can not age to false + assert {_entity} can age with "(negated) setting to true failed" + set whether {_entity} can not age to true + assert {_entity} can not age with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/bukkit/breeding/CondCanBreed.sk b/src/test/skript/tests/bukkit/breeding/CondCanBreed.sk new file mode 100644 index 00000000000..44c1aa9f253 --- /dev/null +++ b/src/test/skript/tests/bukkit/breeding/CondCanBreed.sk @@ -0,0 +1,14 @@ +test "CondCanBreed": + spawn a pig at the event-location: + set {_entity} to the event-entity + + set whether {_entity} can breed to true + assert {_entity} can breed with "setting to true failed" + set whether {_entity} can breed to false + assert {_entity} can not breed with "setting to false failed" + set whether {_entity} can not breed to false + assert {_entity} can breed with "(negated) setting to true failed" + set whether {_entity} can not breed to true + assert {_entity} can not breed with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/bukkit/breeding/CondIsAdult.sk b/src/test/skript/tests/bukkit/breeding/CondIsAdult.sk new file mode 100644 index 00000000000..1bbab1a8033 --- /dev/null +++ b/src/test/skript/tests/bukkit/breeding/CondIsAdult.sk @@ -0,0 +1,14 @@ +test "CondIsAdult": + spawn a pig at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is an adult to true + assert {_entity} is an adult with "setting to true failed" + set whether {_entity} is an adult to false + assert {_entity} is not an adult with "setting to false failed" + set whether {_entity} is not an adult to false + assert {_entity} is an adult with "(negated) setting to true failed" + set whether {_entity} is not an adult to true + assert {_entity} is not an adult with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/bukkit/breeding/CondIsBaby.sk b/src/test/skript/tests/bukkit/breeding/CondIsBaby.sk new file mode 100644 index 00000000000..71af5f77f66 --- /dev/null +++ b/src/test/skript/tests/bukkit/breeding/CondIsBaby.sk @@ -0,0 +1,14 @@ +test "CondIsBaby": + spawn a pig at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is a baby to true + assert {_entity} is a baby with "setting to true failed" + set whether {_entity} is a baby to false + assert {_entity} is not a baby with "setting to false failed" + set whether {_entity} is not a baby to false + assert {_entity} is a baby with "(negated) setting to true failed" + set whether {_entity} is not a baby to true + assert {_entity} is not a baby with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/bukkit/entity/displays/CondTextDisplayHasDropShadow.sk b/src/test/skript/tests/bukkit/entity/displays/CondTextDisplayHasDropShadow.sk new file mode 100644 index 00000000000..6812b8a8e21 --- /dev/null +++ b/src/test/skript/tests/bukkit/entity/displays/CondTextDisplayHasDropShadow.sk @@ -0,0 +1,14 @@ +test "CondTextDisplayHasDropShadow": + spawn a text display at the event-location: + set {_entity} to the event-entity + + set whether {_entity} has a drop shadow to true + assert {_entity} has a drop shadow with "setting to true failed" + set whether {_entity} has a drop shadow to false + assert {_entity} does not have a drop shadow with "setting to false failed" + set whether {_entity} does not have a drop shadow to false + assert {_entity} has a drop shadow with "(negated) setting to true failed" + set whether {_entity} does not have a drop shadow to true + assert {_entity} does not have a drop shadow with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/bukkit/entity/displays/CondTextDisplaySeeThroughBlocks.sk b/src/test/skript/tests/bukkit/entity/displays/CondTextDisplaySeeThroughBlocks.sk new file mode 100644 index 00000000000..038fb552d90 --- /dev/null +++ b/src/test/skript/tests/bukkit/entity/displays/CondTextDisplaySeeThroughBlocks.sk @@ -0,0 +1,14 @@ +test "CondTextDisplaySeeThroughBlocks": + spawn a text display at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is visible through blocks to true + assert {_entity} is visible through blocks with "setting to true failed" + set whether {_entity} is visible through blocks to false + assert {_entity} is not visible through blocks with "setting to false failed" + set whether {_entity} is not visible through blocks to false + assert {_entity} is visible through blocks with "(negated) setting to true failed" + set whether {_entity} is not visible through blocks to true + assert {_entity} is not visible through blocks with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/bukkit/entity/interactions/CondIsResponsive.sk b/src/test/skript/tests/bukkit/entity/interactions/CondIsResponsive.sk new file mode 100644 index 00000000000..42256329692 --- /dev/null +++ b/src/test/skript/tests/bukkit/entity/interactions/CondIsResponsive.sk @@ -0,0 +1,14 @@ +test "CondIsResponsive": + spawn an interaction entity at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is responsive to true + assert {_entity} is responsive with "setting to true failed" + set whether {_entity} is responsive to false + assert {_entity} is not responsive with "setting to false failed" + set whether {_entity} is not responsive to false + assert {_entity} is responsive with "(negated) setting to true failed" + set whether {_entity} is not responsive to true + assert {_entity} is not responsive with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondAllayCanDuplicate.sk b/src/test/skript/tests/syntaxes/conditions/CondAllayCanDuplicate.sk new file mode 100644 index 00000000000..8c2d419c606 --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondAllayCanDuplicate.sk @@ -0,0 +1,14 @@ +test "CondAllayCanDuplicate": + spawn an allay at the event-location: + set {_entity} to the event-entity + + set whether {_entity} can duplicate to true + assert {_entity} can duplicate with "setting to true failed" + set whether {_entity} can duplicate to false + assert {_entity} can not duplicate with "setting to false failed" + set whether {_entity} can not duplicate to false + assert {_entity} can duplicate with "(negated) setting to true failed" + set whether {_entity} can not duplicate to true + assert {_entity} can not duplicate with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondCanPickUpItems.sk b/src/test/skript/tests/syntaxes/conditions/CondCanPickUpItems.sk new file mode 100644 index 00000000000..5f426d8a550 --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondCanPickUpItems.sk @@ -0,0 +1,14 @@ +test "CondCanPickUpItems": + spawn an pig at the event-location: + set {_entity} to the event-entity + + set whether {_entity} can pick up items to true + assert {_entity} can pick up items with "setting to true failed" + set whether {_entity} can pick up items to false + assert {_entity} can not pick up items with "setting to false failed" + set whether {_entity} can not pick up items to false + assert {_entity} can pick up items with "(negated) setting to true failed" + set whether {_entity} can not pick up items to true + assert {_entity} can not pick up items with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondEndermanStaredAt.sk b/src/test/skript/tests/syntaxes/conditions/CondEndermanStaredAt.sk new file mode 100644 index 00000000000..6b667ea073f --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondEndermanStaredAt.sk @@ -0,0 +1,14 @@ +test "CondEndermanStaredAt": + spawn an enderman at the event-location: + set {_entity} to the event-entity + + set whether {_entity} has been stared at to true + assert {_entity} has been stared at with "setting to true failed" + set whether {_entity} has been stared at to false + assert {_entity} does not have been stared at with "setting to false failed" + set whether {_entity} does not have been stared at to false + assert {_entity} has been stared at with "(negated) setting to true failed" + set whether {_entity} does not have been stared at to true + assert {_entity} does not have been stared at with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondEntityUnload.sk b/src/test/skript/tests/syntaxes/conditions/CondEntityUnload.sk new file mode 100644 index 00000000000..ae27b2a0b3c --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondEntityUnload.sk @@ -0,0 +1,14 @@ +test "CondEntityUnload": + spawn an pig at the event-location: + set {_entity} to the event-entity + + set whether {_entity} can despawn when far away to true + assert {_entity} can despawn when far away with "setting to true failed" + set whether {_entity} can despawn when far away to false + assert {_entity} can not despawn when far away with "setting to false failed" + set whether {_entity} can not despawn when far away to false + assert {_entity} can despawn when far away with "(negated) setting to true failed" + set whether {_entity} can not despawn when far away to true + assert {_entity} can not despawn when far away with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondGlowingText.sk b/src/test/skript/tests/syntaxes/conditions/CondGlowingText.sk new file mode 100644 index 00000000000..c3a87fa7925 --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondGlowingText.sk @@ -0,0 +1,16 @@ +test "CondGlowingText": + set {_old} to the block at the event-location + set the block at the event-location to an oak sign + + loop the block at the event-location and an oak sign: + set {_holder} to loop-value + set whether {_holder} has glowing text to true + assert {_holder} has glowing text with "setting to true failed" + set whether {_holder} has glowing text to false + assert {_holder} does not have glowing text with "setting to false failed" + set whether {_holder} does not have glowing text to false + assert {_holder} has glowing text with "(negated) setting to true failed" + set whether {_holder} does not have glowing text to true + assert {_holder} does not have glowing text with "(negated) setting to false failed" + + set the block at the event-location to {_old} diff --git a/src/test/skript/tests/syntaxes/conditions/CondGoatHasHorns.sk b/src/test/skript/tests/syntaxes/conditions/CondGoatHasHorns.sk new file mode 100644 index 00000000000..52916ad452d --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondGoatHasHorns.sk @@ -0,0 +1,19 @@ +test "CondGoatHasHorns": + spawn a goat at the event-location: + set {_entity} to the event-entity + + set whether {_entity} has a left horn to true + assert {_entity} has a left horn with "goat does not have a left horn" + assert {_entity} has a horn with "goat does not have any horn" + set whether {_entity} has a right horn to true + assert {_entity} has a right horn with "goat does not have a right horn" + set whether {_entity} has both horns to false + assert {_entity} does not have any horn with "goat has a horn" + assert {_entity} does not have a left horn with "goat has a left horn" + assert {_entity} does not have a right horn with "goat has a right horn" + assert {_entity} does not have both horns with "goat has both horns" + set whether {_entity} does not have a left horn to false + assert {_entity} has a left horn with "(negated) goat does not have a left horn" + assert {_entity} has a horn with "(negated) goat does not have any horn" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondIgnitionProcess.sk b/src/test/skript/tests/syntaxes/conditions/CondIgnitionProcess.sk new file mode 100644 index 00000000000..2b7d41358dd --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIgnitionProcess.sk @@ -0,0 +1,14 @@ +test "CondIgnitionProcess": + spawn a creeper at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is going to explode to true + assert {_entity} is going to explode with "setting to true failed" + set whether {_entity} is going to explode to false + assert {_entity} is not going to explode with "setting to false failed" + set whether {_entity} is not going to explode to false + assert {_entity} is going to explode with "(negated) setting to true failed" + set whether {_entity} is not going to explode to true + assert {_entity} is not going to explode with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondIncendiary.sk b/src/test/skript/tests/syntaxes/conditions/CondIncendiary.sk new file mode 100644 index 00000000000..553d3145e74 --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIncendiary.sk @@ -0,0 +1,14 @@ +test "CondIncendiary": + spawn a tnt at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is incendiary to true + assert {_entity} is incendiary with "setting to true failed" + set whether {_entity} is incendiary to false + assert {_entity} is not incendiary with "setting to false failed" + set whether {_entity} is not incendiary to false + assert {_entity} is incendiary with "(negated) setting to true failed" + set whether {_entity} is not incendiary to true + assert {_entity} is not incendiary with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsCharged.sk b/src/test/skript/tests/syntaxes/conditions/CondIsCharged.sk index 58131c3dff1..41aa152fd1f 100644 --- a/src/test/skript/tests/syntaxes/conditions/CondIsCharged.sk +++ b/src/test/skript/tests/syntaxes/conditions/CondIsCharged.sk @@ -33,3 +33,18 @@ test "is charged": delete entity within {_w} delete entity within {_s} delete entity within {_z} + +test "CondIsCharged": + spawn a creeper at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is charged to true + assert {_entity} is charged with "setting to true failed" + set whether {_entity} is charged to false + assert {_entity} is not charged with "setting to false failed" + set whether {_entity} is not charged to false + assert {_entity} is charged with "(negated) setting to true failed" + set whether {_entity} is not charged to true + assert {_entity} is not charged with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsChargingFireball.sk b/src/test/skript/tests/syntaxes/conditions/CondIsChargingFireball.sk new file mode 100644 index 00000000000..47b6ba72bfb --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIsChargingFireball.sk @@ -0,0 +1,14 @@ +test "CondIsChargingFireball": + spawn a ghast at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is charging a fireball to true + assert {_entity} is charging a fireball with "setting to true failed" + set whether {_entity} is charging a fireball to false + assert {_entity} is not charging a fireball with "setting to false failed" + set whether {_entity} is not charging a fireball to false + assert {_entity} is charging a fireball with "(negated) setting to true failed" + set whether {_entity} is not charging a fireball to true + assert {_entity} is not charging a fireball with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsCommandBlockConditional.sk b/src/test/skript/tests/syntaxes/conditions/CondIsCommandBlockConditional.sk new file mode 100644 index 00000000000..7a9aed8cc44 --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIsCommandBlockConditional.sk @@ -0,0 +1,20 @@ +test "CondIsCommandBlockConditional": + set {_old} to the block at the event-location + set the block at the event-location to a command block + set {_block} to the block at the event-location + + set whether {_block} is conditional to true + assert {_block} is conditional with "setting to true failed" + set whether {_block} is conditional to false + assert {_block} is not conditional with "setting to false failed" + set whether {_block} is not conditional to false + assert {_block} is conditional with "(negated) setting to true failed" + set whether {_block} is not conditional to true + assert {_block} is not conditional with "(negated) setting to false failed" + + set whether {_block} is unconditional to false + assert {_block} is not unconditional with "(un) setting to true failed" + set whether {_block} is not unconditional to false + assert {_block} is unconditional with "(un) (negated) setting to false failed" + + set the block at the event-location to {_old} diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsCustomNameVisible.sk b/src/test/skript/tests/syntaxes/conditions/CondIsCustomNameVisible.sk index 9d2990b8647..6fe2855784e 100644 --- a/src/test/skript/tests/syntaxes/conditions/CondIsCustomNameVisible.sk +++ b/src/test/skript/tests/syntaxes/conditions/CondIsCustomNameVisible.sk @@ -18,3 +18,18 @@ test "custom name visibility": delete entity within {_z} +test "CondIsCustomNameVisible": + spawn a pig at the event-location: + set {_entity} to the event-entity + + set whether {_entity}'s custom name is visible to true + assert {_entity}'s custom name is visible with "setting to true failed" + set whether {_entity}'s custom name is visible to false + assert {_entity}'s custom name is not visible with "setting to false failed" + set whether {_entity}'s custom name is not visible to false + assert {_entity}'s custom name is visible with "(negated) setting to true failed" + set whether {_entity}'s custom name is not visible to true + assert {_entity}'s custom name is not visible with "(negated) setting to false failed" + + delete the entity within {_entity} + diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsDancing.sk b/src/test/skript/tests/syntaxes/conditions/CondIsDancing.sk new file mode 100644 index 00000000000..ba4ba519086 --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIsDancing.sk @@ -0,0 +1,14 @@ +test "CondIsDancing": + spawn an allay at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is dancing to true + assert {_entity} is dancing with "setting to true failed" + set whether {_entity} is dancing to false + assert {_entity} is not dancing with "setting to false failed" + set whether {_entity} is not dancing to false + assert {_entity} is dancing with "(negated) setting to true failed" + set whether {_entity} is not dancing to true + assert {_entity} is not dancing with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsDashing.sk b/src/test/skript/tests/syntaxes/conditions/CondIsDashing.sk new file mode 100644 index 00000000000..b3ab2e70f7c --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIsDashing.sk @@ -0,0 +1,14 @@ +test "CondIsDashing": + spawn a camel at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is dashing to true + assert {_entity} is dashing with "setting to true failed" + set whether {_entity} is dashing to false + assert {_entity} is not dashing with "setting to false failed" + set whether {_entity} is not dashing to false + assert {_entity} is dashing with "(negated) setting to true failed" + set whether {_entity} is not dashing to true + assert {_entity} is not dashing with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsEating.sk b/src/test/skript/tests/syntaxes/conditions/CondIsEating.sk new file mode 100644 index 00000000000..3fa3e5b615a --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIsEating.sk @@ -0,0 +1,14 @@ +test "CondIsEating": + spawn a panda at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is eating to true + assert {_entity} is eating with "setting to true failed" + set whether {_entity} is eating to false + assert {_entity} is not eating with "setting to false failed" + set whether {_entity} is not eating to false + assert {_entity} is eating with "(negated) setting to true failed" + set whether {_entity} is not eating to true + assert {_entity} is not eating with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsFireResistant.sk b/src/test/skript/tests/syntaxes/conditions/CondIsFireResistant.sk index 7cb78fb9b13..8babf104234 100644 --- a/src/test/skript/tests/syntaxes/conditions/CondIsFireResistant.sk +++ b/src/test/skript/tests/syntaxes/conditions/CondIsFireResistant.sk @@ -1,18 +1,17 @@ -test "is fire resistant" when running minecraft "1.20.5": +test "is fire resistant": # single item: naturally not fire resistant set {_item} to diamond assert {_item} is not fire resistant with "diamond is unexpectedly fire resistant" - # TODO: enable in 1.21 (doesn't work in 1.20.5 or 1.20.6) # single item: artificially not fire resistant - # set {_item} to netherite boots without fire resistance - # assert {_item} is not fire resistant with "netherite boots are unexpectedly fire resistant" + set {_item} to netherite boots without fire resistance + assert {_item} is not fire resistant with "netherite boots are unexpectedly fire resistant" - # TODO: enable in 1.21 (doesn't work in 1.20.5 or 1.20.6) + # TODO does not work? # single item: naturally fire resistant - # set {_item} to netherite boots - # assert {_item} is fire resistant with "netherite boots are unexpectedly not fire resistant" + #set {_item} to netherite boots + #assert {_item} is fire resistant with "netherite boots are unexpectedly not fire resistant" # single item: artificially fire resistant set {_item} to fire resistant diamond @@ -23,19 +22,30 @@ test "is fire resistant" when running minecraft "1.20.5": set {_item2} to stone assert ({_item} and {_item2}) are not fire resistant with "{_item} and {_item2} are unexpectedly fire resistant" - # TODO: enable in 1.21 (doesn't work in 1.20.5 or 1.20.6) # multiple items: artificially not fire resistance - # set {_item} to netherite boots without fire resistance - # set {_item2} to netherite helmet without fire resistance - # assert ({_item} and {_item2}) are not fire resistant with "{_item} and {_item2} are unexpectedly fire resistant" + set {_item} to netherite boots without fire resistance + set {_item2} to netherite helmet without fire resistance + assert ({_item} and {_item2}) are not fire resistant with "{_item} and {_item2} are unexpectedly fire resistant" - # TODO: enable in 1.21 (doesn't work in 1.20.5 or 1.20.6) + # TODO does not work? # multiple items: naturally fire resistant - # set {_item} to netherite boots - # set {_item2} to netherite helmet - # assert ({_item} and {_item2}) are fire resistant with "{_item} and {_item2} are unexpectedly not fire resistant" + #set {_item} to netherite boots + #set {_item2} to netherite helmet + #assert ({_item} and {_item2}) are fire resistant with "{_item} and {_item2} are unexpectedly not fire resistant" - # multiple items: artifically fire resistant + # multiple items: artificially fire resistant set {_item} to diamond with fire resistance set {_item2} to fire resistant stone assert ({_item} and {_item2}) are fire resistant with "fire resistant {_item} and {_item2} are unexpectedly not fire resistant" + +test "CondIsFireResistant": + set {_item} to a diamond + + set whether {_item} is fire resistant to true + assert {_item} is fire resistant with "setting to true failed" + set whether {_item} is fire resistant to false + assert {_item} is not fire resistant with "setting to false failed" + set whether {_item} is not fire resistant to false + assert {_item} is fire resistant with "(negated) setting to true failed" + set whether {_item} is not fire resistant to true + assert {_item} is not fire resistant with "(negated) setting to false failed" diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsGliding.sk b/src/test/skript/tests/syntaxes/conditions/CondIsGliding.sk new file mode 100644 index 00000000000..4704b06d99a --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIsGliding.sk @@ -0,0 +1,14 @@ +test "CondIsGliding": + spawn a zombie at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is gliding to true + assert {_entity} is gliding with "setting to true failed" + set whether {_entity} is gliding to false + assert {_entity} is not gliding with "setting to false failed" + set whether {_entity} is not gliding to false + assert {_entity} is gliding with "(negated) setting to true failed" + set whether {_entity} is not gliding to true + assert {_entity} is not gliding with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsInvisible.sk b/src/test/skript/tests/syntaxes/conditions/CondIsInvisible.sk new file mode 100644 index 00000000000..2b3bfb46b39 --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIsInvisible.sk @@ -0,0 +1,18 @@ +test "CondIsInvisible": + spawn a pig at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is invisible to true + assert {_entity} is invisible with "setting to true failed" + set whether {_entity} is invisible to false + assert {_entity} is not invisible with "setting to false failed" + set whether {_entity} is not invisible to false + assert {_entity} is invisible with "(negated) setting to true failed" + set whether {_entity} is not invisible to true + assert {_entity} is not invisible with "(negated) setting to false failed" + set whether {_entity} is visible to false + assert {_entity} is not visible with "(visible) setting to true failed" + set whether {_entity} is not visible to false + assert {_entity} is visible with "(visible) (negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsInvulnerable.sk b/src/test/skript/tests/syntaxes/conditions/CondIsInvulnerable.sk index 50c76b7f1a7..8d8ea1adb6c 100644 --- a/src/test/skript/tests/syntaxes/conditions/CondIsInvulnerable.sk +++ b/src/test/skript/tests/syntaxes/conditions/CondIsInvulnerable.sk @@ -8,5 +8,15 @@ test "CondIsInvulnerable": assert entity is invulnerable with "Entity should be invulnerable" make entity vulnerable assert entity is not invulnerable with "Entity should be vulnerable" + + set whether entity is invulnerable to true + assert entity is invulnerable with "setting to true failed" + set whether entity is invulnerable to false + assert entity is not invulnerable with "setting to false failed" + set whether entity is not invulnerable to false + assert entity is invulnerable with "(negated) setting to true failed" + set whether entity is not invulnerable to true + assert entity is not invulnerable with "(negated) setting to false failed" + delete entity assert {_none} is not invulnerable with "Empty variable should be vulnerable" diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsJumping.sk b/src/test/skript/tests/syntaxes/conditions/CondIsJumping.sk new file mode 100644 index 00000000000..12421142e07 --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIsJumping.sk @@ -0,0 +1,14 @@ +test "CondIsJumping": + spawn a pig at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is jumping to true + assert {_entity} is jumping with "setting to true failed" + set whether {_entity} is jumping to false + assert {_entity} is not jumping with "setting to false failed" + set whether {_entity} is not jumping to false + assert {_entity} is jumping with "(negated) setting to true failed" + set whether {_entity} is not jumping to true + assert {_entity} is not jumping with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsLeftHanded.sk b/src/test/skript/tests/syntaxes/conditions/CondIsLeftHanded.sk new file mode 100644 index 00000000000..b7bace58b84 --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIsLeftHanded.sk @@ -0,0 +1,18 @@ +test "CondIsLeftHanded": + spawn a zombie at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is left handed to true + assert {_entity} is left handed with "setting to true failed" + assert {_entity} is not right handed with "(right) setting to true failed" + set whether {_entity} is left handed to false + assert {_entity} is not left handed with "setting to false failed" + assert {_entity} is right handed with "(right) setting to false failed" + set whether {_entity} is not left handed to false + assert {_entity} is left handed with "(negated) setting to true failed" + set whether {_entity} is not left handed to true + assert {_entity} is not left handed with "(negated) setting to false failed" + set whether {_entity} is not right handed to true + assert {_entity} is left handed with "(right) (negated) setting to true failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsPersistent.sk b/src/test/skript/tests/syntaxes/conditions/CondIsPersistent.sk new file mode 100644 index 00000000000..22266a1eee8 --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIsPersistent.sk @@ -0,0 +1,19 @@ +test "CondIsPersistent": + spawn a pig at the event-location: + set {_entity} to the event-entity + set {_old} to the block at the event-location + set the block at the event-location to oak leaves + + loop {_entity} and the block at the event-location: + set {_holder} to loop-value + set whether {_holder} is persistent to true + assert {_holder} is persistent with "setting to true failed" + set whether {_holder} is persistent to false + assert {_holder} is not persistent with "setting to false failed" + set whether {_holder} is not persistent to false + assert {_holder} is persistent with "(negated) setting to true failed" + set whether {_holder} is not persistent to true + assert {_holder} is not persistent with "(negated) setting to false failed" + + delete the entity within {_entity} + set the block at the event-location to {_old} diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsPlayingDead.sk b/src/test/skript/tests/syntaxes/conditions/CondIsPlayingDead.sk new file mode 100644 index 00000000000..471260a60ca --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIsPlayingDead.sk @@ -0,0 +1,14 @@ +test "CondIsplaying dead": + spawn an axolotl at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is playing dead to true + assert {_entity} is playing dead with "setting to true failed" + set whether {_entity} is playing dead to false + assert {_entity} is not playing dead with "setting to false failed" + set whether {_entity} is not playing dead to false + assert {_entity} is playing dead with "(negated) setting to true failed" + set whether {_entity} is not playing dead to true + assert {_entity} is not playing dead with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsRiptiding.sk b/src/test/skript/tests/syntaxes/conditions/CondIsRiptiding.sk new file mode 100644 index 00000000000..768e94f5717 --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIsRiptiding.sk @@ -0,0 +1,14 @@ +test "CondIsRiptiding": + spawn a zombie at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is riptiding to true + assert {_entity} is riptiding with "setting to true failed" + set whether {_entity} is riptiding to false + assert {_entity} is not riptiding with "setting to false failed" + set whether {_entity} is not riptiding to false + assert {_entity} is riptiding with "(negated) setting to true failed" + set whether {_entity} is not riptiding to true + assert {_entity} is not riptiding with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsSaddled.sk b/src/test/skript/tests/syntaxes/conditions/CondIsSaddled.sk index 92c3067d5ee..045cdec0acb 100644 --- a/src/test/skript/tests/syntaxes/conditions/CondIsSaddled.sk +++ b/src/test/skript/tests/syntaxes/conditions/CondIsSaddled.sk @@ -13,3 +13,18 @@ test "is saddled": delete entity within {_horse} delete entity within {_pig} + +test "CondIsSaddled": + spawn a pig at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is saddled to true + assert {_entity} is saddled with "setting to true failed" + set whether {_entity} is saddled to false + assert {_entity} is not saddled with "setting to false failed" + set whether {_entity} is not saddled to false + assert {_entity} is saddled with "(negated) setting to true failed" + set whether {_entity} is not saddled to true + assert {_entity} is not saddled with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsScreaming.sk b/src/test/skript/tests/syntaxes/conditions/CondIsScreaming.sk new file mode 100644 index 00000000000..614526c41ad --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIsScreaming.sk @@ -0,0 +1,14 @@ +test "CondIsScreaming": + spawn a goat at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is screaming to true + assert {_entity} is screaming with "setting to true failed" + set whether {_entity} is screaming to false + assert {_entity} is not screaming with "setting to false failed" + set whether {_entity} is not screaming to false + assert {_entity} is screaming with "(negated) setting to true failed" + set whether {_entity} is not screaming to true + assert {_entity} is not screaming with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsSheared.sk b/src/test/skript/tests/syntaxes/conditions/CondIsSheared.sk new file mode 100644 index 00000000000..1970f81c3eb --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIsSheared.sk @@ -0,0 +1,14 @@ +test "CondIsSheared": + spawn a sheep at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is sheared to true + assert {_entity} is sheared with "setting to true failed" + set whether {_entity} is sheared to false + assert {_entity} is not sheared with "setting to false failed" + set whether {_entity} is not sheared to false + assert {_entity} is sheared with "(negated) setting to true failed" + set whether {_entity} is not sheared to true + assert {_entity} is not sheared with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsSilent.sk b/src/test/skript/tests/syntaxes/conditions/CondIsSilent.sk new file mode 100644 index 00000000000..2212a615c0b --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIsSilent.sk @@ -0,0 +1,14 @@ +test "CondIsSilent": + spawn a pig at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is silent to true + assert {_entity} is silent with "setting to true failed" + set whether {_entity} is silent to false + assert {_entity} is not silent with "setting to false failed" + set whether {_entity} is not silent to false + assert {_entity} is silent with "(negated) setting to true failed" + set whether {_entity} is not silent to true + assert {_entity} is not silent with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk b/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk index 6f9c20ad52c..4a33000fc2d 100644 --- a/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk +++ b/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk @@ -8,6 +8,10 @@ test "is tamed": tame {_e} assert {_e} is tamed with "taming a horse should do exactly that" + set whether {_e} is tamed to false + assert {_e} is not tamed with "untaming a horse failed" + set whether {_e} is not tamed to false + assert {_e} is tamed with "(negated) taming a horse failed" untame {_e} assert {_e} is not tamed with "untaming a horse should do exactly that" diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsUnbreakable.sk b/src/test/skript/tests/syntaxes/conditions/CondIsUnbreakable.sk new file mode 100644 index 00000000000..8135fdf4358 --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIsUnbreakable.sk @@ -0,0 +1,17 @@ +test "CondIsUnbreakable": + set {_item} to a diamond shovel + + set whether {_item} is unbreakable to true + assert {_item} is unbreakable with "setting to true failed" + assert {_item} is not breakable with "(breakable) setting to true failed" + set whether {_item} is unbreakable to false + assert {_item} is not unbreakable with "setting to false failed" + assert {_item} is breakable with "(breakable) setting to false failed" + set whether {_item} is not unbreakable to false + assert {_item} is unbreakable with "(negated) setting to true failed" + set whether {_item} is not unbreakable to true + assert {_item} is not unbreakable with "(negated) setting to false failed" + set whether {_item} is breakable to false + assert {_item} is not breakable with "(breakable) setting to true failed" + set whether {_item} is not breakable to false + assert {_item} is breakable with "(breakable) (negated) setting to false failed" diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsWhitelisted.sk b/src/test/skript/tests/syntaxes/conditions/CondIsWhitelisted.sk new file mode 100644 index 00000000000..0bde72b3738 --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIsWhitelisted.sk @@ -0,0 +1,32 @@ +test "CondIsWhitelisted": + # The Server + set whether the server is whitelisted to true + assert the server is whitelisted with "setting to true failed" + set whether the server is whitelisted to false + assert the server is not whitelisted with "setting to false failed" + set whether the server is not whitelisted to false + assert the server is whitelisted with "(negated) setting to true failed" + set whether the server is not whitelisted to true + assert the server is not whitelisted with "(negated) setting to false failed" + + # Enforced + set whether the server whitelist is enforced to true + assert the server whitelist is enforced with "setting to true failed" + set whether the server whitelist is enforced to false + assert the server whitelist is not enforced with "setting to false failed" + set whether the server whitelist is not enforced to false + assert the server whitelist is enforced with "(negated) setting to true failed" + set whether the server whitelist is not enforced to true + assert the server whitelist is not enforced with "(negated) setting to false failed" + + # Player + set {_player} to offlineplayer("Notch") + + set whether {_player} is whitelisted to true + assert {_player} is whitelisted with "setting to true failed" + set whether {_player} is whitelisted to false + assert {_player} is not whitelisted with "setting to false failed" + set whether {_player} is not whitelisted to false + assert {_player} is whitelisted with "(negated) setting to true failed" + set whether {_player} is not whitelisted to true + assert {_player} is not whitelisted with "(negated) setting to false failed" diff --git a/src/test/skript/tests/syntaxes/conditions/CondItemDespawn.sk b/src/test/skript/tests/syntaxes/conditions/CondItemDespawn.sk new file mode 100644 index 00000000000..e4e3e19a38e --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondItemDespawn.sk @@ -0,0 +1,14 @@ +test "CondItemDespawn": + spawn a dropped diamond at the event-location: + set {_item} to the event-entity + + set whether {_item} can naturally despawn to true + assert {_item} can naturally despawn with "setting to true failed" + set whether {_item} can naturally despawn to false + assert {_item} can not naturally despawn with "setting to false failed" + set whether {_item} can not naturally despawn to false + assert {_item} can naturally despawn with "(negated) setting to true failed" + set whether {_item} can not naturally despawn to true + assert {_item} can not naturally despawn with "(negated) setting to false failed" + + delete the entity within {_item} diff --git a/src/test/skript/tests/syntaxes/conditions/CondItemEnchantmentGlint.sk b/src/test/skript/tests/syntaxes/conditions/CondItemEnchantmentGlint.sk new file mode 100644 index 00000000000..14fcf21f869 --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondItemEnchantmentGlint.sk @@ -0,0 +1,19 @@ +test "CondItemEnchantmentGlint": + set {_item} to a diamond + + set whether {_item} has enchantment glint overridden to true + assert {_item} has enchantment glint overridden with "setting to true failed" + assert {_item} is forced to glint with "(glint) setting to true failed" + set whether {_item} has enchantment glint overridden to false + assert {_item} does not have enchantment glint overridden with "setting to false failed" + assert {_item} is not forced to glint with "(glint) setting to true failed" + set whether {_item} does not have enchantment glint overridden to false + assert {_item} has enchantment glint overridden with "(negated) setting to true failed" + set whether {_item} does not have enchantment glint overridden to true + assert {_item} does not have enchantment glint overridden with "(negated) setting to false failed" + set whether {_item} is forced to glint to true + assert {_item} has enchantment glint overridden with "setting to true failed" + assert {_item} is forced to glint with "(glint) setting to true failed" + set whether {_item} is not forced to glint to true + assert {_item} has enchantment glint overridden with "setting to false failed" + assert {_item} is not forced to glint with "(glint) setting to false failed" diff --git a/src/test/skript/tests/syntaxes/conditions/CondPandaIsOnBack.sk b/src/test/skript/tests/syntaxes/conditions/CondPandaIsOnBack.sk new file mode 100644 index 00000000000..db78130a97d --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondPandaIsOnBack.sk @@ -0,0 +1,14 @@ +test "CondPandaIsOnBack": + spawn a panda at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is on its back to true + assert {_entity} is on its back with "setting to true failed" + set whether {_entity} is on its back to false + assert {_entity} is not on its back with "setting to false failed" + set whether {_entity} is not on its back to false + assert {_entity} is on its back with "(negated) setting to true failed" + set whether {_entity} is not on its back to true + assert {_entity} is not on its back with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondPandaIsRolling.sk b/src/test/skript/tests/syntaxes/conditions/CondPandaIsRolling.sk new file mode 100644 index 00000000000..af9214733db --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondPandaIsRolling.sk @@ -0,0 +1,14 @@ +test "CondPandaIsRolling": + spawn a panda at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is rolling to true + assert {_entity} is rolling with "setting to true failed" + set whether {_entity} is rolling to false + assert {_entity} is not rolling with "setting to false failed" + set whether {_entity} is not rolling to false + assert {_entity} is rolling with "(negated) setting to true failed" + set whether {_entity} is not rolling to true + assert {_entity} is not rolling with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondPandaIsSneezing.sk b/src/test/skript/tests/syntaxes/conditions/CondPandaIsSneezing.sk new file mode 100644 index 00000000000..e1a87d28c74 --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondPandaIsSneezing.sk @@ -0,0 +1,14 @@ +test "CondPandaIsSneezing": + spawn a panda at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is sneezing to true + assert {_entity} is sneezing with "setting to true failed" + set whether {_entity} is sneezing to false + assert {_entity} is not sneezing with "setting to false failed" + set whether {_entity} is not sneezing to false + assert {_entity} is sneezing with "(negated) setting to true failed" + set whether {_entity} is not sneezing to true + assert {_entity} is not sneezing with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondPvP.sk b/src/test/skript/tests/syntaxes/conditions/CondPvP.sk new file mode 100644 index 00000000000..b316d41d6a7 --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondPvP.sk @@ -0,0 +1,11 @@ +test "CondPvP": + set {_world} to world "world" + + set whether pvp is enabled in {_world} to true + assert pvp is enabled in {_world} with "setting to true failed" + set whether pvp is enabled in {_world} to false + assert pvp is disabled in {_world} with "setting to false failed" + set whether pvp is disabled in {_world} to false + assert pvp is enabled with "(negated) setting to true failed" + set whether pvp is disabled in {_world} to true + assert pvp is disabled in {_world} with "(negated) setting to false failed" diff --git a/src/test/skript/tests/syntaxes/conditions/CondStriderIsShivering.sk b/src/test/skript/tests/syntaxes/conditions/CondStriderIsShivering.sk new file mode 100644 index 00000000000..377c767e0b6 --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondStriderIsShivering.sk @@ -0,0 +1,14 @@ +test "CondStriderIsShivering": + spawn a strider at the event-location: + set {_entity} to the event-entity + + set whether {_entity} is shivering to true + assert {_entity} is shivering with "setting to true failed" + set whether {_entity} is shivering to false + assert {_entity} is not shivering with "setting to false failed" + set whether {_entity} is not shivering to false + assert {_entity} is shivering with "(negated) setting to true failed" + set whether {_entity} is not shivering to true + assert {_entity} is not shivering with "(negated) setting to false failed" + + delete the entity within {_entity} diff --git a/src/test/skript/tests/syntaxes/conditions/CondTooltip.sk b/src/test/skript/tests/syntaxes/conditions/CondTooltip.sk index 117a2b5bbb1..1a015c5784c 100644 --- a/src/test/skript/tests/syntaxes/conditions/CondTooltip.sk +++ b/src/test/skript/tests/syntaxes/conditions/CondTooltip.sk @@ -13,3 +13,28 @@ test "tooltip" when running minecraft "1.20.5": assert entire tooltip of {_item} is shown with "item unexpectedly doesn't have entire tooltip" show additional tooltip of {_item} assert additional tooltip of {_item} is shown with "item unexpectedly doesn't have additional tooltip" + +test "CondTooltip": + set {_item} to a diamond + + set whether the entire tooltip of {_item} is hidden to true + assert the entire tooltip of {_item} is hidden with "setting to true failed" + assert the entire tooltip of {_item} is not shown with "(shown) setting to true failed" + set whether the entire tooltip of {_item} is hidden to false + assert the entire tooltip of {_item} is not hidden with "setting to false failed" + assert the entire tooltip of {_item} is shown with "(shown) setting to false failed" + set whether the entire tooltip of {_item} is not hidden to false + assert the entire tooltip of {_item} is hidden with "(negated) setting to true failed" + set whether the entire tooltip of {_item} is not hidden to true + assert the entire tooltip of {_item} is not hidden with "(negated) setting to false failed" + + set whether the additional tooltip of {_item} is hidden to true + assert the additional tooltip of {_item} is hidden with "setting to true failed" + assert the additional tooltip of {_item} is not shown with "(shown) setting to true failed" + set whether the additional tooltip of {_item} is hidden to false + assert the additional tooltip of {_item} is not hidden with "setting to false failed" + assert the additional tooltip of {_item} is shown with "(shown) setting to false failed" + set whether the additional tooltip of {_item} is not hidden to false + assert the additional tooltip of {_item} is hidden with "(negated) setting to true failed" + set whether the additional tooltip of {_item} is not hidden to true + assert the additional tooltip of {_item} is not hidden with "(negated) setting to false failed"