From 5cc65d7f4b663e2afe5b9ecb4e3655b159deb381 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Tue, 17 Dec 2024 13:27:38 -0500 Subject: [PATCH 01/16] Initial Commit --- .../skript/conditions/CondItemLifetime.java | 59 ++++++++++++++ .../njol/skript/effects/EffItemLifetime.java | 56 +++++++++++++ .../skript/expressions/ExprItemOwner.java | 79 +++++++++++++++++++ .../skript/expressions/ExprItemThrower.java | 79 +++++++++++++++++++ .../syntaxes/expressions/ExprItemOwner.sk | 23 ++++++ 5 files changed, 296 insertions(+) create mode 100644 src/main/java/ch/njol/skript/conditions/CondItemLifetime.java create mode 100644 src/main/java/ch/njol/skript/effects/EffItemLifetime.java create mode 100644 src/main/java/ch/njol/skript/expressions/ExprItemOwner.java create mode 100644 src/main/java/ch/njol/skript/expressions/ExprItemThrower.java create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprItemOwner.sk diff --git a/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java b/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java new file mode 100644 index 00000000000..8bbf6fe4c9c --- /dev/null +++ b/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java @@ -0,0 +1,59 @@ +package ch.njol.skript.conditions; + +import ch.njol.skript.Skript; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.Since; +import ch.njol.skript.lang.Condition; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Item; +import org.bukkit.event.Event; +import org.jetbrains.annotations.Nullable; + +@Name("Item Has Unlimited Lifetime") +@Description("Checks if the dropped item has unlimited lifetime enabled or disabled.") +@Examples({ + "if all dropped items have unlimited lifetime disabled:", + "\tenable unlimited lifetime for all dropped items" +}) +@Since("INSERT VERSION") +public class CondItemLifetime extends Condition { + + static { + Skript.registerCondition(CondItemLifetime.class, ConditionType.PROPERTY, + "[the] %entities% (has|have) unlimited lifetime enabled", + "unlimited lifetime (is|are) enabled for %entities%", + "[the] %entities% (has|have) unlimited lifetime disabled", + "unlimited lifetime (is|are) disabled for %entities%"); + } + + private Expression exprEntity; + private boolean checkEnabled; + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + checkEnabled = matchedPattern <= 1; + //noinspection unchecked + exprEntity = (Expression) exprs[0]; + return true; + } + + @Override + public boolean check(Event event) { + return exprEntity.check(event, entity -> { + if (!(entity instanceof Item item)) + return false; + return item.isUnlimitedLifetime() == checkEnabled; + }); + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "the " + exprEntity.toString(event, debug) + " have unlimited lifetime " + (checkEnabled ? "enabled" : "disabled"); + } + +} diff --git a/src/main/java/ch/njol/skript/effects/EffItemLifetime.java b/src/main/java/ch/njol/skript/effects/EffItemLifetime.java new file mode 100644 index 00000000000..9c1975b8647 --- /dev/null +++ b/src/main/java/ch/njol/skript/effects/EffItemLifetime.java @@ -0,0 +1,56 @@ +package ch.njol.skript.effects; + +import ch.njol.skript.Skript; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.Since; +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Item; +import org.bukkit.event.Event; +import org.jetbrains.annotations.Nullable; + +@Name("Unlimited Item Lifetime") +@Description("Makes a dropped item have unlimited lifetime, meaning it won't despawn from vanilla Minecraft timer.") +@Examples({ + "enabled unlimited lifetime of all dropped items" +}) +@Since("INSERT VERSION") +public class EffItemLifetime extends Effect { + + static { + Skript.registerEffect(EffItemLifetime.class, + "enable unlimited lifetime (of|for) %entities%", + "disable unlimited lifetime (of|for) %entities%"); + } + + private Expression exprEntity; + private boolean enable; + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + enable = matchedPattern == 0; + //noinspection unchecked + exprEntity = (Expression) exprs[0]; + return true; + } + + @Override + protected void execute(Event event) { + for (Entity entity : exprEntity.getArray(event)) { + if (!(entity instanceof Item item)) + continue; + item.setUnlimitedLifetime(enable); + } + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return (enable ? "enable" : "disable") + " unlimited lifetime of " + exprEntity.toString(event, debug); + } + +} diff --git a/src/main/java/ch/njol/skript/expressions/ExprItemOwner.java b/src/main/java/ch/njol/skript/expressions/ExprItemOwner.java new file mode 100644 index 00000000000..6681ee23a10 --- /dev/null +++ b/src/main/java/ch/njol/skript/expressions/ExprItemOwner.java @@ -0,0 +1,79 @@ +package ch.njol.skript.expressions; + +import ch.njol.skript.classes.Changer.ChangeMode; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.Since; +import ch.njol.skript.expressions.base.SimplePropertyExpression; +import ch.njol.util.coll.CollectionUtils; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Item; +import org.bukkit.event.Event; +import org.jetbrains.annotations.Nullable; + +import java.util.UUID; + +@Name("Item Owner") +@Description("The owner of the dropped item.") +@Examples({ + "broadcast the item owner of all dropped items" +}) +@Since("INSERT VERSION") +public class ExprItemOwner extends SimplePropertyExpression { + + static { + registerDefault(ExprItemOwner.class, OfflinePlayer.class, "item owner", "entities"); + } + + @Override + public @Nullable OfflinePlayer convert(Entity entity) { + if (!(entity instanceof Item item)) + return null; + UUID uuid = item.getOwner(); + if (uuid == null) + return null; + return Bukkit.getOfflinePlayer(uuid); + } + + @Override + public Class @Nullable [] acceptChange(ChangeMode mode) { + if (mode == ChangeMode.SET || mode == ChangeMode.DELETE) + return CollectionUtils.array(OfflinePlayer.class, String.class, UUID.class); + return null; + } + + @Override + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { + UUID newId = null; + if (delta != null) { + if (delta[0] instanceof OfflinePlayer offlinePlayer) { + newId = offlinePlayer.getUniqueId(); + } else if (delta[0] instanceof UUID uuid) { + newId = uuid; + } else if (delta[0] instanceof String string) { + newId = UUID.fromString(string); + } + } + + for (Entity entity : getExpr().getArray(event)) { + if (!(entity instanceof Item item)) + continue; + item.setOwner(newId); + } + + } + + @Override + protected String getPropertyName() { + return "item owner"; + } + + @Override + public Class getReturnType() { + return OfflinePlayer.class; + } + +} diff --git a/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java b/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java new file mode 100644 index 00000000000..438295e5584 --- /dev/null +++ b/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java @@ -0,0 +1,79 @@ +package ch.njol.skript.expressions; + +import ch.njol.skript.classes.Changer.ChangeMode; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.Since; +import ch.njol.skript.expressions.base.SimplePropertyExpression; +import ch.njol.util.coll.CollectionUtils; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Item; +import org.bukkit.event.Event; +import org.jetbrains.annotations.Nullable; + +import java.util.UUID; + +@Name("Item Thrower") +@Description("The player that thrown the dropped item.") +@Examples({ + "broadcast the item thrower of all dropped items" +}) +@Since("INSERT VERSION") +public class ExprItemThrower extends SimplePropertyExpression { + + static { + registerDefault(ExprItemThrower.class, OfflinePlayer.class, "[item] thrower", "entities"); + } + + @Override + public @Nullable OfflinePlayer convert(Entity entity) { + if (!(entity instanceof Item item)) + return null; + UUID uuid = item.getThrower(); + if (uuid == null) + return null; + return Bukkit.getOfflinePlayer(uuid); + } + + @Override + public Class @Nullable [] acceptChange(ChangeMode mode) { + if (mode == ChangeMode.SET || mode == ChangeMode.DELETE) + return CollectionUtils.array(OfflinePlayer.class, String.class, UUID.class); + return null; + } + + @Override + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { + UUID newId = null; + if (delta != null) { + if (delta[0] instanceof OfflinePlayer offlinePlayer) { + newId = offlinePlayer.getUniqueId(); + } else if (delta[0] instanceof UUID uuid) { + newId = uuid; + } else if (delta[0] instanceof String string) { + newId = UUID.fromString(string); + } + } + + for (Entity entity : getExpr().getArray(event)) { + if (!(entity instanceof Item item)) + continue; + item.setThrower(newId); + } + + } + + @Override + protected String getPropertyName() { + return "item thrower"; + } + + @Override + public Class getReturnType() { + return OfflinePlayer.class; + } + +} diff --git a/src/test/skript/tests/syntaxes/expressions/ExprItemOwner.sk b/src/test/skript/tests/syntaxes/expressions/ExprItemOwner.sk new file mode 100644 index 00000000000..f5c59cf4d1a --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprItemOwner.sk @@ -0,0 +1,23 @@ +test "item owner": + ### + Combines: + ExprItemOwner + ExprItemThrower + EffItemLifetime + CondItemLifetime + ### + drop a stone at test-location + set {_drop} to last dropped item + + set {_owner} to "Sahvde" parsed as offline player + set the item owner of {_drop} to {_owner} + assert the item owner of {_drop} is {_owner} with "Item Owner was not set to Sahvde" + + set {_thrower} to "Fusezion" parsed as offline player + set the item thrower of {_drop} to {_thrower} + assert the item thrower of {_drop} is {_thrower} with "Item Thrower was not set to Fusezion" + + enable unlimited lifetime for {_drop} + assert unlimited lifetime is enabled for {_drop} with "Unlimited Lifetime was not enabled" + + clear entity within {_drop} From cb3e08e6e716290560c1702575ee0d2016b64ac8 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Tue, 17 Dec 2024 14:20:36 -0500 Subject: [PATCH 02/16] Partial Changes --- .../skript/conditions/CondItemLifetime.java | 23 +++-- .../njol/skript/effects/EffItemLifetime.java | 21 +++-- .../ch/njol/skript/events/SimpleEvents.java | 91 ++----------------- .../skript/expressions/ExprItemOwner.java | 27 +++--- .../skript/expressions/ExprItemThrower.java | 25 ++--- 5 files changed, 57 insertions(+), 130 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java b/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java index 8bbf6fe4c9c..5f6b6a9024b 100644 --- a/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java +++ b/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java @@ -9,7 +9,6 @@ import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; -import org.bukkit.entity.Entity; import org.bukkit.entity.Item; import org.bukkit.event.Event; import org.jetbrains.annotations.Nullable; @@ -25,35 +24,35 @@ public class CondItemLifetime extends Condition { static { Skript.registerCondition(CondItemLifetime.class, ConditionType.PROPERTY, - "[the] %entities% (has|have) unlimited lifetime enabled", - "unlimited lifetime (is|are) enabled for %entities%", - "[the] %entities% (has|have) unlimited lifetime disabled", - "unlimited lifetime (is|are) disabled for %entities%"); + "[the] %itementities% (has|have) unlimited lifetime enabled", + "unlimited lifetime (is|are) enabled for %itementities%", + "[the] %itementities% (has|have) unlimited lifetime", + "[the] %itementities% (has|have) unlimited lifetime disabled", + "unlimited lifetime (is|are) disabled for %itementities%", + "[the] %itementities% (don't|do not|doesn't|does not) have unlimited lifetime"); } - private Expression exprEntity; + private Expression entities; private boolean checkEnabled; @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - checkEnabled = matchedPattern <= 1; + checkEnabled = matchedPattern <= 2; //noinspection unchecked - exprEntity = (Expression) exprs[0]; + entities = (Expression) exprs[0]; return true; } @Override public boolean check(Event event) { - return exprEntity.check(event, entity -> { - if (!(entity instanceof Item item)) - return false; + return entities.check(event, item -> { return item.isUnlimitedLifetime() == checkEnabled; }); } @Override public String toString(@Nullable Event event, boolean debug) { - return "the " + exprEntity.toString(event, debug) + " have unlimited lifetime " + (checkEnabled ? "enabled" : "disabled"); + return "the " + entities.toString(event, debug) + " have unlimited lifetime " + (checkEnabled ? "enabled" : "disabled"); } } diff --git a/src/main/java/ch/njol/skript/effects/EffItemLifetime.java b/src/main/java/ch/njol/skript/effects/EffItemLifetime.java index 9c1975b8647..76e5877b6dc 100644 --- a/src/main/java/ch/njol/skript/effects/EffItemLifetime.java +++ b/src/main/java/ch/njol/skript/effects/EffItemLifetime.java @@ -9,7 +9,6 @@ import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; -import org.bukkit.entity.Entity; import org.bukkit.entity.Item; import org.bukkit.event.Event; import org.jetbrains.annotations.Nullable; @@ -24,33 +23,35 @@ public class EffItemLifetime extends Effect { static { Skript.registerEffect(EffItemLifetime.class, - "enable unlimited lifetime (of|for) %entities%", - "disable unlimited lifetime (of|for) %entities%"); + "enable unlimited lifetime for %itementities%", + "make [the] lifetime unlimited for %itementities%", + "make [the] %itementities% lifetime unlimited", + "disable unlimited lifetime for %itementities%", + "make [the] lifetime limited for %itementities%", + "make [the] %itementities% lifetime limited"); } - private Expression exprEntity; + private Expression entities; private boolean enable; @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - enable = matchedPattern == 0; + enable = matchedPattern <= 2; //noinspection unchecked - exprEntity = (Expression) exprs[0]; + entities = (Expression) exprs[0]; return true; } @Override protected void execute(Event event) { - for (Entity entity : exprEntity.getArray(event)) { - if (!(entity instanceof Item item)) - continue; + for (Item item : entities.getArray(event)) { item.setUnlimitedLifetime(enable); } } @Override public String toString(@Nullable Event event, boolean debug) { - return (enable ? "enable" : "disable") + " unlimited lifetime of " + exprEntity.toString(event, debug); + return (enable ? "enable" : "disable") + " unlimited lifetime of " + entities.toString(event, debug); } } diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index 5bf1ad37ad3..a4649c116c3 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -26,99 +26,24 @@ import com.destroystokyo.paper.event.entity.ProjectileCollideEvent; import com.destroystokyo.paper.event.player.PlayerArmorChangeEvent; import com.destroystokyo.paper.event.player.PlayerJumpEvent; -import com.destroystokyo.paper.event.server.PaperServerListPingEvent; import com.destroystokyo.paper.event.player.PlayerReadyArrowEvent; -import io.papermc.paper.event.player.PlayerStopUsingItemEvent; +import com.destroystokyo.paper.event.server.PaperServerListPingEvent; import io.papermc.paper.event.player.PlayerDeepSleepEvent; import io.papermc.paper.event.player.PlayerInventorySlotChangeEvent; +import io.papermc.paper.event.player.PlayerStopUsingItemEvent; import io.papermc.paper.event.player.PlayerTradeEvent; import org.bukkit.event.Event; -import org.bukkit.event.block.BlockCanBuildEvent; -import org.bukkit.event.block.BlockDamageEvent; -import org.bukkit.event.block.BlockFertilizeEvent; -import org.bukkit.event.block.BlockFromToEvent; -import org.bukkit.event.block.BlockIgniteEvent; -import org.bukkit.event.block.BlockPhysicsEvent; -import org.bukkit.event.block.BlockPistonExtendEvent; -import org.bukkit.event.block.BlockPistonRetractEvent; -import org.bukkit.event.block.BlockRedstoneEvent; -import org.bukkit.event.block.BlockSpreadEvent; -import org.bukkit.event.block.LeavesDecayEvent; -import org.bukkit.event.block.SignChangeEvent; -import org.bukkit.event.block.SpongeAbsorbEvent; +import org.bukkit.event.block.*; import org.bukkit.event.enchantment.EnchantItemEvent; import org.bukkit.event.enchantment.PrepareItemEnchantEvent; -import org.bukkit.event.entity.AreaEffectCloudApplyEvent; -import org.bukkit.event.entity.CreeperPowerEvent; -import org.bukkit.event.entity.EntityBreakDoorEvent; -import org.bukkit.event.entity.EntityCombustEvent; -import org.bukkit.event.entity.EntityDismountEvent; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.entity.EntityMountEvent; -import org.bukkit.event.entity.EntityPortalEnterEvent; -import org.bukkit.event.entity.EntityPortalEvent; -import org.bukkit.event.entity.EntityResurrectEvent; -import org.bukkit.event.entity.EntityTameEvent; -import org.bukkit.event.entity.EntityToggleGlideEvent; -import org.bukkit.event.entity.EntityToggleSwimEvent; -import org.bukkit.event.entity.ExplosionPrimeEvent; -import org.bukkit.event.entity.FoodLevelChangeEvent; -import org.bukkit.event.entity.HorseJumpEvent; -import org.bukkit.event.entity.PigZapEvent; -import org.bukkit.event.entity.ProjectileHitEvent; -import org.bukkit.event.entity.ProjectileLaunchEvent; -import org.bukkit.event.entity.SheepRegrowWoolEvent; -import org.bukkit.event.entity.SlimeSplitEvent; -import org.bukkit.event.entity.PiglinBarterEvent; -import org.bukkit.event.inventory.FurnaceBurnEvent; -import org.bukkit.event.inventory.FurnaceSmeltEvent; -import org.bukkit.event.inventory.InventoryCloseEvent; -import org.bukkit.event.inventory.InventoryDragEvent; -import org.bukkit.event.inventory.InventoryOpenEvent; -import org.bukkit.event.inventory.InventoryPickupItemEvent; -import org.bukkit.event.inventory.PrepareAnvilEvent; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerAnimationEvent; -import org.bukkit.event.player.PlayerBedEnterEvent; -import org.bukkit.event.player.PlayerBedLeaveEvent; -import org.bukkit.event.player.PlayerBucketEmptyEvent; -import org.bukkit.event.player.PlayerBucketFillEvent; -import org.bukkit.event.player.PlayerChangedWorldEvent; -import org.bukkit.event.player.PlayerEggThrowEvent; -import org.bukkit.event.player.PlayerFishEvent; -import org.bukkit.event.player.PlayerItemBreakEvent; -import org.bukkit.event.player.PlayerItemDamageEvent; -import org.bukkit.event.player.PlayerItemHeldEvent; -import org.bukkit.event.player.PlayerItemMendEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerKickEvent; -import org.bukkit.event.player.PlayerLocaleChangeEvent; -import org.bukkit.event.player.PlayerLoginEvent; -import org.bukkit.event.player.PlayerPickupArrowEvent; -import org.bukkit.event.player.PlayerPortalEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerRespawnEvent; -import org.bukkit.event.player.PlayerRiptideEvent; -import org.bukkit.event.player.PlayerSwapHandItemsEvent; -import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.event.player.PlayerToggleFlightEvent; -import org.bukkit.event.player.PlayerToggleSneakEvent; -import org.bukkit.event.player.PlayerToggleSprintEvent; -import org.bukkit.event.player.PlayerExpCooldownChangeEvent; +import org.bukkit.event.entity.*; +import org.bukkit.event.inventory.*; +import org.bukkit.event.player.*; import org.bukkit.event.server.BroadcastMessageEvent; import org.bukkit.event.server.ServerListPingEvent; -import org.bukkit.event.vehicle.VehicleCreateEvent; -import org.bukkit.event.vehicle.VehicleDamageEvent; -import org.bukkit.event.vehicle.VehicleDestroyEvent; -import org.bukkit.event.vehicle.VehicleEnterEvent; -import org.bukkit.event.vehicle.VehicleExitEvent; +import org.bukkit.event.vehicle.*; import org.bukkit.event.weather.LightningStrikeEvent; -import org.bukkit.event.world.ChunkLoadEvent; -import org.bukkit.event.world.ChunkPopulateEvent; -import org.bukkit.event.world.ChunkUnloadEvent; -import org.bukkit.event.world.LootGenerateEvent; -import org.bukkit.event.world.PortalCreateEvent; -import org.bukkit.event.world.SpawnChangeEvent; +import org.bukkit.event.world.*; /** * @author Peter Güttinger diff --git a/src/main/java/ch/njol/skript/expressions/ExprItemOwner.java b/src/main/java/ch/njol/skript/expressions/ExprItemOwner.java index 6681ee23a10..e5d3ba6c1b4 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprItemOwner.java +++ b/src/main/java/ch/njol/skript/expressions/ExprItemOwner.java @@ -22,26 +22,27 @@ "broadcast the item owner of all dropped items" }) @Since("INSERT VERSION") -public class ExprItemOwner extends SimplePropertyExpression { +public class ExprItemOwner extends SimplePropertyExpression { static { - registerDefault(ExprItemOwner.class, OfflinePlayer.class, "item owner", "entities"); + registerDefault(ExprItemOwner.class, Object.class, "item owner", "itementities"); } @Override - public @Nullable OfflinePlayer convert(Entity entity) { - if (!(entity instanceof Item item)) - return null; + public @Nullable Object convert(Item item) { UUID uuid = item.getOwner(); if (uuid == null) return null; + Entity checkEntity = Bukkit.getEntity(uuid); + if (checkEntity != null) + return checkEntity; return Bukkit.getOfflinePlayer(uuid); } @Override public Class @Nullable [] acceptChange(ChangeMode mode) { if (mode == ChangeMode.SET || mode == ChangeMode.DELETE) - return CollectionUtils.array(OfflinePlayer.class, String.class, UUID.class); + return CollectionUtils.array(OfflinePlayer.class, Entity.class, String.class, UUID.class); return null; } @@ -51,6 +52,8 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { if (delta != null) { if (delta[0] instanceof OfflinePlayer offlinePlayer) { newId = offlinePlayer.getUniqueId(); + } else if (delta[0] instanceof Entity entity) { + newId = entity.getUniqueId(); } else if (delta[0] instanceof UUID uuid) { newId = uuid; } else if (delta[0] instanceof String string) { @@ -58,22 +61,20 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { } } - for (Entity entity : getExpr().getArray(event)) { - if (!(entity instanceof Item item)) - continue; + for (Item item : getExpr().getArray(event)) { item.setOwner(newId); } } @Override - protected String getPropertyName() { - return "item owner"; + public Class getReturnType() { + return Object.class; } @Override - public Class getReturnType() { - return OfflinePlayer.class; + protected String getPropertyName() { + return "item owner"; } } diff --git a/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java b/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java index 438295e5584..4386588c56d 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java +++ b/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java @@ -22,26 +22,27 @@ "broadcast the item thrower of all dropped items" }) @Since("INSERT VERSION") -public class ExprItemThrower extends SimplePropertyExpression { +public class ExprItemThrower extends SimplePropertyExpression { static { - registerDefault(ExprItemThrower.class, OfflinePlayer.class, "[item] thrower", "entities"); + registerDefault(ExprItemThrower.class, Object.class, "[dropped] item thrower", "itementities"); } @Override - public @Nullable OfflinePlayer convert(Entity entity) { - if (!(entity instanceof Item item)) - return null; + public @Nullable Object convert(Item item) { UUID uuid = item.getThrower(); if (uuid == null) return null; + Entity checkEntity = Bukkit.getEntity(uuid); + if (checkEntity != null) + return checkEntity; return Bukkit.getOfflinePlayer(uuid); } @Override public Class @Nullable [] acceptChange(ChangeMode mode) { if (mode == ChangeMode.SET || mode == ChangeMode.DELETE) - return CollectionUtils.array(OfflinePlayer.class, String.class, UUID.class); + return CollectionUtils.array(OfflinePlayer.class, Entity.class, String.class, UUID.class); return null; } @@ -51,6 +52,8 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { if (delta != null) { if (delta[0] instanceof OfflinePlayer offlinePlayer) { newId = offlinePlayer.getUniqueId(); + } else if (delta[0] instanceof Entity entity) { + newId = entity.getUniqueId(); } else if (delta[0] instanceof UUID uuid) { newId = uuid; } else if (delta[0] instanceof String string) { @@ -58,9 +61,7 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { } } - for (Entity entity : getExpr().getArray(event)) { - if (!(entity instanceof Item item)) - continue; + for (Item item : getExpr().getArray(event)) { item.setThrower(newId); } @@ -68,12 +69,12 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { @Override protected String getPropertyName() { - return "item thrower"; + return "dropped item thrower"; } @Override - public Class getReturnType() { - return OfflinePlayer.class; + public Class getReturnType() { + return Object.class; } } From 8038154ee4778310af8c034d9a6663c19035e5d9 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:02:10 -0500 Subject: [PATCH 03/16] More Changes --- .../ch/njol/skript/events/SimpleEvents.java | 91 ++++++++++-- .../skript/expressions/ExprEntityOwner.java | 136 ++++++++++++++++++ .../skript/expressions/ExprEntityTamer.java | 103 ------------- .../skript/expressions/ExprItemOwner.java | 80 ----------- .../skript/expressions/ExprItemThrower.java | 4 +- 5 files changed, 220 insertions(+), 194 deletions(-) create mode 100644 src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java delete mode 100644 src/main/java/ch/njol/skript/expressions/ExprEntityTamer.java delete mode 100644 src/main/java/ch/njol/skript/expressions/ExprItemOwner.java diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index a4649c116c3..5bf1ad37ad3 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -26,24 +26,99 @@ import com.destroystokyo.paper.event.entity.ProjectileCollideEvent; import com.destroystokyo.paper.event.player.PlayerArmorChangeEvent; import com.destroystokyo.paper.event.player.PlayerJumpEvent; -import com.destroystokyo.paper.event.player.PlayerReadyArrowEvent; import com.destroystokyo.paper.event.server.PaperServerListPingEvent; +import com.destroystokyo.paper.event.player.PlayerReadyArrowEvent; +import io.papermc.paper.event.player.PlayerStopUsingItemEvent; import io.papermc.paper.event.player.PlayerDeepSleepEvent; import io.papermc.paper.event.player.PlayerInventorySlotChangeEvent; -import io.papermc.paper.event.player.PlayerStopUsingItemEvent; import io.papermc.paper.event.player.PlayerTradeEvent; import org.bukkit.event.Event; -import org.bukkit.event.block.*; +import org.bukkit.event.block.BlockCanBuildEvent; +import org.bukkit.event.block.BlockDamageEvent; +import org.bukkit.event.block.BlockFertilizeEvent; +import org.bukkit.event.block.BlockFromToEvent; +import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.event.block.BlockPhysicsEvent; +import org.bukkit.event.block.BlockPistonExtendEvent; +import org.bukkit.event.block.BlockPistonRetractEvent; +import org.bukkit.event.block.BlockRedstoneEvent; +import org.bukkit.event.block.BlockSpreadEvent; +import org.bukkit.event.block.LeavesDecayEvent; +import org.bukkit.event.block.SignChangeEvent; +import org.bukkit.event.block.SpongeAbsorbEvent; import org.bukkit.event.enchantment.EnchantItemEvent; import org.bukkit.event.enchantment.PrepareItemEnchantEvent; -import org.bukkit.event.entity.*; -import org.bukkit.event.inventory.*; -import org.bukkit.event.player.*; +import org.bukkit.event.entity.AreaEffectCloudApplyEvent; +import org.bukkit.event.entity.CreeperPowerEvent; +import org.bukkit.event.entity.EntityBreakDoorEvent; +import org.bukkit.event.entity.EntityCombustEvent; +import org.bukkit.event.entity.EntityDismountEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntityMountEvent; +import org.bukkit.event.entity.EntityPortalEnterEvent; +import org.bukkit.event.entity.EntityPortalEvent; +import org.bukkit.event.entity.EntityResurrectEvent; +import org.bukkit.event.entity.EntityTameEvent; +import org.bukkit.event.entity.EntityToggleGlideEvent; +import org.bukkit.event.entity.EntityToggleSwimEvent; +import org.bukkit.event.entity.ExplosionPrimeEvent; +import org.bukkit.event.entity.FoodLevelChangeEvent; +import org.bukkit.event.entity.HorseJumpEvent; +import org.bukkit.event.entity.PigZapEvent; +import org.bukkit.event.entity.ProjectileHitEvent; +import org.bukkit.event.entity.ProjectileLaunchEvent; +import org.bukkit.event.entity.SheepRegrowWoolEvent; +import org.bukkit.event.entity.SlimeSplitEvent; +import org.bukkit.event.entity.PiglinBarterEvent; +import org.bukkit.event.inventory.FurnaceBurnEvent; +import org.bukkit.event.inventory.FurnaceSmeltEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.inventory.InventoryDragEvent; +import org.bukkit.event.inventory.InventoryOpenEvent; +import org.bukkit.event.inventory.InventoryPickupItemEvent; +import org.bukkit.event.inventory.PrepareAnvilEvent; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerAnimationEvent; +import org.bukkit.event.player.PlayerBedEnterEvent; +import org.bukkit.event.player.PlayerBedLeaveEvent; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.bukkit.event.player.PlayerBucketFillEvent; +import org.bukkit.event.player.PlayerChangedWorldEvent; +import org.bukkit.event.player.PlayerEggThrowEvent; +import org.bukkit.event.player.PlayerFishEvent; +import org.bukkit.event.player.PlayerItemBreakEvent; +import org.bukkit.event.player.PlayerItemDamageEvent; +import org.bukkit.event.player.PlayerItemHeldEvent; +import org.bukkit.event.player.PlayerItemMendEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerLocaleChangeEvent; +import org.bukkit.event.player.PlayerLoginEvent; +import org.bukkit.event.player.PlayerPickupArrowEvent; +import org.bukkit.event.player.PlayerPortalEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerRiptideEvent; +import org.bukkit.event.player.PlayerSwapHandItemsEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.player.PlayerToggleFlightEvent; +import org.bukkit.event.player.PlayerToggleSneakEvent; +import org.bukkit.event.player.PlayerToggleSprintEvent; +import org.bukkit.event.player.PlayerExpCooldownChangeEvent; import org.bukkit.event.server.BroadcastMessageEvent; import org.bukkit.event.server.ServerListPingEvent; -import org.bukkit.event.vehicle.*; +import org.bukkit.event.vehicle.VehicleCreateEvent; +import org.bukkit.event.vehicle.VehicleDamageEvent; +import org.bukkit.event.vehicle.VehicleDestroyEvent; +import org.bukkit.event.vehicle.VehicleEnterEvent; +import org.bukkit.event.vehicle.VehicleExitEvent; import org.bukkit.event.weather.LightningStrikeEvent; -import org.bukkit.event.world.*; +import org.bukkit.event.world.ChunkLoadEvent; +import org.bukkit.event.world.ChunkPopulateEvent; +import org.bukkit.event.world.ChunkUnloadEvent; +import org.bukkit.event.world.LootGenerateEvent; +import org.bukkit.event.world.PortalCreateEvent; +import org.bukkit.event.world.SpawnChangeEvent; /** * @author Peter Güttinger diff --git a/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java b/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java new file mode 100644 index 00000000000..f9e7d3cba01 --- /dev/null +++ b/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java @@ -0,0 +1,136 @@ +/** + * This file is part of Skript. + * + * Skript is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Skript is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Skript. If not, see . + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ +package ch.njol.skript.expressions; + +import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer.ChangeMode; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.Since; +import ch.njol.skript.expressions.base.SimplePropertyExpression; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.ExpressionType; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; +import ch.njol.util.coll.CollectionUtils; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Item; +import org.bukkit.entity.Tameable; +import org.bukkit.event.Event; +import org.jetbrains.annotations.Nullable; + +import java.util.UUID; + +@Name("Entity Owner") +@Description("The owner of a tameable entity (i.e. horse or wolf) or a dropped item.") +@Examples({ + "set owner of target entity to player", + "delete owner of target entity", + "set {_t} to uuid of tamer of target entity", + "", + "set the owner of all dropped items to player" +}) +@Since("2.5, INSERT VERSION (dropped items)") +public class ExprEntityOwner extends SimplePropertyExpression { + + static { + Skript.registerExpression(ExprEntityOwner.class, Object.class, ExpressionType.PROPERTY, + "[the] (owner|tamer) of %livingentities%", + "[the] [[dropped] item] owner of %itementities%"); + } + + private boolean useTameable; + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + useTameable = matchedPattern == 0; + return super.init(exprs, matchedPattern, isDelayed, parseResult); + } + + @Override + public @Nullable Object convert(Entity entity) { + if (entity instanceof Tameable tameable && tameable.isTamed()) { + return tameable.getOwner(); + } else if (entity instanceof Item item) { + UUID uuid = item.getOwner(); + if (uuid == null) + return null; + Entity checkEntity = Bukkit.getEntity(uuid); + if (checkEntity != null) + return checkEntity; + return Bukkit.getOfflinePlayer(uuid); + } + return null; + } + + @Override + public Class @Nullable [] acceptChange(ChangeMode mode) { + return switch (mode) { + case SET, DELETE, RESET -> { + if (useTameable) + yield CollectionUtils.array(OfflinePlayer.class); + yield CollectionUtils.array(OfflinePlayer.class, Entity.class, String.class); + } + default -> null; + }; + } + + @Override + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { + UUID newId = null; + OfflinePlayer newPlayer = null; + if (delta != null) { + if (delta[0] instanceof OfflinePlayer offlinePlayer) { + newPlayer = offlinePlayer; + newId = offlinePlayer.getUniqueId(); + } else if (delta[0] instanceof Entity entity) { + newId = entity.getUniqueId(); + } else if (delta[0] instanceof String string) { + newId = UUID.fromString(string); + } + } + + for (Entity entity : getExpr().getArray(event)) { + if (entity instanceof Tameable tameable) { + tameable.setOwner(newPlayer); + } else if (entity instanceof Item item) { + item.setOwner(newId); + } + } + } + + @Override + public Class getReturnType() { + return Object.class; + } + + @Override + protected String getPropertyName() { + return "owner"; + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "owner of " + getExpr().toString(event, debug); + } + +} diff --git a/src/main/java/ch/njol/skript/expressions/ExprEntityTamer.java b/src/main/java/ch/njol/skript/expressions/ExprEntityTamer.java deleted file mode 100644 index 5d5cc0883e7..00000000000 --- a/src/main/java/ch/njol/skript/expressions/ExprEntityTamer.java +++ /dev/null @@ -1,103 +0,0 @@ -/** - * This file is part of Skript. - * - * Skript is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Skript is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Skript. If not, see . - * - * Copyright Peter Güttinger, SkriptLang team and contributors - */ -package ch.njol.skript.expressions; - -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Tameable; -import org.bukkit.event.Event; -import org.jetbrains.annotations.Nullable; - -import ch.njol.skript.classes.Changer.ChangeMode; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Examples; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.Since; -import ch.njol.skript.expressions.base.SimplePropertyExpression; -import ch.njol.util.coll.CollectionUtils; - -@Name("Entity Owner") -@Description("The owner of a tameable entity, such as a horse or wolf.") -@Examples({"set owner of target entity to player", - "delete owner of target entity", - "set {_t} to uuid of tamer of target entity"}) -@Since("2.5") -public class ExprEntityTamer extends SimplePropertyExpression { - - static { - register(ExprEntityTamer.class, OfflinePlayer.class, "(owner|tamer)", "livingentities"); - } - - @Nullable - @Override - public Class[] acceptChange(ChangeMode mode) { - if (mode == ChangeMode.SET || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) - return CollectionUtils.array(OfflinePlayer.class); - return null; - } - - @Nullable - @Override - public OfflinePlayer convert(LivingEntity entity) { - if (entity instanceof Tameable) { - Tameable t = ((Tameable) entity); - if (t.isTamed()) { - return ((OfflinePlayer) t.getOwner()); - } - } - return null; - } - - @Override - public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { - OfflinePlayer player = delta == null ? null : ((OfflinePlayer) delta[0]); - switch (mode) { - case SET: - for (LivingEntity entity : getExpr().getAll(e)) { - if (!(entity instanceof Tameable)) - continue; - ((Tameable) entity).setOwner(player); - } - break; - case DELETE: - case RESET: - for (LivingEntity entity : getExpr().getAll(e)) { - if (!(entity instanceof Tameable)) - continue; - ((Tameable) entity).setOwner(null); - } - } - } - - @Override - public Class getReturnType() { - return OfflinePlayer.class; - } - - @Override - protected String getPropertyName() { - return "entity owner"; - } - - @Override - public String toString(@Nullable Event e, boolean d) { - return "owner of " + getExpr().toString(e, d); - } - -} diff --git a/src/main/java/ch/njol/skript/expressions/ExprItemOwner.java b/src/main/java/ch/njol/skript/expressions/ExprItemOwner.java deleted file mode 100644 index e5d3ba6c1b4..00000000000 --- a/src/main/java/ch/njol/skript/expressions/ExprItemOwner.java +++ /dev/null @@ -1,80 +0,0 @@ -package ch.njol.skript.expressions; - -import ch.njol.skript.classes.Changer.ChangeMode; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Examples; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.Since; -import ch.njol.skript.expressions.base.SimplePropertyExpression; -import ch.njol.util.coll.CollectionUtils; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Item; -import org.bukkit.event.Event; -import org.jetbrains.annotations.Nullable; - -import java.util.UUID; - -@Name("Item Owner") -@Description("The owner of the dropped item.") -@Examples({ - "broadcast the item owner of all dropped items" -}) -@Since("INSERT VERSION") -public class ExprItemOwner extends SimplePropertyExpression { - - static { - registerDefault(ExprItemOwner.class, Object.class, "item owner", "itementities"); - } - - @Override - public @Nullable Object convert(Item item) { - UUID uuid = item.getOwner(); - if (uuid == null) - return null; - Entity checkEntity = Bukkit.getEntity(uuid); - if (checkEntity != null) - return checkEntity; - return Bukkit.getOfflinePlayer(uuid); - } - - @Override - public Class @Nullable [] acceptChange(ChangeMode mode) { - if (mode == ChangeMode.SET || mode == ChangeMode.DELETE) - return CollectionUtils.array(OfflinePlayer.class, Entity.class, String.class, UUID.class); - return null; - } - - @Override - public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { - UUID newId = null; - if (delta != null) { - if (delta[0] instanceof OfflinePlayer offlinePlayer) { - newId = offlinePlayer.getUniqueId(); - } else if (delta[0] instanceof Entity entity) { - newId = entity.getUniqueId(); - } else if (delta[0] instanceof UUID uuid) { - newId = uuid; - } else if (delta[0] instanceof String string) { - newId = UUID.fromString(string); - } - } - - for (Item item : getExpr().getArray(event)) { - item.setOwner(newId); - } - - } - - @Override - public Class getReturnType() { - return Object.class; - } - - @Override - protected String getPropertyName() { - return "item owner"; - } - -} diff --git a/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java b/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java index 4386588c56d..4053fe2ddb2 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java +++ b/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java @@ -42,7 +42,7 @@ public class ExprItemThrower extends SimplePropertyExpression { @Override public Class @Nullable [] acceptChange(ChangeMode mode) { if (mode == ChangeMode.SET || mode == ChangeMode.DELETE) - return CollectionUtils.array(OfflinePlayer.class, Entity.class, String.class, UUID.class); + return CollectionUtils.array(OfflinePlayer.class, Entity.class, String.class); return null; } @@ -54,8 +54,6 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { newId = offlinePlayer.getUniqueId(); } else if (delta[0] instanceof Entity entity) { newId = entity.getUniqueId(); - } else if (delta[0] instanceof UUID uuid) { - newId = uuid; } else if (delta[0] instanceof String string) { newId = UUID.fromString(string); } From 572629219117e1ee0b459b373e46efdd094aeac6 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Tue, 17 Dec 2024 16:07:54 -0500 Subject: [PATCH 04/16] Additional Changes --- .../skript/conditions/CondItemLifetime.java | 13 +++--- .../njol/skript/effects/EffItemLifetime.java | 4 +- .../skript/expressions/ExprEntityOwner.java | 41 ++++++++----------- .../skript/expressions/ExprItemThrower.java | 27 ++++++++---- .../{ExprItemOwner.sk => ExprEntityOwner.sk} | 17 ++++++-- .../syntaxes/expressions/ExprEntityTamer.sk | 6 --- 6 files changed, 59 insertions(+), 49 deletions(-) rename src/test/skript/tests/syntaxes/expressions/{ExprItemOwner.sk => ExprEntityOwner.sk} (50%) delete mode 100644 src/test/skript/tests/syntaxes/expressions/ExprEntityTamer.sk diff --git a/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java b/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java index 5f6b6a9024b..27b91fcfe1a 100644 --- a/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java +++ b/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java @@ -24,20 +24,19 @@ public class CondItemLifetime extends Condition { static { Skript.registerCondition(CondItemLifetime.class, ConditionType.PROPERTY, - "[the] %itementities% (has|have) unlimited lifetime enabled", + "[the] %itementities% (has|have) unlimited lifetime [enabled]", "unlimited lifetime (is|are) enabled for %itementities%", - "[the] %itementities% (has|have) unlimited lifetime", "[the] %itementities% (has|have) unlimited lifetime disabled", "unlimited lifetime (is|are) disabled for %itementities%", "[the] %itementities% (don't|do not|doesn't|does not) have unlimited lifetime"); } private Expression entities; - private boolean checkEnabled; + private boolean negated; @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - checkEnabled = matchedPattern <= 2; + negated = matchedPattern <= 1; //noinspection unchecked entities = (Expression) exprs[0]; return true; @@ -45,14 +44,12 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override public boolean check(Event event) { - return entities.check(event, item -> { - return item.isUnlimitedLifetime() == checkEnabled; - }); + return entities.check(event, Item::isUnlimitedLifetime, !negated); } @Override public String toString(@Nullable Event event, boolean debug) { - return "the " + entities.toString(event, debug) + " have unlimited lifetime " + (checkEnabled ? "enabled" : "disabled"); + return "the " + entities.toString(event, debug) + " have unlimited lifetime " + (negated ? "enabled" : "disabled"); } } diff --git a/src/main/java/ch/njol/skript/effects/EffItemLifetime.java b/src/main/java/ch/njol/skript/effects/EffItemLifetime.java index 76e5877b6dc..45066a5fc02 100644 --- a/src/main/java/ch/njol/skript/effects/EffItemLifetime.java +++ b/src/main/java/ch/njol/skript/effects/EffItemLifetime.java @@ -24,11 +24,11 @@ public class EffItemLifetime extends Effect { static { Skript.registerEffect(EffItemLifetime.class, "enable unlimited lifetime for %itementities%", - "make [the] lifetime unlimited for %itementities%", + "make lifetime unlimited for %itementities%", "make [the] %itementities% lifetime unlimited", "disable unlimited lifetime for %itementities%", "make [the] lifetime limited for %itementities%", - "make [the] %itementities% lifetime limited"); + "make %itementities% lifetime limited"); } private Expression entities; diff --git a/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java b/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java index f9e7d3cba01..936bce8056f 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java +++ b/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java @@ -1,21 +1,3 @@ -/** - * This file is part of Skript. - * - * Skript is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Skript is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Skript. If not, see . - * - * Copyright Peter Güttinger, SkriptLang team and contributors - */ package ch.njol.skript.expressions; import ch.njol.skript.Skript; @@ -41,7 +23,10 @@ import java.util.UUID; @Name("Entity Owner") -@Description("The owner of a tameable entity (i.e. horse or wolf) or a dropped item.") +@Description({ + "The owner of a tameable entity (i.e. horse or wolf) or a dropped item.", + "NOTE: If the owner of a dropped item was an entity and was killed, will return their uuid in string form." +}) @Examples({ "set owner of target entity to player", "delete owner of target entity", @@ -77,7 +62,10 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye Entity checkEntity = Bukkit.getEntity(uuid); if (checkEntity != null) return checkEntity; - return Bukkit.getOfflinePlayer(uuid); + OfflinePlayer checkPlayer = Bukkit.getOfflinePlayer(uuid); + if (checkPlayer != null) + return checkPlayer; + return uuid.toString(); } return null; } @@ -105,7 +93,9 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { } else if (delta[0] instanceof Entity entity) { newId = entity.getUniqueId(); } else if (delta[0] instanceof String string) { - newId = UUID.fromString(string); + try { + newId = UUID.fromString(string); + } catch (Exception ignored) {} } } @@ -117,12 +107,17 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { } } } - + @Override public Class getReturnType() { return Object.class; } - + + @Override + public Class[] possibleReturnTypes() { + return CollectionUtils.array(Entity.class, OfflinePlayer.class, String.class); + } + @Override protected String getPropertyName() { return "owner"; diff --git a/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java b/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java index 4053fe2ddb2..d563efbbd6b 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java +++ b/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java @@ -17,7 +17,10 @@ import java.util.UUID; @Name("Item Thrower") -@Description("The player that thrown the dropped item.") +@Description({ + "The entity that threw/dropped the dropped item.", + "NOTE: If the entity that dropped item was was killed, will return their uuid in string form." +}) @Examples({ "broadcast the item thrower of all dropped items" }) @@ -36,7 +39,10 @@ public class ExprItemThrower extends SimplePropertyExpression { Entity checkEntity = Bukkit.getEntity(uuid); if (checkEntity != null) return checkEntity; - return Bukkit.getOfflinePlayer(uuid); + OfflinePlayer checkPlayer = Bukkit.getOfflinePlayer(uuid); + if (checkPlayer != null) + return checkPlayer; + return uuid.toString(); } @Override @@ -55,7 +61,9 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { } else if (delta[0] instanceof Entity entity) { newId = entity.getUniqueId(); } else if (delta[0] instanceof String string) { - newId = UUID.fromString(string); + try { + newId = UUID.fromString(string); + } catch (Exception ignored) {} } } @@ -66,13 +74,18 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { } @Override - protected String getPropertyName() { - return "dropped item thrower"; + public Class getReturnType() { + return Object.class; } @Override - public Class getReturnType() { - return Object.class; + public Class[] possibleReturnTypes() { + return CollectionUtils.array(Entity.class, OfflinePlayer.class, String.class); + } + + @Override + protected String getPropertyName() { + return "dropped item thrower"; } } diff --git a/src/test/skript/tests/syntaxes/expressions/ExprItemOwner.sk b/src/test/skript/tests/syntaxes/expressions/ExprEntityOwner.sk similarity index 50% rename from src/test/skript/tests/syntaxes/expressions/ExprItemOwner.sk rename to src/test/skript/tests/syntaxes/expressions/ExprEntityOwner.sk index f5c59cf4d1a..4c1a06a5e76 100644 --- a/src/test/skript/tests/syntaxes/expressions/ExprItemOwner.sk +++ b/src/test/skript/tests/syntaxes/expressions/ExprEntityOwner.sk @@ -1,4 +1,11 @@ -test "item owner": +test "entity owner of tameable": + spawn a wolf at test-location: + assert event-entity is tameable with "entity is tameable condition not passing, last spawned wolf is not tameable" + set owner of event-entity to "Notch" parsed as offline player + assert "%owner of event-entity%" = "Notch" with "Owner of last spawned wolf was not set" + delete event-entity + +test "item owner of dropped item": ### Combines: ExprItemOwner @@ -9,11 +16,13 @@ test "item owner": drop a stone at test-location set {_drop} to last dropped item - set {_owner} to "Sahvde" parsed as offline player + spawn a sheep at test-location: + set {_owner} to entity set the item owner of {_drop} to {_owner} assert the item owner of {_drop} is {_owner} with "Item Owner was not set to Sahvde" - set {_thrower} to "Fusezion" parsed as offline player + spawn a pig at test-location: + set {_thrower} to entity set the item thrower of {_drop} to {_thrower} assert the item thrower of {_drop} is {_thrower} with "Item Thrower was not set to Fusezion" @@ -21,3 +30,5 @@ test "item owner": assert unlimited lifetime is enabled for {_drop} with "Unlimited Lifetime was not enabled" clear entity within {_drop} + clear entity within {_owner} + clear entity within {_thrower} diff --git a/src/test/skript/tests/syntaxes/expressions/ExprEntityTamer.sk b/src/test/skript/tests/syntaxes/expressions/ExprEntityTamer.sk deleted file mode 100644 index 8d9aa911491..00000000000 --- a/src/test/skript/tests/syntaxes/expressions/ExprEntityTamer.sk +++ /dev/null @@ -1,6 +0,0 @@ -test "entity tamer expression/condition": - spawn a wolf at test-location: - assert event-entity is tameable with "entity is tameable condition not passing, last spawned wolf is not tameable" - set owner of event-entity to "Notch" parsed as offline player - assert "%owner of event-entity%" = "Notch" with "Owner of last spawned wolf was not set" - delete event-entity From e68e255c352d7ff7ac44eae4167d2956a22959e7 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Wed, 18 Dec 2024 04:28:02 -0500 Subject: [PATCH 05/16] Partial Changes --- .../skript/conditions/CondItemLifetime.java | 18 +++++++++--------- .../njol/skript/effects/EffItemLifetime.java | 12 ++++++------ .../skript/expressions/ExprEntityOwner.java | 6 ++++-- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java b/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java index 27b91fcfe1a..2f69a60f214 100644 --- a/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java +++ b/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java @@ -24,19 +24,19 @@ public class CondItemLifetime extends Condition { static { Skript.registerCondition(CondItemLifetime.class, ConditionType.PROPERTY, - "[the] %itementities% (has|have) unlimited lifetime [enabled]", - "unlimited lifetime (is|are) enabled for %itementities%", - "[the] %itementities% (has|have) unlimited lifetime disabled", - "unlimited lifetime (is|are) disabled for %itementities%", - "[the] %itementities% (don't|do not|doesn't|does not) have unlimited lifetime"); + "[the] %itementities% (has|have) (unlimited|infinite) life(time|span) [enabled]", + "(unlimited|infinite) life(time|span) (is|are) enabled for %itementities%", + "[the] %itementities% (has|have) (unlimited|infinite) life(time|span) disabled", + "(unlimited|infinite) life(time|span) (is|are) disabled for %itementities%", + "[the] %itementities% (don't|do not|doesn't|does not) have (unlimited|infinite) life(time|span)"); } private Expression entities; - private boolean negated; + private boolean enabled; @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - negated = matchedPattern <= 1; + enabled = matchedPattern <= 1; //noinspection unchecked entities = (Expression) exprs[0]; return true; @@ -44,12 +44,12 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override public boolean check(Event event) { - return entities.check(event, Item::isUnlimitedLifetime, !negated); + return entities.check(event, Item::isUnlimitedLifetime, !enabled); } @Override public String toString(@Nullable Event event, boolean debug) { - return "the " + entities.toString(event, debug) + " have unlimited lifetime " + (negated ? "enabled" : "disabled"); + return "the " + entities.toString(event, debug) + " have unlimited lifetime " + (enabled ? "enabled" : "disabled"); } } diff --git a/src/main/java/ch/njol/skript/effects/EffItemLifetime.java b/src/main/java/ch/njol/skript/effects/EffItemLifetime.java index 45066a5fc02..cd6f5e34a4f 100644 --- a/src/main/java/ch/njol/skript/effects/EffItemLifetime.java +++ b/src/main/java/ch/njol/skript/effects/EffItemLifetime.java @@ -23,12 +23,12 @@ public class EffItemLifetime extends Effect { static { Skript.registerEffect(EffItemLifetime.class, - "enable unlimited lifetime for %itementities%", - "make lifetime unlimited for %itementities%", - "make [the] %itementities% lifetime unlimited", - "disable unlimited lifetime for %itementities%", - "make [the] lifetime limited for %itementities%", - "make %itementities% lifetime limited"); + "enable (unlimited|infinite) life(time|span) for [the] %itementities%", + "make life(time|span) (unlimited|infinite) for [the] %itementities%", + "make [the] %itementities% life(time|span) (unlimited|infinite)", + "disable (unlimited|infinite) life(time|span) for [the] %itementities%", + "make life(time|span) (limited|finite) for [the] %itementities%", + "make [the] %itementities% life(time|span) (limited|finite)"); } private Expression entities; diff --git a/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java b/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java index 936bce8056f..d30c8892acd 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java +++ b/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java @@ -40,14 +40,16 @@ public class ExprEntityOwner extends SimplePropertyExpression { static { Skript.registerExpression(ExprEntityOwner.class, Object.class, ExpressionType.PROPERTY, "[the] (owner|tamer) of %livingentities%", - "[the] [[dropped] item] owner of %itementities%"); + "[the] %livingentities%'[s] (owner|tamer)", + "[the] [dropped item] owner of %itementities%", + "[the] %itementities%'[s] [dropped item] owner"); } private boolean useTameable; @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - useTameable = matchedPattern == 0; + useTameable = matchedPattern <= 1; return super.init(exprs, matchedPattern, isDelayed, parseResult); } From e64ae59a63cd48180ad83597c3670129b11c9b1d Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Wed, 18 Dec 2024 05:10:10 -0500 Subject: [PATCH 06/16] Superb Changes --- .../ch/njol/skript/effects/EffItemLifetime.java | 8 ++++---- .../njol/skript/expressions/ExprEntityOwner.java | 11 ++++++++--- .../njol/skript/expressions/ExprItemThrower.java | 14 ++++++++------ .../tests/syntaxes/expressions/ExprEntityOwner.sk | 8 ++++---- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffItemLifetime.java b/src/main/java/ch/njol/skript/effects/EffItemLifetime.java index cd6f5e34a4f..fbb93a5662b 100644 --- a/src/main/java/ch/njol/skript/effects/EffItemLifetime.java +++ b/src/main/java/ch/njol/skript/effects/EffItemLifetime.java @@ -24,11 +24,11 @@ public class EffItemLifetime extends Effect { static { Skript.registerEffect(EffItemLifetime.class, "enable (unlimited|infinite) life(time|span) for [the] %itementities%", - "make life(time|span) (unlimited|infinite) for [the] %itementities%", - "make [the] %itementities% life(time|span) (unlimited|infinite)", + "make [the] life(time|span) (unlimited|infinite) for [the] %itementities%", + "make %itementities%'[s] life(time|span) (unlimited|infinite)", "disable (unlimited|infinite) life(time|span) for [the] %itementities%", - "make life(time|span) (limited|finite) for [the] %itementities%", - "make [the] %itementities% life(time|span) (limited|finite)"); + "make [the] life(time|span) (limited|finite) for [the] %itementities%", + "make %itementities%'[s] life(time|span) (limited|finite)"); } private Expression entities; diff --git a/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java b/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java index d30c8892acd..94e937b47b5 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java +++ b/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java @@ -16,6 +16,7 @@ import org.bukkit.OfflinePlayer; import org.bukkit.entity.Entity; import org.bukkit.entity.Item; +import org.bukkit.entity.Player; import org.bukkit.entity.Tameable; import org.bukkit.event.Event; import org.jetbrains.annotations.Nullable; @@ -25,7 +26,11 @@ @Name("Entity Owner") @Description({ "The owner of a tameable entity (i.e. horse or wolf) or a dropped item.", - "NOTE: If the owner of a dropped item was an entity and was killed, will return their uuid in string form." + "NOTES:", + "Getting the owner of a dropped item will only return an alive entity or online player. " + + "If the entity was killed, or the player is offline, will return null.", + "Setting the owner of a dropped item means only that entity or player can pick it up.", + "Dropping an item does not automatically make the entity or player the owner." }) @Examples({ "set owner of target entity to player", @@ -64,10 +69,10 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye Entity checkEntity = Bukkit.getEntity(uuid); if (checkEntity != null) return checkEntity; - OfflinePlayer checkPlayer = Bukkit.getOfflinePlayer(uuid); + Player checkPlayer = Bukkit.getPlayer(uuid); if (checkPlayer != null) return checkPlayer; - return uuid.toString(); + return null; } return null; } diff --git a/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java b/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java index d563efbbd6b..1834eb82f8e 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java +++ b/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java @@ -11,6 +11,7 @@ import org.bukkit.OfflinePlayer; import org.bukkit.entity.Entity; import org.bukkit.entity.Item; +import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.jetbrains.annotations.Nullable; @@ -19,11 +20,12 @@ @Name("Item Thrower") @Description({ "The entity that threw/dropped the dropped item.", - "NOTE: If the entity that dropped item was was killed, will return their uuid in string form." -}) -@Examples({ - "broadcast the item thrower of all dropped items" + "NOTES:", + "Getting the item thrower will only return alive entity or online player. " + + "If the entity was killed, or the player is offline, will return null.", + "Dropping an item does not automatically make the entity or player the owner." }) +@Examples("broadcast the item thrower of all dropped items") @Since("INSERT VERSION") public class ExprItemThrower extends SimplePropertyExpression { @@ -39,10 +41,10 @@ public class ExprItemThrower extends SimplePropertyExpression { Entity checkEntity = Bukkit.getEntity(uuid); if (checkEntity != null) return checkEntity; - OfflinePlayer checkPlayer = Bukkit.getOfflinePlayer(uuid); + Player checkPlayer = Bukkit.getPlayer(uuid); if (checkPlayer != null) return checkPlayer; - return uuid.toString(); + return null; } @Override diff --git a/src/test/skript/tests/syntaxes/expressions/ExprEntityOwner.sk b/src/test/skript/tests/syntaxes/expressions/ExprEntityOwner.sk index 4c1a06a5e76..e46653c0160 100644 --- a/src/test/skript/tests/syntaxes/expressions/ExprEntityOwner.sk +++ b/src/test/skript/tests/syntaxes/expressions/ExprEntityOwner.sk @@ -18,13 +18,13 @@ test "item owner of dropped item": spawn a sheep at test-location: set {_owner} to entity - set the item owner of {_drop} to {_owner} - assert the item owner of {_drop} is {_owner} with "Item Owner was not set to Sahvde" + set the dropped item owner of {_drop} to {_owner} + assert the dropped item owner of {_drop} is {_owner} with "Item Owner was not set to Sahvde" spawn a pig at test-location: set {_thrower} to entity - set the item thrower of {_drop} to {_thrower} - assert the item thrower of {_drop} is {_thrower} with "Item Thrower was not set to Fusezion" + set the dropped item thrower of {_drop} to {_thrower} + assert the dropped item thrower of {_drop} is {_thrower} with "Item Thrower was not set to Fusezion" enable unlimited lifetime for {_drop} assert unlimited lifetime is enabled for {_drop} with "Unlimited Lifetime was not enabled" From 156663686d622312b7f4504b1bed9063dfc44b7d Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Wed, 18 Dec 2024 05:33:07 -0500 Subject: [PATCH 07/16] Allow OfflinePlayer --- .../ch/njol/skript/expressions/ExprEntityOwner.java | 10 +++++----- .../ch/njol/skript/expressions/ExprItemThrower.java | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java b/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java index 94e937b47b5..617bd552035 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java +++ b/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java @@ -27,8 +27,8 @@ @Description({ "The owner of a tameable entity (i.e. horse or wolf) or a dropped item.", "NOTES:", - "Getting the owner of a dropped item will only return an alive entity or online player. " - + "If the entity was killed, or the player is offline, will return null.", + "Getting the owner of a dropped item will only return an alive entity or a player that has played before. " + + "If the entity was killed, or the player has never played before, will return null.", "Setting the owner of a dropped item means only that entity or player can pick it up.", "Dropping an item does not automatically make the entity or player the owner." }) @@ -41,7 +41,7 @@ }) @Since("2.5, INSERT VERSION (dropped items)") public class ExprEntityOwner extends SimplePropertyExpression { - + static { Skript.registerExpression(ExprEntityOwner.class, Object.class, ExpressionType.PROPERTY, "[the] (owner|tamer) of %livingentities%", @@ -69,8 +69,8 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye Entity checkEntity = Bukkit.getEntity(uuid); if (checkEntity != null) return checkEntity; - Player checkPlayer = Bukkit.getPlayer(uuid); - if (checkPlayer != null) + OfflinePlayer checkPlayer = Bukkit.getOfflinePlayer(uuid); + if (checkPlayer.hasPlayedBefore()) return checkPlayer; return null; } diff --git a/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java b/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java index 1834eb82f8e..0b68cd442ed 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java +++ b/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java @@ -21,8 +21,8 @@ @Description({ "The entity that threw/dropped the dropped item.", "NOTES:", - "Getting the item thrower will only return alive entity or online player. " - + "If the entity was killed, or the player is offline, will return null.", + "Getting the item thrower will only return alive entity or a player that has played before. " + + "If the entity was killed, or the player has never played before, will return null.", "Dropping an item does not automatically make the entity or player the owner." }) @Examples("broadcast the item thrower of all dropped items") @@ -41,8 +41,8 @@ public class ExprItemThrower extends SimplePropertyExpression { Entity checkEntity = Bukkit.getEntity(uuid); if (checkEntity != null) return checkEntity; - Player checkPlayer = Bukkit.getPlayer(uuid); - if (checkPlayer != null) + OfflinePlayer checkPlayer = Bukkit.getOfflinePlayer(uuid); + if (checkPlayer.hasPlayedBefore()) return checkPlayer; return null; } From b729925609788e352f174ea48a38688ccfeb7eeb Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Thu, 19 Dec 2024 05:51:55 -0500 Subject: [PATCH 08/16] Partial Changes --- .../ch/njol/skript/bukkitutil/UUIDUtils.java | 33 ++++++++++++++++ .../skript/expressions/ExprEntityOwner.java | 39 ++++--------------- .../skript/expressions/ExprItemThrower.java | 24 +++++------- .../tests/syntaxes/effects/EffItemLifetime.sk | 13 +++++++ .../syntaxes/expressions/ExprEntityOwner.sk | 9 +---- 5 files changed, 65 insertions(+), 53 deletions(-) create mode 100644 src/main/java/ch/njol/skript/bukkitutil/UUIDUtils.java create mode 100644 src/test/skript/tests/syntaxes/effects/EffItemLifetime.sk diff --git a/src/main/java/ch/njol/skript/bukkitutil/UUIDUtils.java b/src/main/java/ch/njol/skript/bukkitutil/UUIDUtils.java new file mode 100644 index 00000000000..162c01e939e --- /dev/null +++ b/src/main/java/ch/njol/skript/bukkitutil/UUIDUtils.java @@ -0,0 +1,33 @@ +package ch.njol.skript.bukkitutil; + +import ch.njol.util.StringUtils; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Entity; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.UUID; + +public class UUIDUtils { + + /** + * Converts {@code object} into a UUID if possible + * @param object + * @return The resulting {@link UUID} + */ + public static @Nullable UUID asUUID(@NotNull Object object) { + if (object instanceof OfflinePlayer offlinePlayer) { + return offlinePlayer.getUniqueId(); + } else if (object instanceof Entity entity) { + return entity.getUniqueId(); + } else if (object instanceof String string && StringUtils.containsAny(string, "-")) { + try { + return UUID.fromString(string); + } catch (Exception ignored) {} + } else if (object instanceof UUID uuid) { + return uuid; + } + return null; + } + +} diff --git a/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java b/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java index 617bd552035..6f26a989c5c 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java +++ b/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java @@ -1,22 +1,19 @@ package ch.njol.skript.expressions; import ch.njol.skript.Skript; +import ch.njol.skript.bukkitutil.UUIDUtils; import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; import ch.njol.skript.doc.Name; import ch.njol.skript.doc.Since; import ch.njol.skript.expressions.base.SimplePropertyExpression; -import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.ExpressionType; -import ch.njol.skript.lang.SkriptParser.ParseResult; -import ch.njol.util.Kleenean; import ch.njol.util.coll.CollectionUtils; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Entity; import org.bukkit.entity.Item; -import org.bukkit.entity.Player; import org.bukkit.entity.Tameable; import org.bukkit.event.Event; import org.jetbrains.annotations.Nullable; @@ -27,9 +24,10 @@ @Description({ "The owner of a tameable entity (i.e. horse or wolf) or a dropped item.", "NOTES:", - "Getting the owner of a dropped item will only return an alive entity or a player that has played before. " + "Getting the owner of a dropped item will only return a loaded entity or a player that has played before. " + "If the entity was killed, or the player has never played before, will return null.", - "Setting the owner of a dropped item means only that entity or player can pick it up.", + "Setting the owner of a dropped item means only that entity or player can pick it up. " + + "This is UUID based, so it can also be set to a specific UUID.", "Dropping an item does not automatically make the entity or player the owner." }) @Examples({ @@ -50,14 +48,6 @@ public class ExprEntityOwner extends SimplePropertyExpression { "[the] %itementities%'[s] [dropped item] owner"); } - private boolean useTameable; - - @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - useTameable = matchedPattern <= 1; - return super.init(exprs, matchedPattern, isDelayed, parseResult); - } - @Override public @Nullable Object convert(Entity entity) { if (entity instanceof Tameable tameable && tameable.isTamed()) { @@ -80,11 +70,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override public Class @Nullable [] acceptChange(ChangeMode mode) { return switch (mode) { - case SET, DELETE, RESET -> { - if (useTameable) - yield CollectionUtils.array(OfflinePlayer.class); - yield CollectionUtils.array(OfflinePlayer.class, Entity.class, String.class); - } + case SET, DELETE, RESET -> CollectionUtils.array(OfflinePlayer.class, Entity.class, String.class); default -> null; }; } @@ -97,12 +83,8 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { if (delta[0] instanceof OfflinePlayer offlinePlayer) { newPlayer = offlinePlayer; newId = offlinePlayer.getUniqueId(); - } else if (delta[0] instanceof Entity entity) { - newId = entity.getUniqueId(); - } else if (delta[0] instanceof String string) { - try { - newId = UUID.fromString(string); - } catch (Exception ignored) {} + } else { + newId = UUIDUtils.asUUID(delta[0]); } } @@ -122,7 +104,7 @@ public Class getReturnType() { @Override public Class[] possibleReturnTypes() { - return CollectionUtils.array(Entity.class, OfflinePlayer.class, String.class); + return CollectionUtils.array(Entity.class, OfflinePlayer.class); } @Override @@ -130,9 +112,4 @@ protected String getPropertyName() { return "owner"; } - @Override - public String toString(@Nullable Event event, boolean debug) { - return "owner of " + getExpr().toString(event, debug); - } - } diff --git a/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java b/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java index 0b68cd442ed..dfe9c26b257 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java +++ b/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java @@ -1,5 +1,6 @@ package ch.njol.skript.expressions; +import ch.njol.skript.bukkitutil.UUIDUtils; import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; @@ -11,7 +12,6 @@ import org.bukkit.OfflinePlayer; import org.bukkit.entity.Entity; import org.bukkit.entity.Item; -import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.jetbrains.annotations.Nullable; @@ -22,10 +22,13 @@ "The entity that threw/dropped the dropped item.", "NOTES:", "Getting the item thrower will only return alive entity or a player that has played before. " - + "If the entity was killed, or the player has never played before, will return null.", - "Dropping an item does not automatically make the entity or player the owner." + + "If the entity was killed, or the player has never played before, will return null." +}) +@Examples({ + "broadcast the item thrower of all dropped items", + "set the dropped item thrower of {_dropped item} to player", + "clear the item thrower of {_dropped item}" }) -@Examples("broadcast the item thrower of all dropped items") @Since("INSERT VERSION") public class ExprItemThrower extends SimplePropertyExpression { @@ -58,21 +61,12 @@ public class ExprItemThrower extends SimplePropertyExpression { public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { UUID newId = null; if (delta != null) { - if (delta[0] instanceof OfflinePlayer offlinePlayer) { - newId = offlinePlayer.getUniqueId(); - } else if (delta[0] instanceof Entity entity) { - newId = entity.getUniqueId(); - } else if (delta[0] instanceof String string) { - try { - newId = UUID.fromString(string); - } catch (Exception ignored) {} - } + newId = UUIDUtils.asUUID(delta[0]); } for (Item item : getExpr().getArray(event)) { item.setThrower(newId); } - } @Override @@ -82,7 +76,7 @@ public Class getReturnType() { @Override public Class[] possibleReturnTypes() { - return CollectionUtils.array(Entity.class, OfflinePlayer.class, String.class); + return CollectionUtils.array(Entity.class, OfflinePlayer.class); } @Override diff --git a/src/test/skript/tests/syntaxes/effects/EffItemLifetime.sk b/src/test/skript/tests/syntaxes/effects/EffItemLifetime.sk new file mode 100644 index 00000000000..fb5f6896b14 --- /dev/null +++ b/src/test/skript/tests/syntaxes/effects/EffItemLifetime.sk @@ -0,0 +1,13 @@ +test "dropped item lifetime": + ### + Combines: + EffItemLifetime + CondItemLifetime + ### + drop a stone at test-location + set {_drop} to last dropped item + + enable unlimited lifetime for {_drop} + assert unlimited lifetime is enabled for {_drop} with "Unlimited Lifetime was not enabled" + + clear entity within {_drop} diff --git a/src/test/skript/tests/syntaxes/expressions/ExprEntityOwner.sk b/src/test/skript/tests/syntaxes/expressions/ExprEntityOwner.sk index e46653c0160..887b2512143 100644 --- a/src/test/skript/tests/syntaxes/expressions/ExprEntityOwner.sk +++ b/src/test/skript/tests/syntaxes/expressions/ExprEntityOwner.sk @@ -10,8 +10,6 @@ test "item owner of dropped item": Combines: ExprItemOwner ExprItemThrower - EffItemLifetime - CondItemLifetime ### drop a stone at test-location set {_drop} to last dropped item @@ -19,15 +17,12 @@ test "item owner of dropped item": spawn a sheep at test-location: set {_owner} to entity set the dropped item owner of {_drop} to {_owner} - assert the dropped item owner of {_drop} is {_owner} with "Item Owner was not set to Sahvde" + assert the dropped item owner of {_drop} is {_owner} with "Item Owner was not set to sheep" spawn a pig at test-location: set {_thrower} to entity set the dropped item thrower of {_drop} to {_thrower} - assert the dropped item thrower of {_drop} is {_thrower} with "Item Thrower was not set to Fusezion" - - enable unlimited lifetime for {_drop} - assert unlimited lifetime is enabled for {_drop} with "Unlimited Lifetime was not enabled" + assert the dropped item thrower of {_drop} is {_thrower} with "Item Thrower was not set to pig" clear entity within {_drop} clear entity within {_owner} From 9dae51e02cb16032b26031fe389945c827af1c4f Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Thu, 19 Dec 2024 12:46:45 -0500 Subject: [PATCH 09/16] Update Patterns --- .../ch/njol/skript/bukkitutil/UUIDUtils.java | 3 ++ .../skript/conditions/CondItemLifetime.java | 26 ++++++++-------- .../njol/skript/effects/EffItemLifetime.java | 31 +++++++++++-------- .../skript/expressions/ExprEntityOwner.java | 4 +-- .../tests/syntaxes/effects/EffItemLifetime.sk | 4 +-- 5 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/main/java/ch/njol/skript/bukkitutil/UUIDUtils.java b/src/main/java/ch/njol/skript/bukkitutil/UUIDUtils.java index 162c01e939e..aae6835518e 100644 --- a/src/main/java/ch/njol/skript/bukkitutil/UUIDUtils.java +++ b/src/main/java/ch/njol/skript/bukkitutil/UUIDUtils.java @@ -8,6 +8,9 @@ import java.util.UUID; +/** + * Utility class for quick {@link UUID} methods. + */ public class UUIDUtils { /** diff --git a/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java b/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java index 2f69a60f214..46257dda735 100644 --- a/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java +++ b/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java @@ -13,30 +13,30 @@ import org.bukkit.event.Event; import org.jetbrains.annotations.Nullable; -@Name("Item Has Unlimited Lifetime") -@Description("Checks if the dropped item has unlimited lifetime enabled or disabled.") +@Name("Will Despawn") +@Description("Checks if the dropped item will be despawned naturally through Minecraft's timer.") @Examples({ - "if all dropped items have unlimited lifetime disabled:", - "\tenable unlimited lifetime for all dropped items" + "if all dropped items can despawn naturally:", + "\tprevent all dropped items from naturally despawning" }) @Since("INSERT VERSION") public class CondItemLifetime extends Condition { static { Skript.registerCondition(CondItemLifetime.class, ConditionType.PROPERTY, - "[the] %itementities% (has|have) (unlimited|infinite) life(time|span) [enabled]", - "(unlimited|infinite) life(time|span) (is|are) enabled for %itementities%", - "[the] %itementities% (has|have) (unlimited|infinite) life(time|span) disabled", - "(unlimited|infinite) life(time|span) (is|are) disabled for %itementities%", - "[the] %itementities% (don't|do not|doesn't|does not) have (unlimited|infinite) life(time|span)"); + "%itementities% can despawn naturally", + "%itementities% can naturally despawn", + "%itementities% (can not|can't) despawn naturally", + "%itementities% (can not|can't) naturally despawn" + ); } private Expression entities; - private boolean enabled; + private boolean canDespawn; @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - enabled = matchedPattern <= 1; + canDespawn = matchedPattern <= 1; //noinspection unchecked entities = (Expression) exprs[0]; return true; @@ -44,12 +44,12 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override public boolean check(Event event) { - return entities.check(event, Item::isUnlimitedLifetime, !enabled); + return entities.check(event, Item::isUnlimitedLifetime, canDespawn); } @Override public String toString(@Nullable Event event, boolean debug) { - return "the " + entities.toString(event, debug) + " have unlimited lifetime " + (enabled ? "enabled" : "disabled"); + return "the " + entities.toString(event, debug) + (canDespawn ? " can " : " can not ") + "despawn naturally"; } } diff --git a/src/main/java/ch/njol/skript/effects/EffItemLifetime.java b/src/main/java/ch/njol/skript/effects/EffItemLifetime.java index fbb93a5662b..2fc6fa2941f 100644 --- a/src/main/java/ch/njol/skript/effects/EffItemLifetime.java +++ b/src/main/java/ch/njol/skript/effects/EffItemLifetime.java @@ -13,30 +13,29 @@ import org.bukkit.event.Event; import org.jetbrains.annotations.Nullable; -@Name("Unlimited Item Lifetime") -@Description("Makes a dropped item have unlimited lifetime, meaning it won't despawn from vanilla Minecraft timer.") +@Name("Item Despawn") +@Description("Prevent a dropped item from naturally despawning through Minecraft's timer.") @Examples({ - "enabled unlimited lifetime of all dropped items" + "prevent all dropped items from naturally despawning", + "allow all dropped items to naturally despawn" }) @Since("INSERT VERSION") public class EffItemLifetime extends Effect { static { Skript.registerEffect(EffItemLifetime.class, - "enable (unlimited|infinite) life(time|span) for [the] %itementities%", - "make [the] life(time|span) (unlimited|infinite) for [the] %itementities%", - "make %itementities%'[s] life(time|span) (unlimited|infinite)", - "disable (unlimited|infinite) life(time|span) for [the] %itementities%", - "make [the] life(time|span) (limited|finite) for [the] %itementities%", - "make %itementities%'[s] life(time|span) (limited|finite)"); + "prevent %itementities% from naturally despawning", + "prevent %itementities% from despawning naturally", + "allow %itementities% to naturally despawn", + "allow %itementities% to despawn naturally"); } private Expression entities; - private boolean enable; + private boolean prevent; @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - enable = matchedPattern <= 2; + prevent = matchedPattern <= 1; //noinspection unchecked entities = (Expression) exprs[0]; return true; @@ -45,13 +44,19 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override protected void execute(Event event) { for (Item item : entities.getArray(event)) { - item.setUnlimitedLifetime(enable); + item.setUnlimitedLifetime(prevent); } } @Override public String toString(@Nullable Event event, boolean debug) { - return (enable ? "enable" : "disable") + " unlimited lifetime of " + entities.toString(event, debug); + String start = "prevent "; + String designation = "from "; + if (!prevent) { + start = "allow "; + designation = "to "; + } + return start + entities.toString(event, debug) + designation + "naturally despawning"; } } diff --git a/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java b/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java index 6f26a989c5c..e2d32c62c55 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java +++ b/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java @@ -43,9 +43,9 @@ public class ExprEntityOwner extends SimplePropertyExpression { static { Skript.registerExpression(ExprEntityOwner.class, Object.class, ExpressionType.PROPERTY, "[the] (owner|tamer) of %livingentities%", - "[the] %livingentities%'[s] (owner|tamer)", + "%livingentities%'[s] (owner|tamer)", "[the] [dropped item] owner of %itementities%", - "[the] %itementities%'[s] [dropped item] owner"); + "%itementities%'[s] [dropped item] owner"); } @Override diff --git a/src/test/skript/tests/syntaxes/effects/EffItemLifetime.sk b/src/test/skript/tests/syntaxes/effects/EffItemLifetime.sk index fb5f6896b14..b6f48688d57 100644 --- a/src/test/skript/tests/syntaxes/effects/EffItemLifetime.sk +++ b/src/test/skript/tests/syntaxes/effects/EffItemLifetime.sk @@ -7,7 +7,7 @@ test "dropped item lifetime": drop a stone at test-location set {_drop} to last dropped item - enable unlimited lifetime for {_drop} - assert unlimited lifetime is enabled for {_drop} with "Unlimited Lifetime was not enabled" + prevent {_drop} from naturally despawning + assert {_drop} can not despawn naturally with "Dropped Item should not be able to despawn" clear entity within {_drop} From 3147d5f3f44cdaebd4aa67749096d293470d39c1 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:46:03 -0500 Subject: [PATCH 10/16] Additional Changes --- .../skript/conditions/CondItemLifetime.java | 10 ++++----- .../njol/skript/effects/EffItemLifetime.java | 21 +++++++++---------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java b/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java index 46257dda735..1bbc15fa178 100644 --- a/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java +++ b/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java @@ -24,10 +24,8 @@ public class CondItemLifetime extends Condition { static { Skript.registerCondition(CondItemLifetime.class, ConditionType.PROPERTY, - "%itementities% can despawn naturally", - "%itementities% can naturally despawn", - "%itementities% (can not|can't) despawn naturally", - "%itementities% (can not|can't) naturally despawn" + "%itementities% can (despawn naturally|naturally despawn)", + "%itementities% (can not|can't) (despawn naturally|naturally despawn)" ); } @@ -36,7 +34,7 @@ public class CondItemLifetime extends Condition { @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - canDespawn = matchedPattern <= 1; + canDespawn = matchedPattern == 0; //noinspection unchecked entities = (Expression) exprs[0]; return true; @@ -49,7 +47,7 @@ public boolean check(Event event) { @Override public String toString(@Nullable Event event, boolean debug) { - return "the " + entities.toString(event, debug) + (canDespawn ? " can " : " can not ") + "despawn naturally"; + return entities.toString(event, debug) + (canDespawn ? " can " : " can not ") + "despawn naturally"; } } diff --git a/src/main/java/ch/njol/skript/effects/EffItemLifetime.java b/src/main/java/ch/njol/skript/effects/EffItemLifetime.java index 2fc6fa2941f..13af4bbf5b0 100644 --- a/src/main/java/ch/njol/skript/effects/EffItemLifetime.java +++ b/src/main/java/ch/njol/skript/effects/EffItemLifetime.java @@ -8,6 +8,7 @@ import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.skript.lang.SyntaxStringBuilder; import ch.njol.util.Kleenean; import org.bukkit.entity.Item; import org.bukkit.event.Event; @@ -24,10 +25,8 @@ public class EffItemLifetime extends Effect { static { Skript.registerEffect(EffItemLifetime.class, - "prevent %itementities% from naturally despawning", - "prevent %itementities% from despawning naturally", - "allow %itementities% to naturally despawn", - "allow %itementities% to despawn naturally"); + "(prevent|disallow) %itementities% from (naturally despawning|despawning naturally)", + "allow %itementities% to (naturally despawn|despawn naturally)"); } private Expression entities; @@ -35,7 +34,7 @@ public class EffItemLifetime extends Effect { @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - prevent = matchedPattern <= 1; + prevent = matchedPattern == 0; //noinspection unchecked entities = (Expression) exprs[0]; return true; @@ -50,13 +49,13 @@ protected void execute(Event event) { @Override public String toString(@Nullable Event event, boolean debug) { - String start = "prevent "; - String designation = "from "; - if (!prevent) { - start = "allow "; - designation = "to "; + SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug); + if (prevent) { + builder.append("prevent", entities, "from naturally despawning"); + } else { + builder.append("allow", entities, "to naturally despawn"); } - return start + entities.toString(event, debug) + designation + "naturally despawning"; + return builder.toString(); } } From 462551d2d73e938db67c0ae06c08c631a4f262b8 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Thu, 19 Dec 2024 17:10:16 -0500 Subject: [PATCH 11/16] Surplus Changes --- .../ch/njol/skript/bukkitutil/UUIDUtils.java | 27 +++++++++++++++++++ .../skript/conditions/CondItemLifetime.java | 20 +++++--------- .../skript/expressions/ExprEntityOwner.java | 8 +----- .../skript/expressions/ExprItemThrower.java | 11 ++------ 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/main/java/ch/njol/skript/bukkitutil/UUIDUtils.java b/src/main/java/ch/njol/skript/bukkitutil/UUIDUtils.java index aae6835518e..fef1709dfcd 100644 --- a/src/main/java/ch/njol/skript/bukkitutil/UUIDUtils.java +++ b/src/main/java/ch/njol/skript/bukkitutil/UUIDUtils.java @@ -1,6 +1,7 @@ package ch.njol.skript.bukkitutil; import ch.njol.util.StringUtils; +import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Entity; import org.jetbrains.annotations.NotNull; @@ -33,4 +34,30 @@ public class UUIDUtils { return null; } + /** + * Get the {@link Entity} or {@link OfflinePlayer} the {@code uuid} belongs to. + * Will return an {@link OfflinePlayer} regardless if the player exists. + * @param uuid The {@link UUID} + * @return The resulting {@link Entity} or {@link OfflinePlayer} + */ + public static @Nullable Object fromUUID(@NotNull UUID uuid) { + return fromUUID(uuid, false); + } + + /** + * Get the {@link Entity} or {@link OfflinePlayer} the {@code uuid} belongs to. + * @param uuid The {@link UUID} + * @param restrictOffline If the {@link OfflinePlayer} needs to have played the server. + * @return The resulting {@link Entity} or {@link OfflinePlayer} + */ + public static @Nullable Object fromUUID(@NotNull UUID uuid, boolean restrictOffline) { + Entity checkEntity = Bukkit.getEntity(uuid); + if (checkEntity != null) + return checkEntity; + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid); + if (!restrictOffline || (restrictOffline && offlinePlayer.hasPlayedBefore())) + return offlinePlayer; + return null; + } + } diff --git a/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java b/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java index 1bbc15fa178..d86da941e63 100644 --- a/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java +++ b/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java @@ -1,17 +1,14 @@ package ch.njol.skript.conditions; -import ch.njol.skript.Skript; +import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; import ch.njol.skript.doc.Name; import ch.njol.skript.doc.Since; -import ch.njol.skript.lang.Condition; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; import org.bukkit.entity.Item; -import org.bukkit.event.Event; -import org.jetbrains.annotations.Nullable; @Name("Will Despawn") @Description("Checks if the dropped item will be despawned naturally through Minecraft's timer.") @@ -20,13 +17,10 @@ "\tprevent all dropped items from naturally despawning" }) @Since("INSERT VERSION") -public class CondItemLifetime extends Condition { +public class CondItemLifetime extends PropertyCondition { static { - Skript.registerCondition(CondItemLifetime.class, ConditionType.PROPERTY, - "%itementities% can (despawn naturally|naturally despawn)", - "%itementities% (can not|can't) (despawn naturally|naturally despawn)" - ); + PropertyCondition.register(CondItemLifetime.class, PropertyType.CAN, "(despawn naturally|naturally despawn)", "itementities"); } private Expression entities; @@ -41,13 +35,13 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye } @Override - public boolean check(Event event) { - return entities.check(event, Item::isUnlimitedLifetime, canDespawn); + public boolean check(Item item) { + return item.isUnlimitedLifetime(); } @Override - public String toString(@Nullable Event event, boolean debug) { - return entities.toString(event, debug) + (canDespawn ? " can " : " can not ") + "despawn naturally"; + protected String getPropertyName() { + return "naturally despawn"; } } diff --git a/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java b/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java index e2d32c62c55..d85c5df3f4a 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java +++ b/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java @@ -56,13 +56,7 @@ public class ExprEntityOwner extends SimplePropertyExpression { UUID uuid = item.getOwner(); if (uuid == null) return null; - Entity checkEntity = Bukkit.getEntity(uuid); - if (checkEntity != null) - return checkEntity; - OfflinePlayer checkPlayer = Bukkit.getOfflinePlayer(uuid); - if (checkPlayer.hasPlayedBefore()) - return checkPlayer; - return null; + return UUIDUtils.fromUUID(uuid, true); } return null; } diff --git a/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java b/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java index dfe9c26b257..babf1ced688 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java +++ b/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java @@ -8,7 +8,6 @@ import ch.njol.skript.doc.Since; import ch.njol.skript.expressions.base.SimplePropertyExpression; import ch.njol.util.coll.CollectionUtils; -import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Entity; import org.bukkit.entity.Item; @@ -22,7 +21,7 @@ "The entity that threw/dropped the dropped item.", "NOTES:", "Getting the item thrower will only return alive entity or a player that has played before. " - + "If the entity was killed, or the player has never played before, will return null." + + "If the entity was killed, or the player has never played before, this will return null." }) @Examples({ "broadcast the item thrower of all dropped items", @@ -41,13 +40,7 @@ public class ExprItemThrower extends SimplePropertyExpression { UUID uuid = item.getThrower(); if (uuid == null) return null; - Entity checkEntity = Bukkit.getEntity(uuid); - if (checkEntity != null) - return checkEntity; - OfflinePlayer checkPlayer = Bukkit.getOfflinePlayer(uuid); - if (checkPlayer.hasPlayedBefore()) - return checkPlayer; - return null; + return UUIDUtils.fromUUID(uuid, true); } @Override From d18096bf69d566e08461c9b8189dd02b264513fb Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Thu, 19 Dec 2024 18:12:48 -0500 Subject: [PATCH 12/16] Monumental Changes --- ...ItemLifetime.java => CondItemDespawn.java} | 20 +++---------------- ...fItemLifetime.java => EffItemDespawn.java} | 4 ++-- .../skript/expressions/ExprEntityOwner.java | 2 -- .../skript/expressions/ExprItemThrower.java | 3 +-- 4 files changed, 6 insertions(+), 23 deletions(-) rename src/main/java/ch/njol/skript/conditions/{CondItemLifetime.java => CondItemDespawn.java} (50%) rename src/main/java/ch/njol/skript/effects/{EffItemLifetime.java => EffItemDespawn.java} (94%) diff --git a/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java b/src/main/java/ch/njol/skript/conditions/CondItemDespawn.java similarity index 50% rename from src/main/java/ch/njol/skript/conditions/CondItemLifetime.java rename to src/main/java/ch/njol/skript/conditions/CondItemDespawn.java index d86da941e63..ba14e59a856 100644 --- a/src/main/java/ch/njol/skript/conditions/CondItemLifetime.java +++ b/src/main/java/ch/njol/skript/conditions/CondItemDespawn.java @@ -5,9 +5,6 @@ import ch.njol.skript.doc.Examples; import ch.njol.skript.doc.Name; import ch.njol.skript.doc.Since; -import ch.njol.skript.lang.Expression; -import ch.njol.skript.lang.SkriptParser.ParseResult; -import ch.njol.util.Kleenean; import org.bukkit.entity.Item; @Name("Will Despawn") @@ -17,26 +14,15 @@ "\tprevent all dropped items from naturally despawning" }) @Since("INSERT VERSION") -public class CondItemLifetime extends PropertyCondition { +public class CondItemDespawn extends PropertyCondition { static { - PropertyCondition.register(CondItemLifetime.class, PropertyType.CAN, "(despawn naturally|naturally despawn)", "itementities"); - } - - private Expression entities; - private boolean canDespawn; - - @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - canDespawn = matchedPattern == 0; - //noinspection unchecked - entities = (Expression) exprs[0]; - return true; + PropertyCondition.register(CondItemDespawn.class, PropertyType.CAN, "(despawn naturally|naturally despawn)", "itementities"); } @Override public boolean check(Item item) { - return item.isUnlimitedLifetime(); + return !item.isUnlimitedLifetime(); } @Override diff --git a/src/main/java/ch/njol/skript/effects/EffItemLifetime.java b/src/main/java/ch/njol/skript/effects/EffItemDespawn.java similarity index 94% rename from src/main/java/ch/njol/skript/effects/EffItemLifetime.java rename to src/main/java/ch/njol/skript/effects/EffItemDespawn.java index 13af4bbf5b0..6fa3eb00306 100644 --- a/src/main/java/ch/njol/skript/effects/EffItemLifetime.java +++ b/src/main/java/ch/njol/skript/effects/EffItemDespawn.java @@ -21,10 +21,10 @@ "allow all dropped items to naturally despawn" }) @Since("INSERT VERSION") -public class EffItemLifetime extends Effect { +public class EffItemDespawn extends Effect { static { - Skript.registerEffect(EffItemLifetime.class, + Skript.registerEffect(EffItemDespawn.class, "(prevent|disallow) %itementities% from (naturally despawning|despawning naturally)", "allow %itementities% to (naturally despawn|despawn naturally)"); } diff --git a/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java b/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java index d85c5df3f4a..2c1ab1f031a 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java +++ b/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java @@ -10,7 +10,6 @@ import ch.njol.skript.expressions.base.SimplePropertyExpression; import ch.njol.skript.lang.ExpressionType; import ch.njol.util.coll.CollectionUtils; -import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Entity; import org.bukkit.entity.Item; @@ -23,7 +22,6 @@ @Name("Entity Owner") @Description({ "The owner of a tameable entity (i.e. horse or wolf) or a dropped item.", - "NOTES:", "Getting the owner of a dropped item will only return a loaded entity or a player that has played before. " + "If the entity was killed, or the player has never played before, will return null.", "Setting the owner of a dropped item means only that entity or player can pick it up. " diff --git a/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java b/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java index babf1ced688..61d13d4a3f0 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java +++ b/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java @@ -19,8 +19,7 @@ @Name("Item Thrower") @Description({ "The entity that threw/dropped the dropped item.", - "NOTES:", - "Getting the item thrower will only return alive entity or a player that has played before. " + "Getting the item thrower will only return a living entity or a player that has played before. " + "If the entity was killed, or the player has never played before, this will return null." }) @Examples({ From 8b1bd18723342984e6543a421579617165ab35a6 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Fri, 20 Dec 2024 08:44:26 -0500 Subject: [PATCH 13/16] Requested Changes --- .../skript/conditions/CondItemDespawn.java | 2 +- .../conditions/base/PropertyCondition.java | 81 +++++++++++-------- .../njol/skript/effects/EffItemDespawn.java | 1 + 3 files changed, 50 insertions(+), 34 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondItemDespawn.java b/src/main/java/ch/njol/skript/conditions/CondItemDespawn.java index ba14e59a856..0e48438ccd8 100644 --- a/src/main/java/ch/njol/skript/conditions/CondItemDespawn.java +++ b/src/main/java/ch/njol/skript/conditions/CondItemDespawn.java @@ -17,7 +17,7 @@ public class CondItemDespawn extends PropertyCondition { static { - PropertyCondition.register(CondItemDespawn.class, PropertyType.CAN, "(despawn naturally|naturally despawn)", "itementities"); + PropertyCondition.register(CondItemDespawn.class, PropertyType.CAN_WILL, "(despawn naturally|naturally despawn)", "itementities"); } @Override 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 9a71bbb79b3..6d79fded967 100644 --- a/src/main/java/ch/njol/skript/conditions/base/PropertyCondition.java +++ b/src/main/java/ch/njol/skript/conditions/base/PropertyCondition.java @@ -18,6 +18,7 @@ */ package ch.njol.skript.conditions.base; +import ch.njol.skript.lang.SyntaxStringBuilder; import org.bukkit.event.Event; import org.jetbrains.annotations.Nullable; @@ -80,7 +81,13 @@ public enum PropertyType { * Indicates that the condition is in a form of something will/be something, * also possibly in the negated form */ - WILL + WILL, + + /** + * Indicates that the condition is in a multiform of something will/be something and something can something + * also possibly in the negated form + */ + CAN_WILL } private Expression expr; @@ -107,28 +114,34 @@ public static void register(Class condition, PropertyType p throw new SkriptAPIException("The type argument must not contain any '%'s"); switch (propertyType) { - case BE: + case BE -> { Skript.registerCondition(condition, ConditionType.PROPERTY, - "%" + type + "% (is|are) " + property, - "%" + type + "% (isn't|is not|aren't|are not) " + property); - break; - case CAN: + "%" + type + "% (is|are) " + property, + "%" + type + "% (isn't|is not|aren't|are not) " + property); + } + case CAN -> { Skript.registerCondition(condition, ConditionType.PROPERTY, - "%" + type + "% can " + property, - "%" + type + "% (can't|cannot|can not) " + property); - break; - case HAVE: + "%" + type + "% can " + property, + "%" + type + "% (can't|cannot|can not) " + property); + } + case HAVE -> { Skript.registerCondition(condition, ConditionType.PROPERTY, - "%" + type + "% (has|have) " + property, - "%" + type + "% (doesn't|does not|do not|don't) have " + property); - break; - case WILL: + "%" + type + "% (has|have) " + property, + "%" + type + "% (doesn't|does not|do not|don't) have " + property); + } + case WILL -> { Skript.registerCondition(condition, - "%" + type + "% will " + property, - "%" + type + "% (will (not|neither)|won't) " + property); - break; - default: + "%" + type + "% will " + property, + "%" + type + "% (will (not|neither)|won't) " + property); + } + case CAN_WILL -> { + Skript.registerCondition(condition, + "%" + type + "% (will|can) " + property, + "%" + type + "% (will (not|neither)|won't|can not|can't) " + property); + } + default -> { assert false; + } } } @@ -168,25 +181,27 @@ public String toString(@Nullable Event event, boolean debug) { return toString(this, getPropertyType(), event, debug, expr, getPropertyName()); } - public static String toString(Condition condition, PropertyType propertyType, @Nullable Event event, - boolean debug, Expression expr, String property) { - switch (propertyType) { - case BE: - return expr.toString(event, debug) + (expr.isSingle() ? " is " : " are ") + (condition.isNegated() ? "not " : "") + property; - case CAN: - return expr.toString(event, debug) + (condition.isNegated() ? " can't " : " can ") + property; - case HAVE: + public static String toString(Condition condition, PropertyType propertyType, @Nullable Event event, boolean debug, Expression expr, String property) { + SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug); + builder.append(expr); + builder.append(switch (propertyType) { + case BE -> (expr.isSingle() ? "is " : "are ") + (condition.isNegated() ? "not" : ""); + case CAN -> (condition.isNegated() ? "can't" : "can"); + case HAVE -> { if (expr.isSingle()) { - return expr.toString(event, debug) + (condition.isNegated() ? " doesn't have " : " has ") + property; + yield (condition.isNegated() ? "doesn't have" : "has"); } else { - return expr.toString(event, debug) + (condition.isNegated() ? " don't have " : " have ") + property; + yield (condition.isNegated() ? "don't have" : "have"); } - case WILL: - return expr.toString(event, debug) + (condition.isNegated() ? " won't " : " will ") + "be " + property; - default: + } + case WILL, CAN_WILL -> (condition.isNegated() ? "won't " : "will ") + "be"; + default -> { assert false; - return null; - } + yield null; + } + }); + builder.append(property); + return builder.toString(); } } diff --git a/src/main/java/ch/njol/skript/effects/EffItemDespawn.java b/src/main/java/ch/njol/skript/effects/EffItemDespawn.java index 6fa3eb00306..16d2ddc3d7f 100644 --- a/src/main/java/ch/njol/skript/effects/EffItemDespawn.java +++ b/src/main/java/ch/njol/skript/effects/EffItemDespawn.java @@ -26,6 +26,7 @@ public class EffItemDespawn extends Effect { static { Skript.registerEffect(EffItemDespawn.class, "(prevent|disallow) %itementities% from (naturally despawning|despawning naturally)", + "allow natural despawning of %itementities%", "allow %itementities% to (naturally despawn|despawn naturally)"); } From 3c97cbf2455509c3b81d78e4451003dbeee30a2c Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Fri, 20 Dec 2024 13:16:07 -0500 Subject: [PATCH 14/16] Changed --- .../njol/skript/conditions/CondItemDespawn.java | 3 ++- .../skript/conditions/base/PropertyCondition.java | 15 ++------------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondItemDespawn.java b/src/main/java/ch/njol/skript/conditions/CondItemDespawn.java index 0e48438ccd8..062bb3584bd 100644 --- a/src/main/java/ch/njol/skript/conditions/CondItemDespawn.java +++ b/src/main/java/ch/njol/skript/conditions/CondItemDespawn.java @@ -17,7 +17,8 @@ public class CondItemDespawn extends PropertyCondition { static { - PropertyCondition.register(CondItemDespawn.class, PropertyType.CAN_WILL, "(despawn naturally|naturally despawn)", "itementities"); + PropertyCondition.register(CondItemDespawn.class, PropertyType.WILL, "(despawn naturally|naturally despawn)", "itementities"); + PropertyCondition.register(CondItemDespawn.class, PropertyType.CAN, "(despawn naturally|naturally despawn)", "itementities"); } @Override 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 6d79fded967..60e1d940a08 100644 --- a/src/main/java/ch/njol/skript/conditions/base/PropertyCondition.java +++ b/src/main/java/ch/njol/skript/conditions/base/PropertyCondition.java @@ -81,13 +81,7 @@ public enum PropertyType { * Indicates that the condition is in a form of something will/be something, * also possibly in the negated form */ - WILL, - - /** - * Indicates that the condition is in a multiform of something will/be something and something can something - * also possibly in the negated form - */ - CAN_WILL + WILL } private Expression expr; @@ -134,11 +128,6 @@ public static void register(Class condition, PropertyType p "%" + type + "% will " + property, "%" + type + "% (will (not|neither)|won't) " + property); } - case CAN_WILL -> { - Skript.registerCondition(condition, - "%" + type + "% (will|can) " + property, - "%" + type + "% (will (not|neither)|won't|can not|can't) " + property); - } default -> { assert false; } @@ -194,7 +183,7 @@ public static String toString(Condition condition, PropertyType propertyType, @N yield (condition.isNegated() ? "don't have" : "have"); } } - case WILL, CAN_WILL -> (condition.isNegated() ? "won't " : "will ") + "be"; + case WILL -> (condition.isNegated() ? "won't " : "will ") + "be"; default -> { assert false; yield null; From 1d24e8cdf5c513b73e74f1c79fe59d389656494e Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Fri, 20 Dec 2024 13:54:48 -0500 Subject: [PATCH 15/16] Partial Changes --- .../conditions/base/PropertyCondition.java | 54 +++++++++---------- .../skript/expressions/ExprEntityOwner.java | 2 +- .../skript/expressions/ExprItemThrower.java | 2 +- 3 files changed, 27 insertions(+), 31 deletions(-) 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 60e1d940a08..a775c06bd7b 100644 --- a/src/main/java/ch/njol/skript/conditions/base/PropertyCondition.java +++ b/src/main/java/ch/njol/skript/conditions/base/PropertyCondition.java @@ -18,7 +18,6 @@ */ package ch.njol.skript.conditions.base; -import ch.njol.skript.lang.SyntaxStringBuilder; import org.bukkit.event.Event; import org.jetbrains.annotations.Nullable; @@ -108,29 +107,28 @@ public static void register(Class condition, PropertyType p throw new SkriptAPIException("The type argument must not contain any '%'s"); switch (propertyType) { - case BE -> { + case BE: Skript.registerCondition(condition, ConditionType.PROPERTY, "%" + type + "% (is|are) " + property, "%" + type + "% (isn't|is not|aren't|are not) " + property); - } - case CAN -> { + break; + case CAN: Skript.registerCondition(condition, ConditionType.PROPERTY, "%" + type + "% can " + property, "%" + type + "% (can't|cannot|can not) " + property); - } - case HAVE -> { + break; + case HAVE: Skript.registerCondition(condition, ConditionType.PROPERTY, "%" + type + "% (has|have) " + property, "%" + type + "% (doesn't|does not|do not|don't) have " + property); - } - case WILL -> { + break; + case WILL: Skript.registerCondition(condition, "%" + type + "% will " + property, "%" + type + "% (will (not|neither)|won't) " + property); - } - default -> { + break; + default: assert false; - } } } @@ -170,27 +168,25 @@ public String toString(@Nullable Event event, boolean debug) { return toString(this, getPropertyType(), event, debug, expr, getPropertyName()); } - public static String toString(Condition condition, PropertyType propertyType, @Nullable Event event, boolean debug, Expression expr, String property) { - SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug); - builder.append(expr); - builder.append(switch (propertyType) { - case BE -> (expr.isSingle() ? "is " : "are ") + (condition.isNegated() ? "not" : ""); - case CAN -> (condition.isNegated() ? "can't" : "can"); - case HAVE -> { + public static String toString(Condition condition, PropertyType propertyType, @Nullable Event event, + boolean debug, Expression expr, String property) { + switch (propertyType) { + case BE: + return expr.toString(event, debug) + (expr.isSingle() ? " is " : " are ") + (condition.isNegated() ? "not " : "") + property; + case CAN: + return expr.toString(event, debug) + (condition.isNegated() ? " can't " : " can ") + property; + case HAVE: if (expr.isSingle()) { - yield (condition.isNegated() ? "doesn't have" : "has"); + return expr.toString(event, debug) + (condition.isNegated() ? " doesn't have " : " has ") + property; } else { - yield (condition.isNegated() ? "don't have" : "have"); + return expr.toString(event, debug) + (condition.isNegated() ? " don't have " : " have ") + property; } - } - case WILL -> (condition.isNegated() ? "won't " : "will ") + "be"; - default -> { + case WILL: + return expr.toString(event, debug) + (condition.isNegated() ? " won't " : " will ") + "be " + property; + default: assert false; - yield null; - } - }); - builder.append(property); - return builder.toString(); + return null; + } } -} +} \ No newline at end of file diff --git a/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java b/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java index 2c1ab1f031a..aaf38f32b0f 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java +++ b/src/main/java/ch/njol/skript/expressions/ExprEntityOwner.java @@ -23,7 +23,7 @@ @Description({ "The owner of a tameable entity (i.e. horse or wolf) or a dropped item.", "Getting the owner of a dropped item will only return a loaded entity or a player that has played before. " - + "If the entity was killed, or the player has never played before, will return null.", + + "If the entity was killed, or the player has never played before, will return null.", "Setting the owner of a dropped item means only that entity or player can pick it up. " + "This is UUID based, so it can also be set to a specific UUID.", "Dropping an item does not automatically make the entity or player the owner." diff --git a/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java b/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java index 61d13d4a3f0..48f627395c1 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java +++ b/src/main/java/ch/njol/skript/expressions/ExprItemThrower.java @@ -20,7 +20,7 @@ @Description({ "The entity that threw/dropped the dropped item.", "Getting the item thrower will only return a living entity or a player that has played before. " - + "If the entity was killed, or the player has never played before, this will return null." + + "If the entity was killed, or the player has never played before, this will return null." }) @Examples({ "broadcast the item thrower of all dropped items", From 295caf34e1aa3cd8c3144e703531259eb0de6eb7 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Fri, 20 Dec 2024 13:56:37 -0500 Subject: [PATCH 16/16] Revert PropertyCondition --- .../conditions/base/PropertyCondition.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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 a775c06bd7b..9a71bbb79b3 100644 --- a/src/main/java/ch/njol/skript/conditions/base/PropertyCondition.java +++ b/src/main/java/ch/njol/skript/conditions/base/PropertyCondition.java @@ -109,23 +109,23 @@ public static void register(Class condition, PropertyType p switch (propertyType) { case BE: Skript.registerCondition(condition, ConditionType.PROPERTY, - "%" + type + "% (is|are) " + property, - "%" + type + "% (isn't|is not|aren't|are not) " + property); + "%" + type + "% (is|are) " + property, + "%" + type + "% (isn't|is not|aren't|are not) " + property); break; case CAN: Skript.registerCondition(condition, ConditionType.PROPERTY, - "%" + type + "% can " + property, - "%" + type + "% (can't|cannot|can not) " + property); + "%" + type + "% can " + property, + "%" + type + "% (can't|cannot|can not) " + property); break; case HAVE: Skript.registerCondition(condition, ConditionType.PROPERTY, - "%" + type + "% (has|have) " + property, - "%" + type + "% (doesn't|does not|do not|don't) have " + property); + "%" + type + "% (has|have) " + property, + "%" + type + "% (doesn't|does not|do not|don't) have " + property); break; case WILL: Skript.registerCondition(condition, - "%" + type + "% will " + property, - "%" + type + "% (will (not|neither)|won't) " + property); + "%" + type + "% will " + property, + "%" + type + "% (will (not|neither)|won't) " + property); break; default: assert false; @@ -189,4 +189,4 @@ public static String toString(Condition condition, PropertyType propertyType, @N } } -} \ No newline at end of file +}