Permalink
Browse files

Upon death return to creative mode, if you were there in the first

place.
  • Loading branch information...
1 parent 5871a24 commit 3ae0b70667e210b2db9fa4aa4cdbf54425577e05 @mkalus committed May 1, 2012
@@ -81,6 +81,7 @@
private class LocationTime {
public Location location;
public long time;
+ public boolean creative;
}
/**
@@ -561,8 +562,10 @@ public void onPlayerRespawn(PlayerRespawnEvent event) {
// 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
+ if (locationTime.time + 60000 > System.currentTimeMillis()) { // only teleport back if within one minute
event.setRespawnLocation(locationTime.location);
+ if (locationTime.creative) player.setGameMode(GameMode.CREATIVE);
+ }
}
}
@@ -735,13 +738,15 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) {
* Add a player respawn location
* @param player
* @param location
+ * @param creative - return to creative mode?
*/
- public void addPlayerRespawnLocation(Player player, Location location) {
+ public void addPlayerRespawnLocation(Player player, Location location, boolean creative) {
if (respawnLocations == null) respawnLocations = new HashMap<Player, LocationTime>();
// create new location time
LocationTime locationTime = new LocationTime();
locationTime.location = location;
locationTime.time = System.currentTimeMillis();
+ locationTime.creative = creative;
// add it
respawnLocations.put(player, locationTime);
@@ -940,12 +940,13 @@ public boolean onPlayerDeath(Player player) {
if (hasPlayer(player)) {
// delete original position, because player spawns somewhere else anyhow
+ boolean creativeMode = SimpleSpleef.getOriginalPositionKeeper().wasInCreativeBefore(player);
SimpleSpleef.getOriginalPositionKeeper().deleteOriginalPosition(player);
// add respawn location, if set
Location teleportTo = LocationHelper.configToExactLocation(configuration.getConfigurationSection("loseSpawn"));
if (teleportTo != null) {
- SimpleSpleef.getGameHandler().addPlayerRespawnLocation(player, teleportTo);
+ SimpleSpleef.getGameHandler().addPlayerRespawnLocation(player, teleportTo, creativeMode);
}
if (configuration.getBoolean("loseOnDeath", true)) {

0 comments on commit 3ae0b70

Please sign in to comment.