Advertisement
Guest User

Untitled

a guest
Dec 9th, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.66 KB | None | 0 0
  1. /*
  2. * Copyright (c) 2018, Adam <Adam@sigterm.info>
  3. * Copyright (c) 2018, Kamiel
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  19. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. package net.runelite.client.plugins.menuentryswapper;
  27.  
  28. import com.google.common.collect.ImmutableSet;
  29. import com.google.inject.Provides;
  30. import java.util.Set;
  31. import javax.inject.Inject;
  32. import lombok.Getter;
  33. import lombok.Setter;
  34. import net.runelite.api.Client;
  35. import net.runelite.api.GameState;
  36. import net.runelite.api.ItemComposition;
  37. import net.runelite.api.MenuAction;
  38. import net.runelite.api.MenuEntry;
  39. import net.runelite.api.NPC;
  40. import net.runelite.api.events.ConfigChanged;
  41. import net.runelite.api.events.FocusChanged;
  42. import net.runelite.api.events.MenuEntryAdded;
  43. import net.runelite.api.events.MenuOpened;
  44. import net.runelite.api.events.MenuOptionClicked;
  45. import net.runelite.api.events.PostItemComposition;
  46. import net.runelite.api.events.WidgetMenuOptionClicked;
  47. import net.runelite.api.widgets.WidgetInfo;
  48. import net.runelite.client.config.ConfigManager;
  49. import net.runelite.client.eventbus.Subscribe;
  50. import net.runelite.client.game.ItemVariationMapping;
  51. import net.runelite.client.input.KeyManager;
  52. import net.runelite.client.menus.MenuManager;
  53. import net.runelite.client.menus.WidgetMenuOption;
  54. import net.runelite.client.plugins.Plugin;
  55. import net.runelite.client.plugins.PluginDescriptor;
  56. import net.runelite.client.util.Text;
  57. import org.apache.commons.lang3.ArrayUtils;
  58.  
  59. import net.runelite.api.events.*;
  60. import static net.runelite.api.Skill.THIEVING;
  61. import static net.runelite.api.Skill.MAGIC;
  62. import static net.runelite.api.Skill.CONSTRUCTION;
  63.  
  64. import java.util.Arrays;
  65.  
  66. @PluginDescriptor(
  67. name = "Menu Entry Swapper",
  68. description = "Change the default option that is displayed when hovering over objects",
  69. tags = {"npcs", "inventory", "items", "objects"},
  70. enabledByDefault = false
  71. )
  72. public class MenuEntrySwapperPlugin extends Plugin
  73. {
  74. private static final String CONFIGURE = "Configure";
  75. private static final String SAVE = "Save";
  76. private static final String RESET = "Reset";
  77. private static final String MENU_TARGET = "Shift-click";
  78.  
  79. private static final String CONFIG_GROUP = "shiftclick";
  80. private static final String ITEM_KEY_PREFIX = "item_";
  81.  
  82. private static final WidgetMenuOption FIXED_INVENTORY_TAB_CONFIGURE = new WidgetMenuOption(CONFIGURE,
  83. MENU_TARGET, WidgetInfo.FIXED_VIEWPORT_INVENTORY_TAB);
  84.  
  85. private static final WidgetMenuOption FIXED_INVENTORY_TAB_SAVE = new WidgetMenuOption(SAVE,
  86. MENU_TARGET, WidgetInfo.FIXED_VIEWPORT_INVENTORY_TAB);
  87.  
  88. private static final WidgetMenuOption RESIZABLE_INVENTORY_TAB_CONFIGURE = new WidgetMenuOption(CONFIGURE,
  89. MENU_TARGET, WidgetInfo.RESIZABLE_VIEWPORT_INVENTORY_TAB);
  90.  
  91. private static final WidgetMenuOption RESIZABLE_INVENTORY_TAB_SAVE = new WidgetMenuOption(SAVE,
  92. MENU_TARGET, WidgetInfo.RESIZABLE_VIEWPORT_INVENTORY_TAB);
  93.  
  94. private static final WidgetMenuOption RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_CONFIGURE = new WidgetMenuOption(CONFIGURE,
  95. MENU_TARGET, WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_INVENTORY_TAB);
  96.  
  97. private static final WidgetMenuOption RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_SAVE = new WidgetMenuOption(SAVE,
  98. MENU_TARGET, WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_INVENTORY_TAB);
  99.  
  100. @Inject
  101. private Client client;
  102.  
  103. @Inject
  104. private MenuEntrySwapperConfig config;
  105.  
  106. @Inject
  107. private ShiftClickInputListener inputListener;
  108.  
  109. @Inject
  110. private ConfigManager configManager;
  111.  
  112. @Inject
  113. private KeyManager keyManager;
  114.  
  115. @Inject
  116. private MenuManager menuManager;
  117.  
  118. @Getter
  119. private boolean configuringShiftClick = false;
  120.  
  121. @Setter
  122. private boolean shiftModifier = false;
  123.  
  124. @Provides
  125. MenuEntrySwapperConfig provideConfig(ConfigManager configManager)
  126. {
  127. return configManager.getConfig(MenuEntrySwapperConfig.class);
  128. }
  129.  
  130. @Override
  131. public void startUp()
  132. {
  133. if (config.shiftClickCustomization())
  134. {
  135. enableCustomization();
  136. }
  137. }
  138.  
  139. @Override
  140. public void shutDown()
  141. {
  142. disableCustomization();
  143. }
  144.  
  145. @Subscribe
  146. public void onConfigChanged(ConfigChanged event)
  147. {
  148. if (event.getKey().equals("shiftClickCustomization"))
  149. {
  150. if (config.shiftClickCustomization())
  151. {
  152. enableCustomization();
  153. }
  154. else
  155. {
  156. disableCustomization();
  157. }
  158. }
  159. }
  160.  
  161. private Integer getSwapConfig(int itemId)
  162. {
  163. itemId = ItemVariationMapping.map(itemId);
  164. String config = configManager.getConfiguration(CONFIG_GROUP, ITEM_KEY_PREFIX + itemId);
  165. if (config == null || config.isEmpty())
  166. {
  167. return null;
  168. }
  169.  
  170. return Integer.parseInt(config);
  171. }
  172.  
  173. private void setSwapConfig(int itemId, int index)
  174. {
  175. itemId = ItemVariationMapping.map(itemId);
  176. configManager.setConfiguration(CONFIG_GROUP, ITEM_KEY_PREFIX + itemId, index);
  177. }
  178.  
  179. private void unsetSwapConfig(int itemId)
  180. {
  181. configManager.unsetConfiguration(CONFIG_GROUP, ITEM_KEY_PREFIX + itemId);
  182. }
  183.  
  184. private void enableCustomization()
  185. {
  186. keyManager.registerKeyListener(inputListener);
  187. refreshShiftClickCustomizationMenus();
  188. }
  189.  
  190. private void disableCustomization()
  191. {
  192. keyManager.unregisterKeyListener(inputListener);
  193. removeShiftClickCustomizationMenus();
  194. configuringShiftClick = false;
  195. }
  196.  
  197. @Subscribe
  198. public void onWidgetMenuOptionClicked(WidgetMenuOptionClicked event)
  199. {
  200. if (event.getWidget() == WidgetInfo.FIXED_VIEWPORT_INVENTORY_TAB
  201. || event.getWidget() == WidgetInfo.RESIZABLE_VIEWPORT_INVENTORY_TAB
  202. || event.getWidget() == WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_INVENTORY_TAB)
  203. {
  204. configuringShiftClick = event.getMenuOption().equals(CONFIGURE) && Text.removeTags(event.getMenuTarget()).equals(MENU_TARGET);
  205. refreshShiftClickCustomizationMenus();
  206. }
  207. }
  208.  
  209. @Subscribe
  210. public void onMenuOpened(MenuOpened event)
  211. {
  212. if (!configuringShiftClick)
  213. {
  214. return;
  215. }
  216.  
  217. MenuEntry firstEntry = event.getFirstEntry();
  218. if (firstEntry == null)
  219. {
  220. return;
  221. }
  222.  
  223. int widgetId = firstEntry.getParam1();
  224. if (widgetId != WidgetInfo.INVENTORY.getId())
  225. {
  226. return;
  227. }
  228.  
  229. int itemId = firstEntry.getIdentifier();
  230. if (itemId == -1)
  231. {
  232. return;
  233. }
  234.  
  235. ItemComposition itemComposition = client.getItemDefinition(itemId);
  236. String itemName = itemComposition.getName();
  237. String option = "Use";
  238. int shiftClickActionindex = itemComposition.getShiftClickActionIndex();
  239. String[] inventoryActions = itemComposition.getInventoryActions();
  240.  
  241. if (shiftClickActionindex >= 0 && shiftClickActionindex < inventoryActions.length)
  242. {
  243. option = inventoryActions[shiftClickActionindex];
  244. }
  245.  
  246. MenuEntry[] entries = event.getMenuEntries();
  247.  
  248. for (MenuEntry entry : entries)
  249. {
  250. if (itemName.equals(Text.removeTags(entry.getTarget())))
  251. {
  252. entry.setType(MenuAction.RUNELITE.getId());
  253.  
  254. if (option.equals(entry.getOption()))
  255. {
  256. entry.setOption("* " + option);
  257. }
  258. }
  259. }
  260.  
  261. final MenuEntry resetShiftClickEntry = new MenuEntry();
  262. resetShiftClickEntry.setOption(RESET);
  263. resetShiftClickEntry.setTarget(MENU_TARGET);
  264. resetShiftClickEntry.setIdentifier(itemId);
  265. resetShiftClickEntry.setParam1(widgetId);
  266. resetShiftClickEntry.setType(MenuAction.RUNELITE.getId());
  267. client.setMenuEntries(ArrayUtils.addAll(entries, resetShiftClickEntry));
  268. }
  269.  
  270. @Subscribe
  271. public void onMenuOptionClicked(MenuOptionClicked event)
  272. {
  273. if (event.getMenuAction() != MenuAction.RUNELITE || event.getWidgetId() != WidgetInfo.INVENTORY.getId())
  274. {
  275. return;
  276. }
  277.  
  278. int itemId = event.getId();
  279.  
  280. if (itemId == -1)
  281. {
  282. return;
  283. }
  284.  
  285. String option = event.getMenuOption();
  286. String target = event.getMenuTarget();
  287. ItemComposition itemComposition = client.getItemDefinition(itemId);
  288.  
  289. if (option.equals(RESET) && target.equals(MENU_TARGET))
  290. {
  291. unsetSwapConfig(itemId);
  292. itemComposition.resetShiftClickActionIndex();
  293. return;
  294. }
  295.  
  296. if (!itemComposition.getName().equals(Text.removeTags(target)))
  297. {
  298. return;
  299. }
  300.  
  301. int index = -1;
  302. boolean valid = false;
  303.  
  304. if (option.equals("Use")) //because "Use" is not in inventoryActions
  305. {
  306. valid = true;
  307. }
  308. else
  309. {
  310. String[] inventoryActions = itemComposition.getInventoryActions();
  311.  
  312. for (index = 0; index < inventoryActions.length; index++)
  313. {
  314. if (option.equals(inventoryActions[index]))
  315. {
  316. valid = true;
  317. break;
  318. }
  319. }
  320. }
  321.  
  322. if (valid)
  323. {
  324. setSwapConfig(itemId, index);
  325. itemComposition.setShiftClickActionIndex(index);
  326. }
  327. }
  328.  
  329.  
  330. int cachedXp = 0;
  331. boolean knockOutFirst = true;
  332. boolean hasPickpocketed = false;
  333.  
  334. int cachedMagic = 0;
  335. int cachedCons = 0;
  336. int timesBuilt = 0;
  337. boolean castHomeTele = false;
  338.  
  339. @Subscribe
  340. public void onExperienceChanged(ExperienceChanged event)
  341. {
  342. if (event.getSkill() == THIEVING)
  343. {
  344. int thievingXp = client.getSkillExperience(THIEVING);
  345.  
  346. if (thievingXp <= cachedXp)
  347. {
  348. return;
  349. }
  350.  
  351. if (cachedXp == 0)
  352. {
  353. // this is the initial xp sent on login
  354. cachedXp = thievingXp;
  355. return;
  356. }
  357.  
  358. int xpDrop = thievingXp - cachedXp;
  359. if (xpDrop < 50)
  360. {
  361. // successful knockout
  362. knockOutFirst = false;
  363. hasPickpocketed = false;
  364.  
  365. }
  366. else
  367. {
  368. // successful pickpocket
  369. if (hasPickpocketed)
  370. {
  371. // knock out again next
  372. knockOutFirst = true;
  373. hasPickpocketed = false;
  374. }
  375. else
  376. {
  377. hasPickpocketed = true;
  378. }
  379. }
  380.  
  381. cachedXp = thievingXp;
  382. }
  383. else if(event.getSkill() == MAGIC)
  384. {
  385. int mageXp = client.getSkillExperience(MAGIC);
  386.  
  387. if (mageXp <= cachedMagic)
  388. {
  389. return;
  390. }
  391.  
  392. if (cachedMagic == 0)
  393. {
  394. // this is the initial xp sent on login
  395. cachedMagic = mageXp;
  396. return;
  397. }
  398. int xpDrop = mageXp - cachedMagic;
  399. if (xpDrop > 0)
  400. {
  401. timesBuilt = 0;
  402. }
  403. }
  404. else if(event.getSkill() == CONSTRUCTION)
  405. {
  406. int consXp = client.getSkillExperience(CONSTRUCTION);
  407.  
  408. if (consXp <= cachedCons)
  409. {
  410. return;
  411. }
  412.  
  413. if (cachedCons == 0)
  414. {
  415. // this is the initial xp sent on login
  416. cachedCons = consXp;
  417. return;
  418. }
  419.  
  420. int xpDrop = consXp - cachedCons;
  421. if (xpDrop > 0 && timesBuilt < 7)
  422. {
  423. timesBuilt++;
  424. castHomeTele = true;
  425. }
  426. else if(xpDrop > 0)
  427. {
  428. timesBuilt = 0;
  429. castHomeTele = false;
  430. }
  431.  
  432. xpDrop = 0;
  433. cachedCons = consXp;
  434. }
  435.  
  436.  
  437. }
  438.  
  439.  
  440.  
  441. @Subscribe
  442. public void onMenuEntryAdded(MenuEntryAdded event)
  443. {
  444. if (client.getGameState() != GameState.LOGGED_IN)
  445. {
  446. return;
  447. }
  448.  
  449. int itemId = event.getIdentifier();
  450. String option = Text.removeTags(event.getOption()).toLowerCase();
  451. String target = Text.removeTags(event.getTarget()).toLowerCase();
  452.  
  453.  
  454.  
  455. if (option.equals("talk-to"))
  456. {
  457. if (config.swapPickpocket())
  458. {
  459. if (knockOutFirst)
  460. {
  461. swap("knock-out", option, target, true);
  462. swap("pickpocket", option, target, true);
  463. }
  464. else
  465. {
  466. swap("pickpocket", option, target, true);
  467. swap("knock-out", option, target, true);
  468. }
  469. }
  470.  
  471. if (config.swapPickpocket() && target.contains("h.a.m."))
  472. {
  473. swap("pickpocket", option, target, true);
  474. }
  475.  
  476. if (config.swapAbyssTeleport() && target.contains("mage of zamorak"))
  477. {
  478. swap("teleport", option, target, true);
  479. }
  480.  
  481. if (config.swapBank())
  482. {
  483. swap("bank", option, target, true);
  484. }
  485.  
  486. if (config.swapExchange())
  487. {
  488. swap("exchange", option, target, true);
  489. }
  490.  
  491. if (config.swapDarkMage())
  492. {
  493. swap("repairs", option, target, true);
  494. }
  495.  
  496. // make sure assignment swap is higher priority than trade swap for slayer masters
  497. if (config.swapAssignment())
  498. {
  499. swap("assignment", option, target, true);
  500. }
  501.  
  502. if (config.swapTrade())
  503. {
  504. swap("trade", option, target, true);
  505. swap("trade-with", option, target, true);
  506. }
  507.  
  508. if (config.claimSlime() && target.equals("robin"))
  509. {
  510. swap("claim-slime", option, target, true);
  511. }
  512.  
  513. if (config.swapTravel())
  514. {
  515. swap("travel", option, target, true);
  516. swap("pay-fare", option, target, true);
  517. swap("charter", option, target, true);
  518. swap("take-boat", option, target, true);
  519. swap("fly", option, target, true);
  520. swap("jatizso", option, target, true);
  521. swap("neitiznot", option, target, true);
  522. swap("rellekka", option, target, true);
  523. swap("follow", option, target, true);
  524. swap("transport", option, target, true);
  525. }
  526.  
  527. if (config.swapPay())
  528. {
  529. swap("pay", option, target, true);
  530. }
  531.  
  532. if (config.swapDecant())
  533. {
  534. swap("decant", option, target, true);
  535. }
  536.  
  537. if (config.swapQuick())
  538. {
  539. swap("quick-travel", option, target, true);
  540. }
  541. }
  542. else if(config.swapBuildOptions() && (target.equals("fencing") || target.equals("stone space")))
  543. {
  544. swapWalkHere("build", "walk here", target,true);
  545. }
  546. else if(config.swapBuildOptions() && (target.equals("attack stone") || target.equals("wooden fence")))
  547. {
  548. swapWalkHere("remove", "walk here", target, true);
  549. }
  550. else if(config.swapBuildOptions() && (target.equals("door hotspot") || target.equals("hedging") || target.equals("small plant") || target.equals("small plant 2")))
  551. {
  552. removeOptions(option, target, true);
  553. }
  554. else if(config.swapBuildOptions() && target.equals("razmire keelgan"))
  555. {
  556. swap("trade-builders-store", option, target, true);
  557. }
  558. else if(config.swapBuildOptions() && target.contains("morytania"))
  559. {
  560. swap("burgh teleport", option, target, true);
  561. }
  562. else if(config.swapBuildOptions() && target.equals("flamtaer bag") && castHomeTele)
  563. {
  564. swap("empty", option, target, true);
  565. }
  566. else if(config.swapBuildOptions() && option.equals("value"))
  567. {
  568. swap("buy 50", option, target, true);
  569. }
  570. else if(config.swapChop() && option.equals("chop down"))
  571. {
  572. swapWalkHere("walk here", option, "", true);
  573. }
  574. else if(config.marinsKitchen() && option.equals("take"))
  575. {
  576. swap("take-x", option, target, true);
  577. }
  578. else if(config.leftClickDismiss() && option.equals("talk to"))
  579. {
  580. swap("dismiss", option, target, true);
  581. }
  582. else if (config.swapTravel() && option.equals("pass") && target.equals("energy barrier"))
  583. {
  584. swap("pay-toll(2-ecto)", option, target, true);
  585. }
  586. else if (config.swapTravel() && option.equals("open") && target.equals("gate"))
  587. {
  588. swap("pay-toll(10gp)", option, target, true);
  589. }
  590. else if (config.swapTravel() && option.equals("inspect") && target.equals("trapdoor"))
  591. {
  592. swap("travel", option, target, true);
  593. }
  594. else if (config.swapHarpoon() && option.equals("cage"))
  595. {
  596. swap("harpoon", option, target, true);
  597. }
  598. else if (config.swapHarpoon() && (option.equals("big net") || option.equals("net")))
  599. {
  600. swap("harpoon", option, target, true);
  601. }
  602. else if (config.swapHomePortal() != HouseMode.ENTER && option.equals("enter"))
  603. {
  604. switch (config.swapHomePortal())
  605. {
  606. case HOME:
  607. swap("home", option, target, true);
  608. break;
  609. case BUILD_MODE:
  610. swap("build mode", option, target, true);
  611. break;
  612. case FRIENDS_HOUSE:
  613. swap("friend's house", option, target, true);
  614. break;
  615. }
  616. }
  617. else if (config.swapFairyRing() != FairyRingMode.OFF && config.swapFairyRing() != FairyRingMode.ZANARIS
  618. && (option.equals("zanaris") || option.equals("configure") || option.equals("tree")))
  619. {
  620. if (config.swapFairyRing() == FairyRingMode.LAST_DESTINATION)
  621. {
  622. swap("last-destination", option, target, false);
  623. }
  624. else if (config.swapFairyRing() == FairyRingMode.CONFIGURE)
  625. {
  626. swap("configure", option, target, false);
  627. }
  628. }
  629. else if (config.swapFairyRing() == FairyRingMode.ZANARIS && option.equals("tree"))
  630. {
  631. swap("zanaris", option, target, false);
  632. }
  633. else if (config.swapBoxTrap() && (option.equals("check") || option.equals("dismantle")))
  634. {
  635. swap("reset", option, target, true);
  636. }
  637. else if (config.swapBoxTrap() && option.equals("take"))
  638. {
  639. swap("lay", option, target, true);
  640. }
  641. else if (config.swapChase() && option.equals("pick-up"))
  642. {
  643. swap("chase", option, target, true);
  644. }
  645. else if (config.swapBirdhouseEmpty() && option.equals("interact") && target.contains("birdhouse"))
  646. {
  647. swap("empty", option, target, true);
  648. }
  649. else if (config.swapQuick() && option.equals("ring"))
  650. {
  651. swap("quick-start", option, target, true);
  652. }
  653. else if (config.swapQuick() && option.equals("pass"))
  654. {
  655. swap("quick-pass", option, target, true);
  656. swap("quick pass", option, target, true);
  657. }
  658. else if (config.swapAdmire() && option.equals("admire"))
  659. {
  660. swap("teleport", option, target, true);
  661. swap("spellbook", option, target, true);
  662. swap("perks", option, target, true);
  663. }
  664. else if (config.shiftClickCustomization() && shiftModifier && !option.equals("use"))
  665. {
  666. Integer customOption = getSwapConfig(itemId);
  667.  
  668. if (customOption != null && customOption == -1)
  669. {
  670. swap("use", option, target, true);
  671. }
  672. }
  673. // Put all item-related swapping after shift-click
  674. else if (config.swapTeleportItem() && option.equals("wear"))
  675. {
  676. swap("rub", option, target, true);
  677. swap("teleport", option, target, true);
  678. }
  679. else if (option.equals("wield"))
  680. {
  681. if (config.swapTeleportItem())
  682. {
  683. swap("teleport", option, target, true);
  684. }
  685. }
  686. else if (config.swapBones() && option.equals("bury"))
  687. {
  688. swap("use", option, target, true);
  689. }
  690. }
  691.  
  692. @Subscribe
  693. public void onPostItemComposition(PostItemComposition event)
  694. {
  695. ItemComposition itemComposition = event.getItemComposition();
  696. Integer option = getSwapConfig(itemComposition.getId());
  697.  
  698. if (option != null)
  699. {
  700. itemComposition.setShiftClickActionIndex(option);
  701. }
  702. }
  703.  
  704. @Subscribe
  705. public void onFocusChanged(FocusChanged event)
  706. {
  707. if (!event.isFocused())
  708. {
  709. shiftModifier = false;
  710. }
  711. }
  712.  
  713. private int searchIndex(MenuEntry[] entries, String option, String target, boolean strict)
  714. {
  715. for (int i = entries.length - 1; i >= 0; i--)
  716. {
  717. MenuEntry entry = entries[i];
  718. String entryOption = Text.removeTags(entry.getOption()).toLowerCase();
  719. String entryTarget = Text.removeTags(entry.getTarget()).toLowerCase();
  720.  
  721. if (strict)
  722. {
  723. if (entryOption.equals(option) && entryTarget.equals(target))
  724. {
  725. return i;
  726. }
  727. }
  728. else
  729. {
  730. if (entryOption.contains(option.toLowerCase()) && entryTarget.equals(target))
  731. {
  732. return i;
  733. }
  734. }
  735. }
  736.  
  737. return -1;
  738. }
  739.  
  740. private void swap(String optionA, String optionB, String target, boolean strict)
  741. {
  742. MenuEntry[] entries = client.getMenuEntries();
  743.  
  744. int idxA = searchIndex(entries, optionA, target, strict);
  745. int idxB = searchIndex(entries, optionB, target, strict);
  746.  
  747. if (idxA >= 0 && idxB >= 0)
  748. {
  749. MenuEntry entry = entries[idxA];
  750. entries[idxA] = entries[idxB];
  751. entries[idxB] = entry;
  752.  
  753. client.setMenuEntries(entries);
  754. }
  755. }
  756.  
  757. private void removeOptions(String option, String target, boolean strict)
  758. {
  759. MenuEntry[] entries = client.getMenuEntries();
  760.  
  761. MenuEntry[] tempEntries = new MenuEntry[1];
  762.  
  763. tempEntries[0] = entries[0];
  764.  
  765. client.setMenuEntries(tempEntries);
  766. }
  767.  
  768. private void swapWalkHere(String optionA, String optionB, String target, boolean strict)
  769. {
  770. MenuEntry[] entries = client.getMenuEntries();
  771.  
  772. int idxA = searchIndex(entries, optionA, target, strict);
  773. MenuEntry[] tempEntries = new MenuEntry[1];
  774. tempEntries[0] = entries[idxA];
  775.  
  776. client.setMenuEntries(tempEntries);
  777. }
  778.  
  779. private void removeShiftClickCustomizationMenus()
  780. {
  781. menuManager.removeManagedCustomMenu(FIXED_INVENTORY_TAB_CONFIGURE);
  782. menuManager.removeManagedCustomMenu(FIXED_INVENTORY_TAB_SAVE);
  783. menuManager.removeManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_CONFIGURE);
  784. menuManager.removeManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_SAVE);
  785. menuManager.removeManagedCustomMenu(RESIZABLE_INVENTORY_TAB_CONFIGURE);
  786. menuManager.removeManagedCustomMenu(RESIZABLE_INVENTORY_TAB_SAVE);
  787. }
  788.  
  789. private void refreshShiftClickCustomizationMenus()
  790. {
  791. removeShiftClickCustomizationMenus();
  792. if (configuringShiftClick)
  793. {
  794. menuManager.addManagedCustomMenu(FIXED_INVENTORY_TAB_SAVE);
  795. menuManager.addManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_SAVE);
  796. menuManager.addManagedCustomMenu(RESIZABLE_INVENTORY_TAB_SAVE);
  797. }
  798. else
  799. {
  800. menuManager.addManagedCustomMenu(FIXED_INVENTORY_TAB_CONFIGURE);
  801. menuManager.addManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_CONFIGURE);
  802. menuManager.addManagedCustomMenu(RESIZABLE_INVENTORY_TAB_CONFIGURE);
  803. }
  804. }
  805. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement