AdminBuffs.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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.L2Effect;
  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.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. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  42. {
  43. if (command.startsWith("admin_getbuffs"))
  44. {
  45. StringTokenizer st = new StringTokenizer(command, " ");
  46. command = st.nextToken();
  47. if (st.hasMoreTokens())
  48. {
  49. L2PcInstance player = null;
  50. String playername = st.nextToken();
  51. try
  52. {
  53. player = L2World.getInstance().getPlayer(playername);
  54. }
  55. catch (Exception e)
  56. {
  57. }
  58. if (player != null)
  59. {
  60. int page = 1;
  61. if (st.hasMoreTokens())
  62. page = Integer.parseInt(st.nextToken());
  63. showBuffs(activeChar, player, page);
  64. return true;
  65. }
  66. else
  67. {
  68. activeChar.sendMessage("The player " + playername + " is not online");
  69. return false;
  70. }
  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 instanceof L2PcInstance) && !(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() instanceof L2PcInstance)
  162. {
  163. player = (L2PcInstance) activeChar.getTarget();
  164. }
  165. else
  166. {
  167. activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT);
  168. return false;
  169. }
  170. try
  171. {
  172. player.getReuseTimeStamp().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. GMSkillTable.getInstance().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. else
  194. {
  195. activeChar.sendMessage("There is nothing to switch.");
  196. return false;
  197. }
  198. }
  199. else
  200. {
  201. return true;
  202. }
  203. }
  204. public String[] getAdminCommandList()
  205. {
  206. return ADMIN_COMMANDS;
  207. }
  208. public void showBuffs(L2PcInstance activeChar, L2Character target, int page)
  209. {
  210. final L2Effect[] effects = target.getAllEffects();
  211. if (page > effects.length / PAGE_LIMIT + 1 || page < 1)
  212. return;
  213. int max = effects.length / PAGE_LIMIT;
  214. if (effects.length > PAGE_LIMIT * max)
  215. max++;
  216. final StringBuilder html = StringUtil.startAppend(500 + effects.length * 200,
  217. "<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 ",
  218. target.getName(),
  219. "</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>");
  220. int start = ((page - 1) * PAGE_LIMIT);
  221. int end = Math.min(((page - 1) * PAGE_LIMIT) + PAGE_LIMIT, effects.length);
  222. for (int i = start; i < end; i++)
  223. {
  224. L2Effect e = effects[i];
  225. if (e != null)
  226. {
  227. StringUtil.append(html,
  228. "<tr><td>",
  229. e.getSkill().getName(),
  230. "</td><td>",
  231. e.getSkill().isToggle() ? "toggle" : e.getAbnormalTime() - e.getTime() + "s",
  232. "</td><td><button value=\"Remove\" action=\"bypass -h admin_stopbuff ",
  233. Integer.toString(target.getObjectId()),
  234. " ",
  235. String.valueOf(e.getSkill().getId()),
  236. "\" width=60 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
  237. }
  238. }
  239. html.append("</table><table width=300 bgcolor=444444><tr>");
  240. for (int x = 0; x < max; x++)
  241. {
  242. int pagenr = x + 1;
  243. if (page == pagenr)
  244. {
  245. html.append("<td>Page ");
  246. html.append(pagenr);
  247. html.append("</td>");
  248. }
  249. else
  250. {
  251. html.append("<td><a action=\"bypass -h admin_getbuffs ");
  252. html.append(target.getName());
  253. html.append(" ");
  254. html.append(x + 1);
  255. html.append("\"> Page ");
  256. html.append(pagenr);
  257. html.append(" </a></td>");
  258. }
  259. }
  260. html.append("</tr></table>");
  261. StringUtil.append(html, "<br><center><button value=\"Remove All\" action=\"bypass -h admin_stopallbuffs ",
  262. Integer.toString(target.getObjectId()),
  263. "\" width=80 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></html>");
  264. NpcHtmlMessage ms = new NpcHtmlMessage(1);
  265. ms.setHtml(html.toString());
  266. activeChar.sendPacket(ms);
  267. if (Config.GMAUDIT)
  268. GMAudit.auditGMAction(activeChar.getName()+" ["+activeChar.getObjectId()+"]", "getbuffs", target.getName() + " (" + Integer.toString(target.getObjectId()) + ")", "");
  269. }
  270. private void removeBuff(L2PcInstance activeChar, int objId, int skillId)
  271. {
  272. L2Character target = null;
  273. try
  274. {
  275. target = (L2Character) L2World.getInstance().findObject(objId);
  276. }
  277. catch (Exception e)
  278. {
  279. }
  280. if ((target != null) && (skillId > 0))
  281. {
  282. L2Effect[] effects = target.getAllEffects();
  283. for (L2Effect e : effects)
  284. {
  285. if ((e != null) && (e.getSkill().getId() == skillId))
  286. {
  287. e.exit();
  288. activeChar.sendMessage("Removed " + e.getSkill().getName() + " level " + e.getSkill().getLevel() + " from " + target.getName() + " (" + objId + ")");
  289. }
  290. }
  291. showBuffs(activeChar, target, 1);
  292. if (Config.GMAUDIT)
  293. GMAudit.auditGMAction(activeChar.getName()+" ["+activeChar.getObjectId()+"]", "stopbuff", target.getName() + " (" + objId + ")", Integer.toString(skillId));
  294. }
  295. }
  296. private void removeAllBuffs(L2PcInstance activeChar, int objId)
  297. {
  298. L2Character target = null;
  299. try
  300. {
  301. target = (L2Character) L2World.getInstance().findObject(objId);
  302. }
  303. catch (Exception e)
  304. {
  305. }
  306. if (target != null)
  307. {
  308. target.stopAllEffects();
  309. activeChar.sendMessage("Removed all effects from " + target.getName() + " (" + objId + ")");
  310. showBuffs(activeChar, target, 1);
  311. if (Config.GMAUDIT)
  312. GMAudit.auditGMAction(activeChar.getName()+" ["+activeChar.getObjectId()+"]", "stopallbuffs", target.getName() + " (" + objId + ")", "");
  313. }
  314. }
  315. }