コード例 #1
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();
 }
コード例 #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);
    }
  }