diff --git a/src/engine/db/handlers/dbMobBaseHandler.java b/src/engine/db/handlers/dbMobBaseHandler.java index d772f262..d5abeaec 100644 --- a/src/engine/db/handlers/dbMobBaseHandler.java +++ b/src/engine/db/handlers/dbMobBaseHandler.java @@ -11,10 +11,15 @@ package engine.db.handlers; import engine.Enum.GameObjectType; import engine.gameManager.DbManager; -import engine.objects.*; +import engine.objects.MobBase; +import engine.objects.MobBaseEffects; +import engine.objects.MobBaseStats; +import engine.objects.MobLootBase; import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; +import java.sql.Connection; +import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; @@ -27,22 +32,32 @@ public class dbMobBaseHandler extends dbHandlerBase { this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); } - public MobBase GET_MOBBASE(int id, boolean forceDB) { - + public MobBase GET_MOBBASE(int id) { if (id == 0) return null; MobBase mobBase = (MobBase) DbManager.getFromCache(GameObjectType.MobBase, id); - if ( mobBase != null) + if (mobBase != null) return mobBase; - prepareCallable("SELECT * FROM `static_npc_mobbase` WHERE `ID`=?"); - setInt(1, id); - return (MobBase) getObjectSingle(id, forceDB, true); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase` WHERE `ID`=?")) { + + preparedStatement.setInt(1, id); + + ResultSet rs = preparedStatement.executeQuery(); + mobBase = (MobBase) getObjectFromRs(rs); + + } catch (SQLException e) { + Logger.error(e); + } + + return mobBase; } + public ArrayList GET_ALL_MOBBASES() { prepareCallable("SELECT * FROM `static_npc_mobbase`;"); return getObjectList(); diff --git a/src/engine/devcmd/cmds/RenameMobCmd.java b/src/engine/devcmd/cmds/RenameMobCmd.java deleted file mode 100644 index 0e0dee1f..00000000 --- a/src/engine/devcmd/cmds/RenameMobCmd.java +++ /dev/null @@ -1,101 +0,0 @@ -// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . -// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· -// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ -// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ -// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ -// Magicbane Emulator Project © 2013 - 2022 -// www.magicbane.com - - -package engine.devcmd.cmds; - -import engine.devcmd.AbstractDevCmd; -import engine.gameManager.ChatManager; -import engine.objects.AbstractGameObject; -import engine.objects.MobBase; -import engine.objects.NPC; -import engine.objects.PlayerCharacter; - -/** - * - * @author Eighty - * - */ -public class RenameMobCmd extends AbstractDevCmd { - - public RenameMobCmd() { - super("renamemob"); - } - - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { - if (args.length < 1) { - this.sendUsage(pcSender); - return; - } - int loadID = 0; - String name = ""; - NPC npc; - if (target != null && target instanceof NPC) - npc = (NPC) target; - else - npc = getTargetAsNPC(pcSender); - if (npc != null) { - for (int i = 0; i < args.length; i++) { - name += args[i]; - if (i + 1 < args.length) - name += " "; - } - npc.setName(name); - npc.updateDatabase(); - ChatManager.chatSayInfo( - pcSender, - "NPC with ID " + npc.getObjectUUID() + " renamed to " - + npc.getFirstName()); - } else { - try { - loadID = Integer.parseInt(args[0]); - if (args.length > 1) { - for (int i = 1; i < args.length; i++) { - name += args[i]; - if (i + 1 < args.length) - name += " "; - } - } - } catch (Exception e) { - throwbackError(pcSender, - "Invalid renameMob Command. Need mob ID specified."); - return; // NaN - } - MobBase mob = MobBase.getMobBase(loadID); - if (mob == null) { - throwbackError(pcSender, - "Invalid renameMob Command. Mob ID specified is not valid."); - return; - } - if (!MobBase.renameMobBase(mob.getObjectUUID(), name)) { - throwbackError(pcSender, - "renameMob SQL Error. Failed to rename mob."); - return; - } - mob = MobBase.getMobBase(mob.getObjectUUID(), true); // force refresh - // from db - ChatManager.chatSayInfo( - pcSender, - "MobBase with ID " + mob.getObjectUUID() + " renamed to " - + mob.getFirstName()); - } - } - - @Override - protected String _getUsageString() { - return "' /renamemob [ID] newName'"; - } - - @Override - protected String _getHelpString() { - return "Changes a mobs old name to a new name"; - } - -} diff --git a/src/engine/gameManager/DevCmdManager.java b/src/engine/gameManager/DevCmdManager.java index 8e2ecf82..7c68d2f7 100644 --- a/src/engine/gameManager/DevCmdManager.java +++ b/src/engine/gameManager/DevCmdManager.java @@ -93,7 +93,6 @@ public enum DevCmdManager { DevCmdManager.registerDevCmd(new GetBankCmd()); DevCmdManager.registerDevCmd(new GetVaultCmd()); DevCmdManager.registerDevCmd(new CombatMessageCmd()); - DevCmdManager.registerDevCmd(new RenameMobCmd()); DevCmdManager.registerDevCmd(new RenameCmd()); DevCmdManager.registerDevCmd(new CreateItemCmd()); DevCmdManager.registerDevCmd(new GetMemoryCmd()); diff --git a/src/engine/objects/MobBase.java b/src/engine/objects/MobBase.java index 0f32a1d5..67df8821 100644 --- a/src/engine/objects/MobBase.java +++ b/src/engine/objects/MobBase.java @@ -206,20 +206,8 @@ public class MobBase extends AbstractGameObject { return this.spawnTime; } - /* - * Database - */ public static MobBase getMobBase(int id) { - return MobBase.getMobBase(id, false); - } - - public static MobBase getMobBase(int id, boolean forceDB) { - return DbManager.MobBaseQueries.GET_MOBBASE(id, forceDB); - } - - - public static boolean renameMobBase(int ID, String newName) { - return DbManager.MobBaseQueries.RENAME_MOBBASE(ID, newName); + return DbManager.MobBaseQueries.GET_MOBBASE(id); } @Override