public String returnTime(Integer i) {
   i = Math.abs(i);
   int remainder = i % 3600, minutes = remainder / 60, seconds = remainder % 60;
   if (seconds == 0 && minutes == 0) return translationsConfig.getTimeFormatNoTime();
   if (minutes == 0) {
     if (seconds == 1) return String.format(translationsConfig.getTimeFormatSecond(), seconds);
     return String.format(translationsConfig.getTimeFormatSeconds(), seconds);
   }
   if (seconds == 0) {
     if (minutes == 1) return String.format(translationsConfig.getTimeFormatMinute(), minutes);
     return String.format(translationsConfig.getTimeFormatMinutes(), minutes);
   }
   if (seconds == 1) {
     if (minutes == 1)
       return String.format(translationsConfig.getTimeFormatSecondAndMinute(), minutes, seconds);
     return String.format(translationsConfig.getTimeFormatSecondAndMinutes(), minutes, seconds);
   }
   if (minutes == 1) {
     return String.format(translationsConfig.getTimeFormatSecondsAndMinute(), minutes, seconds);
   }
   return String.format(translationsConfig.getTimeFormatSecondsAndMinutes(), minutes, seconds);
 }
 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);
       }
     }
   }
 }
Example #3
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);
       }
     }
   }
 }