Search in sources :

Example 1 with SneakingTrait

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.");
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) SneakingTrait(com.denizenscript.denizen.npc.traits.SneakingTrait) List(java.util.List) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Aggregations

SneakingTrait (com.denizenscript.denizen.npc.traits.SneakingTrait)1 EntityTag (com.denizenscript.denizen.objects.EntityTag)1 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1 List (java.util.List)1 Player (org.bukkit.entity.Player)1