AdminPcCondOverride.java 3.7 KB

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