Add hex code support

This commit is contained in:
Ghoti 2021-01-27 12:58:16 -06:00
parent 29e188f857
commit b33d0685c1
13 changed files with 88 additions and 62 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.fpghoti</groupId> <groupId>com.fpghoti</groupId>
<artifactId>FPChat</artifactId> <artifactId>FPChat</artifactId>
<version>1.1.2</version> <version>1.1.4</version>
<build> <build>
<sourceDirectory>src/main/java</sourceDirectory> <sourceDirectory>src/main/java</sourceDirectory>
<resources> <resources>
@ -57,7 +57,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.16.3-R0.1-SNAPSHOT</version> <version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
<exclusions> <exclusions>
<exclusion> <exclusion>

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.fpghoti</groupId> <groupId>com.fpghoti</groupId>
<artifactId>FPChat</artifactId> <artifactId>FPChat</artifactId>
<version>1.1.3</version> <version>1.1.4</version>
<repositories> <repositories>
<repository> <repository>
<id>spigot-repo</id> <id>spigot-repo</id>
@ -65,7 +65,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.16.3-R0.1-SNAPSHOT</version> <version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -191,7 +191,7 @@ public class FPChat extends JavaPlugin {
} }
public void log(Level level, String msg) { 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]", ""));
} }

View File

@ -112,6 +112,9 @@ public class BadgeList implements Iterable<Badge>{
} }
public Badge getIndex(int index) { public Badge getIndex(int index) {
if(list.size() <= 0) {
return null;
}
return list.get(index); return list.get(index);
} }

View File

@ -1,4 +1,4 @@
package com.fpghoti.fpchatx.customcodes; package com.fpghoti.fpchatx.chat;
public class BubbleCode { public class BubbleCode {

View File

@ -11,8 +11,6 @@ import org.bukkit.entity.Player;
import com.fpghoti.fpchatx.FPChat; import com.fpghoti.fpchatx.FPChat;
import com.fpghoti.fpchatx.config.ChannelFile; 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.permission.Permission;
import com.fpghoti.fpchatx.player.FPlayer; import com.fpghoti.fpchatx.player.FPlayer;
@ -309,11 +307,11 @@ public abstract class ChatChannel {
} }
if(Permission.canUseColor(p)){ if(Permission.canUseColor(p)){
String last = ChatFilter.filter(filler + msg); String last = ChatFilter.filter(filler + msg);
last = BubbleCode.bubblecode(Permission.canBubbleCode(p), Codify.changeFormatSign(last)); last = BubbleCode.bubblecode(Permission.canBubbleCode(p), ChatColor.translateAlternateColorCodes('&', HexColor.formatHex(last)));
finalMessage = ChatColor.translateAlternateColorCodes('&', stf + badges + header + last); finalMessage = HexColor.formatHex(stf + badges + header + last);
}else{ }else{
String newmsg = ChatColor.stripColor(ChatColor.translateAlternateColorCodes('§', ChatFilter.filter(filler + msg))); 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; return finalMessage;
} }

View File

@ -1,36 +1,7 @@
package com.fpghoti.fpchatx.customcodes; package com.fpghoti.fpchatx.chat;
public class Codify { 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) { public static String removeBubbles(String str) {
String nstr = str; String nstr = str;
nstr = nstr.replace('ⓐ', 'a'); nstr = nstr.replace('ⓐ', 'a');

View File

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

View File

@ -1,12 +1,11 @@
package com.fpghoti.fpchatx.chat; package com.fpghoti.fpchatx.chat;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.fpghoti.fpchatx.FPChat; 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.permission.Permission;
import com.fpghoti.fpchatx.player.FPlayer; import com.fpghoti.fpchatx.player.FPlayer;
import com.fpghoti.fpchatx.util.VaultUtil; import com.fpghoti.fpchatx.util.VaultUtil;
@ -38,14 +37,14 @@ public class PrepareChat {
String groupSuffix = ""; String groupSuffix = "";
World world = sender.getWorld(); World world = sender.getWorld();
prefix = VaultUtil.chat.getPlayerPrefix(sender); 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 = 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); group = VaultUtil.permission.getPrimaryGroup(sender);
groupPrefix = VaultUtil.chat.getGroupPrefix(world, group).replace("&", "§"); groupPrefix = VaultUtil.chat.getGroupPrefix(world, group).replace("&", "§");
groupSuffix = VaultUtil.chat.getGroupSuffix(world, group).replace("&", "§"); groupSuffix = VaultUtil.chat.getGroupSuffix(world, group).replace("&", "§");
String displayName = sender.getDisplayName(); 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 = ""; String format = "";
if(channel != null) { if(channel != null) {
if(Permission.isDistinguished(p)) { if(Permission.isDistinguished(p)) {

View File

@ -66,16 +66,18 @@ public class BadgeListCommand extends Commands {
int index = (pg - 1) * 8 + i; int index = (pg - 1) * 8 + i;
if (index < list.getListSize()) { if (index < list.getListSize()) {
Badge badge = list.getIndex(index); Badge badge = list.getIndex(index);
int id = badge.getId(); if(badge != null) {
String name = badge.getName(); int id = badge.getId();
String contents = badge.getContents(); String name = badge.getName();
String perm = badge.getPerm(); String contents = badge.getContents();
String msg = ChatColor.DARK_AQUA + "ID: " + ChatColor.AQUA + id + ChatColor.DARK_AQUA + " - " + ChatColor.RESET + contents + String perm = badge.getPerm();
ChatColor.RESET + ChatColor.DARK_AQUA + " - " + ChatColor.WHITE + ChatColor.BOLD + name; String msg = ChatColor.DARK_AQUA + "ID: " + ChatColor.AQUA + id + ChatColor.DARK_AQUA + " - " + ChatColor.RESET + contents +
if(Permission.isAdmin(p)) { ChatColor.RESET + ChatColor.DARK_AQUA + " - " + ChatColor.WHITE + ChatColor.BOLD + name;
msg = msg + " " + ChatColor.YELLOW + perm; if(Permission.isAdmin(p)) {
msg = msg + " " + ChatColor.YELLOW + perm;
}
FPlayer.plainMsg(p, msg);
} }
FPlayer.plainMsg(p, msg);
} }
} }

View File

@ -16,14 +16,14 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
import com.fpghoti.fpchatx.FPChat; import com.fpghoti.fpchatx.FPChat;
import com.fpghoti.fpchatx.badge.BadgeData; import com.fpghoti.fpchatx.badge.BadgeData;
import com.fpghoti.fpchatx.chat.BubbleCode;
import com.fpghoti.fpchatx.chat.ChatChannel; import com.fpghoti.fpchatx.chat.ChatChannel;
import com.fpghoti.fpchatx.chat.ChatFilter; import com.fpghoti.fpchatx.chat.ChatFilter;
import com.fpghoti.fpchatx.chat.Codify;
import com.fpghoti.fpchatx.chat.PrepareChat; import com.fpghoti.fpchatx.chat.PrepareChat;
import com.fpghoti.fpchatx.chat.StandardChannel; import com.fpghoti.fpchatx.chat.StandardChannel;
import com.fpghoti.fpchatx.chat.TempChannel; import com.fpghoti.fpchatx.chat.TempChannel;
import com.fpghoti.fpchatx.config.PlayerFile; 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.permission.Permission;
import com.fpghoti.fpchatx.util.Util; import com.fpghoti.fpchatx.util.Util;
import com.fpghoti.fpchatx.util.VaultUtil; import com.fpghoti.fpchatx.util.VaultUtil;
@ -550,7 +550,7 @@ public class FPlayer {
} }
if(Permission.canPMColor(from)){ if(Permission.canPMColor(from)){
String last = ChatFilter.filter(filler + msg); 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; finalMessage = stf + header + last;
}else{ }else{
String newmsg = ChatColor.stripColor(ChatColor.translateAlternateColorCodes('§', ChatFilter.filter(filler + msg))); String newmsg = ChatColor.stripColor(ChatColor.translateAlternateColorCodes('§', ChatFilter.filter(filler + msg)));
@ -584,7 +584,7 @@ public class FPlayer {
} }
if(Permission.canPMColor(this)){ if(Permission.canPMColor(this)){
String last = ChatFilter.filter(filler + msg); 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; finalMessage = stf + header + last;
}else{ }else{
String newmsg = ChatColor.stripColor(ChatColor.translateAlternateColorCodes('§', ChatFilter.filter(filler + msg))); String newmsg = ChatColor.stripColor(ChatColor.translateAlternateColorCodes('§', ChatFilter.filter(filler + msg)));

View File

@ -7,7 +7,12 @@ import org.bukkit.entity.Player;
public class Util { 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); UUID id = UUID.fromString(uuid);
Player p = Bukkit.getPlayer(id); Player p = Bukkit.getPlayer(id);
return p; return p;

View File

@ -3,7 +3,7 @@ version: ${project.version}
main: com.fpghoti.fpchatx.FPChat main: com.fpghoti.fpchatx.FPChat
description: Chat plugin for 1.12+ description: Chat plugin for 1.12+
depend: [Vault] depend: [Vault]
loadbefore: [Essentials] loadbefore: [Essentials,ChatManager]
commands: commands:
fpc: fpc:
aliases: [fpchat,ch] aliases: [fpchat,ch]