Конечно есть исходы) 1) итем 2) сам псхендлер
public class DonatorCustomItem implements IItemHandler
{
public DonatorCustomItem()
{
//null
}
protected static final Logger _log = Logger.getLogger(DonatorCustomItem.class.getName());
String INSERT_DATA = "REPLACE INTO characters_custom_data (obj_Id, char_name, hero, noble, donator, donator_end_date) VALUES (?,?,?,?,?,?)";
@Override
public void useItem(L2PlayableInstance playable, L2ItemInstance item)
{
if(Config.DONATOR_CUSTOM_ITEMS)
{
if(!(playable instanceof L2PcInstance))
return;
L2PcInstance activeChar = (L2PcInstance) playable;
if(activeChar.isInOlympiadMode())
{
activeChar.sendMessage("This Item Cannot Be Used On Olympiad Games.");
}
if(activeChar.isDonator())
{
activeChar.sendMessage("You Are Already A Premium!.");
}
else
{
long dtime = System.currentTimeMillis() + (Config.DONATOR_CUSTOM_DAY * 1L * 1L * 60L * 1000L);
activeChar.broadcastPacket(new SocialAction(activeChar.getObjectId(), 16));
activeChar.setDonator(true);
activeChar.setHero(true);
activeChar.setDonatorEnd(dtime);
updateDatabase(activeChar, dtime);
activeChar.sendMessage("You Are Now a Premium user");
activeChar.broadcastUserInfo();
playable.destroyItem("Consume", item.getObjectId(), 1, null, false);
//activeChar.getInventory().addItem("Wings", 6842, 1, activeChar, null);
}
activeChar = null;
}
}
@Override
public int[] getItemIds()
{
return ITEM_IDS;
}
private void updateDatabase(L2PcInstance player, long donatorTime)
{
Connection con = null;
try
{
if(player == null)
return;
con = L2DatabaseFactory.getInstance().getConnection(false);
PreparedStatement stmt = con.prepareStatement(INSERT_DATA);
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.setLong(6, donatorTime);
stmt.execute();
stmt.close();
stmt = null;
}
catch(Exception e)
{
if(Config.ENABLE_ALL_EXCEPTIONS)
e.printStackTrace();
_log.log(Level.SEVERE, "Error: could not update database: ", e);
}
finally
{
CloseUtil.close(con);
con = null;
}
}
private static final int ITEM_IDS[] =
{
Config.DONATOR_CUSTOM_ITEM_ID
};
}
* restore all Custom Data hero/noble/donator.
*/
public void restoreCustomStatus()
{
if(Config.DEVELOPER)
{
_log.info("Restoring character status "+getName()+" from database...");
}
int hero = 0;
int noble = 0;
int donator = 0;
long hero_end = 0;
long donator_end = 0;
Connection con = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection(false);
PreparedStatement statement = con.prepareStatement(STATUS_DATA_GET);
statement.setInt(1, getObjectId());
ResultSet rset = statement.executeQuery();
while(rset.next())
{
hero = rset.getInt("hero");
noble = rset.getInt("noble");
donator = rset.getInt("donator");
hero_end = rset.getLong("hero_end_date");
donator_end = rset.getLong("donator_end_date");
setDonatorEnd(donator_end);
}
rset.close();
statement.close();
statement = null;
rset = null;
}
catch(Exception e)
{
if(Config.ENABLE_ALL_EXCEPTIONS)
e.printStackTrace();
_log.warning("Error: could not restore char custom data info: " + e);
}
finally
{
CloseUtil.close(con);
}
if(hero > 0 && (hero_end == 0 || hero_end > System.currentTimeMillis()))
{
setIsHero(true);
}else{
//delete wings of destiny
destroyItem("HeroEnd", 6842, 1, null, false);
}
if(donator > 0 && (donator_end == 0 || donator_end > System.currentTimeMillis()))
{
setDonator(true);
}else{
setIsHero(false);
}
if(noble > 0)
{
setNoble(true);
}
}