/* * This file is part of the L2J Mobius project. * * 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 . */ package handlers.admincommandhandlers; import java.util.Collection; import java.util.StringTokenizer; import com.l2jmobius.gameserver.handler.IAdminCommandHandler; import com.l2jmobius.gameserver.instancemanager.CursedWeaponsManager; import com.l2jmobius.gameserver.model.CursedWeapon; import com.l2jmobius.gameserver.model.L2Object; import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance; import com.l2jmobius.gameserver.network.SystemMessageId; import com.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage; /** * This class handles following admin commands: - cw_info = displays cursed weapon status - cw_remove = removes a cursed weapon from the world, item id or name must be provided - cw_add = adds a cursed weapon into the world, item id or name must be provided. Target will be the weilder - cw_goto = * teleports GM to the specified cursed weapon - cw_reload = reloads instance manager * @version $Revision: 1.1.6.3 $ $Date: 2007/07/31 10:06:06 $ */ public class AdminCursedWeapons implements IAdminCommandHandler { private static final String[] ADMIN_COMMANDS = { "admin_cw_info", "admin_cw_remove", "admin_cw_goto", "admin_cw_reload", "admin_cw_add", "admin_cw_info_menu" }; private int itemId; @Override public boolean useAdminCommand(String command, L2PcInstance activeChar) { final CursedWeaponsManager cwm = CursedWeaponsManager.getInstance(); int id = 0; final StringTokenizer st = new StringTokenizer(command); st.nextToken(); if (command.startsWith("admin_cw_info")) { if (!command.contains("menu")) { activeChar.sendMessage("====== Cursed Weapons: ======"); for (CursedWeapon cw : cwm.getCursedWeapons()) { activeChar.sendMessage("> " + cw.getName() + " (" + cw.getItemId() + ")"); if (cw.isActivated()) { final L2PcInstance pl = cw.getPlayer(); activeChar.sendMessage(" Player holding: " + (pl == null ? "null" : pl.getName())); activeChar.sendMessage(" Player Reputation: " + cw.getPlayerReputation()); activeChar.sendMessage(" Time Remaining: " + (cw.getTimeLeft() / 60000) + " min."); activeChar.sendMessage(" Kills : " + cw.getNbKills()); } else if (cw.isDropped()) { activeChar.sendMessage(" Lying on the ground."); activeChar.sendMessage(" Time Remaining: " + (cw.getTimeLeft() / 60000) + " min."); activeChar.sendMessage(" Kills : " + cw.getNbKills()); } else { activeChar.sendMessage(" Don't exist in the world."); } activeChar.sendPacket(SystemMessageId.EMPTY3); } } else { final Collection cws = cwm.getCursedWeapons(); final StringBuilder replyMSG = new StringBuilder(cws.size() * 300); final NpcHtmlMessage adminReply = new NpcHtmlMessage(0, 1); adminReply.setFile(activeChar.getHtmlPrefix(), "data/html/admin/cwinfo.htm"); for (CursedWeapon cw : cwm.getCursedWeapons()) { itemId = cw.getItemId(); replyMSG.append(""); if (cw.isActivated()) { final L2PcInstance pl = cw.getPlayer(); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); } else if (cw.isDropped()) { replyMSG.append(""); replyMSG.append(""); } else { replyMSG.append(""); } replyMSG.append("
Name:"); replyMSG.append(cw.getName()); replyMSG.append("
Weilder:"); replyMSG.append(pl == null ? "null" : pl.getName()); replyMSG.append("
Karma:"); replyMSG.append(cw.getPlayerReputation()); replyMSG.append("
Kills:"); replyMSG.append(cw.getPlayerPkKills()); replyMSG.append("/"); replyMSG.append(cw.getNbKills()); replyMSG.append("
Time remaining:"); replyMSG.append(cw.getTimeLeft() / 60000); replyMSG.append(" min.
Position:Lying on the ground
Time remaining:"); replyMSG.append(cw.getTimeLeft() / 60000); replyMSG.append(" min.
Kills:"); replyMSG.append(cw.getNbKills()); replyMSG.append("
Position:Doesn't exist.

"); } adminReply.replace("%cwinfo%", replyMSG.toString()); activeChar.sendPacket(adminReply); } } else if (command.startsWith("admin_cw_reload")) { cwm.load(); } else { CursedWeapon cw = null; try { String parameter = st.nextToken(); if (parameter.matches("[0-9]*")) { id = Integer.parseInt(parameter); } else { parameter = parameter.replace('_', ' '); for (CursedWeapon cwp : cwm.getCursedWeapons()) { if (cwp.getName().toLowerCase().contains(parameter.toLowerCase())) { id = cwp.getItemId(); break; } } } cw = cwm.getCursedWeapon(id); } catch (Exception e) { activeChar.sendMessage("Usage: //cw_remove|//cw_goto|//cw_add "); } if (cw == null) { activeChar.sendMessage("Unknown cursed weapon ID."); return false; } if (command.startsWith("admin_cw_remove ")) { cw.endOfLife(); } else if (command.startsWith("admin_cw_goto ")) { cw.goTo(activeChar); } else if (command.startsWith("admin_cw_add")) { if (cw.isActive()) { activeChar.sendMessage("This cursed weapon is already active."); } else { final L2Object target = activeChar.getTarget(); if (target instanceof L2PcInstance) { ((L2PcInstance) target).addItem("AdminCursedWeaponAdd", id, 1, target, true); } else { activeChar.addItem("AdminCursedWeaponAdd", id, 1, activeChar, true); } cw.setEndTime(System.currentTimeMillis() + (cw.getDuration() * 60000L)); cw.reActivate(); } } else { activeChar.sendMessage("Unknown command."); } } return true; } @Override public String[] getAdminCommandList() { return ADMIN_COMMANDS; } }