Jump to content
  • 0

Question

Posted

heya dudes i try to Edit a legend system like that.

 

i made this smaller just added the last 2

private static final String UPDATE_CHARACTER = "UPDATE characters SET ,language=?,punishment_level=?,donator=?,enddate=? WHERE charId=?";

 

private static final String RESTORE_CHARACTER = "SELECT ,language,punishment_level,donator,enddate FROM characters WHERE charId=?";

 

 

private boolean _donator = false;

private long _PremiumEndDate;

 

public boolean isdonator()

{

return _donator;

}

 

public void setdonator(boolean donator)

{

_donator = donator;

}

 

public void setdonator(int donator)

{

return;

}

 

private long enddate()

{

return _PremiumEndDate;

}

 

public void setPremiumEndTime(long endDate)

{

_PremiumEndDate = endDate;

}

 

public long getPremiumEndTime()

{

      return _PremiumEndDate;

}

 

 

all ok

 

that in UPDATE_CHAR 

 

statement.setInt(54, isdonator() ? 1 : 0);

statement.setLong(55, enddate());

 

that in RESTORE_CHAR

 

restorePremServiceData(player,rset.getString("char_name"));

 

now the restorePremServiceData:

 

private static void PStimeOver(String char_name)

{

Connection con = null;

try

{

con = L2DatabaseFactory.getInstance().getConnection();

PreparedStatement statement = con.prepareStatement(UPDATE_CHARACTER);

statement.setInt(1, 0);

statement.setLong(2, 0);

statement.setString(3, char_name);

statement.execute();

statement.close();

}

catch (SQLException e)

{

_log.warning("PremiumService:  Could not increase data");

}

finally

{

L2DatabaseFactory.close(con);

}

}

 

public static void restorePremServiceData(L2PcInstance player, String char_name)

{

boolean sucess = false;

Connection con = null;

try

{

con = L2DatabaseFactory.getInstance().getConnection();

PreparedStatement statement = con.prepareStatement(RESTORE_CHARACTER);

statement.setString(1, char_name);

ResultSet rset = statement.executeQuery();

while (rset.next())

{

sucess = true;

if (Config.USE_LEGENDSERVICE)

{

if (rset.getLong("enddate") <= System.currentTimeMillis())

{

PStimeOver(char_name);

player.setdonator(0);

}

else

{

player.setdonator(rset.getInt("donator")==1);

player.setPremiumEndTime(rset.getLong("enddate"));

}

}

else

player.setdonator(0);

}

 

rset.close();

statement.close();

}

catch (Exception e)

{

_log.warning("PremiumService: Could not restore PremiumService data for:" + char_name + "." + e);

e.printStackTrace();

}

finally

{

L2DatabaseFactory.close(con);

}

 

if (!sucess)

{

player.setdonator(0);

}

}

 

at last the Admincommand:

 

private static final String[] ADMIN_COMMANDS =

{

"admin_premium_menu",

"admin_premium_add1",

"admin_premium_add2",

"admin_premium_add3",

"admin_premium_end"

};

 

private static final String UPDATE_CHARACTER = "UPDATE characters SET donator=?,enddate=? WHERE char_name=?";

private static final Logger _log = Logger.getLogger(AdminPremium.class.getName());

 

@Override

public boolean useAdminCommand(final String command, final L2PcInstance activeChar)

{

if (command.equals("admin_premium_menu"))

{

AdminHelpPage.showHelpPage(activeChar, "premium_menu.htm");

}

else if (command.startsWith("admin_premium_add1"))

{

try

{

final String val = command.substring(19);

addPremiumServices(1, val);

}

catch (final StringIndexOutOfBoundsException e)

{

activeChar.sendMessage("Err");

}

}

else if (command.startsWith("admin_premium_add2"))

{

try

{

final String val = command.substring(19);

addPremiumServices(2, val);

}

catch (final StringIndexOutOfBoundsException e)

{

activeChar.sendMessage("Err");

}

}

else if (command.startsWith("admin_premium_add3"))

{

try

{

final String val = command.substring(19);

addPremiumServices(3, val);

}

catch (final StringIndexOutOfBoundsException e)

{

activeChar.sendMessage("Err");

}

}

else if (command.startsWith("admin_premium_end"))

{

try

{

final String val = command.substring(19);

addPremiumServices(0, val);

}

catch (final StringIndexOutOfBoundsException e)

{

activeChar.sendMessage("Err");

}

}

 

return true;

}

 

private void addPremiumServices(final int Months, final String char_name)

{

Connection con = null;

try

{

final Calendar finishtime = Calendar.getInstance();

finishtime.setTimeInMillis(System.currentTimeMillis());

finishtime.set(Calendar.SECOND, 0);

finishtime.add(Calendar.MONTH, Months);

 

con = L2DatabaseFactory.getInstance().getConnection();

final PreparedStatement statement = con.prepareStatement(UPDATE_CHARACTER);

statement.setInt(1, 1);

statement.setLong(2, finishtime.getTimeInMillis());

statement.setString(3, char_name);

statement.execute();

statement.close();

}

catch (final SQLException e)

{

_log.info("PremiumService:  Could not increase data");

}

finally

{

L2DatabaseFactory.close(con);

}

}

 

all works ok just the problem is after relog char the donator and enddate is 0 every time if i add and they relog its 0 so what happened ?

 

Thanks for help

5 answers to this question

Recommended Posts

  • 0
Posted

i didnt read all of that, but you use database to save the premium state, so its good to know if you dont save or dont load that data, so set some1 premium and take a look at te database if the changes are done

  • 0
Posted

ye he did change but on relog char he will set it back to 0.

 

and it must be at donator =1 and enddate= the time for 1,2 or 3 month.

 

after relog char, it is 0. thanks for help

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...

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