region: re-implement default colors based on names

This commit is contained in:
Torrie Fischer 2021-06-11 09:34:02 -07:00
parent c40eb3b92c
commit b04ac9e5a4
2 changed files with 40 additions and 10 deletions

View File

@ -42,15 +42,13 @@ public class Region {
private Location m_location; private Location m_location;
private String m_name; private String m_name;
private List<Pattern> m_bannerPatterns = new ArrayList<Pattern>(); private List<Pattern> m_bannerPatterns = new ArrayList<Pattern>();
private DyeColor m_color = null; private DyeColor m_color = DyeColor.values()[(int)(System.currentTimeMillis() % DyeColor.values().length)];
private List<UUID> m_seenPlayers = new ArrayList<UUID>(); private List<UUID> m_seenPlayers = new ArrayList<UUID>();
private boolean m_isHub = false; private boolean m_isHub = false;
public Region(String name, Location location) { public Region(String name, Location location) {
m_location = location.toBlockLocation(); m_location = location.toBlockLocation();
m_name = name; m_name = name;
// Pick a random color
m_color = DyeColor.values()[(int)(System.currentTimeMillis() % DyeColor.values().length)];
} }
public Region(String name, Location location, int visits, int charges, DyeColor color) { public Region(String name, Location location, int visits, int charges, DyeColor color) {
@ -61,6 +59,31 @@ public class Region {
m_color = color; m_color = color;
} }
private static DyeColor[] defaultColors = {
DyeColor.LIGHT_BLUE,
DyeColor.BLACK,
DyeColor.BLUE,
DyeColor.CYAN,
DyeColor.BLUE,
DyeColor.GRAY,
DyeColor.GREEN,
DyeColor.PURPLE,
DyeColor.RED,
DyeColor.ORANGE,
DyeColor.GRAY,
DyeColor.GREEN,
DyeColor.MAGENTA,
DyeColor.RED,
DyeColor.WHITE,
DyeColor.YELLOW,
};
private DyeColor defaultColorForName(String name) {
int colorCount = defaultColors.length;
int hashed = Math.abs(name.hashCode());
return defaultColors[hashed % (colorCount - 1)];
}
public Region(String name, World world, RegionConfiguration conf) { public Region(String name, World world, RegionConfiguration conf) {
if (conf.y == -1) { if (conf.y == -1) {
Location defaultLoc = new Location(world, conf.x, 64, conf.z); Location defaultLoc = new Location(world, conf.x, 64, conf.z);
@ -71,7 +94,11 @@ public class Region {
m_charges = conf.charges; m_charges = conf.charges;
m_location = new Location(world, conf.x, conf.y, conf.z); m_location = new Location(world, conf.x, conf.y, conf.z);
m_bannerPatterns = conf.patterns; m_bannerPatterns = conf.patterns;
if (conf.color == null) {
m_color = defaultColorForName(name);
} else {
m_color = conf.color; m_color = conf.color;
}
m_seenPlayers = conf.seenBy; m_seenPlayers = conf.seenBy;
m_isHub = conf.isHub; m_isHub = conf.isHub;
} }

View File

@ -24,7 +24,7 @@ public class RegionConfiguration implements ConfigurationSerializable {
public boolean isHub; public boolean isHub;
public List<Pattern> patterns; public List<Pattern> patterns;
public List<UUID> seenBy; public List<UUID> seenBy;
public DyeColor color = DyeColor.YELLOW; public DyeColor color = null;
public RegionConfiguration(Region region) { public RegionConfiguration(Region region) {
Location loc = region.location(); Location loc = region.location();
@ -47,7 +47,10 @@ public class RegionConfiguration implements ConfigurationSerializable {
visits = (Integer)confSection.getOrDefault("visits", 0); visits = (Integer)confSection.getOrDefault("visits", 0);
charges = (Integer)confSection.getOrDefault("charges", 0); charges = (Integer)confSection.getOrDefault("charges", 0);
patterns = (List<Pattern>)confSection.getOrDefault("banner", new ArrayList<Pattern>()); patterns = (List<Pattern>)confSection.getOrDefault("banner", new ArrayList<Pattern>());
color = DyeColor.valueOf((String)confSection.getOrDefault("color", "YELLOW")); String colorStr = (String)confSection.getOrDefault("color", null);
if (colorStr != null) {
color = DyeColor.valueOf(colorStr);
}
seenBy = new ArrayList<UUID>(); seenBy = new ArrayList<UUID>();
List<String> strList = (List<String>)confSection.getOrDefault("seenBy", new ArrayList<String>()); List<String> strList = (List<String>)confSection.getOrDefault("seenBy", new ArrayList<String>());
for(String s : strList) { for(String s : strList) {