From 888fa18418e19575985e7203c7dc05666dd34ae2 Mon Sep 17 00:00:00 2001
From: tianyu <32282861@qq.com>
Date: Wed, 24 Jul 2024 20:54:45 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=89=88?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 40 ++++++
pom.xml | 37 ++++++
.../java/me/Demon/BungeeWarpPro/Main.java | 46 +++++++
.../Demon/BungeeWarpPro/atp/AtpCommand.java | 120 ++++++++++++++++++
.../me/Demon/BungeeWarpPro/atp/TpaUtil.java | 49 +++++++
.../Demon/BungeeWarpPro/libs/YamlConfig.java | 55 ++++++++
src/main/resources/config.yml | 1 +
src/main/resources/plugin.yml | 3 +
8 files changed, 351 insertions(+)
create mode 100644 .gitignore
create mode 100644 pom.xml
create mode 100644 src/main/java/me/Demon/BungeeWarpPro/Main.java
create mode 100644 src/main/java/me/Demon/BungeeWarpPro/atp/AtpCommand.java
create mode 100644 src/main/java/me/Demon/BungeeWarpPro/atp/TpaUtil.java
create mode 100644 src/main/java/me/Demon/BungeeWarpPro/libs/YamlConfig.java
create mode 100644 src/main/resources/config.yml
create mode 100644 src/main/resources/plugin.yml
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c037f46
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,40 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
+/.idea/
+/out/
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..7a264e9
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,37 @@
+
+
+ 4.0.0
+
+ org.example
+ BungeeWarpPro
+ 1.0-SNAPSHOT
+
+
+ 8
+ 8
+ UTF-8
+
+
+
+
+ public-rpg
+ https://repo.aurora-pixels.com/repository/public-rpg/
+
+
+
+
+
+ org.spigotmc
+ spigot-api
+ 1.12.2
+
+
+ com.server.bungeecord
+ BungeeCord
+ 1.12.2
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/me/Demon/BungeeWarpPro/Main.java b/src/main/java/me/Demon/BungeeWarpPro/Main.java
new file mode 100644
index 0000000..a8673f3
--- /dev/null
+++ b/src/main/java/me/Demon/BungeeWarpPro/Main.java
@@ -0,0 +1,46 @@
+package me.Demon.BungeeWarpPro;
+
+import com.google.common.io.ByteArrayDataOutput;
+import me.Demon.BungeeWarpPro.atp.AtpCommand;
+import me.Demon.BungeeWarpPro.libs.YamlConfig;
+import net.md_5.bungee.api.ProxyServer;
+import net.md_5.bungee.api.plugin.Listener;
+import net.md_5.bungee.api.plugin.Plugin;
+import net.md_5.bungee.config.Configuration;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+public class Main extends Plugin implements Listener {
+
+ public static YamlConfig yamlConfig;
+ public static Main plugin;
+ private static Main instance;
+ public static List Bungee_Warp_List = new ArrayList<>();
+ public HashMap outputHashMap = new HashMap<>();
+
+ @Override
+ public void onEnable() {
+ plugin = this;
+ instance = this;
+ yamlConfig = new YamlConfig("config.yml", plugin);
+ yamlConfig.saveDefaultConfig();
+ Configuration section = yamlConfig.getConfig().getSection("bungeewarp");
+ if(section != null){
+ Bungee_Warp_List.addAll(section.getKeys());
+ for (String warp_name : Bungee_Warp_List) {
+ System.out.print("# "+warp_name);
+ }
+ }
+ getProxy().registerChannel("bungee:warp");
+ getProxy().getPluginManager().registerListener(this,this);
+ // 关于BC跨服Tpa
+ getProxy().getPluginManager().registerCommand(this, new AtpCommand());
+ ProxyServer.getInstance().registerChannel("bungee:atp");
+
+ }
+ public static Main getInstance(){
+ return instance;
+ }
+}
diff --git a/src/main/java/me/Demon/BungeeWarpPro/atp/AtpCommand.java b/src/main/java/me/Demon/BungeeWarpPro/atp/AtpCommand.java
new file mode 100644
index 0000000..a4ea329
--- /dev/null
+++ b/src/main/java/me/Demon/BungeeWarpPro/atp/AtpCommand.java
@@ -0,0 +1,120 @@
+package me.Demon.BungeeWarpPro.atp;
+
+
+import me.Demon.BungeeWarpPro.Main;
+import net.md_5.bungee.api.CommandSender;
+import net.md_5.bungee.api.ProxyServer;
+import net.md_5.bungee.api.chat.TextComponent;
+import net.md_5.bungee.api.config.ServerInfo;
+import net.md_5.bungee.api.connection.ProxiedPlayer;
+import net.md_5.bungee.api.plugin.Command;
+import net.md_5.bungee.api.plugin.TabExecutor;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class AtpCommand extends Command implements TabExecutor {
+
+ public static Map tpaMap = new HashMap<>();
+ public static Map playerMap = new HashMap<>();
+
+ public AtpCommand() {
+ super("atp");
+ }
+
+ @Override
+ public void execute(CommandSender commandSender, String[] args) {
+ if (!(commandSender instanceof ProxiedPlayer)) {
+ return;
+ }
+ ProxiedPlayer player = (ProxiedPlayer) commandSender;
+ if (args.length == 0) {
+ TpaUtil.sendHelpMessage(player);
+ return;
+ }
+ String target = args[0];
+ if (target.equalsIgnoreCase("accept")) {
+ accept(player);
+ } else if (target.equalsIgnoreCase("deny")) {
+ deny(player);
+ } else {
+ ProxiedPlayer player1 = ProxyServer.getInstance().getPlayer(target);
+ if (player1 == null) {
+ player.sendMessage(new TextComponent("§8§l[§c§l!§8§l] §7在战争领域大区中未找到 §a" + target));
+ } else if (player.getUniqueId().equals(player1.getUniqueId())) {
+ player.sendMessage(new TextComponent("§8§l[§c§l!§8§l] §7目标玩家不能是自己喔"));
+ } else {
+ String server_name = player1.getServer().getInfo().getName();
+ System.out.print("目标所在区服: " + server_name);
+ if (server_name.contains("chkdsc")) {
+ tpa(player, player1, player1.getServer().getInfo());
+ } else {
+ player.sendMessage(new TextComponent("§8§l[§c§l!§8§l] §7未在战争领域服务器中找到 §a" + target));
+ }
+ }
+ }
+ }
+
+ private static void tpa(ProxiedPlayer player, ProxiedPlayer target, ServerInfo serverInfo) {
+ tpaMap.put(player, target);
+ playerMap.put(target, player);
+ player.sendMessage(new TextComponent("§8§l[§a§l!§8§l] §7传送请求已发送至 §6" + target.getName()));
+ TpaUtil.sendTargetMessage(player, target);
+ }
+
+ private static void accept(ProxiedPlayer player) {
+ ProxiedPlayer player1 = playerMap.get(player);
+ if (player1 == null || !player1.isConnected()) {
+ player.sendMessage(new TextComponent("§8§l[§e§l!§8§l] §7没有待处理的传送请求"));
+ return;
+ }
+ player.sendMessage(new TextComponent("§8§l[§e§l!§8§l] §7你接受了 §6" + player1.getName() + " §7的传送请求"));
+ TpaUtil.sendAcceptMessage(player1, player1);
+ tpaMap.remove(player1);
+ playerMap.remove(player);
+ ServerInfo serverInfo = player.getServer().getInfo();
+ boolean flag = false;
+ if (player1.getServer().getInfo().equals(serverInfo)) {
+ flag = true;
+ } else {
+ player1.connect(serverInfo);
+ }
+ boolean finalFlag = flag;
+ TpaUtil.sendMessageToServer("accept", serverInfo, (dataOutputStream -> {
+ try {
+ dataOutputStream.writeUTF(player.getUniqueId().toString());
+ dataOutputStream.writeUTF(player1.getUniqueId().toString());
+ dataOutputStream.writeBoolean(finalFlag);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }));
+ }
+
+ private static void deny(ProxiedPlayer player) {
+ ProxiedPlayer player1 = playerMap.get(player);
+ if (player1 == null || !player1.isConnected()) {
+ player.sendMessage(new TextComponent("§8§l[§e§l!§8§l] §7没有待处理的传送请求"));
+ return;
+ }
+ player.sendMessage(new TextComponent("§8§l[§c§l!§8§l] §7你拒绝 §6" + player1.getName() + " §7的传送请求"));
+ TpaUtil.sendDenyMessage(player1, player);
+ tpaMap.remove(player1);
+ playerMap.remove(player);
+ }
+
+ @Override
+ public Iterable onTabComplete(CommandSender commandSender, String[] strings) {
+ List list = new ArrayList<>();
+ Map hashMap = Main.getInstance().getProxy().getServers();
+ for (String key : hashMap.keySet()) {
+ String serverInfo = hashMap.get(key).getName();
+ if (serverInfo.contains("chkdsc")) {
+ hashMap.get(key).getPlayers().forEach(player -> list.add(player.getName()));
+ }
+ }
+ return list;
+ }
+}
diff --git a/src/main/java/me/Demon/BungeeWarpPro/atp/TpaUtil.java b/src/main/java/me/Demon/BungeeWarpPro/atp/TpaUtil.java
new file mode 100644
index 0000000..63ad7d6
--- /dev/null
+++ b/src/main/java/me/Demon/BungeeWarpPro/atp/TpaUtil.java
@@ -0,0 +1,49 @@
+package me.Demon.BungeeWarpPro.atp;
+
+import com.google.common.io.ByteArrayDataOutput;
+import com.google.common.io.ByteStreams;
+import java.util.function.Consumer;
+import net.md_5.bungee.api.chat.BaseComponent;
+import net.md_5.bungee.api.chat.ClickEvent;
+import net.md_5.bungee.api.chat.HoverEvent;
+import net.md_5.bungee.api.chat.TextComponent;
+import net.md_5.bungee.api.chat.ClickEvent.Action;
+import net.md_5.bungee.api.config.ServerInfo;
+import net.md_5.bungee.api.connection.ProxiedPlayer;
+
+public class TpaUtil {
+
+ public static void sendHelpMessage(ProxiedPlayer player) {
+ player.sendMessage(new TextComponent("§7[§6战争领域§7] §f正确用法: §a/atp [玩家名]"));
+ }
+
+ public static void sendTargetMessage(ProxiedPlayer player, ProxiedPlayer target) {
+ target.sendMessage(new TextComponent("§8§l[§e§l!§8§l] §7玩家 §6" + player.getName() + " §7正在向你发起传送请求."));
+ TextComponent air = new TextComponent(" ");
+ TextComponent acceptComponent = new TextComponent("§7[§a同意传送§7]");
+ acceptComponent.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/atp accept"));
+ acceptComponent.setHoverEvent(new HoverEvent(net.md_5.bungee.api.chat.HoverEvent.Action.SHOW_TEXT, new BaseComponent[]{new TextComponent("§e确认操作")}));
+ TextComponent denyComponent = new TextComponent("§7[§c拒绝传送§7]");
+ denyComponent.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/atp deny"));
+ denyComponent.setHoverEvent(new HoverEvent(net.md_5.bungee.api.chat.HoverEvent.Action.SHOW_TEXT, new BaseComponent[]{new TextComponent("§e确认操作")}));
+ air.addExtra(acceptComponent);
+ air.addExtra(" ");
+ air.addExtra(denyComponent);
+ target.sendMessage(air);
+ }
+
+ public static void sendAcceptMessage(ProxiedPlayer player, ProxiedPlayer target) {
+ player.sendMessage(new TextComponent("§8§l[§a§l!§8§l] §7玩家 §6" + target + " §7接受了你的传送请求"));
+ }
+
+ public static void sendDenyMessage(ProxiedPlayer player, ProxiedPlayer target) {
+ player.sendMessage(new TextComponent("§8§l[§c§l!§8§l] §7玩家 §6" + target + " §7拒绝了你的传送请求"));
+ }
+
+ public static void sendMessageToServer(String channel, ServerInfo server, Consumer consumer) {
+ ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
+ dataOutput.writeUTF(channel);
+ consumer.accept(dataOutput);
+ server.sendData("bungee:atp", dataOutput.toByteArray());
+ }
+}
diff --git a/src/main/java/me/Demon/BungeeWarpPro/libs/YamlConfig.java b/src/main/java/me/Demon/BungeeWarpPro/libs/YamlConfig.java
new file mode 100644
index 0000000..6eb391e
--- /dev/null
+++ b/src/main/java/me/Demon/BungeeWarpPro/libs/YamlConfig.java
@@ -0,0 +1,55 @@
+package me.Demon.BungeeWarpPro.libs;
+
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+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;
+
+public class YamlConfig {
+
+ private final File configFile;
+
+ private final String fileName;
+
+ private final Plugin plugin;
+
+ private final File folder;
+
+ private static Configuration config;
+
+ public YamlConfig(String fileName, Plugin plugin) {
+ this.plugin = plugin;
+ this.fileName = fileName;
+ this.folder = plugin.getDataFolder();
+ this.configFile = new File(this.folder, fileName);
+ }
+
+ public void saveDefaultConfig() {
+ if (!this.folder.exists())
+ this.folder.mkdirs();
+ try {
+ if (!this.configFile.exists())
+ Files.copy(this.plugin.getResourceAsStream(this.fileName), this.configFile.toPath());
+ loadConfig();
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ public void loadConfig() throws IOException {
+ config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(this.configFile);
+ }
+
+ public void saveConfig() throws IOException {
+ ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, this.configFile);
+ }
+
+ public Configuration getConfig() {
+ return config;
+ }
+
+}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
new file mode 100644
index 0000000..31a5a05
--- /dev/null
+++ b/src/main/resources/config.yml
@@ -0,0 +1 @@
+BungeeWarp: {}
\ No newline at end of file
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
new file mode 100644
index 0000000..c60dee9
--- /dev/null
+++ b/src/main/resources/plugin.yml
@@ -0,0 +1,3 @@
+name: BungeeWarpPro
+main: me.Demon.BungeeWarpPro.Main
+version: 1.0.1