Skip to content

Commit

Permalink
add scoreboard tags, fixes #1905
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 6, 2019
1 parent bd25ac0 commit 7563b2a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
Expand Up @@ -3329,7 +3329,8 @@ public void registerCoreMembers() {
// arguments, you will only remove those viewers from the scoreboard, not the entire scoreboard.
//
// @Tags
// None
// <server.scoreboard[(<board>)].exists>
// <server.scoreboard[(<board>)].team_members[<team>]>
//
// @Usage
// Add a score for the player "mythan" to the default scoreboard under the objective "cookies" and let him see it
Expand Down Expand Up @@ -3849,7 +3850,7 @@ public void registerCoreMembers() {
// NOTE: Prefixes and suffixes cannot be longer than 16 characters!
//
// @Tags
// None
// <server.scoreboard[(<board>)].team_members[<team>]>
//
// @Usage
// Use to add a player to a team.
Expand Down
Expand Up @@ -16,6 +16,7 @@
import net.aufdemrand.denizen.scripts.containers.core.AssignmentScriptContainer;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.ScoreboardHelper;
import net.aufdemrand.denizen.utilities.Utilities;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.depends.Depends;
Expand All @@ -39,6 +40,7 @@
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.scoreboard.Scoreboard;

import java.io.File;
import java.sql.Connection;
Expand Down Expand Up @@ -162,6 +164,46 @@ public void serverTag(ReplaceableTagEvent event) {
return;
}

if (attribute.startsWith("scoreboard")) {
Scoreboard board;
String name = "main";
if (attribute.hasContext(1)) {
name = attribute.getContext(1);
board = ScoreboardHelper.getScoreboard(name);
}
else {
board = ScoreboardHelper.getMain();
}
// <--[tag]
// @attribute <server.scoreboard[<board>].exists>
// @returns dList
// @description
// Returns whether a given scoreboard exists on the server.
// -->
if (attribute.startsWith("exists")) {
event.setReplaced(new Element(board != null).getAttribute(attribute.fulfill(2)));
return;
}
if (board == null) {
if (!attribute.hasAlternative()) {
dB.echoError("Scoreboard '" + name + "' does not exist.");
}
return;
}
// <--[tag]
// @attribute <server.scoreboard[(<board>)].team_members[<team>]>
// @returns dList
// @description
// Returns a list of all members of a scoreboard team. Generally returns as a list of names or text entries.
// Members are not necessarily written in any given format and are not guaranteed to validly fit any requirements.
// Optionally, specify which scoreboard to use.
// -->
if (attribute.startsWith("team_members") && attribute.hasContext(2)) {
event.setReplacedObject(new dList(board.getEntries()).getObjectAttribute(attribute.fulfill(2)));
return;
}
}

// <--[tag]
// @attribute <server.object_is_valid[<object>]>
// @returns Element(boolean)
Expand Down

0 comments on commit 7563b2a

Please sign in to comment.