Advertisement
Guest User

Untitled

a guest
May 21st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.69 KB | None | 0 0
  1. package ru.j2dev.gameserver.model.entity;
  2.  
  3. import gnu.trove.set.hash.TIntHashSet;
  4. import org.slf4j.Logger;
  5. import org.slf4j.LoggerFactory;
  6. import ru.j2dev.commons.listener.Listener;
  7. import ru.j2dev.commons.listener.ListenerList;
  8. import ru.j2dev.commons.threading.RunnableImpl;
  9. import ru.j2dev.commons.util.Rnd;
  10. import ru.j2dev.gameserver.ThreadPoolManager;
  11. import ru.j2dev.gameserver.data.xml.holder.NpcTemplateHolder;
  12. import ru.j2dev.gameserver.database.mysql;
  13. import ru.j2dev.gameserver.geodata.GeoEngine;
  14. import ru.j2dev.gameserver.idfactory.IdFactory;
  15. import ru.j2dev.gameserver.listener.actor.door.impl.MasterOnOpenCloseListenerImpl;
  16. import ru.j2dev.gameserver.listener.reflection.OnReflectionCollapseListener;
  17. import ru.j2dev.gameserver.listener.zone.impl.NoLandingZoneListener;
  18. import ru.j2dev.gameserver.listener.zone.impl.ResidenceEnterLeaveListenerImpl;
  19. import ru.j2dev.gameserver.manager.ReflectionManager;
  20. import ru.j2dev.gameserver.model.*;
  21. import ru.j2dev.gameserver.model.instances.DoorInstance;
  22. import ru.j2dev.gameserver.model.instances.NpcInstance;
  23. import ru.j2dev.gameserver.network.lineage2.components.CustomMessage;
  24. import ru.j2dev.gameserver.templates.DoorTemplate;
  25. import ru.j2dev.gameserver.templates.InstantZone;
  26. import ru.j2dev.gameserver.templates.InstantZone.DoorInfo;
  27. import ru.j2dev.gameserver.templates.InstantZone.SpawnInfo;
  28. import ru.j2dev.gameserver.templates.InstantZone.ZoneInfo;
  29. import ru.j2dev.gameserver.templates.ZoneTemplate;
  30. import ru.j2dev.gameserver.utils.Location;
  31. import ru.j2dev.gameserver.utils.NpcUtils;
  32.  
  33. import java.util.*;
  34. import java.util.concurrent.Future;
  35. import java.util.concurrent.atomic.AtomicInteger;
  36. import java.util.concurrent.locks.Lock;
  37. import java.util.concurrent.locks.ReentrantLock;
  38. import java.util.stream.Collectors;
  39.  
  40. public class Reflection {
  41. private static final Logger LOGGER = LoggerFactory.getLogger(Reflection.class);
  42. private static final AtomicInteger _nextId = new AtomicInteger();
  43.  
  44. protected final Lock lock = new ReentrantLock();
  45. protected final List<Spawner> _spawns = new ArrayList<>();
  46. protected final List<GameObject> _objects = new ArrayList<>();
  47. protected final TIntHashSet _visitors = new TIntHashSet();
  48. private final int _id;
  49. private final ReflectionListenerList listeners = new ReflectionListenerList();
  50. protected Map<Integer, DoorInstance> _doors = Collections.emptyMap();
  51. protected Map<String, Zone> _zones = Collections.emptyMap();
  52. protected Map<String, List<Spawner>> _spawners = Collections.emptyMap();
  53. protected int _playerCount;
  54. protected Party _party;
  55. protected CommandChannel _commandChannel;
  56. private String _name = "";
  57. private InstantZone _instance;
  58. private int _geoIndex;
  59. private Location _resetLoc;
  60. private Location _returnLoc;
  61. private Location _teleportLoc;
  62. private int _collapseIfEmptyTime;
  63. private boolean _isCollapseStarted;
  64. private Future<?> _collapseTask;
  65. private Future<?> _collapse1minTask;
  66. private Future<?> _hiddencollapseTask;
  67. private boolean _event;
  68.  
  69. public Reflection() {
  70. this(_nextId.incrementAndGet());
  71. }
  72.  
  73. private Reflection(final int id) {
  74. _id = id;
  75. }
  76.  
  77. public Reflection(final int id, final boolean event) {
  78. _id = id;
  79. _event = event;
  80. }
  81.  
  82. public static Reflection createReflection(final int id) {
  83. if (id > 0) {
  84. throw new IllegalArgumentException("id should be <= 0");
  85. }
  86. return new Reflection(id);
  87. }
  88.  
  89. public int getId() {
  90. return _id;
  91. }
  92.  
  93. public int getInstancedZoneId() {
  94. return (_instance == null) ? 0 : _instance.getId();
  95. }
  96.  
  97. public Party getParty() {
  98. return _party;
  99. }
  100.  
  101. public void setParty(final Party party) {
  102. _party = party;
  103. }
  104.  
  105. public void setCommandChannel(final CommandChannel commandChannel) {
  106. _commandChannel = commandChannel;
  107. }
  108.  
  109. public void setCollapseIfEmptyTime(final int value) {
  110. _collapseIfEmptyTime = value;
  111. }
  112.  
  113. public String getName() {
  114. return _name;
  115. }
  116.  
  117. protected void setName(final String name) {
  118. _name = name;
  119. }
  120.  
  121. public InstantZone getInstancedZone() {
  122. return _instance;
  123. }
  124.  
  125. protected void setInstancedZone(final InstantZone iz) {
  126. _instance = iz;
  127. }
  128.  
  129. public int getGeoIndex() {
  130. return _geoIndex;
  131. }
  132.  
  133. protected void setGeoIndex(final int geoIndex) {
  134. _geoIndex = geoIndex;
  135. }
  136.  
  137. public Location getCoreLoc() {
  138. return _resetLoc;
  139. }
  140.  
  141. public void setCoreLoc(final Location l) {
  142. _resetLoc = l;
  143. }
  144.  
  145. public Location getReturnLoc() {
  146. return _returnLoc;
  147. }
  148.  
  149. public void setReturnLoc(final Location l) {
  150. _returnLoc = l;
  151. }
  152.  
  153. public Location getTeleportLoc() {
  154. return _teleportLoc;
  155. }
  156.  
  157. public void setTeleportLoc(final Location l) {
  158. _teleportLoc = l;
  159. }
  160.  
  161. public List<Spawner> getSpawns() {
  162. return _spawns;
  163. }
  164.  
  165. public Collection<DoorInstance> getDoors() {
  166. return _doors.values();
  167. }
  168.  
  169. public DoorInstance getDoor(final int id) {
  170. return _doors.get(id);
  171. }
  172.  
  173. public Zone getZone(final String name) {
  174. return _zones.get(name);
  175. }
  176.  
  177. public void startCollapseTimer(final long timeInMillis) {
  178. if ((isDefault() || isStatic()) && !_event) {
  179. new Exception("Basic reflection " + _id + " could not be collapsed!").printStackTrace();
  180. return;
  181. }
  182. lock.lock();
  183. try {
  184. if (_collapseTask != null) {
  185. _collapseTask.cancel(false);
  186. _collapseTask = null;
  187. }
  188. if (_collapse1minTask != null) {
  189. _collapse1minTask.cancel(false);
  190. _collapse1minTask = null;
  191. }
  192. _collapseTask = ThreadPoolManager.getInstance().schedule(new RunnableImpl() {
  193. @Override
  194. public void runImpl() {
  195. collapse();
  196. }
  197. }, timeInMillis);
  198. if (timeInMillis >= 60000L) {
  199. _collapse1minTask = ThreadPoolManager.getInstance().schedule(new RunnableImpl() {
  200. @Override
  201. public void runImpl() {
  202. minuteBeforeCollapse();
  203. }
  204. }, timeInMillis - 60000L);
  205. }
  206. } finally {
  207. lock.unlock();
  208. }
  209. }
  210.  
  211. public void stopCollapseTimer() {
  212. lock.lock();
  213. try {
  214. if (_collapseTask != null) {
  215. _collapseTask.cancel(false);
  216. _collapseTask = null;
  217. }
  218. if (_collapse1minTask != null) {
  219. _collapse1minTask.cancel(false);
  220. _collapse1minTask = null;
  221. }
  222. } finally {
  223. lock.unlock();
  224. }
  225. }
  226.  
  227. public void minuteBeforeCollapse() {
  228. if (_isCollapseStarted) {
  229. return;
  230. }
  231. lock.lock();
  232. try {
  233. _objects.stream().filter(GameObject::isPlayer).map(GameObject::getPlayer).forEach(player -> player.sendMessage(new CustomMessage("THIS_INSTANCE_ZONE_WILL_BE_TERMINATED_IN_S1_MINUTES_YOU_WILL_BE_FORCED_OUT_OF_THE_DANGEON_THEN_TIME_EXPIRES", player).addNumber(1L)));
  234. } finally {
  235. lock.unlock();
  236. }
  237. }
  238.  
  239. public void collapse() {
  240. if (_id <= 0 && !_event) {
  241. new Exception("Basic or not event reflection " + _id + " could not be collapsed!").printStackTrace();
  242. return;
  243. }
  244. lock.lock();
  245. try {
  246. if (_isCollapseStarted) {
  247. return;
  248. }
  249. _isCollapseStarted = true;
  250. } finally {
  251. lock.unlock();
  252. }
  253. listeners.onCollapse();
  254. try {
  255. stopCollapseTimer();
  256. if (_hiddencollapseTask != null) {
  257. _hiddencollapseTask.cancel(false);
  258. _hiddencollapseTask = null;
  259. }
  260. _spawns.forEach(Spawner::deleteAll);
  261. _spawners.keySet().forEach(this::despawnByGroup);
  262. _doors.values().forEach(GameObject::deleteMe);
  263. _doors.clear();
  264. _zones.values().forEach(zone -> zone.setActive(false));
  265. _zones.clear();
  266. final List<Player> teleport = new ArrayList<>();
  267. final List<GameObject> delete = new ArrayList<>();
  268. lock.lock();
  269. try {
  270. _objects.forEach(o -> {
  271. if (o.isPlayer()) {
  272. teleport.add((Player) o);
  273. } else {
  274. if (o.isPlayable()) {
  275. return;
  276. }
  277. delete.add(o);
  278. }
  279. });
  280. } finally {
  281. lock.unlock();
  282. }
  283. teleport.forEach(player -> {
  284. if (player.getParty() != null) {
  285. if (equals(player.getParty().getReflection())) {
  286. player.getParty().setReflection(null);
  287. }
  288. if (player.getParty().getCommandChannel() != null && equals(player.getParty().getCommandChannel().getReflection())) {
  289. player.getParty().getCommandChannel().setReflection(null);
  290. }
  291. }
  292. if (equals(player.getReflection())) {
  293. if (getReturnLoc() != null) {
  294. player.teleToLocation(getReturnLoc(), ReflectionManager.DEFAULT);
  295. } else {
  296. player.setReflection(ReflectionManager.DEFAULT);
  297. }
  298. }
  299. });
  300. if (_commandChannel != null) {
  301. _commandChannel.setReflection(null);
  302. _commandChannel = null;
  303. }
  304. if (_party != null) {
  305. _party.setReflection(null);
  306. _party = null;
  307. }
  308. delete.forEach(GameObject::deleteMe);
  309. _spawns.clear();
  310. _objects.clear();
  311. _visitors.clear();
  312. _doors.clear();
  313. _playerCount = 0;
  314. onCollapse();
  315. } finally {
  316. ReflectionManager.getInstance().remove(this);
  317. GeoEngine.FreeGeoIndex(getGeoIndex());
  318. }
  319. }
  320.  
  321. protected void onCollapse() {
  322. }
  323.  
  324. public void addObject(final GameObject o) {
  325. if (_isCollapseStarted) {
  326. return;
  327. }
  328. lock.lock();
  329. try {
  330. _objects.add(o);
  331. if (o.isPlayer()) {
  332. ++_playerCount;
  333. _visitors.add(o.getObjectId());
  334. onPlayerEnter(o.getPlayer());
  335. }
  336. } finally {
  337. lock.unlock();
  338. }
  339. if (_collapseIfEmptyTime > 0 && _hiddencollapseTask != null) {
  340. _hiddencollapseTask.cancel(false);
  341. _hiddencollapseTask = null;
  342. }
  343. }
  344.  
  345. public void removeObject(final GameObject o) {
  346. if (_isCollapseStarted) {
  347. return;
  348. }
  349. lock.lock();
  350. try {
  351. if (!_objects.remove(o)) {
  352. return;
  353. }
  354. if (o.isPlayer()) {
  355. --_playerCount;
  356. onPlayerExit(o.getPlayer());
  357. }
  358. } finally {
  359. lock.unlock();
  360. }
  361. if (_playerCount <= 0 && !isDefault() && !isStatic() && _hiddencollapseTask == null) {
  362. if (_collapseIfEmptyTime <= 0) {
  363. collapse();
  364. } else {
  365. _hiddencollapseTask = ThreadPoolManager.getInstance().schedule(new RunnableImpl() {
  366. @Override
  367. public void runImpl() {
  368. collapse();
  369. }
  370. }, _collapseIfEmptyTime * 60 * 1000L);
  371. }
  372. }
  373. }
  374.  
  375. public void onPlayerEnter(final Player player) {
  376. player.getInventory().validateItems();
  377. }
  378.  
  379. public void onPlayerExit(final Player player) {
  380. player.getInventory().validateItems();
  381. }
  382.  
  383. public List<Player> getPlayers() {
  384. final List<Player> result;
  385. lock.lock();
  386. try {
  387. result = _objects.stream().filter(GameObject::isPlayer).map(o -> (Player) o).collect(Collectors.toList());
  388. } finally {
  389. lock.unlock();
  390. }
  391. return result;
  392. }
  393.  
  394. public List<NpcInstance> getNpcs() {
  395. final List<NpcInstance> result;
  396. lock.lock();
  397. try {
  398. result = _objects.stream().filter(GameObject::isNpc).map(o -> (NpcInstance) o).collect(Collectors.toList());
  399. } finally {
  400. lock.unlock();
  401. }
  402. return result;
  403. }
  404.  
  405. public List<NpcInstance> getAllByNpcId(final int npcId, final boolean onlyAlive) {
  406. final List<NpcInstance> result;
  407. lock.lock();
  408. try {
  409. result = _objects.stream().filter(GameObject::isNpc).map(o -> (NpcInstance) o).filter(npc -> npcId == npc.getNpcId() && (!onlyAlive || !npc.isDead())).collect(Collectors.toList());
  410. } finally {
  411. lock.unlock();
  412. }
  413. return result;
  414. }
  415.  
  416. public boolean canChampions() {
  417. return _id <= 0;
  418. }
  419.  
  420. public boolean isAutolootForced() {
  421. return false;
  422. }
  423.  
  424. public boolean isCollapseStarted() {
  425. return _isCollapseStarted;
  426. }
  427.  
  428. public void addSpawn(final SimpleSpawner spawn) {
  429. if (spawn != null) {
  430. _spawns.add(spawn);
  431. }
  432. }
  433.  
  434. public void fillSpawns(final List<SpawnInfo> si) {
  435. if (si == null) {
  436. return;
  437. }
  438. for (final SpawnInfo s : si) {
  439. switch (s.getSpawnType()) {
  440. case 0: {
  441. s.getCoords().forEach(loc -> {
  442. final SimpleSpawner c = new SimpleSpawner(s.getNpcId());
  443. c.setReflection(this);
  444. c.setRespawnDelay(s.getRespawnDelay(), s.getRespawnRnd());
  445. c.setAmount(s.getCount());
  446. c.setLoc(loc);
  447. c.doSpawn(true);
  448. if (s.getRespawnDelay() == 0) {
  449. c.stopRespawn();
  450. } else {
  451. c.startRespawn();
  452. }
  453. addSpawn(c);
  454. });
  455. break;
  456. }
  457. case 1: {
  458. final SimpleSpawner c = new SimpleSpawner(s.getNpcId());
  459. c.setReflection(this);
  460. c.setRespawnDelay(s.getRespawnDelay(), s.getRespawnRnd());
  461. c.setAmount(1);
  462. c.setLoc(s.getCoords().get(Rnd.get(s.getCoords().size())));
  463. c.doSpawn(true);
  464. if (s.getRespawnDelay() == 0) {
  465. c.stopRespawn();
  466. } else {
  467. c.startRespawn();
  468. }
  469. addSpawn(c);
  470. break;
  471. }
  472. case 2: {
  473. final SimpleSpawner c = new SimpleSpawner(s.getNpcId());
  474. c.setReflection(this);
  475. c.setRespawnDelay(s.getRespawnDelay(), s.getRespawnRnd());
  476. c.setAmount(s.getCount());
  477. c.setTerritory(s.getLoc());
  478. for (int j = 0; j < s.getCount(); ++j) {
  479. c.doSpawn(true);
  480. }
  481. if (s.getRespawnDelay() == 0) {
  482. c.stopRespawn();
  483. } else {
  484. c.startRespawn();
  485. }
  486. addSpawn(c);
  487. }
  488. }
  489. }
  490. }
  491.  
  492. public void init(final Map<Integer, DoorTemplate> doors, final Map<String, ZoneTemplate> zones) {
  493. if (!doors.isEmpty()) {
  494. _doors = new HashMap<>(doors.size());
  495. }
  496. doors.values().forEach(template -> {
  497. final DoorInstance door = new DoorInstance(IdFactory.getInstance().getNextId(), template);
  498. door.setReflection(this);
  499. door.setIsInvul(true);
  500. door.spawnMe(template.getLoc());
  501. if (template.isOpened()) {
  502. door.openMe();
  503. }
  504. _doors.put(template.getNpcId(), door);
  505. });
  506. initDoors();
  507. if (!zones.isEmpty()) {
  508. _zones = new HashMap<>(zones.size());
  509. }
  510. zones.values().forEach(template -> {
  511. final Zone zone = new Zone(template);
  512. zoneAddListeners(zone);
  513. if (template.isEnabled()) {
  514. zone.setActive(true);
  515. }
  516. _zones.put(template.getName(), zone);
  517. });
  518. }
  519.  
  520.  
  521. private void zoneAddListeners(final Zone zone) {
  522. zone.setReflection(this);
  523. switch (zone.getType()) {
  524. case no_landing:
  525. case SIEGE: {
  526. zone.addListener(NoLandingZoneListener.STATIC);
  527. break;
  528. }
  529. case RESIDENCE: {
  530. zone.addListener(ResidenceEnterLeaveListenerImpl.STATIC);
  531. break;
  532. }
  533. }
  534. }
  535.  
  536. private void init0(final Map<Integer, DoorInfo> doors, final Map<String, ZoneInfo> zones) {
  537. if (!doors.isEmpty()) {
  538. _doors = new HashMap<>(doors.size());
  539. }
  540. doors.values().forEach(info -> {
  541. final DoorInstance door = new DoorInstance(IdFactory.getInstance().getNextId(), info.getTemplate());
  542. door.setReflection(this);
  543. door.setIsInvul(info.isInvul());
  544. door.spawnMe(info.getTemplate().getLoc());
  545. if (info.isOpened()) {
  546. door.openMe();
  547. }
  548. _doors.put(info.getTemplate().getNpcId(), door);
  549. });
  550. initDoors();
  551. if (!zones.isEmpty()) {
  552. _zones = new HashMap<>(zones.size());
  553. }
  554. zones.values().forEach(t -> {
  555. final Zone zone = new Zone(t.getTemplate());
  556. zoneAddListeners(zone);
  557. if (t.isActive()) {
  558. zone.setActive(true);
  559. }
  560. _zones.put(t.getTemplate().getName(), zone);
  561. });
  562. }
  563.  
  564. private void initDoors() {
  565. _doors.values().stream().filter(door -> door.getTemplate().getMasterDoor() > 0).forEach(door -> {
  566. final DoorInstance masterDoor = getDoor(door.getTemplate().getMasterDoor());
  567. masterDoor.addListener(new MasterOnOpenCloseListenerImpl(door));
  568. });
  569. }
  570.  
  571. public void openDoor(final int doorId) {
  572. final DoorInstance door = _doors.get(doorId);
  573. if (door != null) {
  574. door.openMe();
  575. }
  576. }
  577.  
  578. public void closeDoor(final int doorId) {
  579. final DoorInstance door = _doors.get(doorId);
  580. if (door != null) {
  581. door.closeMe();
  582. }
  583. }
  584.  
  585. public void clearReflection(final int timeInMinutes, final boolean message) {
  586. if (isDefault() || isStatic()) {
  587. return;
  588. }
  589. getNpcs().forEach(GameObject::deleteMe);
  590. startCollapseTimer(timeInMinutes * 60 * 1000L);
  591. if (message) {
  592. getPlayers().stream().filter(Objects::nonNull).forEach(pl -> {
  593. for (final Player partyPlayer : pl) {
  594. partyPlayer.sendMessage(new CustomMessage("THIS_DUNGEON_WILL_EXPIRE_IN_S1_MINUTES", partyPlayer).addNumber(timeInMinutes));
  595. }
  596. });
  597. }
  598. }
  599.  
  600. public NpcInstance addSpawnWithoutRespawn(final int npcId, final Location loc, final int randomOffset) {
  601. Location newLoc;
  602. if (randomOffset > 0) {
  603. newLoc = Location.findPointToStay(loc, 0, randomOffset, getGeoIndex()).setH(loc.h);
  604. } else {
  605. newLoc = loc;
  606. }
  607. return NpcUtils.spawnSingle(npcId, newLoc, this);
  608. }
  609.  
  610. public NpcInstance addSpawnWithRespawn(final int npcId, final Location loc, final int randomOffset, final int respawnDelay) {
  611. final SimpleSpawner sp = new SimpleSpawner(NpcTemplateHolder.getInstance().getTemplate(npcId));
  612. sp.setLoc((randomOffset > 0) ? Location.findPointToStay(loc, 0, randomOffset, getGeoIndex()) : loc);
  613. sp.setReflection(this);
  614. sp.setAmount(1);
  615. sp.setRespawnDelay(respawnDelay);
  616. sp.doSpawn(true);
  617. sp.startRespawn();
  618. return sp.getLastSpawn();
  619. }
  620.  
  621. public boolean isDefault() {
  622. return getId() <= 0;
  623. }
  624.  
  625. public boolean isStatic() {
  626. return false;
  627. }
  628.  
  629. public int[] getVisitors() {
  630. return _visitors.toArray();
  631. }
  632.  
  633. public void setReenterTime(final long time) {
  634. int[] players;
  635. lock.lock();
  636. try {
  637. players = _visitors.toArray();
  638. } finally {
  639. lock.unlock();
  640. }
  641. if (players != null) {
  642. Arrays.stream(players).forEach(objectId -> {
  643. try {
  644. final Player player = World.getPlayer(objectId);
  645. if (player != null) {
  646. player.setInstanceReuse(getInstancedZoneId(), time);
  647. } else {
  648. mysql.set("REPLACE INTO character_instances (obj_id, id, reuse) VALUES (?,?,?)", objectId, getInstancedZoneId(), time);
  649. }
  650. } catch (Exception e) {
  651. e.printStackTrace();
  652. }
  653. });
  654. }
  655. }
  656.  
  657. protected void onCreate() {
  658. ReflectionManager.getInstance().add(this);
  659. }
  660.  
  661. public void init(final InstantZone instantZone) {
  662. setName(instantZone.getName());
  663. setInstancedZone(instantZone);
  664. if (instantZone.getMapX() >= 0) {
  665. final int geoIndex = GeoEngine.NextGeoIndex(instantZone.getMapX(), instantZone.getMapY(), getId());
  666. setGeoIndex(geoIndex);
  667. }
  668. setTeleportLoc(instantZone.getTeleportCoord());
  669. if (instantZone.getReturnCoords() != null) {
  670. setReturnLoc(instantZone.getReturnCoords());
  671. }
  672. fillSpawns(instantZone.getSpawnsInfo());
  673. if (instantZone.getSpawns().size() > 0) {
  674. _spawners = new HashMap<>(instantZone.getSpawns().size());
  675. instantZone.getSpawns().forEach((key, value) -> {
  676. final List<Spawner> spawnList = new ArrayList<>(value.getTemplates().size());
  677. _spawners.put(key, spawnList);
  678. value.getTemplates().forEach(template -> {
  679. final HardSpawner spawner = new HardSpawner(template);
  680. spawnList.add(spawner);
  681. spawner.setAmount(template.getCount());
  682. spawner.setRespawnDelay(template.getRespawn(), template.getRespawnRandom());
  683. spawner.setReflection(this);
  684. spawner.setRespawnTime(0);
  685. });
  686. if (value.isSpawned()) {
  687. spawnByGroup(key);
  688. }
  689. });
  690. }
  691. init0(instantZone.getDoors(), instantZone.getZones());
  692. if (!isStatic()) {
  693. setCollapseIfEmptyTime(instantZone.getCollapseIfEmpty());
  694. startCollapseTimer(instantZone.getTimelimit() * 60 * 1000L);
  695. }
  696. onCreate();
  697. }
  698.  
  699. public void spawnByGroup(final String name) {
  700. final List<Spawner> list = _spawners.get(name);
  701. if (list == null) {
  702. throw new IllegalArgumentException();
  703. }
  704. list.forEach(Spawner::init);
  705. }
  706.  
  707. public void despawnByGroup(final String name) {
  708. final List<Spawner> list = _spawners.get(name);
  709. if (list == null) {
  710. throw new IllegalArgumentException();
  711. }
  712. list.forEach(Spawner::deleteAll);
  713. }
  714.  
  715. public Collection<Zone> getZones() {
  716. return _zones.values();
  717. }
  718.  
  719. public <T extends Listener<Reflection>> boolean addListener(final T listener) {
  720. return listeners.add(listener);
  721. }
  722.  
  723. public <T extends Listener<Reflection>> boolean removeListener(final T listener) {
  724. return listeners.remove(listener);
  725. }
  726.  
  727. public class ReflectionListenerList extends ListenerList<Reflection> {
  728. void onCollapse() {
  729. if (!getListeners().isEmpty()) {
  730. getListeners().forEach(listener -> ((OnReflectionCollapseListener) listener).onReflectionCollapse(Reflection.this));
  731. }
  732. }
  733. }
  734. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement