diff --git a/pom.xml b/pom.xml
index 2fd38b7..4c22dd0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
pw.yumc
MiaoChat
- 1.3.2
+ 1.3.3
${project.name}
@@ -60,6 +60,7 @@
+
@@ -109,7 +110,7 @@
pw.yumc
YumCore
jar
- 1.0
+ 1.1
pw.yumc
diff --git a/proguard.conf b/proguard.conf
index ff08c3b..f12adfb 100644
--- a/proguard.conf
+++ b/proguard.conf
@@ -16,9 +16,6 @@
# -----保留所有属性
-keepattributes **
-# -----替换包名
--repackageclasses \ʼ.ʽ.ʾ
-
# -----公共数据不混淆-----
-keep class cn.citycraft.CommonData.** {*;}
@@ -37,13 +34,13 @@
}
# -----保护配置注入不被清理-----
--keepclassmembers class * extends **.config.Inject** {
+-keepclassmembers class * extends **.config**Inject** {
;
}
# -----保护注解命令方法不被清理-----
-keepclassmembers class **.commands.annotation.** { ; }
--keepclassmembers class * implements **.commands.CommandExecutor { ; }
+-keepclassmembers class * implements **.commands**CommandExecutor { ; }
# -----保护注解NotProguard标记-----
-keep class **.NotProguard
diff --git a/src/main/java/pw/yumc/MiaoChat/MiaoChat.java b/src/main/java/pw/yumc/MiaoChat/MiaoChat.java
index 7dbe230..767d724 100644
--- a/src/main/java/pw/yumc/MiaoChat/MiaoChat.java
+++ b/src/main/java/pw/yumc/MiaoChat/MiaoChat.java
@@ -1,6 +1,7 @@
package pw.yumc.MiaoChat;
import org.bukkit.Material;
+import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
@@ -8,11 +9,10 @@ import org.bukkit.plugin.java.JavaPlugin;
import pw.yumc.MiaoChat.config.ChatConfig;
import pw.yumc.MiaoChat.listeners.ChatListener;
import pw.yumc.YumCore.bukkit.Log;
-import pw.yumc.YumCore.commands.CommandArgument;
-import pw.yumc.YumCore.commands.CommandExecutor;
import pw.yumc.YumCore.commands.CommandManager;
import pw.yumc.YumCore.commands.annotation.Cmd;
import pw.yumc.YumCore.commands.annotation.Help;
+import pw.yumc.YumCore.commands.interfaces.CommandExecutor;
import pw.yumc.YumCore.config.FileConfig;
import pw.yumc.YumCore.global.L10N;
@@ -31,16 +31,16 @@ public class MiaoChat extends JavaPlugin implements CommandExecutor {
@Cmd(permission = "MiaoChat.toggle")
@Help("关闭聊天功能")
- public void off(final CommandArgument e) {
- ChatListener.offList.add(e.getSender().getName());
- Log.toSender(e.getSender(), "§c聊天功能已关闭!");
+ public void off(CommandSender sender) {
+ ChatListener.offList.add(sender.getName());
+ Log.toSender(sender, "§c聊天功能已关闭!");
}
@Cmd(permission = "MiaoChat.toggle")
@Help("开启聊天功能")
- public void on(final CommandArgument e) {
- ChatListener.offList.remove(e.getSender().getName());
- Log.toSender(e.getSender(), "§a聊天功能已开启!");
+ public void on(CommandSender sender) {
+ ChatListener.offList.remove(sender.getName());
+ Log.toSender(sender, "§a聊天功能已开启!");
}
@Override
@@ -58,9 +58,9 @@ public class MiaoChat extends JavaPlugin implements CommandExecutor {
@Cmd(permission = "MiaoChat.reload")
@Help("重载配置文件")
- public void reload(final CommandArgument e) {
+ public void reload(CommandSender sender) {
cfg.reload();
chatConfig.reload();
- Log.toSender(e.getSender(), "§a配置文件已重载!");
+ Log.toSender(sender, "§a配置文件已重载!");
}
}
diff --git a/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java b/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java
index 3c3a5e1..30b3140 100644
--- a/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java
+++ b/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java
@@ -18,12 +18,12 @@ import pw.yumc.YumCore.config.FileConfig;
* @author 喵♂呜
*/
public class ChatConfig {
- private static final String F = "Formats";
- private final Map formats;
- private final RuleComparator rulecomp;
- private final LinkedList rules;
- private final FileConfig config;
- private final FileConfig format;
+ private static String F = "Formats";
+ private Map formats;
+ private RuleComparator rulecomp;
+ private LinkedList rules;
+ private FileConfig config;
+ private FileConfig format;
public ChatConfig() {
config = P.getConfig();
@@ -40,8 +40,8 @@ public class ChatConfig {
* @param player
* @return {@link ChatConfig}
*/
- public ChatRule getChatRule(final Player player) {
- for (final ChatRule cr : rules) {
+ public ChatRule getChatRule(Player player) {
+ for (ChatRule cr : rules) {
Log.debug(cr.getName());
if (cr.check(player)) {
return cr;
@@ -50,19 +50,19 @@ public class ChatConfig {
return null;
}
- public ChatMessagePart getFormat(final String name) {
+ public ChatMessagePart getFormat(String name) {
return formats.get(name);
}
public void load() {
formats.clear();
- for (final String name : format.getKeys(false)) {
+ for (String name : format.getKeys(false)) {
formats.put(name, new ChatMessagePart(format.getConfigurationSection(name)));
Log.d("载入聊天格式: %s", name);
}
rules.clear();
if (config.isSet(F)) {
- for (final String rule : config.getConfigurationSection(F).getKeys(false)) {
+ for (String rule : config.getConfigurationSection(F).getKeys(false)) {
rules.add(new ChatRule(rule, config.getConfigurationSection(F + "." + rule)));
Log.d("载入聊天规则: %s => \"%s\"", rule, rules.getLast().getFormat());
}
@@ -77,7 +77,7 @@ public class ChatConfig {
private class RuleComparator implements Comparator {
@Override
- public int compare(final ChatRule o1, final ChatRule o2) {
+ public int compare(ChatRule o1, ChatRule o2) {
return o1.getIndex().compareTo(o2.getIndex());
}
}
diff --git a/src/main/java/pw/yumc/MiaoChat/config/ChatMessagePart.java b/src/main/java/pw/yumc/MiaoChat/config/ChatMessagePart.java
index 3a56292..e47965e 100644
--- a/src/main/java/pw/yumc/MiaoChat/config/ChatMessagePart.java
+++ b/src/main/java/pw/yumc/MiaoChat/config/ChatMessagePart.java
@@ -6,9 +6,9 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import me.clip.placeholderapi.PlaceholderAPI;
-import pw.yumc.YumCore.config.ConfigNode;
-import pw.yumc.YumCore.config.InjectConfigurationSection;
-import pw.yumc.YumCore.config.Nullable;
+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;
public class ChatMessagePart extends InjectConfigurationSection {
@@ -23,20 +23,20 @@ public class ChatMessagePart extends InjectConfigurationSection {
private String command;
private transient CLICKTYPE type = CLICKTYPE.SUGGEST;
- public ChatMessagePart(final ConfigurationSection config) {
+ public ChatMessagePart(ConfigurationSection config) {
super(config);
if (typestring != null) {
type = CLICKTYPE.valueOf(typestring);
}
}
- public Tellraw then(final Tellraw tr, final Player p) {
+ public Tellraw then(Tellraw tr, Player p) {
tr.then(f(p, text));
if (tip != null && !tip.isEmpty()) {
tr.tip(f(p, tip));
}
if (command != null && !command.isEmpty()) {
- final String tc = f(p, command);
+ String tc = f(p, command);
switch (type) {
case COMMAND:
tr.command(tc);
@@ -49,17 +49,16 @@ public class ChatMessagePart extends InjectConfigurationSection {
break;
default:
break;
-
}
}
return tr;
}
- private List f(final Player player, final List text) {
+ private List f(Player player, List text) {
return PlaceholderAPI.setPlaceholders(player, text);
}
- private String f(final Player player, final String text) {
+ private String f(Player player, String text) {
return PlaceholderAPI.setPlaceholders(player, text);
}
}
diff --git a/src/main/java/pw/yumc/MiaoChat/config/ChatRule.java b/src/main/java/pw/yumc/MiaoChat/config/ChatRule.java
index 3b4dedc..653a1f5 100644
--- a/src/main/java/pw/yumc/MiaoChat/config/ChatRule.java
+++ b/src/main/java/pw/yumc/MiaoChat/config/ChatRule.java
@@ -4,11 +4,12 @@ import java.util.LinkedList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
-import pw.yumc.YumCore.config.Default;
-import pw.yumc.YumCore.config.InjectConfigurationSection;
+import pw.yumc.YumCore.config.annotation.Default;
+import pw.yumc.YumCore.config.inject.InjectConfigurationSection;
/**
* 聊天规则
@@ -17,7 +18,7 @@ import pw.yumc.YumCore.config.InjectConfigurationSection;
* @author 喵♂呜
*/
public class ChatRule extends InjectConfigurationSection {
- private transient static final Pattern FORMAT_PATTERN = Pattern.compile("[\\[]([^\\[\\]]+)[\\]]");
+ private transient static Pattern FORMAT_PATTERN = Pattern.compile("[\\[]([^\\[\\]]+)[\\]]");
private transient String name;
@Default("50")
private Integer index;
@@ -32,8 +33,9 @@ public class ChatRule extends InjectConfigurationSection {
@Default("&6[&b%s&6]&r")
private String itemformat;
private transient LinkedList formats;
+ private transient String lastColor;
- public ChatRule(final String name, final ConfigurationSection config) {
+ public ChatRule(String name, ConfigurationSection config) {
super(config);
this.name = name;
if (permission == null) {
@@ -41,9 +43,10 @@ public class ChatRule extends InjectConfigurationSection {
}
formats = new LinkedList<>();
load();
+ lastColor = ChatColor.getLastColors(ChatColor.translateAlternateColorCodes('&', formats.getLast()));
}
- public boolean check(final Player player) {
+ public boolean check(Player player) {
return player.hasPermission(permission);
}
@@ -67,6 +70,10 @@ public class ChatRule extends InjectConfigurationSection {
return itemformat;
}
+ public String getLastColor() {
+ return lastColor;
+ }
+
public String getName() {
return name;
}
@@ -84,15 +91,15 @@ public class ChatRule extends InjectConfigurationSection {
}
private void load() {
- final Matcher m = FORMAT_PATTERN.matcher(format);
- final LinkedList temp = new LinkedList<>();
+ Matcher m = FORMAT_PATTERN.matcher(format);
+ LinkedList temp = new LinkedList<>();
while (m.find()) {
temp.add(m.group(1));
}
String tempvar = format;
if (!temp.isEmpty()) {
- for (final String var : temp) {
- final String[] args = tempvar.split("\\[" + var + "\\]", 2);
+ for (String var : temp) {
+ String[] args = tempvar.split("\\[" + var + "\\]", 2);
if (!"".equals(args[0])) {
formats.add(args[0]);
}
diff --git a/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java b/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java
index 2a9c785..20f5911 100644
--- a/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java
+++ b/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java
@@ -34,10 +34,10 @@ import pw.yumc.YumCore.update.SubscribeTask;
public class ChatListener implements Listener {
public static Set offList = new HashSet<>();
- private static final Pattern ITEM_PATTERN = Pattern.compile("%([i1-9]?)");
+ private static Pattern ITEM_PATTERN = Pattern.compile("%([i1-9]?)");
- private final MiaoChat plugin = P.getPlugin();
- private final ChatConfig cc = plugin.getChatConfig();
+ private MiaoChat plugin = P.getPlugin();
+ private ChatConfig cc = plugin.getChatConfig();
public ChatListener() {
Bukkit.getPluginManager().registerEvents(this, P.instance);
@@ -46,30 +46,30 @@ public class ChatListener implements Listener {
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
- public void onChat(final AsyncPlayerChatEvent e) {
- final Player p = e.getPlayer();
- final ChatRule cr = cc.getChatRule(e.getPlayer());
+ public void onChat(AsyncPlayerChatEvent e) {
+ Player p = e.getPlayer();
+ ChatRule cr = cc.getChatRule(e.getPlayer());
if (cr == null) {
// Log.d("玩家: %s 未发现可用ChatRule!", p.getName());
return;
}
e.setCancelled(true);
- final Tellraw tr = Tellraw.create();
+ Tellraw tr = Tellraw.create();
handleChat(p, tr, cr, e.getMessage());
}
- private void handleChat(final Player p, final Tellraw tr, final ChatRule cr, final String message) {
+ private void handleChat(Player p, Tellraw tr, ChatRule cr, String message) {
// Log.d("玩家: %s 使用 %s 规则 解析 %s", p.getName(), cr.getName(), message);
handleFormat(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();
+ private String handleFormat(Player p, Tellraw tr, ChatRule cr) {
+ LinkedList formats = cr.getFormats();
// Log.d("处理前缀信息...");
- for (final String format : formats) {
- final ChatMessagePart cmp = cc.getFormat(format);
+ for (String format : formats) {
+ ChatMessagePart cmp = cc.getFormat(format);
if (cmp != null) {
// Log.d("解析格式: %s", format);
cmp.then(tr, p);
@@ -78,14 +78,15 @@ public class ChatListener implements Listener {
tr.then(PlaceholderAPI.setPlaceholders(p, format));
}
}
+ return ChatColor.getLastColors(formats.getLast());
}
- private LinkedList handleMessage(final LinkedList il, String message) {
- final LinkedList mlist = new LinkedList<>();
+ private LinkedList handleMessage(LinkedList il, String message) {
+ LinkedList mlist = new LinkedList<>();
// Log.d("处理聊天信息...");
if (!il.isEmpty()) {
- for (final String k : il) {
- final String[] args = message.split(k, 2);
+ for (String k : il) {
+ String[] args = message.split(k, 2);
if (!args[0].isEmpty()) {
// Log.d("追加文本: %s", args[0]);
mlist.add(args[0]);
@@ -102,13 +103,13 @@ public class ChatListener implements Listener {
return mlist;
}
- private LinkedList handlePattern(final String message) {
- final Matcher m = ITEM_PATTERN.matcher(message);
- final Set temp = new HashSet<>();
- final LinkedList ilist = new LinkedList<>();
+ private LinkedList handlePattern(String message) {
+ Matcher m = ITEM_PATTERN.matcher(message);
+ Set temp = new HashSet<>();
+ LinkedList ilist = new LinkedList<>();
// Log.d("处理聊天物品信息...");
while (m.find()) {
- final String key = m.group(0);
+ String key = m.group(0);
if (key.length() == 2) {
if (temp.add(key)) {
// Log.d("解析物品关键词: %s", key);
@@ -121,7 +122,7 @@ public class ChatListener implements Listener {
return ilist;
}
- private void handleSend(final Player p, final Tellraw tr, final int range) {
+ private void handleSend(Player p, Tellraw tr, int range) {
Collection extends Entity> plist = Collections.emptyList();
if (range != 0) {
plist = p.getNearbyEntities(range, range, range);
@@ -129,7 +130,7 @@ public class ChatListener implements Listener {
} else {
plist = C.Player.getOnlinePlayers();
}
- for (final Entity ne : plist) {
+ for (Entity ne : plist) {
if (ne instanceof Player && !offList.contains(((Player) ne).getName())) {
tr.send(ne);
}
@@ -137,7 +138,7 @@ public class ChatListener implements Listener {
Bukkit.getConsoleSender().sendMessage(tr.toOldMessageFormat());
}
- private void handleTellraw(final Player player, final Tellraw tr, final ChatRule cr, String message) {
+ private void handleTellraw(Player player, Tellraw tr, ChatRule cr, String message) {
if (message.isEmpty()) {
return;
}
@@ -148,18 +149,19 @@ public class ChatListener implements Listener {
tr.then(message);
return;
}
- final LinkedList il = handlePattern(message);
+ LinkedList il = handlePattern(message);
+ // 如果返回null说明存在相同的物品
if (il == null) {
Log.toSender(player, "§c不允许展示相同的物品!");
return;
}
- final LinkedList ml = handleMessage(il, message);
+ LinkedList ml = handleMessage(il, message);
// Log.d("处理Tellraw格式...");
while (!ml.isEmpty()) {
- final String mm = ml.removeFirst();
+ 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);
+ 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)));
@@ -167,7 +169,7 @@ public class ChatListener implements Listener {
}
} else {
// Log.d("追加聊天: %s", mm);
- tr.then(mm);
+ tr.then(cr.getLastColor() + mm);
}
}
}