AdminCreateItem.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 java.util.StringTokenizer;
  21. import com.l2jserver.gameserver.datatables.ItemTable;
  22. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  23. import com.l2jserver.gameserver.model.L2World;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.model.items.L2Item;
  26. /**
  27. * This class handles following admin commands: - itemcreate = show menu - create_item <id> [num] = creates num items with respective id, if num is not specified, assumes 1.
  28. * @version $Revision: 1.2.2.2.2.3 $ $Date: 2005/04/11 10:06:06 $
  29. */
  30. public class AdminCreateItem implements IAdminCommandHandler
  31. {
  32. private static final String[] ADMIN_COMMANDS =
  33. {
  34. "admin_itemcreate",
  35. "admin_create_item",
  36. "admin_create_coin",
  37. "admin_give_item_target",
  38. "admin_give_item_to_all"
  39. };
  40. @Override
  41. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  42. {
  43. if (command.equals("admin_itemcreate"))
  44. {
  45. AdminHtml.showAdminHtml(activeChar, "itemcreation.htm");
  46. }
  47. else if (command.startsWith("admin_create_item"))
  48. {
  49. try
  50. {
  51. String val = command.substring(17);
  52. StringTokenizer st = new StringTokenizer(val);
  53. if (st.countTokens() == 2)
  54. {
  55. String id = st.nextToken();
  56. int idval = Integer.parseInt(id);
  57. String num = st.nextToken();
  58. long numval = Long.parseLong(num);
  59. createItem(activeChar, activeChar, idval, numval);
  60. }
  61. else if (st.countTokens() == 1)
  62. {
  63. String id = st.nextToken();
  64. int idval = Integer.parseInt(id);
  65. createItem(activeChar, activeChar, idval, 1);
  66. }
  67. }
  68. catch (StringIndexOutOfBoundsException e)
  69. {
  70. activeChar.sendMessage("Usage: //create_item <itemId> [amount]");
  71. }
  72. catch (NumberFormatException nfe)
  73. {
  74. activeChar.sendMessage("Specify a valid number.");
  75. }
  76. AdminHtml.showAdminHtml(activeChar, "itemcreation.htm");
  77. }
  78. else if (command.startsWith("admin_create_coin"))
  79. {
  80. try
  81. {
  82. String val = command.substring(17);
  83. StringTokenizer st = new StringTokenizer(val);
  84. if (st.countTokens() == 2)
  85. {
  86. String name = st.nextToken();
  87. int idval = getCoinId(name);
  88. if (idval > 0)
  89. {
  90. String num = st.nextToken();
  91. long numval = Long.parseLong(num);
  92. createItem(activeChar, activeChar, idval, numval);
  93. }
  94. }
  95. else if (st.countTokens() == 1)
  96. {
  97. String name = st.nextToken();
  98. int idval = getCoinId(name);
  99. createItem(activeChar, activeChar, idval, 1);
  100. }
  101. }
  102. catch (StringIndexOutOfBoundsException e)
  103. {
  104. activeChar.sendMessage("Usage: //create_coin <name> [amount]");
  105. }
  106. catch (NumberFormatException nfe)
  107. {
  108. activeChar.sendMessage("Specify a valid number.");
  109. }
  110. AdminHtml.showAdminHtml(activeChar, "itemcreation.htm");
  111. }
  112. else if (command.startsWith("admin_give_item_target"))
  113. {
  114. try
  115. {
  116. L2PcInstance target;
  117. if (activeChar.getTarget() instanceof L2PcInstance)
  118. {
  119. target = (L2PcInstance) activeChar.getTarget();
  120. }
  121. else
  122. {
  123. activeChar.sendMessage("Invalid target.");
  124. return false;
  125. }
  126. String val = command.substring(22);
  127. StringTokenizer st = new StringTokenizer(val);
  128. if (st.countTokens() == 2)
  129. {
  130. String id = st.nextToken();
  131. int idval = Integer.parseInt(id);
  132. String num = st.nextToken();
  133. long numval = Long.parseLong(num);
  134. createItem(activeChar, target, idval, numval);
  135. }
  136. else if (st.countTokens() == 1)
  137. {
  138. String id = st.nextToken();
  139. int idval = Integer.parseInt(id);
  140. createItem(activeChar, target, idval, 1);
  141. }
  142. }
  143. catch (StringIndexOutOfBoundsException e)
  144. {
  145. activeChar.sendMessage("Usage: //give_item_target <itemId> [amount]");
  146. }
  147. catch (NumberFormatException nfe)
  148. {
  149. activeChar.sendMessage("Specify a valid number.");
  150. }
  151. AdminHtml.showAdminHtml(activeChar, "itemcreation.htm");
  152. }
  153. else if (command.startsWith("admin_give_item_to_all"))
  154. {
  155. String val = command.substring(22);
  156. StringTokenizer st = new StringTokenizer(val);
  157. int idval = 0;
  158. long numval = 0;
  159. if (st.countTokens() == 2)
  160. {
  161. String id = st.nextToken();
  162. idval = Integer.parseInt(id);
  163. String num = st.nextToken();
  164. numval = Long.parseLong(num);
  165. }
  166. else if (st.countTokens() == 1)
  167. {
  168. String id = st.nextToken();
  169. idval = Integer.parseInt(id);
  170. numval = 1;
  171. }
  172. int counter = 0;
  173. L2Item template = ItemTable.getInstance().getTemplate(idval);
  174. if (template == null)
  175. {
  176. activeChar.sendMessage("This item doesn't exist.");
  177. return false;
  178. }
  179. if ((numval > 10) && !template.isStackable())
  180. {
  181. activeChar.sendMessage("This item does not stack - Creation aborted.");
  182. return false;
  183. }
  184. for (L2PcInstance onlinePlayer : L2World.getInstance().getPlayers())
  185. {
  186. if ((activeChar != onlinePlayer) && onlinePlayer.isOnline() && ((onlinePlayer.getClient() != null) && !onlinePlayer.getClient().isDetached()))
  187. {
  188. onlinePlayer.getInventory().addItem("Admin", idval, numval, onlinePlayer, activeChar);
  189. onlinePlayer.sendMessage("Admin spawned " + numval + " " + template.getName() + " in your inventory.");
  190. counter++;
  191. }
  192. }
  193. activeChar.sendMessage(counter + " players rewarded with " + template.getName());
  194. }
  195. return true;
  196. }
  197. @Override
  198. public String[] getAdminCommandList()
  199. {
  200. return ADMIN_COMMANDS;
  201. }
  202. private void createItem(L2PcInstance activeChar, L2PcInstance target, int id, long num)
  203. {
  204. L2Item template = ItemTable.getInstance().getTemplate(id);
  205. if (template == null)
  206. {
  207. activeChar.sendMessage("This item doesn't exist.");
  208. return;
  209. }
  210. if ((num > 10) && !template.isStackable())
  211. {
  212. activeChar.sendMessage("This item does not stack - Creation aborted.");
  213. return;
  214. }
  215. target.getInventory().addItem("Admin", id, num, activeChar, null);
  216. if (activeChar != target)
  217. {
  218. target.sendMessage("Admin spawned " + num + " " + template.getName() + " in your inventory.");
  219. }
  220. activeChar.sendMessage("You have spawned " + num + " " + template.getName() + "(" + id + ") in " + target.getName() + " inventory.");
  221. }
  222. private int getCoinId(String name)
  223. {
  224. int id;
  225. if (name.equalsIgnoreCase("adena"))
  226. {
  227. id = 57;
  228. }
  229. else if (name.equalsIgnoreCase("ancientadena"))
  230. {
  231. id = 5575;
  232. }
  233. else if (name.equalsIgnoreCase("festivaladena"))
  234. {
  235. id = 6673;
  236. }
  237. else if (name.equalsIgnoreCase("blueeva"))
  238. {
  239. id = 4355;
  240. }
  241. else if (name.equalsIgnoreCase("goldeinhasad"))
  242. {
  243. id = 4356;
  244. }
  245. else if (name.equalsIgnoreCase("silvershilen"))
  246. {
  247. id = 4357;
  248. }
  249. else if (name.equalsIgnoreCase("bloodypaagrio"))
  250. {
  251. id = 4358;
  252. }
  253. else if (name.equalsIgnoreCase("fantasyislecoin"))
  254. {
  255. id = 13067;
  256. }
  257. else
  258. {
  259. id = 0;
  260. }
  261. return id;
  262. }
  263. }