Browse Source

Refactor out itembase

combat-2
MagicBot 8 months ago
parent
commit
fc06ea97bd
  1. 51
      src/engine/db/handlers/dbItemBaseHandler.java
  2. 1
      src/engine/gameManager/DbManager.java
  3. 55
      src/engine/objects/ItemBase.java
  4. 4
      src/engine/server/login/LoginServer.java
  5. 3
      src/engine/server/world/WorldServer.java

51
src/engine/db/handlers/dbItemBaseHandler.java

@ -1,51 +0,0 @@ @@ -1,51 +0,0 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.db.handlers;
import engine.gameManager.DbManager;
import engine.objects.ItemBase;
import org.pmw.tinylog.Logger;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class dbItemBaseHandler extends dbHandlerBase {
public dbItemBaseHandler() {
}
public void LOAD_ALL_ITEMBASES() {
ItemBase itemBase;
int recordsRead = 0;
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_itembase")) {
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
recordsRead++;
itemBase = new ItemBase(rs);
ItemBase.addToCache(itemBase);
}
} catch (SQLException e) {
Logger.error(e);
}
Logger.info("read: " + recordsRead + " cached: " + ItemBase.getUUIDCache().size());
}
}

1
src/engine/gameManager/DbManager.java

@ -48,7 +48,6 @@ public enum DbManager { @@ -48,7 +48,6 @@ public enum DbManager {
public static final dbEffectsResourceCostHandler EffectsResourceCostsQueries = new dbEffectsResourceCostHandler();
public static final dbGuildHandler GuildQueries = new dbGuildHandler();
public static final dbItemHandler ItemQueries = new dbItemHandler();
public static final dbItemBaseHandler ItemBaseQueries = new dbItemBaseHandler();
public static final dbKitHandler KitQueries = new dbKitHandler();
public static final dbLootHandler LootQueries = new dbLootHandler();
public static final dbMenuHandler MenuQueries = new dbMenuHandler();

55
src/engine/objects/ItemBase.java

@ -1,55 +0,0 @@ @@ -1,55 +0,0 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.objects;
import engine.gameManager.DbManager;
import org.pmw.tinylog.Logger;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
public class ItemBase {
public static ItemBase GOLD_ITEM_BASE = null;
public static HashMap<Integer, ItemBase> _itemBaseByUUID = new HashMap<>();
public final int uuid;
public ItemBase(ResultSet rs) throws SQLException {
this.uuid = rs.getInt("ID");
}
public static void addToCache(ItemBase itemBase) {
_itemBaseByUUID.put(itemBase.uuid, itemBase);
ItemTemplate template = ItemTemplate.templates.get(itemBase.uuid);
if (template == null)
Logger.error("Null template for: " + itemBase.uuid);
}
public static HashMap<Integer, ItemBase> getUUIDCache() {
return _itemBaseByUUID;
}
public static void loadAllItemBases() {
DbManager.ItemBaseQueries.LOAD_ALL_ITEMBASES();
}
public final int getUUID() {
return uuid;
}
}

4
src/engine/server/login/LoginServer.java

@ -266,9 +266,6 @@ public class LoginServer { @@ -266,9 +266,6 @@ public class LoginServer {
Logger.info("Loading Kits");
DbManager.KitQueries.GET_ALL_KITS();
Logger.info("Initializing ItemBase data.");
ItemBase.loadAllItemBases();
Logger.info("Initializing Race data");
Enum.RaceType.initRaceTypeTables();
Race.loadAllRaces();
@ -279,7 +276,6 @@ public class LoginServer { @@ -279,7 +276,6 @@ public class LoginServer {
Logger.info("Loading All Guilds");
DbManager.GuildQueries.GET_ALL_GUILDS();
Logger.info("***Boot Successful***");
return true;
}

3
src/engine/server/world/WorldServer.java

@ -346,9 +346,6 @@ public class WorldServer { @@ -346,9 +346,6 @@ public class WorldServer {
Logger.info("Back fill template modTables");
DbManager.ItemQueries.LOAD_TEMPLATE_MODTABLES();
Logger.info("Loading ItemBases");
ItemBase.loadAllItemBases();
Logger.info("Loading PromotionClasses");
DbManager.PromotionQueries.GET_ALL_PROMOTIONS();

Loading…
Cancel
Save