测试版

This commit is contained in:
tianyu 2024-07-25 04:34:12 +08:00
commit 4c7e0cbd2a
9 changed files with 379 additions and 0 deletions

40
.gitignore vendored Normal file
View File

@ -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/

37
pom.xml Normal file
View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>DemonWarpPro</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>public-rpg</id>
<url>https://repo.aurora-pixels.com/repository/public-rpg/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2</version>
</dependency>
<dependency>
<groupId>me.Demon.DemonPlugin</groupId>
<artifactId>DemonAPI</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
</project>

View File

@ -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<UUID, UUID> 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);
}
}
}
}
}

View File

@ -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();
}
}
}
}

View File

@ -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());
}
}

View File

@ -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<String> 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);
}
}
}
}
}

View File

@ -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);
}
}

View File

@ -0,0 +1,3 @@
Message:
SpigotWarp: {}

View File

@ -0,0 +1,8 @@
name: DemonWarpPro
main: me.Demon.DemonWarpPro.Main
version: 1.0.0
commands:
spawn:
warp:
warpadmin:
atp: