Search in sources :

Example 21 with PlayerTag

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

the class ToastCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag text = scriptEntry.getElement("text");
    ElementTag frame = scriptEntry.getElement("frame");
    ItemTag icon = scriptEntry.getObjectTag("icon");
    final List<PlayerTag> targets = (List<PlayerTag>) scriptEntry.getObject("targets");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, name, text, frame, icon, db("targets", targets));
    }
    final Advancement advancement = new Advancement(true, new NamespacedKey(Denizen.getInstance(), UUID.randomUUID().toString()), null, icon.getItemStack(), text.asString(), "", null, Advancement.Frame.valueOf(frame.asString().toUpperCase()), true, false, true, 0, 0, 1);
    final AdvancementHelper advancementHelper = NMSHandler.getAdvancementHelper();
    for (PlayerTag target : targets) {
        Player player = target.getPlayerEntity();
        if (player != null) {
            advancementHelper.grant(advancement, player);
            advancementHelper.revoke(advancement, player);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) AdvancementHelper(com.denizenscript.denizen.nms.interfaces.AdvancementHelper) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) NamespacedKey(org.bukkit.NamespacedKey) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) Advancement(com.denizenscript.denizen.nms.util.Advancement)

Example 22 with PlayerTag

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

the class AnimateChestCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    LocationTag location = scriptEntry.getObjectTag("location");
    ElementTag action = scriptEntry.getElement("action");
    ElementTag sound = scriptEntry.getElement("sound");
    List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), location, db("block type", location.getBlock().getType().name()), action, sound, db("players", players));
    }
    PacketHelper packetHelper = NMSHandler.getPacketHelper();
    switch(ChestAction.valueOf(action.asString().toUpperCase())) {
        case OPEN:
            for (PlayerTag player : players) {
                Player ent = player.getPlayerEntity();
                if (sound.asBoolean()) {
                    NMSHandler.getSoundHelper().playSound(ent, location, Sound.BLOCK_CHEST_OPEN, 1, 1, "BLOCKS");
                }
                packetHelper.showBlockAction(ent, location, 1, 1);
            }
            break;
        case CLOSE:
            for (PlayerTag player : players) {
                Player ent = player.getPlayerEntity();
                if (sound.asBoolean()) {
                    NMSHandler.getSoundHelper().playSound(ent, location, Sound.BLOCK_CHEST_CLOSE, 1, 1, "BLOCKS");
                }
                packetHelper.showBlockAction(ent, location, 1, 0);
            }
            break;
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Player(org.bukkit.entity.Player) PacketHelper(com.denizenscript.denizen.nms.interfaces.PacketHelper) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Example 23 with PlayerTag

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

the class TitleCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    String title = scriptEntry.getElement("title").asString();
    String subtitle = scriptEntry.getElement("subtitle").asString();
    DurationTag fade_in = scriptEntry.getObjectTag("fade_in");
    DurationTag stay = scriptEntry.getObjectTag("stay");
    DurationTag fade_out = scriptEntry.getObjectTag("fade_out");
    List<PlayerTag> targets = (List<PlayerTag>) scriptEntry.getObject("targets");
    ElementTag perPlayerObj = scriptEntry.getElement("per_player");
    boolean perPlayer = perPlayerObj != null && perPlayerObj.asBoolean();
    BukkitTagContext context = (BukkitTagContext) scriptEntry.getContext();
    if (!perPlayer) {
        title = TagManager.tag(title, context);
        subtitle = TagManager.tag(subtitle, context);
    }
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("title", title), db("subtitle", subtitle), fade_in, stay, fade_out, db("targets", targets), perPlayerObj);
    }
    for (PlayerTag player : targets) {
        if (player != null) {
            if (!player.isOnline()) {
                Debug.echoDebug(scriptEntry, "Player is offline, can't send title to them. Skipping.");
                continue;
            }
            String personalTitle = title;
            String personalSubtitle = subtitle;
            if (perPlayer) {
                context.player = player;
                personalTitle = TagManager.tag(personalTitle, context);
                personalSubtitle = TagManager.tag(personalSubtitle, context);
            }
            NMSHandler.getPacketHelper().showTitle(player.getPlayerEntity(), personalTitle, personalSubtitle, fade_in.getTicksAsInt(), stay.getTicksAsInt(), fade_out.getTicksAsInt());
        } else {
            Debug.echoError("Sent title to non-existent player!?");
        }
    }
}
Also used : BukkitTagContext(com.denizenscript.denizen.tags.BukkitTagContext) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 24 with PlayerTag

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

the class BossBarCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag id = scriptEntry.getElement("id");
    ElementTag action = scriptEntry.getElement("action");
    ListTag players = scriptEntry.getObjectTag("players");
    ElementTag title = scriptEntry.getElement("title");
    ElementTag progress = scriptEntry.getElement("progress");
    ElementTag color = scriptEntry.getElement("color");
    ElementTag style = scriptEntry.getElement("style");
    ListTag options = scriptEntry.getObjectTag("options");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), id, action, players, title, progress, color, style, options);
    }
    String idString = CoreUtilities.toLowerCase(id.asString());
    switch(Action.valueOf(action.asString().toUpperCase())) {
        case CREATE:
            {
                if (bossBarMap.containsKey(idString)) {
                    Debug.echoError("BossBar '" + idString + "' already exists!");
                    return;
                }
                String barTitle = title != null ? title.asString() : "";
                List<PlayerTag> barPlayers = players.filter(PlayerTag.class, scriptEntry);
                double barProgress = progress != null ? progress.asDouble() : 1D;
                BarColor barColor = color != null ? BarColor.valueOf(color.asString().toUpperCase()) : BarColor.WHITE;
                BarStyle barStyle = style != null ? BarStyle.valueOf(style.asString().toUpperCase()) : BarStyle.SOLID;
                BarFlag[] barFlags = new BarFlag[options != null ? options.size() : 0];
                if (options != null) {
                    for (int i = 0; i < options.size(); i++) {
                        barFlags[i] = (BarFlag.valueOf(options.get(i).toUpperCase()));
                    }
                }
                BossBar bossBar = Bukkit.createBossBar(barTitle, barColor, barStyle, barFlags);
                NMSHandler.getPlayerHelper().setBossBarTitle(bossBar, barTitle);
                bossBar.setProgress(barProgress);
                for (PlayerTag player : barPlayers) {
                    if (!player.isOnline()) {
                        Debug.echoError("Player must be online to show a BossBar to them!");
                        continue;
                    }
                    bossBar.addPlayer(player.getPlayerEntity());
                }
                bossBar.setVisible(true);
                bossBarMap.put(idString, bossBar);
                break;
            }
        case UPDATE:
            {
                if (!bossBarMap.containsKey(idString)) {
                    Debug.echoError("BossBar '" + idString + "' does not exist!");
                    return;
                }
                BossBar bossBar1 = bossBarMap.get(idString);
                if (title != null) {
                    NMSHandler.getPlayerHelper().setBossBarTitle(bossBar1, title.asString());
                }
                if (progress != null) {
                    bossBar1.setProgress(progress.asDouble());
                }
                if (color != null) {
                    bossBar1.setColor(BarColor.valueOf(color.asString().toUpperCase()));
                }
                if (style != null) {
                    bossBar1.setStyle(BarStyle.valueOf(style.asString().toUpperCase()));
                }
                if (options != null) {
                    HashSet<BarFlag> oldFlags = new HashSet<>(Arrays.asList(BarFlag.values()));
                    HashSet<BarFlag> newFlags = new HashSet<>(options.size());
                    for (String flagName : options) {
                        BarFlag flag = BarFlag.valueOf(flagName.toUpperCase());
                        newFlags.add(flag);
                        oldFlags.remove(flag);
                    }
                    for (BarFlag flag : oldFlags) {
                        bossBar1.removeFlag(flag);
                    }
                    for (BarFlag flag : newFlags) {
                        bossBar1.addFlag(flag);
                    }
                }
                if (players != null) {
                    for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
                        bossBar1.addPlayer(player.getPlayerEntity());
                    }
                }
                break;
            }
        case REMOVE:
            {
                if (!bossBarMap.containsKey(idString)) {
                    Debug.echoError("BossBar '" + idString + "' does not exist!");
                    return;
                }
                if (players != null) {
                    BossBar bar = bossBarMap.get(idString);
                    for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
                        bar.removePlayer(player.getPlayerEntity());
                    }
                    break;
                }
                bossBarMap.get(idString).setVisible(false);
                bossBarMap.remove(idString);
                break;
            }
    }
}
Also used : BarStyle(org.bukkit.boss.BarStyle) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) BarColor(org.bukkit.boss.BarColor) BarFlag(org.bukkit.boss.BarFlag) BossBar(org.bukkit.boss.BossBar) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 25 with PlayerTag

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

the class DebugBlockCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    DurationTag duration = scriptEntry.getObjectTag("duration");
    ElementTag clear = scriptEntry.getElement("clear");
    List<LocationTag> locations = (List<LocationTag>) scriptEntry.getObject("locations");
    List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
    ColorTag color = scriptEntry.getObjectTag("color");
    ElementTag alpha = scriptEntry.getElement("alpha");
    ElementTag name = scriptEntry.getElement("name");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), clear == null ? db("locations", locations) : clear, duration, db("players", players), color, alpha, name);
    }
    if (clear != null && clear.asBoolean()) {
        for (PlayerTag player : players) {
            NMSHandler.getPacketHelper().clearDebugTestMarker(player.getPlayerEntity());
        }
    } else {
        int alphaInt = (int) (alpha.asFloat() * 255);
        for (LocationTag location : locations) {
            for (PlayerTag player : players) {
                NMSHandler.getPacketHelper().showDebugTestMarker(player.getPlayerEntity(), location, color, alphaInt, name == null ? "" : name.asString(), (int) duration.getMillis());
            }
        }
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ColorTag(com.denizenscript.denizen.objects.ColorTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

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