Town color error fix, applying changes

This commit is contained in:
Norbi Peti 2019-02-12 22:28:42 +01:00
parent e2a6afd16a
commit df7f8bca5e
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
4 changed files with 20 additions and 10 deletions

View file

@ -52,7 +52,8 @@ public class ChatProcessing {
private static final Pattern SPOILER_PATTERN = Pattern.compile("\\|\\|");
private static final Color[] RainbowPresserColors = new Color[]{Color.Red, Color.Gold, Color.Yellow, Color.Green,
Color.Blue, Color.DarkPurple};
private static boolean pingedconsole = false;
private static final Pattern WORD_PATTERN = Pattern.compile("\\S+");
private static boolean pingedconsole = false;
public static final ChatFormatter ESCAPE_FORMATTER = ChatFormatter.builder().regex(ESCAPE_PATTERN).build();
@ -134,7 +135,7 @@ public class ChatProcessing {
ArrayList<ChatFormatter> formatters = addFormatters(colormode);
if (colormode == channel.Color().get() && mp != null && mp.RainbowPresserColorMode) { // Only overwrite channel color
final AtomicInteger rpc = new AtomicInteger(0);
formatters.add(ChatFormatter.builder().color(colormode).onmatch((match, cf, s) -> {
formatters.add(ChatFormatter.builder().regex(WORD_PATTERN).color(colormode).onmatch((match, cf, s) -> {
cf.setColor(RainbowPresserColors[rpc.getAndUpdate(i -> ++i < RainbowPresserColors.length ? i : 0)]);
return match;
}).build());

View file

@ -3,8 +3,9 @@ package buttondevteam.chat.components.fun;
import buttondevteam.core.component.restart.ScheduledRestartCommand;
import buttondevteam.lib.ScheduledServerRestartEvent;
import buttondevteam.lib.ThorpeUtils;
import buttondevteam.lib.chat.Command2MC;
import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.ICommand2MC;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.event.EventHandler;
@ -13,12 +14,12 @@ import org.bukkit.event.Listener;
import java.util.HashSet;
@CommandClass
public class PressCommand extends Command2MC implements Listener {
public class PressCommand extends ICommand2MC implements Listener {
private HashSet<CommandSender> pressers; //Will be cleared with this class on shutdown/disable
private ScheduledRestartCommand command;
private int startTicks;
@Subcommand
@Command2.Subcommand
public void def(CommandSender sender) {
if (command == null) {
sender.sendMessage("§cThe timer isn't ticking... yet.");

View file

@ -12,6 +12,7 @@ import buttondevteam.lib.architecture.ConfigData;
import buttondevteam.lib.chat.Color;
import com.earth2me.essentials.User;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Nation;
import lombok.experimental.var;
import lombok.val;
import org.bukkit.Bukkit;
@ -79,9 +80,10 @@ public class TownColorComponent extends Component {
return;
for (val entry : TownColors.entrySet()) {
try {
val nation = TownyComponent.TU.getTownsMap().get(entry.getKey()).getNation();
val town = TownyComponent.TU.getTownsMap().get(entry.getKey());
Nation nation;
Color nc;
if (nation == null || (nc = NationColor.get(nation.getName().toLowerCase())) == null)
if (!town.hasNation() || (nation = town.getNation()) == null || (nc = NationColor.get(nation.getName().toLowerCase())) == null)
nc = Color.White;
setTownColor(dtp, buttondevteam.chat.components.towncolors.admin.TownColorCommand.getTownNameCased(entry.getKey()), entry.getValue(), nc);
} catch (Exception e) {

View file

@ -3,6 +3,7 @@ package buttondevteam.chat.components.towny;
import buttondevteam.chat.ChatProcessing;
import buttondevteam.chat.PluginMain;
import buttondevteam.core.component.channel.Channel;
import buttondevteam.lib.TBMCSystemChatEvent;
import buttondevteam.lib.chat.TBMCChatAPI;
import com.palmergames.bukkit.towny.TownyLogger;
import lombok.val;
@ -24,17 +25,17 @@ public class TownyAnnouncer {
case "Town":
TBMCChatAPI.SendSystemMessage(PluginMain.TownChat,
new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, false), groupID),
logRecord.getMessage(), ChatProcessing.MCORIGIN);
logRecord.getMessage(), target, ChatProcessing.MCORIGIN);
break;
case "Nation":
TBMCChatAPI.SendSystemMessage(PluginMain.NationChat,
new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, true), groupID),
logRecord.getMessage(), ChatProcessing.MCORIGIN);
logRecord.getMessage(), target, ChatProcessing.MCORIGIN);
break;
case "Global":
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat,
Channel.RecipientTestResult.ALL,
logRecord.getMessage(), ChatProcessing.MCORIGIN);
logRecord.getMessage(), target, ChatProcessing.MCORIGIN);
break;
}
}
@ -50,11 +51,16 @@ public class TownyAnnouncer {
}
};
private static TBMCSystemChatEvent.BroadcastTarget target;
public static void setup() {
target = TBMCSystemChatEvent.BroadcastTarget.add("towny");
TownyLogger.log.addHandler(HANDLER);
}
public static void setdown() {
TBMCSystemChatEvent.BroadcastTarget.remove(target);
target = null;
TownyLogger.log.removeHandler(HANDLER);
}
}