mirror of
https://e.coding.net/circlecloud/MiaoChat.git
synced 2024-11-22 14:38:47 +00:00
feat: 新增 RGB 颜色支持 兼容 1.19.2
This commit is contained in:
parent
95591ec5ff
commit
d9322cbac4
16
pom.xml
16
pom.xml
@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>MiaoChat</artifactId>
|
<artifactId>MiaoChat</artifactId>
|
||||||
<version>2.1.2</version>
|
<version>2.2.3</version>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>pw.yumc</groupId>
|
<groupId>pw.yumc</groupId>
|
||||||
@ -13,14 +13,18 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<update.description>§a正式版本 §bv2.1.2 §b兼容 1.18.2</update.description>
|
<update.description>§a正式版本 §bv2.2.3 §b默认支持RGB色彩</update.description>
|
||||||
<update.changes>
|
<update.changes>
|
||||||
§622-04-13 §c修复: 部分版本JDK导致启动错误;
|
§622-11-23 §a增强: 默认支持RGB色彩;
|
||||||
§622-04-12 §a增强: 兼容 1.18.2 修复 PAPI 注销报错;
|
§622-11-21 §a增强: 兼容 1.19.2(1.19.x部分版本存在BUG);
|
||||||
§622-02-25 §a增强: 新增 %a-z 自定义解析 实现神奇功能 兼容 1.18.1#133+;
|
§622-07-05 §a增强: 兼容 Paper 1.19;
|
||||||
§621-12-18 §a增强: 全新版本(号) 新增 itemTip 配合龙核 实现神奇功能
|
§622-06-17 §a增强: 兼容 1.19 修复 快捷指令错误;
|
||||||
|
§622-04-13 §c修复: 部分版本JDK导致启动错误
|
||||||
</update.changes>
|
</update.changes>
|
||||||
<update.changelog>
|
<update.changelog>
|
||||||
|
§622-04-12 §a增强: 兼容 1.18.2 修复 PAPI 注销报错;
|
||||||
|
§622-02-25 §a增强: 新增 %a-z 自定义解析 实现神奇功能 兼容 1.18.1#133+;
|
||||||
|
§621-12-18 §a增强: 全新版本(号) 新增 itemTip 配合龙核 实现神奇功能;
|
||||||
§621-12-06 §a增强: 兼容 1.18 版本 兼容新版PAPI;
|
§621-12-06 §a增强: 兼容 1.18 版本 兼容新版PAPI;
|
||||||
§621-06-20 §a增强: 兼容 1.17 版本;
|
§621-06-20 §a增强: 兼容 1.17 版本;
|
||||||
§620-10-10 §c修复: 1.16.3聊天包格式调整的问题;
|
§620-10-10 §c修复: 1.16.3聊天包格式调整的问题;
|
||||||
|
@ -1,23 +1,27 @@
|
|||||||
package pw.yumc.MiaoChat;
|
package pw.yumc.MiaoChat;
|
||||||
|
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
import java.util.zip.GZIPOutputStream;
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
import lombok.SneakyThrows;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created on 16-9-8.
|
* Created on 16-9-8.
|
||||||
|
*
|
||||||
* @author MiaoWoo
|
* @author MiaoWoo
|
||||||
*/
|
*/
|
||||||
public class MiaoMessage {
|
public class MiaoMessage {
|
||||||
|
|
||||||
public static final String CHANNEL = "MiaoChat:Default".toLowerCase();
|
public static final String CHANNEL = "MiaoChat:Default".toLowerCase();
|
||||||
public static final String NORMAL_CHANNEL = "MiaoChat:Normal".toLowerCase();
|
public static final String NORMAL_CHANNEL = "MiaoChat:Normal".toLowerCase();
|
||||||
|
private static final Pattern RGB_PATTERN = Pattern.compile("#[a-fA-F0-9]{6}");
|
||||||
private static final int MAX_MESSAGE_LENGTH = 32000;
|
private static final int MAX_MESSAGE_LENGTH = 32000;
|
||||||
private String json;
|
private String json;
|
||||||
|
|
||||||
@ -58,4 +62,19 @@ public class MiaoMessage {
|
|||||||
input.close();
|
input.close();
|
||||||
output.close();
|
output.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String rgb(String message) {
|
||||||
|
Matcher matcher = RGB_PATTERN.matcher(message);
|
||||||
|
while (matcher.find()) {
|
||||||
|
String hexCode = message.substring(matcher.start(), matcher.end());
|
||||||
|
String replaceSharp = hexCode.replace('#', 'x');
|
||||||
|
char[] ch = replaceSharp.toCharArray();
|
||||||
|
StringBuilder builder = new StringBuilder("");
|
||||||
|
for (char c : ch) {
|
||||||
|
builder.append("&").append(c);
|
||||||
|
}
|
||||||
|
message = message.replace(hexCode, builder.toString());
|
||||||
|
}
|
||||||
|
return ChatColor.translateAlternateColorCodes('&', message);
|
||||||
|
}
|
||||||
}
|
}
|
@ -3,12 +3,14 @@ package pw.yumc.MiaoChat.config;
|
|||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import pw.yumc.MiaoChat.MiaoMessage;
|
||||||
import pw.yumc.YumCore.config.annotation.ConfigNode;
|
import pw.yumc.YumCore.config.annotation.ConfigNode;
|
||||||
import pw.yumc.YumCore.config.annotation.Nullable;
|
import pw.yumc.YumCore.config.annotation.Nullable;
|
||||||
import pw.yumc.YumCore.config.inject.InjectConfigurationSection;
|
import pw.yumc.YumCore.config.inject.InjectConfigurationSection;
|
||||||
import pw.yumc.YumCore.tellraw.Tellraw;
|
import pw.yumc.YumCore.tellraw.Tellraw;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ChatMessagePart extends InjectConfigurationSection {
|
public class ChatMessagePart extends InjectConfigurationSection {
|
||||||
private String text;
|
private String text;
|
||||||
@ -53,10 +55,10 @@ public class ChatMessagePart extends InjectConfigurationSection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<String> f(Player player, List<String> text) {
|
private List<String> f(Player player, List<String> text) {
|
||||||
return PlaceholderAPI.setPlaceholders(player, text);
|
return text.stream().map((line) -> f(player, line)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String f(Player player, String text) {
|
private String f(Player player, String text) {
|
||||||
return PlaceholderAPI.setPlaceholders(player, text);
|
return MiaoMessage.rgb(PlaceholderAPI.setPlaceholders(player, text));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,19 @@
|
|||||||
package pw.yumc.MiaoChat.config;
|
package pw.yumc.MiaoChat.config;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
|
||||||
import pw.yumc.MiaoChat.MiaoChat;
|
import pw.yumc.MiaoChat.MiaoChat;
|
||||||
import pw.yumc.YumCore.bukkit.P;
|
import pw.yumc.YumCore.bukkit.P;
|
||||||
import pw.yumc.YumCore.config.annotation.Default;
|
import pw.yumc.YumCore.config.annotation.Default;
|
||||||
import pw.yumc.YumCore.config.inject.InjectConfigurationSection;
|
import pw.yumc.YumCore.config.inject.InjectConfigurationSection;
|
||||||
import pw.yumc.YumCore.tellraw.Tellraw;
|
import pw.yumc.YumCore.tellraw.Tellraw;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 聊天规则
|
* 聊天规则
|
||||||
*
|
*
|
||||||
@ -22,8 +21,9 @@ import pw.yumc.YumCore.tellraw.Tellraw;
|
|||||||
* @since 2016年9月9日 下午4:59:47
|
* @since 2016年9月9日 下午4:59:47
|
||||||
*/
|
*/
|
||||||
public class ChatRule extends InjectConfigurationSection {
|
public class ChatRule extends InjectConfigurationSection {
|
||||||
private transient static MiaoChat plugin = P.getPlugin();
|
private final transient static MiaoChat plugin = P.getPlugin();
|
||||||
private transient static Pattern FORMAT_PATTERN = Pattern.compile("[\\[]([^\\[\\]]+)[]]");
|
private final transient static Pattern FORMAT_PATTERN = Pattern.compile("[\\[]([^\\[\\]]+)[]]");
|
||||||
|
|
||||||
private transient String name;
|
private transient String name;
|
||||||
@Default("50")
|
@Default("50")
|
||||||
private Integer index;
|
private Integer index;
|
||||||
|
@ -126,6 +126,9 @@ public class ChatListener implements Listener {
|
|||||||
if (player.hasPermission("MiaoChat.color")) {
|
if (player.hasPermission("MiaoChat.color")) {
|
||||||
message = ChatColor.translateAlternateColorCodes('&', message);
|
message = ChatColor.translateAlternateColorCodes('&', message);
|
||||||
}
|
}
|
||||||
|
if (player.hasPermission("MiaoChat.rgb")) {
|
||||||
|
message = MiaoMessage.rgb(message);
|
||||||
|
}
|
||||||
if (!cr.isItem()) {
|
if (!cr.isItem()) {
|
||||||
tr.then(message);
|
tr.then(message);
|
||||||
return tr;
|
return tr;
|
||||||
@ -142,12 +145,6 @@ public class ChatListener implements Listener {
|
|||||||
String mm = ml.removeFirst();
|
String mm = ml.removeFirst();
|
||||||
if (il.contains(mm)) {
|
if (il.contains(mm)) {
|
||||||
char k = mm.charAt(1);
|
char k = mm.charAt(1);
|
||||||
ItemStack is = k == 'i' ? player.getItemInHand() : player.getInventory().getItem(k - '0' - 1);
|
|
||||||
if (is != null && is.getType() != Material.AIR) {
|
|
||||||
// Log.d("处理物品: %s", mm);
|
|
||||||
tr.then(String.format(ChatColor.translateAlternateColorCodes('&', cr.getItemformat()), L10N.getName(is)));
|
|
||||||
tr.item(is);
|
|
||||||
} else {
|
|
||||||
String key = String.valueOf(k);
|
String key = String.valueOf(k);
|
||||||
if (plugin.getChatConfig().getFormats().containsKey(key)) {
|
if (plugin.getChatConfig().getFormats().containsKey(key)) {
|
||||||
if (!player.hasPermission("MiaoChat.format.*") && player.hasPermission("MiaoChat.format." + k)) {
|
if (!player.hasPermission("MiaoChat.format.*") && player.hasPermission("MiaoChat.format." + k)) {
|
||||||
@ -155,6 +152,20 @@ public class ChatListener implements Listener {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
plugin.getChatConfig().getFormats().get(key).then(tr, player);
|
plugin.getChatConfig().getFormats().get(key).then(tr, player);
|
||||||
|
} else {
|
||||||
|
ItemStack is = null;
|
||||||
|
if (k == 'i') {
|
||||||
|
is = player.getItemInHand();
|
||||||
|
} else {
|
||||||
|
int index = k - '0' - 1;
|
||||||
|
if (index < 10) {
|
||||||
|
is = player.getInventory().getItem(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is != null && is.getType() != Material.AIR) {
|
||||||
|
// Log.d("处理物品: %s", mm);
|
||||||
|
tr.then(String.format(ChatColor.translateAlternateColorCodes('&', cr.getItemformat()), L10N.getName(is)));
|
||||||
|
tr.item(is);
|
||||||
} else {
|
} else {
|
||||||
tr.then(cr.getLastColor() + mm);
|
tr.then(cr.getLastColor() + mm);
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,9 @@ permissions:
|
|||||||
${project.artifactId}.color:
|
${project.artifactId}.color:
|
||||||
description: 彩字聊天权限!
|
description: 彩字聊天权限!
|
||||||
default: op
|
default: op
|
||||||
|
${project.artifactId}.rgb:
|
||||||
|
description: RGB聊天权限!
|
||||||
|
default: op
|
||||||
${project.artifactId}.admin:
|
${project.artifactId}.admin:
|
||||||
description: 管理员格式权限!
|
description: 管理员格式权限!
|
||||||
default: op
|
default: op
|
||||||
|
Loading…
Reference in New Issue
Block a user