diff --git a/lib/PlaceholderAPI.jar b/lib/PlaceholderAPI.jar
deleted file mode 100644
index 87bd3ab..0000000
Binary files a/lib/PlaceholderAPI.jar and /dev/null differ
diff --git a/pom.xml b/pom.xml
index 370964d..f87ae16 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
pw.yumc
MiaoChat
- 1.5.1
+ 1.6
${project.name}
@@ -13,14 +13,6 @@
-
- maven-compiler-plugin
- 3.3
-
-
- 1.7
-
-
org.apache.maven.plugins
maven-shade-plugin
@@ -78,16 +70,12 @@
http://ci.yumc.pw/job/${project.artifactId}/
-
-
- DEBUG
+ DEV
UTF-8
+ 1.7
+ 1.7
-
- spigot-repo
- https://hub.spigotmc.org/nexus/content/groups/public/
-
yumc-repo
http://repo.yumc.pw/content/groups/public/
@@ -105,7 +93,7 @@
pw.yumc
YumCore
jar
- 1.2
+ 1.5
\ No newline at end of file
diff --git a/proguard.conf b/proguard.conf
index 444289e..f70d1bb 100644
--- a/proguard.conf
+++ b/proguard.conf
@@ -6,7 +6,7 @@
-dontnote
# -----混淆时应用侵入式重载-----
--overloadaggressively
+-overloadaggressively
# -----启用混淆字典-----
-obfuscationdictionary obf.dict
@@ -16,38 +16,36 @@
# -----保留所有属性
-keepattributes **
-# -----公共数据不混淆-----
--keep class cn.citycraft.CommonData.** {*;}
-
# -----保护所有实体中的字段名称-----
--keepclassmembers class * implements java.io.Serializable { ; }
+-keepclassmembers class * implements java.io.Serializable {;}
# -----保护监听方法不被清理-----
--keepclassmembers class * implements org.bukkit.event.Listener {
- @org.bukkit.event.EventHandler ;
+-keepclassmembers class * implements org.bukkit.event.Listener {
+ @org.bukkit.event.EventHandler ;
}
-keepclassmembers class * implements net.md_5.bungee.api.plugin.Listener {
@net.md_5.bungee.event.EventHandler ;
}
+
# -----保护枚举方法的完整性-----
--keepclassmembers enum * {
- public static **[] values();
- public static ** valueOf(java.lang.String);
+-keepclassmembers enum * {
+ public static **[] values();
+ public static ** valueOf(java.lang.String);
}
# -----保护配置注入不被清理-----
--keepclassmembers class * extends **.config**Inject** {
- ;
+-keepclassmembers class * extends **.config.inject.Inject** {
+ ;
}
# -----保护注解命令方法不被清理-----
--keepclassmembers class **.commands.annotation.** { ; }
--keepclassmembers class * implements **.commands**CommandExecutor { ; }
+-keepclassmembers class **.commands.annotation.** {;}
+-keepclassmembers class * implements **.commands.interfaces.Executor {;}
# -----保护注解NotProguard标记-----
-keep class **.NotProguard
-keep @**.NotProguard class * {*;}
--keepclassmembers class * {
- @**.NotProguard ;
- @**.NotProguard ;
+-keepclassmembers class * {
+ @**.NotProguard ;
+ @**.NotProguard ;
}
\ No newline at end of file
diff --git a/src/main/java/pw/yumc/MiaoChat/MiaoChat.java b/src/main/java/pw/yumc/MiaoChat/MiaoChat.java
index 3774cbd..13b56a0 100644
--- a/src/main/java/pw/yumc/MiaoChat/MiaoChat.java
+++ b/src/main/java/pw/yumc/MiaoChat/MiaoChat.java
@@ -5,23 +5,34 @@ import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.messaging.PluginMessageListener;
+
+import com.google.common.io.ByteArrayDataInput;
+import com.google.common.io.ByteArrayDataOutput;
+import com.google.common.io.ByteStreams;
+
+import me.clip.placeholderapi.PlaceholderAPI;
+import me.clip.placeholderapi.PlaceholderHook;
import pw.yumc.MiaoChat.config.ChatConfig;
import pw.yumc.MiaoChat.listeners.ChatListener;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.bukkit.compatible.C;
-import pw.yumc.YumCore.commands.CommandManager;
+import pw.yumc.YumCore.commands.CommandSub;
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.commands.interfaces.Executor;
import pw.yumc.YumCore.config.FileConfig;
import pw.yumc.YumCore.global.L10N;
-public class MiaoChat extends JavaPlugin implements CommandExecutor, PluginMessageListener {
+public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListener, Listener {
private FileConfig cfg;
private ChatConfig chatConfig;
+ private String ServerName;
public ChatConfig getChatConfig() {
return chatConfig;
@@ -36,27 +47,42 @@ public class MiaoChat extends JavaPlugin implements CommandExecutor, PluginMessa
@Help("关闭聊天功能")
public void off(CommandSender sender) {
ChatListener.offList.add(sender.getName());
- Log.toSender(sender, "§c聊天功能已关闭!");
+ Log.sender(sender, "§c聊天功能已关闭!");
}
@Cmd(permission = "MiaoChat.toggle")
@Help("开启聊天功能")
public void on(CommandSender sender) {
ChatListener.offList.remove(sender.getName());
- Log.toSender(sender, "§a聊天功能已开启!");
+ Log.sender(sender, "§a聊天功能已开启!");
}
@Override
public void onEnable() {
new ChatListener();
- new CommandManager("MiaoChat", this);
+ new CommandSub("MiaoChat", this);
if (getChatConfig().isBungeeCord()) {
- Log.info("已开启 BUngeeCord 模式!");
+ Log.info("已开启 BungeeCord 模式!");
+ Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", this);
+ Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
+ Bukkit.getPluginManager().registerEvents(this, this);
Bukkit.getMessenger().registerIncomingPluginChannel(this, MiaoMessage.CHANNEL, this);
Bukkit.getMessenger().registerOutgoingPluginChannel(this, MiaoMessage.CHANNEL);
Bukkit.getMessenger().registerIncomingPluginChannel(this, MiaoMessage.NORMALCHANNEL, this);
Bukkit.getMessenger().registerOutgoingPluginChannel(this, MiaoMessage.NORMALCHANNEL);
}
+ PlaceholderAPI.registerPlaceholderHook("mct", new PlaceholderHook() {
+ @Override
+ public String onPlaceholderRequest(Player player, String s) {
+ switch (s.toLowerCase()) {
+ case "server":
+ return getChatConfig().getServername();
+ case "bserver":
+ return ServerName;
+ }
+ return "未知的参数";
+ }
+ });
L10N.getName(new ItemStack(Material.AIR));
}
@@ -71,7 +97,7 @@ public class MiaoChat extends JavaPlugin implements CommandExecutor, PluginMessa
public void reload(CommandSender sender) {
cfg.reload();
chatConfig.reload();
- Log.toSender(sender, "§a配置文件已重载!");
+ Log.sender(sender, "§a配置文件已重载!");
}
public static void send(byte[] in) {
@@ -84,6 +110,21 @@ public class MiaoChat extends JavaPlugin implements CommandExecutor, PluginMessa
}
}
+ @EventHandler
+ public void onJoin(final PlayerJoinEvent e) {
+ Bukkit.getScheduler().runTaskLater(this, new Runnable() {
+ @Override
+ public void run() {
+ Player p = e.getPlayer();
+ if (p.isOnline()) {
+ ByteArrayDataOutput out = ByteStreams.newDataOutput();
+ out.writeUTF("GetServer");
+ p.sendPluginMessage(MiaoChat.this, "BungeeCord", out.toByteArray());
+ }
+ }
+ }, 10);
+ }
+
@Override
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
if (MiaoMessage.CHANNEL.equals(channel)) {
@@ -92,6 +133,20 @@ public class MiaoChat extends JavaPlugin implements CommandExecutor, PluginMessa
for (Player p : C.Player.getOnlinePlayers()) {
p.sendMessage(MiaoMessage.decode(message).getJson());
}
+ } else if ("BungeeCord".equals(channel)) {
+ final ByteArrayDataInput input = ByteStreams.newDataInput(message);
+ if ("GetServer".equals(input.readUTF())) {
+ ServerName = input.readUTF();
+ Log.d("获取服务器名称: " + ServerName);
+ PlayerJoinEvent.getHandlerList().unregister((Listener) this);
+ Bukkit.getScheduler().runTaskLater(this, new Runnable() {
+ @Override
+ public void run() {
+ Bukkit.getMessenger().unregisterIncomingPluginChannel(MiaoChat.this, "BungeeCord");
+ Bukkit.getMessenger().unregisterOutgoingPluginChannel(MiaoChat.this, "BungeeCord");
+ }
+ }, 20);
+ }
}
}
}
diff --git a/src/main/java/pw/yumc/MiaoChat/MiaoChatBungee.java b/src/main/java/pw/yumc/MiaoChat/MiaoChatBungee.java
index 589f3fc..6b3222d 100644
--- a/src/main/java/pw/yumc/MiaoChat/MiaoChatBungee.java
+++ b/src/main/java/pw/yumc/MiaoChat/MiaoChatBungee.java
@@ -1,19 +1,28 @@
package pw.yumc.MiaoChat;
+import java.net.InetSocketAddress;
+import java.util.*;
+
+import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.event.PluginMessageEvent;
+import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin;
+import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.event.EventHandler;
-
-import java.net.InetSocketAddress;
+import pw.yumc.MiaoChat.bungee.FileConfig;
+import pw.yumc.MiaoChat.bungee.Log;
public class MiaoChatBungee extends Plugin implements Listener {
+ private Map> groups;
+ private FileConfig config;
+
@EventHandler
public void handle(final PluginMessageEvent event) {
if (event.getTag().equals(MiaoMessage.CHANNEL) || event.getTag().equals(MiaoMessage.NORMALCHANNEL)) {
InetSocketAddress origin = event.getSender().getAddress();
- for (ServerInfo server : getProxy().getServers().values()) {
+ for (ServerInfo server : groups.get(origin)) {
if (!server.getAddress().equals(origin) && server.getPlayers().size() > 0) {
server.sendData(event.getTag(), event.getData());
}
@@ -21,11 +30,61 @@ public class MiaoChatBungee extends Plugin implements Listener {
}
}
+ @Override
+ public void onLoad() {
+ Log.init(this);
+ config = new FileConfig(this, "group.yml");
+ }
+
+ public void loadGroup() {
+ groups = new HashMap<>();
+ Map temp = getProxy().getServers();
+ Set unused = new HashSet<>();
+ Configuration groupSel = config.getSection("Groups");
+ Collection groupname = groupSel.getKeys();
+ for (String gname : groupname) {
+ Set servers = new HashSet<>(groupSel.getStringList(gname));
+ Set sers = new HashSet<>();
+ for (String sname : servers) {
+ sers.add(temp.get(sname));
+ }
+ sers.remove(null);
+ for (String sname : servers) {
+ ServerInfo isadd = temp.get(sname);
+ if (isadd != null) {
+ unused.remove(isadd);
+ groups.put(isadd.getAddress(), sers);
+ }
+ }
+ }
+ for (ServerInfo unser : unused) {
+ groups.put(unser.getAddress(), unused);
+ }
+ }
+
@Override
public void onEnable() {
+ loadGroup();
getProxy().registerChannel(MiaoMessage.CHANNEL);
getProxy().registerChannel(MiaoMessage.NORMALCHANNEL);
getProxy().getPluginManager().registerListener(this, this);
+ getProxy().getPluginManager().registerCommand(this, new Command("MiaoChat", "MiaoChat.admin", "mct") {
+ @Override
+ public void execute(CommandSender commandSender, String[] args) {
+ if (args.length > 0) {
+ switch (args[0].toLowerCase()) {
+ case "reload":
+ config.reload();
+ loadGroup();
+ commandSender.sendMessage("§a配置文件已重载!");
+ return;
+ case "version":
+ default:
+ }
+ }
+ commandSender.sendMessage("§6插件版本: §av" + getDescription().getVersion());
+ }
+ });
getLogger().info("注意: 通过BC转发的聊天信息将不会在控制台显示 仅客户端可见!");
}
}
diff --git a/src/main/java/pw/yumc/MiaoChat/bungee/FileConfig.java b/src/main/java/pw/yumc/MiaoChat/bungee/FileConfig.java
new file mode 100644
index 0000000..05a800c
--- /dev/null
+++ b/src/main/java/pw/yumc/MiaoChat/bungee/FileConfig.java
@@ -0,0 +1,208 @@
+package pw.yumc.MiaoChat.bungee;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.Collection;
+import java.util.List;
+
+import net.md_5.bungee.api.plugin.Plugin;
+import net.md_5.bungee.config.Configuration;
+import net.md_5.bungee.config.ConfigurationProvider;
+import net.md_5.bungee.config.YamlConfiguration;
+
+/**
+ *
+ * Created by 蒋天蓓 on 2016/11/7 0007.
+ */
+public class FileConfig {
+ private File file;
+ private Configuration config;
+
+ public FileConfig(Plugin plugin) {
+ this(plugin, "config.yml");
+ }
+
+ public T get(String path, T def) {
+ return config.get(path, def);
+ }
+
+ public boolean contains(String path) {
+ return config.contains(path);
+ }
+
+ public Object get(String path) {
+ return config.get(path);
+ }
+
+ public Object getDefault(String path) {
+ return config.getDefault(path);
+ }
+
+ public void set(String path, Object value) {
+ config.set(path, value);
+ }
+
+ public Configuration getSection(String path) {
+ return config.getSection(path);
+ }
+
+ public Collection getKeys() {
+ return config.getKeys();
+ }
+
+ public byte getByte(String path) {
+ return config.getByte(path);
+ }
+
+ public byte getByte(String path, byte def) {
+ return config.getByte(path, def);
+ }
+
+ public List getByteList(String path) {
+ return config.getByteList(path);
+ }
+
+ public short getShort(String path) {
+ return config.getShort(path);
+ }
+
+ public short getShort(String path, short def) {
+ return config.getShort(path, def);
+ }
+
+ public List getShortList(String path) {
+ return config.getShortList(path);
+ }
+
+ public int getInt(String path) {
+ return config.getInt(path);
+ }
+
+ public int getInt(String path, int def) {
+ return config.getInt(path, def);
+ }
+
+ public List getIntList(String path) {
+ return config.getIntList(path);
+ }
+
+ public long getLong(String path) {
+ return config.getLong(path);
+ }
+
+ public long getLong(String path, long def) {
+ return config.getLong(path, def);
+ }
+
+ public List getLongList(String path) {
+ return config.getLongList(path);
+ }
+
+ public float getFloat(String path) {
+ return config.getFloat(path);
+ }
+
+ public float getFloat(String path, float def) {
+ return config.getFloat(path, def);
+ }
+
+ public List getFloatList(String path) {
+ return config.getFloatList(path);
+ }
+
+ public double getDouble(String path) {
+ return config.getDouble(path);
+ }
+
+ public double getDouble(String path, double def) {
+ return config.getDouble(path, def);
+ }
+
+ public List getDoubleList(String path) {
+ return config.getDoubleList(path);
+ }
+
+ public boolean getBoolean(String path) {
+ return config.getBoolean(path);
+ }
+
+ public boolean getBoolean(String path, boolean def) {
+ return config.getBoolean(path, def);
+ }
+
+ public List getBooleanList(String path) {
+ return config.getBooleanList(path);
+ }
+
+ public char getChar(String path) {
+ return config.getChar(path);
+ }
+
+ public char getChar(String path, char def) {
+ return config.getChar(path, def);
+ }
+
+ public List getCharList(String path) {
+ return config.getCharList(path);
+ }
+
+ public String getString(String path) {
+ return config.getString(path);
+ }
+
+ public String getString(String path, String def) {
+ return config.getString(path, def);
+ }
+
+ public List getStringList(String path) {
+ return config.getStringList(path);
+ }
+
+ public List> getList(String path) {
+ return config.getList(path);
+ }
+
+ public List> getList(String path, List> def) {
+ return config.getList(path, def);
+ }
+
+ public FileConfig(Plugin plugin, String name) {
+ this.file = new File(plugin.getDataFolder(), name);
+ try {
+ if (!file.exists()) {
+ if (!file.getParentFile().exists()) {
+ file.getParentFile().mkdirs();
+ }
+ Files.copy(plugin.getResourceAsStream(name), file.toPath());
+ }
+ this.config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
+ } catch (IOException e) {
+ Log.w("配置文件读取失败!");
+ e.printStackTrace();
+ }
+ }
+
+ public Configuration getConfig() {
+ return config;
+ }
+
+ public void save() {
+ try {
+ ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, file);
+ } catch (IOException e) {
+ Log.w("配置文件保存失败!");
+ e.printStackTrace();
+ }
+ }
+
+ public void reload() {
+ try {
+ this.config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
+ } catch (IOException e) {
+ Log.w("配置文件读取失败!");
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/main/java/pw/yumc/MiaoChat/bungee/Log.java b/src/main/java/pw/yumc/MiaoChat/bungee/Log.java
new file mode 100644
index 0000000..12fe61f
--- /dev/null
+++ b/src/main/java/pw/yumc/MiaoChat/bungee/Log.java
@@ -0,0 +1,49 @@
+package pw.yumc.MiaoChat.bungee;
+
+import java.util.logging.Logger;
+
+import net.md_5.bungee.api.plugin.Plugin;
+
+/**
+ * 插件日志输出类
+ *
+ * @author 喵♂呜
+ * @since 2016年7月23日 上午9:11:01
+ */
+public class Log {
+ private static boolean debug = false;
+ public static Plugin plugin;
+ public static Logger logger;
+
+ public static void init(Plugin plugin) {
+ Log.plugin = plugin;
+ Log.logger = plugin.getLogger();
+ }
+
+ public static void d(String s, Exception e) {
+ if (debug) {
+ logger.info(s);
+ e.printStackTrace();
+ }
+ }
+
+ public static void i(String s, Object... objects) {
+ logger.info(String.format(s, objects));
+ }
+
+ public static void d(String s) {
+ if (debug) {
+ logger.info(s);
+ }
+ }
+
+ public static void d(Exception e) {
+ if (debug) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void w(String s, Object... objects) {
+ logger.warning(String.format(s, objects));
+ }
+}
diff --git a/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java b/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java
index 24ba714..e32dcfa 100644
--- a/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java
+++ b/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java
@@ -1,12 +1,13 @@
package pw.yumc.MiaoChat.config;
+import java.util.*;
+
import org.bukkit.entity.Player;
+
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.bukkit.P;
import pw.yumc.YumCore.config.FileConfig;
-import java.util.*;
-
/**
*
* @since 2016年9月9日 下午4:40:50
@@ -19,6 +20,7 @@ public class ChatConfig {
private LinkedList rules;
private FileConfig config;
private FileConfig format;
+ private String servername;
private boolean BungeeCord;
public ChatConfig() {
@@ -52,11 +54,12 @@ public class ChatConfig {
return null;
}
- public ChatMessagePart getFormat(String name) {
- return formats.get(name);
+ public Map getFormats() {
+ return formats;
}
public void load() {
+ servername = config.getMessage("Server");
formats.clear();
for (String name : format.getKeys(false)) {
formats.put(name, new ChatMessagePart(format.getConfigurationSection(name)));
@@ -72,6 +75,10 @@ public class ChatConfig {
Collections.sort(rules, rulecomp);
}
+ public String getServername() {
+ return servername;
+ }
+
public void reload() {
format.reload();
load();
diff --git a/src/main/java/pw/yumc/MiaoChat/config/ChatMessagePart.java b/src/main/java/pw/yumc/MiaoChat/config/ChatMessagePart.java
index e47965e..b2afc33 100644
--- a/src/main/java/pw/yumc/MiaoChat/config/ChatMessagePart.java
+++ b/src/main/java/pw/yumc/MiaoChat/config/ChatMessagePart.java
@@ -39,16 +39,11 @@ public class ChatMessagePart extends InjectConfigurationSection {
String tc = f(p, command);
switch (type) {
case COMMAND:
- tr.command(tc);
- break;
+ return tr.command(tc);
case OPENURL:
- tr.openurl(tc);
- break;
+ return tr.openurl(tc);
case SUGGEST:
- tr.suggest(tc);
- break;
- default:
- break;
+ return tr.suggest(tc);
}
}
return tr;
diff --git a/src/main/java/pw/yumc/MiaoChat/config/ChatRule.java b/src/main/java/pw/yumc/MiaoChat/config/ChatRule.java
index 84c91ad..15a394a 100644
--- a/src/main/java/pw/yumc/MiaoChat/config/ChatRule.java
+++ b/src/main/java/pw/yumc/MiaoChat/config/ChatRule.java
@@ -8,8 +8,12 @@ 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;
/**
* 聊天规则
@@ -18,6 +22,7 @@ import pw.yumc.YumCore.config.inject.InjectConfigurationSection;
* @author 喵♂呜
*/
public class ChatRule extends InjectConfigurationSection {
+ private transient static MiaoChat plugin = P.getPlugin();
private transient static Pattern FORMAT_PATTERN = Pattern.compile("[\\[]([^\\[\\]]+)[]]");
private transient String name;
@Default("50")
@@ -88,6 +93,21 @@ public class ChatRule extends InjectConfigurationSection {
return item;
}
+ public Tellraw create(Player p) {
+ Tellraw tr = Tellraw.create();
+ for (String format : formats) {
+ ChatMessagePart cmp = plugin.getChatConfig().getFormats().get(format);
+ if (cmp != null) {
+ // Log.d("解析格式: %s", format);
+ cmp.then(tr, p);
+ } else {
+ // Log.d("追加文本: %s", format);
+ tr.then(PlaceholderAPI.setPlaceholders(p, format));
+ }
+ }
+ return tr;
+ }
+
private void load() {
formats = new LinkedList<>();
Matcher m = FORMAT_PATTERN.matcher(format);
diff --git a/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java b/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java
index 8037127..3cfe297 100644
--- a/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java
+++ b/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java
@@ -15,11 +15,9 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.inventory.ItemStack;
-import me.clip.placeholderapi.PlaceholderAPI;
import pw.yumc.MiaoChat.MiaoChat;
import pw.yumc.MiaoChat.MiaoMessage;
import pw.yumc.MiaoChat.config.ChatConfig;
-import pw.yumc.MiaoChat.config.ChatMessagePart;
import pw.yumc.MiaoChat.config.ChatRule;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.bukkit.P;
@@ -53,30 +51,12 @@ public class ChatListener implements Listener {
return;
}
e.setCancelled(true);
- handleChat(p, Tellraw.create(), cr, e.getMessage());
+ handleChat(p, cr, e.getMessage());
}
- private void handleChat(Player p, Tellraw tr, ChatRule cr, String message) {
+ private void handleChat(Player p, 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 String handleFormat(Player p, Tellraw tr, ChatRule cr) {
- LinkedList formats = cr.getFormats();
- // Log.d("处理前缀信息...");
- for (String format : formats) {
- ChatMessagePart cmp = cc.getFormat(format);
- if (cmp != null) {
- // Log.d("解析格式: %s", format);
- cmp.then(tr, p);
- } else {
- // Log.d("追加文本: %s", format);
- tr.then(PlaceholderAPI.setPlaceholders(p, format));
- }
- }
- return ChatColor.getLastColors(formats.isEmpty() ? "§r" : formats.getLast());
+ handleSend(p, handleTellraw(p, cr.create(p), cr, message), cr.getRange());
}
private LinkedList handleMessage(LinkedList il, String message) {
@@ -121,12 +101,16 @@ public class ChatListener implements Listener {
}
private void handleSend(Player p, Tellraw tr, int range) {
- Collection extends Entity> plist;
+ List plist = new ArrayList<>();
if (range != 0) {
- plist = p.getNearbyEntities(range, range, range);
- tr.send(p);
+ for (Entity ent : p.getNearbyEntities(range, range, range)) {
+ if (ent instanceof Player) {
+ plist.add((Player) ent);
+ }
+ }
+ plist.add(p);
} else {
- plist = C.Player.getOnlinePlayers();
+ plist.addAll(C.Player.getOnlinePlayers());
if (cc.isBungeeCord()) {
byte[] mm = MiaoMessage.encode(tr.toJsonString());
if (mm == null) {
@@ -136,29 +120,28 @@ public class ChatListener implements Listener {
}
}
}
- for (Entity ne : plist) {
- // 此处必须进行强制转换 老版本服务器的Entity没有getName()
- if (ne instanceof Player && !offList.contains(((Player) ne).getName())) {
- tr.send(ne);
+ for (Player player : plist) {
+ if (!offList.contains(player.getName())) {
+ tr.send(player);
}
}
Bukkit.getConsoleSender().sendMessage(tr.toOldMessageFormat());
}
- private void handleTellraw(Player player, Tellraw tr, ChatRule cr, String message) {
- if (message.isEmpty()) { return; }
+ private Tellraw handleTellraw(Player player, Tellraw tr, ChatRule cr, String message) {
+ if (message.isEmpty()) { return tr; }
if (player.hasPermission("MiaoChat.color")) {
message = ChatColor.translateAlternateColorCodes('&', message);
}
if (!cr.isItem()) {
tr.then(message);
- return;
+ return tr;
}
LinkedList il = handlePattern(message);
// 如果返回null说明存在相同的物品
if (il == null) {
- Log.toSender(player, "§c不允许展示相同的物品!");
- return;
+ Log.sender(player, "§c不允许展示相同的物品!");
+ return tr;
}
LinkedList ml = handleMessage(il, message);
// Log.d("处理Tellraw格式...");
@@ -177,5 +160,6 @@ public class ChatListener implements Listener {
tr.then(cr.getLastColor() + mm);
}
}
+ return tr;
}
}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index e67f9b4..9270479 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -1,8 +1,10 @@
#配置文件版本号 请勿修改
-Version: 1.3
+Version: 1.6
#BC跨服模式
BungeeCord: true
+#当前服务器名称(变量为%mct_server%)
+Server: '§a生存服'
#格式列表
Formats:
#格式名称 对应当前文件夹下的default.yml
diff --git a/src/main/resources/group.yml b/src/main/resources/group.yml
new file mode 100644
index 0000000..95982d5
--- /dev/null
+++ b/src/main/resources/group.yml
@@ -0,0 +1,15 @@
+#配置版本号 请勿修改
+Version: 1.0
+
+#跨服分组
+#注: 未在分组内的服务器会被分配到独立的一组
+#注: 内部分组名称为 ungroup 下方如有定义将无效
+Groups:
+ #普通分组
+ normal:
+ - 'sc1'
+ - 'sc2'
+ #游戏分组
+ games:
+ - 'bw1'
+ - 'sg1'
\ No newline at end of file