feat: 添加自动传送

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-10-19 22:58:02 +08:00
parent 4a10b0be94
commit dfcea78eb3
5 changed files with 57 additions and 43 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>pw.yumc</groupId>
<artifactId>MiaoLobby</artifactId>
<version>1.2</version>
<version>1.3</version>
<build>
<finalName>${project.name}</finalName>
<resources>

View File

@ -1,14 +1,11 @@
package pw.yumc.MiaoLobby;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.scheduler.BukkitRunnable;
import fr.xephi.authme.events.LoginEvent;
import pw.yumc.YumCore.bukkit.P;
import pw.yumc.YumCore.bukkit.compatible.C;
public class AuthMeHook implements Listener {
private MiaoLobby plugin = P.getPlugin();
@ -19,22 +16,6 @@ public class AuthMeHook implements Listener {
@EventHandler
public void onLogin(final LoginEvent e) {
new BukkitRunnable() {
Player player = e.getPlayer();
int delay = plugin.config.AutoTPDelay;
@Override
public void run() {
if (player.isOnline()) {
if (delay > 0) {
C.ActionBar.send(player, String.format(plugin.config.TPDelay, delay));
delay--;
return;
}
plugin.random(player);
}
cancel();
}
}.runTaskTimerAsynchronously(plugin, 0, 20);
plugin.delayTP(e.getPlayer());
}
}

View File

@ -17,6 +17,7 @@ public class Config extends InjectConfig {
public String TimeOut;
public String TPDelay;
public String Unavailable;
public Boolean AutoTP;
public Boolean AuthMeAutoTP;
public Integer AutoTPDelay;
public Boolean ReTry;

View File

@ -7,6 +7,9 @@ import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
@ -22,22 +25,11 @@ import pw.yumc.YumCore.commands.annotation.Cmd;
import pw.yumc.YumCore.commands.annotation.Cmd.Executor;
import pw.yumc.YumCore.commands.annotation.Help;
import pw.yumc.YumCore.statistic.Statistics;
import pw.yumc.YumCore.update.SubscribeTask;
public class MiaoLobby extends JavaPlugin implements CommandExecutor {
public class MiaoLobby extends JavaPlugin implements CommandExecutor, Listener {
Config config;
private final SecureRandom random = new SecureRandom();
private void connect(final Player p, final String server) {
final ByteArrayDataOutput out = ByteStreams.newDataOutput();
try {
out.writeUTF("Connect");
out.writeUTF(server);
} catch (final Exception ignored) {
}
p.sendPluginMessage(this, "BungeeCord", out.toByteArray());
}
@Cmd(permission = "MiaoLobby.default", executor = Executor.PLAYER)
@Help("进行随机服务器传送")
public boolean def(final CommandArgument e) {
@ -45,6 +37,25 @@ public class MiaoLobby extends JavaPlugin implements CommandExecutor {
return true;
}
public void delayTP(final Player player) {
new BukkitRunnable() {
int delay = config.AutoTPDelay;
@Override
public void run() {
if (player.isOnline()) {
if (delay > 0) {
C.ActionBar.send(player, String.format(config.TPDelay, delay));
delay--;
return;
}
random(player);
}
cancel();
}
}.runTaskTimerAsynchronously(this, 0, 20);
}
@Override
public FileConfiguration getConfig() {
return config.getConfig();
@ -54,18 +65,44 @@ public class MiaoLobby extends JavaPlugin implements CommandExecutor {
public void onEnable() {
new CommandManager("MiaoLobby", this);
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
if (config.AuthMeAutoTP && Bukkit.getPluginManager().isPluginEnabled("AuthMe")) {
if (config.AutoTP) {
Bukkit.getPluginManager().registerEvents(this, this);
} else if (config.AuthMeAutoTP && Bukkit.getPluginManager().isPluginEnabled("AuthMe")) {
new AuthMeHook();
}
new Statistics();
// new SubscribeTask(true, true);
}
@EventHandler
public void onJoin(PlayerJoinEvent e) {
if (config.AutoTP) {
delayTP(e.getPlayer());
}
}
@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配置文件已重载!");
}
private void connect(final Player p, final String server) {
final ByteArrayDataOutput out = ByteStreams.newDataOutput();
try {
out.writeUTF("Connect");
out.writeUTF(server);
} catch (final Exception ignored) {
}
p.sendPluginMessage(this, "BungeeCord", out.toByteArray());
}
void random(final Player player) {
new BukkitRunnable() {
List<String> servers = new ArrayList<>(config.Servers);
@ -91,11 +128,4 @@ public class MiaoLobby extends JavaPlugin implements CommandExecutor {
}
}.runTaskTimerAsynchronously(this, 0, config.WaitTime);
}
@Cmd(permission = "MiaoLobby.reload")
@Help("重载配置文件")
public void reload(final CommandArgument e) {
config.reload();
Log.toSender(e.getSender(), "§a配置文件已重载!");
}
}

View File

@ -1,5 +1,5 @@
#配置文件版本 请勿修改
Version: 1.2
Version: 1.3
#数据库信息
Servers:
@ -7,9 +7,11 @@ Servers:
- lobby2
#传送超时时间(单位: Tick)
WaitTime: 35
#自带传送(如果开启 则AuthMe自动传送失效)
AutoTP: false
#AuthMe自动传送
AuthMeAutoTP: true
#自动登录延时(单位: 秒)
#自动传送延时(单位: 秒)
AutoTPDelay: 10
#尝试完毕后是否继续重试
ReTry: true