mirror of
https://e.coding.net/circlecloud/MiaoLobby.git
synced 2025-11-03 09:26:08 +00:00
19
src/main/java/pw/yumc/MiaoLobby/Config.java
Normal file
19
src/main/java/pw/yumc/MiaoLobby/Config.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package pw.yumc.MiaoLobby;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import pw.yumc.YumCore.config.InjectConfig;
|
||||
|
||||
/**
|
||||
* 配置文件
|
||||
*
|
||||
* @since 2016年9月22日 下午3:09:06
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
public class Config extends InjectConfig {
|
||||
public List<String> Servers;
|
||||
public Integer WaitTime;
|
||||
public String Message;
|
||||
public String TimeOut;
|
||||
public String Unavailable;
|
||||
}
|
||||
86
src/main/java/pw/yumc/MiaoLobby/MiaoLobby.java
Normal file
86
src/main/java/pw/yumc/MiaoLobby/MiaoLobby.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package pw.yumc.MiaoLobby;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
import pw.yumc.YumCore.bukkit.Log;
|
||||
import pw.yumc.YumCore.bukkit.compatible.C;
|
||||
import pw.yumc.YumCore.commands.CommandArgument;
|
||||
import pw.yumc.YumCore.commands.CommandExecutor;
|
||||
import pw.yumc.YumCore.commands.CommandManager;
|
||||
import pw.yumc.YumCore.commands.annotation.Cmd;
|
||||
import pw.yumc.YumCore.commands.annotation.Help;
|
||||
|
||||
public class MiaoLobby extends JavaPlugin implements CommandExecutor {
|
||||
private final SecureRandom random = new SecureRandom();
|
||||
private Config config;
|
||||
|
||||
public void connect(final Player p, final String server) {
|
||||
final ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
try {
|
||||
out.writeUTF("Connect");
|
||||
out.writeUTF(server);
|
||||
} catch (final Exception localException) {
|
||||
}
|
||||
p.sendPluginMessage(this, "BungeeCord", out.toByteArray());
|
||||
}
|
||||
|
||||
@Cmd(permission = "MiaoLobby.default")
|
||||
@Help("进行随机服务器传送")
|
||||
public boolean def(final CommandArgument e) {
|
||||
final Player player = (Player) e.getSender();
|
||||
new BukkitRunnable() {
|
||||
List<String> servers = new ArrayList<>(config.Servers);
|
||||
int i = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (servers.isEmpty()) {
|
||||
C.ActionBar.send(player, config.Unavailable);
|
||||
player.sendMessage(config.Unavailable);
|
||||
} else if (player.isOnline()) {
|
||||
final String sname = servers.remove(random.nextInt(servers.size()));
|
||||
C.ActionBar.send(player, String.format(i > 0 ? config.TimeOut : config.Message, sname));
|
||||
connect(player, sname);
|
||||
i++;
|
||||
return;
|
||||
}
|
||||
cancel();
|
||||
}
|
||||
}.runTaskTimerAsynchronously(this, 0, config.WaitTime);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileConfiguration getConfig() {
|
||||
return config.getConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
new CommandManager("MiaoLobby", this);
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
config = new Config();
|
||||
}
|
||||
|
||||
@Cmd(permission = "MiaoLobby.reload")
|
||||
@Help("重载配置文件")
|
||||
public void reload(final CommandArgument e) {
|
||||
config.reload();
|
||||
Log.toSender(e.getSender(), "§a配置文件已重载!");
|
||||
}
|
||||
}
|
||||
13
src/main/resources/config.yml
Normal file
13
src/main/resources/config.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
#配置文件版本 请勿修改
|
||||
Version: 1.0
|
||||
|
||||
#数据库信息
|
||||
Servers:
|
||||
- lobby1
|
||||
- lobby2
|
||||
#传送超时时间(单位: Tick)
|
||||
WaitTime: 20
|
||||
#传送提示
|
||||
Message: '&a请稍候 正在传送至服务器 %s ...'
|
||||
TimeOut: '&c传送超时 正在切换到服务器 %s ...'
|
||||
Unavailable: '&4已尝试所有可用服务器 传送失败!'
|
||||
24
src/main/resources/plugin.yml
Normal file
24
src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,24 @@
|
||||
name: ${project.artifactId}
|
||||
description: ${project.description}
|
||||
main: ${project.groupId}.${project.artifactId}.${project.artifactId}
|
||||
version: ${project.version}-git-${env.GIT_COMMIT}
|
||||
author: 喵♂呜
|
||||
website: ${ciManagement.url}
|
||||
commands:
|
||||
${project.artifactId}:
|
||||
description: ${project.artifactId} - ${project.description}
|
||||
aliases:
|
||||
- ml
|
||||
usage: §b使用/${project.artifactId} help 查看帮助!
|
||||
permission: ${project.artifactId}.reload
|
||||
permission-message: §c你没有 <permission> 的权限来执行此命令!
|
||||
permissions:
|
||||
${project.artifactId}.default:
|
||||
description: ${project.artifactId} 默认权限!
|
||||
default: true
|
||||
${project.artifactId}.admin:
|
||||
description: ${project.artifactId} 管理员权限!
|
||||
default: op
|
||||
${project.artifactId}.reload:
|
||||
description: 重新载入插件!
|
||||
default: op
|
||||
Reference in New Issue
Block a user