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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...