测试版

This commit is contained in:
tianyu 2024-07-24 20:54:45 +08:00
commit 888fa18418
8 changed files with 351 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>BungeeWarpPro</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>com.server.bungeecord</groupId>
<artifactId>BungeeCord</artifactId>
<version>1.12.2</version>
</dependency>
</dependencies>
</project>

View File

@ -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<String> Bungee_Warp_List = new ArrayList<>();
public HashMap<String, ByteArrayDataOutput> 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;
}
}

View File

@ -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<ProxiedPlayer, ProxiedPlayer> tpaMap = new HashMap<>();
public static Map<ProxiedPlayer, ProxiedPlayer> 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<String> onTabComplete(CommandSender commandSender, String[] strings) {
List<String> list = new ArrayList<>();
Map<String, ServerInfo> 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;
}
}

View File

@ -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<ByteArrayDataOutput> consumer) {
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
dataOutput.writeUTF(channel);
consumer.accept(dataOutput);
server.sendData("bungee:atp", dataOutput.toByteArray());
}
}

View File

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

View File

@ -0,0 +1 @@
BungeeWarp: {}

View File

@ -0,0 +1,3 @@
name: BungeeWarpPro
main: me.Demon.BungeeWarpPro.Main
version: 1.0.1