AdminKick.java 2.4 KB

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