From 5264245c626902e3a50935c5460db36b565bd748 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Thu, 29 Dec 2016 22:52:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E4=BC=A0=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- pom.xml | 2 +- src/main/java/pw/yumc/MiaoLobby/MiaoLobby.java | 11 ++++++++++- src/main/java/pw/yumc/MiaoLobby/Util.java | 14 ++++++++++++-- .../java/pw/yumc/MiaoLobby/hook/VBossAuthHook.java | 8 +++++++- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 011d024..1e1c848 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 pw.yumc MiaoLobby - 1.5 + 1.6 ${project.name} diff --git a/src/main/java/pw/yumc/MiaoLobby/MiaoLobby.java b/src/main/java/pw/yumc/MiaoLobby/MiaoLobby.java index d8ffd9f..a6643e4 100644 --- a/src/main/java/pw/yumc/MiaoLobby/MiaoLobby.java +++ b/src/main/java/pw/yumc/MiaoLobby/MiaoLobby.java @@ -4,6 +4,9 @@ import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; 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.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; import pw.yumc.MiaoLobby.hook.AuthMeHook; @@ -17,9 +20,14 @@ import pw.yumc.YumCore.commands.interfaces.Executor; import pw.yumc.YumCore.statistic.Statistics; import pw.yumc.YumCore.update.SubscribeTask; -public class MiaoLobby extends JavaPlugin implements Executor { +public class MiaoLobby extends JavaPlugin implements Executor, Listener { Config config; + @EventHandler + public void onQuit(PlayerQuitEvent e) { + Util.cancel(e.getPlayer()); + } + @Cmd(permission = "MiaoLobby.default", executor = Cmd.Executor.PLAYER) @Help("进行随机服务器传送") public boolean def(final Player player) { @@ -36,6 +44,7 @@ public class MiaoLobby extends JavaPlugin implements Executor { public void onEnable() { new CommandSub("MiaoLobby", this); Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); + Bukkit.getPluginManager().registerEvents(this, this); if (config.AutoTP) { new LoginHook(); Log.info("已配置为自动传送模式!"); diff --git a/src/main/java/pw/yumc/MiaoLobby/Util.java b/src/main/java/pw/yumc/MiaoLobby/Util.java index e2e3cfe..13d9964 100644 --- a/src/main/java/pw/yumc/MiaoLobby/Util.java +++ b/src/main/java/pw/yumc/MiaoLobby/Util.java @@ -3,9 +3,11 @@ package pw.yumc.MiaoLobby; import java.security.SecureRandom; import java.util.ArrayList; import java.util.List; +import java.util.Map; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; @@ -21,9 +23,10 @@ public class Util { private final static SecureRandom random = new SecureRandom(); private static MiaoLobby plugin = P.getPlugin(); private static Config config = plugin.config; + private static Map tasks; public static void delayTp(final Player player) { - new BukkitRunnable() { + tasks.put(player.getName(), new BukkitRunnable() { int delay = config.AutoTPDelay; @Override @@ -38,7 +41,14 @@ public class Util { } cancel(); } - }.runTaskTimerAsynchronously(plugin, 0, 20); + }.runTaskTimerAsynchronously(plugin, 0, 20)); + } + + public static void cancel(Player player) { + BukkitTask task = tasks.get(player.getName()); + if (task != null) { + task.cancel(); + } } public static void connect(final Player p, final String server) { diff --git a/src/main/java/pw/yumc/MiaoLobby/hook/VBossAuthHook.java b/src/main/java/pw/yumc/MiaoLobby/hook/VBossAuthHook.java index 8bcf113..2efa740 100644 --- a/src/main/java/pw/yumc/MiaoLobby/hook/VBossAuthHook.java +++ b/src/main/java/pw/yumc/MiaoLobby/hook/VBossAuthHook.java @@ -3,11 +3,17 @@ package pw.yumc.MiaoLobby.hook; import org.bukkit.event.EventHandler; import cn.citycraft.VBossAuth.event.LoginEvent; +import cn.citycraft.VBossAuth.event.RegisterEvent; import pw.yumc.MiaoLobby.Util; public class VBossAuthHook extends Hook { @EventHandler - public void onLogin(final LoginEvent e) { + public void onLogin(LoginEvent e) { + Util.delayTp(e.getPlayer()); + } + + @EventHandler + public void onRegister(RegisterEvent e) { Util.delayTp(e.getPlayer()); } }