Some small changes

This commit is contained in:
Shevchik 2014-07-10 05:08:24 +04:00
parent 80d877390b
commit 0be55c3ec0
3 changed files with 30 additions and 8 deletions

View File

@ -88,7 +88,7 @@ public class Chairs extends JavaPlugin {
@Override @Override
public void onDisable() { public void onDisable() {
if (psitdata != null) { if (psitdata != null) {
for (Player player : getServer().getOnlinePlayers()) { for (Player player : Utils.getOnlinePlayers()) {
if (psitdata.isSitting(player)) { if (psitdata.isSitting(player)) {
psitdata.unsitPlayerNow(player); psitdata.unsitPlayerNow(player);
} }

View File

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

View File

@ -5,11 +5,13 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.ExperienceOrb; import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Damageable;
import org.bukkit.event.player.PlayerExpChangeEvent; import org.bukkit.event.player.PlayerExpChangeEvent;
import org.bukkit.event.player.PlayerLevelChangeEvent; import org.bukkit.event.player.PlayerLevelChangeEvent;
import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerPickupItemEvent;
import com.cnaude.chairs.core.Chairs; import com.cnaude.chairs.core.Chairs;
import com.cnaude.chairs.core.Utils;
public class ChairEffects { public class ChairEffects {
@ -42,14 +44,14 @@ public class ChairEffects {
healTaskID = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { healTaskID = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
@Override @Override
public void run() { public void run() {
for (Player p : Bukkit.getOnlinePlayers()) { for (Player p : Utils.getOnlinePlayers()) {
if (plugin.getPlayerSitData().isSitting(p)) { if (plugin.getPlayerSitData().isSitting(p)) {
if (p.hasPermission("chairs.sit.health")) { if (p.hasPermission("chairs.sit.health")) {
double pHealthPcnt = (p.getHealth()) / p.getMaxHealth() * 100d; double pHealthPcnt = (getPlayerHealth(p)) / getMaxPlayerHealth(p) * 100d;
if ((pHealthPcnt < plugin.sitMaxHealth) && (p.getHealth() < p.getMaxHealth())) { if ((pHealthPcnt < plugin.sitMaxHealth) && (getPlayerHealth(p) < getMaxPlayerHealth(p))) {
double newHealth = plugin.sitHealthPerInterval + p.getHealth(); double newHealth = plugin.sitHealthPerInterval + getPlayerHealth(p);
if (newHealth > p.getMaxHealth()) { if (newHealth > getMaxPlayerHealth(p)) {
newHealth = p.getMaxHealth(); newHealth = getMaxPlayerHealth(p);
} }
p.setHealth(newHealth); p.setHealth(newHealth);
} }
@ -60,6 +62,14 @@ public class ChairEffects {
}, plugin.sitHealInterval, plugin.sitHealInterval); }, 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() { public void startPickup() {
pickupEffectsTask(); pickupEffectsTask();
} }
@ -80,7 +90,7 @@ public class ChairEffects {
pickupTaskID = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { pickupTaskID = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
@Override @Override
public void run() { public void run() {
for (Player p : Bukkit.getOnlinePlayers()) { for (Player p : Utils.getOnlinePlayers()) {
if (plugin.getPlayerSitData().isSitting(p)) { if (plugin.getPlayerSitData().isSitting(p)) {
for (Entity entity : p.getNearbyEntities(1, 2, 1)) { for (Entity entity : p.getNearbyEntities(1, 2, 1)) {
if (entity instanceof Item) { if (entity instanceof Item) {