From 15c9b89fae74f9c2d6b59041c7b7c2830f475c41 Mon Sep 17 00:00:00 2001 From: MiaoWoo Date: Wed, 7 Apr 2021 02:45:35 +0000 Subject: [PATCH] feat: optimize command tp Signed-off-by: MiaoWoo --- pom.xml | 3 ++- src/main/java/pw/yumc/MiaoLobby/MiaoLobby.java | 10 +++++++--- src/main/java/pw/yumc/MiaoLobby/Util.java | 16 ++++++++++------ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 64bf076..cda2371 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 MiaoLobby - 2.1 + 2.2 pw.yumc @@ -24,6 +24,7 @@ §a正式版本 §bv${project.version} + §621-04-02 §a新增: 优化命令传送逻辑; §621-04-01 §a新增: 重复传送限制 离线清理数据; diff --git a/src/main/java/pw/yumc/MiaoLobby/MiaoLobby.java b/src/main/java/pw/yumc/MiaoLobby/MiaoLobby.java index f38d838..8af2705 100644 --- a/src/main/java/pw/yumc/MiaoLobby/MiaoLobby.java +++ b/src/main/java/pw/yumc/MiaoLobby/MiaoLobby.java @@ -20,7 +20,7 @@ import pw.yumc.YumCore.statistic.Statistics; import pw.yumc.YumCore.update.SubscribeTask; public class MiaoLobby extends JavaPlugin implements Executor, Listener { - Config config; + private Config config; @EventHandler public void onQuit(PlayerQuitEvent e) { @@ -29,8 +29,8 @@ public class MiaoLobby extends JavaPlugin implements Executor, Listener { @Cmd(permission = "MiaoLobby.default", executor = Cmd.Executor.PLAYER) @Help("进行随机服务器传送") - public boolean def(final Player player) { - Util.delayTp(player); + public boolean ml(final Player player) { + Util.delayTp(player, 0); return true; } @@ -39,6 +39,10 @@ public class MiaoLobby extends JavaPlugin implements Executor, Listener { return config.getConfig(); } + public Config getMiaoLobbyConfig() { + return config; + } + @Override public void onEnable() { new CommandSub("MiaoLobby", this); diff --git a/src/main/java/pw/yumc/MiaoLobby/Util.java b/src/main/java/pw/yumc/MiaoLobby/Util.java index 4a8c6b6..31e7ba7 100644 --- a/src/main/java/pw/yumc/MiaoLobby/Util.java +++ b/src/main/java/pw/yumc/MiaoLobby/Util.java @@ -23,24 +23,28 @@ import java.util.Map; * @since 2016/12/25 0025 */ 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 = new HashMap<>(); + private static final SecureRandom random = new SecureRandom(); + private static final MiaoLobby plugin = P.getPlugin(); + private static final Config config = P.getInjectConfig(); + private static final Map tasks = new HashMap<>(); public static void delayTp(final Player player) { + Util.delayTp(player, config.AutoTPDelay); + } + + public static void delayTp(final Player player, int autoTPDelay) { if (tasks.containsKey(player.getName())) { Log.sender(player, config.TPing); return; } tasks.put(player.getName(), new BukkitRunnable() { - int delay = config.AutoTPDelay; + int delay = autoTPDelay; @Override public void run() { if (player.isOnline()) { if (delay > 0) { - C.ActionBar.send(player, String.format(plugin.config.TPDelay, delay)); + C.ActionBar.send(player, String.format(config.TPDelay, delay)); delay--; return; }