From 97ebfe21d1a8984030c2fa0fa2c78c00fc9b2ad7 Mon Sep 17 00:00:00 2001 From: HexedHero <6012891+HexedHero@users.noreply.github.com> Date: Thu, 25 Mar 2021 14:16:08 +0000 Subject: [PATCH] Improve runnables Don't make a new thread for every player join and only schedule the task if its the correct name --- .../me/badbones69/crazyauctions/Main.java | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/main/java/me/badbones69/crazyauctions/Main.java b/src/main/java/me/badbones69/crazyauctions/Main.java index f56e2ad..5684f1c 100644 --- a/src/main/java/me/badbones69/crazyauctions/Main.java +++ b/src/main/java/me/badbones69/crazyauctions/Main.java @@ -372,23 +372,17 @@ public class Main extends JavaPlugin implements Listener { @EventHandler public void onJoin(PlayerJoinEvent e) { final Player player = e.getPlayer(); - new BukkitRunnable() { - @Override - public void run() { - if (player.getName().equals("BadBones69")) { - player.sendMessage(Methods.getPrefix() + Methods.color("&7This server is running your Crazy Auctions Plugin. " + "&7It is running version &av" + Bukkit.getServer().getPluginManager().getPlugin("CrazyAuctions").getDescription().getVersion() + "&7.")); - } - } - }.runTaskLater(this, 40); + if (player.getName().equalsIgnoreCase("BadBones69")) { + Bukkit.getScheduler().runTaskLater(this, () -> { + player.sendMessage(Methods.getPrefix() + Methods.color("&7This server is running your Crazy Auctions Plugin. " + "&7It is running version &av" + Bukkit.getServer().getPluginManager().getPlugin("CrazyAuctions").getDescription().getVersion() + "&7.")); + }, 40); + } } private void startCheck() { - new BukkitRunnable() { - @Override - public void run() { - Methods.updateAuction(); - } - }.runTaskTimer(this, 20, 5 * 20); + Bukkit.getScheduler().runTaskTimer(this, () -> { + Methods.updateAuction(); + }, 20, 5 * 20); } private ArrayList getDamageableItems() {