Introduce "last player standing" to death event.

It is now possible to check if an arena player who died was the last
player alive in the arena. Useful for special rewards and stuff.
This commit is contained in:
garbagemule 2013-08-08 06:09:07 +02:00
parent e3381e895d
commit 544fd91de9
4 changed files with 25 additions and 6 deletions

View File

@ -1,7 +1,7 @@
name: MobArena
author: garbagemule
main: com.garbagemule.MobArena.MobArena
version: 0.95.5.11
version: 0.95.5.12
softdepend: [Spout,Towny,Heroes,MagicSpells,Vault]
commands:
ma:

View File

@ -99,6 +99,9 @@ public class ArenaImpl implements Arena
// Scoreboards
private ScoreboardManager scoreboard;
// Last player standing
private Player lastStanding;
/**
* Primary constructor. Requires a name and a world.
*/
@ -485,6 +488,9 @@ public class ArenaImpl implements Arena
return false;
}
// Reset last standing
lastStanding = null;
// Set the running boolean and disable arena if not disabled.
boolean en = enabled;
enabled = false;
@ -652,7 +658,7 @@ public class ArenaImpl implements Arena
public void playerDeath(Player p)
{
// Fire the event
ArenaPlayerDeathEvent event = new ArenaPlayerDeathEvent(p, this);
ArenaPlayerDeathEvent event = new ArenaPlayerDeathEvent(p, this, arenaPlayers.size() == 1);
plugin.getServer().getPluginManager().callEvent(event);
arenaPlayers.remove(p);
@ -1053,7 +1059,7 @@ public class ArenaImpl implements Arena
private void replacePermissions(Player p, PermissionAttachment rep) {
PermissionAttachment old = attachments.get(p);
if (old != null) {
p.removeAttachment(old);
old.remove();
p.recalculatePermissions();
}
if (rep != null) {
@ -1404,6 +1410,11 @@ public class ArenaImpl implements Arena
return isolatedChat;
}
@Override
public Player getLastPlayerStanding() {
return lastStanding;
}
/**
* The "perfect equals method" cf. "Object-Oriented Design and Patterns"
* by Cay S. Horstmann.

View File

@ -11,10 +11,12 @@ public class ArenaPlayerDeathEvent extends Event
private static final HandlerList handlers = new HandlerList();
private Player player;
private Arena arena;
private boolean last;
public ArenaPlayerDeathEvent(Player player, Arena arena) {
public ArenaPlayerDeathEvent(Player player, Arena arena, boolean last) {
this.player = player;
this.arena = arena;
this.arena = arena;
this.last = last;
}
public Player getPlayer() {
@ -25,6 +27,10 @@ public class ArenaPlayerDeathEvent extends Event
return arena;
}
public boolean wasLastPlayerStanding() {
return last;
}
public HandlerList getHandlers() {
return handlers;
}

View File

@ -239,4 +239,6 @@ public interface Arena
public boolean canSpec(Player p);
public boolean hasIsolatedChat();
public Player getLastPlayerStanding();
}