Skip to content

Commit

Permalink
fix/improve scoreboard command, 'scores' parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jul 9, 2019
1 parent e11a696 commit 95d2fe7
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 154 deletions.
Expand Up @@ -4,47 +4,54 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public abstract class Sidebar {

public static class SidebarLine {

public SidebarLine(String _text, int _score) {
text = _text;
score = _score;
}

public String text;

public int score;
}

public static final int MAX_LENGTH = 15;
protected final Player player;
protected String title;
protected String[] lines;
protected int[] scores;
protected int start;
protected int increment;
protected String[] lines = new String[MAX_LENGTH];
protected int[] scores = new int[MAX_LENGTH];
public int setCount = 0;

public Sidebar(Player player) {
this.player = player;
setTitle("");
this.lines = new String[15];
this.scores = new int[15];
this.start = Integer.MIN_VALUE;
this.increment = -1;
}

public String getTitle() {
return title;
}

public List<String> getLines() {
public List<SidebarLine> getLines() {
List<SidebarLine> toReturn = new ArrayList<>(MAX_LENGTH);
for (int i = 0; i < setCount; i++) {
toReturn.add(new SidebarLine(lines[i], scores[i]));
}
return toReturn;
}

public List<String> getLinesText() {
return new ArrayList<>(Arrays.asList(lines));
}

public int[] getScores() {
return scores;
}

public int getStart() {
return start;
}

public int getIncrement() {
return increment;
}

public final void setTitle(String title) {
if (title.length() > 32) {
title = title.substring(0, 32);
Expand All @@ -57,29 +64,19 @@ public final void setTitle(String title) {

protected abstract void setDisplayName(String title);

public void setStart(int start) {
this.start = start;
}

public void setIncrement(int increment) {
this.increment = increment;
}

public void setLines(List<String> lines) {
lines.removeAll(Collections.singleton((String) null));
this.lines = new String[15];
this.scores = new int[15];
int score = this.start;
if (score == Integer.MIN_VALUE) {
score = lines.size();
}
for (int i = 0; i < lines.size() && i < this.lines.length; i++, score += this.increment) {
String line = lines.get(i);
public void setLines(List<SidebarLine> lines) {
setCount = Math.min(lines.size(), MAX_LENGTH);
for (int i = 0; i < setCount; i++) {
String line = lines.get(i).text;
if (line.length() > 40) {
line = line.substring(0, 40);
}
this.lines[i] = line;
this.scores[i] = score;
this.scores[i] = lines.get(i).score;
}
for (int i = setCount; i < MAX_LENGTH; i++) {
this.lines[i] = null;
this.scores[i] = 0;
}
}

Expand Down

0 comments on commit 95d2fe7

Please sign in to comment.