AdminBuffs.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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.ArrayList;
  21. import java.util.Collection;
  22. import java.util.List;
  23. import java.util.StringTokenizer;
  24. import com.l2jserver.Config;
  25. import com.l2jserver.gameserver.data.xml.impl.SkillTreesData;
  26. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  27. import com.l2jserver.gameserver.model.L2World;
  28. import com.l2jserver.gameserver.model.actor.L2Character;
  29. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  30. import com.l2jserver.gameserver.model.effects.AbstractEffect;
  31. import com.l2jserver.gameserver.model.skills.AbnormalType;
  32. import com.l2jserver.gameserver.model.skills.BuffInfo;
  33. import com.l2jserver.gameserver.model.skills.Skill;
  34. import com.l2jserver.gameserver.network.SystemMessageId;
  35. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  36. import com.l2jserver.gameserver.network.serverpackets.SkillCoolTime;
  37. import com.l2jserver.gameserver.util.GMAudit;
  38. import com.l2jserver.util.StringUtil;
  39. public class AdminBuffs implements IAdminCommandHandler
  40. {
  41. private final static int PAGE_LIMIT = 20;
  42. private static final String[] ADMIN_COMMANDS =
  43. {
  44. "admin_getbuffs",
  45. "admin_getbuffs_ps",
  46. "admin_stopbuff",
  47. "admin_stopallbuffs",
  48. "admin_areacancel",
  49. "admin_removereuse",
  50. "admin_switch_gm_buffs"
  51. };
  52. // Misc
  53. private static final String FONT_RED1 = "<font color=\"FF0000\">";
  54. private static final String FONT_RED2 = "</font>";
  55. @Override
  56. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  57. {
  58. if (command.startsWith("admin_getbuffs"))
  59. {
  60. final StringTokenizer st = new StringTokenizer(command, " ");
  61. command = st.nextToken();
  62. if (st.hasMoreTokens())
  63. {
  64. final String playername = st.nextToken();
  65. L2PcInstance player = L2World.getInstance().getPlayer(playername);
  66. if (player != null)
  67. {
  68. int page = 1;
  69. if (st.hasMoreTokens())
  70. {
  71. page = Integer.parseInt(st.nextToken());
  72. }
  73. showBuffs(activeChar, player, page, command.endsWith("_ps"));
  74. return true;
  75. }
  76. activeChar.sendMessage("The player " + playername + " is not online.");
  77. return false;
  78. }
  79. else if ((activeChar.getTarget() != null) && activeChar.getTarget().isCharacter())
  80. {
  81. showBuffs(activeChar, (L2Character) activeChar.getTarget(), 1, command.endsWith("_ps"));
  82. return true;
  83. }
  84. else
  85. {
  86. activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT);
  87. return false;
  88. }
  89. }
  90. else if (command.startsWith("admin_stopbuff"))
  91. {
  92. try
  93. {
  94. StringTokenizer st = new StringTokenizer(command, " ");
  95. st.nextToken();
  96. int objectId = Integer.parseInt(st.nextToken());
  97. int skillId = Integer.parseInt(st.nextToken());
  98. removeBuff(activeChar, objectId, skillId);
  99. return true;
  100. }
  101. catch (Exception e)
  102. {
  103. activeChar.sendMessage("Failed removing effect: " + e.getMessage());
  104. activeChar.sendMessage("Usage: //stopbuff <objectId> <skillId>");
  105. return false;
  106. }
  107. }
  108. else if (command.startsWith("admin_stopallbuffs"))
  109. {
  110. try
  111. {
  112. StringTokenizer st = new StringTokenizer(command, " ");
  113. st.nextToken();
  114. int objectId = Integer.parseInt(st.nextToken());
  115. removeAllBuffs(activeChar, objectId);
  116. return true;
  117. }
  118. catch (Exception e)
  119. {
  120. activeChar.sendMessage("Failed removing all effects: " + e.getMessage());
  121. activeChar.sendMessage("Usage: //stopallbuffs <objectId>");
  122. return false;
  123. }
  124. }
  125. else if (command.startsWith("admin_areacancel"))
  126. {
  127. StringTokenizer st = new StringTokenizer(command, " ");
  128. st.nextToken();
  129. String val = st.nextToken();
  130. try
  131. {
  132. int radius = Integer.parseInt(val);
  133. for (L2Character knownChar : activeChar.getKnownList().getKnownCharactersInRadius(radius))
  134. {
  135. if (knownChar.isPlayer() && !knownChar.equals(activeChar))
  136. {
  137. knownChar.stopAllEffects();
  138. }
  139. }
  140. activeChar.sendMessage("All effects canceled within radius " + radius);
  141. return true;
  142. }
  143. catch (NumberFormatException e)
  144. {
  145. activeChar.sendMessage("Usage: //areacancel <radius>");
  146. return false;
  147. }
  148. }
  149. else if (command.startsWith("admin_removereuse"))
  150. {
  151. StringTokenizer st = new StringTokenizer(command, " ");
  152. command = st.nextToken();
  153. L2PcInstance player = null;
  154. if (st.hasMoreTokens())
  155. {
  156. String playername = st.nextToken();
  157. try
  158. {
  159. player = L2World.getInstance().getPlayer(playername);
  160. }
  161. catch (Exception e)
  162. {
  163. }
  164. if (player == null)
  165. {
  166. activeChar.sendMessage("The player " + playername + " is not online.");
  167. return false;
  168. }
  169. }
  170. else if ((activeChar.getTarget() != null) && activeChar.getTarget().isPlayer())
  171. {
  172. player = activeChar.getTarget().getActingPlayer();
  173. }
  174. else
  175. {
  176. activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT);
  177. return false;
  178. }
  179. try
  180. {
  181. player.resetTimeStamps();
  182. player.resetDisabledSkills();
  183. player.sendPacket(new SkillCoolTime(player));
  184. activeChar.sendMessage("Skill reuse was removed from " + player.getName() + ".");
  185. return true;
  186. }
  187. catch (NullPointerException e)
  188. {
  189. return false;
  190. }
  191. }
  192. else if (command.startsWith("admin_switch_gm_buffs"))
  193. {
  194. if (Config.GM_GIVE_SPECIAL_SKILLS != Config.GM_GIVE_SPECIAL_AURA_SKILLS)
  195. {
  196. final boolean toAuraSkills = activeChar.getKnownSkill(7041) != null;
  197. switchSkills(activeChar, toAuraSkills);
  198. activeChar.sendSkillList();
  199. activeChar.sendMessage("You have succefully changed to target " + (toAuraSkills ? "aura" : "one") + " special skills.");
  200. return true;
  201. }
  202. activeChar.sendMessage("There is nothing to switch.");
  203. return false;
  204. }
  205. return true;
  206. }
  207. /**
  208. * @param gmchar the player to switch the Game Master skills.
  209. * @param toAuraSkills if {@code true} it will remove "GM Aura" skills and add "GM regular" skills, vice versa if {@code false}.
  210. */
  211. public static void switchSkills(L2PcInstance gmchar, boolean toAuraSkills)
  212. {
  213. final Collection<Skill> skills = toAuraSkills ? SkillTreesData.getInstance().getGMSkillTree().values() : SkillTreesData.getInstance().getGMAuraSkillTree().values();
  214. for (Skill skill : skills)
  215. {
  216. gmchar.removeSkill(skill, false); // Don't Save GM skills to database
  217. }
  218. SkillTreesData.getInstance().addSkills(gmchar, toAuraSkills);
  219. }
  220. @Override
  221. public String[] getAdminCommandList()
  222. {
  223. return ADMIN_COMMANDS;
  224. }
  225. public static void showBuffs(L2PcInstance activeChar, L2Character target, int page, boolean passive)
  226. {
  227. final List<BuffInfo> effects = new ArrayList<>();
  228. if (!passive)
  229. {
  230. effects.addAll(target.getEffectList().getEffects());
  231. }
  232. else
  233. {
  234. effects.addAll(target.getEffectList().getPassives());
  235. }
  236. if ((page > ((effects.size() / PAGE_LIMIT) + 1)) || (page < 1))
  237. {
  238. return;
  239. }
  240. int max = effects.size() / PAGE_LIMIT;
  241. if (effects.size() > (PAGE_LIMIT * max))
  242. {
  243. max++;
  244. }
  245. final StringBuilder html = StringUtil.startAppend(500 + (effects.size() * 200), "<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 ", target.getName(), "</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>");
  246. int start = ((page - 1) * PAGE_LIMIT);
  247. int end = Math.min(((page - 1) * PAGE_LIMIT) + PAGE_LIMIT, effects.size());
  248. int count = 0;
  249. for (BuffInfo info : effects)
  250. {
  251. if ((count >= start) && (count < end))
  252. {
  253. final Skill skill = info.getSkill();
  254. for (AbstractEffect effect : info.getEffects())
  255. {
  256. StringUtil.append(html, "<tr><td>", (!info.isInUse() ? FONT_RED1 : "") + skill.getName(), " Lv ", String.valueOf(skill.getLevel()), " (", effect.getClass().getSimpleName(), ")" + (!info.isInUse() ? FONT_RED2 : ""), "</td><td>", skill.isToggle() ? "T (" + info.getTickCount(effect) + ")" : skill.isPassive() ? "P" : info.getTime() + "s", "</td><td><button value=\"X\" action=\"bypass -h admin_stopbuff ", Integer.toString(target.getObjectId()), " ", String.valueOf(skill.getId()), "\" width=30 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
  257. }
  258. }
  259. count++;
  260. }
  261. html.append("</table><table width=300 bgcolor=444444><tr>");
  262. for (int x = 0; x < max; x++)
  263. {
  264. int pagenr = x + 1;
  265. if (page == pagenr)
  266. {
  267. html.append("<td>Page ");
  268. html.append(pagenr);
  269. html.append("</td>");
  270. }
  271. else
  272. {
  273. html.append("<td><a action=\"bypass -h admin_getbuffs" + (passive ? "_ps " : " "));
  274. html.append(target.getName());
  275. html.append(" ");
  276. html.append(x + 1);
  277. html.append("\"> Page ");
  278. html.append(pagenr);
  279. html.append(" </a></td>");
  280. }
  281. }
  282. html.append("</tr></table>");
  283. // Buttons
  284. StringUtil.append(html, "<br><center><button value=\"Refresh\" action=\"bypass -h admin_getbuffs", (passive ? "_ps " : " "), target.getName(), "\" width=80 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  285. StringUtil.append(html, "<button value=\"Remove All\" action=\"bypass -h admin_stopallbuffs ", Integer.toString(target.getObjectId()), "\" width=80 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><br>");
  286. // Legend
  287. if (!passive)
  288. {
  289. StringUtil.append(html, FONT_RED1, "Inactive buffs: ", String.valueOf(target.getEffectList().getHiddenBuffsCount()), FONT_RED2, "<br>");
  290. }
  291. StringUtil.append(html, "Total", passive ? " passive" : "", " buff count: ", String.valueOf(effects.size()));
  292. if ((target.getEffectList().getAllBlockedBuffSlots() != null) && !target.getEffectList().getAllBlockedBuffSlots().isEmpty())
  293. {
  294. StringUtil.append(html, "<br>Blocked buff slots: ");
  295. String slots = "";
  296. for (AbnormalType slot : target.getEffectList().getAllBlockedBuffSlots())
  297. {
  298. slots += slot.toString() + ", ";
  299. }
  300. if (!slots.isEmpty() && (slots.length() > 3))
  301. {
  302. StringUtil.append(html, slots.substring(0, slots.length() - 2));
  303. }
  304. }
  305. StringUtil.append(html, "</html>");
  306. // Send the packet
  307. activeChar.sendPacket(new NpcHtmlMessage(html.toString()));
  308. if (Config.GMAUDIT)
  309. {
  310. GMAudit.auditGMAction(activeChar.getName() + " [" + activeChar.getObjectId() + "]", "getbuffs", target.getName() + " (" + Integer.toString(target.getObjectId()) + ")", "");
  311. }
  312. }
  313. private static void removeBuff(L2PcInstance activeChar, int objId, int skillId)
  314. {
  315. L2Character target = null;
  316. try
  317. {
  318. target = (L2Character) L2World.getInstance().findObject(objId);
  319. }
  320. catch (Exception e)
  321. {
  322. }
  323. if ((target != null) && (skillId > 0))
  324. {
  325. if (target.isAffectedBySkill(skillId))
  326. {
  327. target.stopSkillEffects(true, skillId);
  328. activeChar.sendMessage("Removed skill ID: " + skillId + " effects from " + target.getName() + " (" + objId + ").");
  329. }
  330. showBuffs(activeChar, target, 1, false);
  331. if (Config.GMAUDIT)
  332. {
  333. GMAudit.auditGMAction(activeChar.getName() + " [" + activeChar.getObjectId() + "]", "stopbuff", target.getName() + " (" + objId + ")", Integer.toString(skillId));
  334. }
  335. }
  336. }
  337. private static void removeAllBuffs(L2PcInstance activeChar, int objId)
  338. {
  339. L2Character target = null;
  340. try
  341. {
  342. target = (L2Character) L2World.getInstance().findObject(objId);
  343. }
  344. catch (Exception e)
  345. {
  346. }
  347. if (target != null)
  348. {
  349. target.stopAllEffects();
  350. activeChar.sendMessage("Removed all effects from " + target.getName() + " (" + objId + ")");
  351. showBuffs(activeChar, target, 1, false);
  352. if (Config.GMAUDIT)
  353. {
  354. GMAudit.auditGMAction(activeChar.getName() + " [" + activeChar.getObjectId() + "]", "stopallbuffs", target.getName() + " (" + objId + ")", "");
  355. }
  356. }
  357. }
  358. }