Search in sources :

Example 11 with PlayerTag

use of com.denizenscript.denizen.objects.PlayerTag 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)

Example 12 with PlayerTag

use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.

the class ResetCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    // We allow players to be a single player or multiple players
    ObjectTag player = scriptEntry.getObjectTag("players");
    ListTag players;
    if (player instanceof PlayerTag) {
        players = new ListTag(player);
    } else {
        players = scriptEntry.getObjectTag("players");
    }
    Type type = (Type) scriptEntry.getObject("type");
    ScriptTag script = scriptEntry.getObjectTag("script");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), players, db("type", type), script);
    }
    // Deal with GLOBAL_COOLDOWN reset first, since there's no player/players involved
    if (type == Type.GLOBAL_COOLDOWN) {
        CooldownCommand.setCooldown(null, new DurationTag(0), script.getName(), true);
        return;
    }
    // Now deal with the rest
    for (String object : players) {
        PlayerTag resettable = PlayerTag.valueOf(object, scriptEntry.context);
        if (resettable.isValid()) {
            switch(type) {
                case PLAYER_COOLDOWN:
                    CooldownCommand.setCooldown(resettable, new DurationTag(0), script.getName(), false);
                    return;
            }
        }
    }
}
Also used : PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 13 with PlayerTag

use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.

the class FeedCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    PlayerTag player = scriptEntry.getObjectTag("targetplayer");
    NPCTag npc = scriptEntry.getObjectTag("targetnpc");
    ElementTag amount = scriptEntry.getElement("amount");
    ElementTag saturation = scriptEntry.getElement("saturation");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), player, npc, amount, saturation);
    }
    if (npc != null) {
        if (!npc.getCitizen().hasTrait(HungerTrait.class)) {
            Debug.echoError(scriptEntry, "This NPC does not have the HungerTrait enabled! Use /trait hunger");
            return;
        }
        npc.getCitizen().getOrAddTrait(HungerTrait.class).feed(amount.asInt());
    } else {
        int result = Math.max(0, Math.min(20, player.getPlayerEntity().getFoodLevel() + amount.asInt()));
        player.getPlayerEntity().setFoodLevel(result);
        float satResult = Math.max(0, Math.min(20, player.getPlayerEntity().getSaturation() + saturation.asFloat()));
        player.getPlayerEntity().setSaturation(satResult);
        Debug.echoDebug(scriptEntry, "Player food level updated to " + result + " food and " + satResult + " saturation.");
    }
}
Also used : PlayerTag(com.denizenscript.denizen.objects.PlayerTag) NPCTag(com.denizenscript.denizen.objects.NPCTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) HungerTrait(com.denizenscript.denizen.npc.traits.HungerTrait)

Example 14 with PlayerTag

use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.

the class ActionBarCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    List<PlayerTag> targets = (List<PlayerTag>) scriptEntry.getObject("targets");
    String text = scriptEntry.getElement("text").asString();
    ScriptTag formatObj = scriptEntry.getObjectTag("format");
    ElementTag perPlayerObj = scriptEntry.getElement("per_player");
    boolean perPlayer = perPlayerObj != null && perPlayerObj.asBoolean();
    BukkitTagContext context = (BukkitTagContext) scriptEntry.getContext();
    if (!perPlayer) {
        text = TagManager.tag(text, context);
    }
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("message", text), db("targets", targets), formatObj, perPlayerObj);
    }
    FormatScriptContainer format = formatObj == null ? null : (FormatScriptContainer) formatObj.getContainer();
    for (PlayerTag player : targets) {
        if (player != null) {
            if (!player.isOnline()) {
                Debug.echoDebug(scriptEntry, "Player is offline, can't send actionbar to them. Skipping.");
                continue;
            }
            String personalText = text;
            if (perPlayer) {
                context.player = player;
                personalText = TagManager.tag(personalText, context);
            }
            player.getPlayerEntity().spigot().sendMessage(ChatMessageType.ACTION_BAR, FormattedTextHelper.parse(format != null ? format.getFormattedText(personalText, scriptEntry) : personalText, ChatColor.WHITE));
        } else {
            Debug.echoError("Sent actionbar to non-existent player!?");
        }
    }
}
Also used : BukkitTagContext(com.denizenscript.denizen.tags.BukkitTagContext) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) FormatScriptContainer(com.denizenscript.denizen.scripts.containers.core.FormatScriptContainer) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Example 15 with PlayerTag

use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.

the class BlockCrackCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
    ElementTag progress = scriptEntry.getElement("progress");
    LocationTag location = scriptEntry.getObjectTag("location");
    ElementTag stack = scriptEntry.getElement("stack");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("players", players), progress, location, stack);
    }
    Location loc = location.getBlock().getLocation();
    if (!progressTracker.containsKey(loc)) {
        progressTracker.put(loc, new HashMap<>());
        lastBase += 10;
    }
    Map<UUID, IntHolder> uuidInt = progressTracker.get(loc);
    boolean stackVal = stack.asBoolean();
    PacketHelper packetHelper = NMSHandler.getPacketHelper();
    for (PlayerTag player : players) {
        if (!player.isOnline()) {
            Debug.echoError("Players must be online!");
            continue;
        }
        Player playerEnt = player.getPlayerEntity();
        UUID uuid = playerEnt.getUniqueId();
        if (!uuidInt.containsKey(uuid)) {
            IntHolder newIntHolder = new IntHolder();
            newIntHolder.theInt = lastBase;
            newIntHolder.base = lastBase;
            uuidInt.put(uuid, newIntHolder);
        }
        IntHolder intHolder = uuidInt.get(uuid);
        if (!stackVal && intHolder.theInt > intHolder.base) {
            for (int i = intHolder.base; i <= intHolder.theInt; i++) {
                packetHelper.showBlockCrack(playerEnt, i, loc, -1);
            }
            intHolder.theInt = intHolder.base;
        } else if (stackVal && intHolder.theInt - intHolder.base > 10) {
            continue;
        }
        int id = stackVal ? intHolder.theInt++ : intHolder.theInt;
        packetHelper.showBlockCrack(player.getPlayerEntity(), id, loc, progress.asInt() - 1);
    }
}
Also used : Player(org.bukkit.entity.Player) PacketHelper(com.denizenscript.denizen.nms.interfaces.PacketHelper) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) LocationTag(com.denizenscript.denizen.objects.LocationTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) UUID(java.util.UUID) Location(org.bukkit.Location)

Aggregations

PlayerTag (com.denizenscript.denizen.objects.PlayerTag)81 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)41 Player (org.bukkit.entity.Player)26 List (java.util.List)23 NPCTag (com.denizenscript.denizen.objects.NPCTag)22 EntityTag (com.denizenscript.denizen.objects.EntityTag)16 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)15 ListTag (com.denizenscript.denizencore.objects.core.ListTag)15 LocationTag (com.denizenscript.denizen.objects.LocationTag)14 ItemTag (com.denizenscript.denizen.objects.ItemTag)12 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)11 EventHandler (org.bukkit.event.EventHandler)11 BukkitTagContext (com.denizenscript.denizen.tags.BukkitTagContext)8 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)8 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)8 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)7 BukkitScriptEntryData (com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData)7 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)7 FakeEntity (com.denizenscript.denizen.utilities.entity.FakeEntity)6 Argument (com.denizenscript.denizencore.objects.Argument)6