diff --git a/paper/pom.xml b/paper/pom.xml index ce0e1978cf..5f4e8b84e7 100644 --- a/paper/pom.xml +++ b/paper/pom.xml @@ -31,7 +31,7 @@ net.citizensnpcs citizens-main - 2.0.42-SNAPSHOT + 2.0.43-SNAPSHOT jar provided diff --git a/paper/src/main/java/com/denizenscript/denizen/paper/properties/EntitySneaking.java b/paper/src/main/java/com/denizenscript/denizen/paper/properties/EntitySneaking.java index 1a2e37c0a7..2bb362426e 100644 --- a/paper/src/main/java/com/denizenscript/denizen/paper/properties/EntitySneaking.java +++ b/paper/src/main/java/com/denizenscript/denizen/paper/properties/EntitySneaking.java @@ -6,6 +6,7 @@ import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ElementTag; import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.trait.SneakTrait; public class EntitySneaking extends EntityProperty { @@ -36,18 +37,22 @@ public boolean isDefaultValue(ElementTag value) { @Override public void setPropertyValue(ElementTag value, Mechanism mechanism) { - if (mechanism.requireBoolean()) { - boolean sneaking = value.asBoolean(); - getEntity().setSneaking(sneaking); - if (object.isCitizensNPC()) { - NPC npc = object.getDenizenNPC().getCitizen(); - if (sneaking) { - npc.getOrAddTrait(SneakingTrait.class).sneak(); - } - else if (npc.hasTrait(SneakingTrait.class)) { - npc.getTraitNullable(SneakingTrait.class).stand(); - npc.removeTrait(SneakingTrait.class); - } + if (!mechanism.requireBoolean()) { + return; + } + boolean sneaking = value.asBoolean(); + getEntity().setSneaking(sneaking); + if (object.isCitizensNPC()) { + NPC npc = object.getDenizenNPC().getCitizen(); + if (sneaking) { + npc.getOrAddTrait(SneakTrait.class).setSneaking(true); + } + else if (npc.hasTrait(SneakTrait.class)) { + npc.getOrAddTrait(SneakTrait.class).setSneaking(false); + } + else if (npc.hasTrait(SneakingTrait.class)) { // backsupport + npc.getTraitNullable(SneakingTrait.class).stand(); + npc.removeTrait(SneakingTrait.class); } } } diff --git a/plugin/pom.xml b/plugin/pom.xml index b9ba8f0938..9385f4aa5a 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -44,7 +44,7 @@ net.citizensnpcs citizens-main - 2.0.42-SNAPSHOT + 2.0.43-SNAPSHOT jar provided diff --git a/plugin/src/main/java/com/denizenscript/denizen/npc/traits/SittingTrait.java b/plugin/src/main/java/com/denizenscript/denizen/npc/traits/SittingTrait.java index 556c1f650c..685a144527 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/npc/traits/SittingTrait.java +++ b/plugin/src/main/java/com/denizenscript/denizen/npc/traits/SittingTrait.java @@ -28,6 +28,7 @@ import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.scheduler.BukkitRunnable; +@Deprecated(forRemoval = true) public class SittingTrait extends Trait implements Listener { @Persist("sitting") diff --git a/plugin/src/main/java/com/denizenscript/denizen/npc/traits/SleepingTrait.java b/plugin/src/main/java/com/denizenscript/denizen/npc/traits/SleepingTrait.java index 19eb4a0d9b..269e679274 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/npc/traits/SleepingTrait.java +++ b/plugin/src/main/java/com/denizenscript/denizen/npc/traits/SleepingTrait.java @@ -9,13 +9,11 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.data.type.Bed; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Pose; -import org.bukkit.entity.Villager; +import org.bukkit.entity.*; import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockBreakEvent; +@Deprecated(forRemoval = true) public class SleepingTrait extends Trait { @Persist("sleeping") @@ -47,14 +45,14 @@ public void onSpawn() { } public void internalSleepNow() { - if (npc.getEntity() instanceof Villager) { - if (!((Villager) npc.getEntity()).sleep(bedLocation.clone())) { + if (npc.getEntity() instanceof Villager villager) { + if (!villager.sleep(bedLocation.clone())) { return; } } - else if (npc.getEntity() instanceof Player) { + else if (npc.getEntity() instanceof Player player) { if (bedLocation.getBlock().getBlockData() instanceof Bed) { - ((Player) npc.getEntity()).sleep(bedLocation.clone(), true); + player.sleep(bedLocation.clone(), true); } else { NMSHandler.entityHelper.setPose(npc.getEntity(), Pose.SLEEPING); @@ -115,8 +113,8 @@ public void wakeUp() { return; } sleeping = false; - if (npc.getEntity() instanceof Villager) { - ((Villager) npc.getEntity()).wakeup(); + if (npc.getEntity() instanceof Villager villager) { + villager.wakeup(); } else { if (((Player) npc.getEntity()).isSleeping()) { @@ -138,7 +136,7 @@ public boolean isSleeping() { /** * Gets the bed the NPC is sleeping on - * Returns null if the NPC isnt sleeping + * Returns null if the NPC isn't sleeping * * @return Location */ diff --git a/plugin/src/main/java/com/denizenscript/denizen/npc/traits/SneakingTrait.java b/plugin/src/main/java/com/denizenscript/denizen/npc/traits/SneakingTrait.java index 3621db922d..2b5b083bc9 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/npc/traits/SneakingTrait.java +++ b/plugin/src/main/java/com/denizenscript/denizen/npc/traits/SneakingTrait.java @@ -7,6 +7,7 @@ import org.bukkit.entity.EntityType; import org.bukkit.event.Listener; +@Deprecated(forRemoval = true) public class SneakingTrait extends Trait implements Listener { @Persist("sneaking") diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/NPCTag.java b/plugin/src/main/java/com/denizenscript/denizen/objects/NPCTag.java index a99fa9ec70..e55766ae31 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/NPCTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/NPCTag.java @@ -479,7 +479,8 @@ public static void register() { // --> tagProcessor.registerTag(ElementTag.class, "is_sitting", (attribute, object) -> { NPC citizen = object.getCitizen(); - return new ElementTag(citizen.hasTrait(SittingTrait.class) && citizen.getOrAddTrait(SittingTrait.class).isSitting()); + return new ElementTag((citizen.hasTrait(SitTrait.class) && citizen.getOrAddTrait(SitTrait.class).isSitting()) + || (citizen.hasTrait(SittingTrait.class) && citizen.getOrAddTrait(SittingTrait.class).isSitting())); // backsupport }); // <--[tag] @@ -490,7 +491,8 @@ public static void register() { // --> tagProcessor.registerTag(ElementTag.class, "is_sleeping", (attribute, object) -> { NPC citizen = object.getCitizen(); - return new ElementTag(citizen.hasTrait(SleepingTrait.class) && citizen.getOrAddTrait(SleepingTrait.class).isSleeping()); + return new ElementTag((NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && citizen.hasTrait(SleepTrait.class) && citizen.getOrAddTrait(SleepTrait.class).isSleeping()) + || (citizen.hasTrait(SleepingTrait.class) && citizen.getOrAddTrait(SleepingTrait.class).isSleeping())); //backsupport }); // <--[tag] @@ -1821,15 +1823,16 @@ else if (npcEntity instanceof FallingBlock) { // // --> if (mechanism.matches("set_sneaking") && mechanism.requireBoolean()) { - if (!getCitizen().hasTrait(SneakingTrait.class)) { - getCitizen().addTrait(SneakingTrait.class); + if (getCitizen().hasTrait(SneakingTrait.class)) { // backsupport + getCitizen().getOrAddTrait(SneakingTrait.class).stand(); + getCitizen().removeTrait(SneakingTrait.class); } - SneakingTrait trait = getCitizen().getOrAddTrait(SneakingTrait.class); + SneakTrait trait = getCitizen().getOrAddTrait(SneakTrait.class); if (trait.isSneaking() && !mechanism.getValue().asBoolean()) { - trait.stand(); + trait.setSneaking(false); } else if (!trait.isSneaking() && mechanism.getValue().asBoolean()) { - trait.sneak(); + trait.setSneaking(true); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/entity/SneakCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/entity/SneakCommand.java index d3ee04ad18..e62a7fd119 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/entity/SneakCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/entity/SneakCommand.java @@ -4,14 +4,14 @@ import com.denizenscript.denizen.npc.traits.SneakingTrait; import com.denizenscript.denizen.objects.EntityTag; import com.denizenscript.denizen.objects.PlayerTag; -import com.denizenscript.denizencore.utilities.debugging.Debug; import com.denizenscript.denizen.utilities.packets.NetworkInterceptHelper; -import com.denizenscript.denizencore.exceptions.InvalidArgumentsException; -import com.denizenscript.denizencore.objects.Argument; -import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.objects.core.ListTag; +import com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException; import com.denizenscript.denizencore.scripts.ScriptEntry; import com.denizenscript.denizencore.scripts.commands.AbstractCommand; +import com.denizenscript.denizencore.scripts.commands.generator.*; +import com.denizenscript.denizencore.utilities.debugging.Debug; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.trait.SneakTrait; import org.bukkit.entity.Player; import java.util.HashMap; @@ -25,6 +25,7 @@ public SneakCommand() { setSyntax("sneak [|...] ({start}/stop) (fake/stopfake) (for:|...)"); setRequiredArguments(1, 4); isProcedural = false; + autoCompile(); } // <--[command] @@ -38,7 +39,7 @@ public SneakCommand() { // // @Description // Causes an entity to start or stop sneaking. - // If the entity is NPC, adds the SneakingTrait to apply the sneak setting persistent. + // If the entity is NPC, adds the SneakTrait to apply the sneak setting persistent. // // Can optionally use the 'fake' argument to apply a fake sneak using packets, either globally or for specific players. // Use 'stopfake' to disable faking of sneak. @@ -60,40 +61,51 @@ public SneakCommand() { // // --> - @Override - public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException { - for (Argument arg : scriptEntry) { - if (arg.matches("fake") - && !scriptEntry.hasObject("fake") - && !scriptEntry.hasObject("stopfake")) { - scriptEntry.addObject("fake", new ElementTag(true)); - } - else if (arg.matches("stopfake") - && !scriptEntry.hasObject("fake") - && !scriptEntry.hasObject("stopfake")) { - scriptEntry.addObject("stopfake", new ElementTag(true)); - } - else if ((arg.matches("start") || arg.matches("stop")) - && !scriptEntry.hasObject("mode")) { - scriptEntry.addObject("mode", arg.asElement()); + public enum SneakMode { START, STOP } + + public enum SneakFake { FAKE, STOPFAKE } + + public static void autoExecute(ScriptEntry scriptEntry, + @ArgName("entities") @ArgLinear @ArgDefaultNull @ArgSubType(EntityTag.class) List entities, + @ArgName("mode") @ArgLinear @ArgDefaultNull SneakMode mode, + @ArgName("fake") @ArgLinear @ArgDefaultNull SneakFake fake, + @ArgName("for") @ArgPrefixed @ArgDefaultNull @ArgSubType(PlayerTag.class) List players) { + if (entities == null) { + throw new InvalidArgumentsRuntimeException("Missing entities argument."); + } + boolean shouldSneak = mode == null || mode.equals(SneakMode.START); + boolean shouldFake = fake != null && fake.equals(SneakFake.FAKE); + boolean shouldStopFake = fake != null && fake.equals(SneakFake.STOPFAKE); + for (EntityTag entity : entities) { + if (shouldFake || shouldStopFake) { + if (players == null) { + updateFakeSneak(entity.getUUID(), null, shouldSneak, shouldFake); + for (Player player : NMSHandler.entityHelper.getPlayersThatSee(entity.getBukkitEntity())) { + NMSHandler.packetHelper.sendEntityMetadataFlagsUpdate(player, entity.getBukkitEntity()); + } + } + else { + for (PlayerTag player : players) { + updateFakeSneak(entity.getUUID(), player.getUUID(), shouldSneak, shouldFake); + NMSHandler.packetHelper.sendEntityMetadataFlagsUpdate(player.getPlayerEntity(), entity.getBukkitEntity()); + } + } } - else if (arg.matchesPrefix("for") - && arg.matchesArgumentList(PlayerTag.class) - && !scriptEntry.hasObject("for_players")) { - scriptEntry.addObject("for_players", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry)); + else if (entity.isCitizensNPC()) { + NPC npc = entity.getDenizenNPC().getCitizen(); + if (npc.hasTrait(SneakingTrait.class)) { + npc.getOrAddTrait(SneakingTrait.class).stand(); + npc.removeTrait(SneakingTrait.class); + } + npc.getOrAddTrait(SneakTrait.class).setSneaking(shouldSneak); } - else if (arg.matchesArgumentList(EntityTag.class) - && !scriptEntry.hasObject("entities")) { - scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry)); + else if (entity.isSpawned()) { + NMSHandler.entityHelper.setSneaking(entity.getBukkitEntity(), shouldSneak); } else { - arg.reportUnhandled(); + Debug.echoError("Cannot make unspawned entity sneak."); } } - if (!scriptEntry.hasObject("entities")) { - throw new InvalidArgumentsException("Missing entities argument."); - } - scriptEntry.defaultObject("mode", new ElementTag("start")); } public static HashMap> forceSetSneak = new HashMap<>(); @@ -130,50 +142,4 @@ public static Boolean shouldSneak(UUID entity, UUID player) { } return subMap.get(null); } - - @Override - public void execute(ScriptEntry scriptEntry) { - ElementTag fake = scriptEntry.getElement("fake"); - ElementTag stopfake = scriptEntry.getElement("stopfake"); - ElementTag mode = scriptEntry.getElement("mode"); - List forPlayers = (List) scriptEntry.getObject("for_players"); - List entities = (List) scriptEntry.getObject("entities"); - if (scriptEntry.dbCallShouldDebug()) { - Debug.report(scriptEntry, getName(), mode, db("entities", entities), db("for_players", forPlayers), fake, stopfake); - } - boolean shouldSneak = mode.asString().equalsIgnoreCase("start"); - boolean shouldFake = fake != null && fake.asBoolean(); - boolean shouldStopFake = stopfake != null && stopfake.asBoolean(); - for (EntityTag entity : entities) { - if (shouldFake || shouldStopFake) { - if (forPlayers == null) { - updateFakeSneak(entity.getUUID(), null, shouldSneak, shouldFake); - for (Player player : NMSHandler.entityHelper.getPlayersThatSee(entity.getBukkitEntity())) { - NMSHandler.packetHelper.sendEntityMetadataFlagsUpdate(player, entity.getBukkitEntity()); - } - } - else { - for (PlayerTag player : forPlayers) { - updateFakeSneak(entity.getUUID(), player.getUUID(), shouldSneak, shouldFake); - NMSHandler.packetHelper.sendEntityMetadataFlagsUpdate(player.getPlayerEntity(), entity.getBukkitEntity()); - } - } - } - else if (entity.isCitizensNPC()) { - SneakingTrait trait = entity.getDenizenNPC().getCitizen().getOrAddTrait(SneakingTrait.class); - if (shouldSneak) { - trait.sneak(); - } - else { - trait.stand(); - } - } - else if (entity.isSpawned()) { - NMSHandler.entityHelper.setSneaking(entity.getBukkitEntity(), shouldSneak); - } - else { - Debug.echoError("Cannot make unspawned entity sneak."); - } - } - } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/npc/SitCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/npc/SitCommand.java index 626f427b72..9cc2934f74 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/npc/SitCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/npc/SitCommand.java @@ -1,15 +1,18 @@ package com.denizenscript.denizen.scripts.commands.npc; +import com.denizenscript.denizen.objects.LocationTag; import com.denizenscript.denizen.objects.NPCTag; import com.denizenscript.denizen.utilities.Utilities; -import com.denizenscript.denizencore.utilities.debugging.Debug; -import com.denizenscript.denizen.npc.traits.SittingTrait; -import com.denizenscript.denizen.objects.LocationTag; -import com.denizenscript.denizencore.exceptions.InvalidArgumentsException; -import com.denizenscript.denizencore.objects.Argument; +import com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException; import com.denizenscript.denizencore.scripts.ScriptEntry; import com.denizenscript.denizencore.scripts.commands.AbstractCommand; -import org.bukkit.entity.*; +import com.denizenscript.denizencore.scripts.commands.generator.ArgDefaultNull; +import com.denizenscript.denizencore.scripts.commands.generator.ArgLinear; +import com.denizenscript.denizencore.scripts.commands.generator.ArgName; +import com.denizenscript.denizencore.utilities.debugging.Debug; +import net.citizensnpcs.trait.SitTrait; +import org.bukkit.entity.Player; +import org.bukkit.entity.Sittable; public class SitCommand extends AbstractCommand { @@ -18,6 +21,7 @@ public SitCommand() { setSyntax("sit ()"); setRequiredArguments(0, 1); isProcedural = false; + autoCompile(); } // <--[command] @@ -42,45 +46,20 @@ public SitCommand() { // // --> - @Override - public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException { - for (Argument arg : scriptEntry) { - if (arg.matchesArgumentType(LocationTag.class) - && !scriptEntry.hasObject("location")) { - scriptEntry.addObject("location", arg.asType(LocationTag.class)); - } - else { - arg.reportUnhandled(); - } - } + public static void autoExecute(ScriptEntry scriptEntry, + @ArgName("location") @ArgLinear @ArgDefaultNull LocationTag location) { if (!Utilities.entryHasNPC(scriptEntry)) { - throw new InvalidArgumentsException("This command requires a linked NPC!"); + throw new InvalidArgumentsRuntimeException("This command requires a linked NPC!"); } - } - - @Override - public void execute(ScriptEntry scriptEntry) { - LocationTag location = scriptEntry.getObjectTag("location"); NPCTag npc = Utilities.getEntryNPC(scriptEntry); - if (!(npc.getEntity() instanceof Player || npc.getEntity() instanceof Sittable)) { - Debug.echoError("Entities of type " + npc.getEntityType().getName() + " cannot sit."); - return; - } - if (scriptEntry.dbCallShouldDebug()) { - Debug.report(scriptEntry, getName(), npc, location); + if (npc.getEntity() instanceof Sittable sittable) { + sittable.setSitting(true); } - Entity entity = npc.getEntity(); - if (entity instanceof Sittable) { - ((Sittable) entity).setSitting(true); + else if (npc.getEntity() instanceof Player) { + npc.getCitizen().getOrAddTrait(SitTrait.class).setSitting(location != null ? location : npc.getLocation()); } else { - SittingTrait trait = npc.getCitizen().getOrAddTrait(SittingTrait.class); - if (location != null) { - trait.sit(location); - } - else { - trait.sit(); - } + Debug.echoError("Entities of type " + npc.getEntityType() + " cannot sit."); } } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/npc/SleepCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/npc/SleepCommand.java index 63192107c5..ab8e348412 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/npc/SleepCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/npc/SleepCommand.java @@ -1,14 +1,22 @@ package com.denizenscript.denizen.scripts.commands.npc; +import com.denizenscript.denizen.nms.NMSHandler; +import com.denizenscript.denizen.nms.NMSVersion; +import com.denizenscript.denizen.npc.traits.SittingTrait; import com.denizenscript.denizen.npc.traits.SleepingTrait; import com.denizenscript.denizen.objects.LocationTag; import com.denizenscript.denizen.objects.NPCTag; import com.denizenscript.denizen.utilities.Utilities; -import com.denizenscript.denizencore.utilities.debugging.Debug; -import com.denizenscript.denizencore.exceptions.InvalidArgumentsException; -import com.denizenscript.denizencore.objects.Argument; +import com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException; import com.denizenscript.denizencore.scripts.ScriptEntry; import com.denizenscript.denizencore.scripts.commands.AbstractCommand; +import com.denizenscript.denizencore.scripts.commands.generator.ArgDefaultNull; +import com.denizenscript.denizencore.scripts.commands.generator.ArgLinear; +import com.denizenscript.denizencore.scripts.commands.generator.ArgName; +import com.denizenscript.denizencore.utilities.debugging.Debug; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.trait.SitTrait; +import net.citizensnpcs.trait.SleepTrait; import org.bukkit.entity.EntityType; import org.bukkit.entity.Villager; @@ -19,6 +27,7 @@ public SleepCommand() { setSyntax("sleep ()"); setRequiredArguments(0, 1); isProcedural = false; + autoCompile(); } // <--[command] @@ -43,42 +52,34 @@ public SleepCommand() { // // --> - @Override - public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException { - for (Argument arg : scriptEntry) { - if (arg.matchesArgumentType(LocationTag.class) - && !scriptEntry.hasObject("location")) { - scriptEntry.addObject("location", arg.asType(LocationTag.class)); - } - else { - arg.reportUnhandled(); - } - } + public static void autoExecute(ScriptEntry scriptEntry, + @ArgName("location") @ArgLinear @ArgDefaultNull LocationTag location) { if (!Utilities.entryHasNPC(scriptEntry)) { - throw new InvalidArgumentsException("This command requires a linked NPC!"); + throw new InvalidArgumentsRuntimeException("This command requires a linked NPC!"); } - } - - @Override - public void execute(ScriptEntry scriptEntry) { - LocationTag location = scriptEntry.getObjectTag("location"); NPCTag npc = Utilities.getEntryNPC(scriptEntry); if (npc.getEntityType() != EntityType.PLAYER && !(npc.getEntity() instanceof Villager)) { Debug.echoError("Only Player or villager type NPCs can sit!"); return; } - if (scriptEntry.dbCallShouldDebug()) { - Debug.report(scriptEntry, getName(), npc, location); - } - SleepingTrait trait = npc.getCitizen().getOrAddTrait(SleepingTrait.class); - if (location != null) { - trait.toSleep(location); + NPC citizen = npc.getCitizen(); + if (citizen.hasTrait(SittingTrait.class)) { + citizen.getOrAddTrait(SittingTrait.class).stand(); + citizen.removeTrait(SittingTrait.class); } - else { - trait.toSleep(); + if (citizen.hasTrait(SitTrait.class)) { + citizen.getOrAddTrait(SitTrait.class).setSitting(null); } - if (!trait.isSleeping()) { - npc.getCitizen().removeTrait(SleepingTrait.class); + if (NMSHandler.getVersion().isAtMost(NMSVersion.v1_20)) { // backsupport + SleepingTrait trait = citizen.getOrAddTrait(SleepingTrait.class); + if (location != null) { + trait.toSleep(location); + } + else { + trait.toSleep(); + } + return; } + citizen.getOrAddTrait(SleepTrait.class).setSleeping(location != null ? location : npc.getLocation()); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/npc/StandCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/npc/StandCommand.java index d2da1d8169..ad46b1ce12 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/npc/StandCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/npc/StandCommand.java @@ -1,15 +1,21 @@ package com.denizenscript.denizen.scripts.commands.npc; +import com.denizenscript.denizen.nms.NMSHandler; +import com.denizenscript.denizen.nms.NMSVersion; +import com.denizenscript.denizen.npc.traits.SittingTrait; import com.denizenscript.denizen.npc.traits.SleepingTrait; import com.denizenscript.denizen.objects.NPCTag; import com.denizenscript.denizen.utilities.Utilities; -import com.denizenscript.denizencore.utilities.debugging.Debug; -import com.denizenscript.denizen.npc.traits.SittingTrait; -import com.denizenscript.denizencore.exceptions.InvalidArgumentsException; -import com.denizenscript.denizencore.objects.Argument; +import com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException; import com.denizenscript.denizencore.scripts.ScriptEntry; import com.denizenscript.denizencore.scripts.commands.AbstractCommand; -import org.bukkit.entity.*; +import com.denizenscript.denizencore.utilities.debugging.Debug; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.trait.SitTrait; +import net.citizensnpcs.trait.SleepTrait; +import org.bukkit.entity.Player; +import org.bukkit.entity.Sittable; +import org.bukkit.entity.Villager; public class StandCommand extends AbstractCommand { @@ -18,6 +24,7 @@ public StandCommand() { setSyntax("stand"); setRequiredArguments(0, 0); isProcedural = false; + autoCompile(); } // <--[command] @@ -43,42 +50,35 @@ public StandCommand() { // // --> - @Override - public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException { - //stand should have no additional arguments - for (Argument arg : scriptEntry) { - arg.reportUnhandled(); - } + public static void autoExecute(ScriptEntry scriptEntry) { if (!Utilities.entryHasNPC(scriptEntry)) { - throw new InvalidArgumentsException("This command requires a linked NPC!"); + throw new InvalidArgumentsRuntimeException("This command requires a linked NPC!"); } - } - - @Override - public void execute(ScriptEntry scriptEntry) { NPCTag npc = Utilities.getEntryNPC(scriptEntry); if (!(npc.getEntity() instanceof Player || npc.getEntity() instanceof Sittable || npc.getEntity() instanceof Villager)) { - Debug.echoError("Entities of type " + npc.getEntityType().name() + " cannot sit or sleep."); + Debug.echoError("Entities of type " + npc.getEntityType() + " cannot sit or sleep."); return; } - if (scriptEntry.dbCallShouldDebug()) { - Debug.report(scriptEntry, getName(), db("npc", Utilities.getEntryNPC(scriptEntry))); + if (npc.getEntity() instanceof Sittable sittable) { + sittable.setSitting(false); + return; } - Entity entity = npc.getEntity(); - if (entity instanceof Sittable) { - ((Sittable) entity).setSitting(false); + NPC citizen = npc.getCitizen(); + if (citizen.hasTrait(SittingTrait.class)) { + citizen.getOrAddTrait(SittingTrait.class).stand(); + citizen.removeTrait(SittingTrait.class); } - else { - if (npc.getCitizen().hasTrait(SittingTrait.class)) { - SittingTrait trait = npc.getCitizen().getOrAddTrait(SittingTrait.class); - trait.stand(); - npc.getCitizen().removeTrait(SittingTrait.class); - } - if (npc.getCitizen().hasTrait(SleepingTrait.class)) { - SleepingTrait trait = npc.getCitizen().getOrAddTrait(SleepingTrait.class); - trait.wakeUp(); - npc.getCitizen().removeTrait(SleepingTrait.class); + if (citizen.hasTrait(SitTrait.class)) { + citizen.getOrAddTrait(SitTrait.class).setSitting(null); + } + if (citizen.hasTrait(SleepingTrait.class)) { + citizen.getOrAddTrait(SleepingTrait.class).wakeUp(); + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21)) { + citizen.removeTrait(SleepingTrait.class); } } + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && citizen.hasTrait(SleepTrait.class)) { + citizen.getOrAddTrait(SleepTrait.class).setSleeping(null); + } } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/npc/TraitCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/npc/TraitCommand.java index 0821f299a7..4b1b57c4ec 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/npc/TraitCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/npc/TraitCommand.java @@ -1,18 +1,25 @@ package com.denizenscript.denizen.scripts.commands.npc; +import com.denizenscript.denizen.nms.NMSHandler; +import com.denizenscript.denizen.nms.NMSVersion; +import com.denizenscript.denizen.npc.traits.SittingTrait; +import com.denizenscript.denizen.npc.traits.SleepingTrait; +import com.denizenscript.denizen.npc.traits.SneakingTrait; import com.denizenscript.denizen.objects.NPCTag; +import com.denizenscript.denizen.utilities.BukkitImplDeprecations; import com.denizenscript.denizen.utilities.Utilities; -import com.denizenscript.denizencore.utilities.debugging.Debug; -import com.denizenscript.denizencore.exceptions.InvalidArgumentsException; -import com.denizenscript.denizencore.objects.Argument; -import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.objects.core.ListTag; +import com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException; import com.denizenscript.denizencore.scripts.ScriptEntry; import com.denizenscript.denizencore.scripts.commands.AbstractCommand; +import com.denizenscript.denizencore.scripts.commands.generator.*; +import com.denizenscript.denizencore.utilities.debugging.Debug; import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.trait.TraitInfo; +import net.citizensnpcs.trait.SitTrait; +import net.citizensnpcs.trait.SleepTrait; +import net.citizensnpcs.trait.SneakTrait; import java.util.Collections; import java.util.List; @@ -24,6 +31,7 @@ public TraitCommand() { setSyntax("trait (state:true/false/{toggle}) [] (to:|...)"); setRequiredArguments(1, 3); isProcedural = false; + autoCompile(); } // <--[command] @@ -62,7 +70,7 @@ public TraitCommand() { // // --> - private enum Toggle {TOGGLE, TRUE, FALSE, ON, OFF} + public enum Toggle {TOGGLE, TRUE, FALSE, ON, OFF} @Override public void addCustomTabCompletions(TabCompletionsBuilder tab) { @@ -71,78 +79,61 @@ public void addCustomTabCompletions(TabCompletionsBuilder tab) { } } - @Override - public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException { - for (Argument arg : scriptEntry) { - if (!scriptEntry.hasObject("state") - && arg.matchesPrefix("state", "s") - && arg.matchesEnum(Toggle.class)) { - scriptEntry.addObject("state", new ElementTag(arg.getValue().toUpperCase())); - } - else if (!scriptEntry.hasObject("trait")) { - scriptEntry.addObject("trait", new ElementTag(arg.getValue())); + public static void autoExecute(ScriptEntry scriptEntry, + @ArgName("state") @ArgPrefixed @ArgDefaultNull Toggle toggle, + @ArgName("trait") @ArgLinear @ArgDefaultNull String traitName, + @ArgName("to") @ArgPrefixed @ArgDefaultNull @ArgSubType(NPCTag.class) List npcs) { + if (traitName == null) { + throw new InvalidArgumentsRuntimeException("Missing trait argument!"); + } + Class trait = CitizensAPI.getTraitFactory().getTraitClass(traitName); + if (trait == null) { + throw new InvalidArgumentsRuntimeException("Trait not found: " + traitName); + } + if (trait == SittingTrait.class || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && trait == SleepingTrait.class) || trait == SneakingTrait.class) { + BukkitImplDeprecations.citizensTraits.warn(); + if (trait == SittingTrait.class) { + trait = SitTrait.class; } - else if (!scriptEntry.hasObject("npcs") - && arg.matchesArgumentList(NPCTag.class)) { - scriptEntry.addObject("npcs", arg.asType(ListTag.class).filter(NPCTag.class, scriptEntry)); + else if (trait == SleepingTrait.class) { + trait = SleepTrait.class; } else { - arg.reportUnhandled(); + trait = SneakTrait.class; } } - if (!scriptEntry.hasObject("trait")) { - throw new InvalidArgumentsException("Missing trait argument!"); - } - if (!scriptEntry.hasObject("npcs")) { + if (npcs == null) { if (!Utilities.entryHasNPC(scriptEntry)) { - throw new InvalidArgumentsException("This command requires a linked NPC!"); + throw new InvalidArgumentsRuntimeException("This command requires a linked NPC!"); } - scriptEntry.addObject("npcs", Collections.singletonList(Utilities.getEntryNPC(scriptEntry))); - } - scriptEntry.defaultObject("state", new ElementTag("TOGGLE")); - } - - @Override - public void execute(ScriptEntry scriptEntry) { - ElementTag toggle = scriptEntry.getElement("state"); - ElementTag traitName = scriptEntry.getElement("trait"); - List npcs = (List) scriptEntry.getObject("npcs"); - if (scriptEntry.dbCallShouldDebug()) { - Debug.report(scriptEntry, getName(), traitName, toggle, db("npc", npcs)); - } - Class trait = CitizensAPI.getTraitFactory().getTraitClass(traitName.asString()); - if (trait == null) { - Debug.echoError(scriptEntry, "Trait not found: " + traitName.asString()); - return; + npcs = Collections.singletonList(Utilities.getEntryNPC(scriptEntry)); } for (NPCTag npcTag : npcs) { NPC npc = npcTag.getCitizen(); - switch (Toggle.valueOf(toggle.asString())) { + switch (toggle) { case TRUE: case ON: if (npc.hasTrait(trait)) { - Debug.echoError(scriptEntry, "NPC already has trait '" + traitName.asString() + "'"); - } - else { - npc.addTrait(trait); + Debug.echoError(scriptEntry, "NPC already has trait '" + trait.getName() + "'"); + break; } + npc.addTrait(trait); break; case FALSE: case OFF: if (!npc.hasTrait(trait)) { - Debug.echoError(scriptEntry, "NPC does not have trait '" + traitName.asString() + "'"); + Debug.echoError(scriptEntry, "NPC does not have trait '" + trait.getName() + "'"); } else { npc.removeTrait(trait); } break; - case TOGGLE: + default: if (npc.hasTrait(trait)) { npc.removeTrait(trait); + break; } - else { - npc.addTrait(trait); - } + npc.addTrait(trait); break; } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/utilities/BukkitImplDeprecations.java b/plugin/src/main/java/com/denizenscript/denizen/utilities/BukkitImplDeprecations.java index 19cd68ef9d..9a3b0f0772 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/utilities/BukkitImplDeprecations.java +++ b/plugin/src/main/java/com/denizenscript/denizen/utilities/BukkitImplDeprecations.java @@ -489,6 +489,10 @@ public class BukkitImplDeprecations { // Added 2025/09/22 public static Warning playerSteerEntityEvent = new FutureWarning("playerSteerEntityEvent", "The 'player steers ' event is deprecated in favor of the 'player input' event in MC 1.21+."); + // Added 2026/07/15 + public static Warning citizensTraits = new FutureWarning("citizensTraits", "The Denizen-native 'Sitting', 'Sleeping', and 'Sneaking' traits have been removed in favor of Citizens' 'SitTrait', 'SleepTrait', and 'Sneak' traits respectively."); + public static Warning npcSitCommand = new FutureWarning("npcSitCommand", "The Denizen-native '/npc sit' has been deprecated in favor of Citizens' '/npc sitting'."); + // ==================== PAST deprecations of things that are already gone but still have a warning left behind ==================== // Removed upstream 2025/02/15 diff --git a/plugin/src/main/java/com/denizenscript/denizen/utilities/command/NPCCommandHandler.java b/plugin/src/main/java/com/denizenscript/denizen/utilities/command/NPCCommandHandler.java index fdab9acaf0..b1f2d00e89 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/utilities/command/NPCCommandHandler.java +++ b/plugin/src/main/java/com/denizenscript/denizen/utilities/command/NPCCommandHandler.java @@ -1,10 +1,14 @@ package com.denizenscript.denizen.utilities.command; import com.denizenscript.denizen.Denizen; +import com.denizenscript.denizen.nms.NMSHandler; +import com.denizenscript.denizen.nms.NMSVersion; import com.denizenscript.denizen.npc.traits.*; +import com.denizenscript.denizen.npc.traits.MirrorTrait; import com.denizenscript.denizen.objects.LocationTag; import com.denizenscript.denizen.objects.PlayerTag; import com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer; +import com.denizenscript.denizen.utilities.BukkitImplDeprecations; import com.denizenscript.denizen.utilities.command.manager.messaging.Messaging; import com.denizenscript.denizencore.objects.core.DurationTag; import com.denizenscript.denizencore.scripts.ScriptRegistry; @@ -16,7 +20,7 @@ import net.citizensnpcs.api.command.Requirements; import net.citizensnpcs.api.command.exception.CommandException; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.trait.Anchors; +import net.citizensnpcs.trait.*; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; @@ -336,29 +340,42 @@ else if (args.hasFlag('r')) { min = 1, max = 3, permission = "denizen.npc.sit") @Requirements(selected = true, ownership = true) public void sitting(CommandContext args, CommandSender sender, NPC npc) throws CommandException { + BukkitImplDeprecations.npcSitCommand.warn(); if (npc.hasTrait(SneakingTrait.class)) { npc.getOrAddTrait(SneakingTrait.class).stand(); npc.removeTrait(SneakingTrait.class); } + if (npc.hasTrait(SneakTrait.class)) { + npc.getOrAddTrait(SneakTrait.class).setSneaking(false); + } if (npc.hasTrait(SleepingTrait.class)) { npc.getOrAddTrait(SleepingTrait.class).wakeUp(); - npc.removeTrait(SleepingTrait.class); + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21)) { + npc.removeTrait(SleepingTrait.class); + } + } + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && npc.hasTrait(SleepTrait.class)) { + npc.getOrAddTrait(SleepTrait.class).setSleeping(null); + } + if (npc.hasTrait(SittingTrait.class)) { + npc.getOrAddTrait(SittingTrait.class).stand(); + npc.removeTrait(SittingTrait.class); } - SittingTrait trait = npc.getOrAddTrait(SittingTrait.class); + SitTrait trait = npc.getOrAddTrait(SitTrait.class); if (args.hasValueFlag("location")) { LocationTag location = LocationTag.valueOf(args.getFlag("location"), CoreUtilities.basicContext); if (location == null) { Messaging.sendError(sender, "Usage: /npc sit --location x,y,z,world"); return; } - trait.sit(location); + trait.setSitting(location); return; } else if (args.hasValueFlag("anchor")) { if (npc.hasTrait(Anchors.class)) { Anchors anchors = npc.getOrAddTrait(Anchors.class); if (anchors.getAnchor(args.getFlag("anchor")) != null) { - trait.sit(anchors.getAnchor(args.getFlag("anchor")).getLocation()); + trait.setSitting(anchors.getAnchor(args.getFlag("anchor")).getLocation()); Messaging.send(sender, npc.getName() + " is now sitting."); return; } @@ -381,7 +398,7 @@ else if (args.hasValueFlag("anchor")) { } Block block = targetLocation.getBlock(); BlockData data = block.getBlockData(); - if (data instanceof Stairs || data instanceof Bed || (data instanceof Slab && ((Slab) data).getType() == Slab.Type.BOTTOM)) { + if (data instanceof Stairs || data instanceof Bed || (data instanceof Slab slab && slab.getType() == Slab.Type.BOTTOM)) { targetLocation.setY(targetLocation.getBlockY() + 0.3); } else if (data instanceof Campfire) { @@ -393,7 +410,7 @@ else if (block.getType().name().endsWith("CARPET")) { else if (block.getType().isSolid()) { targetLocation.setY(targetLocation.getBlockY() + 0.8); } - trait.sit(targetLocation); + trait.setSitting(targetLocation); Messaging.send(sender, npc.getName() + " is now sitting."); } @@ -414,6 +431,15 @@ public void standing(CommandContext args, CommandSender sender, NPC npc) throws npc.removeTrait(SittingTrait.class); Messaging.send(sender, npc.getName() + " is now standing."); } + else if (npc.hasTrait(SitTrait.class)) { + SitTrait trait = npc.getOrAddTrait(SitTrait.class); + if (!trait.isSitting()) { + Messaging.sendError(sender, npc.getName() + " is already standing!"); + return; + } + trait.setSitting(null); + Messaging.send(sender, npc.getName() + " is now standing."); + } else if (npc.hasTrait(SneakingTrait.class)) { SneakingTrait trait = npc.getOrAddTrait(SneakingTrait.class); if (!trait.isSneaking()) { @@ -425,15 +451,37 @@ else if (npc.hasTrait(SneakingTrait.class)) { npc.removeTrait(SneakingTrait.class); Messaging.send(sender, npc.getName() + " is now standing."); } + else if (npc.hasTrait(SneakTrait.class)) { + SneakTrait trait = npc.getOrAddTrait(SneakTrait.class); + if (!trait.isSneaking()) { + Messaging.sendError(sender, npc.getName() + " is already standing!"); + return; + } + trait.setSneaking(false); + Messaging.send(sender, npc.getName() + " is now standing."); + } else if (npc.hasTrait(SleepingTrait.class)) { SleepingTrait trait = npc.getOrAddTrait(SleepingTrait.class); if (!trait.isSleeping()) { - npc.removeTrait(SleepingTrait.class); + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21)) { + npc.removeTrait(SleepingTrait.class); + } Messaging.sendError(sender, npc.getName() + " is already standing!"); return; } trait.wakeUp(); - npc.removeTrait(SleepingTrait.class); + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21)) { + npc.removeTrait(SleepingTrait.class); + } + Messaging.send(sender, npc.getName() + " is now standing."); + } + else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && npc.hasTrait(SleepTrait.class)) { + SleepTrait trait = npc.getOrAddTrait(SleepTrait.class); + if (!trait.isSleeping()) { + Messaging.sendError(sender, npc.getName() + " is already standing!"); + return; + } + trait.setSleeping(null); Messaging.send(sender, npc.getName() + " is now standing."); } else { @@ -451,15 +499,28 @@ public void sleeping(CommandContext args, CommandSender sender, NPC npc) throws npc.getOrAddTrait(SneakingTrait.class).stand(); npc.removeTrait(SneakingTrait.class); } + if (npc.hasTrait(SneakTrait.class)) { + npc.getOrAddTrait(SneakTrait.class).setSneaking(false); + } if (npc.hasTrait(SittingTrait.class)) { npc.getOrAddTrait(SittingTrait.class).stand(); npc.removeTrait(SittingTrait.class); } - SleepingTrait trait = npc.getOrAddTrait(SleepingTrait.class); - if (trait.isSleeping()) { + if (npc.hasTrait(SitTrait.class)) { + npc.getOrAddTrait(SitTrait.class).setSitting(null); + } + if (npc.hasTrait(SleepingTrait.class)) { + npc.getOrAddTrait(SleepingTrait.class).wakeUp(); + Messaging.send(sender, npc.getName() + " was already sleeping, and is now standing!"); + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21)) { + npc.removeTrait(SleepingTrait.class); + } + return; + } + SleepTrait trait = npc.getOrAddTrait(SleepTrait.class); + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && trait.isSleeping()) { + trait.setSleeping(null); Messaging.send(sender, npc.getName() + " was already sleeping, and is now standing!"); - trait.wakeUp(); - npc.removeTrait(SleepingTrait.class); return; } if (args.hasValueFlag("location")) { @@ -468,13 +529,13 @@ public void sleeping(CommandContext args, CommandSender sender, NPC npc) throws Messaging.sendError(sender, "Usage: /npc sleep --location x,y,z,world"); return; } - trait.toSleep(location); + trait.setSleeping(location); } else if (args.hasValueFlag("anchor")) { if (npc.hasTrait(Anchors.class)) { Anchors anchors = npc.getOrAddTrait(Anchors.class); if (anchors.getAnchor(args.getFlag("anchor")) != null) { - trait.toSleep(anchors.getAnchor(args.getFlag("anchor")).getLocation().clone().add(0.5, 0, 0.5)); + trait.setSleeping(anchors.getAnchor(args.getFlag("anchor")).getLocation().clone().add(0.5, 0, 0.5)); Messaging.send(sender, npc.getName() + " is now sleeping."); return; } @@ -483,10 +544,7 @@ else if (args.hasValueFlag("anchor")) { return; } else { - trait.toSleep(); - } - if (!trait.isSleeping()) { - npc.removeTrait(SleepingTrait.class); + trait.setSleeping(npc.getStoredLocation()); } Messaging.send(sender, npc.getName() + " is now sleeping."); } @@ -497,15 +555,20 @@ else if (args.hasValueFlag("anchor")) { min = 1, max = 1, permission = "denizen.npc.sleep") @Requirements(selected = true, ownership = true) public void wakingup(CommandContext args, CommandSender sender, NPC npc) throws CommandException { - SleepingTrait trait = npc.getOrAddTrait(SleepingTrait.class); - if (!trait.isSleeping()) { - npc.removeTrait(SleepingTrait.class); + if (npc.hasTrait(SleepingTrait.class)) { + npc.getOrAddTrait(SleepingTrait.class).wakeUp(); + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21)) { + npc.removeTrait(SleepingTrait.class); + } + Messaging.send(sender, npc.getName() + " is no longer sleeping."); + } + else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && npc.hasTrait(SleepTrait.class) && npc.getOrAddTrait(SleepTrait.class).isSleeping()) { + npc.getOrAddTrait(SleepTrait.class).setSleeping(null); + Messaging.send(sender, npc.getName() + " is no longer sleeping."); + } + else { Messaging.sendError(sender, npc.getName() + " is already awake!"); - return; } - trait.wakeUp(); - npc.removeTrait(SleepingTrait.class); - Messaging.send(sender, npc.getName() + " is no longer sleeping."); } @Command( @@ -599,23 +662,35 @@ public void stopFishing(CommandContext args, CommandSender sender, NPC npc) thro public void sneaking(CommandContext args, CommandSender sender, NPC npc) throws CommandException { if (npc.hasTrait(SleepingTrait.class)) { npc.getOrAddTrait(SleepingTrait.class).wakeUp(); - npc.removeTrait(SleepingTrait.class); + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21)) { + npc.removeTrait(SleepingTrait.class); + } } - if (npc.hasTrait(SleepingTrait.class)) { - npc.getOrAddTrait(SleepingTrait.class).wakeUp(); - npc.removeTrait(SleepingTrait.class); + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && npc.hasTrait(SleepTrait.class)) { + npc.getOrAddTrait(SleepTrait.class).setSleeping(null); + } + if (npc.hasTrait(SittingTrait.class)) { + npc.getOrAddTrait(SittingTrait.class).stand(); + npc.removeTrait(SittingTrait.class); + } + if (npc.hasTrait(SitTrait.class)) { + npc.getOrAddTrait(SitTrait.class).setSitting(null); + } + if (npc.hasTrait(SneakingTrait.class)) { + npc.getOrAddTrait(SneakingTrait.class).stand(); + npc.removeTrait(SneakingTrait.class); } if (npc.getEntity().getType() != EntityType.PLAYER) { Messaging.sendError(sender, npc.getName() + " needs to be a Player type NPC to sneak!"); return; } - SneakingTrait trait = npc.getOrAddTrait(SneakingTrait.class); + SneakTrait trait = npc.getOrAddTrait(SneakTrait.class); if (trait.isSneaking()) { - trait.stand(); + trait.setSneaking(false); Messaging.send(sender, npc.getName() + " was already sneaking, and is now standing."); } else { - trait.sneak(); + trait.setSneaking(true); Messaging.send(sender, npc.getName() + " is now sneaking."); } }