Fixes (/u ncolor), not allowing two of the same town colors, not broadcasting announcements if nobody is online #93

Merged
NorbiPeti merged 10 commits from dev into master 2019-01-03 20:43:22 +00:00
3 changed files with 43 additions and 6 deletions
Showing only changes of commit dedfbacda6 - Show all commits

View file

@ -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()

View file

@ -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())

View file

@ -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<String, Color[]> 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);