From 4c7e0cbd2a2e59f7756bf2ee0e89b2945a87c9a5 Mon Sep 17 00:00:00 2001
From: tianyu <32282861@qq.com>
Date: Thu, 25 Jul 2024 04:34:12 +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 ++++++
.../DemonWarpPro/AtpEvent/AtpListener.java | 44 +++++++
.../AtpEvent/AtpPluginMessageListener.java | 40 ++++++
.../me/Demon/DemonWarpPro/BungeeWarpAPI.java | 24 ++++
src/main/java/me/Demon/DemonWarpPro/Main.java | 114 ++++++++++++++++++
.../java/me/Demon/DemonWarpPro/WarpAPI.java | 69 +++++++++++
src/main/resources/config.yml | 3 +
src/main/resources/plugin.yml | 8 ++
9 files changed, 379 insertions(+)
create mode 100644 .gitignore
create mode 100644 pom.xml
create mode 100644 src/main/java/me/Demon/DemonWarpPro/AtpEvent/AtpListener.java
create mode 100644 src/main/java/me/Demon/DemonWarpPro/AtpEvent/AtpPluginMessageListener.java
create mode 100644 src/main/java/me/Demon/DemonWarpPro/BungeeWarpAPI.java
create mode 100644 src/main/java/me/Demon/DemonWarpPro/Main.java
create mode 100644 src/main/java/me/Demon/DemonWarpPro/WarpAPI.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..7b36685
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,37 @@
+
+
+ 4.0.0
+
+ org.example
+ DemonWarpPro
+ 1.0-SNAPSHOT
+
+
+ 8
+ 8
+ UTF-8
+
+
+
+
+ public-rpg
+ https://repo.aurora-pixels.com/repository/public-rpg/
+
+
+
+
+
+ org.spigotmc
+ spigot-api
+ 1.12.2
+
+
+ me.Demon.DemonPlugin
+ DemonAPI
+ 1.2.0
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/me/Demon/DemonWarpPro/AtpEvent/AtpListener.java b/src/main/java/me/Demon/DemonWarpPro/AtpEvent/AtpListener.java
new file mode 100644
index 0000000..b959a35
--- /dev/null
+++ b/src/main/java/me/Demon/DemonWarpPro/AtpEvent/AtpListener.java
@@ -0,0 +1,44 @@
+package me.Demon.DemonWarpPro.AtpEvent;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+import me.Demon.DemonWarpPro.Main;
+import me.Demon.DemonWarpPro.WarpAPI;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.PlayerJoinEvent;
+
+public class AtpListener implements Listener {
+ public static Map tpaMap = new HashMap<>();
+
+ @EventHandler
+ public void onPlayerJoin(PlayerJoinEvent event) {
+ Player player = event.getPlayer();
+ if (tpaMap.containsKey(player.getUniqueId())) {
+ UUID uuid = tpaMap.get(player.getUniqueId());
+ Player player1 = Bukkit.getPlayer(uuid);
+ tpaMap.remove(player.getUniqueId());
+ if (player1 != null && player1.isOnline()) {
+ if (player1.getWorld().getName().contains("fuben_")) {
+ Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
+ WarpAPI.tp_Spigot_Warp(player, "副本区1");
+ player.sendMessage(Main.prefix + "对方所在位置无法将你传送过去.");
+ }, 2L);
+ } else if (player1.getWorld().getName().equalsIgnoreCase("paoku")) {
+ Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
+ WarpAPI.tp_Spigot_Warp(player, "跑酷区");
+ player.sendMessage(Main.prefix + "对方所在位置无法将你传送过去.");
+ }, 2L);
+ } else {
+ Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
+ player.teleport(player1.getLocation());
+ }, 2L);
+ }
+ }
+ }
+
+ }
+}
diff --git a/src/main/java/me/Demon/DemonWarpPro/AtpEvent/AtpPluginMessageListener.java b/src/main/java/me/Demon/DemonWarpPro/AtpEvent/AtpPluginMessageListener.java
new file mode 100644
index 0000000..0b5f243
--- /dev/null
+++ b/src/main/java/me/Demon/DemonWarpPro/AtpEvent/AtpPluginMessageListener.java
@@ -0,0 +1,40 @@
+package me.Demon.DemonWarpPro.AtpEvent;
+
+import com.google.common.io.ByteArrayDataInput;
+import com.google.common.io.ByteStreams;
+import java.util.UUID;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.messaging.PluginMessageListener;
+
+public class AtpPluginMessageListener implements PluginMessageListener {
+
+ public void onPluginMessageReceived(String s, Player player, byte[] bytes) {
+ if (s.equals("bungee:warp")) {
+ ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
+ String subchannel = in.readUTF();
+
+ try {
+ if (subchannel.equalsIgnoreCase("accept")) {
+ String playerUUID1 = in.readUTF();
+ String playerUUID2 = in.readUTF();
+ UUID uuid1 = UUID.fromString(playerUUID1);
+ UUID uuid2 = UUID.fromString(playerUUID2);
+ boolean flag = in.readBoolean();
+ if (flag) {
+ Player player1 = Bukkit.getPlayer(uuid1);
+ Player player2 = Bukkit.getPlayer(uuid2);
+ if (player1 != null && player1.isOnline() && player2 != null && player2.isOnline()) {
+ player2.teleport(player1.getLocation());
+ }
+ } else {
+ AtpListener.tpaMap.put(uuid2, uuid1);
+ }
+ }
+ } catch (Exception var13) {
+ var13.printStackTrace();
+ }
+
+ }
+ }
+}
diff --git a/src/main/java/me/Demon/DemonWarpPro/BungeeWarpAPI.java b/src/main/java/me/Demon/DemonWarpPro/BungeeWarpAPI.java
new file mode 100644
index 0000000..2896a42
--- /dev/null
+++ b/src/main/java/me/Demon/DemonWarpPro/BungeeWarpAPI.java
@@ -0,0 +1,24 @@
+package me.Demon.DemonWarpPro;
+
+import com.google.common.io.ByteArrayDataOutput;
+import com.google.common.io.ByteStreams;
+import me.Demon.DemonPlugin.DemonAPI;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+
+public class BungeeWarpAPI {
+
+ public static void tpLoc(Player p, String warpName) {
+ if (p.isOp()) {
+ p.sendMessage("§7跨服传送中...");
+ DemonAPI.sendTitle(p, 5, 30, 5, "§r", "§e跨服跳转中...");
+ } else {
+ p.sendMessage("§7传送中...");
+ }
+
+ ByteArrayDataOutput out = ByteStreams.newDataOutput();
+ out.writeUTF("bungee:warptp");
+ out.writeUTF(warpName);
+ Bukkit.getPlayerExact(p.getName()).sendPluginMessage(Main.plugin, "bungee:warp", out.toByteArray());
+ }
+}
diff --git a/src/main/java/me/Demon/DemonWarpPro/Main.java b/src/main/java/me/Demon/DemonWarpPro/Main.java
new file mode 100644
index 0000000..f4cc2af
--- /dev/null
+++ b/src/main/java/me/Demon/DemonWarpPro/Main.java
@@ -0,0 +1,114 @@
+package me.Demon.DemonWarpPro;
+
+import com.google.common.io.ByteArrayDataInput;
+import com.google.common.io.ByteArrayDataOutput;
+import com.google.common.io.ByteStreams;
+import me.Demon.DemonWarpPro.AtpEvent.AtpListener;
+import me.Demon.DemonWarpPro.AtpEvent.AtpPluginMessageListener;
+import org.bukkit.Bukkit;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.java.JavaPlugin;
+import org.bukkit.plugin.messaging.PluginMessageListener;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public final class Main extends JavaPlugin implements PluginMessageListener {
+ public static Main plugin;
+ public static String prefix = "§7[§6战争领域§7] §f";
+ public static List Spigot_Warp_List = new ArrayList<>();
+
+ public void onEnable() {
+ plugin = this;
+ this.saveDefaultConfig();
+ if (this.getConfig().getString("SpigotWarp") != null) {
+ Spigot_Warp_List.addAll(this.getConfig().getConfigurationSection("SpigotWarp").getKeys(false));
+ }
+
+ this.getServer().getMessenger().registerOutgoingPluginChannel(this, "bungee:warp");
+ this.getServer().getMessenger().registerIncomingPluginChannel(this, "bungee:warp", this);
+ Bukkit.getConsoleSender().sendMessage("§e[坐标] §r载入本地坐标: " + Spigot_Warp_List.size() + "个");
+ Bukkit.getConsoleSender().sendMessage("§e[坐标] §r正在启动插件...");
+ Bukkit.getServer().getMessenger().registerIncomingPluginChannel(plugin, "bungee:atp", new AtpPluginMessageListener());
+ Bukkit.getPluginManager().registerEvents(new AtpListener(), plugin);
+ Bukkit.getConsoleSender().sendMessage("§e[跨服Atp] §r正在启动插件...");
+ }
+
+ public void onDisable() {
+ Bukkit.getConsoleSender().sendMessage("§e[坐标] §r正在关闭插件...");
+ }
+
+ public boolean onCommand(CommandSender sender, Command cmd, String Command, String[] args) {
+ if (Command.equalsIgnoreCase("spawn") && sender instanceof Player) {
+ WarpAPI.tp_SpigotAndBungee_Warp((Player)sender, "主城");
+ }
+
+ String warp_key;
+ if (Command.equalsIgnoreCase("warp") && sender instanceof Player && args.length == 1) {
+ warp_key = args[0];
+ WarpAPI.tp_SpigotAndBungee_Warp((Player)sender, warp_key);
+ }
+
+ if (Command.equalsIgnoreCase("warpadmin") && sender.isOp()) {
+ if (args.length == 2 && args[0].equalsIgnoreCase("save")) {
+ if (sender instanceof Player) {
+ warp_key = args[1];
+ WarpAPI.Save_Spigot_Warp((Player)sender, warp_key);
+ }
+ } else if (args.length == 2 && args[0].equalsIgnoreCase("shan")) {
+ warp_key = args[1];
+ WarpAPI.Remove_Spigot_Warp(sender, warp_key);
+ } else if (args.length == 1 && args[0].equalsIgnoreCase("Updata")) {
+ if (sender instanceof Player) {
+ Player p = (Player)sender;
+ StringBuilder str = new StringBuilder();
+
+ for (String warp_name : Spigot_Warp_List) {
+ ByteArrayDataOutput out = ByteStreams.newDataOutput();
+ out.writeUTF("bungee:warpupdata");
+ out.writeUTF(warp_name);
+ p.sendPluginMessage(this, "bungee:warp", out.toByteArray());
+ str.append(warp_name).append("§f,§a");
+ }
+
+ p.sendMessage(prefix + "坐标数据已上传: §a" + str);
+ }
+ } else {
+ this.CommandHelp(sender);
+ }
+ }
+
+ return false;
+ }
+
+ public void CommandHelp(CommandSender sender) {
+ sender.sendMessage("");
+ sender.sendMessage("§e------- ======= §6魂式坐标 §e======= -------");
+ sender.sendMessage("§2/warpadmin Updata §f- §2上传数据至BC");
+ sender.sendMessage("§2/warpadmin save §e[坐标] §f- §2设置坐标");
+ sender.sendMessage("§2/warpadmin shan §e[坐标] §f- §2删除坐标");
+ sender.sendMessage("§e------- ======= §6魂式坐标 §e======= -------");
+ }
+
+ public void onPluginMessageReceived(String channel, Player player, byte[] message) {
+ if (channel.equals("bungee:warp")) {
+ final ByteArrayDataInput in = ByteStreams.newDataInput(message);
+ String pindao = in.readUTF();
+ if (pindao.equals("spigot:warptp")) {
+ String name = in.readUTF();
+ final Player player1 = Bukkit.getPlayerExact(name);
+ if (player1 != null) {
+ Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
+ public void run() {
+ String warp_Name = in.readUTF();
+ WarpAPI.tp_Spigot_Warp(player1, warp_Name);
+ }
+ }, 5L);
+ }
+ }
+ }
+
+ }
+}
diff --git a/src/main/java/me/Demon/DemonWarpPro/WarpAPI.java b/src/main/java/me/Demon/DemonWarpPro/WarpAPI.java
new file mode 100644
index 0000000..b6397f3
--- /dev/null
+++ b/src/main/java/me/Demon/DemonWarpPro/WarpAPI.java
@@ -0,0 +1,69 @@
+package me.Demon.DemonWarpPro;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.command.CommandSender;
+import org.bukkit.configuration.file.FileConfiguration;
+import org.bukkit.entity.Player;
+
+public class WarpAPI {
+
+ public static void tp_SpigotAndBungee_Warp(Player p, String warp_key) {
+ if (Main.Spigot_Warp_List.contains(warp_key)) {
+ tp_Spigot_Warp(p, warp_key);
+ } else {
+ BungeeWarpAPI.tpLoc(p, warp_key);
+ }
+
+ }
+
+ public static void tp_Spigot_Warp(Player p, String key) {
+ FileConfiguration yml = Main.plugin.getConfig();
+ if (!Main.Spigot_Warp_List.contains(key)) {
+ p.sendMessage(Main.prefix + "世界坐标§a" + key + "§f传送出现异常,请联系管理员。#1");
+ } else {
+ String str = "SpigotWarp." + key + ".";
+ World world = Bukkit.getWorld(yml.getString(str + "World"));
+ if (world == null) {
+ p.sendMessage(Main.prefix + "世界坐标§a" + key + "§f传送出现异常,请联系管理员。#2");
+ } else {
+ double X = yml.getDouble(str + "X");
+ double Y = yml.getDouble(str + "Y");
+ double Z = yml.getDouble(str + "Z");
+ double Yaw = yml.getDouble(str + "Yaw");
+ double Pitch = yml.getDouble(str + "Pitch");
+ Location loc = new Location(world, X, Y, Z, (float)Yaw, (float)Pitch);
+ loc.add(0.0, 1.0, 0.0);
+ p.sendMessage("§7传送中...");
+ p.teleport(loc);
+ }
+ }
+ }
+
+ public static void Save_Spigot_Warp(Player p, String key) {
+ FileConfiguration yml = Main.plugin.getConfig();
+ String str = "SpigotWarp." + key + ".";
+ Location loc = p.getLocation();
+ yml.set(str + "World", loc.getWorld().getName());
+ yml.set(str + "X", loc.getX());
+ yml.set(str + "Y", loc.getY());
+ yml.set(str + "Z", loc.getZ());
+ yml.set(str + "Yaw", loc.getYaw());
+ yml.set(str + "Pitch", loc.getPitch());
+ Main.plugin.saveConfig();
+ if (!Main.Spigot_Warp_List.contains(key)) {
+ Main.Spigot_Warp_List.add(key);
+ }
+
+ p.sendMessage(Main.prefix + "成功创建坐标: §a" + key);
+ }
+
+ public static void Remove_Spigot_Warp(CommandSender sender, String key) {
+ FileConfiguration yml = Main.plugin.getConfig();
+ yml.set("SpigotWarp." + key, null);
+ Main.plugin.saveConfig();
+ Main.Spigot_Warp_List.remove(key);
+ sender.sendMessage(Main.prefix + "成功删除坐标: §a" + key);
+ }
+}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
new file mode 100644
index 0000000..211b8b8
--- /dev/null
+++ b/src/main/resources/config.yml
@@ -0,0 +1,3 @@
+Message:
+
+SpigotWarp: {}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
new file mode 100644
index 0000000..b12fbb1
--- /dev/null
+++ b/src/main/resources/plugin.yml
@@ -0,0 +1,8 @@
+name: DemonWarpPro
+main: me.Demon.DemonWarpPro.Main
+version: 1.0.0
+commands:
+ spawn:
+ warp:
+ warpadmin:
+ atp:
\ No newline at end of file