AdminMessages.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package handlers.admincommandhandlers;
  16. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  17. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  18. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  19. import com.l2jserver.gameserver.util.Util;
  20. /**
  21. * Allows Game Masters to test System Messages.<br>
  22. * admin_msg display the raw message.<br>
  23. * admin_msgx is an extended version that allows to set parameters.
  24. * @author Zoey76
  25. */
  26. public class AdminMessages implements IAdminCommandHandler
  27. {
  28. private static final String[] ADMIN_COMMANDS =
  29. {
  30. "admin_msg",
  31. "admin_msgx"
  32. };
  33. @Override
  34. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  35. {
  36. if (command.startsWith("admin_msg "))
  37. {
  38. try
  39. {
  40. activeChar.sendPacket(SystemMessage.getSystemMessage(Integer.parseInt(command.substring(10).trim())));
  41. return true;
  42. }
  43. catch (Exception e)
  44. {
  45. activeChar.sendMessage("Command format: //msg <SYSTEM_MSG_ID>");
  46. }
  47. }
  48. else if (command.startsWith("admin_msgx "))
  49. {
  50. String[] tokens = command.split(" ");
  51. if (tokens.length <= 2 || !Util.isDigit(tokens[1]))
  52. {
  53. activeChar.sendMessage("Command format: //msgx <SYSTEM_MSG_ID> [item:Id] [skill:Id] [npc:Id] [zone:x,y,x] [castle:Id] [str:'text']");
  54. return false;
  55. }
  56. SystemMessage sm = SystemMessage.getSystemMessage(Integer.parseInt(tokens[1]));
  57. String val;
  58. int lastPos = 0;
  59. for (int i = 2; i < tokens.length; i++)
  60. {
  61. try
  62. {
  63. val = tokens[i];
  64. if (val.startsWith("item:"))
  65. {
  66. sm.addItemName(Integer.parseInt(val.substring(5)));
  67. }
  68. else if (val.startsWith("skill:"))
  69. {
  70. sm.addSkillName(Integer.parseInt(val.substring(6)));
  71. }
  72. else if (val.startsWith("npc:"))
  73. {
  74. sm.addNpcName(Integer.parseInt(val.substring(4)));
  75. }
  76. else if (val.startsWith("zone:"))
  77. {
  78. int x = Integer.parseInt(val.substring(5, val.indexOf(",")));
  79. int y = Integer.parseInt(val.substring(val.indexOf(",") + 1, val.lastIndexOf(",")));
  80. int z = Integer.parseInt(val.substring(val.lastIndexOf(",") + 1, val.length()));
  81. sm.addZoneName(x, y, z);
  82. }
  83. else if (val.startsWith("castle:"))
  84. {
  85. sm.addCastleId(Integer.parseInt(val.substring(7)));
  86. }
  87. else if (val.startsWith("str:"))
  88. {
  89. final int pos = command.indexOf("'", lastPos+1);
  90. lastPos = command.indexOf("'", pos + 1);
  91. sm.addString(command.substring(pos + 1, lastPos));
  92. }
  93. }
  94. catch (Exception e)
  95. {
  96. activeChar.sendMessage("Exception: " + e.getMessage());
  97. continue;
  98. }
  99. }
  100. activeChar.sendPacket(sm);
  101. }
  102. return false;
  103. }
  104. @Override
  105. public String[] getAdminCommandList()
  106. {
  107. return ADMIN_COMMANDS;
  108. }
  109. }