예제 #1
0
public class Players implements CommandExecutor {
  private Hungergames hg = HungergamesApi.getHungergames();
  private ChatManager cm = HungergamesApi.getChatManager();
  private PlayerManager pm = HungergamesApi.getPlayerManager();

  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;
  }
}
예제 #2
0
 public void onDisable() {
   for (Player p : Bukkit.getOnlinePlayers()) {
     p.kickPlayer(translationsConfig.getKickGameShutdownUnexpected());
     PlayerQuitEvent event = new PlayerQuitEvent(p, "He came, he saw, he conquered");
     playerListener.onQuit(event);
   }
   HungergamesApi.getMySqlManager().getPlayerJoinThread().mySqlDisconnect();
   HungergamesApi.getMySqlManager().getPlayerJoinThread().stop();
 }
예제 #3
0
 @EventHandler
 public void onPlace(BlockPlaceEvent event) {
   if (event.getBlock().getType() == Material.STONE_PLATE && hasAbility(event.getPlayer())) {
     event.getBlock().removeMetadata("Placer", HungergamesApi.getHungergames());
     event
         .getBlock()
         .setMetadata(
             "Placer",
             new FixedMetadataValue(HungergamesApi.getHungergames(), event.getPlayer().getName()));
   }
 }
예제 #4
0
public class Invis implements CommandExecutor {
  private PlayerManager pm = HungergamesApi.getPlayerManager();
  private ChatManager cm = HungergamesApi.getChatManager();

  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;
  }
}
예제 #5
0
 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());
 }
예제 #6
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);
             }
           });
 }
예제 #7
0
 @EventHandler
 public void onDamageByEntity(EntityDamageByEntityEvent event) {
   if (dmgBuff.containsKey(event.getDamager())) {
     DmgBoost boost = dmgBuff.get(event.getDamager());
     if (boost.expires < HungergamesApi.getHungergames().currentTime)
       dmgBuff.remove(event.getDamager());
     else event.setDamage(event.getDamage() + boost.extraDamage);
   }
 }
예제 #8
0
 private void setDamage(Player p, int damage) {
   DmgBoost boost = new DmgBoost();
   boost.expires = HungergamesApi.getHungergames().currentTime + berserkerLength;
   boost.extraDamage = damage;
   dmgBuff.put(p, boost);
   if (giveConfusion)
     p.addPotionEffect(
         new PotionEffect(PotionEffectType.CONFUSION, berserkerLength * 20, 0), true);
 }
예제 #9
0
public class Spawn implements CommandExecutor {
  public String[] aliases = new String[] {"hgspawn"};
  private TranslationManager cm = HungergamesApi.getTranslationManager();
  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;
  }
}
예제 #10
0
 @EventHandler(priority = EventPriority.LOWEST)
 public void onGameStart(GameStartEvent event) {
   for (Player p : getMyPlayers()) {
     Kit kit = getViableKit(p);
     if (kit != null) {
       HungergamesApi.getKitManager().setKit(p, kit.getName());
       kit.giveKit(p);
       p.sendMessage(String.format(messageOnGive, kit.getName()));
     } else p.sendMessage(messageWhenNoKitFound);
   }
 }
예제 #11
0
 private Kit getViableKit(Player player) {
   KitManager kits = HungergamesApi.getKitManager();
   ArrayList<Kit> randomKit = new ArrayList<Kit>();
   for (Kit kit : kits.getKits()) {
     if ((!onlyKitsYouOwn || kits.ownsKit(player, kit)) && !isBadKit(kit)) {
       randomKit.add(kit);
     }
   }
   if (randomKit.size() > 0) return randomKit.get(new Random().nextInt(randomKit.size()));
   return null;
 }
예제 #12
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;
 }
예제 #13
0
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;
  }
}
예제 #14
0
 @EventHandler
 public void onInteract(PlayerInteractEvent event) {
   if (event.isCancelled()) return;
   Block b = event.getClickedBlock();
   if (event.getAction() == Action.PHYSICAL
       && b != null
       && b.hasMetadata("Placer")
       && b.getType() == Material.STONE_PLATE
       && b.getRelative(BlockFace.DOWN).getType() == Material.GRAVEL) {
     b.removeMetadata("Placer", HungergamesApi.getHungergames());
     b.setType(Material.AIR);
     b.getWorld().createExplosion(b.getLocation().clone().add(0.5, 0.5, 0.5), 4F);
   }
 }
예제 #15
0
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;
  }
}
예제 #16
0
 /** Makes the update checker check for a update */
 public void checkUpdate() throws Exception {
   updateChecker = new UpdateChecker();
   updateChecker.checkUpdate(getCurrentVersion());
   latestVersion = updateChecker.getLatestVersion();
   if (latestVersion != null) {
     latestVersion = "v" + latestVersion;
     for (Player p : Bukkit.getOnlinePlayers())
       if (p.hasPermission("hungergames.update"))
         p.sendMessage(
             String.format(
                 HungergamesApi.getTranslationManager().getMessagePlayerUpdateAvailable(),
                 getCurrentVersion(),
                 getLatestVersion()));
   }
 }
예제 #17
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);
             }
           });
 }
예제 #18
0
 private void disguise(Entity entity, Player p) {
   if ((entity instanceof Animals && disguiseAsAnimal)
       || (entity instanceof Monster && disguiseAsMonster)) {
     if (hasAbility(p)) {
       if (!DisguiseAPI.isDisguised(p))
         DisguiseAPI.disguiseToAll(
             p, new MobDisguise(DisguiseType.valueOf(entity.getType().name()), true));
       else {
         Disguise disguise = DisguiseAPI.getDisguise(p);
         if (disguise.getType() == DisguiseType.valueOf(entity.getType().name())) return;
         DisguiseAPI.disguiseToAll(
             p, new MobDisguise(DisguiseType.valueOf(entity.getType().name()), true));
       }
       p.sendMessage(
           String.format(
               chameleonNowDisguised,
               HungergamesApi.getKitManager().toReadable(entity.getType().getName())));
     }
   }
 }
예제 #19
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();
 }
예제 #20
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();
  }
예제 #21
0
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);
  }
}
예제 #22
0
  /** Reload the config. This doesn't reload some values however */
  public void loadConfig() {
    hg.saveDefaultConfig();
    final TranslationManager cm = HungergamesApi.getTranslationManager();
    if (Bukkit.getServer().getAllowEnd() && hg.getConfig().getBoolean("DisableEnd", true)) {
      YamlConfiguration config = YamlConfiguration.loadConfiguration(new File("bukkit.yml"));
      config.set("settings.allow-end", false);
      try {
        config.save(new File("bukkit.yml"));
      } catch (IOException e) {
        e.printStackTrace();
      }
      System.out.println(cm.getLoggerDisabledEnd());
    }
    ReflectionManager rm = HungergamesApi.getReflectionManager();
    if (hg.getServer().getAllowNether() && hg.getConfig().getBoolean("DisableNether", true)) {
      rm.setPropertiesConfig("allow-nether", false);
      rm.savePropertiesConfig();
      System.out.println(cm.getLoggerDisabledNether());
    }
    if (hg.getServer().getSpawnRadius() > 0
        && hg.getConfig().getBoolean("ChangeSpawnLimit", true)) {
      rm.setPropertiesConfig("spawn-protection", 0);
      rm.savePropertiesConfig();
      System.out.println(cm.getLoggerChangedSpawnRadius());
    }
    if ((Integer) rm.getPropertiesConfig("max-build-height", 128) > 128
        && hg.getConfig().getBoolean("ChangeHeightLimit", true)) {
      rm.setPropertiesConfig("max-build-height", 128);
      rm.savePropertiesConfig();
      System.out.println(cm.getLoggerChangedHeightLimit());
    }
    currentVersion = "v" + hg.getDescription().getVersion();
    if (hg.getConfig().getBoolean("CheckUpdates"))
      Bukkit.getScheduler()
          .scheduleAsyncDelayedTask(
              hg,
              new Runnable() {
                public void run() {
                  try {
                    checkUpdate();
                  } catch (Exception ex) {
                    System.out.print(
                        String.format(cm.getLoggerFailedToCheckUpdate(), ex.getMessage()));
                  }
                }
              });

    hg.currentTime = -Math.abs(hg.getConfig().getInt("Countdown", 270));
    mysqlEnabled = hg.getConfig().getBoolean("UseMySql", false);
    displayScoreboards = hg.getConfig().getBoolean("Scoreboards", false);
    displayMessages = hg.getConfig().getBoolean("Messages", true);
    minPlayers = hg.getConfig().getInt("MinPlayers", 2);
    fireSpread = hg.getConfig().getBoolean("DisableFireSpread", false);
    wonBroadcastsDelay = hg.getConfig().getInt("WinnerBroadcastingDelay");
    gameShutdownDelay = hg.getConfig().getInt("GameShutdownDelay");
    feastSize = hg.getConfig().getInt("FeastSize", 20);
    invincibility = hg.getConfig().getInt("Invincibility", 120);
    chestLayers = hg.getConfig().getInt("ChestLayers", 500);
    timeTillFeast = hg.getConfig().getInt("TimeTillFeast", 500);
    spectatorChat = !hg.getConfig().getBoolean("SpectatorChat", true);
    shortenNames = hg.getConfig().getBoolean("ShortenNames");
    spectators = hg.getConfig().getBoolean("Spectators", true);
    kickOnDeath = hg.getConfig().getBoolean("KickOnDeath");
    mushroomStew = hg.getConfig().getBoolean("MushroomStew", false);
    mushroomStewRestores = hg.getConfig().getInt("MushroomStewRestores", 5);
    kitSelector = hg.getConfig().getBoolean("EnableKitSelector", true);
    feastTnt = hg.getConfig().getBoolean("FeastTnt", true);
    feastGround = parseItem(hg.getConfig().getString("FeastGround"));
    feast = parseItem(hg.getConfig().getString("Feast"));
    generatePillars = hg.getConfig().getBoolean("Pillars", true);
    feastInsides = parseItem(hg.getConfig().getString("FeastInsides"));
    pillarCorner = parseItem(hg.getConfig().getString("PillarCorner"));
    pillarInsides = parseItem(hg.getConfig().getString("PillarInsides"));
    forceCords = hg.getConfig().getBoolean("ForceCords", true);
    x = hg.getConfig().getInt("ForceX", 0);
    z = hg.getConfig().getInt("ForceZ", 0);
    kitSelectorIcon = parseItem(hg.getConfig().getString("KitSelectorIcon"));
    if (kitSelectorIcon == null) kitSelectorIcon = new ItemStack(Material.FEATHER);
    kitSelectorBack = parseItem(hg.getConfig().getString("KitSelectorForward"));
    if (kitSelectorBack == null) kitSelectorBack = new ItemStack(Material.SUGAR_CANE_BLOCK);
    kitSelectorForward = parseItem(hg.getConfig().getString("KitSelectorBack"));
    if (kitSelectorForward == null) kitSelectorForward = new ItemStack(Material.SUGAR_CANE_BLOCK);

    spectatorItemBack = parseItem(hg.getConfig().getString("SpectatorInventoryForward"));
    if (spectatorItemBack == null) spectatorItemBack = new ItemStack(Material.SUGAR_CANE_BLOCK);
    spectatorItemForwards = parseItem(hg.getConfig().getString("SpectatorInventoryBack"));
    if (spectatorItemForwards == null)
      spectatorItemForwards = new ItemStack(Material.SUGAR_CANE_BLOCK);

    kitSelectorDynamicSize = hg.getConfig().getBoolean("KitSelectorDynamicSize");
    kitSelectorInventorySize = hg.getConfig().getInt("KitSelectorInventorySize");
    mobSpawnChance = hg.getConfig().getInt("MobSpawnChance");
    if (hg.getConfig().contains("CommandsToRunBeforeShutdown"))
      commandsToRunBeforeShutdown = hg.getConfig().getStringList("CommandsToRunBeforeShutdown");
    else commandsToRunBeforeShutdown = new ArrayList<String>();
    disableMetrics = hg.getConfig().getBoolean("DisableMetrics");
    flyPreGame = hg.getConfig().getBoolean("FlyPregame");
    if (hg.getConfig().getBoolean("ChangeAlivePrefix"))
      alivePrefix = hg.getConfig().getString("AlivePrefix");
    if (hg.getConfig().getBoolean("ChangeSpectatingPrefix"))
      spectatingPrefix = hg.getConfig().getString("SpectatingPrefix");
    invisSpectators = !hg.getConfig().getBoolean("InvisibleSpectators");

    // Create the times where it broadcasts and advertises the feast
    feastBroadcastTimes.clear();
    for (int i = 1; i < 6; i++) feastBroadcastTimes.add(i);
    feastBroadcastTimes.add(30);
    feastBroadcastTimes.add(15);
    feastBroadcastTimes.add(10);

    invincibilityBroadcastTimes.clear();
    // Create the times where it advertises invincibility
    for (int i = 1; i <= 5; i++) invincibilityBroadcastTimes.add(i);
    invincibilityBroadcastTimes.add(30);
    invincibilityBroadcastTimes.add(15);
    invincibilityBroadcastTimes.add(10);

    // Create the times where it advertises when the game starts
    gameStartingBroadcastTimes.clear();
    for (int i = 1; i <= 5; i++) gameStartingBroadcastTimes.add(-i);
    gameStartingBroadcastTimes.add(-30);
    gameStartingBroadcastTimes.add(-15);
    gameStartingBroadcastTimes.add(-10);
  }
예제 #23
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();
 }
예제 #24
0
 public Chameleon() throws Exception {
   if (Bukkit.getPluginManager().getPlugin("iDisguise") == null)
     throw new Exception(
         String.format(
             HungergamesApi.getChatManager().getLoggerDependencyNotFound(), "Plugin iDiguise"));
 }
예제 #25
0
  @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);
    }
  }
예제 #26
0
 public ConfigManager() {
   hg = HungergamesApi.getHungergames();
   loadConfig();
 }
예제 #27
0
 public int getPrize(int pos) {
   if (HungergamesApi.getConfigManager().getWinnersConfig().getPrizesForPlacing().containsKey(pos))
     return HungergamesApi.getConfigManager().getWinnersConfig().getPrizesForPlacing().get(pos);
   return 0;
 }
예제 #28
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);
       }
     }
   }
 }