use of com.denizenscript.denizen.npc.traits.SneakingTrait in project Denizen-For-Bukkit by DenizenScript.
the class SneakCommand method execute.
@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.getEntityHelper().getPlayersThatSee(entity.getBukkitEntity())) {
NMSHandler.getPacketHelper().sendEntityMetadataFlagsUpdate(player, entity.getBukkitEntity());
}
} else {
for (PlayerTag player : forPlayers) {
updateFakeSneak(entity.getUUID(), player.getUUID(), shouldSneak, shouldFake);
NMSHandler.getPacketHelper().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.getEntityHelper().setSneaking(entity.getBukkitEntity(), shouldSneak);
} else {
Debug.echoError("Cannot make unspawned entity sneak.");
}
}
}
Aggregations