/** * Can resident a attack resident b? * * @param a * @param b * @return true if they can attack. */ public static boolean canAttackEnemy(String a, String b) { try { Resident residentA = TownyUniverse.getDataSource().getResident(a); Resident residentB = TownyUniverse.getDataSource().getResident(b); if (residentA.getTown() == residentB.getTown()) return false; if (residentA.getTown().getNation() == residentB.getTown().getNation()) return false; Nation nationA = residentA.getTown().getNation(); Nation nationB = residentB.getTown().getNation(); if (nationA.isNeutral() || nationB.isNeutral()) return false; if (nationA.hasEnemy(nationB)) return true; } catch (NotRegisteredException e) { return false; } return false; }
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(); }