From da049b46185b2d6cd26e24200ca4df2fbaca45d4 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 28 Feb 2017 14:03:05 +0100 Subject: [PATCH] Fix deaths; resolves #210 --- .../dre2n/dungeonsxl/config/DMessages.java | 1 + .../dre2n/dungeonsxl/player/DGamePlayer.java | 39 ++++++++++--------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java index f0b2643b..e6845493 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -178,6 +178,7 @@ public enum DMessages implements Messages { LOG_WORLD_GENERATION_FINISHED("Log_WorldGenerationFinished", "&6World generation finished!"), MISC_NO("Misc_No", "&4[ NO ]"), MISC_OKAY("Misc_Okay", "&a[ OK ]"), + MISC_UNLIMITED("Misc_Unlimited", "unlimited"), MISC_YES("Misc_Yes", "&a[ YES ]"), PLAYER_BLOCK_INFO("Player_BlockInfo", "&6Block ID: &2&v1"), PLAYER_CHECKPOINT_REACHED("Player_CheckpointReached", "&6Checkpoint reached!"), diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java index e8e05d7c..63727a41 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java @@ -817,28 +817,31 @@ public void onDeath(PlayerDeathEvent event) { return; } - if (lives != -1) { - lives = lives - dPlayerDeathEvent.getLostLives(); + if (game.getRules().getKeepInventoryOnDeath()) { + setRespawnInventory(event.getEntity().getInventory().getContents()); + setRespawnArmor(event.getEntity().getInventory().getArmorContents()); + // Delete all drops + for (ItemStack item : event.getDrops()) { + item.setType(Material.AIR); + } + } + + if (getDGroup() != null && dGroup.getLives() != -1) { + dGroup.setLives(dGroup.getLives() - 1); + MessageUtil.broadcastMessage(DMessages.GROUP_DEATH.getMessage(getName(), dGroup.getName(), String.valueOf(dGroup.getLives()))); + + } else { + if (lives != -1) { + lives = lives - dPlayerDeathEvent.getLostLives(); + } DGamePlayer killer = DGamePlayer.getByPlayer(player.getKiller()); + String newLives = lives == -1 ? DMessages.MISC_UNLIMITED.getMessage() : String.valueOf(this.lives); if (killer != null) { - gameWorld.sendMessage(DMessages.PLAYER_KILLED.getMessage(getName(), killer.getName(), String.valueOf(lives))); + gameWorld.sendMessage(DMessages.PLAYER_KILLED.getMessage(getName(), killer.getName(), newLives)); } else { - gameWorld.sendMessage(DMessages.PLAYER_DEATH.getMessage(getName(), String.valueOf(lives))); - } - - if (game.getRules().getKeepInventoryOnDeath()) { - setRespawnInventory(event.getEntity().getInventory().getContents()); - setRespawnArmor(event.getEntity().getInventory().getArmorContents()); - // Delete all drops - for (ItemStack item : event.getDrops()) { - item.setType(Material.AIR); - } + gameWorld.sendMessage(DMessages.PLAYER_DEATH.getMessage(getName(), newLives)); } - - } else if (getDGroup() != null && dGroup.getLives() != -1) { - dGroup.setLives(dGroup.getLives() - 1); - MessageUtil.broadcastMessage(DMessages.GROUP_DEATH.getMessage(player.getName(), String.valueOf(lives))); } if (isStealing()) { @@ -851,7 +854,7 @@ public void onDeath(PlayerDeathEvent event) { } } - if (lives == 0 && ready) { + if ((dGroup.getLives() == 0 || lives == 0) && ready) { kill(); }