Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 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);
             }
           });
 }
Esempio n. 3
0
 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;
 }
Esempio n. 4
0
 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;
 }
Esempio n. 5
0
 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);
             }
           });
 }
Esempio n. 6
0
 public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
   if (sender.hasPermission("hungergames.invis")) {
     Gamer gamer = pm.getGamer(sender.getName());
     Player p = gamer.getPlayer();
     if (args.length > 0) {
       if (args[0].toLowerCase().equals(cm.getCommandInvisNameOfShow())) {
         p.sendMessage(cm.getCommandInvisShow());
         gamer.seeInvis(true);
         gamer.updateOthersToSelf();
       } else if (args[0].toLowerCase().equals(cm.getCommandInvisNameOfHide())) {
         gamer.seeInvis(false);
         gamer.updateOthersToSelf();
         p.sendMessage(cm.getCommandInvisHide());
       } else if (args[0].toLowerCase().equals(cm.getCommandInvisNameOfShowAll())) {
         for (Gamer game : pm.getGamers()) {
           game.seeInvis(true);
           game.updateSelfToOthers();
         }
         p.sendMessage(cm.getCommandInvisShowAll());
       } else if (args[0].toLowerCase().equals(cm.getCommandInvisNameOfHideAll())) {
         for (Gamer game : pm.getGamers()) {
           game.seeInvis(false);
           game.updateSelfToOthers();
         }
         p.sendMessage(cm.getCommandInvisHideAll());
       } else if (args[0].toLowerCase().equals(cm.getCommandInvisNameOfHidePlayer())) {
         if (args.length > 1) {
           if (Bukkit.getPlayer(args[1]) != null) {
             pm.getGamer(Bukkit.getPlayer(args[1])).hide();
             p.sendMessage(
                 String.format(
                     cm.getCommandInvisHidePlayerSuccess(), Bukkit.getPlayer(args[1]).getName()));
           } else p.sendMessage(String.format(cm.getCommandInvisHidePlayerFail(), args[1]));
         } else p.sendMessage(cm.getCommandInvisHidePlayerNoArgs());
       } else if (args[0].toLowerCase().equals(cm.getCommandInvisNameOfShowPlayer())) {
         if (args.length > 1) {
           Player player = Bukkit.getPlayer(args[1]);
           if (player != null) {
             pm.getGamer(player).show();
             p.sendMessage(String.format(cm.getCommandInvisShowPlayerSuccess(), player.getName()));
           } else p.sendMessage(String.format(cm.getCommandInvisShowPlayerFail(), args[1]));
         } else p.sendMessage(cm.getCommandInvisShowPlayerNoArgs());
       } else p.sendMessage(cm.getCommandInvisNotEnoughArguments());
     } else p.sendMessage(cm.getCommandInvisNotEnoughArguments());
   } else sender.sendMessage(cm.getCommandInvisNoPermission());
   return true;
 }
 public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
   List<Gamer> gamers = pm.getAliveGamers();
   ArrayList<String> gamerNames = new ArrayList<String>();
   for (Gamer game : gamers) gamerNames.add(game.getPlayer().getDisplayName());
   Collections.sort(gamerNames);
   String gamersName = "No gamers";
   if (gamerNames.size() > 0)
     gamersName = StringUtils.join(gamerNames, ChatColor.GRAY + ", " + ChatColor.GRAY);
   sender.sendMessage(
       String.format(
           cm.getCommandPlayers(),
           gamers.size(),
           (pm.getGamers().size() - gamers.size()),
           gamersName));
   if (hg.currentTime >= 0)
     sender.sendMessage(
         String.format(cm.getCommandPlayersTimeStatusStarted(), hg.returnTime(hg.currentTime)));
   else
     sender.sendMessage(
         String.format(cm.getCommandPlayersTimeStatusStarting(), hg.returnTime(hg.currentTime)));
   return true;
 }
Esempio n. 8
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());
     }
   }
 }
Esempio n. 9
0
 public synchronized Gamer getGamer(Entity entity) {
   for (Gamer g : gamers) if (g.getPlayer() == entity) return g;
   return null;
 }
Esempio n. 10
0
 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();
 }
Esempio n. 11
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();
  }
Esempio n. 12
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);
       }
     }
   }
 }
Esempio n. 13
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);
       }
     }
   }
 }