Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This file is part of the L2J Mobius project.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package handlers.admincommandhandlers;
- import java.util.Collection;
- import org.l2jmobius.gameserver.handler.IAdminCommandHandler;
- import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
- import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
- import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
- import org.l2jmobius.gameserver.util.Util;
- /**
- * @author Drazeal
- */
- public class AdminInventory implements IAdminCommandHandler
- {
- private static final String[] ADMIN_COMMANDS =
- {
- "admin_show_inventory",
- "admin_delete_item"
- };
- @Override
- public boolean useAdminCommand(String command, PlayerInstance activeChar)
- {
- Object target = activeChar.getTarget();
- PlayerInstance player = null;
- /* 25 */ if (activeChar.getTarget() == null)
- {
- /* */
- /* 27 */ activeChar.sendMessage("Select a target");
- /* 28 */ return false;
- /* */ }
- /* */
- /* */
- /* 32 */ if (target instanceof PlayerInstance)
- {
- /* 33 */ player = (PlayerInstance) target;
- /* */ }
- else
- {
- /* */
- /* 36 */ activeChar.sendMessage("Target need to be player noob.");
- /* 37 */ return false;
- /* */ }
- /* */
- /* */
- /* 41 */ if (command.startsWith(ADMIN_COMMANDS[0]))
- {
- /* */
- /* 43 */ if (command.length() > ADMIN_COMMANDS[0].length())
- /* */ {
- /* 45 */ String com = command.substring(ADMIN_COMMANDS[0].length() + 1);
- /* 46 */ if (Util.isDigit(com))
- /* */ {
- /* 48 */ showItemsPage(activeChar, Integer.parseInt(com));
- /* */
- /* */ }
- /* */ }
- /* */ else
- /* */ {
- /* 54 */ showItemsPage(activeChar, 0);
- /* */ }
- /* */
- /* 57 */ }
- else if (command.contains(ADMIN_COMMANDS[1]))
- {
- /* */
- /* 59 */ String val = command.substring(ADMIN_COMMANDS[1].length() + 1);
- /* */
- /* 61 */ player.destroyItem("GM Destroy", Integer.parseInt(val), player.getInventory().getItemByObjectId(Integer.parseInt(val)).getCount(), null, true);
- /* 62 */ showItemsPage(activeChar, 0);
- /* */ }
- /* */
- /* 65 */ return true;
- /* */ }
- private static void showItemsPage(PlayerInstance activeChar, int page)
- {
- final PlayerInstance target = activeChar.getTarget().getActingPlayer();
- final Collection<ItemInstance> items = target.getInventory().getItems();
- int maxItemsPerPage = 10;
- int maxPages = items.size() / maxItemsPerPage;
- if (items.size() > (maxItemsPerPage * maxPages))
- {
- maxPages++;
- }
- if (page > maxPages)
- {
- page = maxPages;
- }
- int itemsStart = maxItemsPerPage * page;
- int itemsEnd = items.size();
- if ((itemsEnd - itemsStart) > maxItemsPerPage)
- {
- itemsEnd = itemsStart + maxItemsPerPage;
- }
- final NpcHtmlMessage adminReply = new NpcHtmlMessage(0);
- adminReply.setFile(activeChar, "data/html/admin/inventory.htm");
- adminReply.replace("%PLAYER_NAME%", target.getName());
- StringBuilder sbPages = new StringBuilder();
- for (int x = 0; x < maxPages; x++)
- {
- int pagenr = x + 1;
- 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>");
- }
- adminReply.replace("%PAGES%", sbPages.toString());
- StringBuilder sbItems = new StringBuilder();
- for (ItemInstance item : items)
- {
- sbItems.append("<tr><td><img src=\"" + item.getItem().getIcon() + "\" width=32 height=32></td>");
- sbItems.append("<td width=60>" + item.getName() + "</td>");
- 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>");
- }
- adminReply.replace("%ITEMS%", sbItems.toString());
- activeChar.sendPacket(adminReply);
- }
- @Override
- public String[] getAdminCommandList()
- {
- return ADMIN_COMMANDS;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement