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..19b10c6cce 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 @@ -1,11 +1,11 @@ package com.denizenscript.denizen.paper.properties; -import com.denizenscript.denizen.npc.traits.SneakingTrait; import com.denizenscript.denizen.objects.EntityTag; import com.denizenscript.denizen.objects.properties.entity.EntityProperty; 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,19 +36,20 @@ 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()) { + return; + } + 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); } } 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/DenizenNPCHelper.java b/plugin/src/main/java/com/denizenscript/denizen/npc/DenizenNPCHelper.java index d3ac796812..a11e49684a 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/npc/DenizenNPCHelper.java +++ b/plugin/src/main/java/com/denizenscript/denizen/npc/DenizenNPCHelper.java @@ -3,15 +3,20 @@ import com.denizenscript.denizen.Denizen; import com.denizenscript.denizen.events.entity.EntityDespawnScriptEvent; import com.denizenscript.denizen.npc.actions.ActionHandler; +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.EntityTag; import com.denizenscript.denizen.objects.NPCTag; -import com.denizenscript.denizencore.utilities.debugging.Debug; import com.denizenscript.denizen.utilities.depends.Depends; import com.denizenscript.denizencore.objects.core.ElementTag; -import net.citizensnpcs.api.event.NPCDespawnEvent; -import net.citizensnpcs.api.event.NPCRemoveEvent; -import net.citizensnpcs.api.event.NPCSpawnEvent; +import com.denizenscript.denizencore.utilities.debugging.Debug; +import net.citizensnpcs.api.CitizensAPI; +import net.citizensnpcs.api.event.*; import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.trait.SitTrait; +import net.citizensnpcs.trait.SleepTrait; +import net.citizensnpcs.trait.SneakTrait; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -19,7 +24,7 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; -import java.util.*; +import java.util.Arrays; public class DenizenNPCHelper implements Listener { @@ -145,4 +150,29 @@ public void onRemove(NPCRemoveEvent event) { NPC npc = event.getNPC(); new NPCTag(npc).action("remove", null); } + + // backwards compat: SittingTrait, SleepingTrait, and SneakingTrait are deprecated versions. + @EventHandler + public void onCitizensEnable(CitizensEnableEvent event) { + for (NPC npc : CitizensAPI.getNPCRegistry()) { + if (npc.hasTrait(SittingTrait.class)) { + if (npc.getOrAddTrait(SittingTrait.class).isSitting()) { + npc.getOrAddTrait(SitTrait.class).setSitting(npc.getStoredLocation()); + } + npc.removeTrait(SittingTrait.class); + } + if (!SleepingTrait.isSupported() && npc.hasTrait(SleepingTrait.class)) { + if (npc.getOrAddTrait(SleepingTrait.class).isSleeping()) { + npc.getOrAddTrait(SleepTrait.class).setSleeping(npc.getStoredLocation()); + } + npc.removeTrait(SleepingTrait.class); + } + if (npc.hasTrait(SneakingTrait.class)) { + if (npc.getOrAddTrait(SneakingTrait.class).isSneaking()) { + npc.getOrAddTrait(SneakTrait.class).setSneaking(true); + } + npc.removeTrait(SneakingTrait.class); + } + } + } } 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..b3e455edaa 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 @@ -2,6 +2,7 @@ import com.denizenscript.denizen.Denizen; import com.denizenscript.denizen.nms.NMSHandler; +import com.denizenscript.denizen.nms.NMSVersion; import com.denizenscript.denizen.utilities.Utilities; import com.denizenscript.denizencore.utilities.debugging.Debug; import net.citizensnpcs.api.persistence.Persist; @@ -9,15 +10,17 @@ 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 { + public static boolean isSupported() { + return NMSHandler.getVersion().isAtMost(NMSVersion.v1_20); + } + @Persist("sleeping") private boolean sleeping = false; @@ -47,14 +50,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 +118,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 +141,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 74e6bc5e56..fd6415a0d9 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,7 @@ 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()); }); // <--[tag] @@ -490,7 +490,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((!SleepingTrait.isSupported() && citizen.hasTrait(SleepTrait.class) && citizen.getOrAddTrait(SleepTrait.class).isSleeping()) + || (SleepingTrait.isSupported() && citizen.hasTrait(SleepingTrait.class) && citizen.getOrAddTrait(SleepingTrait.class).isSleeping())); }); // <--[tag] @@ -1769,15 +1770,8 @@ else if (npcEntity instanceof FallingBlock) { // // --> tagProcessor.registerMechanism("set_sneaking", false, ElementTag.class, (object, mechanism, input) -> { - if (!mechanism.requireBoolean()) { - return; - } - SneakingTrait trait = object.getCitizen().getOrAddTrait(SneakingTrait.class); - if (trait.isSneaking() && !input.asBoolean()) { - trait.stand(); - } - else if (!trait.isSneaking() && input.asBoolean()) { - trait.sneak(); + if (mechanism.requireBoolean()) { + object.getCitizen().getOrAddTrait(SneakTrait.class).setSneaking(input.asBoolean()); } }); 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..efc8cb16be 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 @@ -1,17 +1,15 @@ package com.denizenscript.denizen.scripts.commands.entity; import com.denizenscript.denizen.nms.NMSHandler; -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.trait.SneakTrait; import org.bukkit.entity.Player; import java.util.HashMap; @@ -25,6 +23,7 @@ public SneakCommand() { setSyntax("sneak [|...] ({start}/stop) (fake/stopfake) (for:|...)"); setRequiredArguments(1, 4); isProcedural = false; + autoCompile(); } // <--[command] @@ -38,7 +37,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 +59,46 @@ 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()) { + entity.getDenizenNPC().getCitizen().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 +135,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..123edeb068 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 @@ -4,11 +4,16 @@ 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 +24,7 @@ public SleepCommand() { setSyntax("sleep ()"); setRequiredArguments(0, 1); isProcedural = false; + autoCompile(); } // <--[command] @@ -43,42 +49,30 @@ 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(SitTrait.class)) { + citizen.getOrAddTrait(SitTrait.class).setSitting(null); } - else { - trait.toSleep(); - } - if (!trait.isSleeping()) { - npc.getCitizen().removeTrait(SleepingTrait.class); + if (SleepingTrait.isSupported()) { + 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..0f2f7edaee 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 @@ -3,13 +3,16 @@ 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 +21,7 @@ public StandCommand() { setSyntax("stand"); setRequiredArguments(0, 0); isProcedural = false; + autoCompile(); } // <--[command] @@ -43,42 +47,28 @@ 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 (npc.getEntity() instanceof Sittable sittable) { + sittable.setSitting(false); return; } - if (scriptEntry.dbCallShouldDebug()) { - Debug.report(scriptEntry, getName(), db("npc", Utilities.getEntryNPC(scriptEntry))); + NPC citizen = npc.getCitizen(); + if (citizen.hasTrait(SitTrait.class)) { + citizen.getOrAddTrait(SitTrait.class).setSitting(null); } - Entity entity = npc.getEntity(); - if (entity instanceof Sittable) { - ((Sittable) entity).setSitting(false); + if (SleepingTrait.isSupported() && citizen.hasTrait(SleepingTrait.class)) { + citizen.getOrAddTrait(SleepingTrait.class).wakeUp(); } - 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 (!SleepingTrait.isSupported() && 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..56cc3f7f1d 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,23 @@ package com.denizenscript.denizen.scripts.commands.npc; +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 +29,7 @@ public TraitCommand() { setSyntax("trait (state:true/false/{toggle}) [] (to:|...)"); setRequiredArguments(1, 3); isProcedural = false; + autoCompile(); } // <--[command] @@ -62,7 +68,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 +77,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 || (!SleepingTrait.isSupported() && 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 == SneakingTrait.class) { + trait = SneakTrait.class; } else { - arg.reportUnhandled(); + trait = SleepTrait.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..dcbf6edfb6 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,9 @@ 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/22 + 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."); + // ==================== 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..c97784d57f 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 @@ -2,6 +2,7 @@ import com.denizenscript.denizen.Denizen; 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; @@ -16,7 +17,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 +337,30 @@ 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 { - 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)) { + if (SleepingTrait.isSupported() && npc.hasTrait(SleepingTrait.class)) { npc.getOrAddTrait(SleepingTrait.class).wakeUp(); - npc.removeTrait(SleepingTrait.class); } - SittingTrait trait = npc.getOrAddTrait(SittingTrait.class); + if (!SleepingTrait.isSupported() && npc.hasTrait(SleepTrait.class)) { + npc.getOrAddTrait(SleepTrait.class).setSleeping(null); + } + 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 +383,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 +395,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."); } @@ -403,37 +405,40 @@ else if (block.getType().isSolid()) { min = 1, max = 1, permission = "denizen.npc.stand") @Requirements(selected = true, ownership = true) public void standing(CommandContext args, CommandSender sender, NPC npc) throws CommandException { - if (npc.hasTrait(SittingTrait.class)) { - SittingTrait trait = npc.getOrAddTrait(SittingTrait.class); + if (npc.hasTrait(SitTrait.class)) { + SitTrait trait = npc.getOrAddTrait(SitTrait.class); if (!trait.isSitting()) { - npc.removeTrait(SittingTrait.class); Messaging.sendError(sender, npc.getName() + " is already standing!"); return; } - trait.stand(); - npc.removeTrait(SittingTrait.class); + trait.setSitting(null); Messaging.send(sender, npc.getName() + " is now standing."); } - else if (npc.hasTrait(SneakingTrait.class)) { - SneakingTrait trait = npc.getOrAddTrait(SneakingTrait.class); + else if (npc.hasTrait(SneakTrait.class)) { + SneakTrait trait = npc.getOrAddTrait(SneakTrait.class); if (!trait.isSneaking()) { - npc.removeTrait(SneakingTrait.class); Messaging.sendError(sender, npc.getName() + " is already standing!"); return; } - trait.stand(); - npc.removeTrait(SneakingTrait.class); + trait.setSneaking(false); Messaging.send(sender, npc.getName() + " is now standing."); } - else if (npc.hasTrait(SleepingTrait.class)) { + else if (SleepingTrait.isSupported() && npc.hasTrait(SleepingTrait.class)) { SleepingTrait trait = npc.getOrAddTrait(SleepingTrait.class); if (!trait.isSleeping()) { - npc.removeTrait(SleepingTrait.class); Messaging.sendError(sender, npc.getName() + " is already standing!"); return; } trait.wakeUp(); - npc.removeTrait(SleepingTrait.class); + Messaging.send(sender, npc.getName() + " is now standing."); + } + else if (!SleepingTrait.isSupported() && 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 { @@ -447,19 +452,49 @@ else if (npc.hasTrait(SleepingTrait.class)) { min = 1, max = 3, permission = "denizen.npc.sleep") @Requirements(selected = true, ownership = true, types = { EntityType.VILLAGER, EntityType.PLAYER }) public void sleeping(CommandContext args, CommandSender sender, NPC npc) throws CommandException { - 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(SitTrait.class)) { + npc.getOrAddTrait(SitTrait.class).setSitting(null); } - if (npc.hasTrait(SittingTrait.class)) { - npc.getOrAddTrait(SittingTrait.class).stand(); - npc.removeTrait(SittingTrait.class); + if (SleepingTrait.isSupported() && npc.hasTrait(SleepingTrait.class)) { + npc.getOrAddTrait(SleepingTrait.class).wakeUp(); + Messaging.send(sender, npc.getName() + " was already sleeping, and is now standing!"); + return; } - SleepingTrait trait = npc.getOrAddTrait(SleepingTrait.class); + if (SleepingTrait.isSupported()) { + SleepingTrait trait = npc.getOrAddTrait(SleepingTrait.class); + if (args.hasValueFlag("location")) { + LocationTag location = LocationTag.valueOf(args.getFlag("location"), CoreUtilities.basicContext); + if (location == null) { + Messaging.sendError(sender, "Usage: /npc sleep --location x,y,z,world"); + return; + } + trait.toSleep(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)); + Messaging.send(sender, npc.getName() + " is now sleeping."); + return; + } + } + Messaging.sendError(sender, "NPC " + npc.getName() + " does not have the anchor '" + args.getFlag("anchor") + "'!"); + return; + } + else { + trait.toSleep(npc.getStoredLocation()); + } + Messaging.send(sender, npc.getName() + " is now sleeping."); + return; + } + SleepTrait trait = npc.getOrAddTrait(SleepTrait.class); if (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 +503,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 +518,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 +529,17 @@ 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 (SleepingTrait.isSupported() && npc.hasTrait(SleepingTrait.class)) { + npc.getOrAddTrait(SleepingTrait.class).wakeUp(); + Messaging.send(sender, npc.getName() + " is no longer sleeping."); + } + else if (!SleepingTrait.isSupported() && 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( @@ -597,25 +631,26 @@ public void stopFishing(CommandContext args, CommandSender sender, NPC npc) thro min = 1, max = 1, permission = "denizen.npc.sneak") @Requirements(selected = true, ownership = true) public void sneaking(CommandContext args, CommandSender sender, NPC npc) throws CommandException { - if (npc.hasTrait(SleepingTrait.class)) { + if (SleepingTrait.isSupported() && npc.hasTrait(SleepingTrait.class)) { npc.getOrAddTrait(SleepingTrait.class).wakeUp(); - npc.removeTrait(SleepingTrait.class); } - if (npc.hasTrait(SleepingTrait.class)) { - npc.getOrAddTrait(SleepingTrait.class).wakeUp(); - npc.removeTrait(SleepingTrait.class); + if (!SleepingTrait.isSupported() && npc.hasTrait(SleepTrait.class)) { + npc.getOrAddTrait(SleepTrait.class).setSleeping(null); + } + if (npc.hasTrait(SitTrait.class)) { + npc.getOrAddTrait(SitTrait.class).setSitting(null); } 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."); } }