Add hex code support
This commit is contained in:
parent
29e188f857
commit
b33d0685c1
|
@ -3,7 +3,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.fpghoti</groupId>
|
||||
<artifactId>FPChat</artifactId>
|
||||
<version>1.1.2</version>
|
||||
<version>1.1.4</version>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<resources>
|
||||
|
@ -57,7 +57,7 @@
|
|||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.16.3-R0.1-SNAPSHOT</version>
|
||||
<version>1.16.5-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -4,7 +4,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.fpghoti</groupId>
|
||||
<artifactId>FPChat</artifactId>
|
||||
<version>1.1.3</version>
|
||||
<version>1.1.4</version>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
|
@ -65,7 +65,7 @@
|
|||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.16.3-R0.1-SNAPSHOT</version>
|
||||
<version>1.16.5-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -191,7 +191,7 @@ public class FPChat extends JavaPlugin {
|
|||
}
|
||||
|
||||
public void log(Level level, String msg) {
|
||||
log.log(level, "[FPChat] " + msg.replaceAll("§[0-9A-FK-OR]", ""));
|
||||
log.log(level, msg.replaceAll("§[0-9A-FK-OR]", ""));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -112,6 +112,9 @@ public class BadgeList implements Iterable<Badge>{
|
|||
}
|
||||
|
||||
public Badge getIndex(int index) {
|
||||
if(list.size() <= 0) {
|
||||
return null;
|
||||
}
|
||||
return list.get(index);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.fpghoti.fpchatx.customcodes;
|
||||
package com.fpghoti.fpchatx.chat;
|
||||
|
||||
public class BubbleCode {
|
||||
|
|
@ -11,8 +11,6 @@ import org.bukkit.entity.Player;
|
|||
|
||||
import com.fpghoti.fpchatx.FPChat;
|
||||
import com.fpghoti.fpchatx.config.ChannelFile;
|
||||
import com.fpghoti.fpchatx.customcodes.BubbleCode;
|
||||
import com.fpghoti.fpchatx.customcodes.Codify;
|
||||
import com.fpghoti.fpchatx.permission.Permission;
|
||||
import com.fpghoti.fpchatx.player.FPlayer;
|
||||
|
||||
|
@ -309,11 +307,11 @@ public abstract class ChatChannel {
|
|||
}
|
||||
if(Permission.canUseColor(p)){
|
||||
String last = ChatFilter.filter(filler + msg);
|
||||
last = BubbleCode.bubblecode(Permission.canBubbleCode(p), Codify.changeFormatSign(last));
|
||||
finalMessage = ChatColor.translateAlternateColorCodes('&', stf + badges + header + last);
|
||||
last = BubbleCode.bubblecode(Permission.canBubbleCode(p), ChatColor.translateAlternateColorCodes('&', HexColor.formatHex(last)));
|
||||
finalMessage = HexColor.formatHex(stf + badges + header + last);
|
||||
}else{
|
||||
String newmsg = ChatColor.stripColor(ChatColor.translateAlternateColorCodes('§', ChatFilter.filter(filler + msg)));
|
||||
finalMessage = stf + badges + Codify.removeBubbles(header + newmsg);
|
||||
finalMessage = stf + badges + Codify.removeBubbles(HexColor.formatHex(header) + newmsg);
|
||||
}
|
||||
return finalMessage;
|
||||
}
|
||||
|
|
|
@ -1,35 +1,6 @@
|
|||
package com.fpghoti.fpchatx.customcodes;
|
||||
package com.fpghoti.fpchatx.chat;
|
||||
|
||||
public class Codify {
|
||||
|
||||
public static String changeFormatSign(String str) {
|
||||
String nstr = str;
|
||||
nstr = nstr.replace("&0", "§0");
|
||||
nstr = nstr.replace("&1", "§1");
|
||||
nstr = nstr.replace("&2", "§2");
|
||||
nstr = nstr.replace("&3", "§3");
|
||||
nstr = nstr.replace("&4", "§4");
|
||||
nstr = nstr.replace("&5", "§5");
|
||||
nstr = nstr.replace("&6", "§6");
|
||||
nstr = nstr.replace("&7", "§7");
|
||||
nstr = nstr.replace("&8", "§8");
|
||||
nstr = nstr.replace("&9", "§9");
|
||||
nstr = nstr.replace("&a", "§a");
|
||||
nstr = nstr.replace("&b", "§b");
|
||||
nstr = nstr.replace("&c", "§c");
|
||||
nstr = nstr.replace("&d", "§d");
|
||||
nstr = nstr.replace("&e", "§e");
|
||||
nstr = nstr.replace("&f", "§f");
|
||||
nstr = nstr.replace("&k", "§k");
|
||||
nstr = nstr.replace("&l", "§l");
|
||||
nstr = nstr.replace("&m", "§m");
|
||||
nstr = nstr.replace("&n", "§n");
|
||||
nstr = nstr.replace("&o", "§o");
|
||||
nstr = nstr.replace("&r", "§r");
|
||||
//nstr = nstr.replace("&w", "§w");
|
||||
//nstr = nstr.replace("&x", "§x");
|
||||
return nstr;
|
||||
}
|
||||
|
||||
public static String removeBubbles(String str) {
|
||||
String nstr = str;
|
|
@ -0,0 +1,48 @@
|
|||
package com.fpghoti.fpchatx.chat;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.fpghoti.fpchatx.util.Util;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
public class HexColor {
|
||||
|
||||
private static final Pattern pattern = Pattern.compile("(?<!\\\\)(#[a-fA-F0-9]{6})");
|
||||
|
||||
public static boolean allowHex() {
|
||||
String version = Util.getGameVersion().replace(".", "-");
|
||||
String[] vnums = version.split("-");
|
||||
int ver = Integer.parseInt(vnums[1]);
|
||||
if(Integer.parseInt(vnums[0]) > 1){
|
||||
return true;
|
||||
};
|
||||
return ver >= 16;
|
||||
}
|
||||
|
||||
public static String formatHex(String message) {
|
||||
if(!allowHex()) {
|
||||
return message;
|
||||
}
|
||||
HashMap<String, String> toReplace = new HashMap<String, String>();
|
||||
Matcher matcher = pattern.matcher(message);
|
||||
while (matcher.find()) {
|
||||
String hex = message.substring(matcher.start(), matcher.end());
|
||||
if(isHexCode(hex)) {
|
||||
toReplace.put(hex, "" + ChatColor.of(hex));
|
||||
}
|
||||
}
|
||||
for(String hex : toReplace.keySet()) {
|
||||
message = message.replace(hex, toReplace.get(hex));
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public static boolean isHexCode(String code) {
|
||||
Pattern pattern = Pattern.compile("#([a-fA-F0-9]{3}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})");
|
||||
Matcher matcher = pattern.matcher(code);
|
||||
return matcher.matches();
|
||||
}
|
||||
}
|
|
@ -1,12 +1,11 @@
|
|||
package com.fpghoti.fpchatx.chat;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.fpghoti.fpchatx.FPChat;
|
||||
import com.fpghoti.fpchatx.customcodes.BubbleCode;
|
||||
import com.fpghoti.fpchatx.customcodes.Codify;
|
||||
import com.fpghoti.fpchatx.permission.Permission;
|
||||
import com.fpghoti.fpchatx.player.FPlayer;
|
||||
import com.fpghoti.fpchatx.util.VaultUtil;
|
||||
|
@ -20,7 +19,7 @@ public class PrepareChat {
|
|||
public static String swapPlaceholders(FPlayer p, String recipient, String msg, boolean in) {
|
||||
return swapPlaceholders(p,null,msg,recipient,in);
|
||||
}
|
||||
|
||||
|
||||
public static String swapPlaceholders(FPlayer p, String msg) {
|
||||
return swapPlaceholders(p,null,msg,"",false);
|
||||
}
|
||||
|
@ -38,14 +37,14 @@ public class PrepareChat {
|
|||
String groupSuffix = "";
|
||||
World world = sender.getWorld();
|
||||
prefix = VaultUtil.chat.getPlayerPrefix(sender);
|
||||
prefix = BubbleCode.bubblecode(Permission.canBubbleCode(p), Codify.changeFormatSign(prefix)).replaceAll("&([0-9A-FK-OR])", "§$1").replace("&", "§");
|
||||
prefix = BubbleCode.bubblecode(Permission.canBubbleCode(p), ChatColor.translateAlternateColorCodes('&', prefix));
|
||||
suffix = VaultUtil.chat.getPlayerSuffix(sender);
|
||||
suffix = BubbleCode.bubblecode(Permission.canBubbleCode(p), Codify.changeFormatSign(suffix)).replaceAll("&([0-9A-FK-OR])", "§$1").replace("&", "§");
|
||||
suffix = BubbleCode.bubblecode(Permission.canBubbleCode(p), ChatColor.translateAlternateColorCodes('&', suffix));
|
||||
group = VaultUtil.permission.getPrimaryGroup(sender);
|
||||
groupPrefix = VaultUtil.chat.getGroupPrefix(world, group).replace("&", "§");
|
||||
groupSuffix = VaultUtil.chat.getGroupSuffix(world, group).replace("&", "§");
|
||||
String displayName = sender.getDisplayName();
|
||||
displayName = BubbleCode.bubblecode(Permission.canBubbleCode(p), Codify.changeFormatSign(displayName)).replaceAll("&([0-9A-FK-OR])", "§$1").replace("&", "§");
|
||||
displayName = BubbleCode.bubblecode(Permission.canBubbleCode(p), ChatColor.translateAlternateColorCodes('&', displayName));
|
||||
String format = "";
|
||||
if(channel != null) {
|
||||
if(Permission.isDistinguished(p)) {
|
||||
|
|
|
@ -66,16 +66,18 @@ public class BadgeListCommand extends Commands {
|
|||
int index = (pg - 1) * 8 + i;
|
||||
if (index < list.getListSize()) {
|
||||
Badge badge = list.getIndex(index);
|
||||
int id = badge.getId();
|
||||
String name = badge.getName();
|
||||
String contents = badge.getContents();
|
||||
String perm = badge.getPerm();
|
||||
String msg = ChatColor.DARK_AQUA + "ID: " + ChatColor.AQUA + id + ChatColor.DARK_AQUA + " - " + ChatColor.RESET + contents +
|
||||
ChatColor.RESET + ChatColor.DARK_AQUA + " - " + ChatColor.WHITE + ChatColor.BOLD + name;
|
||||
if(Permission.isAdmin(p)) {
|
||||
msg = msg + " " + ChatColor.YELLOW + perm;
|
||||
if(badge != null) {
|
||||
int id = badge.getId();
|
||||
String name = badge.getName();
|
||||
String contents = badge.getContents();
|
||||
String perm = badge.getPerm();
|
||||
String msg = ChatColor.DARK_AQUA + "ID: " + ChatColor.AQUA + id + ChatColor.DARK_AQUA + " - " + ChatColor.RESET + contents +
|
||||
ChatColor.RESET + ChatColor.DARK_AQUA + " - " + ChatColor.WHITE + ChatColor.BOLD + name;
|
||||
if(Permission.isAdmin(p)) {
|
||||
msg = msg + " " + ChatColor.YELLOW + perm;
|
||||
}
|
||||
FPlayer.plainMsg(p, msg);
|
||||
}
|
||||
FPlayer.plainMsg(p, msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,14 +16,14 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|||
|
||||
import com.fpghoti.fpchatx.FPChat;
|
||||
import com.fpghoti.fpchatx.badge.BadgeData;
|
||||
import com.fpghoti.fpchatx.chat.BubbleCode;
|
||||
import com.fpghoti.fpchatx.chat.ChatChannel;
|
||||
import com.fpghoti.fpchatx.chat.ChatFilter;
|
||||
import com.fpghoti.fpchatx.chat.Codify;
|
||||
import com.fpghoti.fpchatx.chat.PrepareChat;
|
||||
import com.fpghoti.fpchatx.chat.StandardChannel;
|
||||
import com.fpghoti.fpchatx.chat.TempChannel;
|
||||
import com.fpghoti.fpchatx.config.PlayerFile;
|
||||
import com.fpghoti.fpchatx.customcodes.BubbleCode;
|
||||
import com.fpghoti.fpchatx.customcodes.Codify;
|
||||
import com.fpghoti.fpchatx.permission.Permission;
|
||||
import com.fpghoti.fpchatx.util.Util;
|
||||
import com.fpghoti.fpchatx.util.VaultUtil;
|
||||
|
@ -550,7 +550,7 @@ public class FPlayer {
|
|||
}
|
||||
if(Permission.canPMColor(from)){
|
||||
String last = ChatFilter.filter(filler + msg);
|
||||
last = BubbleCode.bubblecode(Permission.canBubbleCode(from), Codify.changeFormatSign(last));
|
||||
last = BubbleCode.bubblecode(Permission.canBubbleCode(from), ChatColor.translateAlternateColorCodes('&', last));
|
||||
finalMessage = stf + header + last;
|
||||
}else{
|
||||
String newmsg = ChatColor.stripColor(ChatColor.translateAlternateColorCodes('§', ChatFilter.filter(filler + msg)));
|
||||
|
@ -584,7 +584,7 @@ public class FPlayer {
|
|||
}
|
||||
if(Permission.canPMColor(this)){
|
||||
String last = ChatFilter.filter(filler + msg);
|
||||
last = BubbleCode.bubblecode(Permission.canBubbleCode(this), Codify.changeFormatSign(last));
|
||||
last = BubbleCode.bubblecode(Permission.canBubbleCode(this), ChatColor.translateAlternateColorCodes('&', last));
|
||||
finalMessage = stf + header + last;
|
||||
}else{
|
||||
String newmsg = ChatColor.stripColor(ChatColor.translateAlternateColorCodes('§', ChatFilter.filter(filler + msg)));
|
||||
|
|
|
@ -7,7 +7,12 @@ import org.bukkit.entity.Player;
|
|||
|
||||
public class Util {
|
||||
|
||||
public Player playerGet(String uuid){
|
||||
public static String getGameVersion() {
|
||||
String version = Bukkit.getVersion().split("MC: ")[1].replace(")", "");
|
||||
return version;
|
||||
}
|
||||
|
||||
public static Player playerGet(String uuid){
|
||||
UUID id = UUID.fromString(uuid);
|
||||
Player p = Bukkit.getPlayer(id);
|
||||
return p;
|
||||
|
|
|
@ -3,7 +3,7 @@ version: ${project.version}
|
|||
main: com.fpghoti.fpchatx.FPChat
|
||||
description: Chat plugin for 1.12+
|
||||
depend: [Vault]
|
||||
loadbefore: [Essentials]
|
||||
loadbefore: [Essentials,ChatManager]
|
||||
commands:
|
||||
fpc:
|
||||
aliases: [fpchat,ch]
|
||||
|
|
Loading…
Reference in New Issue