public void shutdown(String messageToKickWith) {
   System.out.print(HungergamesApi.getConfigManager().getLoggerConfig().getShuttingDown());
   ServerShutdownEvent event = new ServerShutdownEvent();
   Bukkit.getServer().getPluginManager().callEvent(event);
   if (!event.isCancelled()) {
     for (String command : mainConfig.getCommandsToRunBeforeShutdown())
       Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
     for (Player player : Bukkit.getOnlinePlayers()) {
       player.kickPlayer(messageToKickWith);
     }
     Bukkit.dispatchCommand(Bukkit.getConsoleSender(), mainConfig.getCommandToStopTheServerWith());
   } else
     System.out.print(HungergamesApi.getConfigManager().getLoggerConfig().getShutdownCancelled());
 }
 public void sendToSpawn(Gamer gamer) {
   final Player p = gamer.getPlayer();
   Location originalSpawn = p.getWorld().getSpawnLocation();
   MainConfig main = HungergamesApi.getConfigManager().getMainConfig();
   int spawnRadius = main.getSpawnRadius();
   int spawnHeight = main.getSpawnHeight();
   if (spawns.size() > 0) {
     if (spawnItel == null || !spawnItel.hasNext()) spawnItel = spawns.keySet().iterator();
     originalSpawn = spawnItel.next();
     spawnRadius = Math.max(1, spawns.get(originalSpawn)[0]);
     spawnHeight = Math.max(1, spawns.get(originalSpawn)[1]);
   }
   Location spawn = originalSpawn.clone();
   int chances = 0;
   if (p.isInsideVehicle()) p.leaveVehicle();
   p.eject();
   while (chances < main.getTimesToCheckForValidSpawnPerPlayer()) {
     chances++;
     Location newLoc =
         new Location(
             p.getWorld(),
             spawn.getX() + returnChance(-spawnRadius, spawnRadius),
             spawn.getY() + new Random().nextInt(spawnHeight),
             spawn.getZ() + returnChance(-spawnRadius, spawnRadius));
     if (nonSolid.contains(newLoc.getBlock().getTypeId())
         && nonSolid.contains(newLoc.getBlock().getRelative(BlockFace.UP).getTypeId())) {
       while (newLoc.getBlockY() >= 1
           && nonSolid.contains(newLoc.getBlock().getRelative(BlockFace.DOWN).getTypeId())) {
         newLoc = newLoc.add(0, -1, 0);
       }
       if (newLoc.getBlockY() <= 1) continue;
       spawn = newLoc;
       break;
     }
   }
   if (spawn.equals(originalSpawn)) {
     spawn =
         new Location(
             p.getWorld(),
             spawn.getX() + returnChance(-spawnRadius, spawnRadius),
             0,
             spawn.getZ() + returnChance(-spawnRadius, spawnRadius));
     spawn.setY(spawn.getWorld().getHighestBlockYAt(spawn));
     if (gamer.isAlive() && spawn.getY() <= 1) {
       spawn.getBlock().setType(Material.GLASS);
       spawn.setY(spawn.getY() + 1);
     }
   }
   final Location destination = spawn.add(0.5, 0.1, 0.5);
   p.teleport(destination);
   Bukkit.getScheduler()
       .scheduleSyncDelayedTask(
           hg,
           new Runnable() {
             public void run() {
               p.teleport(destination);
             }
           });
 }
public class SpawnCommand implements CommandExecutor {
  public String[] aliases = new String[] {"hgspawn"};
  private TranslationConfig cm = HungergamesApi.getConfigManager().getTranslationsConfig();
  public String description = "If spectating you can teleport back to spawn";
  private PlayerManager pm = HungergamesApi.getPlayerManager();

  public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    Gamer gamer = pm.getGamer(sender.getName());
    if (!gamer.isAlive()) {
      pm.sendToSpawn(gamer);
      return true;
    } else {
      ((Player) sender).setCompassTarget(HungergamesApi.getHungergames().world.getSpawnLocation());
      gamer.getPlayer().sendMessage(cm.getCommandSpawnPointingToSpawn());
    }
    return true;
  }
}
public class MessageCommand implements CommandExecutor {

  public String[] aliases =
      new String[] {"msg", "mail", "tell", "pm", "whisper", "w", "privatemessage"};
  private transient ChatManager chat = HungergamesApi.getChatManager();
  public String description = "Message a player your secret plans";
  private transient TranslationConfig tm =
      HungergamesApi.getConfigManager().getTranslationsConfig();

  public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (args.length == 0) sender.sendMessage(tm.getCommandMessageNoArgs());
    else if (args.length > 1) {
      Player player = Bukkit.getPlayer(args[0]);
      if (player == null) {
        sender.sendMessage(tm.getCommandMessageNoReceiver());
        return true;
      }
      chat.sendMessage(sender, player, StringUtils.join(args, " ").substring(args[0].length() + 1));
    } else sender.sendMessage(tm.getCommandMessagePlayerNoArgs());
    return true;
  }
}
public class GoTo implements CommandExecutor {
  public String[] aliases = new String[] {"watch"};
  private TranslationConfig cm = HungergamesApi.getConfigManager().getTranslationsConfig();
  public String description = "A command for spectators to teleport to people";
  private PlayerManager pm = HungergamesApi.getPlayerManager();

  public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    Gamer gamer = pm.getGamer(sender.getName());
    if (!gamer.isAlive()) {
      if (args.length > 0) {
        if (Bukkit.getPlayer(args[0]) != null) {
          gamer.getPlayer().eject();
          gamer
              .getPlayer()
              .teleport(sender.getServer().getPlayer(args[0]).getLocation().add(0, 0.1, 0));
          return true;
        } else if (args[0].equalsIgnoreCase(cm.getCommandGotoNameOfFeast())) {
          Location feastLoc = LibsFeastManager.getFeastManager().getFeastLocation();
          if (feastLoc.getBlockY() > 0) {
            gamer.getPlayer().eject();
            gamer
                .getPlayer()
                .teleport(
                    feastLoc
                        .getWorld()
                        .getHighestBlockAt(feastLoc)
                        .getLocation()
                        .clone()
                        .add(0.5, 1, 0.5));
          } else sender.sendMessage(cm.getCommandGotoFeastFailed());
          return true;
        } else sender.sendMessage(cm.getCommandGotoPlayerDoesntExist());
      } else sender.sendMessage(cm.getCommandGotoNotEnoughArgs());
    } else sender.sendMessage(cm.getCommandGotoNotSpectator());
    return true;
  }
}
public class PlayerManager {

  public static int returnChance(int start, int end) {
    return start + (int) (Math.random() * ((end - start) + 1));
  }

  private TranslationConfig cm = HungergamesApi.getConfigManager().getTranslationsConfig();
  private ConcurrentLinkedQueue<Gamer> gamers = new ConcurrentLinkedQueue<Gamer>();
  private Hungergames hg = HungergamesApi.getHungergames();
  private KitManager kits = HungergamesApi.getKitManager();
  public HashMap<Gamer, Damage> lastDamager = new HashMap<Gamer, Damage>();
  public ConcurrentLinkedQueue<Gamer> loadGamer = new ConcurrentLinkedQueue<Gamer>();
  private ArrayList<Integer> nonSolid = new ArrayList<Integer>();
  private Iterator<Location> spawnItel;
  private HashMap<Location, Integer[]> spawns = new HashMap<Location, Integer[]>();

  public PlayerManager() {
    nonSolid.add(0);
    for (int b = 8; b < 12; b++) nonSolid.add(b);
    nonSolid.add(Material.SNOW.getId());
    nonSolid.add(Material.LONG_GRASS.getId());
    nonSolid.add(Material.RED_MUSHROOM.getId());
    nonSolid.add(Material.RED_ROSE.getId());
    nonSolid.add(Material.YELLOW_FLOWER.getId());
    nonSolid.add(Material.BROWN_MUSHROOM.getId());
    nonSolid.add(Material.SIGN_POST.getId());
    nonSolid.add(Material.WALL_SIGN.getId());
    nonSolid.add(Material.FIRE.getId());
    nonSolid.add(Material.TORCH.getId());
    nonSolid.add(Material.REDSTONE_WIRE.getId());
    nonSolid.add(Material.REDSTONE_TORCH_OFF.getId());
    nonSolid.add(Material.REDSTONE_TORCH_ON.getId());
    nonSolid.add(Material.VINE.getId());
  }

  public void addSpawnPoint(Location loc, int radius, int height) {
    spawns.put(loc, new Integer[] {radius, height});
  }

  private String formatDeathMessage(String deathMessage, Player p) {
    String playerKit = cm.getKillMessageNoKit();
    if (kits.getKitByPlayer(p) != null) playerKit = kits.getKitByPlayer(p).getName();
    String killMessage = cm.getKillMessageFormatPlayerKit();
    if (killMessage.contains("%Player%") || killMessage.contains("%Kit%")) {
      playerKit = killMessage.replace("%Player%", p.getName()).replace("%Kit%", playerKit);
    } else {
      playerKit = String.format(killMessage, p.getName(), playerKit);
    }
    return deathMessage.replace(p.getName(), playerKit);
  }

  public List<Gamer> getAliveGamers() {
    List<Gamer> aliveGamers = new ArrayList<Gamer>();
    for (Gamer gamer : gamers) if (gamer.isAlive()) aliveGamers.add(gamer);
    return aliveGamers;
  }

  public synchronized Gamer getGamer(Entity entity) {
    for (Gamer g : gamers) if (g.getPlayer() == entity) return g;
    return null;
  }

  public synchronized Gamer getGamer(String name) {
    for (Gamer g : gamers) if (g.getName().equals(name)) return g;
    return null;
  }

  public List<Gamer> getGamers() {
    List<Gamer> game = new ArrayList<Gamer>();
    for (Gamer g : gamers) game.add(g);
    return game;
  }

  public Gamer getKiller(Gamer victim) {
    Damage dmg = lastDamager.get(victim);
    Gamer backup = null;
    if (dmg != null) if (dmg.getTime() >= System.currentTimeMillis()) backup = dmg.getDamager();
    return backup;
  }

  public void killPlayer(
      Gamer gamer, Entity killer, Location dropLoc, List<ItemStack> drops, String deathMsg) {
    if (!hg.doSeconds || hg.currentTime < 0) return;
    PlayerKilledEvent event =
        new PlayerKilledEvent(gamer, killer, getKiller(gamer), deathMsg, dropLoc, drops);
    Bukkit.getPluginManager().callEvent(event);
    manageDeath(event);
  }

  public void manageDeath(PlayerKilledEvent event) {
    Gamer killed = event.getKilled();
    final Player p = killed.getPlayer();
    p.setHealth(20);
    if (event.isCancelled()) return;
    for (HumanEntity human : p.getInventory().getViewers()) human.closeInventory();
    p.leaveVehicle();
    p.eject();
    p.setLevel(0);
    p.setExp(0F);
    if (event.getDeathMessage().equals(ChatColor.stripColor(event.getDeathMessage())))
      event.setDeathMessage(ChatColor.DARK_RED + event.getDeathMessage());
    event.setDeathMessage(
        this.formatDeathMessage(
            event.getDeathMessage().replace("%Remaining%", "" + (getAliveGamers().size() - 1)), p));
    if (event.getKillerPlayer() != null) {
      event.getKillerPlayer().addKill();
      event.setDeathMessage(
          this.formatDeathMessage(event.getDeathMessage(), event.getKillerPlayer().getPlayer()));
    }
    Bukkit.broadcastMessage(event.getDeathMessage());
    int reward = hg.getPrize(getAliveGamers().size());
    if (reward > 0) killed.addBalance(reward);
    hg.cannon();
    killed.clearInventory();
    World world = p.getWorld();
    for (ItemStack item : event.getDrops()) {
      if (item == null
          || item.getType() == Material.AIR
          || item.containsEnchantment(EnchantmentManager.UNLOOTABLE)) continue;
      else if (item.hasItemMeta())
        world
            .dropItemNaturally(event.getDropsLocation(), item.clone())
            .getItemStack()
            .setItemMeta(item.getItemMeta());
      else world.dropItemNaturally(event.getDropsLocation(), item);
    }
    setSpectator(killed);
    ScoreboardManager.makeScore(
        "Main", DisplaySlot.SIDEBAR, cm.getScoreboardPlayersLength(), getAliveGamers().size());
    hg.checkWinner();
    p.setVelocity(new Vector());
    for (PotionEffect effect : p.getActivePotionEffects()) p.removePotionEffect(effect.getType());
    p.teleport(p.getWorld().getHighestBlockAt(p.getLocation()).getLocation().clone().add(0, 10, 0));
    p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 40, 9), true);
    p.sendBlockChange(p.getLocation(), Material.PORTAL.getId(), (byte) 0);
    p.sendBlockChange(p.getLocation(), Material.AIR.getId(), (byte) 0);
    for (Entity entity : p.getWorld().getEntities()) {
      if (entity instanceof Tameable
          && ((Tameable) entity).isTamed()
          && ((Tameable) entity).getOwner().getName().equals(p.getName())) {
        if (entity instanceof Wolf) ((Wolf) entity).setSitting(true);
        else if (entity instanceof Ocelot) ((Ocelot) entity).setSitting(true);
        else entity.remove();
      }
      if (entity instanceof Creature && ((Creature) entity).getTarget() == p)
        ((Creature) entity).setTarget(null);
    }
    if (HungergamesApi.getConfigManager().getMainConfig().isKickOnDeath()
        && !p.hasPermission("hungergames.spectate"))
      p.kickPlayer(String.format(cm.getKickDeathMessage(), event.getDeathMessage()));
    HungergamesApi.getAbilityManager().unregisterPlayer(p);
    HungergamesApi.getInventoryManager().updateSpectatorHeads();
  }

  public Gamer registerGamer(Player p) {
    Gamer gamer = new Gamer(p);
    gamers.add(gamer);
    return gamer;
  }

  public void removeKilled(Gamer gamer) {
    lastDamager.remove(gamer);
    Iterator<Gamer> itel = lastDamager.keySet().iterator();
    while (itel.hasNext()) {
      Gamer g = itel.next();
      if (lastDamager.get(g).getDamager() == gamer) itel.remove();
    }
  }

  public void sendToSpawn(Gamer gamer) {
    final Player p = gamer.getPlayer();
    Location originalSpawn = p.getWorld().getSpawnLocation();
    MainConfig main = HungergamesApi.getConfigManager().getMainConfig();
    int spawnRadius = main.getSpawnRadius();
    int spawnHeight = main.getSpawnHeight();
    if (spawns.size() > 0) {
      if (spawnItel == null || !spawnItel.hasNext()) spawnItel = spawns.keySet().iterator();
      originalSpawn = spawnItel.next();
      spawnRadius = Math.max(1, spawns.get(originalSpawn)[0]);
      spawnHeight = Math.max(1, spawns.get(originalSpawn)[1]);
    }
    Location spawn = originalSpawn.clone();
    int chances = 0;
    if (p.isInsideVehicle()) p.leaveVehicle();
    p.eject();
    while (chances < main.getTimesToCheckForValidSpawnPerPlayer()) {
      chances++;
      Location newLoc =
          new Location(
              p.getWorld(),
              spawn.getX() + returnChance(-spawnRadius, spawnRadius),
              spawn.getY() + new Random().nextInt(spawnHeight),
              spawn.getZ() + returnChance(-spawnRadius, spawnRadius));
      if (nonSolid.contains(newLoc.getBlock().getTypeId())
          && nonSolid.contains(newLoc.getBlock().getRelative(BlockFace.UP).getTypeId())) {
        while (newLoc.getBlockY() >= 1
            && nonSolid.contains(newLoc.getBlock().getRelative(BlockFace.DOWN).getTypeId())) {
          newLoc = newLoc.add(0, -1, 0);
        }
        if (newLoc.getBlockY() <= 1) continue;
        spawn = newLoc;
        break;
      }
    }
    if (spawn.equals(originalSpawn)) {
      spawn =
          new Location(
              p.getWorld(),
              spawn.getX() + returnChance(-spawnRadius, spawnRadius),
              0,
              spawn.getZ() + returnChance(-spawnRadius, spawnRadius));
      spawn.setY(spawn.getWorld().getHighestBlockYAt(spawn));
      if (gamer.isAlive() && spawn.getY() <= 1) {
        spawn.getBlock().setType(Material.GLASS);
        spawn.setY(spawn.getY() + 1);
      }
    }
    final Location destination = spawn.add(0.5, 0.1, 0.5);
    p.teleport(destination);
    Bukkit.getScheduler()
        .scheduleSyncDelayedTask(
            hg,
            new Runnable() {
              public void run() {
                p.teleport(destination);
              }
            });
  }

  public void setSpectator(final Gamer gamer) {
    gamer.setAlive(false);
    gamer.getPlayer().getInventory().remove(HungergamesApi.getInventoryManager().getKitSelector());
    Bukkit.getScheduler()
        .scheduleSyncDelayedTask(
            hg,
            new Runnable() {
              public void run() {
                ItemStack compass = new ItemStack(Material.COMPASS);
                compass.addEnchantment(EnchantmentManager.UNDROPPABLE, 1);
                EnchantmentManager.updateEnchants(compass);
                if (!gamer.getPlayer().getInventory().contains(compass))
                  gamer.getPlayer().getInventory().addItem(compass);
              }
            });
  }

  public Gamer unregisterGamer(Entity entity) {
    Iterator<Gamer> itel = gamers.iterator();
    while (itel.hasNext()) {
      Gamer g = itel.next();
      if (g.getPlayer() == entity) {
        itel.remove();
        return g;
      }
    }
    return null;
  }

  public void unregisterGamer(Gamer gamer) {
    gamers.remove(gamer);
  }
}
 public void manageDeath(PlayerKilledEvent event) {
   Gamer killed = event.getKilled();
   final Player p = killed.getPlayer();
   p.setHealth(20);
   if (event.isCancelled()) return;
   for (HumanEntity human : p.getInventory().getViewers()) human.closeInventory();
   p.leaveVehicle();
   p.eject();
   p.setLevel(0);
   p.setExp(0F);
   if (event.getDeathMessage().equals(ChatColor.stripColor(event.getDeathMessage())))
     event.setDeathMessage(ChatColor.DARK_RED + event.getDeathMessage());
   event.setDeathMessage(
       this.formatDeathMessage(
           event.getDeathMessage().replace("%Remaining%", "" + (getAliveGamers().size() - 1)), p));
   if (event.getKillerPlayer() != null) {
     event.getKillerPlayer().addKill();
     event.setDeathMessage(
         this.formatDeathMessage(event.getDeathMessage(), event.getKillerPlayer().getPlayer()));
   }
   Bukkit.broadcastMessage(event.getDeathMessage());
   int reward = hg.getPrize(getAliveGamers().size());
   if (reward > 0) killed.addBalance(reward);
   hg.cannon();
   killed.clearInventory();
   World world = p.getWorld();
   for (ItemStack item : event.getDrops()) {
     if (item == null
         || item.getType() == Material.AIR
         || item.containsEnchantment(EnchantmentManager.UNLOOTABLE)) continue;
     else if (item.hasItemMeta())
       world
           .dropItemNaturally(event.getDropsLocation(), item.clone())
           .getItemStack()
           .setItemMeta(item.getItemMeta());
     else world.dropItemNaturally(event.getDropsLocation(), item);
   }
   setSpectator(killed);
   ScoreboardManager.makeScore(
       "Main", DisplaySlot.SIDEBAR, cm.getScoreboardPlayersLength(), getAliveGamers().size());
   hg.checkWinner();
   p.setVelocity(new Vector());
   for (PotionEffect effect : p.getActivePotionEffects()) p.removePotionEffect(effect.getType());
   p.teleport(p.getWorld().getHighestBlockAt(p.getLocation()).getLocation().clone().add(0, 10, 0));
   p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 40, 9), true);
   p.sendBlockChange(p.getLocation(), Material.PORTAL.getId(), (byte) 0);
   p.sendBlockChange(p.getLocation(), Material.AIR.getId(), (byte) 0);
   for (Entity entity : p.getWorld().getEntities()) {
     if (entity instanceof Tameable
         && ((Tameable) entity).isTamed()
         && ((Tameable) entity).getOwner().getName().equals(p.getName())) {
       if (entity instanceof Wolf) ((Wolf) entity).setSitting(true);
       else if (entity instanceof Ocelot) ((Ocelot) entity).setSitting(true);
       else entity.remove();
     }
     if (entity instanceof Creature && ((Creature) entity).getTarget() == p)
       ((Creature) entity).setTarget(null);
   }
   if (HungergamesApi.getConfigManager().getMainConfig().isKickOnDeath()
       && !p.hasPermission("hungergames.spectate"))
     p.kickPlayer(String.format(cm.getKickDeathMessage(), event.getDeathMessage()));
   HungergamesApi.getAbilityManager().unregisterPlayer(p);
   HungergamesApi.getInventoryManager().updateSpectatorHeads();
 }
  @Override
  public void onEnable() {
    HungergamesApi.init(this);
    ConfigManager config = HungergamesApi.getConfigManager();
    config.loadConfigs();
    HungergamesApi.getChestManager().setRandomItems(config.getFeastConfig().getRandomItems());
    translationsConfig = config.getTranslationsConfig();
    mainConfig = config.getMainConfig();
    pm = HungergamesApi.getPlayerManager();
    MySqlManager mysql = HungergamesApi.getMySqlManager();
    mysql.startJoinThread();
    MapLoader.loadMap();
    try {
      metrics = new Metrics(this);
      if (metrics.isOptOut()) System.out.print(config.getLoggerConfig().getMetricsMessage());
      metrics.start();
    } catch (Exception e) {
      e.printStackTrace();
    }
    Bukkit.getScheduler()
        .scheduleSyncDelayedTask(
            this,
            new Runnable() {
              public void run() {
                ScoreboardManager.setDisplayName(
                    "Main", DisplaySlot.SIDEBAR, translationsConfig.getScoreboardStagePreGame());
                world = Bukkit.getWorlds().get(0);
                world.setGameRuleValue("doDaylightCycle", "false");
                world.setTime(6000);
                if (mainConfig.isForcedCords())
                  world.setSpawnLocation(
                      mainConfig.getForceSpawnX(),
                      world.getHighestBlockYAt(
                          mainConfig.getForceSpawnX(), mainConfig.getForceSpawnZ()),
                      mainConfig.getForceSpawnZ());
                Location spawn = world.getSpawnLocation();
                for (int x = -5; x <= 5; x++)
                  for (int z = -5; z <= 5; z++)
                    spawn.clone().add(x * 16, 0, z * 16).getChunk().load();
                File mapConfig = new File(getDataFolder() + "/map.yml");
                YamlConfiguration mapConfiguration = YamlConfiguration.loadConfiguration(mapConfig);
                HungergamesApi.getGenerationManager().generateChunks();
                if (mapConfiguration.getBoolean("GenerateSpawnPlatform")) {
                  ItemStack spawnGround = mapConfiguration.getItemStack("SpawnPlatformBlock");
                  GenerationManager gen = HungergamesApi.getGenerationManager();
                  int platformHeight =
                      gen.getSpawnHeight(
                          world.getSpawnLocation(), mapConfiguration.getInt("SpawnPlatformSize"));
                  gen.generatePlatform(
                      world.getSpawnLocation(),
                      platformHeight,
                      mapConfiguration.getInt("SpawnPlatformSize"),
                      100,
                      spawnGround.getTypeId(),
                      spawnGround.getDurability());
                  world.getSpawnLocation().setY(platformHeight + 2);
                }
                world.setDifficulty(Difficulty.HARD);
                if (world.hasStorm()) world.setStorm(false);
                world.setWeatherDuration(999999999);
                ScoreboardManager.setDisplayName(
                    "Main", DisplaySlot.SIDEBAR, translationsConfig.getScoreboardStagePreGame());
              }
            });
    Bukkit.getServer()
        .getScheduler()
        .scheduleSyncRepeatingTask(
            this,
            new Runnable() {
              private long time = 0;

              public void run() {
                if (System.currentTimeMillis() >= time && doSeconds) {
                  time = System.currentTimeMillis() + 1000;
                  onSecond();
                  Bukkit.getPluginManager().callEvent(new TimeSecondEvent());
                }
              }
            },
            2L,
            1L);
    HungergamesApi.getCommandManager();
    playerListener = new PlayerListener();
    Bukkit.getPluginManager().registerEvents(playerListener, this);
    Bukkit.getPluginManager().registerEvents(new GeneralListener(), this);
    HungergamesApi.getAbilityManager();
    HungergamesApi.getInventoryManager().updateSpectatorHeads();
    if (Bukkit.getPluginManager().getPermission("ThisIsUsedForMessaging") == null) {
      Permission perm = new Permission("ThisIsUsedForMessaging", PermissionDefault.TRUE);
      perm.setDescription("Used for messages in LibsHungergames");
      Bukkit.getPluginManager().addPermission(perm);
    }
  }
 public int getPrize(int pos) {
   if (HungergamesApi.getConfigManager().getWinnersConfig().getPrizesForPlacing().containsKey(pos))
     return HungergamesApi.getConfigManager().getWinnersConfig().getPrizesForPlacing().get(pos);
   return 0;
 }
 private void doBorder(Gamer gamer) {
   Player p = gamer.getPlayer();
   Location pLoc = p.getLocation().clone();
   Location sLoc = world.getSpawnLocation().clone();
   double border = mainConfig.getBorderSize();
   if (mainConfig.isRoundedBorder()) {
     sLoc.setY(pLoc.getY());
     double fromSpawn = pLoc.distance(sLoc);
     if (fromSpawn >= border - 20) {
       // Warn
       p.sendMessage(translationsConfig.getMessagePlayerApproachingBorder());
       if (fromSpawn >= border) {
         // Punish
         if (gamer.isAlive()) {
           // Damage and potentially kill.
           double dmg = HungergamesApi.getConfigManager().getMainConfig().getDamageBorderDeals();
           if (p.getHealth() - dmg > 0) {
             p.damage(0);
             p.setHealth(p.getHealth() - dmg);
           } else {
             pm.killPlayer(
                 gamer,
                 null,
                 pLoc,
                 gamer.getInventory(),
                 String.format(
                     translationsConfig.getKillMessageKilledByBorder(), gamer.getName()));
           }
         } else if (border > 10) {
           // Hmm. Preferably I tp them back inside.
           // May as well just tp to spawn. No harm done.
           pm.sendToSpawn(gamer);
         }
       }
     }
   } else {
     Location tpTo = pLoc.clone();
     int xDist = pLoc.getBlockX() - sLoc.getBlockX();
     if (Math.abs(xDist) > border - 20) {
       if (xDist > 0) {
         tpTo.setX(border - 2 + sLoc.getBlockX());
       } else {
         tpTo.setX(border + 2 + sLoc.getBlockX());
       }
     }
     int zDist = pLoc.getBlockZ() - sLoc.getBlockZ();
     if (Math.abs(zDist) > border - 20) {
       if (zDist > 0) {
         tpTo.setZ(border - 2 + sLoc.getBlockZ());
       } else {
         tpTo.setZ(border + 2 + sLoc.getBlockZ());
       }
     }
     if (!pLoc.equals(tpTo)) p.sendMessage(translationsConfig.getMessagePlayerApproachingBorder());
     if (tpTo.getBlockX() != pLoc.getBlockX() || tpTo.getBlockZ() != pLoc.getBlockZ()) {
       if (gamer.isAlive()) {
         // Damage and potentially kill.
         double dmg = HungergamesApi.getConfigManager().getMainConfig().getDamageBorderDeals();
         if (p.getHealth() - dmg > 0) {
           p.damage(0);
           p.setHealth(p.getHealth() - dmg);
         } else {
           pm.killPlayer(
               gamer,
               null,
               pLoc,
               gamer.getInventory(),
               String.format(translationsConfig.getKillMessageKilledByBorder(), gamer.getName()));
         }
       } else if (border > 10) {
         gamer.getPlayer().teleport(tpTo);
       }
     }
   }
 }