Removed TradeController CSV file compatibility.

This commit is contained in:
MobiusDevelopment
2020-06-10 21:28:54 +00:00
parent 4c3faebdf0
commit 47347785cc

View File

@ -16,10 +16,6 @@
*/
package org.l2jmobius.gameserver;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.LineNumberReader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -74,95 +70,184 @@ public class TradeController
private TradeController()
{
boolean limitedItem = false;
_lists = new HashMap<>();
_listsTaskItem = new HashMap<>();
final File buylistData = new File(Config.DATAPACK_ROOT, "data/buylists.csv");
if (buylistData.exists())
try (Connection con = DatabaseFactory.getConnection())
{
LOGGER.warning("Do, please, remove buylists from data folder and use SQL buylist instead");
String line = null;
FileReader reader = null;
BufferedReader buff = null;
LineNumberReader lnr = null;
final PreparedStatement statement1 = con.prepareStatement("SELECT * FROM merchant_shopids");
final ResultSet rset1 = statement1.executeQuery();
try
while (rset1.next())
{
reader = new FileReader(buylistData);
buff = new BufferedReader(reader);
lnr = new LineNumberReader(buff);
while ((line = lnr.readLine()) != null)
final PreparedStatement statement = con.prepareStatement("SELECT * FROM merchant_buylists WHERE shop_id=? ORDER BY `order` ASC");
statement.setString(1, String.valueOf(rset1.getInt("shop_id")));
final ResultSet rset = statement.executeQuery();
if (rset.next())
{
if ((line.trim().length() == 0) || line.startsWith("#"))
limitedItem = false;
final StoreTradeList buy1 = new StoreTradeList(rset1.getInt("shop_id"));
int itemId = rset.getInt("item_id");
int price = rset.getInt("price");
int count = rset.getInt("count");
int currentCount = rset.getInt("currentCount");
int time = rset.getInt("time");
final ItemInstance item = ItemTable.getInstance().createDummyItem(itemId);
if (item == null)
{
rset.close();
statement.close();
continue;
}
// FIXME: Nothing?
if (count > -1)
{
item.setCountDecrease(true);
limitedItem = true;
}
if (!rset1.getString("npc_id").equals("gm") && (price < (item.getReferencePrice() / 2)))
{
LOGGER.warning("TradeList " + buy1.getListId() + " itemId " + itemId + " has an ADENA sell price lower then reference price.. Automatically Updating it..");
price = item.getReferencePrice();
}
item.setPriceToSell(price);
item.setTime(time);
item.setInitCount(count);
if (currentCount > -1)
{
item.setCount(currentCount);
}
else
{
item.setCount(count);
}
buy1.addItem(item);
buy1.setNpcId(rset1.getString("npc_id"));
try
{
while (rset.next())
{
itemId = rset.getInt("item_id");
price = rset.getInt("price");
count = rset.getInt("count");
time = rset.getInt("time");
currentCount = rset.getInt("currentCount");
final ItemInstance item2 = ItemTable.getInstance().createDummyItem(itemId);
if (item2 == null)
{
continue;
}
if (count > -1)
{
item2.setCountDecrease(true);
limitedItem = true;
}
if (!rset1.getString("npc_id").equals("gm") && (price < (item2.getReferencePrice() / 2)))
{
LOGGER.warning("TradeList " + buy1.getListId() + " itemId " + itemId + " has an ADENA sell price lower then reference price.. Automatically Updating it..");
price = item2.getReferencePrice();
}
item2.setPriceToSell(price);
item2.setTime(time);
item2.setInitCount(count);
if (currentCount > -1)
{
item2.setCount(currentCount);
}
else
{
item2.setCount(count);
}
buy1.addItem(item2);
}
}
catch (Exception e)
{
LOGGER.warning("TradeController: Problem with buylist " + buy1.getListId() + " item " + itemId);
}
if (limitedItem)
{
_listsTaskItem.put(buy1.getListId(), buy1);
}
else
{
_lists.put(buy1.getListId(), buy1);
}
_nextListId = Math.max(_nextListId, buy1.getListId() + 1);
}
LOGGER.info("TradeController: Loaded " + _lists.size() + " Buylists.");
rset.close();
statement.close();
}
rset1.close();
statement1.close();
LOGGER.info("TradeController: Loaded " + _lists.size() + " Buylists.");
LOGGER.info("TradeController: Loaded " + _listsTaskItem.size() + " Limited Buylists.");
/*
* Restore Task for reinitialize count of buy item
*/
try
{
int time = 0;
long savetimer = 0;
final long currentMillis = System.currentTimeMillis();
final PreparedStatement statement2 = con.prepareStatement("SELECT DISTINCT time, savetimer FROM merchant_buylists WHERE time <> 0 ORDER BY time");
final ResultSet rset2 = statement2.executeQuery();
while (rset2.next())
{
time = rset2.getInt("time");
savetimer = rset2.getLong("savetimer");
if ((savetimer - currentMillis) > 0)
{
ThreadPool.schedule(new RestoreCount(time), savetimer - System.currentTimeMillis());
}
else
{
ThreadPool.schedule(new RestoreCount(time), 0);
}
}
rset2.close();
statement2.close();
}
catch (Exception e)
{
LOGGER.warning("Error while creating trade controller in line: " + (lnr == null ? 0 : lnr.getLineNumber()) + " " + e);
}
finally
{
if (lnr != null)
{
try
{
lnr.close();
}
catch (Exception e1)
{
LOGGER.warning("Problem with TradeController: " + e1.getMessage());
}
}
if (buff != null)
{
try
{
buff.close();
}
catch (Exception e1)
{
LOGGER.warning("Problem with TradeController: " + e1.getMessage());
}
}
if (reader != null)
{
try
{
reader.close();
}
catch (Exception e1)
{
LOGGER.warning("Problem with TradeController: " + e1.getMessage());
}
}
LOGGER.warning("TradeController: Could not restore Timer for Item count. " + e.getMessage());
}
}
else
catch (Exception e)
{
LOGGER.warning("TradeController: Buylists could not be initialized." + e.getMessage());
}
/*
* If enabled, initialize the custom buylist.
*/
if (Config.CUSTOM_MERCHANT_TABLES) // Custom merchant tables.
{
LOGGER.info("No buylists found in data folder, using SQL buylist instead.");
/**
* Initialize Shop buylist
*/
boolean limitedItem = false;
try (Connection con = DatabaseFactory.getConnection())
{
final PreparedStatement statement1 = con.prepareStatement("SELECT * FROM merchant_shopids");
final int initialSize = _lists.size();
final PreparedStatement statement1 = con.prepareStatement("SELECT * FROM custom_merchant_shopids");
final ResultSet rset1 = statement1.executeQuery();
while (rset1.next())
{
final PreparedStatement statement = con.prepareStatement("SELECT * FROM merchant_buylists WHERE shop_id=? ORDER BY `order` ASC");
final PreparedStatement statement = con.prepareStatement("SELECT * FROM custom_merchant_buylists WHERE shop_id=? ORDER BY `order` ASC");
statement.setString(1, String.valueOf(rset1.getInt("shop_id")));
final ResultSet rset = statement.executeQuery();
if (rset.next())
@ -174,7 +259,6 @@ public class TradeController
int count = rset.getInt("count");
int currentCount = rset.getInt("currentCount");
int time = rset.getInt("time");
final ItemInstance item = ItemTable.getInstance().createDummyItem(itemId);
if (item == null)
{
@ -225,7 +309,6 @@ public class TradeController
{
continue;
}
if (count > -1)
{
item2.setCountDecrease(true);
@ -239,7 +322,6 @@ public class TradeController
}
item2.setPriceToSell(price);
item2.setTime(time);
item2.setInitCount(count);
if (currentCount > -1)
@ -265,7 +347,6 @@ public class TradeController
{
_lists.put(buy1.getListId(), buy1);
}
_nextListId = Math.max(_nextListId, buy1.getListId() + 1);
}
@ -275,18 +356,17 @@ public class TradeController
rset1.close();
statement1.close();
LOGGER.info("TradeController: Loaded " + _lists.size() + " Buylists.");
LOGGER.info("TradeController: Loaded " + _listsTaskItem.size() + " Limited Buylists.");
LOGGER.info("TradeController: Loaded " + (_lists.size() - initialSize) + " Custom Buylists.");
/*
* Restore Task for reinitialyze count of buy item
/**
* Restore Task for reinitialize count of buy item
*/
try
{
int time = 0;
long savetimer = 0;
final long currentMillis = System.currentTimeMillis();
final PreparedStatement statement2 = con.prepareStatement("SELECT DISTINCT time, savetimer FROM merchant_buylists WHERE time <> 0 ORDER BY time");
final PreparedStatement statement2 = con.prepareStatement("SELECT DISTINCT time, savetimer FROM custom_merchant_buylists WHERE time <> 0 ORDER BY time");
final ResultSet rset2 = statement2.executeQuery();
while (rset2.next())
@ -312,171 +392,7 @@ public class TradeController
}
catch (Exception e)
{
// problem with initializing spawn, go to next one
LOGGER.warning("TradeController: Buylists could not be initialized." + e.getMessage());
}
/*
* If enabled, initialize the custom buylist
*/
if (Config.CUSTOM_MERCHANT_TABLES)// Custom merchat Tabels
{
try (Connection con = DatabaseFactory.getConnection())
{
final int initialSize = _lists.size();
final PreparedStatement statement1 = con.prepareStatement("SELECT * FROM custom_merchant_shopids");
final ResultSet rset1 = statement1.executeQuery();
while (rset1.next())
{
final PreparedStatement statement = con.prepareStatement("SELECT * FROM custom_merchant_buylists WHERE shop_id=? ORDER BY `order` ASC");
statement.setString(1, String.valueOf(rset1.getInt("shop_id")));
final ResultSet rset = statement.executeQuery();
if (rset.next())
{
limitedItem = false;
final StoreTradeList buy1 = new StoreTradeList(rset1.getInt("shop_id"));
int itemId = rset.getInt("item_id");
int price = rset.getInt("price");
int count = rset.getInt("count");
int currentCount = rset.getInt("currentCount");
int time = rset.getInt("time");
final ItemInstance item = ItemTable.getInstance().createDummyItem(itemId);
if (item == null)
{
rset.close();
statement.close();
continue;
}
if (count > -1)
{
item.setCountDecrease(true);
limitedItem = true;
}
if (!rset1.getString("npc_id").equals("gm") && (price < (item.getReferencePrice() / 2)))
{
LOGGER.warning("TradeList " + buy1.getListId() + " itemId " + itemId + " has an ADENA sell price lower then reference price.. Automatically Updating it..");
price = item.getReferencePrice();
}
item.setPriceToSell(price);
item.setTime(time);
item.setInitCount(count);
if (currentCount > -1)
{
item.setCount(currentCount);
}
else
{
item.setCount(count);
}
buy1.addItem(item);
buy1.setNpcId(rset1.getString("npc_id"));
try
{
while (rset.next())
{
itemId = rset.getInt("item_id");
price = rset.getInt("price");
count = rset.getInt("count");
time = rset.getInt("time");
currentCount = rset.getInt("currentCount");
final ItemInstance item2 = ItemTable.getInstance().createDummyItem(itemId);
if (item2 == null)
{
continue;
}
if (count > -1)
{
item2.setCountDecrease(true);
limitedItem = true;
}
if (!rset1.getString("npc_id").equals("gm") && (price < (item2.getReferencePrice() / 2)))
{
LOGGER.warning("TradeList " + buy1.getListId() + " itemId " + itemId + " has an ADENA sell price lower then reference price.. Automatically Updating it..");
price = item2.getReferencePrice();
}
item2.setPriceToSell(price);
item2.setTime(time);
item2.setInitCount(count);
if (currentCount > -1)
{
item2.setCount(currentCount);
}
else
{
item2.setCount(count);
}
buy1.addItem(item2);
}
}
catch (Exception e)
{
LOGGER.warning("TradeController: Problem with buylist " + buy1.getListId() + " item " + itemId);
}
if (limitedItem)
{
_listsTaskItem.put(buy1.getListId(), buy1);
}
else
{
_lists.put(buy1.getListId(), buy1);
}
_nextListId = Math.max(_nextListId, buy1.getListId() + 1);
}
rset.close();
statement.close();
}
rset1.close();
statement1.close();
LOGGER.info("TradeController: Loaded " + (_lists.size() - initialSize) + " Custom Buylists.");
/**
* Restore Task for reinitialyze count of buy item
*/
try
{
int time = 0;
long savetimer = 0;
final long currentMillis = System.currentTimeMillis();
final PreparedStatement statement2 = con.prepareStatement("SELECT DISTINCT time, savetimer FROM custom_merchant_buylists WHERE time <> 0 ORDER BY time");
final ResultSet rset2 = statement2.executeQuery();
while (rset2.next())
{
time = rset2.getInt("time");
savetimer = rset2.getLong("savetimer");
if ((savetimer - currentMillis) > 0)
{
ThreadPool.schedule(new RestoreCount(time), savetimer - System.currentTimeMillis());
}
else
{
ThreadPool.schedule(new RestoreCount(time), 0);
}
}
rset2.close();
statement2.close();
}
catch (Exception e)
{
LOGGER.warning("TradeController: Could not restore Timer for Item count. " + e.getMessage());
}
}
catch (Exception e)
{
// problem with initializing spawn, go to next one
LOGGER.warning("TradeController: Buylists could not be initialized. " + e.getMessage());
}
LOGGER.warning("TradeController: Buylists could not be initialized. " + e.getMessage());
}
}
}
@ -589,9 +505,6 @@ public class TradeController
}
}
/**
* @return
*/
public synchronized int getNextId()
{
return _nextListId++;