Jump to content
  • 0

[HELP] Java Script


Question

Posted

Hi all i decided to write my custom community buffer.

first i wrote only to save buffs and get it and then i decided to add Scheme Function in it so i stucked here.

can anyone help me how to add String Name  in the code to save also in sql?

 

private void saveBuff()
{
	Map<Integer, Integer> ceffects = new FastMap<Integer, Integer>();	
	L2Character character;
    if (character == null)
	{
		return;
	}		
	if (ceffects.isEmpty())
	{
		return;
	}
	if(character.getAllEffects() == null)
	{
		return;
	}	
    for (L2Effect cureffect : character.getAllEffects())
    {
		int idSklll = cureffect.getSkill().getId();
		int lvlSklll = cureffect.getLevel();
		if(character.getAllEffects() != null)
		{
			ceffects.put(idSklll, lvlSklll);// TODO support for Scheme String Name
		}	
	}
	this._bbsBuff.clear();
	this._bbsBuff.putAll(ceffects);
	saveBuffSQL();
}

private void saveBuffSQL()
{
	try(Connection con = L2DatabaseFactory.getInstance().getConnection())
	{		
		PreparedStatement statement = con.prepareStatement("DELETE FROM character_bbs_buff_save WHERE charId=?");
		statement.setInt(1, getObjectId());
		statement.execute();
		statement.close();

		for (Map.Entry<Integer, Integer> entry : ceffects.entrySet())
		{
			statement = con.prepareStatement("INSERT INTO character_bbs_buff_save (charId,skill_id,skill_level) VALUES (?,?,?)");
			statement.setInt(1, getObjectId());
			statement.setInt(2, entry.getKey().intValue());
			statement.setInt(3, entry.getValue().intValue());
			statement.execute();
			statement.close();
		}
	}
	catch (Exception e)
	{
		_log.log(Level.WARNING, "Could not store char effect data: ", e);
	}				
}

6 answers to this question

Recommended Posts

  • 0
Posted

 

I love the photos very much, where did you take it? The light, shadow and portion are superb and excellent, wish i could take photos like yours pretty soon! By the way i'd like to recommend a good shopping website, all the replica tote bags are manufactured with 100% real leather,durable hardwares ,excellent craftsmanship, click here  right now!

  • 0
Posted
statement.setString(1, parameter_here)

is it correct ?

 

private void saveBuff(L2PcInstance activeChar, String SchemeName)
{
	L2Character character = activeChar;
    if (character == null)
	{
		return;
	}		
	if (ceffects.isEmpty())
	{
		return;
	}
	if(character.getAllEffects() == null)
	{
		return;
	}	
    for (L2Effect cureffect : character.getAllEffects())
    {
		int idSklll = cureffect.getSkill().getId();
		int lvlSklll = cureffect.getLevel();
		if(character.getAllEffects() != null)
		{
			ceffects.put(idSklll, lvlSklll);// TODO support for Scheme String Name
		}	
	}
	this._bbsBuff.clear();
	this._bbsBuff.putAll(ceffects);
	saveBuffSQL(activeChar,SchemeName);
}	

private void saveBuffSQL(L2PcInstance activeChar, String SchemeName)
{
	try(Connection con = L2DatabaseFactory.getInstance().getConnection())
	{		
		PreparedStatement statement = con.prepareStatement("DELETE FROM character_bbs_buff_save WHERE charId=?");
		statement.setInt(1, activeChar.getObjectId());
		statement.execute();
		statement.close();

		for (Map.Entry<Integer, Integer> entry : ceffects.entrySet())
		{
			statement = con.prepareStatement("INSERT INTO character_bbs_buff_save (charId,scheme_name,skill_id,skill_level) VALUES (?,?,?,?)");
			statement.setInt(1, activeChar.getObjectId());
			statement.setString(2, SchemeName);
			statement.setInt(3, entry.getKey().intValue());
			statement.setInt(4, entry.getValue().intValue());
			statement.execute();
			statement.close();
		}
	}
	catch (Exception e)
	{
		_log.log(Level.WARNING, "Could not store char effect data: ", e);
	}				
}	

  • 0
Posted

execute() will try to update everything into the SQl database, but executeUpdate() will online update INSERT,DELETE,UPDATE commands which in your case is a lot faster

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..

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