Instance.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. /*
  2. * Copyright (C) 2004-2013 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.model.entity;
  20. import java.io.File;
  21. import java.io.IOException;
  22. import java.util.ArrayList;
  23. import java.util.Collection;
  24. import java.util.HashMap;
  25. import java.util.List;
  26. import java.util.Map;
  27. import java.util.concurrent.ScheduledFuture;
  28. import java.util.logging.Level;
  29. import java.util.logging.Logger;
  30. import javax.xml.parsers.DocumentBuilderFactory;
  31. import org.w3c.dom.Document;
  32. import org.w3c.dom.NamedNodeMap;
  33. import org.w3c.dom.Node;
  34. import com.l2jserver.Config;
  35. import com.l2jserver.gameserver.Announcements;
  36. import com.l2jserver.gameserver.ThreadPoolManager;
  37. import com.l2jserver.gameserver.datatables.DoorTable;
  38. import com.l2jserver.gameserver.datatables.NpcTable;
  39. import com.l2jserver.gameserver.idfactory.IdFactory;
  40. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  41. import com.l2jserver.gameserver.instancemanager.MapRegionManager;
  42. import com.l2jserver.gameserver.model.IL2Procedure;
  43. import com.l2jserver.gameserver.model.L2Spawn;
  44. import com.l2jserver.gameserver.model.L2World;
  45. import com.l2jserver.gameserver.model.L2WorldRegion;
  46. import com.l2jserver.gameserver.model.Location;
  47. import com.l2jserver.gameserver.model.StatsSet;
  48. import com.l2jserver.gameserver.model.actor.L2Attackable;
  49. import com.l2jserver.gameserver.model.actor.L2Npc;
  50. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  51. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  52. import com.l2jserver.gameserver.model.actor.templates.L2DoorTemplate;
  53. import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
  54. import com.l2jserver.gameserver.network.SystemMessageId;
  55. import com.l2jserver.gameserver.network.clientpackets.Say2;
  56. import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
  57. import com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket;
  58. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  59. import com.l2jserver.util.L2FastList;
  60. import com.l2jserver.util.L2FastMap;
  61. /**
  62. * Main class for game instances.
  63. * @author evill33t, GodKratos
  64. */
  65. public class Instance
  66. {
  67. private static final Logger _log = Logger.getLogger(Instance.class.getName());
  68. private final int _id;
  69. private String _name;
  70. private final L2FastList<Integer> _players = new L2FastList<>(true);
  71. private final List<L2Npc> _npcs = new L2FastList<>(true);
  72. private final Map<Integer, L2DoorInstance> _doors = new L2FastMap<>(true);
  73. private final Map<String, List<L2Spawn>> _manualSpawn = new HashMap<>();
  74. private Location _spawnLoc = null;
  75. private boolean _allowSummon = true;
  76. private long _emptyDestroyTime = -1;
  77. private long _lastLeft = -1;
  78. private long _instanceStartTime = -1;
  79. private long _instanceEndTime = -1;
  80. private boolean _isPvPInstance = false;
  81. private boolean _showTimer = false;
  82. private boolean _isTimerIncrease = true;
  83. private String _timerText = "";
  84. protected ScheduledFuture<?> _checkTimeUpTask = null;
  85. public Instance(int id)
  86. {
  87. _id = id;
  88. _instanceStartTime = System.currentTimeMillis();
  89. }
  90. public Instance(int id, String name)
  91. {
  92. _id = id;
  93. _name = name;
  94. _instanceStartTime = System.currentTimeMillis();
  95. }
  96. /**
  97. * @return the ID of this instance.
  98. */
  99. public int getId()
  100. {
  101. return _id;
  102. }
  103. /**
  104. * @return the name of this instance
  105. */
  106. public String getName()
  107. {
  108. return _name;
  109. }
  110. public void setName(String name)
  111. {
  112. _name = name;
  113. }
  114. /**
  115. * @return whether summon friend type skills are allowed for this instance
  116. */
  117. public boolean isSummonAllowed()
  118. {
  119. return _allowSummon;
  120. }
  121. /**
  122. * Sets the status for the instance for summon friend type skills
  123. * @param b
  124. */
  125. public void setAllowSummon(boolean b)
  126. {
  127. _allowSummon = b;
  128. }
  129. /**
  130. * Returns true if entire instance is PvP zone
  131. * @return
  132. */
  133. public boolean isPvPInstance()
  134. {
  135. return _isPvPInstance;
  136. }
  137. /**
  138. * Sets PvP zone status of the instance
  139. * @param b
  140. */
  141. public void setPvPInstance(boolean b)
  142. {
  143. _isPvPInstance = b;
  144. }
  145. /**
  146. * Set the instance duration task
  147. * @param duration in milliseconds
  148. */
  149. public void setDuration(int duration)
  150. {
  151. if (_checkTimeUpTask != null)
  152. {
  153. _checkTimeUpTask.cancel(true);
  154. }
  155. _checkTimeUpTask = ThreadPoolManager.getInstance().scheduleGeneral(new CheckTimeUp(duration), 500);
  156. _instanceEndTime = System.currentTimeMillis() + duration + 500;
  157. }
  158. /**
  159. * Set time before empty instance will be removed
  160. * @param time in milliseconds
  161. */
  162. public void setEmptyDestroyTime(long time)
  163. {
  164. _emptyDestroyTime = time;
  165. }
  166. /**
  167. * Checks if the player exists within this instance
  168. * @param objectId
  169. * @return true if player exists in instance
  170. */
  171. public boolean containsPlayer(int objectId)
  172. {
  173. return _players.contains(objectId);
  174. }
  175. /**
  176. * Adds the specified player to the instance
  177. * @param objectId Players object ID
  178. */
  179. public void addPlayer(int objectId)
  180. {
  181. _players.add(objectId);
  182. }
  183. /**
  184. * Removes the specified player from the instance list.
  185. * @param objectId the player's object Id
  186. */
  187. public void removePlayer(Integer objectId)
  188. {
  189. _players.remove(objectId);
  190. if (_players.isEmpty() && (_emptyDestroyTime >= 0))
  191. {
  192. _lastLeft = System.currentTimeMillis();
  193. setDuration((int) (_instanceEndTime - System.currentTimeMillis() - 500));
  194. }
  195. }
  196. public void addNpc(L2Npc npc)
  197. {
  198. _npcs.add(npc);
  199. }
  200. public void removeNpc(L2Npc npc)
  201. {
  202. if (npc.getSpawn() != null)
  203. {
  204. npc.getSpawn().stopRespawn();
  205. }
  206. _npcs.remove(npc);
  207. }
  208. /**
  209. * Adds a door into the instance
  210. * @param doorId - from doors.xml
  211. * @param set - StatsSet for initializing door
  212. */
  213. public void addDoor(int doorId, StatsSet set)
  214. {
  215. if (_doors.containsKey(doorId))
  216. {
  217. _log.warning("Door ID " + doorId + " already exists in instance " + getId());
  218. return;
  219. }
  220. final L2DoorInstance newdoor = new L2DoorInstance(IdFactory.getInstance().getNextId(), new L2DoorTemplate(set));
  221. newdoor.setInstanceId(getId());
  222. newdoor.setCurrentHp(newdoor.getMaxHp());
  223. newdoor.spawnMe(newdoor.getTemplate().getX(), newdoor.getTemplate().getY(), newdoor.getTemplate().getZ());
  224. _doors.put(doorId, newdoor);
  225. }
  226. public List<Integer> getPlayers()
  227. {
  228. return _players;
  229. }
  230. public List<L2Npc> getNpcs()
  231. {
  232. return _npcs;
  233. }
  234. public Collection<L2DoorInstance> getDoors()
  235. {
  236. return _doors.values();
  237. }
  238. public L2DoorInstance getDoor(int id)
  239. {
  240. return _doors.get(id);
  241. }
  242. public long getInstanceEndTime()
  243. {
  244. return _instanceEndTime;
  245. }
  246. public long getInstanceStartTime()
  247. {
  248. return _instanceStartTime;
  249. }
  250. public boolean isShowTimer()
  251. {
  252. return _showTimer;
  253. }
  254. public boolean isTimerIncrease()
  255. {
  256. return _isTimerIncrease;
  257. }
  258. public String getTimerText()
  259. {
  260. return _timerText;
  261. }
  262. /**
  263. * @return the spawn location for this instance to be used when leaving the instance
  264. */
  265. public Location getSpawnLoc()
  266. {
  267. return _spawnLoc;
  268. }
  269. /**
  270. * Sets the spawn location for this instance to be used when leaving the instance
  271. * @param loc
  272. */
  273. public void setSpawnLoc(Location loc)
  274. {
  275. _spawnLoc = loc;
  276. }
  277. public void removePlayers()
  278. {
  279. _players.executeForEach(new EjectProcedure());
  280. _players.clear();
  281. }
  282. public void removeNpcs()
  283. {
  284. for (L2Npc mob : _npcs)
  285. {
  286. if (mob != null)
  287. {
  288. if (mob.getSpawn() != null)
  289. {
  290. mob.getSpawn().stopRespawn();
  291. }
  292. mob.deleteMe();
  293. }
  294. }
  295. _npcs.clear();
  296. _manualSpawn.clear();
  297. }
  298. public void removeDoors()
  299. {
  300. for (L2DoorInstance door : _doors.values())
  301. {
  302. if (door != null)
  303. {
  304. L2WorldRegion region = door.getWorldRegion();
  305. door.decayMe();
  306. if (region != null)
  307. {
  308. region.removeVisibleObject(door);
  309. }
  310. door.getKnownList().removeAllKnownObjects();
  311. L2World.getInstance().removeObject(door);
  312. }
  313. }
  314. _doors.clear();
  315. }
  316. /**
  317. * Spawns group of instance NPC's
  318. * @param groupName - name of group from XML definition to spawn
  319. * @return list of spawned NPC's
  320. */
  321. public List<L2Npc> spawnGroup(String groupName)
  322. {
  323. List<L2Npc> ret = null;
  324. if (_manualSpawn.containsKey(groupName))
  325. {
  326. final List<L2Spawn> manualSpawn = _manualSpawn.get(groupName);
  327. ret = new ArrayList<>(manualSpawn.size());
  328. for (L2Spawn spawnDat : manualSpawn)
  329. {
  330. ret.add(spawnDat.doSpawn());
  331. }
  332. }
  333. else
  334. {
  335. _log.warning(getName() + " instance: cannot spawn NPC's, wrong group name: " + groupName);
  336. }
  337. return ret;
  338. }
  339. public void loadInstanceTemplate(String filename)
  340. {
  341. Document doc = null;
  342. File xml = new File(Config.DATAPACK_ROOT, "data/instances/" + filename);
  343. try
  344. {
  345. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  346. factory.setValidating(false);
  347. factory.setIgnoringComments(true);
  348. doc = factory.newDocumentBuilder().parse(xml);
  349. for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
  350. {
  351. if ("instance".equalsIgnoreCase(n.getNodeName()))
  352. {
  353. parseInstance(n);
  354. }
  355. }
  356. }
  357. catch (IOException e)
  358. {
  359. _log.log(Level.WARNING, "Instance: can not find " + xml.getAbsolutePath() + " ! " + e.getMessage(), e);
  360. }
  361. catch (Exception e)
  362. {
  363. _log.log(Level.WARNING, "Instance: error while loading " + xml.getAbsolutePath() + " ! " + e.getMessage(), e);
  364. }
  365. }
  366. private void parseInstance(Node n) throws Exception
  367. {
  368. L2Spawn spawnDat;
  369. L2NpcTemplate npcTemplate;
  370. String name = null;
  371. name = n.getAttributes().getNamedItem("name").getNodeValue();
  372. setName(name);
  373. Node a;
  374. Node first = n.getFirstChild();
  375. for (n = first; n != null; n = n.getNextSibling())
  376. {
  377. if ("activityTime".equalsIgnoreCase(n.getNodeName()))
  378. {
  379. a = n.getAttributes().getNamedItem("val");
  380. if (a != null)
  381. {
  382. _checkTimeUpTask = ThreadPoolManager.getInstance().scheduleGeneral(new CheckTimeUp(Integer.parseInt(a.getNodeValue()) * 60000), 15000);
  383. _instanceEndTime = System.currentTimeMillis() + (Long.parseLong(a.getNodeValue()) * 60000) + 15000;
  384. }
  385. }
  386. //@formatter:off
  387. /*
  388. else if ("timeDelay".equalsIgnoreCase(n.getNodeName()))
  389. {
  390. a = n.getAttributes().getNamedItem("val");
  391. if (a != null)
  392. instance.setTimeDelay(Integer.parseInt(a.getNodeValue()));
  393. }
  394. */
  395. //@formatter:on
  396. else if ("allowSummon".equalsIgnoreCase(n.getNodeName()))
  397. {
  398. a = n.getAttributes().getNamedItem("val");
  399. if (a != null)
  400. {
  401. setAllowSummon(Boolean.parseBoolean(a.getNodeValue()));
  402. }
  403. }
  404. else if ("emptyDestroyTime".equalsIgnoreCase(n.getNodeName()))
  405. {
  406. a = n.getAttributes().getNamedItem("val");
  407. if (a != null)
  408. {
  409. _emptyDestroyTime = Long.parseLong(a.getNodeValue()) * 1000;
  410. }
  411. }
  412. else if ("showTimer".equalsIgnoreCase(n.getNodeName()))
  413. {
  414. a = n.getAttributes().getNamedItem("val");
  415. if (a != null)
  416. {
  417. _showTimer = Boolean.parseBoolean(a.getNodeValue());
  418. }
  419. a = n.getAttributes().getNamedItem("increase");
  420. if (a != null)
  421. {
  422. _isTimerIncrease = Boolean.parseBoolean(a.getNodeValue());
  423. }
  424. a = n.getAttributes().getNamedItem("text");
  425. if (a != null)
  426. {
  427. _timerText = a.getNodeValue();
  428. }
  429. }
  430. else if ("PvPInstance".equalsIgnoreCase(n.getNodeName()))
  431. {
  432. a = n.getAttributes().getNamedItem("val");
  433. if (a != null)
  434. {
  435. setPvPInstance(Boolean.parseBoolean(a.getNodeValue()));
  436. }
  437. }
  438. else if ("doorlist".equalsIgnoreCase(n.getNodeName()))
  439. {
  440. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  441. {
  442. int doorId = 0;
  443. if ("door".equalsIgnoreCase(d.getNodeName()))
  444. {
  445. doorId = Integer.parseInt(d.getAttributes().getNamedItem("doorId").getNodeValue());
  446. StatsSet set = new StatsSet();
  447. set.add(DoorTable.getInstance().getDoorTemplate(doorId));
  448. for (Node bean = d.getFirstChild(); bean != null; bean = bean.getNextSibling())
  449. {
  450. if ("set".equalsIgnoreCase(bean.getNodeName()))
  451. {
  452. NamedNodeMap attrs = bean.getAttributes();
  453. String setname = attrs.getNamedItem("name").getNodeValue();
  454. String value = attrs.getNamedItem("val").getNodeValue();
  455. set.set(setname, value);
  456. }
  457. }
  458. addDoor(doorId, set);
  459. }
  460. }
  461. }
  462. else if ("spawnlist".equalsIgnoreCase(n.getNodeName()))
  463. {
  464. for (Node group = n.getFirstChild(); group != null; group = group.getNextSibling())
  465. {
  466. if ("group".equalsIgnoreCase(group.getNodeName()))
  467. {
  468. String spawnGroup = group.getAttributes().getNamedItem("name").getNodeValue();
  469. List<L2Spawn> manualSpawn = new ArrayList<>();
  470. for (Node d = group.getFirstChild(); d != null; d = d.getNextSibling())
  471. {
  472. int npcId = 0, x = 0, y = 0, z = 0, respawn = 0, heading = 0, delay = -1;
  473. if ("spawn".equalsIgnoreCase(d.getNodeName()))
  474. {
  475. npcId = Integer.parseInt(d.getAttributes().getNamedItem("npcId").getNodeValue());
  476. x = Integer.parseInt(d.getAttributes().getNamedItem("x").getNodeValue());
  477. y = Integer.parseInt(d.getAttributes().getNamedItem("y").getNodeValue());
  478. z = Integer.parseInt(d.getAttributes().getNamedItem("z").getNodeValue());
  479. heading = Integer.parseInt(d.getAttributes().getNamedItem("heading").getNodeValue());
  480. respawn = Integer.parseInt(d.getAttributes().getNamedItem("respawn").getNodeValue());
  481. if (d.getAttributes().getNamedItem("onKillDelay") != null)
  482. {
  483. delay = Integer.parseInt(d.getAttributes().getNamedItem("onKillDelay").getNodeValue());
  484. }
  485. npcTemplate = NpcTable.getInstance().getTemplate(npcId);
  486. if (npcTemplate != null)
  487. {
  488. spawnDat = new L2Spawn(npcTemplate);
  489. spawnDat.setLocx(x);
  490. spawnDat.setLocy(y);
  491. spawnDat.setLocz(z);
  492. spawnDat.setAmount(1);
  493. spawnDat.setHeading(heading);
  494. spawnDat.setRespawnDelay(respawn);
  495. if (respawn == 0)
  496. {
  497. spawnDat.stopRespawn();
  498. }
  499. else
  500. {
  501. spawnDat.startRespawn();
  502. }
  503. spawnDat.setInstanceId(getId());
  504. if (spawnGroup.equals("general"))
  505. {
  506. L2Npc spawned = spawnDat.doSpawn();
  507. if ((delay >= 0) && (spawned instanceof L2Attackable))
  508. {
  509. ((L2Attackable) spawned).setOnKillDelay(delay);
  510. }
  511. }
  512. else
  513. {
  514. manualSpawn.add(spawnDat);
  515. }
  516. }
  517. else
  518. {
  519. _log.warning("Instance: Data missing in NPC table for ID: " + npcId + " in Instance " + getId());
  520. }
  521. }
  522. }
  523. if (!manualSpawn.isEmpty())
  524. {
  525. _manualSpawn.put(spawnGroup, manualSpawn);
  526. }
  527. }
  528. }
  529. }
  530. else if ("spawnpoint".equalsIgnoreCase(n.getNodeName()))
  531. {
  532. try
  533. {
  534. int x = Integer.parseInt(n.getAttributes().getNamedItem("spawnX").getNodeValue());
  535. int y = Integer.parseInt(n.getAttributes().getNamedItem("spawnY").getNodeValue());
  536. int z = Integer.parseInt(n.getAttributes().getNamedItem("spawnZ").getNodeValue());
  537. _spawnLoc = new Location(x, y, z);
  538. }
  539. catch (Exception e)
  540. {
  541. _log.log(Level.WARNING, "Error parsing instance xml: " + e.getMessage(), e);
  542. _spawnLoc = null;
  543. }
  544. }
  545. }
  546. }
  547. protected void doCheckTimeUp(int remaining)
  548. {
  549. CreatureSay cs = null;
  550. int timeLeft;
  551. int interval;
  552. if (_players.isEmpty() && (_emptyDestroyTime == 0))
  553. {
  554. remaining = 0;
  555. interval = 500;
  556. }
  557. else if (_players.isEmpty() && (_emptyDestroyTime > 0))
  558. {
  559. Long emptyTimeLeft = (_lastLeft + _emptyDestroyTime) - System.currentTimeMillis();
  560. if (emptyTimeLeft <= 0)
  561. {
  562. interval = 0;
  563. remaining = 0;
  564. }
  565. else if ((remaining > 300000) && (emptyTimeLeft > 300000))
  566. {
  567. interval = 300000;
  568. remaining = remaining - 300000;
  569. }
  570. else if ((remaining > 60000) && (emptyTimeLeft > 60000))
  571. {
  572. interval = 60000;
  573. remaining = remaining - 60000;
  574. }
  575. else if ((remaining > 30000) && (emptyTimeLeft > 30000))
  576. {
  577. interval = 30000;
  578. remaining = remaining - 30000;
  579. }
  580. else
  581. {
  582. interval = 10000;
  583. remaining = remaining - 10000;
  584. }
  585. }
  586. else if (remaining > 300000)
  587. {
  588. timeLeft = remaining / 60000;
  589. interval = 300000;
  590. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.DUNGEON_EXPIRES_IN_S1_MINUTES);
  591. sm.addString(Integer.toString(timeLeft));
  592. Announcements.getInstance().announceToInstance(sm, getId());
  593. remaining = remaining - 300000;
  594. }
  595. else if (remaining > 60000)
  596. {
  597. timeLeft = remaining / 60000;
  598. interval = 60000;
  599. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.DUNGEON_EXPIRES_IN_S1_MINUTES);
  600. sm.addString(Integer.toString(timeLeft));
  601. Announcements.getInstance().announceToInstance(sm, getId());
  602. remaining = remaining - 60000;
  603. }
  604. else if (remaining > 30000)
  605. {
  606. timeLeft = remaining / 1000;
  607. interval = 30000;
  608. cs = new CreatureSay(0, Say2.ALLIANCE, "Notice", timeLeft + " seconds left.");
  609. remaining = remaining - 30000;
  610. }
  611. else
  612. {
  613. timeLeft = remaining / 1000;
  614. interval = 10000;
  615. cs = new CreatureSay(0, Say2.ALLIANCE, "Notice", timeLeft + " seconds left.");
  616. remaining = remaining - 10000;
  617. }
  618. if (cs != null)
  619. {
  620. _players.executeForEach(new BroadcastPacket(cs));
  621. }
  622. cancelTimer();
  623. if (remaining >= 10000)
  624. {
  625. _checkTimeUpTask = ThreadPoolManager.getInstance().scheduleGeneral(new CheckTimeUp(remaining), interval);
  626. }
  627. else
  628. {
  629. _checkTimeUpTask = ThreadPoolManager.getInstance().scheduleGeneral(new TimeUp(), interval);
  630. }
  631. }
  632. public void cancelTimer()
  633. {
  634. if (_checkTimeUpTask != null)
  635. {
  636. _checkTimeUpTask.cancel(true);
  637. }
  638. }
  639. public class CheckTimeUp implements Runnable
  640. {
  641. private final int _remaining;
  642. public CheckTimeUp(int remaining)
  643. {
  644. _remaining = remaining;
  645. }
  646. @Override
  647. public void run()
  648. {
  649. doCheckTimeUp(_remaining);
  650. }
  651. }
  652. public class TimeUp implements Runnable
  653. {
  654. @Override
  655. public void run()
  656. {
  657. InstanceManager.getInstance().destroyInstance(getId());
  658. }
  659. }
  660. public final class EjectProcedure implements IL2Procedure<Integer>
  661. {
  662. @Override
  663. public boolean execute(Integer objectId)
  664. {
  665. final L2PcInstance player = L2World.getInstance().getPlayer(objectId);
  666. if ((player != null) && (player.getInstanceId() == getId()))
  667. {
  668. player.setInstanceId(0);
  669. player.sendMessage("You were removed from the instance");
  670. if (getSpawnLoc() != null)
  671. {
  672. player.teleToLocation(getSpawnLoc(), true);
  673. }
  674. else
  675. {
  676. player.teleToLocation(MapRegionManager.TeleportWhereType.Town);
  677. }
  678. }
  679. return true;
  680. }
  681. }
  682. public final class BroadcastPacket implements IL2Procedure<Integer>
  683. {
  684. private final L2GameServerPacket _packet;
  685. public BroadcastPacket(L2GameServerPacket packet)
  686. {
  687. _packet = packet;
  688. }
  689. @Override
  690. public boolean execute(Integer objectId)
  691. {
  692. final L2PcInstance player = L2World.getInstance().getPlayer(objectId);
  693. if ((player != null) && (player.getInstanceId() == getId()))
  694. {
  695. player.sendPacket(_packet);
  696. }
  697. return true;
  698. }
  699. }
  700. }