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 extends Entity> 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);
}
}