Search in sources :

Example 1 with Sidebar

use of com.denizenscript.denizen.nms.abstracts.Sidebar in project Denizen-For-Bukkit by DenizenScript.

the class PlayerTag method registerTags.

public static void registerTags() {
    AbstractFlagTracker.registerFlagHandlers(tagProcessor);
    // ///////////////////
    // OFFLINE ATTRIBUTES
    // ///////////////
    // Defined in EntityTag
    tagProcessor.registerTag(ElementTag.class, "is_player", (attribute, object) -> {
        return new ElementTag(true);
    });
    // ///////////////////
    // DENIZEN ATTRIBUTES
    // ///////////////
    // <--[tag]
    // @attribute <PlayerTag.chat_history_list>
    // @returns ListTag
    // @description
    // Returns a list of the last 10 things the player has said, less if the player hasn't said all that much.
    // Works with offline players.
    // -->
    tagProcessor.registerTag(ListTag.class, "chat_history_list", (attribute, object) -> {
        return new ListTag(PlayerTagBase.playerChatHistory.get(object.getUUID()), true);
    });
    // <--[tag]
    // @attribute <PlayerTag.chat_history[(<#>)]>
    // @returns ElementTag
    // @description
    // Returns the last thing the player said.
    // If a number is specified, returns an earlier thing the player said.
    // Works with offline players.
    // -->
    tagProcessor.registerTag(ElementTag.class, "chat_history", (attribute, object) -> {
        int x = 1;
        if (attribute.hasParam() && ArgumentHelper.matchesInteger(attribute.getParam())) {
            x = attribute.getIntParam();
        }
        // No playerchathistory? Return null.
        if (!PlayerTagBase.playerChatHistory.containsKey(object.getUUID())) {
            return null;
        }
        List<String> messages = PlayerTagBase.playerChatHistory.get(object.getUUID());
        if (messages.size() < x || x < 1) {
            return null;
        }
        return new ElementTag(messages.get(x - 1), true);
    });
    // ///////////////////
    // ECONOMY ATTRIBUTES
    // ///////////////
    // <--[tag]
    // @attribute <PlayerTag.formatted_money>
    // @returns ElementTag
    // @plugin Vault
    // @description
    // Returns the formatted form of the player's money balance in the registered Economy system.
    // -->
    tagProcessor.registerTag(ElementTag.class, "formatted_money", (attribute, object) -> {
        if (Depends.economy == null) {
            if (!attribute.hasAlternative()) {
                Debug.echoError("No economy loaded! Have you installed Vault and a compatible economy plugin?");
            }
            return null;
        }
        return new ElementTag(Depends.economy.format(Depends.economy.getBalance(object.getOfflinePlayer())), true);
    });
    // <--[tag]
    // @attribute <PlayerTag.money>
    // @returns ElementTag(Decimal)
    // @plugin Vault
    // @description
    // Returns the amount of money the player has with the registered Economy system.
    // May work offline depending on economy provider.
    // -->
    tagProcessor.registerTag(ElementTag.class, "money", (attribute, object) -> {
        if (Depends.economy == null) {
            if (!attribute.hasAlternative()) {
                Debug.echoError("No economy loaded! Have you installed Vault and a compatible economy plugin?");
            }
            return null;
        }
        if (attribute.startsWith("formatted", 2)) {
            attribute.fulfill(1);
            Deprecations.playerMoneyFormatTag.warn(attribute.context);
            return new ElementTag(Depends.economy.format(Depends.economy.getBalance(object.getOfflinePlayer())));
        }
        if (attribute.startsWith("currency_singular", 2)) {
            attribute.fulfill(1);
            Deprecations.oldEconomyTags.warn(attribute.context);
            return new ElementTag(Depends.economy.currencyNameSingular());
        }
        if (attribute.startsWith("currency", 2)) {
            attribute.fulfill(1);
            Deprecations.oldEconomyTags.warn(attribute.context);
            return new ElementTag(Depends.economy.currencyNamePlural());
        }
        return new ElementTag(Depends.economy.getBalance(object.getOfflinePlayer()));
    });
    // ///////////////////
    // ENTITY LIST ATTRIBUTES
    // ///////////////
    // <--[tag]
    // @attribute <PlayerTag.target[(<matcher>)]>
    // @returns EntityTag
    // @description
    // Returns the entity that the player is looking at, within a maximum range of 50 blocks,
    // or null if the player is not looking at an entity.
    // Optionally, specify an entity type matcher to only count matches as possible targets.
    // -->
    registerOnlineOnlyTag(ObjectTag.class, "target", (attribute, object) -> {
        double range = 50;
        String matcher = attribute.hasParam() ? attribute.getParam() : null;
        // -->
        if (attribute.startsWith("within", 2) && attribute.hasContext(2)) {
            range = attribute.getDoubleContext(2);
            attribute.fulfill(1);
        }
        Location eyeLoc = object.getEyeLocation();
        RayTraceResult result = eyeLoc.getWorld().rayTrace(eyeLoc, eyeLoc.getDirection(), range, FluidCollisionMode.NEVER, true, 0.01, (e) -> {
            if (e.getUniqueId().equals(object.getUUID())) {
                return false;
            }
            if (matcher != null) {
                return BukkitScriptEvent.tryEntity(new EntityTag(e), matcher);
            }
            return true;
        });
        if (result == null || result.getHitEntity() == null) {
            return null;
        }
        return new EntityTag(result.getHitEntity()).getDenizenObject();
    });
    // ///////////////////
    // LOCATION ATTRIBUTES
    // ///////////////
    // <--[tag]
    // @attribute <PlayerTag.bed_spawn>
    // @returns LocationTag
    // @mechanism PlayerTag.bed_spawn_location
    // @description
    // Returns the location of the player's bed spawn location, null if
    // it doesn't exist.
    // Works with offline players.
    // -->
    tagProcessor.registerTag(LocationTag.class, "bed_spawn", (attribute, object) -> {
        try {
            NMSHandler.getChunkHelper().changeChunkServerThread(object.getWorld());
            if (object.getOfflinePlayer().getBedSpawnLocation() == null) {
                return null;
            }
            return new LocationTag(object.getOfflinePlayer().getBedSpawnLocation());
        } finally {
            NMSHandler.getChunkHelper().restoreServerThread(object.getWorld());
        }
    });
    tagProcessor.registerTag(ObjectTag.class, "location", (attribute, object) -> {
        if (object.isOnline() && !object.getPlayerEntity().isDead()) {
            return new EntityTag(object.getPlayerEntity()).doLocationTag(attribute);
        }
        return object.getLocation();
    });
    tagProcessor.registerTag(WorldTag.class, "world", (attribute, object) -> {
        return new WorldTag(object.getWorld());
    });
    // ///////////////////
    // STATE ATTRIBUTES
    // ///////////////
    // <--[tag]
    // @attribute <PlayerTag.item_cooldown[<material>]>
    // @returns DurationTag
    // @description
    // Returns the cooldown duration remaining on player's material.
    // -->
    registerOnlineOnlyTag(DurationTag.class, "item_cooldown", (attribute, object) -> {
        MaterialTag mat = new ElementTag(attribute.getParam()).asType(MaterialTag.class, attribute.context);
        if (mat != null) {
            return new DurationTag((long) object.getPlayerEntity().getCooldown(mat.getMaterial()));
        }
        return null;
    });
    // <--[tag]
    // @attribute <PlayerTag.first_played_time>
    // @returns TimeTag
    // @description
    // Returns the time of when the player first logged on to this server.
    // Works with offline players.
    // -->
    tagProcessor.registerTag(TimeTag.class, "first_played_time", (attribute, object) -> {
        return new TimeTag(object.getOfflinePlayer().getFirstPlayed());
    });
    tagProcessor.registerTag(DurationTag.class, "first_played", (attribute, object) -> {
        Deprecations.playerTimePlayedTags.warn(attribute.context);
        return new DurationTag(object.getOfflinePlayer().getFirstPlayed() / 50);
    });
    // <--[tag]
    // @attribute <PlayerTag.has_played_before>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the player has played before.
    // Works with offline players.
    // Note: This will just always return true.
    // -->
    tagProcessor.registerTag(ElementTag.class, "has_played_before", (attribute, object) -> {
        return new ElementTag(true);
    });
    // <--[tag]
    // @attribute <PlayerTag.exhaustion>
    // @returns ElementTag(Decimal)
    // @mechanism PlayerTag.exhaustion
    // @description
    // Returns the player's exhaustion value. Exhaustion is increased in vanilla when a player sprints or jumps, and is used to reduce food saturation over time.
    // This can reach a maximum value of 40, and decreases by 4 every tick.
    // Works with offline players.
    // -->
    tagProcessor.registerTag(ElementTag.class, "exhaustion", (attribute, object) -> {
        if (object.isOnline()) {
            return new ElementTag(object.getPlayerEntity().getExhaustion());
        } else {
            return new ElementTag(object.getNBTEditor().getExhaustion());
        }
    });
    // Handle EntityTag oxygen tags here to allow getting them when the player is offline
    tagProcessor.registerTag(DurationTag.class, "max_oxygen", (attribute, object) -> {
        return new DurationTag((long) object.getMaximumAir());
    });
    tagProcessor.registerTag(DurationTag.class, "oxygen", (attribute, object) -> {
        if (attribute.startsWith("max", 2)) {
            Deprecations.entityMaxOxygenTag.warn(attribute.context);
            attribute.fulfill(1);
            return new DurationTag((long) object.getMaximumAir());
        }
        return new DurationTag((long) object.getRemainingAir());
    });
    // <--[tag]
    // @attribute <PlayerTag.health_is_scaled>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the player's health bar is currently being scaled.
    // -->
    tagProcessor.registerTag(ElementTag.class, "health_is_scaled", (attribute, object) -> {
        return new ElementTag(object.getPlayerEntity().isHealthScaled());
    });
    // <--[tag]
    // @attribute <PlayerTag.health_scale>
    // @returns ElementTag(Decimal)
    // @mechanism PlayerTag.health_scale
    // @description
    // Returns the current scale for the player's health bar
    // -->
    tagProcessor.registerTag(ElementTag.class, "health_scale", (attribute, object) -> {
        return new ElementTag(object.getPlayerEntity().getHealthScale());
    });
    // Handle EntityTag health tags here to allow getting them when the player is offline
    tagProcessor.registerTag(ElementTag.class, "formatted_health", (attribute, object) -> {
        Double maxHealth = attribute.hasParam() ? attribute.getDoubleParam() : null;
        return EntityHealth.getHealthFormatted(new EntityTag(object.getPlayerEntity()), maxHealth);
    });
    tagProcessor.registerTag(ElementTag.class, "health_percentage", (attribute, object) -> {
        double maxHealth = object.getPlayerEntity().getMaxHealth();
        if (attribute.hasParam()) {
            maxHealth = attribute.getIntParam();
        }
        return new ElementTag((object.getPlayerEntity().getHealth() / maxHealth) * 100);
    });
    tagProcessor.registerTag(ElementTag.class, "health_max", (attribute, object) -> {
        return new ElementTag(object.getMaxHealth());
    });
    tagProcessor.registerTag(ElementTag.class, "health", (attribute, object) -> {
        if (attribute.startsWith("is_scaled", 2)) {
            attribute.fulfill(1);
            Deprecations.entityHealthTags.warn(attribute.context);
            return new ElementTag(object.getPlayerEntity().isHealthScaled());
        }
        if (attribute.startsWith("scale", 2)) {
            attribute.fulfill(1);
            Deprecations.entityHealthTags.warn(attribute.context);
            return new ElementTag(object.getPlayerEntity().getHealthScale());
        }
        if (attribute.startsWith("formatted", 2)) {
            Deprecations.entityHealthTags.warn(attribute.context);
            Double maxHealth = attribute.hasContext(2) ? attribute.getDoubleContext(2) : null;
            attribute.fulfill(1);
            return EntityHealth.getHealthFormatted(new EntityTag(object.getPlayerEntity()), maxHealth);
        }
        if (attribute.startsWith("percentage", 2)) {
            Deprecations.entityHealthTags.warn(attribute.context);
            attribute.fulfill(1);
            double maxHealth = object.getPlayerEntity().getMaxHealth();
            if (attribute.hasParam()) {
                maxHealth = attribute.getIntParam();
            }
            return new ElementTag((object.getPlayerEntity().getHealth() / maxHealth) * 100);
        }
        if (attribute.startsWith("max", 2)) {
            Deprecations.entityHealthTags.warn(attribute.context);
            attribute.fulfill(1);
            return new ElementTag(object.getMaxHealth());
        }
        return new ElementTag(object.getHealth());
    });
    // <--[tag]
    // @attribute <PlayerTag.is_banned>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the player is banned.
    // -->
    tagProcessor.registerTag(ElementTag.class, "is_banned", (attribute, object) -> {
        BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(object.getName());
        if (ban == null) {
            return new ElementTag(false);
        } else if (ban.getExpiration() == null) {
            return new ElementTag(true);
        }
        return new ElementTag(ban.getExpiration().after(new Date()));
    });
    // <--[tag]
    // @attribute <PlayerTag.is_online>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the player is currently online.
    // Works with offline players (returns false in that case).
    // -->
    tagProcessor.registerTag(ElementTag.class, "is_online", (attribute, object) -> {
        return new ElementTag(object.isOnline());
    });
    // <--[tag]
    // @attribute <PlayerTag.is_op>
    // @returns ElementTag(Boolean)
    // @mechanism PlayerTag.is_op
    // @description
    // Returns whether the player is a full server operator.
    // Works with offline players.
    // -->
    tagProcessor.registerTag(ElementTag.class, "is_op", (attribute, object) -> {
        return new ElementTag(object.getOfflinePlayer().isOp());
    });
    // <--[tag]
    // @attribute <PlayerTag.is_whitelisted>
    // @returns ElementTag(Boolean)
    // @mechanism PlayerTag.is_whitelisted
    // @description
    // Returns whether the player is whitelisted.
    // Works with offline players.
    // -->
    tagProcessor.registerTag(ElementTag.class, "is_whitelisted", (attribute, object) -> {
        return new ElementTag(object.getOfflinePlayer().isWhitelisted());
    });
    // <--[tag]
    // @attribute <PlayerTag.last_played_time>
    // @returns TimeTag
    // @description
    // Returns the time of when the player was last seen.
    // Works with offline players.
    // Not very useful for online players.
    // -->
    tagProcessor.registerTag(TimeTag.class, "last_played_time", (attribute, object) -> {
        if (object.isOnline()) {
            return TimeTag.now();
        }
        return new TimeTag(object.getOfflinePlayer().getLastPlayed());
    });
    tagProcessor.registerTag(DurationTag.class, "last_played", (attribute, object) -> {
        Deprecations.playerTimePlayedTags.warn(attribute.context);
        if (object.isOnline()) {
            return new DurationTag(System.currentTimeMillis() / 50);
        }
        return new DurationTag(object.getOfflinePlayer().getLastPlayed() / 50);
    });
    // <--[tag]
    // @attribute <PlayerTag.groups[(<world>)]>
    // @returns ListTag
    // @description
    // Returns a list of all groups the player is in.
    // May work with offline players, depending on permission plugin.
    // -->
    tagProcessor.registerTag(ListTag.class, "groups", (attribute, object) -> {
        if (Depends.permissions == null) {
            if (!attribute.hasAlternative()) {
                Debug.echoError("No permission system loaded! Have you installed Vault and a compatible permissions plugin?");
            }
            return null;
        }
        ListTag list = new ListTag();
        WorldTag world = null;
        if (attribute.hasParam()) {
            world = attribute.paramAsType(WorldTag.class);
            if (world == null) {
                Debug.echoError("Invalid world specified: " + attribute.getParam());
                return null;
            }
        }
        for (String group : Depends.permissions.getGroups()) {
            if (Depends.permissions.playerInGroup(world != null ? world.getName() : null, object.getOfflinePlayer(), group)) {
                list.addObject(new ElementTag(group, true));
            }
        }
        return list;
    });
    // <--[tag]
    // @attribute <PlayerTag.ban_expiration_time>
    // @returns TimeTag
    // @description
    // Returns the expiration of the player's ban, if they are banned.
    // Potentially can be null.
    // -->
    tagProcessor.registerTag(TimeTag.class, "ban_expiration_time", (attribute, object) -> {
        BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(object.getName());
        if (ban == null || ban.getExpiration() == null || (ban.getExpiration() != null && ban.getExpiration().before(new Date()))) {
            return null;
        }
        return new TimeTag(ban.getExpiration().getTime());
    });
    tagProcessor.registerTag(DurationTag.class, "ban_expiration", (attribute, object) -> {
        Deprecations.playerTimePlayedTags.warn(attribute.context);
        BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(object.getName());
        if (ban == null || ban.getExpiration() == null || (ban.getExpiration() != null && ban.getExpiration().before(new Date()))) {
            return null;
        }
        return new DurationTag(ban.getExpiration().getTime() / 50);
    });
    // <--[tag]
    // @attribute <PlayerTag.ban_reason>
    // @returns ElementTag
    // @description
    // Returns the reason for the player's ban, if they are banned.
    // -->
    tagProcessor.registerTag(ElementTag.class, "ban_reason", (attribute, object) -> {
        BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(object.getName());
        if (ban == null || (ban.getExpiration() != null && ban.getExpiration().before(new Date()))) {
            return null;
        }
        return new ElementTag(ban.getReason(), true);
    });
    // <--[tag]
    // @attribute <PlayerTag.ban_created_time>
    // @returns TimeTag
    // @description
    // Returns when the player's ban was created, if they are banned.
    // -->
    tagProcessor.registerTag(TimeTag.class, "ban_created_time", (attribute, object) -> {
        BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(object.getName());
        if (ban == null || (ban.getExpiration() != null && ban.getExpiration().before(new Date()))) {
            return null;
        }
        return new TimeTag(ban.getCreated().getTime());
    });
    tagProcessor.registerTag(DurationTag.class, "ban_created", (attribute, object) -> {
        Deprecations.timeTagRewrite.warn(attribute.context);
        BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(object.getName());
        if (ban == null || (ban.getExpiration() != null && ban.getExpiration().before(new Date()))) {
            return null;
        }
        return new DurationTag(ban.getCreated().getTime() / 50);
    });
    // <--[tag]
    // @attribute <PlayerTag.ban_source>
    // @returns ElementTag
    // @description
    // Returns the source of the player's ban, if they are banned.
    // -->
    tagProcessor.registerTag(ElementTag.class, "ban_source", (attribute, object) -> {
        BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(object.getName());
        if (ban == null || (ban.getExpiration() != null && ban.getExpiration().before(new Date()))) {
            return null;
        }
        return new ElementTag(ban.getSource(), true);
    });
    tagProcessor.registerTag(ObjectTag.class, "ban_info", (attribute, object) -> {
        Deprecations.playerBanInfoTags.warn(attribute.context);
        BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(object.getName());
        if (ban == null || (ban.getExpiration() != null && ban.getExpiration().before(new Date()))) {
            return null;
        }
        if (attribute.startsWith("expiration", 2) && ban.getExpiration() != null) {
            attribute.fulfill(1);
            return new DurationTag(ban.getExpiration().getTime() / 50);
        } else if (attribute.startsWith("reason", 2)) {
            attribute.fulfill(1);
            return new ElementTag(ban.getReason());
        } else if (attribute.startsWith("created", 2)) {
            attribute.fulfill(1);
            return new DurationTag(ban.getCreated().getTime() / 50);
        } else if (attribute.startsWith("source", 2)) {
            attribute.fulfill(1);
            return new ElementTag(ban.getSource());
        }
        return null;
    });
    // <--[tag]
    // @attribute <PlayerTag.in_group[<group_name>]>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the player is in the specified group.
    // (May work with offline players, depending on your permissions system.)
    // -->
    tagProcessor.registerTag(ElementTag.class, "in_group", (attribute, object) -> {
        if (Depends.permissions == null) {
            if (!attribute.hasAlternative()) {
                Debug.echoError("No permission system loaded! Have you installed Vault and a compatible permissions plugin?");
            }
            return null;
        }
        String group = attribute.getParam();
        // Non-world specific permission
        if (attribute.startsWith("global", 2)) {
            attribute.fulfill(1);
            return new ElementTag(Depends.permissions.playerInGroup(null, object.getOfflinePlayer(), group));
        } else // Permission in certain world
        if (attribute.startsWith("world", 2)) {
            WorldTag world = null;
            if (attribute.hasContext(2)) {
                world = attribute.contextAsType(2, WorldTag.class);
                if (world == null) {
                    Debug.echoError("Invalid world specified: " + attribute.getContext(2));
                    return null;
                }
            }
            attribute.fulfill(1);
            return new ElementTag(Depends.permissions.playerInGroup(world != null ? world.getName() : null, object.getOfflinePlayer(), group));
        } else // Permission in current world
        if (object.isOnline()) {
            return new ElementTag(Depends.permissions.playerInGroup(object.getPlayerEntity(), group));
        } else if (Depends.permissions != null) {
            return new ElementTag(Depends.permissions.playerInGroup(null, object.getOfflinePlayer(), group));
        }
        return null;
    });
    // <--[tag]
    // @attribute <PlayerTag.has_permission[permission.node]>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the player has the specified node.
    // (May work with offline players, depending on your permissions system.)
    // -->
    tagProcessor.registerTag(ElementTag.class, "has_permission", (attribute, object) -> {
        String permission = attribute.getParam();
        // Non-world specific permission
        if (attribute.startsWith("global", 2)) {
            if (Depends.permissions == null) {
                if (!attribute.hasAlternative()) {
                    Debug.echoError("No permission system loaded! Have you installed Vault and a compatible permissions plugin?");
                }
                return null;
            }
            attribute.fulfill(1);
            return new ElementTag(Depends.permissions.playerHas(null, object.getOfflinePlayer(), permission));
        } else // Permission in certain world
        if (attribute.startsWith("world", 2)) {
            String world = attribute.getContext(2);
            if (Depends.permissions == null) {
                if (!attribute.hasAlternative()) {
                    Debug.echoError("No permission system loaded! Have you installed Vault and a compatible permissions plugin?");
                }
                return null;
            }
            attribute.fulfill(1);
            if (world.startsWith("w@")) {
                world = world.substring(2);
            }
            return new ElementTag(Depends.permissions.playerHas(world, object.getOfflinePlayer(), permission));
        } else // Permission in current world
        if (object.isOnline()) {
            return new ElementTag(object.getPlayerEntity().hasPermission(permission));
        } else if (Depends.permissions != null) {
            return new ElementTag(Depends.permissions.playerHas(null, object.getOfflinePlayer(), permission));
        }
        return null;
    }, "permission");
    // <--[tag]
    // @attribute <PlayerTag.statistic[<statistic>]>
    // @returns ElementTag(Number)
    // @description
    // Returns the player's current value for the specified statistic.
    // Valid statistics: <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Statistic.html>
    // Works with offline players.
    // -->
    tagProcessor.registerTag(ElementTag.class, "statistic", (attribute, object) -> {
        if (!attribute.hasParam()) {
            return null;
        }
        Statistic statistic;
        try {
            statistic = Statistic.valueOf(attribute.getParam().toUpperCase());
        } catch (IllegalArgumentException ex) {
            attribute.echoError("Statistic '" + attribute.getParam() + "' does not exist: " + ex.getMessage());
            return null;
        }
        // -->
        if (attribute.startsWith("qualifier", 2)) {
            ObjectTag obj = ObjectFetcher.pickObjectFor(attribute.getContext(2), attribute.context);
            attribute.fulfill(1);
            try {
                if (obj instanceof MaterialTag) {
                    return new ElementTag(object.getOfflinePlayer().getStatistic(statistic, ((MaterialTag) obj).getMaterial()));
                } else if (obj instanceof EntityTag) {
                    return new ElementTag(object.getOfflinePlayer().getStatistic(statistic, ((EntityTag) obj).getBukkitEntityType()));
                } else {
                    return null;
                }
            } catch (Exception e) {
                Debug.echoError("Invalid statistic: " + statistic + " for this player!");
                return null;
            }
        }
        try {
            return new ElementTag(object.getOfflinePlayer().getStatistic(statistic));
        } catch (Exception e) {
            Debug.echoError("Invalid statistic: " + statistic + " for this player!");
            return null;
        }
    });
    // <--[tag]
    // @attribute <PlayerTag.uuid>
    // @returns ElementTag
    // @description
    // Returns the UUID of the player.
    // Works with offline players.
    // -->
    tagProcessor.registerTag(ElementTag.class, "uuid", (attribute, object) -> {
        return new ElementTag(object.getUUID().toString());
    });
    // <--[tag]
    // @attribute <PlayerTag.list_name>
    // @returns ElementTag
    // @mechanism PlayerTag.player_list_name
    // @description
    // Returns the name of the player as shown in the player list.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "list_name", (attribute, object) -> {
        return new ElementTag(AdvancedTextImpl.instance.getPlayerListName(object.getPlayerEntity()), true);
    });
    // <--[tag]
    // @attribute <PlayerTag.display_name>
    // @returns ElementTag
    // @mechanism PlayerTag.display_name
    // @description
    // Returns the display name of the player, which may contain prefixes and suffixes, colors, etc.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "display_name", (attribute, object) -> {
        return new ElementTag(object.getPlayerEntity().getDisplayName(), true);
    });
    // Documented in EntityTag
    tagProcessor.registerTag(ElementTag.class, "name", (attribute, object) -> {
        if (attribute.startsWith("list", 2) && object.isOnline()) {
            Deprecations.playerNameTags.warn(attribute.context);
            attribute.fulfill(1);
            return new ElementTag(object.getPlayerEntity().getPlayerListName(), true);
        }
        if (attribute.startsWith("display", 2) && object.isOnline()) {
            Deprecations.playerNameTags.warn(attribute.context);
            attribute.fulfill(1);
            return new ElementTag(object.getPlayerEntity().getDisplayName(), true);
        }
        return new ElementTag(object.getName(), true);
    });
    // <--[tag]
    // @attribute <PlayerTag.client_brand>
    // @returns ElementTag
    // @description
    // Returns the brand of the client, as sent via the "minecraft:brand" packet.
    // On normal clients, will say "vanilla". On broken clients, will say "unknown". Modded clients will identify themselves (though not guaranteed!).
    // It may be ideal to change setting "Packets.Auto init" in the Denizen config to "true" to guarantee this tag functions as expected.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "client_brand", (attribute, object) -> {
        NetworkInterceptHelper.enable();
        return new ElementTag(NMSHandler.getPlayerHelper().getPlayerBrand(object.getPlayerEntity()), true);
    });
    // <--[tag]
    // @attribute <PlayerTag.locale>
    // @returns ElementTag
    // @description
    // Returns the current locale of the player.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "locale", (attribute, object) -> {
        return new ElementTag(object.getPlayerEntity().getLocale(), true);
    });
    // ///////////////////
    // INVENTORY ATTRIBUTES
    // ///////////////
    // <--[tag]
    // @attribute <PlayerTag.inventory>
    // @returns InventoryTag
    // @description
    // Returns a InventoryTag of the player's current inventory.
    // Works with offline players.
    // -->
    tagProcessor.registerTag(InventoryTag.class, "inventory", (attribute, object) -> {
        return object.getInventory();
    });
    // <--[tag]
    // @attribute <PlayerTag.enderchest>
    // @returns InventoryTag
    // @description
    // Gets the player's enderchest inventory.
    // Works with offline players.
    // -->
    tagProcessor.registerTag(InventoryTag.class, "enderchest", (attribute, object) -> {
        return object.getEnderChest();
    });
    // ///////////////////
    // ONLINE ATTRIBUTES
    // ///////////////
    // <--[tag]
    // @attribute <PlayerTag.open_inventory>
    // @returns InventoryTag
    // @description
    // Gets the inventory the player currently has open. If the player has no open
    // inventory, this returns the player's inventory.
    // -->
    registerOnlineOnlyTag(InventoryTag.class, "open_inventory", (attribute, object) -> {
        return InventoryTag.mirrorBukkitInventory(object.getPlayerEntity().getOpenInventory().getTopInventory());
    });
    // <--[tag]
    // @attribute <PlayerTag.discovered_recipes>
    // @returns ListTag
    // @description
    // Returns a list of the recipes the player has discovered, in the Namespace:Key format, for example "minecraft:gold_nugget".
    // -->
    registerOnlineOnlyTag(ListTag.class, "discovered_recipes", (attribute, object) -> {
        return new ListTag(NMSHandler.getEntityHelper().getDiscoveredRecipes(object.getPlayerEntity()));
    });
    // <--[tag]
    // @attribute <PlayerTag.selected_trade_index>
    // @returns ElementTag(Number)
    // @description
    // Returns the index of the trade the player is currently viewing, if any.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "selected_trade_index", (attribute, object) -> {
        if (object.getPlayerEntity().getOpenInventory().getTopInventory() instanceof MerchantInventory) {
            return new ElementTag(((MerchantInventory) object.getPlayerEntity().getOpenInventory().getTopInventory()).getSelectedRecipeIndex() + 1);
        }
        return null;
    });
    // [tag]
    // @attribute <PlayerTag.selected_trade>
    // @returns TradeTag
    // @description
    // Returns the trade the player is currently viewing, if any.
    // This is almost completely broke and only works if the player has placed items in the trade slots.
    // 
    registerOnlineOnlyTag(TradeTag.class, "selected_trade", (attribute, object) -> {
        Inventory playerInventory = object.getPlayerEntity().getOpenInventory().getTopInventory();
        if (playerInventory instanceof MerchantInventory && ((MerchantInventory) playerInventory).getSelectedRecipe() != null) {
            return new TradeTag(((MerchantInventory) playerInventory).getSelectedRecipe()).duplicate();
        }
        return null;
    });
    // <--[tag]
    // @attribute <PlayerTag.item_on_cursor>
    // @returns ItemTag
    // @mechanism PlayerTag.item_on_cursor
    // @description
    // Returns the item on the player's cursor, if any. This includes
    // chest interfaces, inventories, and hotbars, etc.
    // -->
    registerOnlineOnlyTag(ItemTag.class, "item_on_cursor", (attribute, object) -> {
        return new ItemTag(object.getPlayerEntity().getItemOnCursor());
    });
    // <--[tag]
    // @attribute <PlayerTag.held_item_slot>
    // @returns ElementTag(Number)
    // @description
    // Returns the slot location of the player's selected item.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "held_item_slot", (attribute, object) -> {
        return new ElementTag(object.getPlayerEntity().getInventory().getHeldItemSlot() + 1);
    });
    registerOnlineOnlyTag(ObjectTag.class, "item_in_hand", (attribute, object) -> {
        if (attribute.startsWith("slot", 2)) {
            Deprecations.playerItemInHandSlotTag.warn(attribute.context);
            attribute.fulfill(1);
            return new ElementTag(object.getPlayerEntity().getInventory().getHeldItemSlot() + 1);
        }
        return object.getHeldItem();
    });
    // <--[tag]
    // @attribute <PlayerTag.sidebar_lines>
    // @returns ListTag
    // @description
    // Returns the current lines set on the player's Sidebar via <@link command sidebar>.
    // -->
    registerOnlineOnlyTag(ListTag.class, "sidebar_lines", (attribute, object) -> {
        Sidebar sidebar = SidebarCommand.getSidebar(object);
        if (sidebar == null) {
            return null;
        }
        return new ListTag(sidebar.getLinesText(), true);
    });
    // <--[tag]
    // @attribute <PlayerTag.sidebar_title>
    // @returns ElementTag
    // @description
    // Returns the current title set on the player's Sidebar via <@link command sidebar>.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "sidebar_title", (attribute, object) -> {
        Sidebar sidebar = SidebarCommand.getSidebar(object);
        if (sidebar == null) {
            return null;
        }
        return new ElementTag(sidebar.getTitle(), true);
    });
    // <--[tag]
    // @attribute <PlayerTag.sidebar_scores>
    // @returns ListTag
    // @description
    // Returns the current scores set on the player's Sidebar via <@link command sidebar>,
    // in the same order as <@link tag PlayerTag.sidebar_lines>.
    // -->
    registerOnlineOnlyTag(ListTag.class, "sidebar_scores", (attribute, object) -> {
        Sidebar sidebar = SidebarCommand.getSidebar(object);
        if (sidebar == null) {
            return null;
        }
        ListTag scores = new ListTag();
        for (int score : sidebar.getScores()) {
            scores.add(String.valueOf(score));
        }
        return scores;
    });
    registerOnlineOnlyTag(ObjectTag.class, "sidebar", (attribute, object) -> {
        Deprecations.playerSidebarTags.warn(attribute.context);
        if (attribute.startsWith("lines", 2)) {
            attribute.fulfill(1);
            Sidebar sidebar = SidebarCommand.getSidebar(object);
            if (sidebar == null) {
                return null;
            }
            return new ListTag(sidebar.getLinesText());
        }
        if (attribute.startsWith("title", 2)) {
            attribute.fulfill(1);
            Sidebar sidebar = SidebarCommand.getSidebar(object);
            if (sidebar == null) {
                return null;
            }
            return new ElementTag(sidebar.getTitle());
        }
        if (attribute.startsWith("scores", 2)) {
            attribute.fulfill(1);
            Sidebar sidebar = SidebarCommand.getSidebar(object);
            if (sidebar == null) {
                return null;
            }
            ListTag scores = new ListTag();
            for (int score : sidebar.getScores()) {
                scores.add(String.valueOf(score));
            }
            return scores;
        }
        return null;
    });
    // <--[tag]
    // @attribute <PlayerTag.skin_blob>
    // @returns ElementTag
    // @mechanism PlayerTag.skin_blob
    // @description
    // Returns the player's current skin blob.
    // In the format: "texture;signature" (two values separated by a semicolon).
    // See also <@link language Player Entity Skins (Skin Blobs)>.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "skin_blob", (attribute, object) -> {
        return new ElementTag(NMSHandler.getInstance().getProfileEditor().getPlayerSkinBlob(object.getPlayerEntity()));
    });
    // <--[tag]
    // @attribute <PlayerTag.skull_skin>
    // @returns ElementTag
    // @description
    // Returns the player's current skin blob, formatted for input to a Player Skull item.
    // In the format: "UUID|Texture|Name" (three values separated by pipes).
    // See also <@link language Player Entity Skins (Skin Blobs)>.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "skull_skin", (attribute, object) -> {
        String skin = NMSHandler.getInstance().getProfileEditor().getPlayerSkinBlob(object.getPlayerEntity());
        if (skin == null) {
            return null;
        }
        int semicolon = skin.indexOf(';');
        return new ElementTag(object.getPlayerEntity().getUniqueId() + "|" + skin.substring(0, semicolon) + "|" + object.getName());
    });
    // <--[tag]
    // @attribute <PlayerTag.skull_item>
    // @returns ItemTag
    // @description
    // Returns a Player_Head item with the skin of the player.
    // See also <@link language Player Entity Skins (Skin Blobs)>.
    // -->
    registerOnlineOnlyTag(ItemTag.class, "skull_item", (attribute, object) -> {
        ItemStack item = new ItemStack(Material.PLAYER_HEAD);
        item = NMSHandler.getItemHelper().setSkullSkin(item, NMSHandler.getInstance().getPlayerProfile(object.getPlayerEntity()));
        return new ItemTag(item);
    });
    registerOnlineOnlyTag(ObjectTag.class, "attack_cooldown", (attribute, object) -> {
        Deprecations.playerAttackCooldownTags.warn(attribute.context);
        if (attribute.startsWith("duration", 2)) {
            attribute.fulfill(1);
            return new DurationTag((long) NMSHandler.getPlayerHelper().ticksPassedDuringCooldown(object.getPlayerEntity()));
        } else if (attribute.startsWith("max_duration", 2)) {
            attribute.fulfill(1);
            return new DurationTag((long) NMSHandler.getPlayerHelper().getMaxAttackCooldownTicks(object.getPlayerEntity()));
        } else if (attribute.startsWith("percent", 2)) {
            attribute.fulfill(1);
            return new ElementTag(NMSHandler.getPlayerHelper().getAttackCooldownPercent(object.getPlayerEntity()) * 100);
        }
        Debug.echoError("The tag 'player.attack_cooldown...' must be followed by a sub-tag.");
        return null;
    });
    // <--[tag]
    // @attribute <PlayerTag.main_hand>
    // @returns ElementTag
    // @description
    // Returns the player's main hand, either LEFT or RIGHT.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "main_hand", (attribute, object) -> {
        return new ElementTag(object.getPlayerEntity().getMainHand().toString());
    });
    // ///////////////////
    // CITIZENS ATTRIBUTES
    // ///////////////
    // <--[tag]
    // @attribute <PlayerTag.selected_npc>
    // @returns NPCTag
    // @mechanism PlayerTag.selected_npc
    // @description
    // Returns the NPCTag that the player currently has selected with '/npc select', null if no NPC selected.
    // -->
    registerOnlineOnlyTag(NPCTag.class, "selected_npc", (attribute, object) -> {
        if (object.getPlayerEntity().hasMetadata("selected")) {
            return object.getSelectedNPC();
        }
        return null;
    });
    // ///////////////////
    // CONVERSION ATTRIBUTES
    // ///////////////
    // <--[tag]
    // @attribute <PlayerTag.entity>
    // @returns EntityTag
    // @description
    // Returns the EntityTag object of the player.
    // (Note: This should never actually be needed. PlayerTags are considered valid EntityTags.)
    // -->
    registerOnlineOnlyTag(EntityTag.class, "entity", (attribute, object) -> {
        return new EntityTag(object.getPlayerEntity());
    });
    // ///////////////////
    // IDENTIFICATION ATTRIBUTES
    // ///////////////
    // <--[tag]
    // @attribute <PlayerTag.ip_address>
    // @returns ElementTag
    // @description
    // Returns the player's IP address, without port or hostname.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "ip_address", (attribute, object) -> {
        return new ElementTag(object.getPlayerEntity().getAddress().getAddress().toString());
    });
    // <--[tag]
    // @attribute <PlayerTag.ip>
    // @returns ElementTag
    // @description
    // Returns the player's IP address host name.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "ip", (attribute, object) -> {
        // -->
        if (attribute.startsWith("address_only", 2)) {
            attribute.fulfill(1);
            return new ElementTag(object.getPlayerEntity().getAddress().toString());
        }
        String host = object.getPlayerEntity().getAddress().getHostName();
        // -->
        if (attribute.startsWith("address", 2)) {
            attribute.fulfill(1);
            return new ElementTag(object.getPlayerEntity().getAddress().toString());
        }
        return new ElementTag(host);
    }, "host_name");
    // <--[tag]
    // @attribute <PlayerTag.nameplate>
    // @returns ElementTag
    // @description
    // Returns the displayed text in the nameplate of the player.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "nameplate", (attribute, object) -> {
        return new ElementTag(NMSHandler.getInstance().getProfileEditor().getPlayerName(object.getPlayerEntity()), true);
    });
    // ///////////////////
    // LOCATION ATTRIBUTES
    // ///////////////
    // <--[tag]
    // @attribute <PlayerTag.compass_target>
    // @returns LocationTag
    // @description
    // Returns the location of the player's compass target.
    // -->
    registerOnlineOnlyTag(LocationTag.class, "compass_target", (attribute, object) -> {
        Location target = object.getPlayerEntity().getCompassTarget();
        if (target != null) {
            return new LocationTag(target);
        }
        return null;
    });
    // <--[tag]
    // @attribute <PlayerTag.chunk_loaded[<chunk>]>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the player has the chunk loaded on their client.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "chunk_loaded", (attribute, object) -> {
        if (!attribute.hasParam()) {
            return null;
        }
        ChunkTag chunk = attribute.paramAsType(ChunkTag.class);
        if (chunk == null) {
            return null;
        }
        return new ElementTag(chunk.isLoadedSafe() && object.hasChunkLoaded(chunk.getChunkForTag(attribute)));
    });
    // ///////////////////
    // STATE ATTRIBUTES
    // ///////////////
    // <--[tag]
    // @attribute <PlayerTag.can_fly>
    // @returns ElementTag(Boolean)
    // @mechanism PlayerTag.can_fly
    // @description
    // Returns whether the player is allowed to fly.
    // Works with offline players.
    // -->
    tagProcessor.registerTag(ElementTag.class, "can_fly", (attribute, object) -> {
        if (object.isOnline()) {
            return new ElementTag(object.getPlayerEntity().getAllowFlight());
        } else {
            return new ElementTag(object.getNBTEditor().getAllowFlight());
        }
    }, "allowed_flight");
    // <--[tag]
    // @attribute <PlayerTag.fly_speed>
    // @returns ElementTag(Decimal)
    // @mechanism PlayerTag.fly_speed
    // @description
    // Returns the speed the player can fly at.
    // Default value is '0.2'.
    // Works with offline players.
    // -->
    tagProcessor.registerTag(ElementTag.class, "fly_speed", (attribute, object) -> {
        if (object.isOnline()) {
            return new ElementTag(object.getPlayerEntity().getFlySpeed());
        } else {
            return new ElementTag(object.getNBTEditor().getFlySpeed());
        }
    });
    // <--[tag]
    // @attribute <PlayerTag.walk_speed>
    // @returns ElementTag(Decimal)
    // @mechanism PlayerTag.walk_speed
    // @description
    // Returns the speed the player can walk at.
    // Works with offline players.
    // -->
    tagProcessor.registerTag(ElementTag.class, "walk_speed", (attribute, object) -> {
        if (object.isOnline()) {
            return new ElementTag(object.getPlayerEntity().getWalkSpeed());
        } else {
            return new ElementTag(object.getNBTEditor().getWalkSpeed());
        }
    });
    // <--[tag]
    // @attribute <PlayerTag.saturation>
    // @returns ElementTag(Decimal)
    // @mechanism PlayerTag.saturation
    // @description
    // Returns the current food saturation of the player.
    // Works with offline players.
    // -->
    tagProcessor.registerTag(ElementTag.class, "saturation", (attribute, object) -> {
        if (object.isOnline()) {
            return new ElementTag(object.getPlayerEntity().getSaturation());
        } else {
            return new ElementTag(object.getNBTEditor().getSaturation());
        }
    });
    // <--[tag]
    // @attribute <PlayerTag.formatted_food_level[(<max>)]>
    // @returns ElementTag
    // @mechanism PlayerTag.food_level
    // @description
    // Returns a 'formatted' value of the player's current food level.
    // May be 'starving', 'famished', 'parched, 'hungry', or 'healthy'.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "formatted_food_level", (attribute, object) -> {
        double maxHunger = object.getPlayerEntity().getMaxHealth();
        if (attribute.hasParam()) {
            maxHunger = attribute.getIntParam();
        }
        attribute.fulfill(1);
        int foodLevel = object.getFoodLevel();
        if (foodLevel / maxHunger < .10) {
            return new ElementTag("starving");
        } else if (foodLevel / maxHunger < .40) {
            return new ElementTag("famished");
        } else if (foodLevel / maxHunger < .75) {
            return new ElementTag("parched");
        } else if (foodLevel / maxHunger < 1) {
            return new ElementTag("hungry");
        } else {
            return new ElementTag("healthy");
        }
    });
    // <--[tag]
    // @attribute <PlayerTag.food_level>
    // @returns ElementTag(Number)
    // @mechanism PlayerTag.food_level
    // @description
    // Returns the current food level (aka hunger) of the player.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "food_level", (attribute, object) -> {
        if (attribute.startsWith("formatted", 2)) {
            Deprecations.playerFoodLevelFormatTag.warn(attribute.context);
            double maxHunger = object.getPlayerEntity().getMaxHealth();
            if (attribute.hasContext(2)) {
                maxHunger = attribute.getIntContext(2);
            }
            attribute.fulfill(1);
            int foodLevel = object.getFoodLevel();
            if (foodLevel / maxHunger < .10) {
                return new ElementTag("starving");
            } else if (foodLevel / maxHunger < .40) {
                return new ElementTag("famished");
            } else if (foodLevel / maxHunger < .75) {
                return new ElementTag("parched");
            } else if (foodLevel / maxHunger < 1) {
                return new ElementTag("hungry");
            } else {
                return new ElementTag("healthy");
            }
        }
        return new ElementTag(object.getFoodLevel());
    });
    // <--[tag]
    // @attribute <PlayerTag.gamemode>
    // @returns ElementTag
    // @mechanism PlayerTag.gamemode
    // @description
    // Returns the name of the gamemode the player is currently set to.
    // Works with offline players.
    // -->
    tagProcessor.registerTag(ElementTag.class, "gamemode", (attribute, object) -> {
        if (object.isOnline()) {
            return new ElementTag(object.getPlayerEntity().getGameMode().name());
        }
        return new ElementTag(object.getNBTEditor().getGameMode().name());
    });
    // <--[tag]
    // @attribute <PlayerTag.is_blocking>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the player is currently blocking.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "is_blocking", (attribute, object) -> {
        return new ElementTag(object.getPlayerEntity().isBlocking());
    });
    // <--[tag]
    // @attribute <PlayerTag.ping>
    // @returns ElementTag(Number)
    // @description
    // Returns the player's current ping.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "ping", (attribute, object) -> {
        return new ElementTag(NMSHandler.getPlayerHelper().getPing(object.getPlayerEntity()));
    });
    // <--[tag]
    // @attribute <PlayerTag.is_flying>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the player is currently flying.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "is_flying", (attribute, object) -> {
        return new ElementTag(object.getPlayerEntity().isFlying());
    });
    // <--[tag]
    // @attribute <PlayerTag.is_sneaking>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the player is currently sneaking.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "is_sneaking", (attribute, object) -> {
        return new ElementTag(object.getPlayerEntity().isSneaking());
    });
    // <--[tag]
    // @attribute <PlayerTag.is_sprinting>
    // @returns ElementTag(Boolean)
    // @mechanism PlayerTag.sprinting
    // @description
    // Returns whether the player is currently sprinting.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "is_sprinting", (attribute, object) -> {
        return new ElementTag(object.getPlayerEntity().isSprinting());
    });
    // <--[tag]
    // @attribute <PlayerTag.has_advancement[<advancement>]>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the player has completed the specified advancement.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "has_advancement", (attribute, object) -> {
        if (!attribute.hasParam()) {
            return null;
        }
        Advancement adv = AdvancementHelper.getAdvancement(attribute.getParam());
        if (adv == null) {
            if (!attribute.hasAlternative()) {
                Debug.echoError("Advancement '" + attribute.getParam() + "' does not exist.");
            }
            return null;
        }
        AdvancementProgress progress = object.getPlayerEntity().getAdvancementProgress(adv);
        return new ElementTag(progress.isDone());
    });
    // <--[tag]
    // @attribute <PlayerTag.advancements>
    // @returns ListTag
    // @description
    // Returns a list of the names of all advancements the player has completed.
    // -->
    registerOnlineOnlyTag(ListTag.class, "advancements", (attribute, object) -> {
        ListTag list = new ListTag();
        Bukkit.advancementIterator().forEachRemaining((adv) -> {
            if (object.getPlayerEntity().getAdvancementProgress(adv).isDone()) {
                list.add(adv.getKey().toString());
            }
        });
        return list;
    }, "list_advancements");
    // <--[tag]
    // @attribute <PlayerTag.time_asleep>
    // @returns DurationTag
    // @description
    // Returns the time the player has been asleep.
    // -->
    registerOnlineOnlyTag(DurationTag.class, "time_asleep", (attribute, object) -> {
        return new DurationTag((long) object.getPlayerEntity().getSleepTicks());
    });
    // <--[tag]
    // @attribute <PlayerTag.time>
    // @returns ElementTag(Number)
    // @description
    // Returns the time the player is currently experiencing.
    // This time could differ from the time that the rest of the world is currently experiencing if <@link command time> is being used on the player.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "time", (attribute, object) -> {
        return new ElementTag(object.getPlayerEntity().getPlayerTime());
    });
    // <--[tag]
    // @attribute <PlayerTag.weather>
    // @returns ElementTag
    // @description
    // Returns the type of weather the player is experiencing. This will be different
    // from the weather currently in the world that the player is residing in if
    // the weather is currently being forced onto the player.
    // Returns null if the player does not currently have any forced weather.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "weather", (attribute, object) -> {
        if (object.getPlayerEntity().getPlayerWeather() != null) {
            return new ElementTag(object.getPlayerEntity().getPlayerWeather().name());
        } else {
            return null;
        }
    });
    // <--[tag]
    // @attribute <PlayerTag.calculate_xp>
    // @returns ElementTag(Number)
    // @description
    // Returns the calculated total amount of XP the player has, based on the amount of experience needed per level, for each level the player has.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "calculate_xp", (attribute, object) -> {
        int level = object.getPlayerEntity().getLevel();
        return new ElementTag(ExperienceCommand.TOTAL_XP_FOR_LEVEL(level) + (object.getPlayerEntity().getExp() * ExperienceCommand.XP_FOR_NEXT_LEVEL(level)));
    });
    // <--[tag]
    // @attribute <PlayerTag.xp_level>
    // @returns ElementTag(Number)
    // @description
    // Returns the number of XP levels the player has.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "xp_level", (attribute, object) -> {
        return new ElementTag(object.getPlayerEntity().getLevel());
    });
    // <--[tag]
    // @attribute <PlayerTag.xp_to_next_level>
    // @returns ElementTag(Number)
    // @description
    // Returns the amount of XP the player needs to get to the next level.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "xp_to_next_level", (attribute, object) -> {
        return new ElementTag(object.getPlayerEntity().getExpToLevel());
    });
    // <--[tag]
    // @attribute <PlayerTag.xp_total>
    // @returns ElementTag(Number)
    // @description
    // Returns the total amount of experience points the player has.
    // This is how much XP the player has ever received, not a current value.
    // To get the current total, use @<link tag PlayerTag.calculate_xp>.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "xp_total", (attribute, object) -> {
        return new ElementTag(object.getPlayerEntity().getTotalExperience());
    });
    // <--[tag]
    // @attribute <PlayerTag.xp>
    // @returns ElementTag(Decimal)
    // @description
    // Returns the percentage of experience points to the next level.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "xp", (attribute, object) -> {
        if (attribute.startsWith("level", 2)) {
            Deprecations.playerXpTags.warn(attribute.context);
            attribute.fulfill(1);
            return new ElementTag(object.getPlayerEntity().getLevel());
        }
        if (attribute.startsWith("to_next_level", 2)) {
            Deprecations.playerXpTags.warn(attribute.context);
            attribute.fulfill(1);
            return new ElementTag(object.getPlayerEntity().getExpToLevel());
        }
        if (attribute.startsWith("total", 2)) {
            Deprecations.playerXpTags.warn(attribute.context);
            attribute.fulfill(1);
            return new ElementTag(object.getPlayerEntity().getTotalExperience());
        }
        return new ElementTag(object.getPlayerEntity().getExp() * 100);
    });
    // <--[tag]
    // @attribute <PlayerTag.chat_prefix>
    // @returns ElementTag
    // @plugin Vault
    // @mechanism PlayerTag.chat_prefix
    // @description
    // Returns the player's chat prefix.
    // NOTE: May work with offline players.
    // Requires a Vault-compatible chat plugin.
    // -->
    tagProcessor.registerTag(ElementTag.class, "chat_prefix", (attribute, object) -> {
        if (Depends.chat == null) {
            if (!attribute.hasAlternative()) {
                Debug.echoError("'chat_prefix' tag unavailable: Vault and a chat plugin are required.");
            }
            return null;
        }
        String prefix = Depends.chat.getPlayerPrefix(object.getWorld().getName(), object.getOfflinePlayer());
        if (prefix == null) {
            return null;
        }
        return new ElementTag(prefix, true);
    });
    // <--[tag]
    // @attribute <PlayerTag.chat_suffix>
    // @returns ElementTag
    // @plugin Vault
    // @mechanism PlayerTag.chat_suffix
    // @description
    // Returns the player's chat suffix.
    // NOTE: May work with offline players.
    // Requires a Vault-compatible chat plugin.
    // -->
    tagProcessor.registerTag(ElementTag.class, "chat_suffix", (attribute, object) -> {
        if (Depends.chat == null) {
            if (!attribute.hasAlternative()) {
                Debug.echoError("'chat_suffix' tag unavailable: Vault and a chat plugin are required.");
            }
            return null;
        }
        String suffix = Depends.chat.getPlayerSuffix(object.getWorld().getName(), object.getOfflinePlayer());
        if (suffix == null) {
            return null;
        }
        return new ElementTag(suffix, true);
    });
    // <--[tag]
    // @attribute <PlayerTag.fake_block_locations>
    // @returns ListTag(LocationTag)
    // @description
    // Returns a list of locations that the player will see a fake block at, as set by <@link command showfake> or connected commands.
    // -->
    tagProcessor.registerTag(ListTag.class, "fake_block_locations", (attribute, object) -> {
        ListTag list = new ListTag();
        FakeBlock.FakeBlockMap map = FakeBlock.blocks.get(object.getUUID());
        if (map != null) {
            for (LocationTag loc : map.byLocation.keySet()) {
                list.addObject(loc.clone());
            }
        }
        return list;
    });
    // <--[tag]
    // @attribute <PlayerTag.fake_block[<location>]>
    // @returns MaterialTag
    // @description
    // Returns the fake material that the player will see at the input location, as set by <@link command showfake> or connected commands.
    // Works best alongside <@link tag PlayerTag.fake_block_locations>.
    // Returns null if the player doesn't have a fake block at the location.
    // -->
    tagProcessor.registerTag(MaterialTag.class, "fake_block", (attribute, object) -> {
        if (!attribute.hasParam()) {
            return null;
        }
        LocationTag input = attribute.paramAsType(LocationTag.class);
        FakeBlock.FakeBlockMap map = FakeBlock.blocks.get(object.getUUID());
        if (map != null) {
            FakeBlock block = map.byLocation.get(input);
            if (block != null) {
                return block.material;
            }
        }
        return null;
    });
    // <--[tag]
    // @attribute <PlayerTag.fake_entities>
    // @returns ListTag(EntityTag)
    // @description
    // Returns a list of fake entities the player can see, as set by <@link command fakespawn>.
    // Note that these entities are not being tracked by the server, so many operations may not be possible on them.
    // -->
    tagProcessor.registerTag(ListTag.class, "fake_entities", (attribute, object) -> {
        ListTag list = new ListTag();
        FakeEntity.FakeEntityMap map = FakeEntity.playersToEntities.get(object.getUUID());
        if (map != null) {
            for (Map.Entry<Integer, FakeEntity> entry : map.byId.entrySet()) {
                list.addObject(entry.getValue().entity);
            }
        }
        return list;
    });
    // <--[tag]
    // @attribute <PlayerTag.disguise_to_self[(<player>)]>
    // @returns EntityTag
    // @group properties
    // @description
    // Returns the fake entity used to disguise the entity in the player's self-view (only relevant to players), either globally (if no context input given), or to the specified player.
    // Relates to <@link command disguise>.
    // -->
    tagProcessor.registerTag(EntityTag.class, "disguise_to_self", (attribute, object) -> {
        HashMap<UUID, DisguiseCommand.TrackedDisguise> map = DisguiseCommand.disguises.get(object.getUUID());
        if (map == null) {
            return null;
        }
        DisguiseCommand.TrackedDisguise disguise;
        if (attribute.hasParam()) {
            PlayerTag player = attribute.paramAsType(PlayerTag.class);
            if (player == null) {
                attribute.echoError("Invalid player for is_disguised tag.");
                return null;
            }
            disguise = map.get(player.getUUID());
            if (disguise == null) {
                disguise = map.get(null);
            }
        } else {
            disguise = map.get(null);
        }
        if (disguise == null) {
            return null;
        }
        if (disguise.fakeToSelf == null) {
            return null;
        }
        return disguise.fakeToSelf.entity;
    });
    // <--[tag]
    // @attribute <PlayerTag.spectator_target>
    // @returns EntityTag
    // @mechanism PlayerTag.spectator_target
    // @description
    // Returns the entity that a spectator-mode player is currently spectating, if any.
    // -->
    registerOnlineOnlyTag(ObjectTag.class, "spectator_target", (attribute, object) -> {
        if (object.getPlayerEntity().getGameMode() != GameMode.SPECTATOR) {
            return null;
        }
        Entity target = object.getPlayerEntity().getSpectatorTarget();
        if (target == null) {
            return null;
        }
        return new EntityTag(target).getDenizenObject();
    });
    // <--[tag]
    // @attribute <PlayerTag.packets_sent>
    // @returns ElementTag(Number)
    // @description
    // Returns a total count of how many network packets have been sent to this player while they have been online.
    // It may be ideal to change setting "Packets.Auto init" in the Denizen config to "true" to guarantee this tag functions as expected.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "packets_sent", (attribute, object) -> {
        NetworkInterceptHelper.enable();
        return new ElementTag(NMSHandler.getPacketHelper().getPacketStats(object.getPlayerEntity(), true));
    });
    // <--[tag]
    // @attribute <PlayerTag.packets_received>
    // @returns ElementTag(Number)
    // @description
    // Returns a total count of how many network packets have been received from this player while they have been online.
    // It may be ideal to change setting "Packets.Auto init" in the Denizen config to "true" to guarantee this tag functions as expected.
    // -->
    registerOnlineOnlyTag(ElementTag.class, "packets_received", (attribute, object) -> {
        NetworkInterceptHelper.enable();
        return new ElementTag(NMSHandler.getPacketHelper().getPacketStats(object.getPlayerEntity(), false));
    });
    // <--[tag]
    // @attribute <PlayerTag.fish_hook>
    // @returns EntityTag
    // @description
    // Returns the fishing hook a player has cast (if any).
    // -->
    registerOnlineOnlyTag(EntityTag.class, "fish_hook", (attribute, object) -> {
        FishHook hook = NMSHandler.getFishingHelper().getHookFrom(object.getPlayerEntity());
        if (hook == null) {
            return null;
        }
        return new EntityTag(hook);
    });
    // <--[tag]
    // @attribute <PlayerTag.spawn_forced>
    // @returns ElementTag(Boolean)
    // @mechanism PlayerTag.spawn_forced
    // @description
    // Returns whether the player's bed spawn location is forced (ie still valid even if a bed is missing).
    // -->
    tagProcessor.registerTag(ElementTag.class, "spawn_forced", (attribute, object) -> {
        if (object.isOnline()) {
            return new ElementTag(NMSHandler.getPlayerHelper().getSpawnForced(object.getPlayerEntity()));
        }
        return new ElementTag(object.getNBTEditor().isSpawnForced());
    });
    // <--[tag]
    // @attribute <PlayerTag.last_action_time>
    // @returns TimeTag
    // @description
    // Returns the time of the last direct input from the player. Internally used with <@link tag server.idle_timeout>.
    // -->
    registerOnlineOnlyTag(TimeTag.class, "last_action_time", (attribute, object) -> {
        // The internal time values use monotonic time - this converts to real time.
        long playerMilliTime = NMSHandler.getPlayerHelper().getLastActionTime(object.getPlayerEntity());
        long relativeMillis = System.nanoTime() / 1000000L - playerMilliTime;
        return new TimeTag(System.currentTimeMillis() - relativeMillis);
    });
    // <--[tag]
    // @attribute <PlayerTag.scoreboard_id>
    // @returns ElementTag
    // @description
    // Returns the ID of the scoreboard from <@link command scoreboard> that a player is currently viewing, if any.
    // -->
    tagProcessor.registerTag(ElementTag.class, "scoreboard_id", (attribute, object) -> {
        String id = ScoreboardHelper.viewerMap.get(object.getUUID());
        if (id == null) {
            return null;
        }
        return new ElementTag(id);
    });
    // <--[tag]
    // @attribute <PlayerTag.bossbar_ids>
    // @returns ListTag
    // @description
    // Returns a list of all bossbars from <@link command bossbar> that this player can see.
    // Does not list bossbars created by any other source.
    // -->
    registerOnlineOnlyTag(ListTag.class, "bossbar_ids", (attribute, object) -> {
        ListTag result = new ListTag();
        for (Map.Entry<String, BossBar> bar : BossBarCommand.bossBarMap.entrySet()) {
            if (bar.getValue().getPlayers().contains(object.getPlayerEntity())) {
                result.addObject(new ElementTag(bar.getKey(), true));
            }
        }
        return result;
    });
    // <--[tag]
    // @attribute <PlayerTag.tab_completions[<command>]>
    // @returns ListTag
    // @description
    // Returns a list of all tab completions for the given plaintext of a command.
    // Input is formatted equivalent to if it were typed into a chat bar, minus the '/' slash at the start.
    // Input must necessarily contain at least one space.
    // For example: "<player.tab_completions[npc ]>" will return all /NPC sub command names available to the player.
    // This is only compatible with commands registered in Spigot. Meaning in particular, vanilla commands are not recognized or supported.
    // -->
    registerOnlineOnlyTag(ListTag.class, "tab_completions", (attribute, object) -> {
        if (!attribute.hasParam()) {
            return null;
        }
        String cmdFull = attribute.getParam();
        int space = cmdFull.indexOf(' ');
        if (space == -1) {
            attribute.echoError("Invalid command input '" + cmdFull + "': must have at least one space");
            return null;
        }
        String cmdName = cmdFull.substring(0, space);
        PluginCommand actualCmd = Bukkit.getPluginCommand(cmdName);
        if (actualCmd == null) {
            attribute.echoError("Unknown command '" + cmdName + "'");
            return null;
        }
        String args = cmdFull.substring(space + 1);
        ListTag result = new ListTag();
        for (String str : actualCmd.tabComplete(object.getPlayerEntity(), cmdName, CoreUtilities.split(args, ' ').toArray(new String[0]))) {
            result.addObject(new ElementTag(str, true));
        }
        return result;
    });
}
Also used : DisguiseCommand(com.denizenscript.denizen.scripts.commands.player.DisguiseCommand) FakeEntity(com.denizenscript.denizen.utilities.entity.FakeEntity) BossBar(org.bukkit.boss.BossBar) AdvancementProgress(org.bukkit.advancement.AdvancementProgress) RayTraceResult(org.bukkit.util.RayTraceResult) Sidebar(com.denizenscript.denizen.nms.abstracts.Sidebar) FakeEntity(com.denizenscript.denizen.utilities.entity.FakeEntity) PluginCommand(org.bukkit.command.PluginCommand) FakeBlock(com.denizenscript.denizen.utilities.blocks.FakeBlock) Advancement(org.bukkit.advancement.Advancement)

Example 2 with Sidebar

use of com.denizenscript.denizen.nms.abstracts.Sidebar in project Denizen-For-Bukkit by DenizenScript.

the class SidebarCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag action = scriptEntry.getElement("action");
    ElementTag elTitle = scriptEntry.getElement("title");
    ElementTag elScores = scriptEntry.getElement("scores");
    ElementTag elValue = scriptEntry.getElement("value");
    ElementTag elIncrement = scriptEntry.getElement("increment");
    ElementTag elStart = scriptEntry.getElement("start");
    ElementTag elPlayers = scriptEntry.getElement("players");
    ElementTag elPerPlayer = scriptEntry.getElement("per_player");
    ListTag players = ListTag.valueOf(TagManager.tag(elPlayers.asString(), scriptEntry.getContext()), scriptEntry.getContext());
    boolean per_player = elPerPlayer.asBoolean();
    String perTitle = null;
    String perScores = null;
    String perValue = null;
    String perIncrement = null;
    String perStart = null;
    ElementTag title = null;
    ListTag scores = null;
    ListTag value = null;
    ElementTag increment = null;
    ElementTag start = null;
    if (per_player) {
        if (elTitle != null) {
            perTitle = elTitle.asString();
        }
        if (elScores != null) {
            perScores = elScores.asString();
        }
        if (elValue != null) {
            perValue = elValue.asString();
        }
        if (elIncrement != null) {
            perIncrement = elIncrement.asString();
        }
        if (elStart != null) {
            perStart = elStart.asString();
        }
        if (scriptEntry.dbCallShouldDebug()) {
            Debug.report(scriptEntry, getName(), action, elTitle, elScores, elValue, elIncrement, elStart, db("players", players));
        }
    } else {
        BukkitTagContext context = (BukkitTagContext) scriptEntry.getContext();
        if (elTitle != null) {
            title = new ElementTag(TagManager.tag(elTitle.asString(), context));
        }
        if (elScores != null) {
            scores = ListTag.getListFor(TagManager.tagObject(elScores.asString(), context), context);
        }
        if (elValue != null) {
            value = ListTag.getListFor(TagManager.tagObject(elValue.asString(), context), context);
        }
        if (elIncrement != null) {
            increment = new ElementTag(TagManager.tag(elIncrement.asString(), context));
        }
        if (elStart != null) {
            start = new ElementTag(TagManager.tag(elStart.asString(), context));
        }
        if (scriptEntry.dbCallShouldDebug()) {
            Debug.report(scriptEntry, getName(), action, title, scores, value, increment, start, db("players", players));
        }
    }
    switch(Action.valueOf(action.asString())) {
        case ADD:
            for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
                if (player == null || !player.isValid()) {
                    Debug.echoError("Invalid player!");
                    continue;
                }
                Sidebar sidebar = createSidebar(player);
                if (sidebar == null) {
                    continue;
                }
                List<Sidebar.SidebarLine> current = sidebar.getLines();
                if (per_player) {
                    TagContext context = new BukkitTagContext(player, Utilities.getEntryNPC(scriptEntry), scriptEntry, scriptEntry.shouldDebug(), scriptEntry.getScript());
                    value = ListTag.getListFor(TagManager.tagObject(perValue, context), context);
                    if (perScores != null) {
                        scores = ListTag.getListFor(TagManager.tagObject(perScores, context), context);
                    }
                }
                try {
                    int index = start != null ? start.asInt() : (current.size() > 0 ? current.get(current.size() - 1).score : value.size());
                    int incr = increment != null ? increment.asInt() : -1;
                    for (int i = 0; i < value.size(); i++, index += incr) {
                        int score = (scores != null && i < scores.size()) ? Integer.valueOf(scores.get(i)) : index;
                        while (hasScoreAlready(current, score)) {
                            score += (incr == 0 ? 1 : incr);
                        }
                        current.add(new Sidebar.SidebarLine(value.get(i), score));
                    }
                } catch (Exception e) {
                    Debug.echoError(e);
                    continue;
                }
                sidebar.setLines(current);
                sidebar.sendUpdate();
            }
            break;
        case REMOVE:
            for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
                if (player == null || !player.isValid()) {
                    Debug.echoError("Invalid player!");
                    continue;
                }
                Sidebar sidebar = createSidebar(player);
                if (sidebar == null) {
                    continue;
                }
                List<Sidebar.SidebarLine> current = sidebar.getLines();
                if (per_player) {
                    TagContext context = new BukkitTagContext(player, Utilities.getEntryNPC(scriptEntry), scriptEntry, scriptEntry.shouldDebug(), scriptEntry.getScript());
                    if (perValue != null) {
                        value = ListTag.getListFor(TagManager.tagObject(perValue, context), context);
                    }
                    if (perScores != null) {
                        scores = ListTag.getListFor(TagManager.tagObject(perScores, context), context);
                    }
                }
                boolean removedAny = false;
                if (scores != null) {
                    try {
                        for (String scoreString : scores) {
                            int score = Integer.valueOf(scoreString);
                            for (int i = 0; i < current.size(); i++) {
                                if (current.get(i).score == score) {
                                    current.remove(i--);
                                }
                            }
                        }
                    } catch (Exception e) {
                        Debug.echoError(e);
                        continue;
                    }
                    sidebar.setLines(current);
                    sidebar.sendUpdate();
                    removedAny = true;
                }
                if (value != null) {
                    for (String line : value) {
                        for (int i = 0; i < current.size(); i++) {
                            if (current.get(i).text.equalsIgnoreCase(line)) {
                                current.remove(i--);
                            }
                        }
                    }
                    sidebar.setLines(current);
                    sidebar.sendUpdate();
                    removedAny = true;
                }
                if (!removedAny) {
                    sidebar.remove();
                    sidebars.remove(player.getPlayerEntity().getUniqueId());
                }
            }
            break;
        case SET_LINE:
            for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
                if (player == null || !player.isValid()) {
                    Debug.echoError("Invalid player!");
                    continue;
                }
                if ((scores == null || scores.isEmpty()) && perScores == null) {
                    Debug.echoError("Missing or invalid 'scores' parameter.");
                    return;
                }
                if ((value == null || value.size() != scores.size()) && perValue == null) {
                    Debug.echoError("Missing or invalid 'values' parameter.");
                    return;
                }
                Sidebar sidebar = createSidebar(player);
                if (sidebar == null) {
                    continue;
                }
                List<Sidebar.SidebarLine> current = sidebar.getLines();
                if (per_player) {
                    TagContext context = new BukkitTagContext(player, Utilities.getEntryNPC(scriptEntry), scriptEntry, scriptEntry.shouldDebug(), scriptEntry.getScript());
                    if (perValue != null) {
                        value = ListTag.getListFor(TagManager.tagObject(perValue, context), context);
                    }
                    if (perScores != null) {
                        scores = ListTag.getListFor(TagManager.tagObject(perScores, context), context);
                    }
                }
                try {
                    for (int i = 0; i < value.size(); i++) {
                        if (!ArgumentHelper.matchesInteger(scores.get(i))) {
                            Debug.echoError("Sidebar command scores input contains not-a-valid-number: " + scores.get(i));
                            return;
                        }
                        int score = Integer.parseInt(scores.get(i));
                        if (hasScoreAlready(current, score)) {
                            for (Sidebar.SidebarLine line : current) {
                                if (line.score == score) {
                                    line.text = value.get(i);
                                    break;
                                }
                            }
                        } else {
                            current.add(new Sidebar.SidebarLine(value.get(i), score));
                        }
                    }
                } catch (Exception e) {
                    Debug.echoError(e);
                    continue;
                }
                sidebar.setLines(current);
                sidebar.sendUpdate();
            }
            break;
        case SET:
            for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
                if (player == null || !player.isValid()) {
                    Debug.echoError("Invalid player!");
                    continue;
                }
                Sidebar sidebar = createSidebar(player);
                if (sidebar == null) {
                    continue;
                }
                List<Sidebar.SidebarLine> current = new ArrayList<>();
                if (per_player) {
                    TagContext context = new BukkitTagContext(player, Utilities.getEntryNPC(scriptEntry), scriptEntry, scriptEntry.shouldDebug(), scriptEntry.getScript());
                    if (perValue != null) {
                        value = ListTag.getListFor(TagManager.tagObject(perValue, context), context);
                    }
                    if (perScores != null) {
                        scores = ListTag.getListFor(TagManager.tagObject(perScores, context), context);
                    }
                    if (perStart != null) {
                        start = new ElementTag(TagManager.tag(perStart, context));
                    }
                    if (perIncrement != null) {
                        increment = new ElementTag(TagManager.tag(perIncrement, context));
                    }
                    if (perTitle != null) {
                        title = new ElementTag(TagManager.tag(perTitle, context));
                    }
                }
                if (value != null) {
                    try {
                        int index = start != null ? start.asInt() : value.size();
                        int incr = increment != null ? increment.asInt() : -1;
                        for (int i = 0; i < value.size(); i++, index += incr) {
                            int score = (scores != null && i < scores.size()) ? Integer.valueOf(scores.get(i)) : index;
                            current.add(new Sidebar.SidebarLine(value.get(i), score));
                        }
                    } catch (Exception e) {
                        Debug.echoError(e);
                        continue;
                    }
                    sidebar.setLines(current);
                }
                if (title != null) {
                    sidebar.setTitle(title.asString());
                }
                sidebar.sendUpdate();
            }
            break;
    }
}
Also used : PlayerTag(com.denizenscript.denizen.objects.PlayerTag) BukkitTagContext(com.denizenscript.denizen.tags.BukkitTagContext) TagContext(com.denizenscript.denizencore.tags.TagContext) ListTag(com.denizenscript.denizencore.objects.core.ListTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException) BukkitTagContext(com.denizenscript.denizen.tags.BukkitTagContext) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) Sidebar(com.denizenscript.denizen.nms.abstracts.Sidebar)

Aggregations

Sidebar (com.denizenscript.denizen.nms.abstracts.Sidebar)2 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)1 DisguiseCommand (com.denizenscript.denizen.scripts.commands.player.DisguiseCommand)1 BukkitTagContext (com.denizenscript.denizen.tags.BukkitTagContext)1 FakeBlock (com.denizenscript.denizen.utilities.blocks.FakeBlock)1 FakeEntity (com.denizenscript.denizen.utilities.entity.FakeEntity)1 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1 ListTag (com.denizenscript.denizencore.objects.core.ListTag)1 TagContext (com.denizenscript.denizencore.tags.TagContext)1 Advancement (org.bukkit.advancement.Advancement)1 AdvancementProgress (org.bukkit.advancement.AdvancementProgress)1 BossBar (org.bukkit.boss.BossBar)1 PluginCommand (org.bukkit.command.PluginCommand)1 RayTraceResult (org.bukkit.util.RayTraceResult)1