commit
0d26ad7e53
Binary file not shown.
22
pom.xml
22
pom.xml
|
@ -3,7 +3,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>pw.yumc</groupId>
|
<groupId>pw.yumc</groupId>
|
||||||
<artifactId>MiaoChat</artifactId>
|
<artifactId>MiaoChat</artifactId>
|
||||||
<version>1.5.1</version>
|
<version>1.6</version>
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.name}</finalName>
|
<finalName>${project.name}</finalName>
|
||||||
<resources>
|
<resources>
|
||||||
|
@ -13,14 +13,6 @@
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.3</version>
|
|
||||||
<configuration>
|
|
||||||
<source>1.7</source>
|
|
||||||
<target>1.7</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
@ -78,16 +70,12 @@
|
||||||
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
|
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
|
||||||
</ciManagement>
|
</ciManagement>
|
||||||
<properties>
|
<properties>
|
||||||
<update.description></update.description>
|
<env.GIT_COMMIT>DEV</env.GIT_COMMIT>
|
||||||
<update.changes></update.changes>
|
|
||||||
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>1.7</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.7</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
|
||||||
<id>spigot-repo</id>
|
|
||||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>yumc-repo</id>
|
<id>yumc-repo</id>
|
||||||
<url>http://repo.yumc.pw/content/groups/public/</url>
|
<url>http://repo.yumc.pw/content/groups/public/</url>
|
||||||
|
@ -105,7 +93,7 @@
|
||||||
<groupId>pw.yumc</groupId>
|
<groupId>pw.yumc</groupId>
|
||||||
<artifactId>YumCore</artifactId>
|
<artifactId>YumCore</artifactId>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<version>1.2</version>
|
<version>1.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
|
@ -6,7 +6,7 @@
|
||||||
-dontnote
|
-dontnote
|
||||||
|
|
||||||
# -----混淆时应用侵入式重载-----
|
# -----混淆时应用侵入式重载-----
|
||||||
-overloadaggressively
|
-overloadaggressively
|
||||||
|
|
||||||
# -----启用混淆字典-----
|
# -----启用混淆字典-----
|
||||||
-obfuscationdictionary obf.dict
|
-obfuscationdictionary obf.dict
|
||||||
|
@ -16,38 +16,36 @@
|
||||||
# -----保留所有属性
|
# -----保留所有属性
|
||||||
-keepattributes **
|
-keepattributes **
|
||||||
|
|
||||||
# -----公共数据不混淆-----
|
|
||||||
-keep class cn.citycraft.CommonData.** {*;}
|
|
||||||
|
|
||||||
# -----保护所有实体中的字段名称-----
|
# -----保护所有实体中的字段名称-----
|
||||||
-keepclassmembers class * implements java.io.Serializable { <fields>; }
|
-keepclassmembers class * implements java.io.Serializable {<fields>;}
|
||||||
|
|
||||||
# -----保护监听方法不被清理-----
|
# -----保护监听方法不被清理-----
|
||||||
-keepclassmembers class * implements org.bukkit.event.Listener {
|
-keepclassmembers class * implements org.bukkit.event.Listener {
|
||||||
@org.bukkit.event.EventHandler <methods>;
|
@org.bukkit.event.EventHandler <methods>;
|
||||||
}
|
}
|
||||||
-keepclassmembers class * implements net.md_5.bungee.api.plugin.Listener {
|
-keepclassmembers class * implements net.md_5.bungee.api.plugin.Listener {
|
||||||
@net.md_5.bungee.event.EventHandler <methods>;
|
@net.md_5.bungee.event.EventHandler <methods>;
|
||||||
}
|
}
|
||||||
|
|
||||||
# -----保护枚举方法的完整性-----
|
# -----保护枚举方法的完整性-----
|
||||||
-keepclassmembers enum * {
|
-keepclassmembers enum * {
|
||||||
public static **[] values();
|
public static **[] values();
|
||||||
public static ** valueOf(java.lang.String);
|
public static ** valueOf(java.lang.String);
|
||||||
}
|
}
|
||||||
|
|
||||||
# -----保护配置注入不被清理-----
|
# -----保护配置注入不被清理-----
|
||||||
-keepclassmembers class * extends **.config**Inject** {
|
-keepclassmembers class * extends **.config.inject.Inject** {
|
||||||
<fields>;
|
<fields>;
|
||||||
}
|
}
|
||||||
|
|
||||||
# -----保护注解命令方法不被清理-----
|
# -----保护注解命令方法不被清理-----
|
||||||
-keepclassmembers class **.commands.annotation.** { <methods>; }
|
-keepclassmembers class **.commands.annotation.** {<methods>;}
|
||||||
-keepclassmembers class * implements **.commands**CommandExecutor { <methods>; }
|
-keepclassmembers class * implements **.commands.interfaces.Executor {<methods>;}
|
||||||
|
|
||||||
# -----保护注解NotProguard标记-----
|
# -----保护注解NotProguard标记-----
|
||||||
-keep class **.NotProguard
|
-keep class **.NotProguard
|
||||||
-keep @**.NotProguard class * {*;}
|
-keep @**.NotProguard class * {*;}
|
||||||
-keepclassmembers class * {
|
-keepclassmembers class * {
|
||||||
@**.NotProguard <fields>;
|
@**.NotProguard <fields>;
|
||||||
@**.NotProguard <methods>;
|
@**.NotProguard <methods>;
|
||||||
}
|
}
|
|
@ -5,23 +5,34 @@ import org.bukkit.Material;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
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.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
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.config.ChatConfig;
|
||||||
import pw.yumc.MiaoChat.listeners.ChatListener;
|
import pw.yumc.MiaoChat.listeners.ChatListener;
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
import pw.yumc.YumCore.bukkit.compatible.C;
|
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.Cmd;
|
||||||
import pw.yumc.YumCore.commands.annotation.Help;
|
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.config.FileConfig;
|
||||||
import pw.yumc.YumCore.global.L10N;
|
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 FileConfig cfg;
|
||||||
private ChatConfig chatConfig;
|
private ChatConfig chatConfig;
|
||||||
|
private String ServerName;
|
||||||
|
|
||||||
public ChatConfig getChatConfig() {
|
public ChatConfig getChatConfig() {
|
||||||
return chatConfig;
|
return chatConfig;
|
||||||
|
@ -36,27 +47,42 @@ public class MiaoChat extends JavaPlugin implements CommandExecutor, PluginMessa
|
||||||
@Help("关闭聊天功能")
|
@Help("关闭聊天功能")
|
||||||
public void off(CommandSender sender) {
|
public void off(CommandSender sender) {
|
||||||
ChatListener.offList.add(sender.getName());
|
ChatListener.offList.add(sender.getName());
|
||||||
Log.toSender(sender, "§c聊天功能已关闭!");
|
Log.sender(sender, "§c聊天功能已关闭!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cmd(permission = "MiaoChat.toggle")
|
@Cmd(permission = "MiaoChat.toggle")
|
||||||
@Help("开启聊天功能")
|
@Help("开启聊天功能")
|
||||||
public void on(CommandSender sender) {
|
public void on(CommandSender sender) {
|
||||||
ChatListener.offList.remove(sender.getName());
|
ChatListener.offList.remove(sender.getName());
|
||||||
Log.toSender(sender, "§a聊天功能已开启!");
|
Log.sender(sender, "§a聊天功能已开启!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
new ChatListener();
|
new ChatListener();
|
||||||
new CommandManager("MiaoChat", this);
|
new CommandSub("MiaoChat", this);
|
||||||
if (getChatConfig().isBungeeCord()) {
|
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().registerIncomingPluginChannel(this, MiaoMessage.CHANNEL, this);
|
||||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, MiaoMessage.CHANNEL);
|
Bukkit.getMessenger().registerOutgoingPluginChannel(this, MiaoMessage.CHANNEL);
|
||||||
Bukkit.getMessenger().registerIncomingPluginChannel(this, MiaoMessage.NORMALCHANNEL, this);
|
Bukkit.getMessenger().registerIncomingPluginChannel(this, MiaoMessage.NORMALCHANNEL, this);
|
||||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, MiaoMessage.NORMALCHANNEL);
|
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));
|
L10N.getName(new ItemStack(Material.AIR));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +97,7 @@ public class MiaoChat extends JavaPlugin implements CommandExecutor, PluginMessa
|
||||||
public void reload(CommandSender sender) {
|
public void reload(CommandSender sender) {
|
||||||
cfg.reload();
|
cfg.reload();
|
||||||
chatConfig.reload();
|
chatConfig.reload();
|
||||||
Log.toSender(sender, "§a配置文件已重载!");
|
Log.sender(sender, "§a配置文件已重载!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void send(byte[] in) {
|
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
|
@Override
|
||||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||||
if (MiaoMessage.CHANNEL.equals(channel)) {
|
if (MiaoMessage.CHANNEL.equals(channel)) {
|
||||||
|
@ -92,6 +133,20 @@ public class MiaoChat extends JavaPlugin implements CommandExecutor, PluginMessa
|
||||||
for (Player p : C.Player.getOnlinePlayers()) {
|
for (Player p : C.Player.getOnlinePlayers()) {
|
||||||
p.sendMessage(MiaoMessage.decode(message).getJson());
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,28 @@
|
||||||
package pw.yumc.MiaoChat;
|
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.config.ServerInfo;
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
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.Listener;
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
import net.md_5.bungee.config.Configuration;
|
||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
import pw.yumc.MiaoChat.bungee.FileConfig;
|
||||||
import java.net.InetSocketAddress;
|
import pw.yumc.MiaoChat.bungee.Log;
|
||||||
|
|
||||||
public class MiaoChatBungee extends Plugin implements Listener {
|
public class MiaoChatBungee extends Plugin implements Listener {
|
||||||
|
private Map<InetSocketAddress, Set<ServerInfo>> groups;
|
||||||
|
private FileConfig config;
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void handle(final PluginMessageEvent event) {
|
public void handle(final PluginMessageEvent event) {
|
||||||
if (event.getTag().equals(MiaoMessage.CHANNEL) || event.getTag().equals(MiaoMessage.NORMALCHANNEL)) {
|
if (event.getTag().equals(MiaoMessage.CHANNEL) || event.getTag().equals(MiaoMessage.NORMALCHANNEL)) {
|
||||||
InetSocketAddress origin = event.getSender().getAddress();
|
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) {
|
if (!server.getAddress().equals(origin) && server.getPlayers().size() > 0) {
|
||||||
server.sendData(event.getTag(), event.getData());
|
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<String, ServerInfo> temp = getProxy().getServers();
|
||||||
|
Set<ServerInfo> unused = new HashSet<>();
|
||||||
|
Configuration groupSel = config.getSection("Groups");
|
||||||
|
Collection<String> groupname = groupSel.getKeys();
|
||||||
|
for (String gname : groupname) {
|
||||||
|
Set<String> servers = new HashSet<>(groupSel.getStringList(gname));
|
||||||
|
Set<ServerInfo> 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
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
loadGroup();
|
||||||
getProxy().registerChannel(MiaoMessage.CHANNEL);
|
getProxy().registerChannel(MiaoMessage.CHANNEL);
|
||||||
getProxy().registerChannel(MiaoMessage.NORMALCHANNEL);
|
getProxy().registerChannel(MiaoMessage.NORMALCHANNEL);
|
||||||
getProxy().getPluginManager().registerListener(this, this);
|
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转发的聊天信息将不会在控制台显示 仅客户端可见!");
|
getLogger().info("注意: 通过BC转发的聊天信息将不会在控制台显示 仅客户端可见!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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> 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<String> 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<Byte> 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<Short> 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<Integer> 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<Long> 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<Float> 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<Double> 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<Boolean> 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<Character> 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<String> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,12 +1,13 @@
|
||||||
package pw.yumc.MiaoChat.config;
|
package pw.yumc.MiaoChat.config;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
import pw.yumc.YumCore.bukkit.P;
|
import pw.yumc.YumCore.bukkit.P;
|
||||||
import pw.yumc.YumCore.config.FileConfig;
|
import pw.yumc.YumCore.config.FileConfig;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @since 2016年9月9日 下午4:40:50
|
* @since 2016年9月9日 下午4:40:50
|
||||||
|
@ -19,6 +20,7 @@ public class ChatConfig {
|
||||||
private LinkedList<ChatRule> rules;
|
private LinkedList<ChatRule> rules;
|
||||||
private FileConfig config;
|
private FileConfig config;
|
||||||
private FileConfig format;
|
private FileConfig format;
|
||||||
|
private String servername;
|
||||||
private boolean BungeeCord;
|
private boolean BungeeCord;
|
||||||
|
|
||||||
public ChatConfig() {
|
public ChatConfig() {
|
||||||
|
@ -52,11 +54,12 @@ public class ChatConfig {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChatMessagePart getFormat(String name) {
|
public Map<String, ChatMessagePart> getFormats() {
|
||||||
return formats.get(name);
|
return formats;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void load() {
|
public void load() {
|
||||||
|
servername = config.getMessage("Server");
|
||||||
formats.clear();
|
formats.clear();
|
||||||
for (String name : format.getKeys(false)) {
|
for (String name : format.getKeys(false)) {
|
||||||
formats.put(name, new ChatMessagePart(format.getConfigurationSection(name)));
|
formats.put(name, new ChatMessagePart(format.getConfigurationSection(name)));
|
||||||
|
@ -72,6 +75,10 @@ public class ChatConfig {
|
||||||
Collections.sort(rules, rulecomp);
|
Collections.sort(rules, rulecomp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getServername() {
|
||||||
|
return servername;
|
||||||
|
}
|
||||||
|
|
||||||
public void reload() {
|
public void reload() {
|
||||||
format.reload();
|
format.reload();
|
||||||
load();
|
load();
|
||||||
|
|
|
@ -39,16 +39,11 @@ public class ChatMessagePart extends InjectConfigurationSection {
|
||||||
String tc = f(p, command);
|
String tc = f(p, command);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case COMMAND:
|
case COMMAND:
|
||||||
tr.command(tc);
|
return tr.command(tc);
|
||||||
break;
|
|
||||||
case OPENURL:
|
case OPENURL:
|
||||||
tr.openurl(tc);
|
return tr.openurl(tc);
|
||||||
break;
|
|
||||||
case SUGGEST:
|
case SUGGEST:
|
||||||
tr.suggest(tc);
|
return tr.suggest(tc);
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tr;
|
return tr;
|
||||||
|
|
|
@ -8,8 +8,12 @@ import org.bukkit.ChatColor;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
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.annotation.Default;
|
||||||
import pw.yumc.YumCore.config.inject.InjectConfigurationSection;
|
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 喵♂呜
|
* @author 喵♂呜
|
||||||
*/
|
*/
|
||||||
public class ChatRule extends InjectConfigurationSection {
|
public class ChatRule extends InjectConfigurationSection {
|
||||||
|
private transient static MiaoChat plugin = P.getPlugin();
|
||||||
private transient static Pattern FORMAT_PATTERN = Pattern.compile("[\\[]([^\\[\\]]+)[]]");
|
private transient static Pattern FORMAT_PATTERN = Pattern.compile("[\\[]([^\\[\\]]+)[]]");
|
||||||
private transient String name;
|
private transient String name;
|
||||||
@Default("50")
|
@Default("50")
|
||||||
|
@ -88,6 +93,21 @@ public class ChatRule extends InjectConfigurationSection {
|
||||||
return item;
|
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() {
|
private void load() {
|
||||||
formats = new LinkedList<>();
|
formats = new LinkedList<>();
|
||||||
Matcher m = FORMAT_PATTERN.matcher(format);
|
Matcher m = FORMAT_PATTERN.matcher(format);
|
||||||
|
|
|
@ -15,11 +15,9 @@ import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
|
||||||
import pw.yumc.MiaoChat.MiaoChat;
|
import pw.yumc.MiaoChat.MiaoChat;
|
||||||
import pw.yumc.MiaoChat.MiaoMessage;
|
import pw.yumc.MiaoChat.MiaoMessage;
|
||||||
import pw.yumc.MiaoChat.config.ChatConfig;
|
import pw.yumc.MiaoChat.config.ChatConfig;
|
||||||
import pw.yumc.MiaoChat.config.ChatMessagePart;
|
|
||||||
import pw.yumc.MiaoChat.config.ChatRule;
|
import pw.yumc.MiaoChat.config.ChatRule;
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
import pw.yumc.YumCore.bukkit.P;
|
import pw.yumc.YumCore.bukkit.P;
|
||||||
|
@ -53,30 +51,12 @@ public class ChatListener implements Listener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e.setCancelled(true);
|
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);
|
// Log.d("玩家: %s 使用 %s 规则 解析 %s", p.getName(), cr.getName(), message);
|
||||||
handleFormat(p, tr, cr);
|
handleSend(p, handleTellraw(p, cr.create(p), cr, message), cr.getRange());
|
||||||
handleTellraw(p, tr, cr, message);
|
|
||||||
handleSend(p, tr, cr.getRange());
|
|
||||||
}
|
|
||||||
|
|
||||||
private String handleFormat(Player p, Tellraw tr, ChatRule cr) {
|
|
||||||
LinkedList<String> 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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private LinkedList<String> handleMessage(LinkedList<String> il, String message) {
|
private LinkedList<String> handleMessage(LinkedList<String> il, String message) {
|
||||||
|
@ -121,12 +101,16 @@ public class ChatListener implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleSend(Player p, Tellraw tr, int range) {
|
private void handleSend(Player p, Tellraw tr, int range) {
|
||||||
Collection<? extends Entity> plist;
|
List<Player> plist = new ArrayList<>();
|
||||||
if (range != 0) {
|
if (range != 0) {
|
||||||
plist = p.getNearbyEntities(range, range, range);
|
for (Entity ent : p.getNearbyEntities(range, range, range)) {
|
||||||
tr.send(p);
|
if (ent instanceof Player) {
|
||||||
|
plist.add((Player) ent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
plist.add(p);
|
||||||
} else {
|
} else {
|
||||||
plist = C.Player.getOnlinePlayers();
|
plist.addAll(C.Player.getOnlinePlayers());
|
||||||
if (cc.isBungeeCord()) {
|
if (cc.isBungeeCord()) {
|
||||||
byte[] mm = MiaoMessage.encode(tr.toJsonString());
|
byte[] mm = MiaoMessage.encode(tr.toJsonString());
|
||||||
if (mm == null) {
|
if (mm == null) {
|
||||||
|
@ -136,29 +120,28 @@ public class ChatListener implements Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entity ne : plist) {
|
for (Player player : plist) {
|
||||||
// 此处必须进行强制转换 老版本服务器的Entity没有getName()
|
if (!offList.contains(player.getName())) {
|
||||||
if (ne instanceof Player && !offList.contains(((Player) ne).getName())) {
|
tr.send(player);
|
||||||
tr.send(ne);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Bukkit.getConsoleSender().sendMessage(tr.toOldMessageFormat());
|
Bukkit.getConsoleSender().sendMessage(tr.toOldMessageFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleTellraw(Player player, Tellraw tr, ChatRule cr, String message) {
|
private Tellraw handleTellraw(Player player, Tellraw tr, ChatRule cr, String message) {
|
||||||
if (message.isEmpty()) { return; }
|
if (message.isEmpty()) { return tr; }
|
||||||
if (player.hasPermission("MiaoChat.color")) {
|
if (player.hasPermission("MiaoChat.color")) {
|
||||||
message = ChatColor.translateAlternateColorCodes('&', message);
|
message = ChatColor.translateAlternateColorCodes('&', message);
|
||||||
}
|
}
|
||||||
if (!cr.isItem()) {
|
if (!cr.isItem()) {
|
||||||
tr.then(message);
|
tr.then(message);
|
||||||
return;
|
return tr;
|
||||||
}
|
}
|
||||||
LinkedList<String> il = handlePattern(message);
|
LinkedList<String> il = handlePattern(message);
|
||||||
// 如果返回null说明存在相同的物品
|
// 如果返回null说明存在相同的物品
|
||||||
if (il == null) {
|
if (il == null) {
|
||||||
Log.toSender(player, "§c不允许展示相同的物品!");
|
Log.sender(player, "§c不允许展示相同的物品!");
|
||||||
return;
|
return tr;
|
||||||
}
|
}
|
||||||
LinkedList<String> ml = handleMessage(il, message);
|
LinkedList<String> ml = handleMessage(il, message);
|
||||||
// Log.d("处理Tellraw格式...");
|
// Log.d("处理Tellraw格式...");
|
||||||
|
@ -177,5 +160,6 @@ public class ChatListener implements Listener {
|
||||||
tr.then(cr.getLastColor() + mm);
|
tr.then(cr.getLastColor() + mm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return tr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
#配置文件版本号 请勿修改
|
#配置文件版本号 请勿修改
|
||||||
Version: 1.3
|
Version: 1.6
|
||||||
|
|
||||||
#BC跨服模式
|
#BC跨服模式
|
||||||
BungeeCord: true
|
BungeeCord: true
|
||||||
|
#当前服务器名称(变量为%mct_server%)
|
||||||
|
Server: '§a生存服'
|
||||||
#格式列表
|
#格式列表
|
||||||
Formats:
|
Formats:
|
||||||
#格式名称 对应当前文件夹下的default.yml
|
#格式名称 对应当前文件夹下的default.yml
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
#配置版本号 请勿修改
|
||||||
|
Version: 1.0
|
||||||
|
|
||||||
|
#跨服分组
|
||||||
|
#注: 未在分组内的服务器会被分配到独立的一组
|
||||||
|
#注: 内部分组名称为 ungroup 下方如有定义将无效
|
||||||
|
Groups:
|
||||||
|
#普通分组
|
||||||
|
normal:
|
||||||
|
- 'sc1'
|
||||||
|
- 'sc2'
|
||||||
|
#游戏分组
|
||||||
|
games:
|
||||||
|
- 'bw1'
|
||||||
|
- 'sg1'
|
Loading…
Reference in New Issue