From b45fd2101c92b4b00fabf0febf3caa349a60c02c Mon Sep 17 00:00:00 2001 From: Goh Wei Wen Date: Sun, 14 Jun 2020 22:45:38 +0800 Subject: [PATCH] Use Registry's Iterable implementation in announce command/task --- .../dungeonsxl/announcer/AnnouncerTask.java | 14 ++++++-------- .../dungeonsxl/command/AnnounceCommand.java | 16 +++++++--------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerTask.java b/core/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerTask.java index 313aa96a..461f3efa 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerTask.java +++ b/core/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerTask.java @@ -17,11 +17,10 @@ package de.erethon.dungeonsxl.announcer; import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.player.GlobalPlayer; +import de.erethon.dungeonsxl.api.player.InstancePlayer; import de.erethon.dungeonsxl.player.DGlobalPlayer; -import de.erethon.dungeonsxl.player.DInstancePlayer; import java.util.List; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; /** @@ -45,11 +44,10 @@ public class AnnouncerTask extends BukkitRunnable { public void run() { Announcer announcer = announcers.get(index); List worlds = announcer.getWorlds(); - for (Player player : Bukkit.getOnlinePlayers()) { - DGlobalPlayer dPlayer = (DGlobalPlayer) plugin.getPlayerCache().get(player); - if (!(dPlayer instanceof DInstancePlayer) && dPlayer.isAnnouncerEnabled()) { - if (worlds.isEmpty() || worlds.contains(player.getWorld().getName())) { - announcer.send(player); + for (GlobalPlayer dPlayer : plugin.getPlayerCache()) { + if (!(dPlayer instanceof InstancePlayer) && ((DGlobalPlayer) dPlayer).isAnnouncerEnabled()) { + if (worlds.isEmpty() || worlds.contains(dPlayer.getPlayer().getWorld().getName())) { + announcer.send(dPlayer.getPlayer()); } } } diff --git a/core/src/main/java/de/erethon/dungeonsxl/command/AnnounceCommand.java b/core/src/main/java/de/erethon/dungeonsxl/command/AnnounceCommand.java index 23c452de..6e42f1aa 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/command/AnnounceCommand.java +++ b/core/src/main/java/de/erethon/dungeonsxl/command/AnnounceCommand.java @@ -19,18 +19,17 @@ package de.erethon.dungeonsxl.command; import de.erethon.commons.chat.MessageUtil; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.announcer.Announcer; +import de.erethon.dungeonsxl.api.player.GlobalPlayer; +import de.erethon.dungeonsxl.api.player.InstancePlayer; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DGlobalPlayer; -import de.erethon.dungeonsxl.player.DInstancePlayer; import de.erethon.dungeonsxl.player.DPermission; -import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import java.util.List; /** - * @author Daniel Saukel + * @author Goh Wei Wen */ public class AnnounceCommand extends DCommand { @@ -55,11 +54,10 @@ public class AnnounceCommand extends DCommand { } List worlds = announcer.getWorlds(); - for (Player player : Bukkit.getOnlinePlayers()) { - DGlobalPlayer dPlayer = (DGlobalPlayer) plugin.getPlayerCache().get(player); - if (!(dPlayer instanceof DInstancePlayer) && dPlayer.isAnnouncerEnabled()) { - if (worlds.isEmpty() || worlds.contains(player.getWorld().getName())) { - announcer.send(player); + for (GlobalPlayer dPlayer : plugin.getPlayerCache()) { + if (!(dPlayer instanceof InstancePlayer) && ((DGlobalPlayer) dPlayer).isAnnouncerEnabled()) { + if (worlds.isEmpty() || worlds.contains(dPlayer.getPlayer().getWorld().getName())) { + announcer.send(dPlayer.getPlayer()); } } }