Jump to content
  • 0

[HELP] How to add line to remove weapons in Code Java ?


rafiuskyz

Question

how do I add a command line when to remove the member VIP also remove a weapon that the inventory?

 

see the code...

 

package com.l2j.gameserver.handler.admincommandhandlers;

import java.sql.Connection;
import java.sql.PreparedStatement;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.l2j.L2DatabaseFactory;
import com.l2j.gameserver.Announcements;
import com.l2j.gameserver.datatables.GmListTable;
import com.l2j.gameserver.handler.IAdminCommandHandler;
import com.l2j.gameserver.model.L2Object;
import com.l2j.gameserver.model.actor.instance.L2PcInstance;
import com.l2j.gameserver.network.serverpackets.SocialAction;

public class AdminVip implements IAdminCommandHandler
{
private static String[]		ADMIN_COMMANDS	=
											{ "admin_setvip" };
private final static Log	_log			= LogFactory.getLog(AdminVip.class.getName());

public boolean useAdminCommand(String command, L2PcInstance activeChar)
{
	if (activeChar == null)
		return false;

	if (command.startsWith("admin_setvip"))
	{
		L2Object target = activeChar.getTarget();

		if (target instanceof L2PcInstance)
		{
			L2PcInstance targetPlayer = (L2PcInstance) target;
			boolean newVip = !targetPlayer.isCharViP();

			if (newVip)
			{
				targetPlayer.setCharViP(true);
				targetPlayer.updateNameTitleColor();
				updateDatabase(activeChar, true);
				sendMessages(true, targetPlayer, activeChar, true, true);
				targetPlayer.broadcastPacket(new SocialAction(targetPlayer.getObjectId(), 16)); 
				targetPlayer.broadcastUserInfo();
			}
			else
			{
					targetPlayer.setCharViP(false);
				targetPlayer.updateNameTitleColor();
				updateDatabase(activeChar, false);
				sendMessages(false, targetPlayer, activeChar, true, true);
				targetPlayer.broadcastUserInfo();
			}
		}
		else
		{
			activeChar.sendMessage("Impossible to set a non Player Target as VIP.");
			_log.info("GM: " + activeChar.getName() + " is trying to set a non Player Target as VIP.");
			return false;
		}
	}
	return true;
}

private void sendMessages(boolean fornewVip, L2PcInstance player, L2PcInstance gm, boolean announce, boolean notifyGmList)
{
	if (fornewVip)
	{
		player.sendMessage(gm.getName() + " has granted VIP Status for you!");
		gm.sendMessage("You've granted VIP Status for " + player.getName());

		if (announce)
			Announcements.getInstance().announceToAll(player.getName() + " has received VIP Status!");

		if (notifyGmList)
			GmListTable.broadcastMessageToGMs("Warn: " + gm.getName() + " has Set " + player.getName() + " as VIP !");
	}
	else
	{
		player.sendMessage(gm.getName() + " has revoked VIP Status from you!");
		gm.sendMessage("You've revoked VIP Status from " + player.getName());

		if (announce)
			Announcements.getInstance().announceToAll(player.getName() + " has lost VIP Status!");

		if (notifyGmList)
			GmListTable.broadcastMessageToGMs("Warn: " + gm.getName() + " has removed VIP Status of player" + player.getName());
	}
}

/**
 *
 * @param activeChar
 * @param newDonator
 */
private void updateDatabase(L2PcInstance player, boolean newVIP)
{
	Connection con = null;
	try
	{
		// prevents any NPE.
		// ----------------
		if (player == null)
			return;

		// Database Connection
		//--------------------------------
		con = L2DatabaseFactory.getInstance().getConnection();
		PreparedStatement stmt = con.prepareStatement(newVIP ? INSERT_DATA : DEL_DATA);

		// if it is a new donator insert proper data
		// --------------------------------------------
		if (newVIP)
		{
			stmt.setInt(1, player.getObjectId());
			stmt.setString(2, player.getName());
			stmt.setInt(3, player.isHero() ? 1 : 0);
			stmt.setInt(4, player.isNoble() ? 1 : 0);
			stmt.setInt(5, player.isDonator() ? 1 : 0);
			stmt.setInt(6, 1);
			stmt.execute();
			stmt.close();
		}
		else
		// deletes from database
		{
			stmt.setInt(1, player.getObjectId());
			stmt.execute();
			stmt.close();
		}
	}
	catch (Exception e)
	{
		_log.error("Error: could not update database: ", e);
	}
	finally
	{
		try
		{
			con.close();
		}
		catch (Exception e)
		{
			_log.error("Error: could not update database: ", e);
		}
	}
}

// Updates That Will be Executed by MySQL
// ----------------------------------------
String	INSERT_DATA	= "REPLACE INTO characters_custom_data (obj_Id, char_name, hero, noble, donator, vip) VALUES (?,?,?,?,?,?)";
String	DEL_DATA	= "UPDATE characters_custom_data SET vip = 0 WHERE obj_Id=?";

/**
 * @return
 */
public String[] getAdminCommandList()
{
	return ADMIN_COMMANDS;
}
}

 

thxx

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Sorry i use translator!

 

Vamos la, estou querendo adicionar um linha de comando para quando eu remover o membro VIP remova também um certo item que esta no inventario dele, uma Weapon por exemplo.

 

Postei o código do AdminCommand //setvip no post antigo.

Link to comment
Share on other sites

  • 0

Sorry i use translator!

 

Vamos la, estou querendo adicionar um linha de comando para quando eu remover o membro VIP remova também um certo item que esta no inventario dele, uma Weapon por exemplo.

 

Postei o código do AdminCommand //setvip no post antigo.

Just use L2PcInstance player = null; player.getInventory().deleteItem(itemId);

I don't have eclipse on this PC so the method names might be wrong,but thats basically it.

Link to comment
Share on other sites

  • 0

In setvip, something like (example of my aio systtem):

 

_player.getInventory().addItem("", Config.AIO_ITEMID, 1, _player, null);

 

and to remove

 

_player.getInventory().destroyItemByItemId("", Config.AIO_ITEMID, 1, _player, null);
_player.getWarehouse().destroyItemByItemId("", Config.AIO_ITEMID, 1, _player, null);

 

WH check in case, he put the item into wh.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...