Instance.java 19 KB

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