AdminKick.java 2.6 KB

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