mirror of
https://e.coding.net/circlecloud/MiaoChat.git
synced 2024-11-16 13:48:47 +00:00
commit
0d26ad7e53
Binary file not shown.
22
pom.xml
22
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>pw.yumc</groupId>
|
||||
<artifactId>MiaoChat</artifactId>
|
||||
<version>1.5.1</version>
|
||||
<version>1.6</version>
|
||||
<build>
|
||||
<finalName>${project.name}</finalName>
|
||||
<resources>
|
||||
@ -13,14 +13,6 @@
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
@ -78,16 +70,12 @@
|
||||
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
|
||||
</ciManagement>
|
||||
<properties>
|
||||
<update.description></update.description>
|
||||
<update.changes></update.changes>
|
||||
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
|
||||
<env.GIT_COMMIT>DEV</env.GIT_COMMIT>
|
||||
<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>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>yumc-repo</id>
|
||||
<url>http://repo.yumc.pw/content/groups/public/</url>
|
||||
@ -105,7 +93,7 @@
|
||||
<groupId>pw.yumc</groupId>
|
||||
<artifactId>YumCore</artifactId>
|
||||
<type>jar</type>
|
||||
<version>1.2</version>
|
||||
<version>1.5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -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 { <fields>; }
|
||||
-keepclassmembers class * implements java.io.Serializable {<fields>;}
|
||||
|
||||
# -----保护监听方法不被清理-----
|
||||
-keepclassmembers class * implements org.bukkit.event.Listener {
|
||||
@org.bukkit.event.EventHandler <methods>;
|
||||
-keepclassmembers class * implements org.bukkit.event.Listener {
|
||||
@org.bukkit.event.EventHandler <methods>;
|
||||
}
|
||||
-keepclassmembers class * implements net.md_5.bungee.api.plugin.Listener {
|
||||
@net.md_5.bungee.event.EventHandler <methods>;
|
||||
}
|
||||
|
||||
# -----保护枚举方法的完整性-----
|
||||
-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** {
|
||||
<fields>;
|
||||
-keepclassmembers class * extends **.config.inject.Inject** {
|
||||
<fields>;
|
||||
}
|
||||
|
||||
# -----保护注解命令方法不被清理-----
|
||||
-keepclassmembers class **.commands.annotation.** { <methods>; }
|
||||
-keepclassmembers class * implements **.commands**CommandExecutor { <methods>; }
|
||||
-keepclassmembers class **.commands.annotation.** {<methods>;}
|
||||
-keepclassmembers class * implements **.commands.interfaces.Executor {<methods>;}
|
||||
|
||||
# -----保护注解NotProguard标记-----
|
||||
-keep class **.NotProguard
|
||||
-keep @**.NotProguard class * {*;}
|
||||
-keepclassmembers class * {
|
||||
@**.NotProguard <fields>;
|
||||
@**.NotProguard <methods>;
|
||||
-keepclassmembers class * {
|
||||
@**.NotProguard <fields>;
|
||||
@**.NotProguard <methods>;
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<InetSocketAddress, Set<ServerInfo>> 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<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
|
||||
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转发的聊天信息将不会在控制台显示 仅客户端可见!");
|
||||
}
|
||||
}
|
||||
|
208
src/main/java/pw/yumc/MiaoChat/bungee/FileConfig.java
Normal file
208
src/main/java/pw/yumc/MiaoChat/bungee/FileConfig.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
49
src/main/java/pw/yumc/MiaoChat/bungee/Log.java
Normal file
49
src/main/java/pw/yumc/MiaoChat/bungee/Log.java
Normal file
@ -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;
|
||||
|
||||
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<ChatRule> 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<String, ChatMessagePart> 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();
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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<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());
|
||||
handleSend(p, handleTellraw(p, cr.create(p), cr, message), cr.getRange());
|
||||
}
|
||||
|
||||
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) {
|
||||
Collection<? extends Entity> plist;
|
||||
List<Player> 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<String> il = handlePattern(message);
|
||||
// 如果返回null说明存在相同的物品
|
||||
if (il == null) {
|
||||
Log.toSender(player, "§c不允许展示相同的物品!");
|
||||
return;
|
||||
Log.sender(player, "§c不允许展示相同的物品!");
|
||||
return tr;
|
||||
}
|
||||
LinkedList<String> ml = handleMessage(il, message);
|
||||
// Log.d("处理Tellraw格式...");
|
||||
@ -177,5 +160,6 @@ public class ChatListener implements Listener {
|
||||
tr.then(cr.getLastColor() + mm);
|
||||
}
|
||||
}
|
||||
return tr;
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
#配置文件版本号 请勿修改
|
||||
Version: 1.3
|
||||
Version: 1.6
|
||||
|
||||
#BC跨服模式
|
||||
BungeeCord: true
|
||||
#当前服务器名称(变量为%mct_server%)
|
||||
Server: '§a生存服'
|
||||
#格式列表
|
||||
Formats:
|
||||
#格式名称 对应当前文件夹下的default.yml
|
||||
|
15
src/main/resources/group.yml
Normal file
15
src/main/resources/group.yml
Normal file
@ -0,0 +1,15 @@
|
||||
#配置版本号 请勿修改
|
||||
Version: 1.0
|
||||
|
||||
#跨服分组
|
||||
#注: 未在分组内的服务器会被分配到独立的一组
|
||||
#注: 内部分组名称为 ungroup 下方如有定义将无效
|
||||
Groups:
|
||||
#普通分组
|
||||
normal:
|
||||
- 'sc1'
|
||||
- 'sc2'
|
||||
#游戏分组
|
||||
games:
|
||||
- 'bw1'
|
||||
- 'sg1'
|
Loading…
Reference in New Issue
Block a user