mirror of
https://github.com/Aust1n46/VentureChat.git
synced 2025-05-23 10:39:05 +00:00
Support PlaceholderAPI version 2.10.7
Allow hex color format #ffffff in placeholders Properly handle capitol color codes Known Issue: Hex colors display as white in the message remover
This commit is contained in:
parent
e1dddceb5e
commit
664c71bb86
@ -111,7 +111,7 @@ import com.comphenix.protocol.ProtocolLibrary;
|
|||||||
import com.comphenix.protocol.events.PacketContainer;
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||||
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||||
|
|
||||||
public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
||||||
// Listeners --------------------------------
|
// Listeners --------------------------------
|
||||||
@ -406,14 +406,7 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
|||||||
if(pluginManager.isPluginEnabled("PlaceholderAPI")) {
|
if(pluginManager.isPluginEnabled("PlaceholderAPI")) {
|
||||||
Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Enabling PlaceholderAPI Hook"));
|
Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Enabling PlaceholderAPI Hook"));
|
||||||
}
|
}
|
||||||
/*boolean hooked = */PlaceholderAPI.registerPlaceholderHook("venturechat", new VentureChatPlaceholders());
|
PlaceholderAPIPlugin.getInstance().getLocalExpansionManager().register(new VentureChatPlaceholders());
|
||||||
//Tired of people reporting this non issue...
|
|
||||||
// if(hooked) {
|
|
||||||
// Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Added placeholders to PlaceholderAPI!"));
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - &cPlaceholders were not added to PlaceholderAPI!"));
|
|
||||||
// }
|
|
||||||
Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Loading player data"));
|
Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Loading player data"));
|
||||||
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
|
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
|
||||||
scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
|
scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
|
||||||
|
@ -3,12 +3,11 @@ package mineverse.Aust1n46.chat;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||||
import me.clip.placeholderapi.PlaceholderHook;
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
|
|
||||||
import mineverse.Aust1n46.chat.api.MineverseChatAPI;
|
import mineverse.Aust1n46.chat.api.MineverseChatAPI;
|
||||||
import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
|
import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
|
||||||
|
|
||||||
public class VentureChatPlaceholders extends PlaceholderHook {
|
public class VentureChatPlaceholders extends PlaceholderExpansion {
|
||||||
@Override
|
@Override
|
||||||
public String onPlaceholderRequest(Player p, String identifier) {
|
public String onPlaceholderRequest(Player p, String identifier) {
|
||||||
if(p == null) {
|
if(p == null) {
|
||||||
@ -67,4 +66,29 @@ public class VentureChatPlaceholders extends PlaceholderHook {
|
|||||||
if(color.equalsIgnoreCase("white")) return "f";
|
if(color.equalsIgnoreCase("white")) return "f";
|
||||||
return "f";
|
return "f";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean persist(){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canRegister(){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAuthor() {
|
||||||
|
return "Aust1n46";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getIdentifier() {
|
||||||
|
return "venturechat";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getVersion() {
|
||||||
|
return MineverseChat.getInstance().getDescription().getVersion();
|
||||||
|
}
|
||||||
}
|
}
|
@ -12,6 +12,7 @@ import mineverse.Aust1n46.chat.channel.ChatChannel;
|
|||||||
import mineverse.Aust1n46.chat.json.JsonFormat;
|
import mineverse.Aust1n46.chat.json.JsonFormat;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
//Wrapper class for Player, this class stores additional information along with a players Player pointer.
|
//Wrapper class for Player, this class stores additional information along with a players Player pointer.
|
||||||
@ -329,6 +330,10 @@ public class MineverseChatPlayer {
|
|||||||
return this.online ? this.player : null;
|
return this.online ? this.player : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public OfflinePlayer getOfflinePlayer() {
|
||||||
|
return Bukkit.getOfflinePlayer(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasPlayed() {
|
public boolean hasPlayed() {
|
||||||
return this.hasPlayed;
|
return this.hasPlayed;
|
||||||
}
|
}
|
||||||
|
@ -323,7 +323,7 @@ public class ChatListener implements Listener {
|
|||||||
chDistance = eventChannel.getDistance();
|
chDistance = eventChannel.getDistance();
|
||||||
}
|
}
|
||||||
|
|
||||||
format = PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), Format.FormatStringAll(plugin.getConfig().getConfigurationSection("channels." + eventChannel.getName()).getString("format")));
|
format = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getOfflinePlayer(), Format.FormatStringAll(plugin.getConfig().getConfigurationSection("channels." + eventChannel.getName()).getString("format"))));
|
||||||
if(plugin.getConfig().getBoolean("formatcleaner", false)) {
|
if(plugin.getConfig().getBoolean("formatcleaner", false)) {
|
||||||
format = format.replace("[]", " ");
|
format = format.replace("[]", " ");
|
||||||
format = format.replace(" ", " ").replace(" ", " ").replace(" ", " ");
|
format = format.replace(" ", " ").replace(" ", " ").replace(" ", " ");
|
||||||
|
@ -262,7 +262,7 @@ public class CommandListener implements CommandExecutor, Listener {
|
|||||||
if(target != null) {
|
if(target != null) {
|
||||||
command = command.replace("{player_name}", target.getName());
|
command = command.replace("{player_name}", target.getName());
|
||||||
if(target.isOnline()) {
|
if(target.isOnline()) {
|
||||||
command = PlaceholderAPI.setBracketPlaceholders(target.getPlayer(), command);
|
command = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(target.getPlayer(), command));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -98,26 +98,26 @@ public class Format {
|
|||||||
String hover = "";
|
String hover = "";
|
||||||
if(placeholder.contains(prefix)) {
|
if(placeholder.contains(prefix)) {
|
||||||
action = format.getClickPrefix();
|
action = format.getClickPrefix();
|
||||||
text = PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), format.getClickPrefixText());
|
text = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getOfflinePlayer(), format.getClickPrefixText()));
|
||||||
for(String st : format.getHoverTextPrefix()) {
|
for(String st : format.getHoverTextPrefix()) {
|
||||||
hover += Format.FormatStringAll(st) + "\n";
|
hover += Format.FormatStringAll(st) + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(placeholder.contains(nickname)) {
|
if(placeholder.contains(nickname)) {
|
||||||
action = format.getClickName();
|
action = format.getClickName();
|
||||||
text = PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), format.getClickNameText());
|
text = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getOfflinePlayer(), format.getClickNameText()));
|
||||||
for(String st : format.getHoverTextName()) {
|
for(String st : format.getHoverTextName()) {
|
||||||
hover += Format.FormatStringAll(st) + "\n";
|
hover += Format.FormatStringAll(st) + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(placeholder.contains(suffix)) {
|
if(placeholder.contains(suffix)) {
|
||||||
action = format.getClickSuffix();
|
action = format.getClickSuffix();
|
||||||
text = PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), format.getClickSuffixText());
|
text = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getOfflinePlayer(), format.getClickSuffixText()));
|
||||||
for(String st : format.getHoverTextSuffix()) {
|
for(String st : format.getHoverTextSuffix()) {
|
||||||
hover += Format.FormatStringAll(st) + "\n";
|
hover += Format.FormatStringAll(st) + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hover = PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), hover.substring(0, hover.length() - 1));
|
hover = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getOfflinePlayer(), hover.substring(0, hover.length() - 1)));
|
||||||
temp += convertToJsonColors(lastCode + placeholder, ",\"clickEvent\":{\"action\":\"" + action + "\",\"value\":\"" + text + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[" + convertToJsonColors(hover) + "]}}") + ",";
|
temp += convertToJsonColors(lastCode + placeholder, ",\"clickEvent\":{\"action\":\"" + action + "\",\"value\":\"" + text + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[" + convertToJsonColors(hover) + "]}}") + ",";
|
||||||
lastCode = getLastCode(lastCode + placeholder);
|
lastCode = getLastCode(lastCode + placeholder);
|
||||||
remaining = remaining.substring(indexEnd);
|
remaining = remaining.substring(indexEnd);
|
||||||
@ -436,19 +436,20 @@ public class Format {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Pattern chatHexColorPattern = Pattern.compile("(?i)&([X])");
|
protected static Pattern chatColorPattern = Pattern.compile("(?i)&([0-9])");
|
||||||
protected static Pattern chatColorPattern = Pattern.compile("(?i)&([0-9A-F])");
|
|
||||||
protected static Pattern chatMagicPattern = Pattern.compile("(?i)&([K])");
|
|
||||||
protected static Pattern chatBoldPattern = Pattern.compile("(?i)&([L])");
|
|
||||||
protected static Pattern chatStrikethroughPattern = Pattern.compile("(?i)&([M])");
|
|
||||||
protected static Pattern chatUnderlinePattern = Pattern.compile("(?i)&([N])");
|
|
||||||
protected static Pattern chatItalicPattern = Pattern.compile("(?i)&([O])");
|
|
||||||
protected static Pattern chatResetPattern = Pattern.compile("(?i)&([R])");
|
|
||||||
|
|
||||||
public static String FormatStringColor(String string) {
|
public static String FormatStringColor(String string) {
|
||||||
String allFormated = string;
|
String allFormated = string;
|
||||||
allFormated = chatColorPattern.matcher(allFormated).replaceAll("\u00A7$1");
|
allFormated = chatColorPattern.matcher(allFormated).replaceAll("\u00A7$1");
|
||||||
allFormated = chatHexColorPattern.matcher(allFormated).replaceAll("\u00A7$1");
|
|
||||||
|
allFormated = allFormated.replaceAll("&[x]", "§x");
|
||||||
|
allFormated = allFormated.replaceAll("&[aA]", "§a");
|
||||||
|
allFormated = allFormated.replaceAll("&[bB]", "§b");
|
||||||
|
allFormated = allFormated.replaceAll("&[cC]", "§c");
|
||||||
|
allFormated = allFormated.replaceAll("&[dD]", "§d");
|
||||||
|
allFormated = allFormated.replaceAll("&[eE]", "§e");
|
||||||
|
allFormated = allFormated.replaceAll("&[fF]", "§f");
|
||||||
|
|
||||||
allFormated = allFormated.replaceAll("%", "\\%");
|
allFormated = allFormated.replaceAll("%", "\\%");
|
||||||
|
|
||||||
allFormated = convertHexColorCodeStringToBukkitColorCodeString(allFormated);
|
allFormated = convertHexColorCodeStringToBukkitColorCodeString(allFormated);
|
||||||
@ -457,12 +458,13 @@ public class Format {
|
|||||||
|
|
||||||
public static String FormatString(String string) {
|
public static String FormatString(String string) {
|
||||||
String allFormated = string;
|
String allFormated = string;
|
||||||
allFormated = chatMagicPattern.matcher(allFormated).replaceAll("\u00A7$1");
|
allFormated = allFormated.replaceAll("&[kK]", "§k");
|
||||||
allFormated = chatBoldPattern.matcher(allFormated).replaceAll("\u00A7$1");
|
allFormated = allFormated.replaceAll("&[lL]", "§l");
|
||||||
allFormated = chatStrikethroughPattern.matcher(allFormated).replaceAll("\u00A7$1");
|
allFormated = allFormated.replaceAll("&[mM]", "§m");
|
||||||
allFormated = chatUnderlinePattern.matcher(allFormated).replaceAll("\u00A7$1");
|
allFormated = allFormated.replaceAll("&[nN]", "§n");
|
||||||
allFormated = chatItalicPattern.matcher(allFormated).replaceAll("\u00A7$1");
|
allFormated = allFormated.replaceAll("&[oO]", "§o");
|
||||||
allFormated = chatResetPattern.matcher(allFormated).replaceAll("\u00A7$1");
|
allFormated = allFormated.replaceAll("&[rR]", "§r");
|
||||||
|
|
||||||
allFormated = allFormated.replaceAll("%", "\\%");
|
allFormated = allFormated.replaceAll("%", "\\%");
|
||||||
return allFormated;
|
return allFormated;
|
||||||
}
|
}
|
||||||
@ -473,25 +475,6 @@ public class Format {
|
|||||||
return allFormated;
|
return allFormated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String FormatPlayerName(String playerPrefix, String playerDisplayName, String playerSuffix) {
|
|
||||||
playerPrefix = chatColorPattern.matcher(playerPrefix).replaceAll("\u00A7$1");
|
|
||||||
playerPrefix = chatMagicPattern.matcher(playerPrefix).replaceAll("\u00A7$1");
|
|
||||||
playerPrefix = chatBoldPattern.matcher(playerPrefix).replaceAll("\u00A7$1");
|
|
||||||
playerPrefix = chatStrikethroughPattern.matcher(playerPrefix).replaceAll("\u00A7$1");
|
|
||||||
playerPrefix = chatUnderlinePattern.matcher(playerPrefix).replaceAll("\u00A7$1");
|
|
||||||
playerPrefix = chatItalicPattern.matcher(playerPrefix).replaceAll("\u00A7$1");
|
|
||||||
playerPrefix = chatResetPattern.matcher(playerPrefix).replaceAll("\u00A7$1");
|
|
||||||
|
|
||||||
playerSuffix = chatColorPattern.matcher(playerSuffix).replaceAll("\u00A7$1");
|
|
||||||
playerSuffix = chatMagicPattern.matcher(playerSuffix).replaceAll("\u00A7$1");
|
|
||||||
playerSuffix = chatBoldPattern.matcher(playerSuffix).replaceAll("\u00A7$1");
|
|
||||||
playerSuffix = chatStrikethroughPattern.matcher(playerSuffix).replaceAll("\u00A7$1");
|
|
||||||
playerSuffix = chatUnderlinePattern.matcher(playerSuffix).replaceAll("\u00A7$1");
|
|
||||||
playerSuffix = chatItalicPattern.matcher(playerSuffix).replaceAll("\u00A7$1");
|
|
||||||
playerSuffix = chatResetPattern.matcher(playerSuffix).replaceAll("\u00A7$1");
|
|
||||||
return playerPrefix + playerDisplayName.trim() + playerSuffix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String FilterChat(String msg) {
|
public static String FilterChat(String msg) {
|
||||||
int t = 0;
|
int t = 0;
|
||||||
List<String> filters = plugin.getConfig().getStringList("filters");
|
List<String> filters = plugin.getConfig().getStringList("filters");
|
||||||
@ -532,7 +515,7 @@ public class Format {
|
|||||||
for(int a = 1; a < color.length(); a++) {
|
for(int a = 1; a < color.length(); a++) {
|
||||||
bukkitColorCode.append(BUKKIT_COLOR_CODE_PREFIX + color.charAt(a));
|
bukkitColorCode.append(BUKKIT_COLOR_CODE_PREFIX + color.charAt(a));
|
||||||
}
|
}
|
||||||
return bukkitColorCode.toString();
|
return bukkitColorCode.toString().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String convertHexColorCodeStringToBukkitColorCodeString(String string) {
|
public static String convertHexColorCodeStringToBukkitColorCodeString(String string) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user