Browse Source

Refactor to remove abstraction

master
MagicBot 2 years ago
parent
commit
2cdb2fce42
  1. 29
      src/engine/db/handlers/dbMobBaseHandler.java
  2. 101
      src/engine/devcmd/cmds/RenameMobCmd.java
  3. 1
      src/engine/gameManager/DevCmdManager.java
  4. 14
      src/engine/objects/MobBase.java

29
src/engine/db/handlers/dbMobBaseHandler.java

@ -11,10 +11,15 @@ package engine.db.handlers;
import engine.Enum.GameObjectType; import engine.Enum.GameObjectType;
import engine.gameManager.DbManager; 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 engine.server.MBServerStatics;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
@ -27,22 +32,32 @@ public class dbMobBaseHandler extends dbHandlerBase {
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); 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) if (id == 0)
return null; return null;
MobBase mobBase = (MobBase) DbManager.getFromCache(GameObjectType.MobBase, id); MobBase mobBase = (MobBase) DbManager.getFromCache(GameObjectType.MobBase, id);
if ( mobBase != null) if (mobBase != null)
return mobBase; return mobBase;
prepareCallable("SELECT * FROM `static_npc_mobbase` WHERE `ID`=?"); try (Connection connection = DbManager.getConnection();
setInt(1, id); PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase` WHERE `ID`=?")) {
return (MobBase) getObjectSingle(id, forceDB, true);
preparedStatement.setInt(1, id);
ResultSet rs = preparedStatement.executeQuery();
mobBase = (MobBase) getObjectFromRs(rs);
} catch (SQLException e) {
Logger.error(e);
} }
return mobBase;
}
public ArrayList<MobBase> GET_ALL_MOBBASES() { public ArrayList<MobBase> GET_ALL_MOBBASES() {
prepareCallable("SELECT * FROM `static_npc_mobbase`;"); prepareCallable("SELECT * FROM `static_npc_mobbase`;");
return getObjectList(); return getObjectList();

101
src/engine/devcmd/cmds/RenameMobCmd.java

@ -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";
}
}

1
src/engine/gameManager/DevCmdManager.java

@ -93,7 +93,6 @@ public enum DevCmdManager {
DevCmdManager.registerDevCmd(new GetBankCmd()); DevCmdManager.registerDevCmd(new GetBankCmd());
DevCmdManager.registerDevCmd(new GetVaultCmd()); DevCmdManager.registerDevCmd(new GetVaultCmd());
DevCmdManager.registerDevCmd(new CombatMessageCmd()); DevCmdManager.registerDevCmd(new CombatMessageCmd());
DevCmdManager.registerDevCmd(new RenameMobCmd());
DevCmdManager.registerDevCmd(new RenameCmd()); DevCmdManager.registerDevCmd(new RenameCmd());
DevCmdManager.registerDevCmd(new CreateItemCmd()); DevCmdManager.registerDevCmd(new CreateItemCmd());
DevCmdManager.registerDevCmd(new GetMemoryCmd()); DevCmdManager.registerDevCmd(new GetMemoryCmd());

14
src/engine/objects/MobBase.java

@ -206,20 +206,8 @@ public class MobBase extends AbstractGameObject {
return this.spawnTime; return this.spawnTime;
} }
/*
* Database
*/
public static MobBase getMobBase(int id) { public static MobBase getMobBase(int id) {
return MobBase.getMobBase(id, false); return DbManager.MobBaseQueries.GET_MOBBASE(id);
}
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);
} }
@Override @Override

Loading…
Cancel
Save