From 6d7660f96c0c04ad5ebc0b6af8cba974f9c5135a Mon Sep 17 00:00:00 2001 From: 502647092 Date: Wed, 14 Sep 2016 14:21:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=80=BC=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E7=89=B9=E6=AE=8A=E5=AD=97=E7=AC=A6=E6=97=B6=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- pom.xml | 13 +------ .../yumc/MiaoChat/listeners/ChatListener.java | 35 ++++++++++++++----- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index d99315f..91c8664 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 pw.yumc MiaoChat - 1.3 + 1.3.1 ${project.name} @@ -31,7 +31,6 @@ pw.yumc:YumCore - cn.citycraft:PluginHelper @@ -39,10 +38,6 @@ pw.yumc.YumCore ${project.groupId}.${project.artifactId} - - cn.citycraft.PluginHelper - ${project.groupId}.${project.artifactId} - @@ -110,12 +105,6 @@ jar 1.10.2-R0.1-SNAPSHOT - - cn.citycraft - PluginHelper - jar - 1.0 - pw.yumc YumCore diff --git a/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java b/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java index 8dc2c99..8038862 100644 --- a/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java +++ b/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java @@ -49,26 +49,31 @@ public class ChatListener implements Listener { final Player p = e.getPlayer(); final ChatRule cr = cc.getChatRule(e.getPlayer()); if (cr == null) { + // Log.d("玩家: %s 未发现可用ChatRule!", p.getName()); return; } e.setCancelled(true); final Tellraw tr = Tellraw.create(); - handleChat(p, tr, cr, e); + handleChat(p, tr, cr, e.getMessage()); } - private void handleChat(final Player p, final Tellraw tr, final ChatRule cr, final AsyncPlayerChatEvent e) { + private void handleChat(final Player p, final Tellraw tr, final ChatRule cr, final String message) { + // Log.d("玩家: %s 使用 %s 规则 解析 %s", p.getName(), cr.getName(), message); handleFormat(p, tr, cr); - handleTellraw(p, tr, cr, e.getMessage()); - handleSend(p, tr, cr); + handleTellraw(p, tr, cr, message); + handleSend(p, tr, cr.getRange()); } private void handleFormat(final Player p, final Tellraw tr, final ChatRule cr) { final LinkedList formats = cr.getFormats(); + // Log.d("处理前缀信息..."); for (final String format : formats) { final ChatMessagePart cmp = cc.getFormat(format); if (cmp != null) { + // Log.d("解析格式: %s", format); cmp.then(tr, p); } else { + // Log.d("追加文本: %s", format); tr.then(format); } } @@ -76,15 +81,21 @@ public class ChatListener implements Listener { private LinkedList handleMessage(final LinkedList il, String message) { final LinkedList mlist = new LinkedList<>(); + // Log.d("处理聊天信息..."); if (!il.isEmpty()) { for (final String k : il) { final String[] args = message.split(k, 2); - mlist.add(args[0]); + if (!args[0].isEmpty()) { + // Log.d("追加文本: %s", args[0]); + mlist.add(args[0]); + } + // Log.d("解析物品: %s", args[0]); mlist.add(k); message = args[1]; } } if (!message.isEmpty()) { + // Log.d("追加文本: %s", message); mlist.add(message); } return mlist; @@ -94,10 +105,12 @@ public class ChatListener implements Listener { final Matcher m = ITEM_PATTERN.matcher(message); final Set temp = new HashSet<>(); final LinkedList ilist = new LinkedList<>(); + // Log.d("处理聊天物品信息..."); while (m.find()) { final String key = m.group(0); if (key.length() == 2) { if (temp.add(key)) { + // Log.d("解析物品关键词: %s", key); ilist.add(key); } else { return null; @@ -107,8 +120,7 @@ public class ChatListener implements Listener { return ilist; } - private void handleSend(final Player p, final Tellraw tr, final ChatRule cr) { - final int range = cr.getRange(); + private void handleSend(final Player p, final Tellraw tr, final int range) { Collection plist = Collections.emptyList(); if (range != 0) { plist = p.getNearbyEntities(range, range, range); @@ -125,28 +137,35 @@ public class ChatListener implements Listener { } private void handleTellraw(final Player player, final Tellraw tr, final ChatRule cr, String message) { - if (message.isEmpty() || !cr.isItem()) { + if (message.isEmpty()) { return; } if (player.hasPermission("MiaoChat.color")) { message = ChatColor.translateAlternateColorCodes('&', message); } + if (!cr.isItem()) { + tr.then(message); + return; + } final LinkedList il = handlePattern(message); if (il == null) { Log.toSender(player, "§c不允许展示相同的物品!"); return; } final LinkedList ml = handleMessage(il, message); + // Log.d("处理Tellraw格式..."); while (!ml.isEmpty()) { final String mm = ml.removeFirst(); if (il.contains(mm)) { final char k = mm.charAt(1); final 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.getItemName(is))); tr.item(is); } } else { + // Log.d("追加聊天: %s", mm); tr.then(mm); } }