feat: optimize command tp

Signed-off-by: MiaoWoo <admin@yumc.pw>
master
MiaoWoo 2021-04-07 02:45:35 +00:00
parent dd7e87d890
commit 15c9b89fae
3 changed files with 19 additions and 10 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>MiaoLobby</artifactId> <artifactId>MiaoLobby</artifactId>
<version>2.1</version> <version>2.2</version>
<parent> <parent>
<groupId>pw.yumc</groupId> <groupId>pw.yumc</groupId>
@ -24,6 +24,7 @@
<properties> <properties>
<update.description>§a正式版本 §bv${project.version}</update.description> <update.description>§a正式版本 §bv${project.version}</update.description>
<update.changes> <update.changes>
§621-04-02 §a新增: 优化命令传送逻辑;
§621-04-01 §a新增: 重复传送限制 离线清理数据; §621-04-01 §a新增: 重复传送限制 离线清理数据;
</update.changes> </update.changes>
<update.changelog> <update.changelog>

View File

@ -20,7 +20,7 @@ import pw.yumc.YumCore.statistic.Statistics;
import pw.yumc.YumCore.update.SubscribeTask; import pw.yumc.YumCore.update.SubscribeTask;
public class MiaoLobby extends JavaPlugin implements Executor, Listener { public class MiaoLobby extends JavaPlugin implements Executor, Listener {
Config config; private Config config;
@EventHandler @EventHandler
public void onQuit(PlayerQuitEvent e) { 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) @Cmd(permission = "MiaoLobby.default", executor = Cmd.Executor.PLAYER)
@Help("进行随机服务器传送") @Help("进行随机服务器传送")
public boolean def(final Player player) { public boolean ml(final Player player) {
Util.delayTp(player); Util.delayTp(player, 0);
return true; return true;
} }
@ -39,6 +39,10 @@ public class MiaoLobby extends JavaPlugin implements Executor, Listener {
return config.getConfig(); return config.getConfig();
} }
public Config getMiaoLobbyConfig() {
return config;
}
@Override @Override
public void onEnable() { public void onEnable() {
new CommandSub("MiaoLobby", this); new CommandSub("MiaoLobby", this);

View File

@ -23,24 +23,28 @@ import java.util.Map;
* @since 2016/12/25 0025 * @since 2016/12/25 0025
*/ */
public class Util { public class Util {
private final static SecureRandom random = new SecureRandom(); private static final SecureRandom random = new SecureRandom();
private static MiaoLobby plugin = P.getPlugin(); private static final MiaoLobby plugin = P.getPlugin();
private static Config config = plugin.config; private static final Config config = P.getInjectConfig();
private static Map<String, BukkitTask> tasks = new HashMap<>(); private static final Map<String, BukkitTask> tasks = new HashMap<>();
public static void delayTp(final Player player) { 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())) { if (tasks.containsKey(player.getName())) {
Log.sender(player, config.TPing); Log.sender(player, config.TPing);
return; return;
} }
tasks.put(player.getName(), new BukkitRunnable() { tasks.put(player.getName(), new BukkitRunnable() {
int delay = config.AutoTPDelay; int delay = autoTPDelay;
@Override @Override
public void run() { public void run() {
if (player.isOnline()) { if (player.isOnline()) {
if (delay > 0) { if (delay > 0) {
C.ActionBar.send(player, String.format(plugin.config.TPDelay, delay)); C.ActionBar.send(player, String.format(config.TPDelay, delay));
delay--; delay--;
return; return;
} }