Advertisement
Drazeal

Untitled

Feb 21st, 2021
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. /*
  2. * This file is part of the L2J Mobius project.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. package handlers.admincommandhandlers;
  18.  
  19. import java.util.Collection;
  20.  
  21. import org.l2jmobius.gameserver.handler.IAdminCommandHandler;
  22. import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
  23. import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
  24. import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
  25. import org.l2jmobius.gameserver.util.Util;
  26.  
  27. /**
  28. * @author Drazeal
  29. */
  30. public class AdminInventory implements IAdminCommandHandler
  31. {
  32. private static final String[] ADMIN_COMMANDS =
  33. {
  34. "admin_show_inventory",
  35. "admin_delete_item"
  36. };
  37.  
  38. @Override
  39. public boolean useAdminCommand(String command, PlayerInstance activeChar)
  40. {
  41. Object target = activeChar.getTarget();
  42. PlayerInstance player = null;
  43.  
  44. /* 25 */ if (activeChar.getTarget() == null)
  45. {
  46. /* */
  47. /* 27 */ activeChar.sendMessage("Select a target");
  48. /* 28 */ return false;
  49. /* */ }
  50. /* */
  51. /* */
  52. /* 32 */ if (target instanceof PlayerInstance)
  53. {
  54. /* 33 */ player = (PlayerInstance) target;
  55. /* */ }
  56. else
  57. {
  58. /* */
  59. /* 36 */ activeChar.sendMessage("Target need to be player noob.");
  60. /* 37 */ return false;
  61. /* */ }
  62. /* */
  63. /* */
  64. /* 41 */ if (command.startsWith(ADMIN_COMMANDS[0]))
  65. {
  66. /* */
  67. /* 43 */ if (command.length() > ADMIN_COMMANDS[0].length())
  68. /* */ {
  69. /* 45 */ String com = command.substring(ADMIN_COMMANDS[0].length() + 1);
  70. /* 46 */ if (Util.isDigit(com))
  71. /* */ {
  72. /* 48 */ showItemsPage(activeChar, Integer.parseInt(com));
  73. /* */
  74. /* */ }
  75. /* */ }
  76. /* */ else
  77. /* */ {
  78. /* 54 */ showItemsPage(activeChar, 0);
  79. /* */ }
  80. /* */
  81. /* 57 */ }
  82. else if (command.contains(ADMIN_COMMANDS[1]))
  83. {
  84. /* */
  85. /* 59 */ String val = command.substring(ADMIN_COMMANDS[1].length() + 1);
  86. /* */
  87. /* 61 */ player.destroyItem("GM Destroy", Integer.parseInt(val), player.getInventory().getItemByObjectId(Integer.parseInt(val)).getCount(), null, true);
  88. /* 62 */ showItemsPage(activeChar, 0);
  89. /* */ }
  90. /* */
  91. /* 65 */ return true;
  92. /* */ }
  93.  
  94. private static void showItemsPage(PlayerInstance activeChar, int page)
  95. {
  96. final PlayerInstance target = activeChar.getTarget().getActingPlayer();
  97.  
  98. final Collection<ItemInstance> items = target.getInventory().getItems();
  99.  
  100. int maxItemsPerPage = 10;
  101. int maxPages = items.size() / maxItemsPerPage;
  102. if (items.size() > (maxItemsPerPage * maxPages))
  103. {
  104. maxPages++;
  105. }
  106.  
  107. if (page > maxPages)
  108. {
  109. page = maxPages;
  110. }
  111.  
  112. int itemsStart = maxItemsPerPage * page;
  113. int itemsEnd = items.size();
  114. if ((itemsEnd - itemsStart) > maxItemsPerPage)
  115. {
  116. itemsEnd = itemsStart + maxItemsPerPage;
  117. }
  118.  
  119. final NpcHtmlMessage adminReply = new NpcHtmlMessage(0);
  120. adminReply.setFile(activeChar, "data/html/admin/inventory.htm");
  121. adminReply.replace("%PLAYER_NAME%", target.getName());
  122.  
  123. StringBuilder sbPages = new StringBuilder();
  124. for (int x = 0; x < maxPages; x++)
  125. {
  126. int pagenr = x + 1;
  127. sbPages.append("<td><button value=\"" + String.valueOf(pagenr) + "\" action=\"bypass -h admin_show_inventory " + String.valueOf(x) + "\" width=20 height=20 back=\\\"L2UI_ct1.button_df\\\" fore=\\\"L2UI_ct1.button_df\"></td>");
  128. }
  129.  
  130. adminReply.replace("%PAGES%", sbPages.toString());
  131.  
  132. StringBuilder sbItems = new StringBuilder();
  133.  
  134. for (ItemInstance item : items)
  135. {
  136.  
  137. sbItems.append("<tr><td><img src=\"" + item.getItem().getIcon() + "\" width=32 height=32></td>");
  138. sbItems.append("<td width=60>" + item.getName() + "</td>");
  139. sbItems.append("<td><button action=\"bypass -h admin_delete_item " + String.valueOf(item.getObjectId()) + "\" width=16 height=16 back=\"L2UI_ct1.Button_DF_Delete\" fore=\"L2UI_ct1.Button_DF_Delete\">" + "</td></tr>");
  140. }
  141.  
  142. adminReply.replace("%ITEMS%", sbItems.toString());
  143.  
  144. activeChar.sendPacket(adminReply);
  145. }
  146.  
  147. @Override
  148. public String[] getAdminCommandList()
  149. {
  150. return ADMIN_COMMANDS;
  151. }
  152.  
  153. }
  154.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement