/* * 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 silentium.scripts.handlers.admin; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import silentium.gameserver.data.html.StaticHtmPath; import silentium.gameserver.handler.IAdminCommandHandler; import silentium.gameserver.model.L2Object; import silentium.gameserver.model.actor.instance.L2PcInstance; import silentium.gameserver.network.SystemMessageId; import silentium.gameserver.network.clientpackets.Say2; import silentium.gameserver.network.serverpackets.NpcHtmlMessage; import java.util.StringTokenizer; /** * This class handles following admin commands: <li>add_exp_sp_to_character <i>shows menu for add or remove</i> <li>add_exp_sp exp sp <i>Adds exp * & sp to target, displays menu if a parameter is missing</i> <li>remove_exp_sp exp sp <i>Removes exp & sp from target, displays menu if a * parameter is missing</i> */ public class AdminExpSp implements IAdminCommandHandler { private static final Logger _log = LoggerFactory.getLogger(AdminExpSp.class.getName()); private static final String[] ADMIN_COMMANDS = { "admin_add_exp_sp_to_character", "admin_add_exp_sp", "admin_remove_exp_sp" }; @Override public boolean useAdminCommand(final String command, final L2PcInstance activeChar) { if (command.startsWith("admin_add_exp_sp")) { try { final String val = command.substring(16); if (!adminAddExpSp(activeChar, val)) activeChar.sendChatMessage(0, Say2.ALL, "SYS", "Usage: //add_exp_sp exp sp"); } catch (StringIndexOutOfBoundsException e) { // Case of missing parameter activeChar.sendChatMessage(0, Say2.ALL, "SYS", "Usage: //add_exp_sp exp sp"); } } else if (command.startsWith("admin_remove_exp_sp")) { try { final String val = command.substring(19); if (!adminRemoveExpSP(activeChar, val)) activeChar.sendChatMessage(0, Say2.ALL, "SYS", "Usage: //remove_exp_sp exp sp"); } catch (StringIndexOutOfBoundsException e) { // Case of missing parameter activeChar.sendChatMessage(0, Say2.ALL, "SYS", "Usage: //remove_exp_sp exp sp"); } } addExpSp(activeChar); return true; } @Override public String[] getAdminCommandList() { return ADMIN_COMMANDS; } private static void addExpSp(final L2PcInstance activeChar) { final L2Object target = activeChar.getTarget(); L2PcInstance player = null; if (target instanceof L2PcInstance) player = (L2PcInstance) target; else { activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET); return; } final NpcHtmlMessage adminReply = new NpcHtmlMessage(5); adminReply.setFile(StaticHtmPath.AdminHtmPath + "expsp.htm", player); adminReply.replace("%name%", player.getName()); adminReply.replace("%level%", String.valueOf(player.getLevel())); adminReply.replace("%xp%", String.valueOf(player.getExp())); adminReply.replace("%sp%", String.valueOf(player.getSp())); adminReply.replace("%class%", player.getTemplate().className); activeChar.sendPacket(adminReply); } private static boolean adminAddExpSp(final L2PcInstance activeChar, final String ExpSp) { final L2Object target = activeChar.getTarget(); L2PcInstance player = null; if (target instanceof L2PcInstance) { player = (L2PcInstance) target; } else { activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET); return false; } final StringTokenizer st = new StringTokenizer(ExpSp); if (st.countTokens() != 2) return false; final String exp = st.nextToken(); final String sp = st.nextToken(); long expval = 0; int spval = 0; try { expval = Long.parseLong(exp); spval = Integer.parseInt(sp); } catch (Exception e) { return false; } if (expval != 0 || spval != 0) { // Common character information player.sendMessage("Admin is adding you " + expval + " xp and " + spval + " sp."); player.addExpAndSp(expval, spval); // Admin information activeChar.sendChatMessage(0, Say2.ALL, "SYS", "Added " + expval + " xp and " + spval + " sp to " + player.getName() + '.'); _log.info("GM: " + activeChar.getName() + '(' + activeChar.getObjectId() + ") added " + expval + " xp " + "and " + spval + " sp to " + player.getObjectId() + '.'); } return true; } private static boolean adminRemoveExpSP(final L2PcInstance activeChar, final String ExpSp) { final L2Object target = activeChar.getTarget(); L2PcInstance player = null; if (target instanceof L2PcInstance) { player = (L2PcInstance) target; } else { activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET); return false; } final StringTokenizer st = new StringTokenizer(ExpSp); if (st.countTokens() != 2) return false; final String exp = st.nextToken(); final String sp = st.nextToken(); long expval = 0; int spval = 0; try { expval = Long.parseLong(exp); spval = Integer.parseInt(sp); } catch (Exception e) { return false; } if (expval != 0 || spval != 0) { // Common character information player.sendMessage("Admin is removing you " + expval + " xp and " + spval + " sp."); player.removeExpAndSp(expval, spval); // Admin information activeChar.sendChatMessage(0, Say2.ALL, "SYS", "Removed " + expval + " xp and " + spval + " sp from " + player.getName() + '.'); _log.info("GM: " + activeChar.getName() + '(' + activeChar.getObjectId() + ") removed " + expval + " xp " + "and " + spval + " sp from " + player.getObjectId() + '.'); } return true; } }