AdminKick.java 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 net.sf.l2j.gameserver.handler.admincommandhandlers;
  16. import java.util.StringTokenizer;
  17. import net.sf.l2j.gameserver.communitybbs.Manager.RegionBBSManager;
  18. import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  19. import net.sf.l2j.gameserver.model.L2World;
  20. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  21. import net.sf.l2j.gameserver.serverpackets.LeaveWorld;
  22. public class AdminKick implements IAdminCommandHandler {
  23. private static final String[] ADMIN_COMMANDS = {"admin_kick" ,"admin_kick_non_gm"};
  24. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  25. {
  26. if (command.startsWith("admin_kick"))
  27. {
  28. StringTokenizer st = new StringTokenizer(command);
  29. if (st.countTokens() > 1)
  30. {
  31. st.nextToken();
  32. String player = st.nextToken();
  33. L2PcInstance plyr = L2World.getInstance().getPlayer(player);
  34. if (plyr != null)
  35. {
  36. plyr.logout();
  37. activeChar.sendMessage("You kicked " + plyr.getName() + " from the game.");
  38. RegionBBSManager.getInstance().changeCommunityBoard();
  39. }
  40. }
  41. }
  42. if (command.startsWith("admin_kick_non_gm"))
  43. {
  44. int counter = 0;
  45. for (L2PcInstance player : L2World.getInstance().getAllPlayers())
  46. {
  47. if(!player.isGM())
  48. {
  49. counter++;
  50. player.sendPacket(new LeaveWorld());
  51. player.logout();
  52. RegionBBSManager.getInstance().changeCommunityBoard();
  53. }
  54. }
  55. activeChar.sendMessage("Kicked "+counter+" players");
  56. }
  57. return true;
  58. }
  59. public String[] getAdminCommandList() {
  60. return ADMIN_COMMANDS;
  61. }
  62. }