Exemplo n.º 1
0
 public void checkWinner() {
   if (doSeconds) {
     List<Gamer> aliveGamers = pm.getAliveGamers();
     if (aliveGamers.size() == 1) {
       doSeconds = false;
       final Gamer winner = aliveGamers.get(0);
       Bukkit.getPluginManager().callEvent(new PlayerWinEvent(winner));
       int reward = getPrize(1);
       if (reward > 0) winner.addBalance(reward);
       winner.getPlayer().setAllowFlight(true);
       Bukkit.getScheduler()
           .scheduleSyncRepeatingTask(
               this,
               new Runnable() {
                 public void run() {
                   Bukkit.broadcastMessage(
                       String.format(
                           translationsConfig.getBroadcastWinnerWon(), winner.getName()));
                 }
               },
               0,
               mainConfig.getWonBroadcastsDelay() * 20);
       Bukkit.getScheduler()
           .scheduleSyncDelayedTask(
               this,
               new Runnable() {
                 public void run() {
                   String kick =
                       String.format(translationsConfig.getKickMessageWon(), winner.getName());
                   shutdown(kick);
                 }
               },
               mainConfig.getGameShutdownDelay() * 20);
     } else if (aliveGamers.size() == 0) {
       doSeconds = false;
       shutdown(translationsConfig.getKickNobodyWonMessage());
     }
   }
 }
Exemplo n.º 2
0
  public void startGame() {
    currentTime = 0;
    for (Kit kit : HungergamesApi.getKitManager().getKits()) {
      final int amount = kit.getPlayerSize();
      if (amount <= 0) continue;
      metrics
          .getKitsUsed()
          .addPlotter(
              new Metrics.Plotter(kit.getName()) {

                @Override
                public int getValue() {
                  return amount;
                }
              });
    }
    ScoreboardManager.hideScore(
        "Main", DisplaySlot.SIDEBAR, translationsConfig.getScoreBoardGameStartingIn());
    ScoreboardManager.makeScore("Main", DisplaySlot.PLAYER_LIST, "", 0);
    if (mainConfig.getTimeForInvincibility() > 0) {
      ScoreboardManager.makeScore(
          "Main",
          DisplaySlot.SIDEBAR,
          translationsConfig.getScoreboardInvincibleRemaining(),
          mainConfig.getTimeForInvincibility());
    } else {
      Bukkit.getPluginManager().callEvent(new InvincibilityWearOffEvent());
    }
    Bukkit.broadcastMessage(translationsConfig.getBroadcastGameStartedMessage());
    if (mainConfig.getTimeForInvincibility() > 0)
      Bukkit.broadcastMessage(
          String.format(
              translationsConfig.getBroadcastInvincibiltyWearsOffIn(),
              returnTime(mainConfig.getTimeForInvincibility() - currentTime)));
    for (Gamer gamer : pm.getGamers()) {
      if (mainConfig.isKitSelectorEnabled())
        gamer
            .getPlayer()
            .getInventory()
            .remove(HungergamesApi.getInventoryManager().getKitSelector());
      gamer.seeInvis(false);
      gamer.setAlive(true);
      if (mainConfig.isTeleportToSpawnLocationPregame()
          && mainConfig.isPreventMovingFromSpawnUsingPotions()) {
        gamer.getPlayer().removePotionEffect(PotionEffectType.SLOW);
        gamer.getPlayer().removePotionEffect(PotionEffectType.JUMP);
      }
      pm.sendToSpawn(gamer);
    }
    world.setGameRuleValue("doDaylightCycle", "true");
    world.setTime(mainConfig.getTimeOfDay());
    world.playSound(world.getSpawnLocation(), Sound.AMBIENCE_THUNDER, 1, 0.8F);
    Bukkit.getScheduler()
        .scheduleSyncDelayedTask(
            this,
            new Runnable() {
              public void run() {
                for (Gamer gamer : pm.getAliveGamers())
                  gamer.getPlayer().getInventory().addItem(new ItemStack(Material.COMPASS));
                for (me.libraryaddict.Hungergames.Types.Kit kit :
                    HungergamesApi.getKitManager().getKits()) kit.giveKit();
                HungergamesApi.getAbilityManager().registerAbilityListeners();
                Bukkit.getPluginManager().callEvent(new GameStartEvent());
                for (Location l : entitysToSpawn.keySet())
                  l.getWorld().spawnEntity(l, entitysToSpawn.get(l));
                entitysToSpawn.clear();
              }
            });
    checkWinner();
    HungergamesApi.getInventoryManager().updateSpectatorHeads();
    ScoreboardManager.doStage();
  }
Exemplo n.º 3
0
 private void onSecond() {
   currentTime++;
   if (currentTime < 0) {
     world.setTime(0);
     ScoreboardManager.makeScore(
         "Main",
         DisplaySlot.SIDEBAR,
         translationsConfig.getScoreBoardGameStartingIn(),
         -currentTime);
     if (mainConfig.isTeleportToSpawnLocationPregame()
         && -currentTime == mainConfig.getSecondsToTeleportPlayerToSpawn()) {
       for (Gamer gamer : HungergamesApi.getPlayerManager().getGamers()) {
         HungergamesApi.getPlayerManager().sendToSpawn(gamer);
         if (mainConfig.isPreventMovingFromSpawnUsingPotions()) {
           for (Player player : Bukkit.getOnlinePlayers()) {
             player.addPotionEffect(
                 new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, 200), true);
             player.addPotionEffect(
                 new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 200), true);
           }
         }
       }
     }
     if (mainConfig.isGameStarting(currentTime))
       Bukkit.broadcastMessage(
           String.format(
               translationsConfig.getBroadcastGameStartingIn(), returnTime(currentTime)));
   } else if (currentTime == 0) {
     if (pm.getGamers().size() < mainConfig.getMinPlayersForGameStart()) {
       currentTime = -90;
       ScoreboardManager.makeScore(
           "Main",
           DisplaySlot.SIDEBAR,
           translationsConfig.getScoreBoardGameStartingIn(),
           -currentTime);
       Bukkit.broadcastMessage(translationsConfig.getBroadcastNotEnoughPlayers());
     } else {
       startGame();
       return;
     }
   } else if (mainConfig.getAmountBorderClosesInPerSecond() > 0
       && currentTime > mainConfig.getBorderStartsClosingIn()) {
     double borderSize =
         mainConfig.getBorderSize() - mainConfig.getAmountBorderClosesInPerSecond();
     if (borderSize < 0) borderSize = 0;
     mainConfig.setBorderSize(borderSize);
     ScoreboardManager.makeScore(
         "Main",
         DisplaySlot.SIDEBAR,
         translationsConfig.getScoreboardBorderSize(),
         (int) mainConfig.getBorderSize());
   }
   for (Gamer gamer : pm.getGamers()) {
     this.doBorder(gamer);
   }
   if (mainConfig.getTimeForInvincibility() > 0
       && currentTime <= mainConfig.getTimeForInvincibility()
       && currentTime >= 0) {
     ScoreboardManager.makeScore(
         "Main",
         DisplaySlot.SIDEBAR,
         translationsConfig.getScoreboardInvincibleRemaining(),
         mainConfig.getTimeForInvincibility() - currentTime);
     if (currentTime == mainConfig.getTimeForInvincibility()) {
       Bukkit.broadcastMessage(translationsConfig.getBroadcastInvincibilityWornOff());
       ScoreboardManager.hideScore(
           "Main", DisplaySlot.SIDEBAR, translationsConfig.getScoreboardInvincibleRemaining());
       Bukkit.getPluginManager().callEvent(new InvincibilityWearOffEvent());
     } else if (mainConfig.advertiseInvincibility(currentTime)) {
       Bukkit.broadcastMessage(
           String.format(
               translationsConfig.getBroadcastInvincibiltyWearsOffIn(),
               returnTime(mainConfig.getTimeForInvincibility() - currentTime)));
     }
   }
   ScoreboardManager.doStage();
 }
Exemplo n.º 4
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);
       }
     }
   }
 }
Exemplo n.º 5
0
 private void onSecond() {
   currentTime++;
   if (currentTime < 0) {
     world.setTime(0);
     ScoreboardManager.makeScore(
         "Main",
         DisplaySlot.SIDEBAR,
         translationsConfig.getScoreBoardGameStartingIn(),
         -currentTime);
     if (mainConfig.isGameStarting(currentTime))
       Bukkit.broadcastMessage(
           String.format(
               translationsConfig.getBroadcastGameStartingIn(), returnTime(currentTime)));
   } else if (currentTime == 0) {
     if (pm.getGamers().size() < mainConfig.getMinPlayersForGameStart()) {
       currentTime = -90;
       ScoreboardManager.makeScore(
           "Main",
           DisplaySlot.SIDEBAR,
           translationsConfig.getScoreBoardGameStartingIn(),
           -currentTime);
       Bukkit.broadcastMessage(translationsConfig.getBroadcastNotEnoughPlayers());
     } else {
       startGame();
       return;
     }
   } else if (mainConfig.getAmountBorderClosesInPerSecond() > 0
       && currentTime > mainConfig.getBorderStartsClosingIn()) {
     mainConfig.setBorderSize(
         mainConfig.getBorderSize() - mainConfig.getAmountBorderClosesInPerSecond());
     ScoreboardManager.makeScore(
         "Main",
         DisplaySlot.SIDEBAR,
         translationsConfig.getScoreboardBorderSize(),
         (int) mainConfig.getBorderSize());
   }
   for (Gamer gamer : pm.getGamers()) {
     this.doBorder(gamer);
   }
   if (mainConfig.getTimeForInvincibility() > 0
       && currentTime <= mainConfig.getTimeForInvincibility()
       && currentTime >= 0) {
     ScoreboardManager.makeScore(
         "Main",
         DisplaySlot.SIDEBAR,
         translationsConfig.getScoreboardInvincibleRemaining(),
         mainConfig.getTimeForInvincibility() - currentTime);
     if (currentTime == mainConfig.getTimeForInvincibility()) {
       Bukkit.broadcastMessage(translationsConfig.getBroadcastInvincibilityWornOff());
       ScoreboardManager.hideScore(
           "Main", DisplaySlot.SIDEBAR, translationsConfig.getScoreboardInvincibleRemaining());
       Bukkit.getPluginManager().callEvent(new InvincibilityWearOffEvent());
     } else if (mainConfig.advertiseInvincibility(currentTime)) {
       Bukkit.broadcastMessage(
           String.format(
               translationsConfig.getBroadcastInvincibiltyWearsOffIn(),
               returnTime(mainConfig.getTimeForInvincibility() - currentTime)));
     }
   }
   ScoreboardManager.doStage();
 }
Exemplo n.º 6
0
 private void doBorder(Gamer gamer) {
   Player p = gamer.getPlayer();
   Location loc = p.getLocation().clone();
   Location sLoc = world.getSpawnLocation().clone();
   double border = mainConfig.getBorderSize();
   if (mainConfig.isRoundedBorder()) {
     sLoc.setY(loc.getY());
     double fromBorder = loc.distance(sLoc) - border;
     if (fromBorder - 20 > 0) {
       // Warn
       p.sendMessage(translationsConfig.getMessagePlayerApproachingBorder());
       if (fromBorder > 0) {
         // Punish
         if (gamer.isAlive()) {
           // Damage and potentially kill.
           if (p.getHealth() - 2 > 0) {
             p.damage(0);
             p.setHealth(p.getHealth() - 2);
           } else {
             pm.killPlayer(
                 gamer,
                 null,
                 loc,
                 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 = loc.clone();
     int fromSpawn = loc.getBlockX() - sLoc.getBlockX();
     if (fromSpawn > border - 20) {
       tpTo.setX(((border - 2) + sLoc.getBlockX()));
     }
     if (fromSpawn < -(border - 20)) {
       tpTo.setX((-(border - 2) + sLoc.getBlockX()));
     }
     boolean hurt = Math.abs(fromSpawn) >= border;
     fromSpawn = loc.getBlockZ() - sLoc.getBlockZ();
     if (fromSpawn > (border - 20)) {
       tpTo.setZ(((border - 2) + sLoc.getBlockZ()));
     }
     if (fromSpawn < -(border - 20)) {
       tpTo.setZ((-(border - 2) + sLoc.getBlockZ()));
     }
     if (!hurt) hurt = Math.abs(fromSpawn) >= border;
     if (!loc.equals(tpTo)) p.sendMessage(translationsConfig.getMessagePlayerApproachingBorder());
     if (hurt) {
       if (gamer.isAlive()) {
         // Damage and potentially kill.
         if (p.getHealth() - 2 > 0) {
           p.damage(0);
           p.setHealth(p.getHealth() - 2);
         } else {
           pm.killPlayer(
               gamer,
               null,
               loc,
               gamer.getInventory(),
               String.format(translationsConfig.getKillMessageKilledByBorder(), gamer.getName()));
         }
       } else if (border > 10) {
         gamer.getPlayer().teleport(tpTo);
       }
     }
   }
 }