AdminMessages.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  23. import com.l2jserver.gameserver.util.Util;
  24. /**
  25. * Allows Game Masters to test System Messages.<br>
  26. * admin_msg display the raw message.<br>
  27. * admin_msgx is an extended version that allows to set parameters.
  28. * @author Zoey76
  29. */
  30. public class AdminMessages implements IAdminCommandHandler
  31. {
  32. private static final String[] ADMIN_COMMANDS =
  33. {
  34. "admin_msg",
  35. "admin_msgx"
  36. };
  37. @Override
  38. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  39. {
  40. if (command.startsWith("admin_msg "))
  41. {
  42. try
  43. {
  44. activeChar.sendPacket(SystemMessage.getSystemMessage(Integer.parseInt(command.substring(10).trim())));
  45. return true;
  46. }
  47. catch (Exception e)
  48. {
  49. activeChar.sendMessage("Command format: //msg <SYSTEM_MSG_ID>");
  50. }
  51. }
  52. else if (command.startsWith("admin_msgx "))
  53. {
  54. String[] tokens = command.split(" ");
  55. if ((tokens.length <= 2) || !Util.isDigit(tokens[1]))
  56. {
  57. activeChar.sendMessage("Command format: //msgx <SYSTEM_MSG_ID> [item:Id] [skill:Id] [npc:Id] [zone:x,y,x] [castle:Id] [str:'text']");
  58. return false;
  59. }
  60. SystemMessage sm = SystemMessage.getSystemMessage(Integer.parseInt(tokens[1]));
  61. String val;
  62. int lastPos = 0;
  63. for (int i = 2; i < tokens.length; i++)
  64. {
  65. try
  66. {
  67. val = tokens[i];
  68. if (val.startsWith("item:"))
  69. {
  70. sm.addItemName(Integer.parseInt(val.substring(5)));
  71. }
  72. else if (val.startsWith("skill:"))
  73. {
  74. sm.addSkillName(Integer.parseInt(val.substring(6)));
  75. }
  76. else if (val.startsWith("npc:"))
  77. {
  78. sm.addNpcName(Integer.parseInt(val.substring(4)));
  79. }
  80. else if (val.startsWith("zone:"))
  81. {
  82. int x = Integer.parseInt(val.substring(5, val.indexOf(",")));
  83. int y = Integer.parseInt(val.substring(val.indexOf(",") + 1, val.lastIndexOf(",")));
  84. int z = Integer.parseInt(val.substring(val.lastIndexOf(",") + 1, val.length()));
  85. sm.addZoneName(x, y, z);
  86. }
  87. else if (val.startsWith("castle:"))
  88. {
  89. sm.addCastleId(Integer.parseInt(val.substring(7)));
  90. }
  91. else if (val.startsWith("str:"))
  92. {
  93. final int pos = command.indexOf("'", lastPos + 1);
  94. lastPos = command.indexOf("'", pos + 1);
  95. sm.addString(command.substring(pos + 1, lastPos));
  96. }
  97. }
  98. catch (Exception e)
  99. {
  100. activeChar.sendMessage("Exception: " + e.getMessage());
  101. continue;
  102. }
  103. }
  104. activeChar.sendPacket(sm);
  105. }
  106. return false;
  107. }
  108. @Override
  109. public String[] getAdminCommandList()
  110. {
  111. return ADMIN_COMMANDS;
  112. }
  113. }