From dedfbacda6bd949ac6d5cc395bf73a2903e8dbb8 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 16 Dec 2018 19:16:05 +0100 Subject: [PATCH] NColor fix and only one TC/NC NColor fixed Only allowing one of a color combination Only allowing one of each nation color (except the default) --- .../chat/commands/ucmds/NColorCommand.java | 12 ++++---- .../ucmds/admin/NationColorCommand.java | 9 ++++++ .../ucmds/admin/TownColorCommand.java | 28 +++++++++++++++++++ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/NColorCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/NColorCommand.java index 9ac3cff..88403b1 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/NColorCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/NColorCommand.java @@ -58,16 +58,16 @@ public class NColorCommand extends UCommandBase { player.sendMessage("§cYour town doesn't have a color set. The town mayor can set it using /u towncolor."); return true; } - if (nameparts.length < towncolors.length) { - player.sendMessage("§cYou need more vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1) + ")"); + if (nameparts.length < towncolors.length + 1) { //+1: Nation color + player.sendMessage("§cYou need more vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1 + 1) + ")"); //Nation color return true; } - if (nameparts.length > towncolors.length * 2) { - player.sendMessage("§cYou have waay too many vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1) + ")"); + if (nameparts.length > (towncolors.length + 1) * 2) { + player.sendMessage("§cYou have waay too many vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1 + 1) + ")"); return true; } - if (nameparts.length > towncolors.length) { - player.sendMessage("§cYou have too many vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1) + ")"); + if (nameparts.length > towncolors.length + 1) { + player.sendMessage("§cYou have too many vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1 + 1) + ")"); return true; } ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class).NameColorLocations() diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/admin/NationColorCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/admin/NationColorCommand.java index 60564c5..ddc8e5b 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/admin/NationColorCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/admin/NationColorCommand.java @@ -2,6 +2,7 @@ package buttondevteam.chat.commands.ucmds.admin; import buttondevteam.chat.PluginMain; import buttondevteam.chat.listener.TownyListener; +import buttondevteam.lib.chat.Color; import com.palmergames.bukkit.towny.object.Nation; import com.palmergames.bukkit.towny.object.Town; import lombok.val; @@ -37,6 +38,14 @@ public class NationColorCommand extends AdminCommandBase { } val c = TownColorCommand.getColorOrSendError(args[1], sender); if (!c.isPresent()) return true; + if (!c.get().getName().equals(Color.White.getName())) { //Default nation color + for (val nc : PluginMain.NationColor.values()) { + if (nc.getName().equals(c.get().getName())) { + sender.sendMessage("§cAnother nation already uses this color!"); + return true; + } + } + } PluginMain.NationColor.put(args[0].toLowerCase(), c.get()); Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> { for (Town t : nation.getTowns()) diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/admin/TownColorCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/admin/TownColorCommand.java index e1cd357..97224ad 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/admin/TownColorCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/admin/TownColorCommand.java @@ -10,6 +10,7 @@ import org.bukkit.command.CommandSender; import org.dynmap.towny.DynmapTownyPlugin; import java.util.Arrays; +import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; @@ -46,6 +47,33 @@ public class TownColorCommand extends AdminCommandBase { return true; clrs[i - 1] = c.get(); } + for (Map.Entry other : PluginMain.TownColors.entrySet()) { + Color nc, tnc; + try { + nc = PluginMain.NationColor.get(PluginMain.TU.getTownsMap().get(other.getKey()).getNation().getName().toLowerCase()); + } catch (Exception e) { //Too lazy for lots of null-checks and it may throw exceptions anyways + nc = null; + } + if (nc == null) nc = Color.White; //Default nation color + try { + tnc = PluginMain.NationColor.get(targetTown.getNation().getName().toLowerCase()); + } catch (Exception e) { + tnc = null; + } + if (tnc == null) tnc = Color.White; //Default nation color - TODO: Make configurable + if (nc.getName().equals(tnc.getName())) { + int C = 0; + if (clrs.length == other.getValue().length) + for (int i = 0; i < clrs.length; i++) + if (clrs[i].getName().equals(other.getValue()[i].getName())) + C++; + else break; + if (C == clrs.length) { + sender.sendMessage("§cThis town color combination is already used!"); + return true; + } + } + } PluginMain.TownColors.put(args[0].toLowerCase(), clrs); TownyListener.updateTownMembers(targetTown);