AdminBuffs.java 11 KB

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