From c9680d75565ed49eb15d32a512b83a90ebe37363 Mon Sep 17 00:00:00 2001 From: taoneill Date: Sat, 15 Jan 2011 21:16:31 -0500 Subject: [PATCH] Found a way to mimmick onDeath. Some tp errors not not systematic anymore. --- .../main/java/bukkit/tommytony/war/War.java | 4 +- .../tommytony/war/WarEntityListener.java | 157 +++++++++--------- .../tommytony/war/WarPlayerListener.java | 45 ++++- 3 files changed, 123 insertions(+), 83 deletions(-) diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java index b9588c6..c96f076 100644 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ b/war/src/main/java/bukkit/tommytony/war/War.java @@ -65,8 +65,8 @@ public class War extends JavaPlugin { pm.registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Normal, this); - pm.registerEvent(Event.Type.ENTITY_DAMAGED, entityListener, Priority.Normal, this); - //pm.registerEvent(Event.Type.ENTITY_DAMAGEDBY_ENTITY, entityListener, Priority.Normal, this); //DAMAGE + //pm.registerEvent(Event.Type.ENTITY_DAMAGED, entityListener, Priority.Normal, this); // done thru Move at respawn + pm.registerEvent(Event.Type.ENTITY_DAMAGEDBY_ENTITY, entityListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_IGNITE, blockListener, Priority.Normal, this); diff --git a/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java b/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java index d0e28a8..b72ed83 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java @@ -28,50 +28,51 @@ public class WarEntityListener extends EntityListener { // TODO Auto-generated constructor stub } - public void onEntityDamaged(EntityDamagedEvent event) { - Entity damaged = event.getEntity(); - DamageCause cause = event.getCause(); - if(damaged != null && damaged instanceof Player){ - Player player = (Player)damaged; - int damage = event.getDamage(); - int currentPlayerHp = player.getHealth(); - if(damage >= currentPlayerHp) { - Warzone zone = war.warzone(player.getLocation()); - if(war.getPlayerTeam(player.getName()) != null) { - // player on a team killed himself - handleDeath(((Player)damaged)); - - } else if (zone != null ) { - player.teleportTo(zone.getTeleport()); - } - event.setCancelled(true); // Don't totally kill the player - } - } - } - - public void onEntityDamagedByBlock(EntityDamagedByBlockEvent event) { - Entity damaged = event.getEntity(); - - if(damaged != null && damaged instanceof Player){ - Player player = (Player)damaged; - int damage = event.getDamage(); - int currentPlayerHp = player.getHealth(); - if(damage >= currentPlayerHp) { - Warzone zone = war.warzone(player.getLocation()); - if(war.getPlayerTeam(player.getName()) != null) { - // player on a team killed himself - handleDeath(((Player)damaged)); - - } else if (zone != null ) { - player.teleportTo(zone.getTeleport()); - } - event.setCancelled(true); // Don't let the block totally kill the player - } - } - - } +// public void onEntityDamaged(EntityDamagedEvent event) { +// Entity damaged = event.getEntity(); +// DamageCause cause = event.getCause(); +// if(damaged != null && damaged instanceof Player){ +// Player player = (Player)damaged; +// int damage = event.getDamage(); +// int currentPlayerHp = player.getHealth(); +// if(damage >= currentPlayerHp) { +// Warzone zone = war.warzone(player.getLocation()); +// if(war.getPlayerTeam(player.getName()) != null) { +// // player on a team killed himself +// handleDeath(((Player)damaged)); +// +// } else if (zone != null ) { +// player.teleportTo(zone.getTeleport()); +// } +// event.setCancelled(true); // Don't totally kill the player +// } +// } +// } +// +// public void onEntityDamagedByBlock(EntityDamagedByBlockEvent event) { +// Entity damaged = event.getEntity(); +// +// if(damaged != null && damaged instanceof Player){ +// Player player = (Player)damaged; +// int damage = event.getDamage(); +// int currentPlayerHp = player.getHealth(); +// if(damage >= currentPlayerHp) { +// Warzone zone = war.warzone(player.getLocation()); +// if(war.getPlayerTeam(player.getName()) != null) { +// // player on a team killed himself +// handleDeath(((Player)damaged)); +// +// } else if (zone != null ) { +// player.teleportTo(zone.getTeleport()); +// } +// event.setCancelled(true); // Don't let the block totally kill the player +// } +// } +// +// } public void onEntityDamagedByEntity(EntityDamagedByEntityEvent event) { + // BUKKIT !! Entity attacker = event.getDamager(); Entity defender = event.getEntity(); @@ -124,41 +125,41 @@ public class WarEntityListener extends EntityListener { } private void handleDeath(Player player) { - Team team = war.getPlayerTeam(player.getName()); - if(team != null){ - // teleport to team spawn upon death - Warzone zone = war.warzone(player.getLocation()); - boolean roundOver = false; - synchronized(zone) { - int remaining = team.getRemainingTickets(); - if(remaining == 0) { // your death caused your team to lose - List teams = zone.getTeams(); - for(Team t : teams) { - t.teamcast(war.str("The battle is over. Team " + team.getName() + " lost: " - + player.getName() + " hit the bottom of their life pool." )); - t.teamcast(war.str("A new battle begins. The warzone is being reset...")); - if(!t.getName().equals(team.getName())) { - // all other teams get a point - t.addPoint(); - t.resetSign(); - } - } - zone.endRound(); - zone.getVolume().resetBlocks(); - zone.initializeZone(); - roundOver = true; - } else { - team.setRemainingTickets(remaining - 1); - } - } - if(!roundOver) { - zone.respawnPlayer(team, player); - player.sendMessage(war.str("You died!")); - team.resetSign(); - war.getLogger().log(Level.INFO, player.getName() + " died and was tp'd back to team " + team.getName() + "'s spawn"); - } else { - war.getLogger().log(Level.INFO, player.getName() + " died and battle ended in team " + team.getName() + "'s disfavor"); - } - } +// Team team = war.getPlayerTeam(player.getName()); +// if(team != null){ +// // teleport to team spawn upon death +// Warzone zone = war.warzone(player.getLocation()); +// boolean roundOver = false; +// synchronized(zone) { +// int remaining = team.getRemainingTickets(); +// if(remaining == 0) { // your death caused your team to lose +// List teams = zone.getTeams(); +// for(Team t : teams) { +// t.teamcast(war.str("The battle is over. Team " + team.getName() + " lost: " +// + player.getName() + " hit the bottom of their life pool." )); +// t.teamcast(war.str("A new battle begins. The warzone is being reset...")); +// if(!t.getName().equals(team.getName())) { +// // all other teams get a point +// t.addPoint(); +// t.resetSign(); +// } +// } +// zone.endRound(); +// zone.getVolume().resetBlocks(); +// zone.initializeZone(); +// roundOver = true; +// } else { +// team.setRemainingTickets(remaining - 1); +// } +// } +// if(!roundOver) { +// zone.respawnPlayer(team, player); +// player.sendMessage(war.str("You died!")); +// team.resetSign(); +// war.getLogger().log(Level.INFO, player.getName() + " died and was tp'd back to team " + team.getName() + "'s spawn"); +// } else { +// war.getLogger().log(Level.INFO, player.getName() + " died and battle ended in team " + team.getName() + "'s disfavor"); +// } +// } } } diff --git a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java index 744543f..d064e1b 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java @@ -602,11 +602,50 @@ public class WarPlayerListener extends PlayerListener { Warzone playerWarzone = war.getPlayerWarzone(player.getName()); if(playerWarzone != null) { - Team playerTeam = war.getPlayerTeam(player.getName()); + Team team = war.getPlayerTeam(player.getName()); + + // Player belongs to a warzone team but is outside: he just died! Handle death! + if(to != null && war.warzone(player.getLocation()) == null && team != null) { + // teleport to team spawn upon death + + boolean roundOver = false; + synchronized(playerWarzone) { + int remaining = team.getRemainingTickets(); + if(remaining == 0) { // your death caused your team to lose + List teams = playerWarzone.getTeams(); + for(Team t : teams) { + t.teamcast(war.str("The battle is over. Team " + team.getName() + " lost: " + + player.getName() + " hit the bottom of their life pool." )); + t.teamcast(war.str("A new battle begins. The warzone is being reset...")); + if(!t.getName().equals(team.getName())) { + // all other teams get a point + t.addPoint(); + t.resetSign(); + } + } + playerWarzone.endRound(); + playerWarzone.getVolume().resetBlocks(); + playerWarzone.initializeZone(); + roundOver = true; + } else { + team.setRemainingTickets(remaining - 1); + } + } + synchronized(player) { + if(!roundOver && war.warzone(player.getLocation()) == null) { // only respawn him if he isnt back at zone yet + playerWarzone.respawnPlayer(event, team, player); + player.sendMessage(war.str("You died!")); + team.resetSign(); + war.getLogger().log(Level.INFO, player.getName() + " died and was tp'd back to team " + team.getName() + "'s spawn"); + } else { + war.getLogger().log(Level.INFO, player.getName() + " died and battle ended in team " + team.getName() + "'s disfavor"); + } + } + } // Monuments - if(to != null && playerTeam != null - && playerWarzone.nearAnyOwnedMonument(to, playerTeam) + if(to != null && team != null + && playerWarzone.nearAnyOwnedMonument(to, team) && player.getHealth() < 20 && random.nextInt(42) == 3 ) { // one chance out of many of getting healed player.setHealth(20);