Some small changes
This commit is contained in:
parent
80d877390b
commit
0be55c3ec0
@ -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);
|
||||
}
|
||||
|
12
src/com/cnaude/chairs/core/Utils.java
Normal file
12
src/com/cnaude/chairs/core/Utils.java
Normal 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();
|
||||
}
|
||||
|
||||
}
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user