Use Registry's Iterable implementation in announce command/task

This commit is contained in:
Goh Wei Wen 2020-06-14 22:45:38 +08:00
parent 2e1339b8e8
commit b45fd2101c
2 changed files with 13 additions and 17 deletions

View File

@ -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<String> 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());
}
}
}

View File

@ -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<String> 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());
}
}
}