Jump to content
  • 0

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


Question

Posted

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

4 answers to this question

Recommended Posts

  • 0
Posted

Sorry you have to speak better english.

 

[Offtopic]

Se quiseres escreve em brazileiro que eu leio,o teu inglês é ilegivel

  • 0
Posted

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.

  • 0
Posted

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.

  • 0
Posted

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.

Guest
This topic is now closed to further replies.


  • Posts

    • “Hello, I’d like to present a short description of the server. Everyone starts equally at max level 80. The server includes a custom buffer, custom class master, custom weapons and armors, custom zones, custom teleporter, custom raid bosses, and much more. I’ll leave a link in the description for those who want to see how everything looks inside. The server is only open on weekends, and you can find more news via the Facebook link.”   https://www.facebook.com/profile.php?id=61578869175323
    • 1. You where subscriber 3 years ago. 2. There is no current L2jMobius 2.8 Seven Signs version. Subcriber or not. 3. You have your answer from multiple forums that more items is more delay.  
    • 1. Optimize Packet Serialization Look in ItemList.java or wherever the inventory packet is constructed. Instead of building the packet with inefficient string concatenation or repeated allocations, use a preallocated buffer and avoid creating new objects for each item. Mobius sources are Java-based, so profiling with something like VisualVM or YourKit can help see where most time is spent. 2. Avoid Sending the Full List Each Time Modify the server to send only changed items (diff packets) when the inventory window opens. Some newer forks implement this as “lazy loading” or paged inventory so the client only loads e.g. 100 items at a time. 3. Limit the Inventory Size Per Page Instead of showing all 500 slots at once, split the inventory into pages/tabs (100 slots each). When the user switches a tab, send only that page’s items. This requires some client-side editing, but it’s the most user-friendly long-term fix. 4. Database & Cache Optimizations Ensure your items table is indexed by owner_id to make the query for player items fast. Cache item templates and static data so they are not reloaded every time the inventory is shown. ⚠️ Things to Keep in Mind Increasing slots from 80 → 500 does not just change a number — it multiplies the workload for packet building and UI rendering. You can’t fully avoid some extra cost with 500 items, but you can keep it under a few milliseconds if you optimize how and when the data is sent.    
    • i think it's the auto sorting of the interface that sucks, check InventoryWnd script in interface.u, or completely disable the request item list packet when toggling the inventory window (also in InventoryWnd script or similar name)
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock