mirror of
https://github.com/darksaid98/TownyChat.git
synced 2026-12-04 14:38:58 +00:00
Fix chat format line not parsing hex colors. (#28)
* Add hex colors to townychat. * Add the ampersand and bracket format for hex codes. * Fix chat format line not parsing hex colors.
This commit is contained in:
1 parent
4c6a1e2da1
commit
278344f44a
2 files changed
+23
-8
No files matched your search
@@ -3,6 +3,7 @@ package com.palmergames.bukkit.TownyChat;
|
|||||||
import com.palmergames.bukkit.TownyChat.config.ChatSettings;
|
import com.palmergames.bukkit.TownyChat.config.ChatSettings;
|
||||||
import com.palmergames.bukkit.TownyChat.listener.LocalTownyChatEvent;
|
import com.palmergames.bukkit.TownyChat.listener.LocalTownyChatEvent;
|
||||||
import com.palmergames.bukkit.TownyChat.util.StringReplaceManager;
|
import com.palmergames.bukkit.TownyChat.util.StringReplaceManager;
|
||||||
|
import com.palmergames.bukkit.towny.Towny;
|
||||||
import com.palmergames.bukkit.towny.TownySettings;
|
import com.palmergames.bukkit.towny.TownySettings;
|
||||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||||
import com.palmergames.bukkit.towny.object.Nation;
|
import com.palmergames.bukkit.towny.object.Nation;
|
||||||
@@ -214,9 +215,17 @@ public class TownyChatFormatter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String hexIfCompatible(String str) {
|
||||||
|
if (Towny.is116Plus()) {
|
||||||
|
return HexFormatter.translateHexColors(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
public static String getChatFormat(LocalTownyChatEvent event) {
|
public static String getChatFormat(LocalTownyChatEvent event) {
|
||||||
// Replace the {msg} here so it's not regex parsed.
|
// Replace the {msg} here so it's not regex parsed.
|
||||||
return replacer.replaceAll(event.getFormat(), event).replace("{modplayername}", "%1$s").replace("{msg}", "%2$s");
|
return hexIfCompatible(replacer.replaceAll(event.getFormat(), event).replace("{modplayername}", "%1$s").replace("{msg}", "%2$s"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -287,11 +296,11 @@ public class TownyChatFormatter {
|
|||||||
try {
|
try {
|
||||||
if (resident.hasTown())
|
if (resident.hasTown())
|
||||||
if (full)
|
if (full)
|
||||||
return String.format(ChatSettings.getTownTag(), resident.getTown().getName());
|
return hexIfCompatible(String.format(ChatSettings.getTownTag(), resident.getTown().getName()));
|
||||||
else if (resident.getTown().hasTag())
|
else if (resident.getTown().hasTag())
|
||||||
return String.format(ChatSettings.getTownTag(), resident.getTown().getTag());
|
return hexIfCompatible(String.format(ChatSettings.getTownTag(), resident.getTown().getTag()));
|
||||||
else if (override)
|
else if (override)
|
||||||
return String.format(ChatSettings.getTownTag(), resident.getTown().getName());
|
return hexIfCompatible(String.format(ChatSettings.getTownTag(), resident.getTown().getName()));
|
||||||
|
|
||||||
} catch (NotRegisteredException e) {
|
} catch (NotRegisteredException e) {
|
||||||
}
|
}
|
||||||
@@ -302,11 +311,11 @@ public class TownyChatFormatter {
|
|||||||
try {
|
try {
|
||||||
if (resident.hasNation())
|
if (resident.hasNation())
|
||||||
if (full)
|
if (full)
|
||||||
return String.format(ChatSettings.getNationTag(), resident.getTown().getNation().getName());
|
return hexIfCompatible(String.format(ChatSettings.getNationTag(), resident.getTown().getNation().getName()));
|
||||||
else if (resident.getTown().getNation().hasTag())
|
else if (resident.getTown().getNation().hasTag())
|
||||||
return String.format(ChatSettings.getNationTag(), resident.getTown().getNation().getTag());
|
return hexIfCompatible(String.format(ChatSettings.getNationTag(), resident.getTown().getNation().getTag()));
|
||||||
else if (override)
|
else if (override)
|
||||||
return String.format(ChatSettings.getNationTag(), resident.getTown().getNation().getName());
|
return hexIfCompatible(String.format(ChatSettings.getNationTag(), resident.getTown().getNation().getName()));
|
||||||
|
|
||||||
} catch (NotRegisteredException e) {
|
} catch (NotRegisteredException e) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -190,7 +190,13 @@ public class TownyChatPlayerListener implements Listener {
|
|||||||
Resident resident = TownyUniverse.getInstance().getDataSource().getResident(player.getName());
|
Resident resident = TownyUniverse.getInstance().getDataSource().getResident(player.getName());
|
||||||
|
|
||||||
LocalTownyChatEvent chatEvent = new LocalTownyChatEvent(event, resident);
|
LocalTownyChatEvent chatEvent = new LocalTownyChatEvent(event, resident);
|
||||||
event.setFormat(TownyChatFormatter.getChatFormat(chatEvent));
|
|
||||||
|
if (Towny.is116Plus()) {
|
||||||
|
event.setFormat(HexFormatter.translateHexColors(TownyChatFormatter.getChatFormat(chatEvent)));
|
||||||
|
} else {
|
||||||
|
event.setFormat(TownyChatFormatter.getChatFormat(chatEvent));
|
||||||
|
}
|
||||||
|
|
||||||
} catch (NotRegisteredException e) {
|
} catch (NotRegisteredException e) {
|
||||||
// World or resident not registered with Towny
|
// World or resident not registered with Towny
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
Reference in new issue
Block a user