@ArenaEventHandler(priority = EventPriority.HIGH) public void onPlayerRespawn(PlayerRespawnEvent event, final ArenaPlayer p) { if (Defaults.DEBUG_TRACE) MessageUtil.sendMessage(p, " -onPlayerRespawn t=" + p.getTeam()); if (isWon()) { return; } final TransitionOptions mo = tops.getOptions(MatchState.ONDEATH); if (mo == null) return; if (respawns) { final boolean randomRespawn = mo.randomRespawn(); /// Lets cancel our death respawn timer Integer timer = deathTimer.get(p.getName()); if (timer != null) { Bukkit.getScheduler().cancelTask(timer); } final Location loc; final ArenaTeam t = getTeam(p); if (mo.hasAnyOption( TransitionOption.TELEPORTLOBBY, TransitionOption.TELEPORTMAINLOBBY, TransitionOption.TELEPORTWAITROOM, TransitionOption.TELEPORTMAINWAITROOM)) { final int index = t.getIndex(); if (mo.hasOption(TransitionOption.TELEPORTLOBBY)) { loc = RoomController.getLobbySpawn(index, getParams().getType(), randomRespawn); } else if (mo.hasOption(TransitionOption.TELEPORTMAINLOBBY)) { loc = RoomController.getLobbySpawn( Defaults.MAIN_SPAWN, getParams().getType(), randomRespawn); } else if (mo.hasOption(TransitionOption.TELEPORTMAINWAITROOM)) { loc = this.getWaitRoomSpawn(Defaults.MAIN_SPAWN, randomRespawn); } else { loc = this.getWaitRoomSpawn(index, randomRespawn); } /// Should we respawn the player to the team spawn after a certain amount of time if (mo.hasOption(TransitionOption.RESPAWNTIME)) { int id = Bukkit.getScheduler() .scheduleSyncDelayedTask( BattleArena.getSelf(), new Runnable() { @Override public void run() { Integer id = respawnTimer.remove(p.getName()); Bukkit.getScheduler().cancelTask(id); Location loc = getTeamSpawn( index, tops.hasOptionAt( MatchState.ONSPAWN, TransitionOption.RANDOMRESPAWN)); TeleportController.teleport(p.getPlayer(), loc); } }, mo.getRespawnTime() * 20); respawnTimer.put(p.getName(), id); } } else { loc = getTeamSpawn(getTeam(p), randomRespawn); } event.setRespawnLocation(loc); /// For some reason, the player from onPlayerRespawn Event isnt the one in the main thread, so // we need to /// resync before doing any effects final Match am = this; Bukkit.getScheduler() .scheduleSyncDelayedTask( BattleArena.getSelf(), new Runnable() { public void run() { ArenaTeam t = getTeam(p); PerformTransition.transition(am, MatchState.ONDEATH, p, t, false); PerformTransition.transition(am, MatchState.ONSPAWN, p, t, false); if (respawnsWithClass) { ArenaClass ac = null; if (p.getPreferredClass() != null) { ac = p.getPreferredClass(); } else if (p.getCurrentClass() != null) { ac = p.getCurrentClass(); } if (ac != null) { ArenaClassController.giveClass(p, ac); } } if (keepsInventory) { psc.restoreMatchItems(p); } if (woolTeams) { TeamUtil.setTeamHead(t.getIndex(), p); } } }); } else { /// This player is now out of the system now that we have given the ondeath effects Location l = tops.hasOptionAt(MatchState.ONLEAVE, TransitionOption.TELEPORTTO) ? tops.getOptions(MatchState.ONLEAVE).getTeleportToLoc() : oldlocs.get(p.getName()); if (l != null) event.setRespawnLocation(l); } }