AdminBuffs.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /*
  2. * Copyright (C) 2004-2013 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.Collection;
  21. import java.util.List;
  22. import java.util.StringTokenizer;
  23. import com.l2jserver.Config;
  24. import com.l2jserver.gameserver.datatables.SkillTreesData;
  25. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  26. import com.l2jserver.gameserver.model.L2World;
  27. import com.l2jserver.gameserver.model.actor.L2Character;
  28. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  29. import com.l2jserver.gameserver.model.effects.L2Effect;
  30. import com.l2jserver.gameserver.model.skills.L2Skill;
  31. import com.l2jserver.gameserver.network.SystemMessageId;
  32. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  33. import com.l2jserver.gameserver.network.serverpackets.SkillCoolTime;
  34. import com.l2jserver.gameserver.util.GMAudit;
  35. import com.l2jserver.util.StringUtil;
  36. public class AdminBuffs implements IAdminCommandHandler
  37. {
  38. private final static int PAGE_LIMIT = 20;
  39. private static final String[] ADMIN_COMMANDS =
  40. {
  41. "admin_getbuffs",
  42. "admin_stopbuff",
  43. "admin_stopallbuffs",
  44. "admin_areacancel",
  45. "admin_removereuse",
  46. "admin_switch_gm_buffs"
  47. };
  48. @Override
  49. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  50. {
  51. if (command.startsWith("admin_getbuffs"))
  52. {
  53. StringTokenizer st = new StringTokenizer(command, " ");
  54. command = st.nextToken();
  55. if (st.hasMoreTokens())
  56. {
  57. L2PcInstance player = null;
  58. String playername = st.nextToken();
  59. try
  60. {
  61. player = L2World.getInstance().getPlayer(playername);
  62. }
  63. catch (Exception e)
  64. {
  65. }
  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);
  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() instanceof L2Character))
  80. {
  81. showBuffs(activeChar, (L2Character) activeChar.getTarget(), 1);
  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().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.getSkillReuseTimeStamps().clear();
  182. player.getDisabledSkills().clear();
  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. else
  206. {
  207. return true;
  208. }
  209. }
  210. /**
  211. * @param gmchar the player to switch the Game Master skills.
  212. * @param toAuraSkills if {@code true} it will remove "GM Aura" skills and add "GM regular" skills, vice versa if {@code false}.
  213. */
  214. public static void switchSkills(L2PcInstance gmchar, boolean toAuraSkills)
  215. {
  216. final Collection<L2Skill> skills = toAuraSkills ? SkillTreesData.getInstance().getGMSkillTree().values() : SkillTreesData.getInstance().getGMAuraSkillTree().values();
  217. for (L2Skill skill : skills)
  218. {
  219. gmchar.removeSkill(skill, false); // Don't Save GM skills to database
  220. }
  221. SkillTreesData.getInstance().addSkills(gmchar, toAuraSkills);
  222. }
  223. @Override
  224. public String[] getAdminCommandList()
  225. {
  226. return ADMIN_COMMANDS;
  227. }
  228. public static void showBuffs(L2PcInstance activeChar, L2Character target, int page)
  229. {
  230. final List<L2Effect> effects = target.getAllEffects();
  231. if ((page > ((effects.size() / PAGE_LIMIT) + 1)) || (page < 1))
  232. {
  233. return;
  234. }
  235. int max = effects.size() / PAGE_LIMIT;
  236. if (effects.size() > (PAGE_LIMIT * max))
  237. {
  238. max++;
  239. }
  240. 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><td>In use</td></tr>");
  241. int start = ((page - 1) * PAGE_LIMIT);
  242. int end = Math.min(((page - 1) * PAGE_LIMIT) + PAGE_LIMIT, effects.size());
  243. for (int i = start; i < end; i++)
  244. {
  245. L2Effect e = effects.get(i);
  246. if (e != null)
  247. {
  248. final L2Skill skill = e.getSkill();
  249. StringUtil.append(html, "<tr><td>", skill.getName(), "(", e.getClass().getSimpleName(), ")", "</td><td>", skill.isToggle() ? "T (" + e.getTickCount() + ")" : skill.isPassive() ? "P" : e.getTimeLeft() + "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><td>" + e.isInUse() + "</td></tr>");
  250. }
  251. }
  252. html.append("</table><table width=300 bgcolor=444444><tr>");
  253. for (int x = 0; x < max; x++)
  254. {
  255. int pagenr = x + 1;
  256. if (page == pagenr)
  257. {
  258. html.append("<td>Page ");
  259. html.append(pagenr);
  260. html.append("</td>");
  261. }
  262. else
  263. {
  264. html.append("<td><a action=\"bypass -h admin_getbuffs ");
  265. html.append(target.getName());
  266. html.append(" ");
  267. html.append(x + 1);
  268. html.append("\"> Page ");
  269. html.append(pagenr);
  270. html.append(" </a></td>");
  271. }
  272. }
  273. html.append("</tr></table>");
  274. StringUtil.append(html, "<br><center><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\"></html>");
  275. NpcHtmlMessage ms = new NpcHtmlMessage(1);
  276. ms.setHtml(html.toString());
  277. activeChar.sendPacket(ms);
  278. if (Config.GMAUDIT)
  279. {
  280. GMAudit.auditGMAction(activeChar.getName() + " [" + activeChar.getObjectId() + "]", "getbuffs", target.getName() + " (" + Integer.toString(target.getObjectId()) + ")", "");
  281. }
  282. }
  283. private static void removeBuff(L2PcInstance activeChar, int objId, int skillId)
  284. {
  285. L2Character target = null;
  286. try
  287. {
  288. target = (L2Character) L2World.getInstance().findObject(objId);
  289. }
  290. catch (Exception e)
  291. {
  292. }
  293. if ((target != null) && (skillId > 0))
  294. {
  295. for (L2Effect e : target.getAllEffects())
  296. {
  297. if ((e != null) && (e.getSkill().getId() == skillId))
  298. {
  299. e.exit();
  300. activeChar.sendMessage("Removed " + e.getSkill().getName() + " level " + e.getSkill().getLevel() + " from " + target.getName() + " (" + objId + ")");
  301. }
  302. }
  303. showBuffs(activeChar, target, 1);
  304. if (Config.GMAUDIT)
  305. {
  306. GMAudit.auditGMAction(activeChar.getName() + " [" + activeChar.getObjectId() + "]", "stopbuff", target.getName() + " (" + objId + ")", Integer.toString(skillId));
  307. }
  308. }
  309. }
  310. private static void removeAllBuffs(L2PcInstance activeChar, int objId)
  311. {
  312. L2Character target = null;
  313. try
  314. {
  315. target = (L2Character) L2World.getInstance().findObject(objId);
  316. }
  317. catch (Exception e)
  318. {
  319. }
  320. if (target != null)
  321. {
  322. target.stopAllEffects();
  323. activeChar.sendMessage("Removed all effects from " + target.getName() + " (" + objId + ")");
  324. showBuffs(activeChar, target, 1);
  325. if (Config.GMAUDIT)
  326. {
  327. GMAudit.auditGMAction(activeChar.getName() + " [" + activeChar.getObjectId() + "]", "stopallbuffs", target.getName() + " (" + objId + ")", "");
  328. }
  329. }
  330. }
  331. }