forked from circlecloud/MiaoChat
		
	Compare commits
	
		
			3 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| d9322cbac4 | |||
| 95591ec5ff | |||
| 11fb155a37 | 
							
								
								
									
										17
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								pom.xml
									
									
									
									
									
								
							@@ -3,7 +3,7 @@
 | 
			
		||||
    <modelVersion>4.0.0</modelVersion>
 | 
			
		||||
 | 
			
		||||
    <artifactId>MiaoChat</artifactId>
 | 
			
		||||
    <version>2.0.0</version>
 | 
			
		||||
    <version>2.2.3</version>
 | 
			
		||||
 | 
			
		||||
    <parent>
 | 
			
		||||
        <groupId>pw.yumc</groupId>
 | 
			
		||||
@@ -13,13 +13,20 @@
 | 
			
		||||
    </parent>
 | 
			
		||||
 | 
			
		||||
    <properties>
 | 
			
		||||
        <update.description>§a正式版本 §bv2.0.0 §b全新版本(号) 配合龙核食用</update.description>
 | 
			
		||||
        <update.description>§a正式版本 §bv2.2.3 §b默认支持RGB色彩</update.description>
 | 
			
		||||
        <update.changes>
 | 
			
		||||
            §621-12-18 §a增强: 全新版本(号) 新增 itemTip 配合龙核 实现神奇功能;
 | 
			
		||||
            §621-12-06 §a增强: 兼容 1.18 版本 兼容新版PAPI;
 | 
			
		||||
            §621-06-20 §a增强: 兼容 1.17 版本
 | 
			
		||||
            §622-11-23 §a增强: 默认支持RGB色彩;
 | 
			
		||||
            §622-11-21 §a增强: 兼容 1.19.2(1.19.x部分版本存在BUG);
 | 
			
		||||
            §622-07-05 §a增强: 兼容 Paper 1.19;
 | 
			
		||||
            §622-06-17 §a增强: 兼容 1.19 修复 快捷指令错误;
 | 
			
		||||
            §622-04-13 §c修复: 部分版本JDK导致启动错误
 | 
			
		||||
        </update.changes>
 | 
			
		||||
        <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-06-20 §a增强: 兼容 1.17 版本;
 | 
			
		||||
            §620-10-10 §c修复: 1.16.3聊天包格式调整的问题;
 | 
			
		||||
            §620-04-10 §c修复: L10N 本地化组件报错的问题;
 | 
			
		||||
            §620-04-09 §c修复: 1.13-1.15.2新增物品不兼容的问题;
 | 
			
		||||
 
 | 
			
		||||
@@ -67,7 +67,7 @@ public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListe
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onDisable() {
 | 
			
		||||
        this.expansion.unregister();
 | 
			
		||||
        try {this.expansion.unregister();} catch (Throwable ignored) {}
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void enableBungeeCord() {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,23 +1,27 @@
 | 
			
		||||
package pw.yumc.MiaoChat;
 | 
			
		||||
 | 
			
		||||
import lombok.SneakyThrows;
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
 | 
			
		||||
import java.io.ByteArrayInputStream;
 | 
			
		||||
import java.io.ByteArrayOutputStream;
 | 
			
		||||
import java.io.InputStream;
 | 
			
		||||
import java.io.OutputStream;
 | 
			
		||||
import java.nio.charset.StandardCharsets;
 | 
			
		||||
import java.util.regex.Matcher;
 | 
			
		||||
import java.util.regex.Pattern;
 | 
			
		||||
import java.util.zip.GZIPInputStream;
 | 
			
		||||
import java.util.zip.GZIPOutputStream;
 | 
			
		||||
 | 
			
		||||
import lombok.SneakyThrows;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Created on 16-9-8.
 | 
			
		||||
 *
 | 
			
		||||
 * @author MiaoWoo
 | 
			
		||||
 */
 | 
			
		||||
public class MiaoMessage {
 | 
			
		||||
 | 
			
		||||
    public static final String CHANNEL = "MiaoChat:Default".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 String json;
 | 
			
		||||
 | 
			
		||||
@@ -44,7 +48,7 @@ public class MiaoMessage {
 | 
			
		||||
    public byte[] encode() {
 | 
			
		||||
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
 | 
			
		||||
        copy(new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)), new GZIPOutputStream(baos));
 | 
			
		||||
        if (baos.size() > MAX_MESSAGE_LENGTH) { return null; }
 | 
			
		||||
        if (baos.size() > MAX_MESSAGE_LENGTH) {return null;}
 | 
			
		||||
        return baos.toByteArray();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -58,4 +62,19 @@ public class MiaoMessage {
 | 
			
		||||
        input.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 org.bukkit.configuration.ConfigurationSection;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import pw.yumc.MiaoChat.MiaoMessage;
 | 
			
		||||
import pw.yumc.YumCore.config.annotation.ConfigNode;
 | 
			
		||||
import pw.yumc.YumCore.config.annotation.Nullable;
 | 
			
		||||
import pw.yumc.YumCore.config.inject.InjectConfigurationSection;
 | 
			
		||||
import pw.yumc.YumCore.tellraw.Tellraw;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
public class ChatMessagePart extends InjectConfigurationSection {
 | 
			
		||||
    private String text;
 | 
			
		||||
@@ -53,10 +55,10 @@ public class ChatMessagePart extends InjectConfigurationSection {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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) {
 | 
			
		||||
        return PlaceholderAPI.setPlaceholders(player, text);
 | 
			
		||||
        return MiaoMessage.rgb(PlaceholderAPI.setPlaceholders(player, text));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,20 +1,19 @@
 | 
			
		||||
package pw.yumc.MiaoChat.config;
 | 
			
		||||
 | 
			
		||||
import java.util.LinkedList;
 | 
			
		||||
import java.util.regex.Matcher;
 | 
			
		||||
import java.util.regex.Pattern;
 | 
			
		||||
 | 
			
		||||
import me.clip.placeholderapi.PlaceholderAPI;
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.configuration.ConfigurationSection;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import me.clip.placeholderapi.PlaceholderAPI;
 | 
			
		||||
import pw.yumc.MiaoChat.MiaoChat;
 | 
			
		||||
import pw.yumc.YumCore.bukkit.P;
 | 
			
		||||
import pw.yumc.YumCore.config.annotation.Default;
 | 
			
		||||
import pw.yumc.YumCore.config.inject.InjectConfigurationSection;
 | 
			
		||||
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
 | 
			
		||||
 */
 | 
			
		||||
public class ChatRule extends InjectConfigurationSection {
 | 
			
		||||
    private transient static MiaoChat plugin = P.getPlugin();
 | 
			
		||||
    private transient static Pattern FORMAT_PATTERN = Pattern.compile("[\\[]([^\\[\\]]+)[]]");
 | 
			
		||||
    private final transient static MiaoChat plugin = P.getPlugin();
 | 
			
		||||
    private final transient static Pattern FORMAT_PATTERN = Pattern.compile("[\\[]([^\\[\\]]+)[]]");
 | 
			
		||||
 | 
			
		||||
    private transient String name;
 | 
			
		||||
    @Default("50")
 | 
			
		||||
    private Integer index;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,12 +1,5 @@
 | 
			
		||||
package pw.yumc.MiaoChat.listeners;
 | 
			
		||||
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
import java.util.LinkedList;
 | 
			
		||||
import java.util.Queue;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
import java.util.regex.Matcher;
 | 
			
		||||
import java.util.regex.Pattern;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
@@ -16,7 +9,6 @@ import org.bukkit.event.EventPriority;
 | 
			
		||||
import org.bukkit.event.Listener;
 | 
			
		||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
 | 
			
		||||
import org.bukkit.inventory.ItemStack;
 | 
			
		||||
 | 
			
		||||
import pw.yumc.MiaoChat.MiaoChat;
 | 
			
		||||
import pw.yumc.MiaoChat.MiaoMessage;
 | 
			
		||||
import pw.yumc.MiaoChat.config.ChatConfig;
 | 
			
		||||
@@ -28,14 +20,18 @@ import pw.yumc.YumCore.statistic.Statistics;
 | 
			
		||||
import pw.yumc.YumCore.tellraw.Tellraw;
 | 
			
		||||
import pw.yumc.YumCore.update.SubscribeTask;
 | 
			
		||||
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
import java.util.LinkedList;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
import java.util.regex.Matcher;
 | 
			
		||||
import java.util.regex.Pattern;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author MiaoWoo
 | 
			
		||||
 */
 | 
			
		||||
public class ChatListener implements Listener {
 | 
			
		||||
    public static Set<Player> offList = new HashSet<>();
 | 
			
		||||
    private static Pattern ITEM_PATTERN = Pattern.compile("%([i1-9]?)");
 | 
			
		||||
 | 
			
		||||
    private final Queue<String> queue = new LinkedList<>();
 | 
			
		||||
    private static Pattern PATTERN = Pattern.compile("%([a-z1-9]?)");
 | 
			
		||||
 | 
			
		||||
    private MiaoChat plugin = P.getPlugin();
 | 
			
		||||
    private ChatConfig cc = plugin.getChatConfig();
 | 
			
		||||
@@ -85,7 +81,7 @@ public class ChatListener implements Listener {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private LinkedList<String> handlePattern(String message) {
 | 
			
		||||
        Matcher m = ITEM_PATTERN.matcher(message);
 | 
			
		||||
        Matcher m = PATTERN.matcher(message);
 | 
			
		||||
        Set<String> temp = new HashSet<>();
 | 
			
		||||
        LinkedList<String> ilist = new LinkedList<>();
 | 
			
		||||
        // Log.d("处理聊天物品信息...");
 | 
			
		||||
@@ -126,10 +122,13 @@ public class ChatListener implements Listener {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Tellraw handleTellraw(Player player, Tellraw tr, ChatRule cr, String message) {
 | 
			
		||||
        if (message.isEmpty()) { return tr; }
 | 
			
		||||
        if (message.isEmpty()) {return tr;}
 | 
			
		||||
        if (player.hasPermission("MiaoChat.color")) {
 | 
			
		||||
            message = ChatColor.translateAlternateColorCodes('&', message);
 | 
			
		||||
        }
 | 
			
		||||
        if (player.hasPermission("MiaoChat.rgb")) {
 | 
			
		||||
            message = MiaoMessage.rgb(message);
 | 
			
		||||
        }
 | 
			
		||||
        if (!cr.isItem()) {
 | 
			
		||||
            tr.then(message);
 | 
			
		||||
            return tr;
 | 
			
		||||
@@ -146,11 +145,30 @@ public class ChatListener implements Listener {
 | 
			
		||||
            String mm = ml.removeFirst();
 | 
			
		||||
            if (il.contains(mm)) {
 | 
			
		||||
                char k = mm.charAt(1);
 | 
			
		||||
                ItemStack is = k == 'i' ? player.getItemInHand() : player.getInventory().getItem(k - '0' - 1);
 | 
			
		||||
                String key = String.valueOf(k);
 | 
			
		||||
                if (plugin.getChatConfig().getFormats().containsKey(key)) {
 | 
			
		||||
                    if (!player.hasPermission("MiaoChat.format.*") && player.hasPermission("MiaoChat.format." + k)) {
 | 
			
		||||
                        Log.sender(player, "§c你没有使用 " + mm + " 的权限!");
 | 
			
		||||
                        continue;
 | 
			
		||||
                    }
 | 
			
		||||
                    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 {
 | 
			
		||||
                        tr.then(cr.getLastColor() + mm);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                // Log.d("追加聊天: %s", mm);
 | 
			
		||||
 
 | 
			
		||||
@@ -48,3 +48,24 @@ help:
 | 
			
		||||
  click:
 | 
			
		||||
    type: 'COMMAND'
 | 
			
		||||
    command: '管理员@%player_name% 我需要你的帮助!'
 | 
			
		||||
l:
 | 
			
		||||
  text: '&6[&b点击看我仓库]&6'
 | 
			
		||||
  #  item:
 | 
			
		||||
  #    # 物品枚举
 | 
			
		||||
  #    type: STONE
 | 
			
		||||
  #    # 物品子ID
 | 
			
		||||
  #    damage: 0
 | 
			
		||||
  #    # 物品名称(用于萌芽/龙核匹配) 为空则使用 text
 | 
			
		||||
  #    name: '§g§s§p'
 | 
			
		||||
  tip:
 | 
			
		||||
    - '&a点击查看 &b%player_name% &a的仓库'
 | 
			
		||||
  click:
 | 
			
		||||
    type: 'COMMAND'
 | 
			
		||||
    command: '/mgs look %player_name% local 1'
 | 
			
		||||
t:
 | 
			
		||||
  text: '&6[&b点击和我交易&6]&r'
 | 
			
		||||
  tip:
 | 
			
		||||
    - '&a点击和 &b%player_name% &a发起交易'
 | 
			
		||||
  click:
 | 
			
		||||
    type: 'COMMAND'
 | 
			
		||||
    command: '/trade %player_name%'
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
name: ${project.artifactId}
 | 
			
		||||
description: ${project.description}
 | 
			
		||||
main: ${project.groupId}.${project.artifactId}.${project.artifactId}
 | 
			
		||||
version: ${project.version}-git-${env.GIT_COMMIT}
 | 
			
		||||
version: ${project.version}
 | 
			
		||||
api-version: 1.13
 | 
			
		||||
author: MiaoWoo
 | 
			
		||||
website: ${ciManagement.url}
 | 
			
		||||
@@ -26,6 +26,9 @@ permissions:
 | 
			
		||||
  ${project.artifactId}.color:
 | 
			
		||||
    description: 彩字聊天权限!
 | 
			
		||||
    default: op
 | 
			
		||||
  ${project.artifactId}.rgb:
 | 
			
		||||
    description: RGB聊天权限!
 | 
			
		||||
    default: op
 | 
			
		||||
  ${project.artifactId}.admin:
 | 
			
		||||
    description: 管理员格式权限!
 | 
			
		||||
    default: op
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user