AdminElement.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.admincommandhandlers;
  20. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  21. import com.l2jserver.gameserver.model.Elementals;
  22. import com.l2jserver.gameserver.model.L2Object;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.itemcontainer.Inventory;
  25. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  26. import com.l2jserver.gameserver.network.SystemMessageId;
  27. import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  28. /**
  29. * This class handles following admin commands: - delete = deletes target
  30. * @version $Revision: 1.2.2.1.2.4 $ $Date: 2005/04/11 10:05:56 $
  31. */
  32. public class AdminElement implements IAdminCommandHandler
  33. {
  34. private static final String[] ADMIN_COMMANDS =
  35. {
  36. "admin_setlh",
  37. "admin_setlc",
  38. "admin_setll",
  39. "admin_setlg",
  40. "admin_setlb",
  41. "admin_setlw",
  42. "admin_setls"
  43. };
  44. @Override
  45. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  46. {
  47. int armorType = -1;
  48. if (command.startsWith("admin_setlh"))
  49. {
  50. armorType = Inventory.PAPERDOLL_HEAD;
  51. }
  52. else if (command.startsWith("admin_setlc"))
  53. {
  54. armorType = Inventory.PAPERDOLL_CHEST;
  55. }
  56. else if (command.startsWith("admin_setlg"))
  57. {
  58. armorType = Inventory.PAPERDOLL_GLOVES;
  59. }
  60. else if (command.startsWith("admin_setlb"))
  61. {
  62. armorType = Inventory.PAPERDOLL_FEET;
  63. }
  64. else if (command.startsWith("admin_setll"))
  65. {
  66. armorType = Inventory.PAPERDOLL_LEGS;
  67. }
  68. else if (command.startsWith("admin_setlw"))
  69. {
  70. armorType = Inventory.PAPERDOLL_RHAND;
  71. }
  72. else if (command.startsWith("admin_setls"))
  73. {
  74. armorType = Inventory.PAPERDOLL_LHAND;
  75. }
  76. if (armorType != -1)
  77. {
  78. try
  79. {
  80. String[] args = command.split(" ");
  81. byte element = Elementals.getElementId(args[1]);
  82. int value = Integer.parseInt(args[2]);
  83. if ((element < -1) || (element > 5) || (value < 0) || (value > 450))
  84. {
  85. activeChar.sendMessage("Usage: //setlh/setlc/setlg/setlb/setll/setlw/setls <element> <value>[0-450]");
  86. return false;
  87. }
  88. setElement(activeChar, element, value, armorType);
  89. }
  90. catch (Exception e)
  91. {
  92. activeChar.sendMessage("Usage: //setlh/setlc/setlg/setlb/setll/setlw/setls <element>[0-5] <value>[0-450]");
  93. return false;
  94. }
  95. }
  96. return true;
  97. }
  98. @Override
  99. public String[] getAdminCommandList()
  100. {
  101. return ADMIN_COMMANDS;
  102. }
  103. private void setElement(L2PcInstance activeChar, byte type, int value, int armorType)
  104. {
  105. // get the target
  106. L2Object target = activeChar.getTarget();
  107. if (target == null)
  108. {
  109. target = activeChar;
  110. }
  111. L2PcInstance player = null;
  112. if (target instanceof L2PcInstance)
  113. {
  114. player = (L2PcInstance) target;
  115. }
  116. else
  117. {
  118. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  119. return;
  120. }
  121. L2ItemInstance itemInstance = null;
  122. // only attempt to enchant if there is a weapon equipped
  123. L2ItemInstance parmorInstance = player.getInventory().getPaperdollItem(armorType);
  124. if ((parmorInstance != null) && (parmorInstance.getLocationSlot() == armorType))
  125. {
  126. itemInstance = parmorInstance;
  127. }
  128. if (itemInstance != null)
  129. {
  130. String old, current;
  131. Elementals element = itemInstance.getElemental(type);
  132. if (element == null)
  133. {
  134. old = "None";
  135. }
  136. else
  137. {
  138. old = element.toString();
  139. }
  140. // set enchant value
  141. player.getInventory().unEquipItemInSlot(armorType);
  142. if (type == -1)
  143. {
  144. itemInstance.clearElementAttr(type);
  145. }
  146. else
  147. {
  148. itemInstance.setElementAttr(type, value);
  149. }
  150. player.getInventory().equipItem(itemInstance);
  151. if (itemInstance.getElementals() == null)
  152. {
  153. current = "None";
  154. }
  155. else
  156. {
  157. current = itemInstance.getElemental(type).toString();
  158. }
  159. // send packets
  160. InventoryUpdate iu = new InventoryUpdate();
  161. iu.addModifiedItem(itemInstance);
  162. player.sendPacket(iu);
  163. // informations
  164. activeChar.sendMessage("Changed elemental power of " + player.getName() + "'s " + itemInstance.getItem().getName() + " from " + old + " to " + current + ".");
  165. if (player != activeChar)
  166. {
  167. player.sendMessage(activeChar.getName() + " has changed the elemental power of your " + itemInstance.getItem().getName() + " from " + old + " to " + current + ".");
  168. }
  169. }
  170. }
  171. }