From 787672486835add8f75e569db37a329451399561 Mon Sep 17 00:00:00 2001 From: Alex 'mcmonkey' Goodwin Date: Sat, 9 Oct 2021 06:28:14 -0700 Subject: [PATCH] bossbar viewer tags --- .../denizen/objects/PlayerTag.java | 20 ++++++++++++++++++- .../commands/server/BossBarCommand.java | 10 +++------- .../denizen/tags/core/ServerTagBase.java | 20 ++++++++++++++++++- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/PlayerTag.java b/plugin/src/main/java/com/denizenscript/denizen/objects/PlayerTag.java index d397ce79fd..2596d00c49 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/PlayerTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/PlayerTag.java @@ -5,6 +5,7 @@ import com.denizenscript.denizen.objects.properties.entity.EntityHealth; import com.denizenscript.denizen.scripts.commands.player.DisguiseCommand; import com.denizenscript.denizen.scripts.commands.player.SidebarCommand; +import com.denizenscript.denizen.scripts.commands.server.BossBarCommand; import com.denizenscript.denizen.utilities.AdvancedTextImpl; import com.denizenscript.denizen.utilities.FormattedTextHelper; import com.denizenscript.denizen.utilities.ScoreboardHelper; @@ -43,6 +44,7 @@ import org.bukkit.advancement.Advancement; import org.bukkit.advancement.AdvancementProgress; import org.bukkit.block.banner.PatternType; +import org.bukkit.boss.BossBar; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.FishHook; @@ -2353,13 +2355,29 @@ else if (foodLevel / maxHunger < 1) { // @description // Returns the ID of the scoreboard from <@link command scoreboard> that a player is currently viewing, if any. // --> - registerOnlineOnlyTag("scoreboard_id", (attribute, object) -> { + registerTag("scoreboard_id", (attribute, object) -> { String id = ScoreboardHelper.viewerMap.get(object.getUUID()); if (id == null) { return null; } return new ElementTag(id); }); + + // <--[tag] + // @attribute + // @returns ListTag + // @description + // Returns a list of all bossbars from <@link command bossbar> that this player can see. + // --> + registerOnlineOnlyTag("bossbar_ids", (attribute, object) -> { + ListTag result = new ListTag(); + for (Map.Entry bar : BossBarCommand.bossBarMap.entrySet()) { + if (bar.getValue().getPlayers().contains(object.getPlayerEntity())) { + result.addObject(new ElementTag(bar.getKey(), true)); + } + } + return result; + }); } public static ObjectTagProcessor tagProcessor = new ObjectTagProcessor<>(); diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/server/BossBarCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/server/BossBarCommand.java index 9be847ec35..d33bb0fda5 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/server/BossBarCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/server/BossBarCommand.java @@ -51,6 +51,8 @@ public BossBarCommand() { // // @Tags // + // ]> + // // // @Usage // Shows a message to all online players. @@ -157,13 +159,7 @@ public void execute(ScriptEntry scriptEntry) { ElementTag style = scriptEntry.getElement("style"); ListTag options = scriptEntry.getObjectTag("options"); if (scriptEntry.dbCallShouldDebug()) { - Debug.report(scriptEntry, getName(), id.debug() + action.debug() - + (players != null ? players.debug() : "") - + (title != null ? title.debug() : "") - + (progress != null ? progress.debug() : "") - + (color != null ? color.debug() : "") - + (style != null ? style.debug() : "") - + (options != null ? options.debug() : "")); + Debug.report(scriptEntry, getName(), id, action, players, title, progress, color, style, options); } String idString = CoreUtilities.toLowerCase(id.asString()); switch (Action.valueOf(action.asString().toUpperCase())) { diff --git a/plugin/src/main/java/com/denizenscript/denizen/tags/core/ServerTagBase.java b/plugin/src/main/java/com/denizenscript/denizen/tags/core/ServerTagBase.java index c166a91dfc..4a0f748351 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/tags/core/ServerTagBase.java +++ b/plugin/src/main/java/com/denizenscript/denizen/tags/core/ServerTagBase.java @@ -42,6 +42,7 @@ import org.bukkit.*; import org.bukkit.block.Biome; import org.bukkit.block.banner.PatternType; +import org.bukkit.boss.BossBar; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.EntityType; @@ -2072,13 +2073,30 @@ else if (attribute.startsWith("npc_is_valid") // @attribute // @returns ListTag // @description - // Returns a list of all currently active boss bar IDs. + // Returns a list of all currently active boss bar IDs from <@link command bossbar>. // --> else if (attribute.startsWith("current_bossbars")) { ListTag dl = new ListTag(BossBarCommand.bossBarMap.keySet()); event.setReplacedObject(dl.getObjectAttribute(attribute.fulfill(1))); } + // <--[tag] + // @attribute ]> + // @returns ListTag(PlayerTag) + // @description + // Returns a list of players that should be able to see the given bossbar ID from <@link command bossbar>. + // --> + else if (attribute.startsWith("bossbar_viewers") && attribute.hasContext(1)) { + BossBar bar = BossBarCommand.bossBarMap.get(CoreUtilities.toLowerCase(attribute.getContext(1))); + if (bar != null) { + ListTag list = new ListTag(); + for (Player player : bar.getPlayers()) { + list.addObject(new PlayerTag(player)); + } + event.setReplacedObject(list.getObjectAttribute(attribute.fulfill(1))); + } + } + // <--[tag] // @attribute // @returns ListTag