From 6758628cba917beae54b89a2bcc48cccc4c11427 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sat, 25 Jul 2015 15:26:14 +1000 Subject: [PATCH] Fixes #447 --- .../plot/listeners/PlotPlusListener.java | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java b/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java index 9b7903a80..495aaec3e 100644 --- a/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java +++ b/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java @@ -22,8 +22,10 @@ package com.intellectualcrafters.plot.listeners; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.UUID; import org.bukkit.Bukkit; @@ -69,30 +71,40 @@ public class PlotPlusListener extends PlotListener implements Listener { plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { @Override public void run() { - for (final Map.Entry entry : feedRunnable.entrySet()) { + for (Iterator> iter = healRunnable.entrySet().iterator(); iter.hasNext();){ + Entry entry = iter.next(); final Interval value = entry.getValue(); ++value.count; if (value.count == value.interval) { value.count = 0; final Player player = Bukkit.getPlayer(entry.getKey()); - final int level = player.getFoodLevel(); - if (level != value.max) { - player.setFoodLevel(Math.min(level + value.amount, value.max)); + if (player == null) { + iter.remove(); + continue; } - } - } - for (final Map.Entry entry : healRunnable.entrySet()) { - final Interval value = entry.getValue(); - ++value.count; - if (value.count == value.interval) { - value.count = 0; - final Player player = Bukkit.getPlayer(entry.getKey()); final double level = player.getHealth(); if (level != value.max) { player.setHealth(Math.min(level + value.amount, value.max)); } } } + for (Iterator> iter = feedRunnable.entrySet().iterator(); iter.hasNext();){ + Entry entry = iter.next(); + final Interval value = entry.getValue(); + ++value.count; + if (value.count == value.interval) { + value.count = 0; + final Player player = Bukkit.getPlayer(entry.getKey()); + if (player == null) { + iter.remove(); + continue; + } + final int level = player.getFoodLevel(); + if (level != value.max) { + player.setFoodLevel(Math.min(level + value.amount, value.max)); + } + } + } } }, 0l, 20l); } @@ -214,8 +226,9 @@ public class PlotPlusListener extends PlotListener implements Listener { event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', C.PREFIX_FAREWELL.s().replaceAll("%id%", plot.id + "") + FlagManager.getPlotFlag(plot, "farewell").getValueString())); } final PlotPlayer pl = BukkitUtil.getPlayer(leaver); - feedRunnable.remove(leaver.getName()); - healRunnable.remove(leaver.getName()); + String name = leaver.getName(); + feedRunnable.remove(name); + healRunnable.remove(name); if (FlagManager.isBooleanFlag(plot, "notify-leave", false)) { if (Permissions.hasPermission(pl, "plots.flag.notify-leave.bypass")) { return;