Rename and clean up MapleStorage
This commit is contained in:
@@ -166,7 +166,7 @@ public class Character extends AbstractCharacterObject {
|
||||
private PlayerShop playerShop = null;
|
||||
private Shop shop = null;
|
||||
private SkinColor skinColor = SkinColor.NORMAL;
|
||||
private MapleStorage storage = null;
|
||||
private Storage storage = null;
|
||||
private MapleTrade trade = null;
|
||||
private MonsterBook monsterbook;
|
||||
private CashShop cashshop;
|
||||
@@ -5863,7 +5863,7 @@ public class Character extends AbstractCharacterObject {
|
||||
}
|
||||
}
|
||||
|
||||
public MapleStorage getStorage() {
|
||||
public Storage getStorage() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import config.YamlConfig;
|
||||
import constants.inventory.ItemConstants;
|
||||
import net.packet.InPacket;
|
||||
import server.ItemInformationProvider;
|
||||
import server.MapleStorage;
|
||||
import server.Storage;
|
||||
import tools.FilePrinter;
|
||||
import tools.PacketCreator;
|
||||
|
||||
@@ -47,7 +47,7 @@ public class StorageProcessor {
|
||||
public static void storageAction(InPacket p, Client c) {
|
||||
ItemInformationProvider ii = ItemInformationProvider.getInstance();
|
||||
Character chr = c.getPlayer();
|
||||
MapleStorage storage = chr.getStorage();
|
||||
Storage storage = chr.getStorage();
|
||||
byte mode = p.readByte();
|
||||
|
||||
if (chr.getLevel() < 15){
|
||||
|
||||
@@ -53,7 +53,7 @@ import net.server.services.ServicesManager;
|
||||
import net.server.services.type.WorldServices;
|
||||
import net.server.task.*;
|
||||
import scripting.event.EventInstanceManager;
|
||||
import server.MapleStorage;
|
||||
import server.Storage;
|
||||
import server.TimerManager;
|
||||
import server.maps.*;
|
||||
import tools.DatabaseConnection;
|
||||
@@ -96,7 +96,7 @@ public class World {
|
||||
private MonitoredWriteLock chnWLock = MonitoredWriteLockFactory.createLock(chnLock);
|
||||
|
||||
private Map<Integer, SortedMap<Integer, Character>> accountChars = new HashMap<>();
|
||||
private Map<Integer, MapleStorage> accountStorages = new HashMap<>();
|
||||
private Map<Integer, Storage> accountStorages = new HashMap<>();
|
||||
private MonitoredReentrantLock accountCharsLock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.WORLD_CHARS, true);
|
||||
|
||||
private Set<Integer> queuedGuilds = new HashSet<>();
|
||||
@@ -435,7 +435,7 @@ public class World {
|
||||
}
|
||||
|
||||
private void registerAccountStorage(Integer accountId) {
|
||||
MapleStorage storage = MapleStorage.loadOrCreateFromDB(accountId, this.id);
|
||||
Storage storage = Storage.loadOrCreateFromDB(accountId, this.id);
|
||||
accountCharsLock.lock();
|
||||
try {
|
||||
accountStorages.put(accountId, storage);
|
||||
@@ -453,7 +453,7 @@ public class World {
|
||||
}
|
||||
}
|
||||
|
||||
public MapleStorage getAccountStorage(Integer accountId) {
|
||||
public Storage getAccountStorage(Integer accountId) {
|
||||
return accountStorages.get(accountId);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,28 +43,27 @@ import java.util.*;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Matze
|
||||
*/
|
||||
public class MapleStorage {
|
||||
private static Map<Integer, Integer> trunkGetCache = new HashMap<>();
|
||||
private static Map<Integer, Integer> trunkPutCache = new HashMap<>();
|
||||
public class Storage {
|
||||
private static final Map<Integer, Integer> trunkGetCache = new HashMap<>();
|
||||
private static final Map<Integer, Integer> trunkPutCache = new HashMap<>();
|
||||
|
||||
private int id;
|
||||
private final int id;
|
||||
private int currentNpcid;
|
||||
private int meso;
|
||||
private byte slots;
|
||||
private Map<InventoryType, List<Item>> typeItems = new HashMap<>();
|
||||
private final Map<InventoryType, List<Item>> typeItems = new HashMap<>();
|
||||
private List<Item> items = new LinkedList<>();
|
||||
private Lock lock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.STORAGE, true);
|
||||
private final Lock lock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.STORAGE, true);
|
||||
|
||||
private MapleStorage(int id, byte slots, int meso) {
|
||||
private Storage(int id, byte slots, int meso) {
|
||||
this.id = id;
|
||||
this.slots = slots;
|
||||
this.meso = meso;
|
||||
}
|
||||
|
||||
private static MapleStorage create(int id, int world) throws SQLException {
|
||||
private static Storage create(int id, int world) throws SQLException {
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("INSERT INTO storages (accountid, world, slots, meso) VALUES (?, ?, 4, 0)")) {
|
||||
ps.setInt(1, id);
|
||||
@@ -75,8 +74,8 @@ public class MapleStorage {
|
||||
return loadOrCreateFromDB(id, world);
|
||||
}
|
||||
|
||||
public static MapleStorage loadOrCreateFromDB(int id, int world) {
|
||||
MapleStorage ret;
|
||||
public static Storage loadOrCreateFromDB(int id, int world) {
|
||||
Storage ret;
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT storageid, slots, meso FROM storages WHERE accountid = ? AND world = ?")) {
|
||||
ps.setInt(1, id);
|
||||
@@ -84,7 +83,7 @@ public class MapleStorage {
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (rs.next()) {
|
||||
ret = new MapleStorage(rs.getInt("storageid"), (byte) rs.getInt("slots"), rs.getInt("meso"));
|
||||
ret = new Storage(rs.getInt("storageid"), (byte) rs.getInt("slots"), rs.getInt("meso"));
|
||||
for (Pair<Item, InventoryType> item : ItemFactory.STORAGE.loadItems(ret.id, false)) {
|
||||
ret.items.add(item.getLeft());
|
||||
}
|
||||
@@ -225,7 +224,7 @@ public class MapleStorage {
|
||||
}
|
||||
|
||||
public void sendStorage(Client c, int npcId) {
|
||||
if (c.getPlayer().getLevel() < 15){
|
||||
if (c.getPlayer().getLevel() < 15) {
|
||||
c.getPlayer().dropMessage(1, "You may only use the storage once you have reached level 15.");
|
||||
c.sendPacket(PacketCreator.enableActions());
|
||||
return;
|
||||
@@ -307,12 +306,12 @@ public class MapleStorage {
|
||||
public int getStoreFee() { // thanks to GabrielSin
|
||||
int npcId = currentNpcid;
|
||||
Integer fee = trunkPutCache.get(npcId);
|
||||
if(fee == null) {
|
||||
if (fee == null) {
|
||||
fee = 100;
|
||||
|
||||
DataProvider npc = DataProviderFactory.getDataProvider(WZFiles.NPC);
|
||||
Data npcData = npc.getData(npcId + ".img");
|
||||
if(npcData != null) {
|
||||
if (npcData != null) {
|
||||
fee = DataTool.getIntConvert("info/trunkPut", npcData, 100);
|
||||
}
|
||||
|
||||
@@ -325,12 +324,12 @@ public class MapleStorage {
|
||||
public int getTakeOutFee() {
|
||||
int npcId = currentNpcid;
|
||||
Integer fee = trunkGetCache.get(npcId);
|
||||
if(fee == null) {
|
||||
if (fee == null) {
|
||||
fee = 0;
|
||||
|
||||
DataProvider npc = DataProviderFactory.getDataProvider(WZFiles.NPC);
|
||||
Data npcData = npc.getData(npcId + ".img");
|
||||
if(npcData != null) {
|
||||
if (npcData != null) {
|
||||
fee = DataTool.getIntConvert("info/trunkGet", npcData, 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user