Рейтинг темы:
  • 0 Голос(ов) - 0 в среднем
  • 1
  • 2
  • 3
  • 4
  • 5
Скрипт для Модера
#1
Столкнулся с такой проблемой при доделывании скрипта не как не могу добавить в него бан чара когда тот в оффе и разбан чара вот скрипт
Код:
/*
* 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;
    }
Ответ
#2
По поводу первого,
где найдешь :
Код:
L2PcInstance player = L2World.getInstance().getPlayer(objId);
            if (player == null || player.isOnline() == 0)
            {
                 activeChar.sendMessage("Player not online !");
                 return false;
            }
замени на :
Код:
L2PcInstance player = L2World.getInstance().getPlayer(objId);
            if (player == null)
            {
                 activeChar.sendMessage("Player not found !");
                 return false;
            }
Ответ
#3
Array Написал:По поводу первого,
где найдешь :
Код:
L2PcInstance player = L2World.getInstance().getPlayer(objId);
            if (player == null || player.isOnline() == 0)
            {
                 activeChar.sendMessage("Player not online !");
                 return false;
            }
замени на :
Код:
L2PcInstance player = L2World.getInstance().getPlayer(objId);
            if (player == null)
            {
                 activeChar.sendMessage("Player not found !");
                 return false;
            }

Спасибо, но это не поможет, где бан чара там убрана эта функция

Добавлено через 1 час 42 минуты
Так вот подвел 2 скрипт к 1, но всё равно не получается не разбанить чара не забанить если в офе, вот весь скрипт
Код:
/*
* 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.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.StringTokenizer;

import com.l2open.Config;
import com.l2open.L2DatabaseFactory;
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;
import com.l2open.gameserver.network.clientpackets.Say2;

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 == activeChar)
                        {
                            activeChar.sendMessage("You can't ban yourself !");
                            return false;
                        }
                                            
                        return changeCharAccessLevel(params, activeChar, -100);
                                                
                    }
                }
            }
            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);
                        if (player == activeChar)
                        {
                            activeChar.sendMessage("You can't ban yourself !");
                            return false;
                        }
                        
                        return changeCharAccessLevel(params, activeChar, 0);                    
                    }                                        
                }
            }
            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)
                        {
                             activeChar.sendMessage("Player not found !");
                             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)
                        {
                             activeChar.sendMessage("Player not found !");
                             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;
    }
    private boolean changeCharAccessLevel(String params, L2PcInstance activeChar, int lvl)
    {
        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.setAccessLevel(lvl);
            activeChar.sendMessage("The character " + player.getName() + " has now been banned.");
            }
        else
        {        
            StringTokenizer st1 = new StringTokenizer(params);
            if (st1.hasMoreTokens())            
            {
                String name1 = st1.nextToken();                                        
                int objId1 = CharNameTable.getInstance().getIdByName(name1);
                if (objId1 > 0)
                {
                                    
                    L2PcInstance player = L2World.getInstance().getPlayer(objId1);
                    if (player != null)
        {
            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, params);
                statement.execute();
                int count = statement.getUpdateCount();
                statement.close();
                if (count == 0)
                {
                    activeChar.sendMessage("Character not found or access level unaltered.");
                    return false;
                }
                else
                    activeChar.sendMessage( "Player" + player.getName() + " 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;
    }

    /**
     *
     * @see ru.l2open.gameserver.handler.IVoicedCommandHandler#getVoicedCommandList()
     */
    public String[] getVoicedCommandList()
    {
        return VOICED_COMMANDS;
    }
}
Ответ
#4
lxShaDoWxl Написал:Столкнулся с такой проблемой при доделывании скрипта не как не могу добавить в него бан чара когда тот в оффе и разбан чара вот скрипт
Код:
/*
* 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;
    }


хм видал что-то подобное на сервере Какойто чар с определёнными правами ну допустим 20 пишет в чат команду .chat после чего там вводит ник время и причину после выдачи бан чата на весь мир в системный чат красным цветом пишет Модетатор Feyser забанил чат игроку lxShaDoWxl на 100 минут Причина: МАт

Также есть в этой фишке и разбан таково типа как приведённый с верхуSmile

Это оно?

Можно ли исходники этой прелести ?
Ответ
#5
Feyser Написал:хм видал что-то подобное на сервере Какойто чар с определёнными правами ну допустим 20 пишет в чат команду .chat после чего там вводит ник время и причину после выдачи бан чата на весь мир в системный чат красным цветом пишет Модетатор Feyser забанил чат игроку lxShaDoWxl на 100 минут Причина: МАт

Также есть в этой фишке и разбан таково типа как приведённый с верхуSmile

Это оно?

Можно ли исходники этой прелести ?

не это не оно, первый код вполне полный бан чара только не удалось сделать, а так бан чата
Ответ
#6
lxShaDoWxl Написал:не это не оно, первый код вполне полный бан чара только не удалось сделать, а так бан чата

Жаль ...

Давно ищю эту фишку)
Ответ


Возможно похожие темы ...
Тема Автор Ответы Просмотры Последний пост
  Скрипт для альт+б Jm0t 0 1,815 03-21-2019, 04:18 PM
Последний пост: Jm0t
  Помогите переписать скрипт с Python на Java Virrilis3 0 1,478 03-29-2018, 10:55 PM
Последний пост: Virrilis3
  кто может открыть .u формат скрипт? velterna 1 1,926 01-31-2018, 09:49 PM
Последний пост: PROGRAMMATOR
  Скрипт не срабатывает сразу Froust 4 2,384 09-22-2017, 02:14 PM
Последний пост: Froust
  скрипт на превращение зарича по id v1kt0r 3 2,131 05-07-2017, 10:04 PM
Последний пост: Emperor
  Скрипт статистики онлайн серверов NewUser 18 5,001 01-26-2015, 02:33 PM
Последний пост: Apoloser
  Скрипт установки сервера не работает. Linux /. SunWar 2 1,333 08-24-2014, 06:48 PM
Последний пост: SunWar
  Нужен скрипт на услуги донат менеджера (PW Soft) Intruder 3 2,276 05-26-2014, 08:22 AM
Последний пост: Masone
  скрипт Vasya 12 2,876 04-16-2014, 04:33 PM
Последний пост: Cywka!
  скрипт кс Vasya 9 2,260 04-07-2014, 08:20 PM
Последний пост: L2scripts-Guard

Перейти к форуму:


Пользователи, просматривающие эту тему: 2 Гость(ей)