AdminKick.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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.gameserver.handler.IAdminCommandHandler;
  19. import com.l2jserver.gameserver.model.L2World;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. public class AdminKick implements IAdminCommandHandler
  22. {
  23. private static final String[] ADMIN_COMMANDS =
  24. {
  25. "admin_kick",
  26. "admin_kick_non_gm"
  27. };
  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. Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers().values();
  49. //synchronized (L2World.getInstance().getAllPlayers())
  50. {
  51. for (L2PcInstance player : pls)
  52. if (!player.isGM())
  53. {
  54. counter++;
  55. player.logout();
  56. }
  57. }
  58. activeChar.sendMessage("Kicked " + counter + " players");
  59. }
  60. return true;
  61. }
  62. public String[] getAdminCommandList()
  63. {
  64. return ADMIN_COMMANDS;
  65. }
  66. }