Guest User

Untitled

a guest
Jan 14th, 2020
115
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package io.ruin.cache;
  2.  
  3. import io.ruin.Server;
  4. import io.ruin.api.buffer.InBuffer;
  5. import io.ruin.api.filestore.IndexFile;
  6. import io.ruin.api.utils.StringUtils;
  7. import io.ruin.model.World;
  8. import io.ruin.model.achievements.Achievement;
  9. import io.ruin.model.activities.cluescrolls.ClueType;
  10. import io.ruin.model.combat.*;
  11. import io.ruin.model.combat.special.Special;
  12. import io.ruin.model.entity.Entity;
  13. import io.ruin.model.entity.player.Player;
  14. import io.ruin.model.inter.journal.presets.Preset;
  15. import io.ruin.model.item.Item;
  16. import io.ruin.model.item.actions.ItemAction;
  17. import io.ruin.model.item.actions.ItemGroundItemAction;
  18. import io.ruin.model.item.actions.ItemItemAction;
  19. import io.ruin.model.item.actions.impl.ItemBreaking;
  20. import io.ruin.model.item.actions.impl.ItemSet;
  21. import io.ruin.model.item.actions.impl.ItemUpgrading;
  22. import io.ruin.model.item.actions.impl.Pet;
  23. import io.ruin.model.item.actions.impl.combine.ItemCombining;
  24. import io.ruin.model.item.listeners.IncomingHitListener;
  25. import io.ruin.model.item.listeners.OutgoingHitListener;
  26. import io.ruin.model.map.ground.GroundItemAction;
  27. import io.ruin.model.skills.farming.crop.Crop;
  28. import io.ruin.model.skills.herblore.Potion;
  29. import io.ruin.model.skills.magic.rune.Rune;
  30. import io.ruin.model.skills.mining.Pickaxe;
  31. import io.ruin.model.skills.smithing.SmithBar;
  32. import io.ruin.model.skills.woodcutting.Hatchet;
  33.  
  34. import java.util.ArrayList;
  35. import java.util.HashMap;
  36. import java.util.Map;
  37. import java.util.function.BiConsumer;
  38. import java.util.function.Consumer;
  39.  
  40. public class ItemDef {
  41.  
  42. public static ItemDef[] LOADED;
  43.  
  44. public static void load() {
  45. IndexFile index = Server.fileStore.get(2);
  46. LOADED = new ItemDef[index.getLastFileId(10) + 1];
  47. for(int id = 0; id < LOADED.length; id++) {
  48. ItemDef def = new ItemDef();
  49. def.id = id;
  50. byte[] data = index.getFile(10, def.id);
  51. def.decode(new InBuffer(data));
  52. if (def.stackable)
  53. def.descriptiveName = "some " + def.name.toLowerCase();
  54. else if(StringUtils.vowelStart(def.name))
  55. def.descriptiveName = "an " + def.name;
  56. else
  57. def.descriptiveName = "a " + def.name;
  58. LOADED[def.id] = def;
  59. }
  60. }
  61.  
  62. public static void forEach(Consumer<ItemDef> consumer) {
  63. for(ItemDef def : LOADED) {
  64. if(def != null)
  65. consumer.accept(def);
  66. }
  67. }
  68.  
  69. public static int findId(String name) {
  70. for(ItemDef def : LOADED) {
  71. if(def != null && def.name.toLowerCase().contains(name))
  72. return def.id;
  73. }
  74. System.err.println("Failed to find item with name: " + name + " | " + new Throwable().getStackTrace()[1].toString());
  75. return -1;
  76. }
  77.  
  78. public static ItemDef get(int id) {
  79. if(id < 0 || id >= LOADED.length)
  80. return null;
  81. return LOADED[id];
  82. }
  83.  
  84.  
  85.  
  86. /**
  87. * Stored data
  88. */
  89.  
  90. public int id;
  91.  
  92. public boolean tradeable;
  93.  
  94. public String examine;
  95.  
  96. public double weightInventory, weightEquipment;
  97.  
  98. public String descriptiveName;
  99.  
  100. public int equipSlot = -1;
  101.  
  102. public int[] equipReqs;
  103.  
  104. public int[] equipBonuses;
  105.  
  106. public ShieldType shieldType;
  107.  
  108. public WeaponType weaponType;
  109.  
  110. public RangedWeapon rangedWeapon;
  111.  
  112. public RangedAmmo rangedAmmo;
  113.  
  114. public boolean twoHanded;
  115.  
  116. public boolean hideHair, hideBeard, hideArms;
  117.  
  118. public boolean maxType;
  119.  
  120. public int lowAlchValue, highAlchValue;
  121.  
  122. public Achievement achievement;
  123. public boolean achievementReqIsIronmanOnly;
  124.  
  125. /**
  126. * Custom data
  127. */
  128.  
  129. public int dropOption = -1;
  130.  
  131. public int protectValue;
  132. public boolean neverProtect;
  133.  
  134. public int equipOption = -1;
  135.  
  136. public Special special;
  137.  
  138. public int rangedLevel = 1;
  139.  
  140. public ItemAction[] inventoryActions, equipmentActions;
  141.  
  142. public GroundItemAction[] groundActions;
  143.  
  144. public ItemItemAction defaultPrimaryItemItemAction;
  145.  
  146. public ArrayList<ItemItemAction> primaryItemItemActions, secondaryItemItemActions;
  147.  
  148. public ItemGroundItemAction defaultItemGroundItemAction;
  149.  
  150. public Map<Integer, ItemGroundItemAction> itemGroundItemActions;
  151.  
  152. public ItemAction tickAction, attackAction, defendAction;
  153.  
  154. public int pickupOption = -1;
  155.  
  156. public Hatchet hatchet;
  157.  
  158. public Pickaxe pickaxe;
  159.  
  160. public boolean sharpWeapon;
  161.  
  162. public boolean consumable;
  163.  
  164. public Potion potion;
  165.  
  166. public int potionDoses;
  167.  
  168. public Rune rune;
  169.  
  170. public Rune staffRune;
  171.  
  172. public boolean allowFruit;
  173.  
  174. public boolean allowPilesToNote;
  175.  
  176. public SmithBar smithBar;
  177.  
  178. public ItemSet itemSet;
  179.  
  180. public ClueType clueType;
  181.  
  182. public Crop seedType;
  183. public Crop produceOf;
  184.  
  185. public ItemBreaking brokenFrom;
  186. public ItemBreaking breakTo;
  187. public ItemUpgrading upgradedFrom;
  188. public ItemCombining combinedFrom;
  189. public int breakId;
  190.  
  191. public int bmShopPrice = -1;
  192.  
  193. public int sigmundBuyPrice;
  194.  
  195. public boolean slayerHelm;
  196.  
  197. public boolean leafBladed;
  198.  
  199. public boolean slayerBoostMelee;
  200.  
  201. public boolean slayerBoostAll;
  202.  
  203. public boolean[] godItem = new boolean[4]; // protection against gwd aggro
  204.  
  205. public BankWithdrawListener bankWithdrawListener;
  206.  
  207. public Pet pet;
  208.  
  209. public boolean graniteMaul;
  210.  
  211. public boolean free;
  212.  
  213. public boolean coxItem;
  214.  
  215. /**
  216. * Cache data
  217. */
  218.  
  219. public String name = "null";
  220. public int zoom2d = 2000;
  221. public int xan2d = 0;
  222. public int yan2d = 0;
  223. public int zan2d = 0;
  224. public int xof2d = 0;
  225. public int yof2d = 0;
  226. public boolean stackable;
  227. public int value = 1;
  228. public boolean members = false;
  229. public String[] groundOptions = {null, null, "Take", null, null};
  230. public String[] inventoryOptions = {null, null, null, null, "Drop"};
  231. public int notedId = -1;
  232. public int notedTemplateId = -1;
  233. public int ambient = 0;
  234. public int contrast = 0;
  235. public int team = 0;
  236. public boolean grandExchange = false;
  237. public int placeholderMainId = -1;
  238. public int placeholderTemplateId = -1;
  239. public int anInt1504 = -1;
  240. int anInt1493 = -1;
  241. int maleOffset = 0;
  242. int anInt1467 = -1;
  243. int anInt1496 = -1;
  244. int femaleOffset = 0;
  245. int anInt1498 = -1;
  246. int anInt1499 = -1;
  247. int maleHeadModel = -1;
  248. int anInt1501 = -1;
  249. int femaleHeadModel = -1;
  250. int anInt1503 = -1;
  251. int resizeX = 128;
  252. int resizeY = 128;
  253. int resizeZ = 128;
  254. int anInt1489 = -1;
  255. int anInt1515 = -1;
  256. public int inventoryModel;
  257. public short[] colorFind;
  258. public short[] colorReplace;
  259. short[] textureFind;
  260. short[] textureReplace;
  261. int[] anIntArray1497;
  262. int[] anIntArray1505;
  263. public HashMap<Object, Object> attributes;
  264.  
  265. /**
  266. * Decoding
  267. */
  268.  
  269. private void decode(InBuffer buffer) {
  270. for(; ; ) {
  271. int i = buffer.readUnsignedByte();
  272. if(i == 0)
  273. break;
  274. decode(buffer, i);
  275. }
  276. if(id == 2742) {
  277. name = "Coin Casket (small)";
  278. inventoryOptions[1] = null;
  279. }
  280.  
  281. if(id == 2744) {
  282. name = "Coin Casket (medium)";
  283. inventoryOptions[1] = null;
  284. }
  285.  
  286. if(id == 2746) {
  287. name = "Coin Casket (large)";
  288. inventoryOptions[1] = null;
  289. }
  290.  
  291. if(id == 2748) {
  292. name = "Coin Casket (giant)";
  293. inventoryOptions[1] = null;
  294. }
  295.  
  296. if (id == 1464) {
  297. name = "Vote Lottery Ticket";
  298. stackable = false;
  299. }
  300.  
  301. if(id == 13190) { //bond
  302. name = World.type.getWorldName() + " Credit";
  303. stackable = true;
  304. value = 0; //important for sigmund
  305. inventoryOptions[0] = "Claim";
  306. inventoryOptions[2] = null;
  307. }
  308.  
  309.  
  310. if (id == 5020) {
  311. name = "PK Ticket";
  312. stackable = true;
  313. tradeable = true;
  314. }
  315.  
  316. if (id == Preset.DRAGON_2H_SWORD || id == 13024 || id == 13026 || id == 9243 || id == 6109 || id == 3751) {
  317. value = 0;
  318. }
  319.  
  320. if(id == 6199) {
  321. inventoryOptions[2] = "Gift";
  322. }
  323.  
  324. if(id == 290) {
  325. name = "Super Mystery Box";
  326. inventoryOptions[1] = "Open";
  327. inventoryOptions[2] = "Gift";
  328. }
  329.  
  330. if(id == 6828) {
  331. name = "Pet Mystery Box";
  332. inventoryOptions[1] = "Open";
  333. inventoryOptions[2] = "Gift";
  334. }
  335.  
  336. if(id == 6829) {
  337. name = "Voting Mystery Box";
  338. inventoryOptions[1] = "Open";
  339. inventoryOptions[2] = "Gift";
  340. }
  341.  
  342. if(id == 6830) {
  343. name = "Cape Mystery Box";
  344. inventoryOptions[1] = "Open";
  345. inventoryOptions[2] = "Gift";
  346. }
  347.  
  348. if(id == 6831) {
  349. name = "3rd age Mystery Box";
  350. inventoryOptions[1] = "Open";
  351. inventoryOptions[2] = "Gift";
  352. }
  353.  
  354. if(id == 6832) {
  355. name = "Activity Mystery Box";
  356. inventoryOptions[1] = "Open";
  357. inventoryOptions[2] = "Gift";
  358. }
  359.  
  360. if(id == 6833) {
  361. name = "Loyalty Mystery Box";
  362. inventoryOptions[1] = "Open";
  363. inventoryOptions[2] = "Gift";
  364. }
  365.  
  366. if(id == 1505) {
  367. name = "Obelisk destination scroll";
  368. }
  369.  
  370. if(id == 4067) {
  371. name = "Vote ticket";
  372. }
  373.  
  374. if(id == 10834) {
  375. name = "Dice bag";
  376. inventoryOptions[0] = "Roll 4-sided";
  377. inventoryOptions[1] = "Roll 12-sided";
  378. inventoryOptions[2] = "Roll 100-sided";
  379. }
  380.  
  381. if (id == 9477) {
  382. name = "Coinbox";
  383. inventoryOptions[0] = "Open";
  384. stackable = false;
  385. tradeable = true;
  386. }
  387.  
  388. if (id == 3455 || id == 3457 || id == 3458) {
  389. name = "Clue key";
  390. inventoryOptions[3] = "Check-Hint";
  391. }
  392.  
  393. if(id == 786) {
  394. name = "Item Upgrade Scroll";
  395. }
  396.  
  397. if(id == 19625) {
  398. name = "Home teleport";
  399. }
  400. if(id == 8007) {
  401. inventoryOptions[1] = null;
  402. }
  403. if(id >= 1567 && id <= 1572)
  404. name = "Overgrown cat";
  405. /* Quick option for repairing all broken items */
  406. if(name.endsWith("(broken)"))
  407. inventoryOptions[0] = "Fix";
  408. if(id == 11169) {
  409. name = World.type.getWorldName() + " Herald";
  410. inventoryOptions[0] = "View-updates";
  411. inventoryOptions[1] = null;
  412. inventoryOptions[4] = "Destroy";
  413. }
  414. if(id == 12746 || (id >= 12748 && id <= 12756)) {
  415. inventoryOptions[0] = "Info";
  416. inventoryOptions[1] = "Redeem";
  417. }
  418. if(id == 5023) {
  419. name = "Tournament ticket";
  420. inventoryOptions[0] = "Read";
  421. stackable = true;
  422. }
  423. if (World.isPVP()) {
  424. if (id == 12810) {
  425. name = "Contender's helm";
  426. }
  427. if (id == 12811) {
  428. name = "Contender's platebody";
  429. }
  430. if (id == 12812) {
  431. name = "Contender's platelegs";
  432. }
  433. if (id == 12813) {
  434. name = "Champion's helm";
  435. }
  436. if (id == 12814) {
  437. name = "Champion's platebody";
  438. }
  439. if (id == 12815) {
  440. name = "Champion's platelegs";
  441. }
  442. if (id == 20792) {
  443. name = "Legend's helm";
  444. }
  445. if (id == 20794) {
  446. name = "Legend's platebody";
  447. }
  448. if (id == 20796) {
  449. name = "Legend's platelegs";
  450. }
  451. }
  452. if(id == 21532) {
  453. name = "Fragments";
  454. }
  455. if(id == 607) {
  456. name = "Rare Drop Scroll";
  457. inventoryOptions[0] = "Activate";
  458. }
  459. if(id == 608) {
  460. name = "Pet Drop Scroll";
  461. inventoryOptions[0] = "Activate";
  462. }
  463. if(id == 6758) {
  464. name = "Bonus Exp Scroll";
  465. inventoryOptions[0] = "Activate";
  466. }
  467. if(id == 7671)
  468. name += " (red)";
  469. if (id == 7673)
  470. name += " (blue)";
  471.  
  472. if(id == 2730) {
  473. name = "Wilderness Reward Box (small)";
  474. inventoryOptions[0] = "Open";
  475. inventoryOptions[1] = null;
  476. }
  477.  
  478. if(id == 2732) {
  479. name = "Wilderness Reward Box (medium)";
  480. inventoryOptions[0] = "Open";
  481. inventoryOptions[1] = null;
  482. }
  483.  
  484. if(id == 2734) {
  485. name = "Wilderness Reward Box (large)";
  486. inventoryOptions[0] = "Open";
  487. inventoryOptions[1] = null;
  488. }
  489.  
  490. if(id == 2736) {
  491. name = "Wilderness Reward Box (giant)";
  492. inventoryOptions[0] = "Open";
  493. inventoryOptions[1] = null;
  494. }
  495.  
  496. if(id == 13215) {
  497. name = "Bloody Token";
  498. stackable = true;
  499. }
  500.  
  501. if(id == 22330) {
  502. name = "PVP Armour Mystery Box";
  503. inventoryOptions[0] = "Open";
  504. inventoryOptions[1] = "Gift";
  505. }
  506.  
  507. if(World.isPVP()) {
  508. if (id == 13329 || id == 13331 || id == 21776 || id == 13333 ||
  509. id == 21780 || id == 13335 || id == 21784 || id == 13337 ||
  510. id == 21898 || id == 20760 || id == 21285) {
  511. inventoryOptions[2] = "Revert";
  512. }
  513. }
  514.  
  515. if(id == 3606) {
  516. name = "Bloody key (easy)";
  517. }
  518.  
  519. if(id == 3608) {
  520. name = "Bloody key (medium)";
  521. }
  522.  
  523. if(id == 7297) {
  524. name = "Bloody key (hard)";
  525. }
  526.  
  527. if(id == 11918) {
  528. name = "Santa Outfit Box";
  529. inventoryOptions[0] = "Open";
  530. }
  531.  
  532. if(id == 12897) {
  533. name = "Anti-Santa Outfit Box";
  534. inventoryOptions[0] = "Open";
  535. }
  536.  
  537. if(id == 22816 || id == 22817) {
  538. inventoryOptions[4] = "Destroy";
  539. }
  540.  
  541. if(id == 21227) {
  542. name = "Easter Egg";
  543. inventoryOptions[0] = "Open";
  544. }
  545.  
  546. if(id == 11028) {
  547. stackable = true;
  548. }
  549.  
  550. if(id == 8943) {
  551. name = "Wilderness key (1M OSRS)";
  552. inventoryOptions[0] = "Information";
  553. inventoryOptions[3] = null;
  554. inventoryOptions[4] = "Destroy";
  555. }
  556.  
  557. if(id == 8944) {
  558. name = "Wilderness key (5M OSRS)";
  559. inventoryOptions[0] = "Information";
  560. inventoryOptions[3] = null;
  561. inventoryOptions[4] = "Destroy";
  562. }
  563.  
  564. if(id == 8945) {
  565. name = "Wilderness key (10M OSRS)";
  566. inventoryOptions[0] = "Information";
  567. inventoryOptions[3] = null;
  568. inventoryOptions[4] = "Destroy";
  569. }
  570.  
  571. if(id == 8946) {
  572. name = "Wilderness key (25M OSRS)";
  573. inventoryOptions[0] = "Information";
  574. inventoryOptions[3] = null;
  575. inventoryOptions[4] = "Destroy";
  576. }
  577.  
  578. if(id == 8947) {
  579. name = "Wilderness key (50M OSRS)";
  580. inventoryOptions[0] = "Information";
  581. inventoryOptions[3] = null;
  582. inventoryOptions[4] = "Destroy";
  583. }
  584.  
  585. if(id == 8948) {
  586. name = "Wilderness key (100M OSRS)";
  587. inventoryOptions[0] = "Information";
  588. inventoryOptions[3] = null;
  589. inventoryOptions[4] = "Destroy";
  590. }
  591. }
  592.  
  593. private void decode(InBuffer buffer, int opcode) {
  594. if(opcode == 1)
  595. inventoryModel = buffer.readUnsignedShort();
  596. else if(opcode == 2)
  597. name = buffer.readString();
  598. else if(opcode == 4)
  599. zoom2d = buffer.readUnsignedShort();
  600. else if(opcode == 5)
  601. xan2d = buffer.readUnsignedShort();
  602. else if(opcode == 6)
  603. yan2d = buffer.readUnsignedShort();
  604. else if(opcode == 7) {
  605. xof2d = buffer.readUnsignedShort();
  606. if(xof2d > 32767)
  607. xof2d -= 65536;
  608. } else if(opcode == 8) {
  609. yof2d = buffer.readUnsignedShort();
  610. if(yof2d > 32767)
  611. yof2d -= 65536;
  612. } else if(opcode == 11)
  613. stackable = true;
  614. else if(opcode == 12)
  615. value = buffer.readInt();
  616. else if(opcode == 16)
  617. members = true;
  618. else if(opcode == 23) {
  619. anInt1504 = buffer.readUnsignedShort();
  620. maleOffset = buffer.readUnsignedByte();
  621. } else if(opcode == 24)
  622. anInt1493 = buffer.readUnsignedShort();
  623. else if(opcode == 25) {
  624. anInt1467 = buffer.readUnsignedShort();
  625. femaleOffset = buffer.readUnsignedByte();
  626. } else if(opcode == 26)
  627. anInt1496 = buffer.readUnsignedShort();
  628. else if(opcode >= 30 && opcode < 35) {
  629. groundOptions[opcode - 30] = buffer.readString();
  630. if(groundOptions[opcode - 30].equalsIgnoreCase("Hidden"))
  631. groundOptions[opcode - 30] = null;
  632. } else if(opcode >= 35 && opcode < 40)
  633. inventoryOptions[opcode - 35] = buffer.readString();
  634. else if(opcode == 40) {
  635. int i_0_ = buffer.readUnsignedByte();
  636. colorFind = new short[i_0_];
  637. colorReplace = new short[i_0_];
  638. for(int i_1_ = 0; i_1_ < i_0_; i_1_++) {
  639. colorFind[i_1_] = (short) buffer.readUnsignedShort();
  640. colorReplace[i_1_] = (short) buffer.readUnsignedShort();
  641. }
  642. } else if(opcode == 41) {
  643. int i_2_ = buffer.readUnsignedByte();
  644. textureFind = new short[i_2_];
  645. textureReplace = new short[i_2_];
  646. for(int i_3_ = 0; i_3_ < i_2_; i_3_++) {
  647. textureFind[i_3_] = (short) buffer.readUnsignedShort();
  648. textureReplace[i_3_] = (short) buffer.readUnsignedShort();
  649. }
  650. } else if(opcode == 65)
  651. grandExchange = true;
  652. else if(opcode == 78)
  653. anInt1498 = buffer.readUnsignedShort();
  654. else if(opcode == 79)
  655. anInt1499 = buffer.readUnsignedShort();
  656. else if(opcode == 90)
  657. maleHeadModel = buffer.readUnsignedShort();
  658. else if(opcode == 91)
  659. femaleHeadModel = buffer.readUnsignedShort();
  660. else if(opcode == 92)
  661. anInt1501 = buffer.readUnsignedShort();
  662. else if(opcode == 93)
  663. anInt1503 = buffer.readUnsignedShort();
  664. else if(opcode == 95)
  665. zan2d = buffer.readUnsignedShort();
  666. else if(opcode == 97)
  667. notedId = buffer.readUnsignedShort();
  668. else if(opcode == 98)
  669. notedTemplateId = buffer.readUnsignedShort();
  670. else if(opcode >= 100 && opcode < 110) {
  671. if(anIntArray1497 == null) {
  672. anIntArray1497 = new int[10];
  673. anIntArray1505 = new int[10];
  674. }
  675. anIntArray1497[opcode - 100] = buffer.readUnsignedShort();
  676. anIntArray1505[opcode - 100] = buffer.readUnsignedShort();
  677. } else if(opcode == 110)
  678. resizeX = buffer.readUnsignedShort();
  679. else if(opcode == 111)
  680. resizeY = buffer.readUnsignedShort();
  681. else if(opcode == 112)
  682. resizeZ = buffer.readUnsignedShort();
  683. else if(opcode == 113)
  684. ambient = buffer.readByte();
  685. else if(opcode == 114)
  686. contrast = buffer.readByte() * 5;
  687. else if(opcode == 115)
  688. team = buffer.readUnsignedByte();
  689. else if(opcode == 139)
  690. anInt1489 = buffer.readUnsignedShort();
  691. else if(opcode == 140)
  692. anInt1515 = buffer.readUnsignedShort();
  693. else if(opcode == 148)
  694. placeholderMainId = buffer.readUnsignedShort();
  695. else if(opcode == 149)
  696. placeholderTemplateId = buffer.readUnsignedShort();
  697. else if(opcode == 249) {
  698. int size = buffer.readUnsignedByte();
  699. if(attributes == null)
  700. attributes = new HashMap<>();
  701. for(int i = 0; i < size; i++) {
  702. boolean stringType = buffer.readUnsignedByte() == 1;
  703. int key = buffer.readMedium();
  704. if(stringType)
  705. attributes.put(key, buffer.readString());
  706. else
  707. attributes.put(key, buffer.readInt());
  708. }
  709. }
  710. }
  711.  
  712. public int getOption(String... options) {
  713. if(inventoryOptions != null) {
  714. for(String s : options) {
  715. for(int i = 0; i < inventoryOptions.length; i++) {
  716. String option = inventoryOptions[i];
  717. if(s.equalsIgnoreCase(option))
  718. return i + 1;
  719. }
  720. }
  721. }
  722. return -1;
  723. }
  724.  
  725. public int getGroundOption(String... options) {
  726. if(groundOptions != null) {
  727. for(String s : options) {
  728. for(int i = 0; i < groundOptions.length; i++) {
  729. String option = groundOptions[i];
  730. if(s.equalsIgnoreCase(option))
  731. return i + 1;
  732. }
  733. }
  734. }
  735. return -1;
  736. }
  737.  
  738. public boolean hasOption(String... options) {
  739. return getOption(options) != -1;
  740. }
  741.  
  742. public boolean isNote() {
  743. return notedId != -1 && notedTemplateId != -1;
  744. }
  745.  
  746. public ItemDef fromNote() {
  747. return LOADED[notedId];
  748. }
  749.  
  750. public boolean isPlaceholder() {
  751. return placeholderMainId != -1 && placeholderTemplateId != -1;
  752. }
  753.  
  754. public boolean hasPlaceholder() {
  755. return placeholderMainId != -1 && placeholderTemplateId == -1;
  756. }
  757.  
  758. public int bankWithdrawListener(Player player, Item item, int amount) {
  759. if (bankWithdrawListener != null)
  760. return bankWithdrawListener.withdraw(player, item, amount);
  761. return 0;
  762. }
  763.  
  764. /**
  765. * Predicate
  766. */
  767.  
  768. @FunctionalInterface
  769. public interface ItemDefPredicate {
  770.  
  771. boolean accept(ItemDef def, String name);
  772.  
  773. default boolean test(ItemDef def) {
  774. return accept(def, def.name.toLowerCase());
  775. }
  776.  
  777. }
  778.  
  779. @FunctionalInterface
  780. public interface BankWithdrawListener {
  781.  
  782. int withdraw(Player player, Item item, int amount);
  783.  
  784. }
  785.  
  786. /**
  787. * u brought this on urself tbh
  788. */
  789. private OutgoingHitListener postTargetDamageListener;
  790. private OutgoingHitListener preTargetDefendListener;;
  791. private OutgoingHitListener postTargetDefendListener;
  792. private IncomingHitListener postDamageListener;
  793. private IncomingHitListener preDefendListener;
  794. private BiConsumer<Player, Item> onTick;
  795. private Consumer<Item> onDrop;
  796.  
  797.  
  798. /**
  799. * Adds a listener for when a player with this item equipped <b>deals damage</b>.
  800. */
  801. public void addPostTargetDamageListener(OutgoingHitListener listener) {
  802. if (postTargetDamageListener == null)
  803. postTargetDamageListener = listener;
  804. else
  805. postTargetDamageListener = postTargetDamageListener.andThen(listener);
  806. }
  807.  
  808. public void postTargetDamage(Player player, Item item, Hit hit, Entity entity) {
  809. if (postTargetDamageListener != null)
  810. postTargetDamageListener.accept(player, item, hit, entity);
  811. }
  812.  
  813. /**
  814. * Adds a listener for when a player with this item equipped <b>takes a hite</b>.
  815. */
  816. public void addPostDamageListener(IncomingHitListener event) {
  817. if (postDamageListener == null)
  818. postDamageListener = event;
  819. else
  820. postDamageListener = postDamageListener.andThen(event);
  821. }
  822.  
  823. public void postDamage(Player player, Item item, Hit hit) {
  824. if (postDamageListener != null)
  825. postDamageListener.accept(player, item, hit);
  826. }
  827.  
  828. /**
  829. * Adds a listener for when a player with this item equipped <b>is defending against a hit</b>.
  830. */
  831.  
  832. public void addPreDefendListener(IncomingHitListener event) {
  833. if (preDefendListener == null)
  834. preDefendListener = event;
  835. else
  836. preDefendListener = preDefendListener.andThen(event);
  837. }
  838.  
  839. public void preDefend(Player player, Item item, Hit hit) {
  840. if (preDefendListener != null)
  841. preDefendListener.accept(player, item, hit);
  842. }
  843.  
  844. /**
  845. * Adds a listener for when a player with this item equipped <b>is attacking but the hit hasn't yet been dealt.</b>.
  846. */
  847.  
  848. public void addPreTargetDefendListener(OutgoingHitListener event) {
  849. if (preTargetDefendListener == null)
  850. preTargetDefendListener = event;
  851. else
  852. preTargetDefendListener = preTargetDefendListener.andThen(event);
  853. }
  854.  
  855. public void preTargetDefend(Player player, Item item, Hit hit, Entity victim) {
  856. if (preTargetDefendListener != null)
  857. preTargetDefendListener.accept(player, item, hit, victim);
  858. }
  859.  
  860.  
  861. public void addPostTargetDefendListener(OutgoingHitListener event) {
  862. if (postTargetDefendListener == null)
  863. postTargetDefendListener = event;
  864. else
  865. postTargetDefendListener = postTargetDefendListener.andThen(event);
  866. }
  867.  
  868. public void postTargetDefend(Player player, Item item, Hit hit, Entity victim) {
  869. if (postTargetDefendListener != null)
  870. postTargetDefendListener.accept(player, item, hit, victim);
  871. }
  872.  
  873. /**
  874. * Adds a listener on each tick while the player has this item equipped.
  875. */
  876. public void addOnTickEvent(BiConsumer<Player, Item> event) {
  877. if (onTick == null)
  878. onTick = event;
  879. else
  880. onTick = onTick.andThen(event);
  881. }
  882.  
  883. public void onTick(Player player, Item item) {
  884. if (onTick != null)
  885. onTick.accept(player, item);
  886. }
  887.  
  888. /**
  889. * Adds a listener for when a grounditem for this item is created
  890. */
  891. public void addOnDropEvent(Consumer<Item> event) {
  892. if (onDrop == null)
  893. onDrop = event;
  894. else
  895. onDrop = onDrop.andThen(event);
  896. }
  897.  
  898. public void onDrop(Item item) {
  899. if (onDrop != null)
  900. onDrop.accept(item);
  901. }
  902.  
  903.  
  904. }
RAW Paste Data