Commit 8aeea43d authored by Kenix Whisperwind's avatar Kenix Whisperwind

Market is now a non-static class member of World and MarketDatabase is now a...

Market is now a non-static class member of World and MarketDatabase is now a non-static class member of Market.
parent 94954de1
package com.openrsc.server.plugins.minigames.mage_arena;
import com.openrsc.server.Server;
import com.openrsc.server.content.market.Market;
import com.openrsc.server.model.entity.npc.Npc;
import com.openrsc.server.model.entity.player.Player;
import com.openrsc.server.net.rsc.ActionSender;
......@@ -172,7 +171,7 @@ public class Gundai implements TalkToNpcExecutiveListener, TalkToNpcListener, Np
ActionSender.sendBox(player, "Bank pin correct", false);
}
}
Market.getInstance().addPlayerCollectItemsTask(player);
player.getWorld().getMarket().addPlayerCollectItemsTask(player);
}
});
}
......@@ -239,7 +238,7 @@ public class Gundai implements TalkToNpcExecutiveListener, TalkToNpcListener, Np
}
}
if (Server.getServer().getConfig().SPAWN_AUCTION_NPCS && auction) {
Market.getInstance().addPlayerCollectItemsTask(player);
player.getWorld().getMarket().addPlayerCollectItemsTask(player);
} else {
player.setAccessingBank(true);
ActionSender.showBank(player);
......
package com.openrsc.server.plugins.npcs;
import com.openrsc.server.Server;
import com.openrsc.server.content.market.Market;
import com.openrsc.server.model.entity.npc.Npc;
import com.openrsc.server.model.entity.player.Player;
import com.openrsc.server.net.rsc.ActionSender;
......@@ -229,7 +228,7 @@ public class Bankers implements TalkToNpcExecutiveListener, TalkToNpcListener, N
player.setAttribute("bankpin", true);
ActionSender.sendBox(player, "Bank pin correct", false);
}
Market.getInstance().addPlayerCollectItemsTask(player);
player.getWorld().getMarket().addPlayerCollectItemsTask(player);
}
}
......@@ -279,7 +278,7 @@ public class Bankers implements TalkToNpcExecutiveListener, TalkToNpcListener, N
player.message("You have correctly entered your PIN");
}
if (auction) {
Market.getInstance().addPlayerCollectItemsTask(player);
player.getWorld().getMarket().addPlayerCollectItemsTask(player);
} else {
player.setAccessingBank(true);
ActionSender.showBank(player);
......
......@@ -24,26 +24,26 @@ public class Market implements Runnable {
*/
private static final Logger LOGGER = LogManager.getLogger();
private static Market instance;
private final World world;
private final MarketDatabase marketDatabase;
private Boolean running;
private ArrayList<MarketItem> auctionItems;
private LinkedBlockingQueue<MarketTask> auctionTaskQueue = new LinkedBlockingQueue<>();
private LinkedBlockingQueue<MarketTask> auctionTaskQueue;
private long lastCleanUp = 0;
private LinkedBlockingQueue<OpenMarketTask> refreshRequestTasks = new LinkedBlockingQueue<>();
private LinkedBlockingQueue<OpenMarketTask> refreshRequestTasks;
private ScheduledExecutorService scheduledExecutor;
public Market() {
auctionItems = new ArrayList<>();
scheduledExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat(Server.getServer().getName()+" : AuctionHouseThread").build());
start();
}
public static Market getInstance() {
if (!Server.getServer().getConfig().SPAWN_AUCTION_NPCS) return null;
if (instance == null) {
instance = new Market();
}
return instance;
public Market(World world) {
this.world = world;
this.auctionItems = new ArrayList<>();
this.auctionTaskQueue = new LinkedBlockingQueue<>();
this.refreshRequestTasks = new LinkedBlockingQueue<>();
this.scheduledExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat(Server.getServer().getName()+" : AuctionHouseThread").build());
this.marketDatabase = new MarketDatabase(this);
this.running = false;
}
public void addBuyAuctionItemTask(final Player player, int auctionID, int amount) {
......@@ -92,7 +92,7 @@ public class Market implements Runnable {
int amount = expiredItem.getAmountLeft();
Player sellerPlayer = World.getWorld().getPlayerID(expiredItem.getSeller());
MarketDatabase.setSoldOut(expiredItem);
getMarketDatabase().setSoldOut(expiredItem);
expiredItemsStatement.setInt(1, itemIndex);
expiredItemsStatement.setInt(2, amount);
......@@ -139,26 +139,46 @@ public class Market implements Runnable {
}
private void processUpdateAuctionItemCache() {
int activeAuctionCount = MarketDatabase.getAuctionCount();
int activeAuctionCount = getMarketDatabase().getAuctionCount();
if (activeAuctionCount == auctionItems.size()) return;
auctionItems.clear();
auctionItems = MarketDatabase.getAuctionItemsOnSale();
auctionItems = getMarketDatabase().getAuctionItemsOnSale();
}
@Override
public void run() {
try {
if (System.currentTimeMillis() - lastCleanUp > 60000) checkAndRemoveExpiredItems();
processAuctionTasks();
processUpdateAuctionItemCache();
processRefreshRequests();
} catch (Throwable r) {
LOGGER.catching(r);
synchronized (running) {
try {
if (System.currentTimeMillis() - lastCleanUp > 60000) checkAndRemoveExpiredItems();
processAuctionTasks();
processUpdateAuctionItemCache();
processRefreshRequests();
} catch (Throwable r) {
LOGGER.catching(r);
}
}
}
public void stop() {
synchronized(running) {
running = false;
scheduledExecutor.shutdown();
}
}
public void start() {
scheduledExecutor.scheduleAtFixedRate(this, 50, 50, TimeUnit.MILLISECONDS);
LOGGER.info("Market executor running");
synchronized(running) {
running = true;
scheduledExecutor.scheduleAtFixedRate(this, 50, 50, TimeUnit.MILLISECONDS);
LOGGER.info("Market executor running");
}
}
public World getWorld() {
return world;
}
public MarketDatabase getMarketDatabase() {
return marketDatabase;
}
}
package com.openrsc.server.content.market;
import com.openrsc.server.Server;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -16,10 +15,16 @@ public class MarketDatabase {
*/
private static final Logger LOGGER = LogManager.getLogger();
public static boolean add(MarketItem item) {
private final Market market;
public MarketDatabase(Market market) {
this.market = market;
}
public boolean add(MarketItem item) {
try {
PreparedStatement statement = Server.getServer().getDatabaseConnection().prepareStatement(
"INSERT INTO `" + Server.getServer().getConfig().MYSQL_TABLE_PREFIX
PreparedStatement statement = getMarket().getWorld().getServer().getDatabaseConnection().prepareStatement(
"INSERT INTO `" + getMarket().getWorld().getServer().getConfig().MYSQL_TABLE_PREFIX
+ "auctions`(`itemID`, `amount`, `amount_left`, `price`, `seller`, `seller_username`, `buyer_info`, `time`) VALUES (?,?,?,?,?,?,?,?)");
statement.setInt(1, item.getItemID());
statement.setInt(2, item.getAmount());
......@@ -37,13 +42,13 @@ public class MarketDatabase {
return false;
}
public static boolean addCollectableItem(String explanation, final int itemIndex, final int amount,
public boolean addCollectableItem(String explanation, final int itemIndex, final int amount,
final int playerID) {
final String finalExplanation = explanation.replaceAll("'", "");
try {
PreparedStatement statement = Server.getServer().getDatabaseConnection().prepareStatement(
"INSERT INTO `" + Server.getServer().getConfig().MYSQL_TABLE_PREFIX
PreparedStatement statement = getMarket().getWorld().getServer().getDatabaseConnection().prepareStatement(
"INSERT INTO `" + getMarket().getWorld().getServer().getConfig().MYSQL_TABLE_PREFIX
+ "expired_auctions`(`item_id`, `item_amount`, `time`, `playerID`, `explanation`) VALUES (?,?,?,?,?)");
statement.setInt(1, itemIndex);
statement.setInt(2, amount);
......@@ -58,10 +63,10 @@ public class MarketDatabase {
return false;
}
public static boolean cancel(MarketItem item) {
public boolean cancel(MarketItem item) {
try {
PreparedStatement statement = Server.getServer().getDatabaseConnection()
.prepareStatement("UPDATE `" + Server.getServer().getConfig().MYSQL_TABLE_PREFIX
PreparedStatement statement = getMarket().getWorld().getServer().getDatabaseConnection()
.prepareStatement("UPDATE `" + getMarket().getWorld().getServer().getConfig().MYSQL_TABLE_PREFIX
+ "auctions` SET `sold-out`='1', `was_cancel`='1' WHERE `auctionID`=?");
statement.setInt(1, item.getAuctionID());
statement.executeUpdate();
......@@ -72,10 +77,10 @@ public class MarketDatabase {
return false;
}
static int getAuctionCount() {
public int getAuctionCount() {
try {
PreparedStatement statement = Server.getServer().getDatabaseConnection()
.prepareStatement("SELECT count(*) as auction_count FROM `" + Server.getServer().getConfig().MYSQL_TABLE_PREFIX
PreparedStatement statement = getMarket().getWorld().getServer().getDatabaseConnection()
.prepareStatement("SELECT count(*) as auction_count FROM `" + getMarket().getWorld().getServer().getConfig().MYSQL_TABLE_PREFIX
+ "auctions` WHERE `sold-out`='0'");
ResultSet result = statement.executeQuery();
if (result.next()) {
......@@ -88,10 +93,10 @@ public class MarketDatabase {
return 0;
}
public static int getMyAuctionsCount(int ownerID) {
public int getMyAuctionsCount(int ownerID) {
try {
PreparedStatement statement = Server.getServer().getDatabaseConnection()
.prepareStatement("SELECT count(*) as my_slots FROM `" + Server.getServer().getConfig().MYSQL_TABLE_PREFIX
PreparedStatement statement = getMarket().getWorld().getServer().getDatabaseConnection()
.prepareStatement("SELECT count(*) as my_slots FROM `" + getMarket().getWorld().getServer().getConfig().MYSQL_TABLE_PREFIX
+ "auctions` WHERE `seller`='" + ownerID + "' AND `sold-out`='0'");
ResultSet result = statement.executeQuery();
if (result.next()) {
......@@ -104,10 +109,10 @@ public class MarketDatabase {
return 0;
}
public static MarketItem getAuctionItem(int auctionID) {
public MarketItem getAuctionItem(int auctionID) {
try {
PreparedStatement statement = Server.getServer().getDatabaseConnection()
.prepareStatement("SELECT `auctionID`, `itemID`, `amount`, `amount_left`, `price`, `seller`, `seller_username`, `buyer_info`, `time` FROM `" + Server.getServer().getConfig().MYSQL_TABLE_PREFIX
PreparedStatement statement = getMarket().getWorld().getServer().getDatabaseConnection()
.prepareStatement("SELECT `auctionID`, `itemID`, `amount`, `amount_left`, `price`, `seller`, `seller_username`, `buyer_info`, `time` FROM `" + getMarket().getWorld().getServer().getConfig().MYSQL_TABLE_PREFIX
+ "auctions` WHERE `auctionID`= ? AND `sold-out` = '0'");
statement.setInt(1, auctionID);
......@@ -123,11 +128,11 @@ public class MarketDatabase {
return null;
}
static ArrayList<MarketItem> getAuctionItemsOnSale() {
public ArrayList<MarketItem> getAuctionItemsOnSale() {
ArrayList<MarketItem> auctionItems = new ArrayList<>();
try {
PreparedStatement statement = Server.getServer().getDatabaseConnection()
.prepareStatement("SELECT `auctionID`, `itemID`, `amount`, `amount_left`, `price`, `seller`, `seller_username`, `buyer_info`, `time` FROM `" + Server.getServer().getConfig().MYSQL_TABLE_PREFIX
PreparedStatement statement = getMarket().getWorld().getServer().getDatabaseConnection()
.prepareStatement("SELECT `auctionID`, `itemID`, `amount`, `amount_left`, `price`, `seller`, `seller_username`, `buyer_info`, `time` FROM `" + getMarket().getWorld().getServer().getConfig().MYSQL_TABLE_PREFIX
+ "auctions` WHERE `sold-out`='0'");
ResultSet result = statement.executeQuery();
while (result.next()) {
......@@ -142,10 +147,10 @@ public class MarketDatabase {
return auctionItems;
}
public static boolean setSoldOut(MarketItem item) {
public boolean setSoldOut(MarketItem item) {
try {
PreparedStatement statement = Server.getServer().getDatabaseConnection()
.prepareStatement("UPDATE `" + Server.getServer().getConfig().MYSQL_TABLE_PREFIX
PreparedStatement statement = getMarket().getWorld().getServer().getDatabaseConnection()
.prepareStatement("UPDATE `" + getMarket().getWorld().getServer().getConfig().MYSQL_TABLE_PREFIX
+ "auctions` SET `amount_left`=?, `sold-out`=?, `buyer_info`=? WHERE `auctionID`=?");
statement.setInt(1, item.getAmountLeft());
statement.setInt(2, 1);
......@@ -159,10 +164,10 @@ public class MarketDatabase {
return false;
}
public static boolean update(MarketItem item) {
public boolean update(MarketItem item) {
try {
PreparedStatement statement = Server.getServer().getDatabaseConnection().prepareStatement(
"UPDATE `" + Server.getServer().getConfig().MYSQL_TABLE_PREFIX
PreparedStatement statement = getMarket().getWorld().getServer().getDatabaseConnection().prepareStatement(
"UPDATE `" + getMarket().getWorld().getServer().getConfig().MYSQL_TABLE_PREFIX
+ "auctions` SET `amount_left`=?, `price` = ?, `buyer_info`=? WHERE `auctionID`= ?");
statement.setInt(1, item.getAmountLeft());
statement.setInt(2, item.getPrice());
......@@ -176,10 +181,10 @@ public class MarketDatabase {
return false;
}
public static ArrayList<CollectableItem> getCollectableItemsFor(int player) {
public ArrayList<CollectableItem> getCollectableItemsFor(int player) {
ArrayList<CollectableItem> list = new ArrayList<>();
try {
PreparedStatement statement = Server.getServer().getDatabaseConnection().prepareStatement("SELECT `claim_id`, `item_id`, `item_amount`, `playerID`, `explanation` FROM `" + Server.getServer().getConfig().MYSQL_TABLE_PREFIX
PreparedStatement statement = getMarket().getWorld().getServer().getDatabaseConnection().prepareStatement("SELECT `claim_id`, `item_id`, `item_amount`, `playerID`, `explanation` FROM `" + getMarket().getWorld().getServer().getConfig().MYSQL_TABLE_PREFIX
+ "expired_auctions` WHERE `playerID` = ? AND `claimed`= '0'");
statement.setInt(1, player);
ResultSet result = statement.executeQuery();
......@@ -197,4 +202,8 @@ public class MarketDatabase {
}
return list;
}
public Market getMarket() {
return market;
}
}
package com.openrsc.server.content.market.task;
import com.openrsc.server.Server;
import com.openrsc.server.content.market.Market;
import com.openrsc.server.content.market.MarketDatabase;
import com.openrsc.server.content.market.MarketItem;
import com.openrsc.server.external.ItemDefinition;
import com.openrsc.server.model.container.Item;
......@@ -24,7 +22,7 @@ public class BuyMarketItemTask extends MarketTask {
@Override
public void doTask() {
MarketItem item = MarketDatabase.getAuctionItem(auctionID);
MarketItem item = playerBuyer.getWorld().getMarket().getMarketDatabase().getAuctionItem(auctionID);
boolean updateDiscord = false;
if (item == null) {
......@@ -85,7 +83,7 @@ public class BuyMarketItemTask extends MarketTask {
sellerPlayer.save();
}
MarketDatabase.addCollectableItem("Sold " + def.getName() + "(" + item.getItemID() + ") x" + amount + " for " + auctionPrice + "gp", 10, auctionPrice, sellerUsernameID);
playerBuyer.getWorld().getMarket().getMarketDatabase().addCollectableItem("Sold " + def.getName() + "(" + item.getItemID() + ") x" + amount + " for " + auctionPrice + "gp", 10, auctionPrice, sellerUsernameID);
item.setBuyers(!item.getBuyers().isEmpty() ? item.getBuyers() + ", \n" + "[" + (System.currentTimeMillis() / 1000) + ": "
+ playerBuyer.getUsername() + ": x" + amount + "]" : "[" + (System.currentTimeMillis() / 1000) + ": "
+ playerBuyer.getUsername() + ": x" + amount + "]");
......@@ -93,17 +91,17 @@ public class BuyMarketItemTask extends MarketTask {
item.setAmountLeft(item.getAmountLeft() - amount);
item.setPrice(item.getAmountLeft() * priceForEach);
if (item.getAmountLeft() == 0) MarketDatabase.setSoldOut(item);
else MarketDatabase.update(item);
if (item.getAmountLeft() == 0) playerBuyer.getWorld().getMarket().getMarketDatabase().setSoldOut(item);
else playerBuyer.getWorld().getMarket().getMarketDatabase().update(item);
for (MarketItem marketItem : Market.getInstance().getAuctionItems()) {
for (MarketItem marketItem : playerBuyer.getWorld().getMarket().getAuctionItems()) {
if (marketItem.getAuctionID() == item.getAuctionID()) {
marketItem.setAmountLeft(item.getAmountLeft());
marketItem.setPrice(item.getPrice());
}
}
Market.getInstance().addRequestOpenAuctionHouseTask(playerBuyer);
playerBuyer.getWorld().getMarket().addRequestOpenAuctionHouseTask(playerBuyer);
if (updateDiscord) {
Server.getServer().getDiscordService().auctionBuy(item);
......
package com.openrsc.server.content.market.task;
import com.openrsc.server.Server;
import com.openrsc.server.content.market.Market;
import com.openrsc.server.content.market.MarketDatabase;
import com.openrsc.server.content.market.MarketItem;
import com.openrsc.server.external.ItemDefinition;
import com.openrsc.server.model.container.Item;
......@@ -22,13 +20,13 @@ public class CancelMarketItemTask extends MarketTask {
@Override
public void doTask() {
boolean updateDiscord = false;
MarketItem item = MarketDatabase.getAuctionItem(auctionID);
MarketItem item = owner.getWorld().getMarket().getMarketDatabase().getAuctionItem(auctionID);
if (item != null) {
int itemIndex = item.getItemID();
int amount = item.getAmountLeft();
ItemDefinition def = owner.getWorld().getServer().getEntityHandler().getItemDef(itemIndex);
if (!owner.getInventory().full() && (!def.isStackable() && owner.getInventory().size() + amount <= 30)) {
if (MarketDatabase.cancel(item)) {
if (owner.getWorld().getMarket().getMarketDatabase().cancel(item)) {
if (!def.isStackable()) for (int i = 0; i < amount; i++)
owner.getInventory().add(new Item(itemIndex, 1));
else owner.getInventory().add(new Item(itemIndex, amount));
......@@ -36,7 +34,7 @@ public class CancelMarketItemTask extends MarketTask {
updateDiscord = true;
}
} else if (!owner.getBank().full()) {
if (MarketDatabase.cancel(item)) {
if (owner.getWorld().getMarket().getMarketDatabase().cancel(item)) {
owner.getBank().add(new Item(itemIndex, amount));
ActionSender.sendBox(owner, "@gre@[Auction House - Success] % @whi@ The item has been canceled and returned to your bank. % Talk with a Banker to collect your item(s).", false);
updateDiscord = true;
......@@ -44,7 +42,7 @@ public class CancelMarketItemTask extends MarketTask {
} else
ActionSender.sendBox(owner, "@red@[Auction House - Error] % @whi@ Unable to cancel auction! % % @red@Reason: @whi@No space left in your bank or inventory.", false);
}
Market.getInstance().addRequestOpenAuctionHouseTask(owner);
owner.getWorld().getMarket().addRequestOpenAuctionHouseTask(owner);
if (updateDiscord) {
Server.getServer().getDiscordService().auctionCancel(item);
}
......
package com.openrsc.server.content.market.task;
import com.openrsc.server.content.market.CollectableItem;
import com.openrsc.server.content.market.MarketDatabase;
import com.openrsc.server.external.ItemDefinition;
import com.openrsc.server.model.entity.player.Player;
import com.openrsc.server.net.rsc.ActionSender;
......@@ -18,7 +17,7 @@ public class CollectableItemsNotificationTask extends MarketTask {
@Override
public void doTask() {
ArrayList<CollectableItem> list = MarketDatabase.getCollectableItemsFor(player.getDatabaseID());
ArrayList<CollectableItem> list = player.getWorld().getMarket().getMarketDatabase().getCollectableItemsFor(player.getDatabaseID());
StringBuilder items = new StringBuilder("Following items have been removed from market: % ");
for (CollectableItem item : list) {
ItemDefinition def = player.getWorld().getServer().getEntityHandler().getItemDef(item.item_id);
......
package com.openrsc.server.content.market.task;
import com.openrsc.server.Server;
import com.openrsc.server.content.market.Market;
import com.openrsc.server.content.market.MarketDatabase;
import com.openrsc.server.content.market.MarketItem;
import com.openrsc.server.model.entity.player.Player;
import com.openrsc.server.net.rsc.ActionSender;
......@@ -24,18 +22,18 @@ public class ModeratorDeleteAuctionTask extends MarketTask {
player.setSuspiciousPlayer(true);
ActionSender.sendBox(player, "@red@[Auction House - Error] % @whi@ Unable to remove auction", false);
} else {
MarketItem item = MarketDatabase.getAuctionItem(auctionID);
MarketItem item = player.getWorld().getMarket().getMarketDatabase().getAuctionItem(auctionID);
if (item != null) {
int itemIndex = item.getItemID();
int amount = item.getAmountLeft();
if (MarketDatabase.setSoldOut(item)) {
MarketDatabase.addCollectableItem("Removed by " + player.getStaffName(), itemIndex, amount, item.getSeller());
if (player.getWorld().getMarket().getMarketDatabase().setSoldOut(item)) {
player.getWorld().getMarket().getMarketDatabase().addCollectableItem("Removed by " + player.getStaffName(), itemIndex, amount, item.getSeller());
ActionSender.sendBox(player, "@gre@[Auction House - Success] % @whi@ Item has been removed from Auctions. % % Returned to collections for: " + item.getSellerName(), false);
updateDiscord = true;
} else
ActionSender.sendBox(player, "@red@[Auction House - Error] % @whi@ Unable to remove auction", false);
}
Market.getInstance().addRequestOpenAuctionHouseTask(player);
player.getWorld().getMarket().addRequestOpenAuctionHouseTask(player);
if (updateDiscord) {
Server.getServer().getDiscordService().auctionModDelete(item);
}
......
package com.openrsc.server.content.market.task;
import com.openrsc.server.Server;
import com.openrsc.server.content.market.Market;
import com.openrsc.server.content.market.MarketDatabase;
import com.openrsc.server.content.market.MarketItem;
import com.openrsc.server.external.ItemDefinition;
import com.openrsc.server.model.container.Item;
......@@ -65,7 +63,7 @@ public class NewMarketItemTask extends MarketTask {
if (def.getOriginalItemID() != -1) newItem.setItemID(def.getOriginalItemID());
if (MarketDatabase.add(newItem)) {
if (owner.getWorld().getMarket().getMarketDatabase().add(newItem)) {
//ActionSender.sendBox(owner, "@gre@[Auction House - Success] % @whi@ Auction has been listed % " + newItem.getAmount() + "x @yel@" + def.getName() + " @whi@for @yel@" + newItem.getPrice() + "gp % @whi@Completed auction fee: @gre@" + feeCost + "gp", false);
ActionSender.sendBox(owner, "@gre@[Auction House - Success] % @whi@ Auction has been listed % " + newItem.getAmount() + "x @yel@" + def.getName() + " @whi@for @yel@" + newItem.getPrice() + "gp", false);
updateDiscord = true;
......@@ -80,7 +78,7 @@ public class NewMarketItemTask extends MarketTask {
}
ActionSender.sendBox(owner, "@red@[Auction House - Error] % @whi@ Failed to add item to Auction. % Item(s) have been returned to your inventory.", false);
}
Market.getInstance().addRequestOpenAuctionHouseTask(owner);
owner.getWorld().getMarket().addRequestOpenAuctionHouseTask(owner);
if (updateDiscord) {
Server.getServer().getDiscordService().auctionAdd(newItem);
}
......
package com.openrsc.server.content.market.task;
import com.openrsc.server.content.market.Market;
import com.openrsc.server.content.market.MarketItem;
import com.openrsc.server.model.entity.player.Player;
import com.openrsc.server.net.Packet;
......@@ -23,7 +22,7 @@ public class OpenMarketTask extends MarketTask {
owner.write(pb.toPacket());
@SuppressWarnings("unchecked")
ArrayList<MarketItem> items = (ArrayList<MarketItem>) Market.getInstance().getAuctionItems().clone();
ArrayList<MarketItem> items = (ArrayList<MarketItem>) owner.getWorld().getMarket().getAuctionItems().clone();
System.out.println("There's currently " + items.size() + " auctions. ");
Iterator<MarketItem> iterator = items.iterator();
......
package com.openrsc.server.content.market.task;
import com.openrsc.server.content.market.CollectableItem;
import com.openrsc.server.content.market.MarketDatabase;
import com.openrsc.server.model.container.Item;
import com.openrsc.server.model.entity.player.Player;
import com.openrsc.server.net.rsc.ActionSender;
......@@ -27,7 +26,7 @@ public class PlayerCollectItemsTask extends MarketTask {
@Override
public void doTask() {
ArrayList<CollectableItem> list = MarketDatabase.getCollectableItemsFor(player.getDatabaseID());
ArrayList<CollectableItem> list = player.getWorld().getMarket().getMarketDatabase().getCollectableItemsFor(player.getDatabaseID());
if (list.size() == 0) {
player.message("You have no items to collect.");
......
......@@ -5,6 +5,7 @@ import com.openrsc.server.constants.ItemId;
import com.openrsc.server.constants.NpcId;
import com.openrsc.server.content.DropTable;
import com.openrsc.server.content.clan.ClanManager;
import com.openrsc.server.content.market.Market;
import com.openrsc.server.content.minigame.fishingtrawler.FishingTrawler;
import com.openrsc.server.content.minigame.fishingtrawler.FishingTrawler.TrawlerBoat;
import com.openrsc.server.content.party.PartyManager;
......@@ -81,6 +82,7 @@ public final class World implements SimpleSubscriber<FishingTrawler> {
private final List<Shop> shops;
private final Map<TrawlerBoat, FishingTrawler> fishingTrawler;
private final TileValue[][] tiles;
private final Market market;
private final WorldLoader worldLoader;
......@@ -111,6 +113,7 @@ public final class World implements SimpleSubscriber<FishingTrawler> {
snapshots = new LinkedList<Snapshot>();
worldLoader = new WorldLoader(this);
regionManager = new RegionManager(this);
market = getServer().getConfig().SPAWN_AUCTION_NPCS ? new Market(this) : null;
}
public static synchronized World getWorld() {
......@@ -942,4 +945,8 @@ public final class World implements SimpleSubscriber<FishingTrawler> {
public RegionManager getRegionManager() {
return regionManager;
}
public Market getMarket() {
return market;
}
}
......@@ -4,7 +4,6 @@ import com.openrsc.server.Server;
import com.openrsc.server.content.clan.Clan;
import com.openrsc.server.content.clan.ClanManager;
import com.openrsc.server.content.clan.ClanPlayer;
import com.openrsc.server.content.market.Market;
import com.openrsc.server.content.party.Party;
import com.openrsc.server.content.party.PartyManager;
import com.openrsc.server.content.party.PartyPlayer;
......@@ -1246,7 +1245,7 @@ public class ActionSender {
if (!p.getLocation().inWilderness()) {
if (Server.getServer().getConfig().SPAWN_AUCTION_NPCS) {
Market.getInstance().addCollectableItemsNotificationTask(p);
p.getWorld().getMarket().addCollectableItemsNotificationTask(p);
}
}
......@@ -1308,7 +1307,7 @@ public class ActionSender {
}
public static void sendOpenAuctionHouse(final Player player) {
Market.getInstance().addRequestOpenAuctionHouseTask(player);
player.getWorld().getMarket().addRequestOpenAuctionHouseTask(player);
}
public static void sendClan(Player p) {
......
......@@ -2,7 +2,6 @@ package com.openrsc.server.net.rsc.handlers;
import com.openrsc.server.Server;
import com.openrsc.server.content.clan.*;
import com.openrsc.server.content.market.Market;
import com.openrsc.server.content.party.*;
import com.openrsc.server.model.entity.npc.Npc;
import com.openrsc.server.model.entity.player.Player;
......@@ -216,18 +215,18 @@ public class InterfaceOptionHandler implements PacketHandler {
}
player.setAttribute("ah_buy_item", System.currentTimeMillis());
Market.getInstance().addBuyAuctionItemTask(player, auctionBuyID, amountBuy);
player.getWorld().getMarket().addBuyAuctionItemTask(player, auctionBuyID, amountBuy);
break;
case 1: /* Create auction */
int itemID = p.readInt();
int amount = p.readInt();
int price = p.readInt();
Market.getInstance().addNewAuctionItemTask(player, itemID, amount, price);
player.getWorld().getMarket().addNewAuctionItemTask(player, itemID, amount, price);
break;
case 2:
int auctionID = p.readInt();
Market.getInstance().addCancelAuctionItemTask(player, auctionID);
player.getWorld().getMarket().addCancelAuctionItemTask(player, auctionID);
break;
case 3:
if (System.currentTimeMillis() - player.getAttribute("ah_refresh", (long) 0) < 5000) {
......@@ -244,7 +243,7 @@ public class InterfaceOptionHandler implements PacketHandler {
case 5:
auctionID = p.readInt();
Market.getInstance().addModeratorDeleteItemTask(player, auctionID);
player.getWorld().getMarket().addModeratorDeleteItemTask(player, auctionID);
break;
}
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment