Jump to content

l2jkain

Members
  • Content Count

    200
  • Joined

  • Last visited

  • Feedback

    0%

Community Reputation

1 Neutral

About l2jkain

  • Rank
    Knight

Contact Methods

  • Website URL
    http://l2jkain.com

Profile Information

  • Gender
    Male
  • Country
    Brazil

Recent Profile Visitors

1,183 profile views
  1. Hello, I'm trying to put some time in some items, however the items added in the config are not saving in my database, would anyone help me solve this? code complete : https://pastebin.com/raw/y3B7Cvfk Class responsible for saving and removing from database package net.sf.l2j.gameserver.data.sql; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Logger; import net.sf.l2j.Config; import net.sf.l2j.L2DatabaseFactory; import net.sf.l2j.gameserver.model.World; import net.sf.l2j.gameserver.model.WorldObject; import net.sf.l2j.gameserver.model.actor.instance.Player; import net.sf.l2j.gameserver.model.item.instance.ItemInstance; import net.sf.l2j.gameserver.network.SystemMessageId; import net.sf.l2j.gameserver.network.serverpackets.ItemList; import net.sf.l2j.gameserver.network.serverpackets.SystemMessage; import net.sf.l2j.gameserver.taskmanager.ItemsTaskManager; public class TimedItemTable public final Map<Integer, Info> _timedItems = new ConcurrentHashMap<>(); { private static Logger _log = Logger.getLogger(TimedItemTable.class.getName()); public class Info { int _charId; int _itemId; long _activationTime; } public static final TimedItemTable getInstance() { return SingletonHolder._instance; } private static class SingletonHolder { protected static final TimedItemTable _instance = new TimedItemTable(); } public TimedItemTable() { restore(); _startControlTask.schedule(60000); } public boolean getActiveTimed(Player player, boolean trade) { for (Info i : _timedItems.values()) { if ((i != null) && (i._charId == player.getObjectId())) { ItemInstance item = player.getInventory().getItemByObjectId(i._itemId); if (item != null) { if (System.currentTimeMillis() < i._activationTime) return true; } } } return false; } public synchronized void destroy(ItemInstance item) { Info inf = _timedItems.get(item.getObjectId()); if (inf != null) { _timedItems.remove(inf._itemId); try (Connection con = L2DatabaseFactory.getInstance().getConnection()) { PreparedStatement statement = con.prepareStatement("DELETE FROM character_timed_items WHERE charId = ? AND itemId = ?"); statement.setInt(1, inf._charId); statement.setInt(2, inf._itemId); statement.execute(); statement.close(); } catch (Exception e) { e.printStackTrace(); } } } public synchronized void setTimed(ItemInstance item) { Info inf = _timedItems.get(item.getObjectId()); if (inf != null) inf._charId = item.getOwnerId(); else { inf = new Info(); inf._activationTime = (System.currentTimeMillis() / 1000) + (Config.TIMED_ITEM_TIME * 60); inf._charId = item.getOwnerId(); inf._itemId = item.getObjectId(); _timedItems.put(inf._itemId, inf); } saveToDb(inf); } public boolean isActive(ItemInstance item) { for (Info i : _timedItems.values()) { if (i._itemId == item.getObjectId()) return true; } return false; } private void restore() { try (Connection con = L2DatabaseFactory.getInstance().getConnection()) { PreparedStatement statement = con.prepareStatement("SELECT charId, itemId, time FROM character_timed_items"); ResultSet rs = statement.executeQuery(); while (rs.next()) { Info inf = new Info(); inf._activationTime = rs.getLong("time"); inf._charId = rs.getInt("charId"); inf._itemId = rs.getInt("itemId"); _timedItems.put(inf._itemId, inf); } rs.close(); statement.close(); _log.info("loaded " + _timedItems.size() + " Timed Items "); } catch (Exception e) { e.printStackTrace(); } } @SuppressWarnings("resource") private static void saveToDb(Info temp) { try (Connection con = L2DatabaseFactory.getInstance().getConnection()) { PreparedStatement statement = con.prepareStatement("UPDATE character_timed_items set charId = ? where itemId = ?"); statement.setInt(1, temp._charId); statement.setInt(2, temp._itemId); if (statement.executeUpdate() == 0) { statement = con.prepareStatement("INSERT INTO character_timed_items (charId, itemId, time) VALUES (?, ?, ?)"); statement.setInt(1, temp._charId); statement.setInt(2, temp._itemId); statement.setLong(3, temp._activationTime); statement.execute(); statement.close(); } } catch (Exception e) { e.printStackTrace(); } } @SuppressWarnings("resource") public void delete(Info temp) { _timedItems.remove(temp._itemId); try (Connection con = L2DatabaseFactory.getInstance().getConnection()) { PreparedStatement statement = con.prepareStatement("DELETE FROM character_timed_items WHERE charId =? AND itemId =?"); statement.setInt(1, temp._charId); statement.setInt(2, temp._itemId); statement.execute(); } catch (Exception e) { e.printStackTrace(); } Player player = World.getInstance().getPlayer(temp._charId); if (player != null) { ItemInstance item = player.getInventory().getItemByObjectId(temp._itemId); if (item.isEquipped()) player.getInventory().unEquipItemInSlot(item.getLocationSlot()); player.getInventory().destroyItem("timeLost", item, player, player); player.sendPacket(new ItemList(player, false)); player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_DISAPPEARED).addItemName(item.getItemId())); } else { try (Connection con = L2DatabaseFactory.getInstance().getConnection();) { if (temp._charId != 0) { try (PreparedStatement statement = con.prepareStatement("DELETE FROM items WHERE owner_id = ? AND object_id = ?");) { statement.setInt(1, temp._charId); statement.setInt(2, temp._itemId); statement.execute(); statement.close(); } } else { for (WorldObject o : World.getInstance().getObjects()) { if (o.getObjectId() == temp._itemId) { World.getInstance().removeObject(o); break; } } } } catch (Exception e) { e.printStackTrace(); } } } private final ItemsTaskManager _startControlTask = new ItemsTaskManager() { @Override protected void onElapsed() { for (Info temp : _timedItems.values()) { if (temp._activationTime < (System.currentTimeMillis() / 1000)) delete(temp); } schedule(60000); } }; }
  2. Hello, this event I was creating, but I do not know what else to do, I took a lot of it out and there is a lot to be removed, I can not finish it any more, so anyone who wants to finish is a good event... https://pastebin.com/raw/x9GwZugx
  3. ### Eclipse Workspace Patch 1.0 #P aCis_Gameserver Index: java/net/sf/l2j/gameserver/model/multisell/Ingredient.java =================================================================== --- java/net/sf/l2j/gameserver/model/multisell/Ingredient.java (revision 15) +++ java/net/sf/l2j/gameserver/model/multisell/Ingredient.java (working copy) @@ -22,14 +22,14 @@ public Ingredient(StatsSet set) { + this(set.getInteger("id"), set.getInteger("count"), set.getInteger("enchantmentLevel", 0), set.getBool("isTaxIngredient", false), set.getBool("maintainIngredient", false)); - this(set.getInteger("id"), set.getInteger("count"), set.getBool("isTaxIngredient", false), set.getBool("maintainIngredient", false)); } + public Ingredient(int itemId, int itemCount, int enchantmentLevel, boolean isTaxIngredient, boolean maintainIngredient) - public Ingredient(int itemId, int itemCount, boolean isTaxIngredient, boolean maintainIngredient) { _itemId = itemId; _itemCount = itemCount; + _enchantmentLevel = enchantmentLevel; - _isTaxIngredient = isTaxIngredient; _maintainIngredient = maintainIngredient; @@ -42,7 +42,7 @@ */ public Ingredient getCopy() { + return new Ingredient(_itemId, _itemCount, _enchantmentLevel, _isTaxIngredient, _maintainIngredient); - return new Ingredient(_itemId, _itemCount, _isTaxIngredient, _maintainIngredient); } public final int getItemId() Index: java/net/sf/l2j/gameserver/model/multisell/PreparedEntry.java =================================================================== --- java/net/sf/l2j/gameserver/model/multisell/PreparedEntry.java (revision 15) +++ java/net/sf/l2j/gameserver/model/multisell/PreparedEntry.java (working copy) @@ -48,7 +48,7 @@ // now add the adena, if any. adenaAmount += _taxAmount; // do not forget tax if (adenaAmount > 0) + _ingredients.add(new Ingredient(57, adenaAmount, 0, false, false)); - _ingredients.add(new Ingredient(57, adenaAmount, false, false)); // now copy products _products = new ArrayList<>(template.getProducts().size());
×