From 420b880c63a0aa1df22374460263ef427c284c5c Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sun, 24 Feb 2019 00:59:02 +0100 Subject: [PATCH] Get rid of one-line separate class tasks --- .../dungeonsxl/player/DPlayerCache.java | 16 +++++++- .../dungeonsxl/player/LazyUpdateTask.java | 40 ------------------- .../erethon/dungeonsxl/player/UpdateTask.java | 40 ------------------- .../dungeonsxl/sign/lobby/ReadySign.java | 1 - .../dungeonsxl/world/DResourceWorld.java | 4 +- .../erethon/dungeonsxl/world/DWorldCache.java | 4 +- 6 files changed, 17 insertions(+), 88 deletions(-) delete mode 100644 src/main/java/de/erethon/dungeonsxl/player/LazyUpdateTask.java delete mode 100644 src/main/java/de/erethon/dungeonsxl/player/UpdateTask.java diff --git a/src/main/java/de/erethon/dungeonsxl/player/DPlayerCache.java b/src/main/java/de/erethon/dungeonsxl/player/DPlayerCache.java index a5429ef7..527f7450 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/DPlayerCache.java +++ b/src/main/java/de/erethon/dungeonsxl/player/DPlayerCache.java @@ -26,6 +26,7 @@ import java.util.UUID; import java.util.concurrent.CopyOnWriteArrayList; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; /** * DGlobalPlayer instance manager. @@ -49,8 +50,19 @@ public class DPlayerCache { if (config.isSecureModeEnabled()) { new SecureModeTask(plugin).runTaskTimer(plugin, config.getSecureModeCheckInterval(), config.getSecureModeCheckInterval()); } - new UpdateTask(plugin).runTaskTimer(plugin, 2L, 2L); - new LazyUpdateTask(plugin).runTaskTimer(plugin, 20L, 20L); + + new BukkitRunnable() { + @Override + public void run() { + plugin.getDPlayerCache().getDGamePlayers().forEach(p -> p.update(false)); + } + }.runTaskTimer(plugin, 2L, 2L); + new BukkitRunnable() { + @Override + public void run() { + plugin.getDPlayerCache().getDGamePlayers().forEach(p -> p.update(true)); + } + }.runTaskTimer(plugin, 20L, 20L); Bukkit.getPluginManager().registerEvents(new DPlayerListener(plugin), plugin); } diff --git a/src/main/java/de/erethon/dungeonsxl/player/LazyUpdateTask.java b/src/main/java/de/erethon/dungeonsxl/player/LazyUpdateTask.java deleted file mode 100644 index 85acd329..00000000 --- a/src/main/java/de/erethon/dungeonsxl/player/LazyUpdateTask.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2012-2019 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.player; - -import de.erethon.dungeonsxl.DungeonsXL; -import org.bukkit.scheduler.BukkitRunnable; - -/** - * @author Frank Baumann, Daniel Saukel - */ -public class LazyUpdateTask extends BukkitRunnable { - - private DungeonsXL plugin; - - public LazyUpdateTask(DungeonsXL plugin) { - this.plugin = plugin; - } - - @Override - public void run() { - for (DGamePlayer dPlayer : plugin.getDPlayerCache().getDGamePlayers()) { - dPlayer.update(true); - } - } - -} diff --git a/src/main/java/de/erethon/dungeonsxl/player/UpdateTask.java b/src/main/java/de/erethon/dungeonsxl/player/UpdateTask.java deleted file mode 100644 index b0a68d8e..00000000 --- a/src/main/java/de/erethon/dungeonsxl/player/UpdateTask.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2012-2019 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.player; - -import de.erethon.dungeonsxl.DungeonsXL; -import org.bukkit.scheduler.BukkitRunnable; - -/** - * @author Frank Baumann, Daniel Saukel - */ -public class UpdateTask extends BukkitRunnable { - - private DungeonsXL plugin; - - public UpdateTask(DungeonsXL plugin) { - this.plugin = plugin; - } - - @Override - public void run() { - for (DInstancePlayer dPlayer : plugin.getDPlayerCache().getDInstancePlayers()) { - dPlayer.update(false); - } - } - -} diff --git a/src/main/java/de/erethon/dungeonsxl/sign/lobby/ReadySign.java b/src/main/java/de/erethon/dungeonsxl/sign/lobby/ReadySign.java index 047db882..ced274e4 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/lobby/ReadySign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/lobby/ReadySign.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.sign.lobby; import de.erethon.caliburn.item.VanillaItem; -import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.misc.NumberUtil; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.config.DMessage; diff --git a/src/main/java/de/erethon/dungeonsxl/world/DResourceWorld.java b/src/main/java/de/erethon/dungeonsxl/world/DResourceWorld.java index 1a6b0882..253b6777 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/DResourceWorld.java +++ b/src/main/java/de/erethon/dungeonsxl/world/DResourceWorld.java @@ -197,7 +197,7 @@ public class DResourceWorld { * @param game whether the instance is a DGameWorld * @return an instance of this world */ - public DInstanceWorld instantiate(final boolean game) { + public DInstanceWorld instantiate(boolean game) { int id = worlds.generateId(); String name = worlds.generateName(game, id); @@ -223,7 +223,7 @@ public class DResourceWorld { FileUtil.copyDir(folder, instanceFolder, DungeonsXL.EXCLUDED_FILES); instance.world = Bukkit.createWorld(WorldCreator.name(name).environment(getWorldEnvironment())); - if (Bukkit.getPluginManager().getPlugin("dynmap") != null) { + if (Bukkit.getPluginManager().isPluginEnabled("dynmap")) { Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "dynmap pause all"); Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "dmap worldset " + name + " enabled:false"); Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "dynmap pause none"); diff --git a/src/main/java/de/erethon/dungeonsxl/world/DWorldCache.java b/src/main/java/de/erethon/dungeonsxl/world/DWorldCache.java index 0a5de173..1590dfb2 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/DWorldCache.java +++ b/src/main/java/de/erethon/dungeonsxl/world/DWorldCache.java @@ -29,7 +29,6 @@ import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.WorldCreator; import org.bukkit.WorldType; -import org.bukkit.scheduler.BukkitTask; /** * World instance manager. @@ -252,8 +251,7 @@ public class DWorldCache { */ public void deleteAllInstances() { BackupMode backupMode = config.getBackupMode(); - HashSet instances = new HashSet<>(this.instances); - for (DInstanceWorld instance : instances) { + for (DInstanceWorld instance : instances.toArray(new DInstanceWorld[instances.size()])) { if (backupMode == BackupMode.ON_DISABLE | backupMode == BackupMode.ON_DISABLE_AND_SAVE && instance instanceof DEditWorld) { instance.getResource().backup(); }