Skip to content

Commit

Permalink
scoreboard team tags
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 24, 2023
1 parent af1b177 commit 5f09335
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ public void setTeamSuffix(Team team, String suffix) {
team.suffix(PaperModule.parseFormattedText(suffix, ChatColor.WHITE));
}

@Override
public String getTeamPrefix(Team team) {
return PaperModule.stringifyComponent(team.prefix());
}

@Override
public String getTeamSuffix(Team team) {
return PaperModule.stringifyComponent(team.suffix());
}

@Override
public String convertTextToMiniMessage(String text) {
Component parsed = PaperModule.jsonToComponent(FormattedTextHelper.componentToJson(FormattedTextHelper.parse(text, ChatColor.WHITE, false)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.*;
import org.bukkit.map.MapView;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import org.bukkit.util.RayTraceResult;

import java.util.*;
Expand Down Expand Up @@ -2492,6 +2494,22 @@ else if (foodLevel / maxHunger < 1) {
return new ElementTag(id);
});

// <--[tag]
// @attribute <PlayerTag.scoreboard_team_name[(<board>)]>
// @returns ElementTag
// @description
// Returns the name of the team the player is in for a given scoreboard, if any.
// If no scoreboard is specified, uses the default (main) board.
// -->
tagProcessor.registerTag(ElementTag.class, "scoreboard_team_name", (attribute, object) -> {
Scoreboard board = attribute.hasParam() ? ScoreboardHelper.getScoreboard(attribute.getParam()) : ScoreboardHelper.getMain();
Team team = board.getEntryTeam(object.getName());
if (team == null) {
return null;
}
return new ElementTag(team.getName());
});

// <--[tag]
// @attribute <PlayerTag.bossbar_ids>
// @returns ListTag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,28 @@ else if (value.startsWith("e@")) {
if (attribute.startsWith("members")) {
event.setReplacedObject(new ListTag(team.getEntries()).getObjectAttribute(attribute.fulfill(1)));
}

// <--[tag]
// @attribute <server.scoreboard[(<board>)].team[<team>].prefix>
// @returns ElementTag
// @description
// Returns the team's prefix.
// Optionally, specify which scoreboard to use.
// -->
if (attribute.startsWith("prefix")) {
event.setReplacedObject(new ElementTag(PaperAPITools.instance.getTeamPrefix(team)).getObjectAttribute(attribute.fulfill(1)));
}

// <--[tag]
// @attribute <server.scoreboard[(<board>)].team[<team>].suffix>
// @returns ElementTag
// @description
// Returns the team's suffix.
// Optionally, specify which scoreboard to use.
// -->
if (attribute.startsWith("suffix")) {
event.setReplacedObject(new ElementTag(PaperAPITools.instance.getTeamSuffix(team)).getObjectAttribute(attribute.fulfill(1)));
}
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ public void setTeamSuffix(Team team, String suffix) {
team.setSuffix(suffix);
}

public String getTeamPrefix(Team team) {
return team.getPrefix();
}

public String getTeamSuffix(Team team) {
return team.getSuffix();
}

public String convertTextToMiniMessage(String text) {
return text;
}
Expand Down

0 comments on commit 5f09335

Please sign in to comment.