mirror of
https://github.com/taoneill/war.git
synced 2024-11-27 20:59:39 +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_COMMAND, playerListener, Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.PLAYER_MOVE, 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_DAMAGED, entityListener, Priority.Normal, this); // done thru Move at respawn
|
||||||
//pm.registerEvent(Event.Type.ENTITY_DAMAGEDBY_ENTITY, entityListener, Priority.Normal, this); //DAMAGE
|
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_PLACED, blockListener, Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.BLOCK_IGNITE, 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
|
// TODO Auto-generated constructor stub
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onEntityDamaged(EntityDamagedEvent event) {
|
// public void onEntityDamaged(EntityDamagedEvent event) {
|
||||||
Entity damaged = event.getEntity();
|
// Entity damaged = event.getEntity();
|
||||||
DamageCause cause = event.getCause();
|
// DamageCause cause = event.getCause();
|
||||||
if(damaged != null && damaged instanceof Player){
|
// if(damaged != null && damaged instanceof Player){
|
||||||
Player player = (Player)damaged;
|
// Player player = (Player)damaged;
|
||||||
int damage = event.getDamage();
|
// int damage = event.getDamage();
|
||||||
int currentPlayerHp = player.getHealth();
|
// int currentPlayerHp = player.getHealth();
|
||||||
if(damage >= currentPlayerHp) {
|
// if(damage >= currentPlayerHp) {
|
||||||
Warzone zone = war.warzone(player.getLocation());
|
// Warzone zone = war.warzone(player.getLocation());
|
||||||
if(war.getPlayerTeam(player.getName()) != null) {
|
// if(war.getPlayerTeam(player.getName()) != null) {
|
||||||
// player on a team killed himself
|
// // player on a team killed himself
|
||||||
handleDeath(((Player)damaged));
|
// handleDeath(((Player)damaged));
|
||||||
|
//
|
||||||
} else if (zone != null ) {
|
// } else if (zone != null ) {
|
||||||
player.teleportTo(zone.getTeleport());
|
// player.teleportTo(zone.getTeleport());
|
||||||
}
|
// }
|
||||||
event.setCancelled(true); // Don't totally kill the player
|
// event.setCancelled(true); // Don't totally kill the player
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void onEntityDamagedByBlock(EntityDamagedByBlockEvent event) {
|
// public void onEntityDamagedByBlock(EntityDamagedByBlockEvent event) {
|
||||||
Entity damaged = event.getEntity();
|
// Entity damaged = event.getEntity();
|
||||||
|
//
|
||||||
if(damaged != null && damaged instanceof Player){
|
// if(damaged != null && damaged instanceof Player){
|
||||||
Player player = (Player)damaged;
|
// Player player = (Player)damaged;
|
||||||
int damage = event.getDamage();
|
// int damage = event.getDamage();
|
||||||
int currentPlayerHp = player.getHealth();
|
// int currentPlayerHp = player.getHealth();
|
||||||
if(damage >= currentPlayerHp) {
|
// if(damage >= currentPlayerHp) {
|
||||||
Warzone zone = war.warzone(player.getLocation());
|
// Warzone zone = war.warzone(player.getLocation());
|
||||||
if(war.getPlayerTeam(player.getName()) != null) {
|
// if(war.getPlayerTeam(player.getName()) != null) {
|
||||||
// player on a team killed himself
|
// // player on a team killed himself
|
||||||
handleDeath(((Player)damaged));
|
// handleDeath(((Player)damaged));
|
||||||
|
//
|
||||||
} else if (zone != null ) {
|
// } else if (zone != null ) {
|
||||||
player.teleportTo(zone.getTeleport());
|
// player.teleportTo(zone.getTeleport());
|
||||||
}
|
// }
|
||||||
event.setCancelled(true); // Don't let the block totally kill the player
|
// event.setCancelled(true); // Don't let the block totally kill the player
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
public void onEntityDamagedByEntity(EntityDamagedByEntityEvent event) {
|
public void onEntityDamagedByEntity(EntityDamagedByEntityEvent event) {
|
||||||
|
// BUKKIT !!
|
||||||
Entity attacker = event.getDamager();
|
Entity attacker = event.getDamager();
|
||||||
Entity defender = event.getEntity();
|
Entity defender = event.getEntity();
|
||||||
|
|
||||||
@ -124,41 +125,41 @@ public class WarEntityListener extends EntityListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleDeath(Player player) {
|
private void handleDeath(Player player) {
|
||||||
Team team = war.getPlayerTeam(player.getName());
|
// Team team = war.getPlayerTeam(player.getName());
|
||||||
if(team != null){
|
// if(team != null){
|
||||||
// teleport to team spawn upon death
|
// // teleport to team spawn upon death
|
||||||
Warzone zone = war.warzone(player.getLocation());
|
// Warzone zone = war.warzone(player.getLocation());
|
||||||
boolean roundOver = false;
|
// boolean roundOver = false;
|
||||||
synchronized(zone) {
|
// synchronized(zone) {
|
||||||
int remaining = team.getRemainingTickets();
|
// int remaining = team.getRemainingTickets();
|
||||||
if(remaining == 0) { // your death caused your team to lose
|
// if(remaining == 0) { // your death caused your team to lose
|
||||||
List<Team> teams = zone.getTeams();
|
// List<Team> teams = zone.getTeams();
|
||||||
for(Team t : teams) {
|
// for(Team t : teams) {
|
||||||
t.teamcast(war.str("The battle is over. Team " + team.getName() + " lost: "
|
// t.teamcast(war.str("The battle is over. Team " + team.getName() + " lost: "
|
||||||
+ player.getName() + " hit the bottom of their life pool." ));
|
// + player.getName() + " hit the bottom of their life pool." ));
|
||||||
t.teamcast(war.str("A new battle begins. The warzone is being reset..."));
|
// t.teamcast(war.str("A new battle begins. The warzone is being reset..."));
|
||||||
if(!t.getName().equals(team.getName())) {
|
// if(!t.getName().equals(team.getName())) {
|
||||||
// all other teams get a point
|
// // all other teams get a point
|
||||||
t.addPoint();
|
// t.addPoint();
|
||||||
t.resetSign();
|
// t.resetSign();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
zone.endRound();
|
// zone.endRound();
|
||||||
zone.getVolume().resetBlocks();
|
// zone.getVolume().resetBlocks();
|
||||||
zone.initializeZone();
|
// zone.initializeZone();
|
||||||
roundOver = true;
|
// roundOver = true;
|
||||||
} else {
|
// } else {
|
||||||
team.setRemainingTickets(remaining - 1);
|
// team.setRemainingTickets(remaining - 1);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if(!roundOver) {
|
// if(!roundOver) {
|
||||||
zone.respawnPlayer(team, player);
|
// zone.respawnPlayer(team, player);
|
||||||
player.sendMessage(war.str("You died!"));
|
// player.sendMessage(war.str("You died!"));
|
||||||
team.resetSign();
|
// team.resetSign();
|
||||||
war.getLogger().log(Level.INFO, player.getName() + " died and was tp'd back to team " + team.getName() + "'s spawn");
|
// war.getLogger().log(Level.INFO, player.getName() + " died and was tp'd back to team " + team.getName() + "'s spawn");
|
||||||
} else {
|
// } else {
|
||||||
war.getLogger().log(Level.INFO, player.getName() + " died and battle ended in team " + team.getName() + "'s disfavor");
|
// 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());
|
Warzone playerWarzone = war.getPlayerWarzone(player.getName());
|
||||||
if(playerWarzone != null) {
|
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
|
// Monuments
|
||||||
if(to != null && playerTeam != null
|
if(to != null && team != null
|
||||||
&& playerWarzone.nearAnyOwnedMonument(to, playerTeam)
|
&& playerWarzone.nearAnyOwnedMonument(to, team)
|
||||||
&& player.getHealth() < 20
|
&& player.getHealth() < 20
|
||||||
&& random.nextInt(42) == 3 ) { // one chance out of many of getting healed
|
&& random.nextInt(42) == 3 ) { // one chance out of many of getting healed
|
||||||
player.setHealth(20);
|
player.setHealth(20);
|
||||||
|
Loading…
Reference in New Issue
Block a user