Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion paper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<dependency>
<groupId>net.citizensnpcs</groupId>
<artifactId>citizens-main</artifactId>
<version>2.0.42-SNAPSHOT</version>
<version>2.0.43-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
<exclusions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ElementTag> {

Expand Down Expand Up @@ -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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<dependency>
<groupId>net.citizensnpcs</groupId>
<artifactId>citizens-main</artifactId>
<version>2.0.42-SNAPSHOT</version>
<version>2.0.43-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
<exclusions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()) {
Expand All @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
17 changes: 10 additions & 7 deletions plugin/src/main/java/com/denizenscript/denizen/objects/NPCTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -1821,15 +1823,16 @@ else if (npcEntity instanceof FallingBlock) {
// <NPCTag.is_sneaking>
// -->
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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +25,7 @@ public SneakCommand() {
setSyntax("sneak [<entity>|...] ({start}/stop) (fake/stopfake) (for:<player>|...)");
setRequiredArguments(1, 4);
isProcedural = false;
autoCompile();
}

// <--[command]
Expand All @@ -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.
Expand All @@ -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<EntityTag> entities,
@ArgName("mode") @ArgLinear @ArgDefaultNull SneakMode mode,
@ArgName("fake") @ArgLinear @ArgDefaultNull SneakFake fake,
@ArgName("for") @ArgPrefixed @ArgDefaultNull @ArgSubType(PlayerTag.class) List<PlayerTag> 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<UUID, HashMap<UUID, Boolean>> forceSetSneak = new HashMap<>();
Expand Down Expand Up @@ -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<PlayerTag> forPlayers = (List<PlayerTag>) scriptEntry.getObject("for_players");
List<EntityTag> entities = (List<EntityTag>) 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.");
}
}
}
}
Loading