mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-24 19:25:15 +01:00
Added armor (merged from zeeZ).
This commit is contained in:
parent
3b16a36b99
commit
3fd511a8d1
30
src/main/java/org/dynmap/Armor.java
Normal file
30
src/main/java/org/dynmap/Armor.java
Normal 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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -529,19 +529,47 @@
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.dynmap .playerHealth {
|
||||
.dynmap .healthContainer {
|
||||
display: block;
|
||||
position: absolute;
|
||||
bottom: 3px;
|
||||
bottom: 0;
|
||||
left: 34px;
|
||||
height: 11px;
|
||||
|
||||
background: url(../images/heart.png) rgba(0,0,0,0.6) repeat-x left center;
|
||||
padding: 1px 0;
|
||||
width: 50px;
|
||||
|
||||
background: rgba(0,0,0,0.6);
|
||||
padding: 2px;
|
||||
|
||||
-moz-border-radius: 3px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.dynmap .playerHealth {
|
||||
height: 7px;
|
||||
|
||||
background: url(../images/heart.png) repeat-x left center;
|
||||
}
|
||||
|
||||
.dynmap .playerHealthBackground {
|
||||
height: 7px;
|
||||
width: 50px;
|
||||
|
||||
background: url(../images/heart_depleted.png) repeat-x left center;
|
||||
}
|
||||
|
||||
.dynmap .playerArmor {
|
||||
height: 7px;
|
||||
|
||||
background: url(../images/armor.png) repeat-x left center;
|
||||
}
|
||||
|
||||
.dynmap .playerArmorBackground {
|
||||
height: 7px;
|
||||
width: 50px;
|
||||
|
||||
background: url(../images/armor_depleted.png) repeat-x left center;
|
||||
}
|
||||
|
||||
|
||||
/*******************
|
||||
* Compass
|
||||
|
BIN
web/images/armor.png
Normal file
BIN
web/images/armor.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 213 B |
BIN
web/images/armor_depleted.png
Normal file
BIN
web/images/armor_depleted.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 192 B |
Binary file not shown.
Before Width: | Height: | Size: 180 B After Width: | Height: | Size: 198 B |
BIN
web/images/heart_depleted.png
Normal file
BIN
web/images/heart_depleted.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 183 B |
@ -454,7 +454,8 @@ DynMap.prototype = {
|
||||
name: update.name,
|
||||
location: new Location(me.worlds[update.world], parseFloat(update.x), parseFloat(update.y), parseFloat(update.z)),
|
||||
health: update.health,
|
||||
account: update.account
|
||||
armor: update.armor,
|
||||
account: update.account
|
||||
};
|
||||
|
||||
$(me).trigger('playeradded', [ player ]);
|
||||
@ -497,6 +498,7 @@ DynMap.prototype = {
|
||||
var me = this;
|
||||
var location = player.location = new Location(me.worlds[update.world], parseFloat(update.x), parseFloat(update.y), parseFloat(update.z));
|
||||
player.health = update.health;
|
||||
player.armor = update.armor;
|
||||
|
||||
$(me).trigger('playerupdated', [ player ]);
|
||||
|
||||
|
@ -15,7 +15,7 @@ componentconstructors['playermarkers'] = function(dynmap, configuration) {
|
||||
.text(player.name));
|
||||
|
||||
if (configuration.showplayerfaces) {
|
||||
getMinecraftHead(player.account, 32, function(head) {
|
||||
getMinecraftHead(player.name, 32, function(head) {
|
||||
$(head)
|
||||
.addClass('playericon')
|
||||
.prependTo(div);
|
||||
@ -23,10 +23,28 @@ componentconstructors['playermarkers'] = function(dynmap, configuration) {
|
||||
});
|
||||
}
|
||||
if (configuration.showplayerhealth) {
|
||||
player.healthBar = $('<div/>')
|
||||
.addClass('playerHealth')
|
||||
.css('width', (player.health/2*9) + 'px')
|
||||
player.healthContainer = $('<div/>')
|
||||
.addClass('healthContainer')
|
||||
.appendTo(div);
|
||||
if (player.health !== undefined && player.armor !== undefined) {
|
||||
player.healthBar = $('<div/>')
|
||||
.addClass('playerHealth')
|
||||
.css('width', (player.health/2*5) + 'px');
|
||||
player.armorBar = $('<div/>')
|
||||
.addClass('playerArmor')
|
||||
.css('width', (player.armor/2*5) + 'px');
|
||||
|
||||
$('<div/>')
|
||||
.addClass('playerHealthBackground')
|
||||
.append(player.healthBar)
|
||||
.appendTo(player.healthContainer);
|
||||
$('<div/>')
|
||||
.addClass('playerArmorBackground')
|
||||
.append(player.armorBar)
|
||||
.appendTo(player.healthContainer);
|
||||
} else {
|
||||
player.healthContainer.css('display','none');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -40,7 +58,14 @@ componentconstructors['playermarkers'] = function(dynmap, configuration) {
|
||||
player.marker.toggle(dynmap.world === player.location.world);
|
||||
player.marker.setPosition(markerPosition);
|
||||
// Update health
|
||||
if (configuration.showplayerhealth)
|
||||
player.healthBar.css('width', (player.health/2*9) + 'px');
|
||||
if (configuration.showplayerhealth) {
|
||||
if (player.health !== undefined && player.armor !== undefined) {
|
||||
player.healthContainer.css('display','block');
|
||||
player.healthBar.css('width', (player.health/2*5) + 'px');
|
||||
player.armorBar.css('width', (player.armor/2*5) + 'px');
|
||||
} else {
|
||||
player.healthContainer.css('display','none');
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user