Exemplo n.º 1
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();
 }
Exemplo n.º 2
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);
    }
  }