04-28-2010, 04:06 PM
(Сообщение последний раз редактировалось: 04-28-2010, 04:19 PM lxShaDoWxl.)
Столкнулся с такой проблемой при доделывании скрипта не как не могу добавить в него бан чара когда тот в оффе и разбан чара вот скрипт
Кто сможет помочь его дописать и если надо еще выложу вывод в конфиг и добавления в handler.voicedcommandhandlers
Добавлено через 13 минут
еще вопрос как добавить в верхний скрипт вот это? кому не сложно помогите
Код:
/*
* This program 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.
*
* This program 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 com.l2open.gameserver.handler.voicedcommandhandlers;
import java.util.StringTokenizer;
import com.l2open.gameserver.datatables.AdminCommandAccessRights;
import com.l2open.gameserver.datatables.CharNameTable;
import com.l2open.gameserver.handler.IVoicedCommandHandler;
import com.l2open.gameserver.model.L2World;
import com.l2open.gameserver.model.actor.instance.L2PcInstance;
public class ChatAdmin implements IVoicedCommandHandler
{
private static final String[] VOICED_COMMANDS =
{
"banchat",
"unbanchat",
"ban",
"unban",
"jail",
"unjail"
};
/**
*
* @see ru.l2open.gameserver.handler.IVoicedCommandHandler#useVoicedCommand(java.lang.String, ru.l2open.gameserver.model.actor.instance.L2PcInstance, java.lang.String)
*/
public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params)
{
if (!AdminCommandAccessRights.getInstance().hasAccess(command, activeChar.getAccessLevel()))
return false;
if (command.equalsIgnoreCase(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() == 0)
{
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 (AdminCommandAccessRights.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.equalsIgnoreCase(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() == 0)
{
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;
}
}
}
else if (command.equalsIgnoreCase(VOICED_COMMANDS[2])) // ban
{
if (params == null)
{
activeChar.sendMessage("Usage: .ban name [day]");
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);
int objId = CharNameTable.getInstance().getIdByName(name);
if (objId > 0)
{
L2PcInstance player = L2World.getInstance().getPlayer(objId);
if (player == null && name.equals(name))
{
return true;
}
if (player == activeChar)
{
activeChar.sendMessage("You can't ban yourself !");
return false;
}
player.setPunishLevel(L2PcInstance.PunishLevel.CHAR, length);
player.sendMessage("Chat banned by moderator " + activeChar.getName());
if (length > 0)
activeChar.sendMessage("Player " + player.getName() + " char banned for " + length + " day.");
else
activeChar.sendMessage("Player " + player.getName() + " char banned forever.");
}
else
{
activeChar.sendMessage("Player not found !");
return false;
}
}
}
else if (command.equalsIgnoreCase(VOICED_COMMANDS[3])) //unban
{
if (params == null)
{
activeChar.sendMessage("Usage: .unban 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);
player.setPunishLevel(L2PcInstance.PunishLevel.CHAR, 0);
activeChar.sendMessage("Player " + player.getName() + " char unbanned.");
}
else
{
activeChar.sendMessage("Player not found !");
return false;
}
}
}
else if (command.equalsIgnoreCase(VOICED_COMMANDS[4])) // jail
{
if (params == null)
{
activeChar.sendMessage("Usage: .jail 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() == 0)
{
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 (AdminCommandAccessRights.getInstance().hasAccess(command, player.getAccessLevel()))
{
activeChar.sendMessage("You can't ban moderator !");
return false;
}
if (length <= 0)
{
activeChar.sendMessage("Wrong ban length");
return false;
}
player.setPunishLevel(L2PcInstance.PunishLevel.JAIL, length);
player.sendMessage("Chat banned by moderator " + activeChar.getName());
if (length > 0)
activeChar.sendMessage("Player " + player.getName() + " jail for " + length + " minutes.");
else
activeChar.sendMessage("Player " + player.getName() + " jail forever.");
}
else
{
activeChar.sendMessage("Player not found !");
return false;
}
}
}
else if (command.equalsIgnoreCase(VOICED_COMMANDS[5])) //unjail
{
if (params == null)
{
activeChar.sendMessage("Usage: .unjail name");
return true;
}
StringTokenizer st1 = new StringTokenizer(params);
if (st1.hasMoreTokens())
{
String name = st1.nextToken();
int objId = CharNameTable.getInstance().getIdByName(name);
if (objId > 0)
{
L2PcInstance player = L2World.getInstance().getPlayer(objId);
if (player == null || player.isOnline() == 0)
{
activeChar.sendMessage("Player not online !");
return false;
}
if (player.getPunishLevel() != L2PcInstance.PunishLevel.JAIL)
{
activeChar.sendMessage("Player is not jail !");
return false;
}
player.setPunishLevel(L2PcInstance.PunishLevel.NONE, 1);
activeChar.sendMessage("Player " + player.getName() + " unjail.");
}
else
{
activeChar.sendMessage("Player not found !");
return false;
}
}
}
return true;
}
/**
*
* @see ru.l2open.gameserver.handler.IVoicedCommandHandler#getVoicedCommandList()
*/
public String[] getVoicedCommandList()
{
return VOICED_COMMANDS;
}
}
Кто сможет помочь его дописать и если надо еще выложу вывод в конфиг и добавления в handler.voicedcommandhandlers
Добавлено через 13 минут
еще вопрос как добавить в верхний скрипт вот это? кому не сложно помогите
Код:
private boolean changeCharAccessLevel(L2PcInstance targetPlayer, String player, L2PcInstance activeChar, int lvl)
{
if (targetPlayer != null)
{
targetPlayer.setAccessLevel(lvl);
targetPlayer.sendChatMessage(0, Say2.ALL, "SYS", "Your character has been banned. Good Bye.");
targetPlayer.logout();
RegionBBSManager.getInstance().changeCommunityBoard();
activeChar.sendChatMessage(0, Say2.ALL, "SYS", "The character " + targetPlayer.getName() + " has now been banned.");
}
else
{
Connection con = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("UPDATE characters SET accesslevel=? WHERE char_name=?");
statement.setInt(1, lvl);
statement.setString(2, player);
statement.execute();
int count = statement.getUpdateCount();
statement.close();
if (count == 0)
{
activeChar.sendChatMessage(0, Say2.ALL, "SYS", "Character not found or access level unaltered.");
return false;
}
else
activeChar.sendChatMessage(0, Say2.ALL, "SYS", player + " now has an access level of " + lvl);
}
catch (SQLException se)
{
activeChar.sendChatMessage(0, Say2.ALL, "SYS", "SQLException while changing character's access level.");
if (Config.DEBUG)
se.printStackTrace();
return false;
}
finally
{
L2DatabaseFactory.close(con);
}
}
return true;
}