mirror of
https://github.com/taoneill/war.git
synced 2024-11-23 18:55:28 +01:00
Found a way to mimmick onDeath. Some tp errors not not systematic anymore.
This commit is contained in:
parent
64dbaaa00d
commit
c9680d7556
@ -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);
|
||||
|
@ -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<Team> 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<Team> 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");
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -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<Team> 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);
|
||||
|
Loading…
Reference in New Issue
Block a user