AdminPcCondOverride.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 java.util.StringTokenizer;
  17. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  18. import com.l2jserver.gameserver.model.PcCondOverride;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  21. import com.l2jserver.gameserver.util.Util;
  22. /**
  23. * Handler provides ability to override server's conditions for admin.
  24. * @author UnAfraid
  25. */
  26. public class AdminPcCondOverride implements IAdminCommandHandler
  27. {
  28. private static final String[] COMMANDS =
  29. {
  30. "admin_exceptions",
  31. "admin_set_exception",
  32. };
  33. @Override
  34. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  35. {
  36. StringTokenizer st = new StringTokenizer(command);
  37. if (st.hasMoreTokens())
  38. {
  39. switch (st.nextToken()) // command
  40. {
  41. case "admin_exceptions":
  42. {
  43. NpcHtmlMessage msg = new NpcHtmlMessage(5, 1);
  44. msg.setFile(activeChar.getHtmlPrefix(), "data/html/admin/cond_override.htm");
  45. StringBuilder sb = new StringBuilder();
  46. for (PcCondOverride ex : PcCondOverride.values())
  47. {
  48. sb.append("<tr><td fixwidth=\"180\">" + ex.getDescription() + ":</td><td><a action=\"bypass -h admin_set_exception " + ex.ordinal() + "\">" + (activeChar.canOverrideCond(ex) ? "Disable" : "Enable") + "</a></td></tr>");
  49. }
  50. msg.replace("%cond_table%", sb.toString());
  51. activeChar.sendPacket(msg);
  52. break;
  53. }
  54. case "admin_set_exception":
  55. {
  56. if (st.hasMoreTokens())
  57. {
  58. String token = st.nextToken();
  59. if (Util.isDigit(token))
  60. {
  61. PcCondOverride ex = PcCondOverride.getCondOverride(Integer.valueOf(token));
  62. if (ex != null)
  63. {
  64. if (activeChar.canOverrideCond(ex))
  65. {
  66. activeChar.removeOverridedCond(ex);
  67. activeChar.sendMessage("You've disabled " + ex.getDescription());
  68. }
  69. else
  70. {
  71. activeChar.addOverrideCond(ex);
  72. activeChar.sendMessage("You've enabled " + ex.getDescription());
  73. }
  74. }
  75. }
  76. else
  77. {
  78. switch (token)
  79. {
  80. case "enable_all":
  81. {
  82. for (PcCondOverride ex : PcCondOverride.values())
  83. {
  84. if (!activeChar.canOverrideCond(ex))
  85. {
  86. activeChar.addOverrideCond(ex);
  87. }
  88. }
  89. activeChar.sendMessage("All condition exceptions have been enabled.");
  90. break;
  91. }
  92. case "disable_all":
  93. {
  94. for (PcCondOverride ex : PcCondOverride.values())
  95. {
  96. if (activeChar.canOverrideCond(ex))
  97. {
  98. activeChar.removeOverridedCond(ex);
  99. }
  100. }
  101. activeChar.sendMessage("All condition exceptions have been disabled.");
  102. break;
  103. }
  104. }
  105. }
  106. useAdminCommand(COMMANDS[0], activeChar);
  107. }
  108. break;
  109. }
  110. }
  111. }
  112. return true;
  113. }
  114. @Override
  115. public String[] getAdminCommandList()
  116. {
  117. return COMMANDS;
  118. }
  119. }