Permalink
Browse files

Implemented respawn on lose spawn when being killed in the arena.

  • Loading branch information...
mkalus committed Apr 22, 2012
1 parent 2da3c0a commit 3c8a0225d0339d30b8e9e98638737508959e87dd
@@ -51,6 +51,7 @@
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
+import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import com.sk89q.worldguard.protection.managers.RegionManager;
@@ -71,6 +72,16 @@
* games array
*/
private List<Game> games;
+
+ /**
+ * keeps respawn locations for players that dies during game
+ */
+ private HashMap<Player, LocationTime> respawnLocations;
+
+ private class LocationTime {
+ public Location location;
+ public long time;
+ }
/**
* Initialize game handler - mainly read arena cubes and update game data
@@ -88,6 +99,9 @@ public void updateGameHandlerData() {
// add game to list
games.add(game);
}
+
+ // initialize respawn locations
+ respawnLocations = new HashMap<Player, LocationTime>();
}
/**
@@ -537,7 +551,21 @@ public void onEntityDeath(EntityDeathEvent event) {
if (game.onPlayerDeath((Player) event.getEntity())) return;
}
}
-
+
+ /**
+ * @param event
+ */
+ @EventHandler
+ public void onPlayerRespawn(PlayerRespawnEvent event) {
+ Player player = event.getPlayer();
+ // pass event to games
+ if (respawnLocations != null && respawnLocations.containsKey(player)) {
+ LocationTime locationTime = respawnLocations.remove(player);
+ if (locationTime.time + 60000 > System.currentTimeMillis()) // only teleport back if within one minute
+ event.setRespawnLocation(locationTime.location);
+ }
+ }
+
/**
* @param event
*/
@@ -676,7 +704,7 @@ public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
if (game.onPlayerGameModeChange(event)) return;
}
}
-
+
/**
* @param event
*/
@@ -689,7 +717,7 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
if (game.onCreatureSpawn(event)) return;
}
}
-
+
/**
* @param event
*/
@@ -703,6 +731,22 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) {
}
}
+ /**
+ * Add a player respawn location
+ * @param player
+ * @param location
+ */
+ public void addPlayerRespawnLocation(Player player, Location location) {
+ if (respawnLocations == null) respawnLocations = new HashMap<Player, LocationTime>();
+ // create new location time
+ LocationTime locationTime = new LocationTime();
+ locationTime.location = location;
+ locationTime.time = System.currentTimeMillis();
+
+ // add it
+ respawnLocations.put(player, locationTime);
+ }
+
/**
* get player's statistics and sends them to sender
* @param sender
@@ -941,6 +941,12 @@ public boolean onPlayerDeath(Player player) {
if (hasPlayer(player)) {
// delete original position, because player spawns somewhere else anyhow
SimpleSpleef.getOriginalPositionKeeper().deleteOriginalPosition(player);
+
+ // add respawn location, if set
+ Location teleportTo = LocationHelper.configToExactLocation(configuration.getConfigurationSection("loseSpawn"));
+ if (teleportTo != null) {
+ SimpleSpleef.getGameHandler().addPlayerRespawnLocation(player, teleportTo);
+ }
if (configuration.getBoolean("loseOnDeath", true)) {
// broadcast message of somebody loosing
@@ -958,7 +964,7 @@ public boolean onPlayerDeath(Player player) {
changeGameModeToCreative(player);
// player loses, if set to true
- playerLoses(player, false); // do not teleport dead players... TODO
+ playerLoses(player, false); // do not teleport dead players...
} // else - do nothing...
return true;
}
@@ -1,6 +1,6 @@
name: SimpleSpleef
main: de.beimax.simplespleef.SimpleSpleef
-version: 3.0.13
+version: 3.0.14
dev-url: http://dev.bukkit.org/server-mods/simple-spleef/
author: maxkalus
description: >

0 comments on commit 3c8a022

Please sign in to comment.