Skip to content

Instantly share code, notes, and snippets.

@Sunstrike
Created September 30, 2012 11:54
Show Gist options
  • Select an option

  • Save Sunstrike/3806574 to your computer and use it in GitHub Desktop.

Select an option

Save Sunstrike/3806574 to your computer and use it in GitHub Desktop.
Player respawn code
@EventHandler (priority = EventPriority.HIGH)
public void onPlayerRespawn(PlayerRespawnEvent event) {
Team t = TeamManager.instance().getTeamForPlayer(event.getPlayer());
Player plr = event.getPlayer();
FileConfiguration config = plugin.getConfig();
Location spawn = null;
if (event.isBedSpawn()) {
Teams.log.info("[Bukkit-Teams] Sending player " + plr.getDisplayName() + " to their bed spawn.");
spawn = event.getPlayer().getBedSpawnLocation();
} else {
switch (t) {
case RED:
Teams.log.info("[Bukkit-Teams] Sending player " + plr.getDisplayName() + " to the RED spawn.");
double xRed = config.getDouble("spawns.red.x");
double zRed = config.getDouble("spawns.red.z");
Location tmpRed = new Location(plr.getWorld(), xRed, 0, zRed);
double yRed = plr.getWorld().getHighestBlockYAt(tmpRed);
spawn = new Location(plr.getWorld(), xRed, yRed, zRed);
break;
case BLUE:
Teams.log.info("[Bukkit-Teams] Sending player " + plr.getDisplayName() + " to the BLUE spawn.");
double xBlue = config.getDouble("spawns.blue.x");
double zBlue = config.getDouble("spawns.blue.z");
Location tmpBlue = new Location(plr.getWorld(), xBlue, 0, zBlue);
double yBlue = plr.getWorld().getHighestBlockYAt(tmpBlue);
spawn = new Location(plr.getWorld(), xBlue, yBlue, zBlue);
break;
case NONE:
break;
}
if (config.getBoolean("spawns.shared-enabled")) {
spawn = plr.getWorld().getSpawnLocation();
}
}
Teams.log.warning("[Bukkit-Teams][DBG] New spawn: " + spawn);
event.setRespawnLocation(spawn);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment