AdminBuffs.java 11 KB

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