@Override public void run() { for (Resident resident : CivGlobal.getResidents()) { if (!resident.isProtected()) { continue; } int mins; try { mins = CivSettings.getInteger(CivSettings.civConfig, "global.pvp_timer"); if (DateUtil.isAfterMins(new Date(resident.getRegistered()), mins)) { // if (DateUtil.isAfterSeconds(new Date(resident.getRegistered()), mins)) { resident.setisProtected(false); CivMessage.send( resident, CivColor.LightGray + CivSettings.localize.localizedString("pvpTimerEnded")); } } catch (InvalidConfiguration e) { e.printStackTrace(); return; } } }
@Override public void onInteract(PlayerInteractEvent event) { try { if (War.isWarTime()) { throw new CivException("Cannot use spy missions during war time."); } ConfigMission mission = CivSettings.missions.get(this.getId()); if (mission == null) { throw new CivException("Unknown mission " + this.getId()); } Resident resident = CivGlobal.getResident(event.getPlayer()); if (resident == null || !resident.hasTown()) { throw new CivException("Only residents of towns can perform spy missions."); } Date now = new Date(); if (!event.getPlayer().isOp()) { try { int spyRegisterTime = CivSettings.getInteger(CivSettings.espionageConfig, "espionage.spy_register_time"); int spyOnlineTime = CivSettings.getInteger(CivSettings.espionageConfig, "espionage.spy_online_time"); long expire = resident.getRegistered() + (spyRegisterTime * 60 * 1000); if (now.getTime() <= expire) { throw new CivException( "You cannot use a spy yet, you must play CivCraft a bit longer before you can use it."); } expire = resident.getLastOnline() + (spyOnlineTime * 60 * 1000); if (now.getTime() <= expire) { throw new CivException("You must be online longer before you can use a spy."); } } catch (InvalidConfiguration e) { e.printStackTrace(); } } ConfigUnit unit = Unit.getPlayerUnit(event.getPlayer()); if (unit == null || !unit.id.equals("u_spy")) { event.getPlayer().getInventory().remove(event.getItem()); throw new CivException("Only spies can use mission books."); } ChunkCoord coord = new ChunkCoord(event.getPlayer().getLocation()); CultureChunk cc = CivGlobal.getCultureChunk(coord); TownChunk tc = CivGlobal.getTownChunk(coord); if (cc == null || cc.getCiv() == resident.getCiv()) { throw new CivException( "You must be in a civilization's culture that's not your own to spy on them."); } if ((cc != null && cc.getCiv().isAdminCiv()) || (tc != null && tc.getTown().getCiv().isAdminCiv())) { throw new CivException("You cannot spy on an admin civ."); } if (CivGlobal.isCasualMode()) { if (!cc.getCiv().getDiplomacyManager().isHostileWith(resident.getCiv()) && !cc.getCiv().getDiplomacyManager().atWarWith(resident.getCiv())) { throw new CivException( "You must be hostile or at war with " + cc.getCiv().getName() + " in order to perform spy missions in casual mode."); } } resident.setInteractiveMode( new InteractiveSpyMission( mission, event.getPlayer().getName(), event.getPlayer().getLocation(), cc.getTown())); } catch (CivException e) { CivMessage.sendError(event.getPlayer(), e.getMessage()); } }