Fix faulty scoreboard logic
This commit is contained in:
parent
87eaeabd7f
commit
4641ed828b
@ -53,6 +53,8 @@ public class MineplexScoreboard
|
||||
|
||||
// The list of available trackers, implemented as a queue
|
||||
private final LinkedList<String> _availableTrackers = new LinkedList<>();
|
||||
// The set of custom trackers
|
||||
private final Set<String> _customTrackers = new HashSet<>();
|
||||
|
||||
// The list of registered lines, which have been calculated, in the order of registration
|
||||
// The ScoreboardLine at index 0 is the one at the top of the scoreboard
|
||||
@ -257,4 +259,9 @@ public class MineplexScoreboard
|
||||
{
|
||||
this._availableTrackers.add(tracker);
|
||||
}
|
||||
|
||||
Set<String> getCustomTrackers()
|
||||
{
|
||||
return _customTrackers;
|
||||
}
|
||||
}
|
||||
|
@ -5,14 +5,31 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
// fixme bulk send prefix/suffix packets?
|
||||
public class ScoreboardElement
|
||||
{
|
||||
private static final Set<String> CUSTOM_TRACKER_TRACKER = new HashSet<>();
|
||||
private static final Pattern COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf('§') + "[0-9A-F]");
|
||||
private static final char[] CHARS = "1234567890abcdefklmnor".toCharArray();
|
||||
|
||||
private static final List<String> HAS_COLOR_TRACKERS = new ArrayList<>();
|
||||
|
||||
static
|
||||
{
|
||||
for (char c : CHARS)
|
||||
{
|
||||
HAS_COLOR_TRACKERS.add("§" + String.valueOf(c));
|
||||
}
|
||||
}
|
||||
|
||||
private static final AtomicInteger COUNTER = new AtomicInteger();
|
||||
|
||||
@ -27,6 +44,8 @@ public class ScoreboardElement
|
||||
|
||||
private String _customTracker;
|
||||
|
||||
private Set<String> _customTrackerTracker;
|
||||
|
||||
private String _oldValue;
|
||||
|
||||
private int _lineNumber;
|
||||
@ -37,6 +56,7 @@ public class ScoreboardElement
|
||||
this._sidebar = sidebar;
|
||||
this._line = line;
|
||||
this._tracker = tracker;
|
||||
this._customTrackerTracker = scoreboard.getCustomTrackers();
|
||||
this._team = scoreboard.getHandle().registerNewTeam("SBE" + String.valueOf(COUNTER.getAndIncrement()));
|
||||
this._team.addEntry(this._tracker);
|
||||
this._lineNumber = lineNumber;
|
||||
@ -54,6 +74,7 @@ public class ScoreboardElement
|
||||
|
||||
this._oldValue = value;
|
||||
|
||||
// If everything can be fit in the prefix, go ahead and do that
|
||||
if (value.length() <= 16)
|
||||
{
|
||||
if (!StringUtils.equals(this._team.getPrefix(), value))
|
||||
@ -69,6 +90,7 @@ public class ScoreboardElement
|
||||
String right = value.substring(16);
|
||||
String ending = ChatColor.getLastColors(left);
|
||||
right = ending + right;
|
||||
// If everything can be fit in the prefix and suffix (don't forget about color codes!), do that
|
||||
if (right.length() <= 16)
|
||||
{
|
||||
if (!StringUtils.equals(this._team.getPrefix(), left))
|
||||
@ -80,48 +102,47 @@ public class ScoreboardElement
|
||||
}
|
||||
else
|
||||
{
|
||||
right = value.substring(16);
|
||||
|
||||
// ensure unique custom trackers
|
||||
if (right.length() <= 40)
|
||||
String temp = value.substring(16);
|
||||
temp = ending + temp;
|
||||
Matcher matcher = COLOR_PATTERN.matcher(ending);
|
||||
boolean hasColors = matcher.find();
|
||||
if (!hasColors)
|
||||
{
|
||||
if (_customTracker == null || !_customTracker.equals(right))
|
||||
{
|
||||
if (!CUSTOM_TRACKER_TRACKER.add(right))
|
||||
{
|
||||
String resets = ChatColor.RESET.toString();
|
||||
while (!CUSTOM_TRACKER_TRACKER.add(resets + ending + right))
|
||||
{
|
||||
resets += ChatColor.RESET.toString();
|
||||
}
|
||||
temp = ChatColor.WHITE + temp;
|
||||
}
|
||||
|
||||
right = resets + ending + right;
|
||||
}
|
||||
String tracker = null;
|
||||
int index = 0;
|
||||
|
||||
// Determine the most suitable tracker. The scoreboard only has 15 lines so we should never need to append more than 2 characters
|
||||
while (tracker == null)
|
||||
{
|
||||
String temp1 = HAS_COLOR_TRACKERS.get(index++) + temp;
|
||||
String substr = temp1.length() <= 40 ? temp1 : temp1.substring(0, 40);
|
||||
if (substr.equals(_customTracker) || _customTrackerTracker.add(substr))
|
||||
{
|
||||
tracker = substr;
|
||||
temp = temp1;
|
||||
}
|
||||
}
|
||||
|
||||
if (right.length() <= 40)
|
||||
if (_customTracker == null || !_customTracker.equals(tracker))
|
||||
{
|
||||
clearCustomTracker();
|
||||
}
|
||||
|
||||
// If everything can be fit in the tracker, do that
|
||||
if (temp.length() <= 40)
|
||||
{
|
||||
if (this._customTracker == null)
|
||||
{
|
||||
this._customTracker = right;
|
||||
this._customTracker = temp;
|
||||
|
||||
this._scoreboard.getHandle().resetScores(this._tracker);
|
||||
|
||||
this._team.addEntry(this._customTracker);
|
||||
this._sidebar.getScore(this._customTracker).setScore(this._lineNumber);
|
||||
}
|
||||
else if (!right.equals(this._customTracker))
|
||||
{
|
||||
this._scoreboard.getHandle().resetScores(this._customTracker);
|
||||
this._team.removeEntry(this._customTracker);
|
||||
CUSTOM_TRACKER_TRACKER.remove(this._customTracker);
|
||||
|
||||
this._customTracker = right;
|
||||
|
||||
this._team.addEntry(this._customTracker);
|
||||
this._sidebar.getScore(this._customTracker).setScore(this._lineNumber);
|
||||
}
|
||||
|
||||
if (!StringUtils.equals(this._team.getPrefix(), left))
|
||||
this._team.setPrefix(left);
|
||||
@ -130,64 +151,30 @@ public class ScoreboardElement
|
||||
}
|
||||
else
|
||||
{
|
||||
CUSTOM_TRACKER_TRACKER.remove(right);
|
||||
// Otherwise try to use the prefix
|
||||
right = temp.substring(40);
|
||||
|
||||
String middle = right.substring(0, 40);
|
||||
right = right.substring(40);
|
||||
|
||||
if (_customTracker == null || !_customTracker.equals(middle))
|
||||
// It's too long for even the suffix. Trim and move on
|
||||
if (right.length() > 16)
|
||||
{
|
||||
if (!CUSTOM_TRACKER_TRACKER.add(middle))
|
||||
{
|
||||
String resets = ChatColor.RESET.toString();
|
||||
while (!CUSTOM_TRACKER_TRACKER.add(resets + ending + middle))
|
||||
{
|
||||
resets += ChatColor.RESET.toString();
|
||||
}
|
||||
|
||||
middle = resets + ending + middle;
|
||||
|
||||
if (middle.length() > 40)
|
||||
{
|
||||
right = right + middle.substring(40);
|
||||
middle = middle.substring(0, 40);
|
||||
}
|
||||
}
|
||||
right = right.substring(0, 16);
|
||||
System.out.println("WARNING: Trimmed suffix from '" + temp.substring(40) + "' to '" + right + "'");
|
||||
}
|
||||
|
||||
if (right.length() <= 16)
|
||||
if (this._customTracker == null)
|
||||
{
|
||||
if (this._customTracker == null)
|
||||
{
|
||||
this._customTracker = middle;
|
||||
this._customTracker = tracker;
|
||||
|
||||
this._scoreboard.getHandle().resetScores(this._tracker);
|
||||
this._scoreboard.getHandle().resetScores(this._tracker);
|
||||
|
||||
this._team.addEntry(this._customTracker);
|
||||
this._sidebar.getScore(this._customTracker).setScore(this._lineNumber);
|
||||
|
||||
}
|
||||
else if (!middle.equals(this._customTracker))
|
||||
{
|
||||
this._scoreboard.getHandle().resetScores(this._customTracker);
|
||||
this._team.removeEntry(this._customTracker);
|
||||
CUSTOM_TRACKER_TRACKER.remove(this._customTracker);
|
||||
|
||||
this._customTracker = middle;
|
||||
|
||||
this._team.addEntry(this._customTracker);
|
||||
this._sidebar.getScore(this._customTracker).setScore(this._lineNumber);
|
||||
}
|
||||
|
||||
if (!StringUtils.equals(this._team.getPrefix(), left))
|
||||
this._team.setPrefix(left);
|
||||
if (!StringUtils.equals(this._team.getSuffix(), right))
|
||||
this._team.setSuffix(right);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("The following scoreboard line is too damn long: " + value);
|
||||
this._team.addEntry(this._customTracker);
|
||||
this._sidebar.getScore(this._customTracker).setScore(this._lineNumber);
|
||||
}
|
||||
|
||||
if (!StringUtils.equals(this._team.getPrefix(), left))
|
||||
this._team.setPrefix(left);
|
||||
if (!StringUtils.equals(this._team.getSuffix(), right))
|
||||
this._team.setSuffix(right);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -218,7 +205,7 @@ public class ScoreboardElement
|
||||
if (this._customTracker != null)
|
||||
{
|
||||
this._scoreboard.getHandle().resetScores(this._customTracker);
|
||||
CUSTOM_TRACKER_TRACKER.remove(this._customTracker);
|
||||
_customTrackerTracker.remove(this._customTracker);
|
||||
}
|
||||
this._scoreboard.returnTracker(this._tracker);
|
||||
this._team = null;
|
||||
@ -232,7 +219,7 @@ public class ScoreboardElement
|
||||
{
|
||||
this._scoreboard.getHandle().resetScores(this._customTracker);
|
||||
this._team.removeEntry(this._customTracker);
|
||||
CUSTOM_TRACKER_TRACKER.remove(this._customTracker);
|
||||
_customTrackerTracker.remove(this._customTracker);
|
||||
this._customTracker = null;
|
||||
|
||||
this._team.addEntry(this._tracker);
|
||||
|
@ -1259,28 +1259,31 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
||||
|
||||
System.out.println("Searching Maps in: " + folder);
|
||||
|
||||
for (File file : folder.listFiles())
|
||||
if (folder.listFiles() != null)
|
||||
{
|
||||
if (!file.isFile())
|
||||
for (File file : folder.listFiles())
|
||||
{
|
||||
System.out.println(file.getName() + " is not a file!");
|
||||
continue;
|
||||
if (!file.isFile())
|
||||
{
|
||||
System.out.println(file.getName() + " is not a file!");
|
||||
continue;
|
||||
}
|
||||
|
||||
String name = file.getName();
|
||||
|
||||
if (name.length() < 5)
|
||||
continue;
|
||||
|
||||
name = name.substring(name.length() - 4, name.length());
|
||||
|
||||
if (!name.equals(".zip"))
|
||||
{
|
||||
System.out.println(file.getName() + " is not a zip.");
|
||||
continue;
|
||||
}
|
||||
|
||||
maps.add(file.getName().substring(0, file.getName().length() - 4));
|
||||
}
|
||||
|
||||
String name = file.getName();
|
||||
|
||||
if (name.length() < 5)
|
||||
continue;
|
||||
|
||||
name = name.substring(name.length() - 4, name.length());
|
||||
|
||||
if (!name.equals(".zip"))
|
||||
{
|
||||
System.out.println(file.getName() + " is not a zip.");
|
||||
continue;
|
||||
}
|
||||
|
||||
maps.add(file.getName().substring(0, file.getName().length() - 4));
|
||||
}
|
||||
|
||||
for (String map : maps)
|
||||
|
Loading…
Reference in New Issue
Block a user