Skip to content

Commit

Permalink
add sidebar set_line option
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 4, 2019
1 parent fac2dcf commit b1512e8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
Expand Up @@ -183,7 +183,7 @@ public void registerCommands() {
registerCoreMember(ScribeCommand.class, "SCRIBE", "scribe [<script>] (<item>/give/equip/{drop <location>})", 1);
registerCoreMember(ShootCommand.class, "SHOOT", "shoot [<entity>|...] (origin:<entity>/<location>) (destination:<location>) (height:<#.#>) (speed:<#.#>) (script:<name>) (def:<element>|...) (shooter:<entity>) (spread:<#.#>) (lead:<location>) (no_rotate)", 1);
registerCoreMember(ShowFakeCommand.class, "SHOWFAKE", "showfake [<material>|.../cancel] [<location>|...] (players:<player>|...) (d:<duration>{10s})", 2);
registerCoreMember(SidebarCommand.class, "SIDEBAR", "sidebar (add/remove/{set}) (title:<title>) (lines:<#>|...) (values:<line>|...) (start:<#>/{num_of_lines}) (increment:<#>/{-1}) (players:<player>|...) (per_player)", 1);
registerCoreMember(SidebarCommand.class, "SIDEBAR", "sidebar (add/remove/{set}/set_line) (title:<title>) (scores:<#>|...) (values:<line>|...) (start:<#>/{num_of_lines}) (increment:<#>/{-1}) (players:<player>|...) (per_player)", 1);
registerCoreMember(SignCommand.class, "SIGN", "sign (type:{automatic}/sign_post/wall_sign) [\"<line>|...\"] [<location>] (direction:n/s/e/w)", 1);
registerCoreMember(SitCommand.class, "SIT", "sit (<location>)", 0);
registerCoreMember(SpawnCommand.class, "SPAWN", "spawn [<entity>|...] (<location>) (target:<entity>) (persistent)", 1);
Expand Down
Expand Up @@ -29,7 +29,7 @@ public class SidebarCommand extends AbstractCommand {

// <--[command]
// @Name Sidebar
// @Syntax sidebar (add/remove/{set}) (title:<title>) (scores:<#>|...) (values:<line>|...) (start:<#>/{num_of_lines}) (increment:<#>/{-1}) (players:<player>|...) (per_player)
// @Syntax sidebar (add/remove/{set}/set_line) (title:<title>) (scores:<#>|...) (values:<line>|...) (start:<#>/{num_of_lines}) (increment:<#>/{-1}) (players:<player>|...) (per_player)
// @Required 1
// @Short Controls clientside-only sidebars.
// @Group player
Expand Down Expand Up @@ -91,7 +91,7 @@ public class SidebarCommand extends AbstractCommand {

// TODO: Clean me!

private enum Action {ADD, REMOVE, SET}
private enum Action {ADD, REMOVE, SET, SET_LINE}

@Override
public void onEnable() {
Expand Down Expand Up @@ -347,6 +347,60 @@ public void execute(ScriptEntry scriptEntry) {
}
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.size() == 0) {
Debug.echoError("Missing or invalid 'scores' parameter.");
return;
}
if (value == null || value.size() != scores.size()) {
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),
false, scriptEntry, scriptEntry.shouldDebug(), scriptEntry.getScript());
if (perValue != null) {
value = ListTag.valueOf(TagManager.tag(perValue, context));
}
if (perScores != null) {
scores = ListTag.valueOf(TagManager.tag(perScores, context));
}
}
try {
for (int i = 0; i < value.size(); i++) {
int score = ArgumentHelper.getIntegerFrom(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()) {
Expand Down

0 comments on commit b1512e8

Please sign in to comment.