diff --git a/src/com/cnaude/chairs/core/Chairs.java b/src/com/cnaude/chairs/core/Chairs.java index a0f78ea..96c8a34 100644 --- a/src/com/cnaude/chairs/core/Chairs.java +++ b/src/com/cnaude/chairs/core/Chairs.java @@ -88,7 +88,7 @@ public class Chairs extends JavaPlugin { @Override public void onDisable() { if (psitdata != null) { - for (Player player : getServer().getOnlinePlayers()) { + for (Player player : Utils.getOnlinePlayers()) { if (psitdata.isSitting(player)) { psitdata.unsitPlayerNow(player); } diff --git a/src/com/cnaude/chairs/core/Utils.java b/src/com/cnaude/chairs/core/Utils.java new file mode 100644 index 0000000..bb31029 --- /dev/null +++ b/src/com/cnaude/chairs/core/Utils.java @@ -0,0 +1,12 @@ +package com.cnaude.chairs.core; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class Utils { + + public static Player[] getOnlinePlayers() { + return Bukkit.getOnlinePlayers(); + } + +} diff --git a/src/com/cnaude/chairs/sitaddons/ChairEffects.java b/src/com/cnaude/chairs/sitaddons/ChairEffects.java index 1a39357..d951db0 100644 --- a/src/com/cnaude/chairs/sitaddons/ChairEffects.java +++ b/src/com/cnaude/chairs/sitaddons/ChairEffects.java @@ -5,11 +5,13 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.ExperienceOrb; import org.bukkit.entity.Item; import org.bukkit.entity.Player; +import org.bukkit.entity.Damageable; import org.bukkit.event.player.PlayerExpChangeEvent; import org.bukkit.event.player.PlayerLevelChangeEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import com.cnaude.chairs.core.Chairs; +import com.cnaude.chairs.core.Utils; public class ChairEffects { @@ -42,14 +44,14 @@ public class ChairEffects { healTaskID = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { @Override public void run() { - for (Player p : Bukkit.getOnlinePlayers()) { + for (Player p : Utils.getOnlinePlayers()) { if (plugin.getPlayerSitData().isSitting(p)) { if (p.hasPermission("chairs.sit.health")) { - double pHealthPcnt = (p.getHealth()) / p.getMaxHealth() * 100d; - if ((pHealthPcnt < plugin.sitMaxHealth) && (p.getHealth() < p.getMaxHealth())) { - double newHealth = plugin.sitHealthPerInterval + p.getHealth(); - if (newHealth > p.getMaxHealth()) { - newHealth = p.getMaxHealth(); + double pHealthPcnt = (getPlayerHealth(p)) / getMaxPlayerHealth(p) * 100d; + if ((pHealthPcnt < plugin.sitMaxHealth) && (getPlayerHealth(p) < getMaxPlayerHealth(p))) { + double newHealth = plugin.sitHealthPerInterval + getPlayerHealth(p); + if (newHealth > getMaxPlayerHealth(p)) { + newHealth = getMaxPlayerHealth(p); } p.setHealth(newHealth); } @@ -60,6 +62,14 @@ public class ChairEffects { }, plugin.sitHealInterval, plugin.sitHealInterval); } + private double getPlayerHealth(Player player) { + return ((Damageable) player).getHealth(); + } + + private double getMaxPlayerHealth(Player player) { + return ((Damageable) player).getMaxHealth(); + } + public void startPickup() { pickupEffectsTask(); } @@ -80,7 +90,7 @@ public class ChairEffects { pickupTaskID = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { @Override public void run() { - for (Player p : Bukkit.getOnlinePlayers()) { + for (Player p : Utils.getOnlinePlayers()) { if (plugin.getPlayerSitData().isSitting(p)) { for (Entity entity : p.getNearbyEntities(1, 2, 1)) { if (entity instanceof Item) {