AdminBuffs.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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.Config;
  18. import com.l2jserver.gameserver.datatables.GMSkillTable;
  19. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  20. import com.l2jserver.gameserver.model.L2World;
  21. import com.l2jserver.gameserver.model.actor.L2Character;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.effects.L2Effect;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  26. import com.l2jserver.gameserver.network.serverpackets.SkillCoolTime;
  27. import com.l2jserver.gameserver.util.GMAudit;
  28. import com.l2jserver.util.StringUtil;
  29. public class AdminBuffs implements IAdminCommandHandler
  30. {
  31. private final static int PAGE_LIMIT = 20;
  32. private static final String[] ADMIN_COMMANDS =
  33. {
  34. "admin_getbuffs",
  35. "admin_stopbuff",
  36. "admin_stopallbuffs",
  37. "admin_areacancel",
  38. "admin_removereuse",
  39. "admin_switch_gm_buffs"
  40. };
  41. @Override
  42. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  43. {
  44. if (command.startsWith("admin_getbuffs"))
  45. {
  46. StringTokenizer st = new StringTokenizer(command, " ");
  47. command = st.nextToken();
  48. if (st.hasMoreTokens())
  49. {
  50. L2PcInstance player = null;
  51. String playername = st.nextToken();
  52. try
  53. {
  54. player = L2World.getInstance().getPlayer(playername);
  55. }
  56. catch (Exception e)
  57. {
  58. }
  59. if (player != null)
  60. {
  61. int page = 1;
  62. if (st.hasMoreTokens())
  63. page = Integer.parseInt(st.nextToken());
  64. showBuffs(activeChar, player, page);
  65. return true;
  66. }
  67. activeChar.sendMessage("The player " + playername + " is not online");
  68. return false;
  69. }
  70. else if ((activeChar.getTarget() != null) && (activeChar.getTarget() instanceof L2Character))
  71. {
  72. showBuffs(activeChar, (L2Character) activeChar.getTarget(), 1);
  73. return true;
  74. }
  75. else
  76. {
  77. activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT);
  78. return false;
  79. }
  80. }
  81. else if (command.startsWith("admin_stopbuff"))
  82. {
  83. try
  84. {
  85. StringTokenizer st = new StringTokenizer(command, " ");
  86. st.nextToken();
  87. int objectId = Integer.parseInt(st.nextToken());
  88. int skillId = Integer.parseInt(st.nextToken());
  89. removeBuff(activeChar, objectId, skillId);
  90. return true;
  91. }
  92. catch (Exception e)
  93. {
  94. activeChar.sendMessage("Failed removing effect: " + e.getMessage());
  95. activeChar.sendMessage("Usage: //stopbuff <objectId> <skillId>");
  96. return false;
  97. }
  98. }
  99. else if (command.startsWith("admin_stopallbuffs"))
  100. {
  101. try
  102. {
  103. StringTokenizer st = new StringTokenizer(command, " ");
  104. st.nextToken();
  105. int objectId = Integer.parseInt(st.nextToken());
  106. removeAllBuffs(activeChar, objectId);
  107. return true;
  108. }
  109. catch (Exception e)
  110. {
  111. activeChar.sendMessage("Failed removing all effects: " + e.getMessage());
  112. activeChar.sendMessage("Usage: //stopallbuffs <objectId>");
  113. return false;
  114. }
  115. }
  116. else if (command.startsWith("admin_areacancel"))
  117. {
  118. StringTokenizer st = new StringTokenizer(command, " ");
  119. st.nextToken();
  120. String val = st.nextToken();
  121. try
  122. {
  123. int radius = Integer.parseInt(val);
  124. for (L2Character knownChar : activeChar.getKnownList().getKnownCharactersInRadius(radius))
  125. {
  126. if ((knownChar instanceof L2PcInstance) && !(knownChar.equals(activeChar)))
  127. knownChar.stopAllEffects();
  128. }
  129. activeChar.sendMessage("All effects canceled within raidus " + radius);
  130. return true;
  131. }
  132. catch (NumberFormatException e)
  133. {
  134. activeChar.sendMessage("Usage: //areacancel <radius>");
  135. return false;
  136. }
  137. }
  138. else if (command.startsWith("admin_removereuse"))
  139. {
  140. StringTokenizer st = new StringTokenizer(command, " ");
  141. command = st.nextToken();
  142. L2PcInstance player = null;
  143. if (st.hasMoreTokens())
  144. {
  145. String playername = st.nextToken();
  146. try
  147. {
  148. player = L2World.getInstance().getPlayer(playername);
  149. }
  150. catch (Exception e)
  151. {
  152. }
  153. if (player == null)
  154. {
  155. activeChar.sendMessage("The player " + playername + " is not online.");
  156. return false;
  157. }
  158. }
  159. else if (activeChar.getTarget() instanceof L2PcInstance)
  160. {
  161. player = (L2PcInstance) activeChar.getTarget();
  162. }
  163. else
  164. {
  165. activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT);
  166. return false;
  167. }
  168. try
  169. {
  170. player.getReuseTimeStamp().clear();
  171. player.getDisabledSkills().clear();
  172. player.sendPacket(new SkillCoolTime(player));
  173. activeChar.sendMessage("Skill reuse was removed from " + player.getName() + ".");
  174. return true;
  175. }
  176. catch (NullPointerException e)
  177. {
  178. return false;
  179. }
  180. }
  181. else if (command.startsWith("admin_switch_gm_buffs"))
  182. {
  183. if (Config.GM_GIVE_SPECIAL_SKILLS != Config.GM_GIVE_SPECIAL_AURA_SKILLS)
  184. {
  185. final boolean toAuraSkills = activeChar.getKnownSkill(7041) != null;
  186. GMSkillTable.getInstance().switchSkills(activeChar, toAuraSkills);
  187. activeChar.sendSkillList();
  188. activeChar.sendMessage("You have succefully changed to target " + (toAuraSkills ? "aura" : "one") + " special skills.");
  189. return true;
  190. }
  191. activeChar.sendMessage("There is nothing to switch.");
  192. return false;
  193. }
  194. else
  195. {
  196. return true;
  197. }
  198. }
  199. @Override
  200. public String[] getAdminCommandList()
  201. {
  202. return ADMIN_COMMANDS;
  203. }
  204. public void showBuffs(L2PcInstance activeChar, L2Character target, int page)
  205. {
  206. final L2Effect[] effects = target.getAllEffects();
  207. if (page > effects.length / PAGE_LIMIT + 1 || page < 1)
  208. return;
  209. int max = effects.length / PAGE_LIMIT;
  210. if (effects.length > PAGE_LIMIT * max)
  211. max++;
  212. final StringBuilder html = StringUtil.startAppend(500 + effects.length * 200,
  213. "<html><table width=\"100%\"><tr><td width=45><button value=\"Main\" action=\"bypass -h admin_admin\" width=45 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td><td width=180><center><font color=\"LEVEL\">Effects of ",
  214. target.getName(),
  215. "</font></td><td width=45><button value=\"Back\" action=\"bypass -h admin_current_player\" width=45 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr></table><br><table width=\"100%\"><tr><td width=200>Skill</td><td width=30>Rem. Time</td><td width=70>Action</td></tr>");
  216. int start = ((page - 1) * PAGE_LIMIT);
  217. int end = Math.min(((page - 1) * PAGE_LIMIT) + PAGE_LIMIT, effects.length);
  218. for (int i = start; i < end; i++)
  219. {
  220. L2Effect e = effects[i];
  221. if (e != null)
  222. {
  223. StringUtil.append(html,
  224. "<tr><td>",
  225. e.getSkill().getName(),
  226. "</td><td>",
  227. e.getSkill().isToggle() ? "toggle" : e.getAbnormalTime() - e.getTime() + "s",
  228. "</td><td><button value=\"Remove\" action=\"bypass -h admin_stopbuff ",
  229. Integer.toString(target.getObjectId()),
  230. " ",
  231. String.valueOf(e.getSkill().getId()),
  232. "\" width=60 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
  233. }
  234. }
  235. html.append("</table><table width=300 bgcolor=444444><tr>");
  236. for (int x = 0; x < max; x++)
  237. {
  238. int pagenr = x + 1;
  239. if (page == pagenr)
  240. {
  241. html.append("<td>Page ");
  242. html.append(pagenr);
  243. html.append("</td>");
  244. }
  245. else
  246. {
  247. html.append("<td><a action=\"bypass -h admin_getbuffs ");
  248. html.append(target.getName());
  249. html.append(" ");
  250. html.append(x + 1);
  251. html.append("\"> Page ");
  252. html.append(pagenr);
  253. html.append(" </a></td>");
  254. }
  255. }
  256. html.append("</tr></table>");
  257. StringUtil.append(html, "<br><center><button value=\"Remove All\" action=\"bypass -h admin_stopallbuffs ",
  258. Integer.toString(target.getObjectId()),
  259. "\" width=80 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></html>");
  260. NpcHtmlMessage ms = new NpcHtmlMessage(1);
  261. ms.setHtml(html.toString());
  262. activeChar.sendPacket(ms);
  263. if (Config.GMAUDIT)
  264. GMAudit.auditGMAction(activeChar.getName()+" ["+activeChar.getObjectId()+"]", "getbuffs", target.getName() + " (" + Integer.toString(target.getObjectId()) + ")", "");
  265. }
  266. private void removeBuff(L2PcInstance activeChar, int objId, int skillId)
  267. {
  268. L2Character target = null;
  269. try
  270. {
  271. target = (L2Character) L2World.getInstance().findObject(objId);
  272. }
  273. catch (Exception e)
  274. {
  275. }
  276. if ((target != null) && (skillId > 0))
  277. {
  278. L2Effect[] effects = target.getAllEffects();
  279. for (L2Effect e : effects)
  280. {
  281. if ((e != null) && (e.getSkill().getId() == skillId))
  282. {
  283. e.exit();
  284. activeChar.sendMessage("Removed " + e.getSkill().getName() + " level " + e.getSkill().getLevel() + " from " + target.getName() + " (" + objId + ")");
  285. }
  286. }
  287. showBuffs(activeChar, target, 1);
  288. if (Config.GMAUDIT)
  289. GMAudit.auditGMAction(activeChar.getName()+" ["+activeChar.getObjectId()+"]", "stopbuff", target.getName() + " (" + objId + ")", Integer.toString(skillId));
  290. }
  291. }
  292. private void removeAllBuffs(L2PcInstance activeChar, int objId)
  293. {
  294. L2Character target = null;
  295. try
  296. {
  297. target = (L2Character) L2World.getInstance().findObject(objId);
  298. }
  299. catch (Exception e)
  300. {
  301. }
  302. if (target != null)
  303. {
  304. target.stopAllEffects();
  305. activeChar.sendMessage("Removed all effects from " + target.getName() + " (" + objId + ")");
  306. showBuffs(activeChar, target, 1);
  307. if (Config.GMAUDIT)
  308. GMAudit.auditGMAction(activeChar.getName()+" ["+activeChar.getObjectId()+"]", "stopallbuffs", target.getName() + " (" + objId + ")", "");
  309. }
  310. }
  311. }