From cb26c414bd615e7b4f7dce697f6d9b768bfdfbef Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 26 Feb 2019 15:48:12 +0100 Subject: [PATCH] Don't force-tie groups to colors; resolves #516 --- .../dungeonsxl/announcer/Announcer.java | 2 +- .../dungeonsxl/command/GroupCommand.java | 2 +- .../dungeonsxl/command/StatusCommand.java | 2 +- .../erethon/dungeonsxl/config/MainConfig.java | 45 +++++++++++-------- .../de/erethon/dungeonsxl/player/DGroup.java | 32 +++++++++---- .../de/erethon/dungeonsxl/util/DColor.java | 2 +- 6 files changed, 54 insertions(+), 31 deletions(-) diff --git a/src/main/java/de/erethon/dungeonsxl/announcer/Announcer.java b/src/main/java/de/erethon/dungeonsxl/announcer/Announcer.java index d636068a..4c2b520c 100644 --- a/src/main/java/de/erethon/dungeonsxl/announcer/Announcer.java +++ b/src/main/java/de/erethon/dungeonsxl/announcer/Announcer.java @@ -423,7 +423,7 @@ public class Announcer { boolean full = playerCount >= maxPlayersPerGroup; - DColor color = plugin.getMainConfig().getGroupColorPriority().get(groupCount); + DColor color = plugin.getMainConfig().getGroupColorPriority(groupCount); ItemStack button = color.getWoolMaterial().toItemStack(); ItemMeta meta = button.getItemMeta(); meta.setDisplayName(name + (full ? ChatColor.DARK_RED : ChatColor.GREEN) + " [" + playerCount + "/" + maxPlayersPerGroup + "]"); diff --git a/src/main/java/de/erethon/dungeonsxl/command/GroupCommand.java b/src/main/java/de/erethon/dungeonsxl/command/GroupCommand.java index 66d809b8..73e83038 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/GroupCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/GroupCommand.java @@ -254,7 +254,7 @@ public class GroupCommand extends DCommand { MessageUtil.sendCenteredMessage(sender, "&4&l[ &6" + dGroup.getName() + " &4&l]"); MessageUtil.sendMessage(sender, "&bCaptain: &e" + dGroup.getCaptain().getName()); - String players = new String(); + String players = ""; for (String player : dGroup.getPlayers().getNames()) { players += (players.isEmpty() ? "" : "&b, &e") + player; } diff --git a/src/main/java/de/erethon/dungeonsxl/command/StatusCommand.java b/src/main/java/de/erethon/dungeonsxl/command/StatusCommand.java index d851830d..59b5953d 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/StatusCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/StatusCommand.java @@ -52,7 +52,7 @@ public class StatusCommand extends DCommand { @Override public void onExecute(String[] args, CommandSender sender) { String minecraftVersion = compat.getVersion().toString(); - String bukkitVersion = Bukkit.getName() + (compat.isSpigot() ? " (Spigot)" : new String()) + " " + Bukkit.getBukkitVersion(); + String bukkitVersion = Bukkit.getName() + (compat.isSpigot() ? " (Spigot)" : "") + " " + Bukkit.getBukkitVersion(); String internalsVersion = compat.getInternals().toString(); String dungeonsxlVersion = plugin.getDescription().getVersion(); diff --git a/src/main/java/de/erethon/dungeonsxl/config/MainConfig.java b/src/main/java/de/erethon/dungeonsxl/config/MainConfig.java index dacbbf1e..809105f2 100644 --- a/src/main/java/de/erethon/dungeonsxl/config/MainConfig.java +++ b/src/main/java/de/erethon/dungeonsxl/config/MainConfig.java @@ -75,7 +75,6 @@ public class MainConfig extends DREConfig { LIGHT_GREEN, PURPLE, ORANGE, - WHITE, BLACK, LIGHT_BLUE, DARK_GREEN, @@ -83,7 +82,8 @@ public class MainConfig extends DREConfig { LIGHT_GRAY, CYAN, MAGENTA, - DARK_GRAY + DARK_GRAY, + PINK )); private double announcementInterval = 30; @@ -285,6 +285,14 @@ public class MainConfig extends DREConfig { return groupColorPriority; } + /** + * @param count the group count + * @return the group color for the count + */ + public DColor getGroupColorPriority(int count) { + return (count < groupColorPriority.size() && count >= 0) ? groupColorPriority.get(count) : DColor.WHITE; + } + /** * @param colors the colors to set */ @@ -583,24 +591,23 @@ public class MainConfig extends DREConfig { tutorialStartGroup = config.getString("tutorial.startgroup", tutorialStartGroup); tutorialEndGroup = config.getString("tutorial.endgroup", tutorialEndGroup); - if (config.contains("groupColorPriority")) { - if (config.getStringList("groupColorPriority").size() < 15) { - ArrayList strings = new ArrayList<>(); - for (DColor color : groupColorPriority) { - strings.add(color.toString()); - } - config.set("groupColorPriority", strings); - try { - config.save(file); - } catch (IOException exception) { - } + if (config.getStringList("groupColorPriority").size() < 14) { + ArrayList strings = new ArrayList<>(); + for (DColor color : groupColorPriority) { + strings.add(color.toString()); + } + config.set("groupColorPriority", strings); + try { + config.save(file); + } catch (IOException exception) { + } - } else { - groupColorPriority.clear(); - for (String color : config.getStringList("groupColorPriority")) { - if (EnumUtil.isValidEnum(DColor.class, color)) { - groupColorPriority.add(DColor.valueOf(color)); - } + } else { + groupColorPriority.clear(); + for (String color : config.getStringList("groupColorPriority")) { + DColor dColor = EnumUtil.getEnum(DColor.class, color); + if (dColor != null && dColor != DColor.WHITE) { + groupColorPriority.add(dColor); } } } diff --git a/src/main/java/de/erethon/dungeonsxl/player/DGroup.java b/src/main/java/de/erethon/dungeonsxl/player/DGroup.java index bdea47ed..f06645d7 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/DGroup.java +++ b/src/main/java/de/erethon/dungeonsxl/player/DGroup.java @@ -58,6 +58,9 @@ public class DGroup { DungeonsXL plugin; DPlayerCache dPlayers; + private static int counter; + + private int id; private String name; private Player captain; private PlayerCollection players = new PlayerCollection(); @@ -76,11 +79,11 @@ public class DGroup { private int lives = -1; public DGroup(DungeonsXL plugin, Player player) { - this(plugin, "Group " + plugin.getDGroupCache().size(), player); + this(plugin, "Group#" + counter, player); } public DGroup(DungeonsXL plugin, Player player, DColor color) { - this(plugin, color.toString().replace("_", " "), player); + this(plugin, color.toString() + "#" + counter, player); } public DGroup(DungeonsXL plugin, String name, Player player) { @@ -95,10 +98,12 @@ public class DGroup { playing = false; floorCount = 0; + + id = counter++; } public DGroup(DungeonsXL plugin, Player player, Dungeon dungeon) { - this(plugin, plugin.getMainConfig().getGroupColorPriority().get(plugin.getDGroupCache().size()).toString(), player, dungeon); + this(plugin, "Group#" + counter, player, dungeon); } public DGroup(DungeonsXL plugin, String name, Player player, Dungeon dungeon) { @@ -129,14 +134,23 @@ public class DGroup { setDungeon(dungeon); playing = false; floorCount = 0; + + id = counter++; } // Getters and setters + /** + * @return the group ID + */ + public int getId() { + return id; + } + /** * @return the name; formatted */ public String getName() { - return (color != null ? color.getChatColor().toString() : new String()) + name; + return getDColor().getChatColor() + name; } /** @@ -157,7 +171,7 @@ public class DGroup { * @param color the color to fetch the name from */ public void setName(DColor color) { - name = color.toString().replace("_", " "); + name = color.toString() + "#" + id; } /** @@ -520,7 +534,7 @@ public class DGroup { * @return if the group has been customized with a command */ public boolean isCustom() { - return !name.matches("Group_[0-9]{1,}"); + return !name.matches("Group#[0-9]{1,}"); } /** @@ -544,7 +558,7 @@ public class DGroup { if (color != null) { return color; } else { - return DColor.DEFAULT; + return DColor.WHITE; } } @@ -766,7 +780,9 @@ public class DGroup { GameRuleProvider rules = game.getRules(); gameWorld.setWeather(rules); - color = plugin.getMainConfig().getGroupColorPriority().get(game.getDGroups().indexOf(this)); + if (color == null) { + color = plugin.getMainConfig().getGroupColorPriority((game.getDGroups().indexOf(this))); + } for (DGroup dGroup : game.getDGroups()) { if (dGroup == null) { diff --git a/src/main/java/de/erethon/dungeonsxl/util/DColor.java b/src/main/java/de/erethon/dungeonsxl/util/DColor.java index c454b60b..09ddfb45 100644 --- a/src/main/java/de/erethon/dungeonsxl/util/DColor.java +++ b/src/main/java/de/erethon/dungeonsxl/util/DColor.java @@ -43,7 +43,7 @@ public enum DColor { LIGHT_RED(ChatColor.RED, DyeColor.RED, VanillaItem.RED_WOOL), ORANGE(ChatColor.GOLD, DyeColor.ORANGE, VanillaItem.ORANGE_WOOL), YELLOW(ChatColor.YELLOW, DyeColor.YELLOW, VanillaItem.YELLOW_WOOL), - DEFAULT(ChatColor.BLUE, DyeColor.PINK, VanillaItem.PINK_WOOL); + PINK(ChatColor.BLUE, DyeColor.PINK, VanillaItem.PINK_WOOL); private ChatColor chat; private DyeColor dye;