Files
BattleBane/src/engine/db/handlers/dbEnchantmentHandler.java
T

76 lines
2.9 KiB
Java
Raw Normal View History

2022-04-30 09:41:17 -04:00
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.db.handlers;
2023-05-21 17:50:44 -04:00
import engine.gameManager.DbManager;
2022-04-30 09:41:17 -04:00
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger;
2023-05-21 17:50:44 -04:00
import java.sql.Connection;
import java.sql.PreparedStatement;
2022-04-30 09:41:17 -04:00
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.concurrent.ConcurrentHashMap;
public class dbEnchantmentHandler extends dbHandlerBase {
2023-05-23 10:27:03 -04:00
public ConcurrentHashMap<String, Integer> GET_ENCHANTMENTS_FOR_ITEM(final int id) {
2023-05-21 17:50:44 -04:00
2023-05-23 10:27:03 -04:00
ConcurrentHashMap<String, Integer> enchants = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
2023-05-21 17:50:44 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_item_enchantment` WHERE `ItemID`=?;")) {
2023-05-21 17:50:44 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setLong(1, id);
2023-05-21 17:50:44 -04:00
2023-05-23 10:27:03 -04:00
ResultSet rs = preparedStatement.executeQuery();
2023-05-21 17:50:44 -04:00
2023-05-23 10:27:03 -04:00
while (rs.next())
enchants.put(rs.getString("powerAction"), rs.getInt("rank"));
2023-05-21 17:50:44 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
2023-05-21 17:50:44 -04:00
2023-05-23 10:27:03 -04:00
return enchants;
}
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
public boolean CREATE_ENCHANTMENT_FOR_ITEM(long itemID, String powerAction, int rank) {
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_item_enchantment` (`itemID`, `powerAction`, `rank`) VALUES (?, ?, ?);")) {
2023-05-21 17:50:44 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setLong(1, itemID);
preparedStatement.setString(2, powerAction);
preparedStatement.setInt(3, rank);
2023-05-21 17:50:44 -04:00
2023-05-23 10:27:03 -04:00
return (preparedStatement.executeUpdate() > 0);
2023-05-21 17:50:44 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
return false;
}
2023-05-23 09:17:06 -04:00
2023-05-23 10:27:03 -04:00
public boolean CLEAR_ENCHANTMENTS(long itemID) {
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_item_enchantment` WHERE `itemID`=?;")) {
2023-05-21 17:50:44 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setLong(1, itemID);
return (preparedStatement.executeUpdate() > 0);
2023-05-21 17:50:44 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
return false;
}
2022-04-30 09:41:17 -04:00
}