feat: compatible 1.18

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2021-12-06 15:14:47 +00:00
parent 4da0b92f3f
commit 45ec56bebe
3 changed files with 56 additions and 30 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>MiaoChat</artifactId> <artifactId>MiaoChat</artifactId>
<version>1.9.3</version> <version>1.9.5</version>
<parent> <parent>
<groupId>pw.yumc</groupId> <groupId>pw.yumc</groupId>
@ -13,8 +13,9 @@
</parent> </parent>
<properties> <properties>
<update.description>§a正式版本 §bv1.9.3 §b兼容 1.17 版本</update.description> <update.description>§a正式版本 §bv1.9.5 §b兼容 1.15 版本</update.description>
<update.changes> <update.changes>
§621-06-20 §a增强: 兼容 1.18 版本 兼容新版PAPI;
§621-06-20 §a增强: 兼容 1.17 版本; §621-06-20 §a增强: 兼容 1.17 版本;
§620-10-10 §c修复: 1.16.3聊天包格式调整的问题; §620-10-10 §c修复: 1.16.3聊天包格式调整的问题;
§620-04-10 §c修复: L10N 本地化组件报错的问题; §620-04-10 §c修复: L10N 本地化组件报错的问题;

View File

@ -1,5 +1,9 @@
package pw.yumc.MiaoChat; package pw.yumc.MiaoChat;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -11,12 +15,7 @@ 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 org.jetbrains.annotations.NotNull;
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;
@ -32,6 +31,7 @@ public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListe
private FileConfig cfg; private FileConfig cfg;
private ChatConfig chatConfig; private ChatConfig chatConfig;
private String ServerName; private String ServerName;
private PlaceholderExpansion expansion;
public ChatConfig getChatConfig() { public ChatConfig getChatConfig() {
return chatConfig; return chatConfig;
@ -65,6 +65,11 @@ public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListe
L10N.getName(new ItemStack(Material.AIR)); L10N.getName(new ItemStack(Material.AIR));
} }
@Override
public void onDisable() {
this.expansion.unregister();
}
private void enableBungeeCord() { private void enableBungeeCord() {
if (getChatConfig().isBungeeCord()) { if (getChatConfig().isBungeeCord()) {
Log.i("已开启 BungeeCord 模式!"); Log.i("已开启 BungeeCord 模式!");
@ -79,19 +84,40 @@ public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListe
} }
private void hookPlaceholderAPI() { private void hookPlaceholderAPI() {
PlaceholderAPI.registerPlaceholderHook("mct", new PlaceholderHook() { this.expansion = new PlaceholderExpansion() {
@Override @Override
public String onPlaceholderRequest(Player player, String s) { public @NotNull String getIdentifier() {
switch (s.toLowerCase()) { return "mct";
case "server": }
return getChatConfig().getServername();
case "bserver": @Override
return ServerName; public @NotNull String getAuthor() {
return "MiaoWoo";
}
@Override
public @NotNull String getVersion() {
return "1.0";
}
@Override
public boolean persist() {
return true;
}
@Override
public String onPlaceholderRequest(Player player, @NotNull String params) {
switch (params.toLowerCase()) {
case "server":
return getChatConfig().getServername();
case "bserver":
return ServerName;
default: default:
} }
return "未知的参数"; return "未知的参数";
} }
}); };
this.expansion.register();
} }
@Override @Override

View File

@ -1,11 +1,5 @@
package pw.yumc.MiaoChat; package pw.yumc.MiaoChat;
import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import net.md_5.bungee.api.CommandSender; 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;
@ -17,6 +11,12 @@ import net.md_5.bungee.event.EventHandler;
import pw.yumc.MiaoChat.bungee.FileConfig; import pw.yumc.MiaoChat.bungee.FileConfig;
import pw.yumc.MiaoChat.bungee.Log; import pw.yumc.MiaoChat.bungee.Log;
import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/** /**
* @author MiaoWoo * @author MiaoWoo
*/ */
@ -49,21 +49,20 @@ public class MiaoChatBungee extends Plugin implements Listener {
Map<String, ServerInfo> temp = getProxy().getServers(); Map<String, ServerInfo> temp = getProxy().getServers();
Set<ServerInfo> unused = new HashSet<>(temp.values()); Set<ServerInfo> unused = new HashSet<>(temp.values());
Configuration groupSel = config.getSection("Groups"); Configuration groupSel = config.getSection("Groups");
// 读取所有的分组名称
groupSel.getKeys().forEach(groupName -> { groupSel.getKeys().forEach(groupName -> {
// 获取每个分组的服务器名称
Set<String> servers = new HashSet<>(groupSel.getStringList(groupName)); Set<String> servers = new HashSet<>(groupSel.getStringList(groupName));
// 新建当前分组数组
Set<ServerInfo> serverInfos = new HashSet<>(); Set<ServerInfo> serverInfos = new HashSet<>();
servers.forEach(s -> { servers.forEach(s -> {
if (temp.containsKey(s)) { if (temp.containsKey(s)) {
ServerInfo serverInfo = temp.get(s); ServerInfo info = temp.get(s);
unused.remove(serverInfo); unused.remove(info);
servers.forEach(ss -> { serverInfos.add(info);
if (temp.containsKey(ss) && !ss.equals(s)) {
serverInfos.add(temp.get(ss));
}
});
groups.put(serverInfo.getAddress(), serverInfos);
} }
}); });
serverInfos.forEach(serverInfo -> groups.put(serverInfo.getAddress(), serverInfos));
}); });
unused.forEach(serverInfo -> groups.put(serverInfo.getAddress(), unused)); unused.forEach(serverInfo -> groups.put(serverInfo.getAddress(), unused));
} }