コード例 #1
0
 /**
  * Saves the player's death and resets their spawn point to the team spawn
  *
  * @param event
  */
 @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
 public void onDeath(final PlayerDeathEvent event) {
   // getLogger().info("DEBUG: death");
   Player player = event.getEntity();
   // Check if player died in-game
   if (!player.getWorld().equals(getBeaconzWorld())) {
     // getLogger().info("DEBUG: not in world");
     return;
   }
   // If in the lobby, ignore
   if (getGameMgr().isLocationInLobby(player.getLocation())) {
     // getLogger().info("DEBUG: died in lobby");
     return;
   }
   // Get game
   Game game = getGameMgr().getGame(player.getLocation());
   if (game != null) {
     Team team = game.getScorecard().getTeam(player);
     // getLogger().info("DEBUG: team is " + team.getDisplayName());
     // Store new spawn point
     Location spawnPoint = game.getScorecard().getTeamSpawnPoint(team);
     // getLogger().info("DEBUG: new spawn point is " + spawnPoint);
     if (event.getKeepInventory()) {
       // Store the inventory for this player because they will get it when they come back
       // Will also store their exp
       // getLogger().info("DEBUG: keep inventory is true");
       getBeaconzStore().storeInventory(player, game.getName(), spawnPoint);
     } else {
       // getLogger().info("DEBUG: keep inventory is false");
       // Their inventory is going to get dumped on the floor so they need to have their
       // possessions removed
       getBeaconzStore().clearItems(player, game.getName(), spawnPoint);
     }
     if (!event.getKeepLevel()) {
       // getLogger().info("DEBUG: lose level! - new exp = " + event.getNewExp());
       // If they don't get to keep their level, their exp needs updating to what they'll get in
       // this world.
       getBeaconzStore().setExp(player, game.getName(), event.getNewExp());
     } else {
       // getLogger().info("DEBUG: keep level");
     }
     // They are dead, so when they respawn they need to have full health (otherwise they will die
     // repeatedly)
     getBeaconzStore().setHealth(player, game.getName(), player.getMaxHealth());
     // They will also get full food level
     getBeaconzStore().setFood(player, game.getName(), 20);
     // Make a note of their death status
     deadPlayers.put(player.getUniqueId(), spawnPoint);
   } else {
     // getLogger().info("DEBUG: game is null");
   }
 }