Added armor (merged from zeeZ).

This commit is contained in:
zeeZ 2011-05-22 16:09:50 +02:00 committed by FrozenCow
parent 3b16a36b99
commit 3fd511a8d1
9 changed files with 99 additions and 13 deletions

View file

@ -0,0 +1,30 @@
package org.dynmap;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class Armor {
/**
* http://www.minecraftwiki.net/wiki/Item_Durability#Armor_durability
* We rely on getArmorContents() to return 4 armor pieces in the order
* of: boots, pants, chest, helmet
*/
private static final double armorPoints[] = {1.5, 3.0, 4.0, 1.5};
public static final int getArmorPoints(Player player) {
int currentDurability = 0;
int baseDurability = 0;
double baseArmorPoints = 0;
ItemStack inventory[] = player.getInventory().getArmorContents();
for(int i=0;i<inventory.length;i++) {
final short maxDurability = inventory[i].getType().getMaxDurability();
if(maxDurability < 0)
continue;
final short durability = inventory[i].getDurability();
baseDurability += maxDurability;
currentDurability += maxDurability - durability;
baseArmorPoints += armorPoints[i];
}
return (int)(2*baseArmorPoints*currentDurability/baseDurability);
}
}

View file

@ -45,6 +45,7 @@ public class ClientUpdateComponent extends Component {
s(jp, "z", pl.getZ());
if (configuration.getBoolean("sendhealth", false)) {
s(jp, "health", p.getHealth());
s(jp, "armor", Armor.getArmorPoints(p));
}
a(u, "players", jp);
}