123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- /*
- * Copyright (C) 2004-2013 L2J DataPack
- *
- * This file is part of L2J DataPack.
- *
- * L2J DataPack is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * L2J DataPack is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package handlers.voicedcommandhandlers;
- import java.util.StringTokenizer;
- import com.l2jserver.gameserver.datatables.AdminTable;
- import com.l2jserver.gameserver.datatables.CharNameTable;
- import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
- import com.l2jserver.gameserver.model.L2World;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- public class ChatAdmin implements IVoicedCommandHandler
- {
- private static final String[] VOICED_COMMANDS =
- {
- "banchat",
- "unbanchat"
- };
-
- @Override
- public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params)
- {
- if (!AdminTable.getInstance().hasAccess(command, activeChar.getAccessLevel()))
- {
- return false;
- }
-
- if (command.equals(VOICED_COMMANDS[0])) // banchat
- {
- if (params == null)
- {
- activeChar.sendMessage("Usage: .banchat name [minutes]");
- return true;
- }
- StringTokenizer st = new StringTokenizer(params);
- if (st.hasMoreTokens())
- {
- String name = st.nextToken();
- int length = 0;
- if (st.hasMoreTokens())
- {
- try
- {
- length = Integer.parseInt(st.nextToken());
- }
- catch (NumberFormatException e)
- {
- activeChar.sendMessage("Wrong ban length !");
- return false;
- }
- }
- if (length < 0)
- {
- length = 0;
- }
-
- int objId = CharNameTable.getInstance().getIdByName(name);
- if (objId > 0)
- {
- L2PcInstance player = L2World.getInstance().getPlayer(objId);
- if ((player == null) || !player.isOnline())
- {
- activeChar.sendMessage("Player not online !");
- return false;
- }
- if (player.getPunishLevel() != L2PcInstance.PunishLevel.NONE)
- {
- activeChar.sendMessage("Player is already punished !");
- return false;
- }
- if (player == activeChar)
- {
- activeChar.sendMessage("You can't ban yourself !");
- return false;
- }
- if (player.isGM())
- {
- activeChar.sendMessage("You can't ban GM !");
- return false;
- }
- if (AdminTable.getInstance().hasAccess(command, player.getAccessLevel()))
- {
- activeChar.sendMessage("You can't ban moderator !");
- return false;
- }
-
- player.setPunishLevel(L2PcInstance.PunishLevel.CHAT, length);
- player.sendMessage("Chat banned by moderator " + activeChar.getName());
-
- if (length > 0)
- {
- activeChar.sendMessage("Player " + player.getName() + " chat banned for " + length + " minutes.");
- }
- else
- {
- activeChar.sendMessage("Player " + player.getName() + " chat banned forever.");
- }
- }
- else
- {
- activeChar.sendMessage("Player not found !");
- return false;
- }
- }
- }
- else if (command.equals(VOICED_COMMANDS[1])) // unbanchat
- {
- if (params == null)
- {
- activeChar.sendMessage("Usage: .unbanchat name");
- return true;
- }
- StringTokenizer st = new StringTokenizer(params);
- if (st.hasMoreTokens())
- {
- String name = st.nextToken();
-
- int objId = CharNameTable.getInstance().getIdByName(name);
- if (objId > 0)
- {
- L2PcInstance player = L2World.getInstance().getPlayer(objId);
- if ((player == null) || !player.isOnline())
- {
- activeChar.sendMessage("Player not online !");
- return false;
- }
- if (player.getPunishLevel() != L2PcInstance.PunishLevel.CHAT)
- {
- activeChar.sendMessage("Player is not chat banned !");
- return false;
- }
-
- player.setPunishLevel(L2PcInstance.PunishLevel.NONE, 0);
-
- activeChar.sendMessage("Player " + player.getName() + " chat unbanned.");
- player.sendMessage("Chat unbanned by moderator " + activeChar.getName());
- }
- else
- {
- activeChar.sendMessage("Player not found !");
- return false;
- }
- }
- }
- return true;
- }
-
- @Override
- public String[] getVoicedCommandList()
- {
- return VOICED_COMMANDS;
- }
- }
|