Spigot 1.20 子服跨服传送插件教程 (BungeeCord API)
Spigot 1.20 子服跨服传送插件教程 (BungeeCord API)
本教程将引导你使用 BungeeCord API 创建一个 Spigot 1.20 插件,实现通过指令进行子服之间的跨服传送。
1. 添加依赖
首先,你需要在你的项目中添加 BungeeCord API 的依赖。根据你使用的构建工具 (Maven 或 Gradle),将以下依赖添加到你的项目配置中:
**Maven:**xml
**Gradle:**groovycompileOnly 'net.md-5:BungeeCord:1.16.5-R0.4-SNAPSHOT'
2. 创建主类
创建一个继承自 JavaPlugin 的主类,并重写 onEnable() 和 onCommand() 方法。javaimport org.bukkit.command.Command;import org.bukkit.command.CommandSender;import org.bukkit.plugin.java.JavaPlugin;
public class YourPlugin extends JavaPlugin {
@Override public void onEnable() { // 插件启用时的逻辑,例如注册监听器 }
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { // 处理命令逻辑 if (command.getName().equalsIgnoreCase('crossserver')) { if (args.length < 2) { sender.sendMessage('使用方法: /crossserver <服务器名称> <玩家名称>'); return true; } String serverName = args[0]; String playerName = args[1]; // 使用 BungeeCord API 进行跨服传送 getServer().getMessenger().registerOutgoingPluginChannel(this, 'BungeeCord'); ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF('ConnectOther'); out.writeUTF(playerName); out.writeUTF(serverName); sender.sendPluginMessage(this, 'BungeeCord', out.toByteArray()); return true; } return false; }}
在这个例子中:
- 我们创建了一个名为 'crossserver' 的命令,它接受两个参数:目标服务器的名称和要传送的玩家的名称。* 然后,我们使用 BungeeCord API 发送一个消息给 BungeeCord 插件,请求将玩家传送到指定的服务器。
3. 配置 plugin.yml
在 plugin.yml 文件中注册你的插件和命令:yamlname: YourPluginversion: 1.0main: com.example.YourPluginauthor: Your Name
commands: crossserver: description: 跨服传送命令 usage: /crossserver <服务器名称> <玩家名称>
4. 启用插件消息监听
确保在你的 BungeeCord 配置文件 (config.yml) 中启用了插件消息监听:yamllisteners: - query_port: 25577 motd: '&1Another BungeeCord - By &bmd_5' query_enabled: false forced_hosts: pvp.md-5.net: pvp tab_list: GLOBAL_PING bind_local_address: true ping_passthrough: false default_server: lobby force_default_server: false forward_ip: false online_mode: true disabled_commands: - disabledcommandhere server_connect_timeout: 5000 connection_throttle: 4000 remote_ping_cache: -1 remote_ping_timeout: 3000 network_compression_threshold: 256 - query_port: 25565 motd: '&1Another BungeeCord - By &bmd_5' query_enabled: true forced_hosts: pvp.md-5.net: pvp tab_list: GLOBAL_PING bind_local_address: true ping_passthrough: false default_server: lobby force_default_server: false forward_ip: false online_mode: true disabled_commands: - disabledcommandhere server_connect_timeout: 5000 connection_throttle: 4000 remote_ping_cache: -1 remote_ping_timeout: 3000 network_compression_threshold: 256ip_forward: truetimeout: 30000player_limit: -1protocol: 756compression_threshold: 256groups: md_5: - admin - moderatorpermissions: bungeecord.command.server: - admin bungeecord.command.alert: - admin bungeecord.command.end: - admin bungeecord.command.ip: - admin bungeecord.command.reload: - admindisabled_commands:- disabledcommandherestats: 8173log_pings: true
完成!
你现在可以在你的 Spigot 服务器上使用 /crossserver 命令进行子服之间的跨服传送了.
原文地址: https://www.cveoy.top/t/topic/fPKE 著作权归作者所有。请勿转载和采集!