Fixes (/u ncolor), not allowing two of the same town colors, not broadcasting announcements if nobody is online #93
3 changed files with 43 additions and 6 deletions
|
@ -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.");
|
player.sendMessage("§cYour town doesn't have a color set. The town mayor can set it using /u towncolor.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (nameparts.length < towncolors.length) {
|
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) + ")");
|
player.sendMessage("§cYou need more vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1 + 1) + ")"); //Nation color
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (nameparts.length > towncolors.length * 2) {
|
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) + ")");
|
player.sendMessage("§cYou have waay too many vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1 + 1) + ")");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (nameparts.length > towncolors.length) {
|
if (nameparts.length > towncolors.length + 1) {
|
||||||
player.sendMessage("§cYou have too many vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1) + ")");
|
player.sendMessage("§cYou have too many vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1 + 1) + ")");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class).NameColorLocations()
|
ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class).NameColorLocations()
|
||||||
|
|
|
@ -2,6 +2,7 @@ package buttondevteam.chat.commands.ucmds.admin;
|
||||||
|
|
||||||
import buttondevteam.chat.PluginMain;
|
import buttondevteam.chat.PluginMain;
|
||||||
import buttondevteam.chat.listener.TownyListener;
|
import buttondevteam.chat.listener.TownyListener;
|
||||||
|
import buttondevteam.lib.chat.Color;
|
||||||
import com.palmergames.bukkit.towny.object.Nation;
|
import com.palmergames.bukkit.towny.object.Nation;
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
|
@ -37,6 +38,14 @@ public class NationColorCommand extends AdminCommandBase {
|
||||||
}
|
}
|
||||||
val c = TownColorCommand.getColorOrSendError(args[1], sender);
|
val c = TownColorCommand.getColorOrSendError(args[1], sender);
|
||||||
if (!c.isPresent()) return true;
|
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());
|
PluginMain.NationColor.put(args[0].toLowerCase(), c.get());
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
|
||||||
for (Town t : nation.getTowns())
|
for (Town t : nation.getTowns())
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.bukkit.command.CommandSender;
|
||||||
import org.dynmap.towny.DynmapTownyPlugin;
|
import org.dynmap.towny.DynmapTownyPlugin;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -46,6 +47,33 @@ public class TownColorCommand extends AdminCommandBase {
|
||||||
return true;
|
return true;
|
||||||
clrs[i - 1] = c.get();
|
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);
|
PluginMain.TownColors.put(args[0].toLowerCase(), clrs);
|
||||||
TownyListener.updateTownMembers(targetTown);
|
TownyListener.updateTownMembers(targetTown);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue