Fix onDeath

This commit is contained in:
Daniel Saukel 2015-09-20 17:18:57 +02:00
parent 56c3e982ba
commit c98e52a925

View File

@ -15,40 +15,46 @@ import com.dre.dungeonsxl.P;
import com.dre.dungeonsxl.game.GameWorld; import com.dre.dungeonsxl.game.GameWorld;
public class PlayerDeathListener implements Listener { public class PlayerDeathListener implements Listener {
P p = P.p; P p = P.p;
int lives = -1; int lives = -1;
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onDeath(PlayerDeathEvent event) { public void onDeath(PlayerDeathEvent event) {
Player player = event.getEntity(); Player player = event.getEntity();
DPlayer dPlayer = DPlayer.get(player); DPlayer dPlayer = DPlayer.get(player);
DConfig dConfig = GameWorld.get(player.getLocation().getWorld()).config; GameWorld gameWorld = GameWorld.get(player.getLocation().getWorld());
if (gameWorld != null) {
if (dPlayer != null) { DConfig dConfig = gameWorld.config;
if (dConfig.getKeepInventoryOnDeath()) {
dPlayer.respawnInventory = event.getEntity().getInventory().getContents(); if (dPlayer != null) {
dPlayer.respawnArmor = event.getEntity().getInventory().getArmorContents(); if (dConfig != null) {
// Delete all drops if (dConfig.getKeepInventoryOnDeath()) {
for (ItemStack istack : event.getDrops()) { dPlayer.respawnInventory = event.getEntity().getInventory().getContents();
istack.setType(Material.AIR); dPlayer.respawnArmor = event.getEntity().getInventory().getArmorContents();
// Delete all drops
for (ItemStack istack : event.getDrops()) {
istack.setType(Material.AIR);
}
}
}
if (p.lives.containsKey(player)) {
lives = p.lives.get(player) - 1;
p.lives.put(player, lives);
}
if (lives == 0 && dPlayer.isReady) {
Bukkit.broadcastMessage(p.language.get("Player_DeathKick").replaceAll("v1", player.getName()).replaceAll("&", "\u00a7"));
player.performCommand("dxl leave");
} else if ( !(lives == -1)) {
p.msg(player, p.language.get("Player_Death").replaceAll("v1", String.valueOf(lives)));
} }
} }
if (p.lives.containsKey(player)) {
lives = p.lives.get(player) - 1;
p.lives.put(player, lives);
}
if (lives == 0 && dPlayer.isReady) {
Bukkit.broadcastMessage(p.language.get("Player_DeathKick").replaceAll("v1", player.getName()).replaceAll("&", "\u00a7"));
player.performCommand("dxl leave");
} else if (!(lives == -1)) {
p.msg(player, p.language.get("Player_Death").replaceAll("v1", String.valueOf(lives)));
}
} }
} }
} }