/**
   * Apply the mining fatigue game mechanic
   *
   * <p>Players who mine stone below a certain depth increase their hunger
   *
   * @param player The player to act upon
   * @param blockY The Y coordinate of the mined block
   */
  public void doMiningFatigue(int blockY) {
    Double exhaustion = 0.0;

    if (blockY < UhcMatch.DIAMOND_LAYER) {
      exhaustion = this.player.getMatch().getConfig().getMiningFatigueDiamond();
    } else if (blockY < UhcMatch.GOLD_LAYER) {
      exhaustion = this.player.getMatch().getConfig().getMiningFatigueGold();
    }

    if (exhaustion > 0) {
      if (!miningFatigueAlerted) {
        sendMessage(
            ChatColor.GOLD + "Warning: mining at this depth will soon make you very hungry!");
        miningFatigueAlerted = true;
      }
      if (miningFatigueGrace > 0) {
        if (--miningFatigueGrace == 0)
          sendMessage(
              ChatColor.GOLD + "Warning: mining any more at this depth will make you very hungry!");
      } else {
        player.getPlayer().setExhaustion((float) (player.getPlayer().getExhaustion() + exhaustion));
        player
            .getPlayer()
            .addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, 1200, 0));
      }
    }
  }
 public boolean start() {
   return (player.feed()
       && player.clearXP()
       && player.clearPotionEffects()
       && player.heal()
       && player.setGameMode(GameMode.SURVIVAL));
 }
 public UhcParticipant(UhcPlayer pl, UhcTeam team) {
   this.player = pl;
   this.team = team;
   if (pl.isOnline()) {
     this.currentHealth = pl.getPlayer().getHealth();
     this.currentArmor = ArmorPoints.fromPlayerInventory(pl.getPlayer().getInventory());
   }
 }
 public void doWorldEdgeWarning(Location borderPoint) {
   if (this.worldEdgeWarningSoundCountdown-- == 0) {
     player.getPlayer().playSound(borderPoint, Sound.NOTE_PIANO, 10, 1);
     this.worldEdgeWarningSoundCountdown = WORLD_EDGE_WARNING_SOUND_COUNTDOWN_LENGTH;
   }
   if (worldEdgeWarningActive) return;
   worldEdgeWarningActive = true;
   sendMessage("You are close to the edge of the world!");
   player
       .getPlayer()
       .addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 0));
 }
 public boolean isOutsideBorder(int border) {
   Location l = player.getLocation();
   return l.getBlockX() > border
       || l.getBlockZ() > border
       || l.getBlockX() < -border
       || l.getBlockZ() < -border;
 }
  /**
   * Apply the hard stone game mechanic
   *
   * <p>Players who mine stone below a certain depth increase their hunger
   *
   * @param blockY The Y coordinate of the mined block
   * @param tool The tool that was used to mine the block
   */
  public void doHardStone(int blockY, ItemStack tool) {

    // Calculate applicable durability penalty

    short penalty;

    if (tool.getType() == Material.GOLD_PICKAXE) {
      penalty = UhcMatch.DURABILITY_PENALTY_GOLD;
    } else if (tool.getType() == Material.WOOD_PICKAXE) {
      penalty = UhcMatch.DURABILITY_PENALTY_WOOD;
    } else if (tool.getType() == Material.STONE_PICKAXE) {
      penalty = UhcMatch.DURABILITY_PENALTY_STONE;
    } else if (tool.getType() == Material.IRON_PICKAXE) {
      penalty = UhcMatch.DURABILITY_PENALTY_IRON;
    } else if (tool.getType() == Material.DIAMOND_PICKAXE) {
      penalty = UhcMatch.DURABILITY_PENALTY_DIAMOND;
    } else return;

    // Warn the player the first time

    if (!warnedHardStone) {
      player.sendMessage(
          ChatColor.GOLD
              + "Warning! Mining smoothstone will wear out your tools more quickly than in normal Minecraft.");
      warnedHardStone = true;
    }

    // Apply durability cost

    tool.setDurability((short) (tool.getDurability() + penalty));
  }
 public String getName() {
   return player.getName();
 }
 public void updateInventory() {
   for (UhcPlayer up : TesseractUHC.getInstance().getMatch().getOnlinePlayers()) {
     if (up.isSpectator()) updateSpectatorOnInventory(up.getPlayer());
   }
 }
 public void clearWorldEdgeWarning() {
   if (!worldEdgeWarningActive) return;
   worldEdgeWarningActive = false;
   this.worldEdgeWarningSoundCountdown = 0;
   player.getPlayer().removePotionEffect(PotionEffectType.SLOW);
 }
 /** @return whether the player has healed recently */
 public boolean isRecentlyHealed() {
   return (player.getMatch().getStartingWorld().getFullTime() - lastHealTime
       < UhcMatch.PLAYER_HEAL_ALERT_TICKS);
 }
 /** Mark the player as having healed */
 public void setHealTimer() {
   lastHealTime = player.getMatch().getStartingWorld().getFullTime();
 }
 /** @return whether the player has taken damage recently */
 public boolean isRecentlyDamaged() {
   return (player.getMatch().getStartingWorld().getFullTime() - lastDamageTime
       < UhcMatch.PLAYER_DAMAGE_ALERT_TICKS);
 }
 public boolean sendMessage(String message) {
   return player.sendMessage(message);
 }
 public boolean sendToStartPoint() {
   return (player.setGameMode(GameMode.ADVENTURE)
       && teleport(getStartPoint().getLocation())
       && player.renew());
 }
 public boolean teleport(Location l, String message) {
   return player.teleport(l, message);
 }