diff --git a/doc/api.md b/doc/api.md index f748ee2..3ab6cee 100644 --- a/doc/api.md +++ b/doc/api.md @@ -62,6 +62,7 @@ - [player.spawn()](#playerspawn) - [player.setGameMode(gameMode)](#playersetgamemodegamemode) - [player.handleCommand(command)](#playerhandlecommandcommand) + - [player.updateHealth(health)](#playerupdatehealthhealth) - [Low level properties](#low-level-properties) - [player._client](#player_client) - [Low level methods](#low-level-methods) @@ -288,6 +289,10 @@ set player gameMode to `gameMode` handle `command` +#### player.updateHealth(health) + +update the player health. + ### Low level properties #### player._client diff --git a/lib/playerPlugins/pvp.js b/lib/playerPlugins/pvp.js index dc693b2..36066b4 100644 --- a/lib/playerPlugins/pvp.js +++ b/lib/playerPlugins/pvp.js @@ -15,12 +15,7 @@ function inject(serv, player) function attackEntity(entityId) { var attackedPlayer = serv.entities[entityId].player; - attackedPlayer.entity.health -= 1; - attackedPlayer._client.write('update_health', { - food: attackedPlayer.entity.food, - foodSaturation: 0.0, - health: attackedPlayer.entity.health - }); + attackedPlayer.updateHealth(attackedPlayer.entity.health - 1); if(attackedPlayer.entity.health==0) attackedPlayer._writeOthers('entity_status',{