Skip to content

Commit

Permalink
bossbar viewer tags
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 9, 2021
1 parent 2a33586 commit 7876724
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 <PlayerTag.bossbar_ids>
// @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<String, BossBar> bar : BossBarCommand.bossBarMap.entrySet()) {
if (bar.getValue().getPlayers().contains(object.getPlayerEntity())) {
result.addObject(new ElementTag(bar.getKey(), true));
}
}
return result;
});
}

public static ObjectTagProcessor<PlayerTag> tagProcessor = new ObjectTagProcessor<>();
Expand Down
Expand Up @@ -51,6 +51,8 @@ public BossBarCommand() {
//
// @Tags
// <server.current_bossbars>
// <server.bossbar_viewers[<bossbar_id>]>
// <PlayerTag.bossbar_ids>
//
// @Usage
// Shows a message to all online players.
Expand Down Expand Up @@ -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())) {
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -2072,13 +2073,30 @@ else if (attribute.startsWith("npc_is_valid")
// @attribute <server.current_bossbars>
// @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 <server.bossbar_viewers[<bossbar_id>]>
// @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 <server.recent_tps>
// @returns ListTag
Expand Down

0 comments on commit 7876724

Please sign in to comment.