示例#1
0
文件: War.java 项目: adegie/Towny
 public void setupDelay(int delay) {
   if (delay <= 0) start();
   else {
     for (Long t : TimeMgmt.getCountdownDelays(delay, TimeMgmt.defaultCountdownDelays)) {
       // Schedule the warnings leading up to the start of the war event
       // warTimer.schedule(
       //              new ServerBroadCastTimerTask(plugin,
       //                              String.format("War starts in %s",
       // TimeMgmt.formatCountdownTime(t))),
       //                              (delay-t)*1000);
       int id =
           plugin
               .getServer()
               .getScheduler()
               .scheduleAsyncDelayedTask(
                   getPlugin(),
                   new ServerBroadCastTimerTask(
                       plugin, String.format("War starts in %s", TimeMgmt.formatCountdownTime(t))),
                   TimeTools.convertToTicks((delay - t)));
       if (id == -1) {
         TownyMessaging.sendErrorMsg("Could not schedule a countdown message for war event.");
         end();
       } else addTaskId(id);
     }
     // warTimer.schedule(new StartWarTimerTask(universe), delay*1000);
     int id =
         plugin
             .getServer()
             .getScheduler()
             .scheduleAsyncDelayedTask(
                 getPlugin(), new StartWarTimerTask(universe), TimeTools.convertToTicks(delay));
     if (id == -1) {
       TownyMessaging.sendErrorMsg("Could not schedule setup delay for war event.");
       end();
     } else addTaskId(id);
   }
 }
示例#2
0
文件: War.java 项目: adegie/Towny
  public void start() {
    warTime = true;

    // Announce

    // Seed spoils of war
    try {
      warSpoils.pay(TownySettings.getBaseSpoilsOfWar(), "Start of War - Base Spoils");
      TownyMessaging.sendMsg(
          "[War] Seeding spoils of war with " + TownySettings.getBaseSpoilsOfWar());
    } catch (EconomyException e) {
      TownyMessaging.sendErrorMsg("[War] Could not seed spoils of war.");
    }

    // Gather all nations at war
    for (Nation nation : TownyUniverse.getDataSource().getNations()) {
      if (!nation.isNeutral()) {
        add(nation);
        TownyMessaging.sendGlobalMessage(
            String.format(TownySettings.getLangString("msg_war_join_nation"), nation.getName()));
      } else if (!TownySettings.isDeclaringNeutral()) {
        try {
          nation.setNeutral(false);
          add(nation);
          TownyMessaging.sendGlobalMessage(
              String.format(TownySettings.getLangString("msg_war_join_forced"), nation.getName()));
        } catch (TownyException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
    // warTimer.scheduleAtFixedRate(new WarTimerTask(this), 0, 1000);
    int id =
        plugin
            .getServer()
            .getScheduler()
            .scheduleAsyncRepeatingTask(
                getPlugin(), new WarTimerTask(this), 0, TimeTools.convertToTicks(5));
    if (id == -1) {
      TownyMessaging.sendErrorMsg("Could not schedule war event loop.");
      end();
    } else addTaskId(id);
    checkEnd();
  }