AdminKick.java 2.0 KB

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