Files
prestonbane/src/engine/db/handlers/dbPlayerCharacterHandler.java
T

572 lines
21 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;
import engine.Enum;
import engine.gameManager.DbManager;
2024-04-01 17:00:14 -04:00
import engine.objects.AbstractWorldObject;
import engine.objects.Heraldry;
import engine.objects.PlayerCharacter;
import engine.objects.PlayerFriends;
2022-04-30 09:41:17 -04:00
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger;
2023-05-22 08:54:59 -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.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
public class dbPlayerCharacterHandler extends dbHandlerBase {
2023-05-23 10:27:03 -04:00
public dbPlayerCharacterHandler() {
this.localClass = PlayerCharacter.class;
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
}
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
public PlayerCharacter ADD_PLAYER_CHARACTER(final PlayerCharacter toAdd) {
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
PlayerCharacter playerCharacter = null;
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
if (toAdd.getAccount() == null)
return null;
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("CALL `character_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")) {
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setLong(1, toAdd.getAccount().getObjectUUID());
preparedStatement.setString(2, toAdd.getFirstName());
preparedStatement.setString(3, toAdd.getLastName());
2024-03-27 17:17:34 -05:00
preparedStatement.setInt(4, toAdd.race.getRaceRuneID());
preparedStatement.setInt(5, toAdd.baseClass.getObjectUUID());
2023-05-23 10:27:03 -04:00
preparedStatement.setInt(6, toAdd.getStrMod());
preparedStatement.setInt(7, toAdd.getDexMod());
preparedStatement.setInt(8, toAdd.getConMod());
preparedStatement.setInt(9, toAdd.getIntMod());
preparedStatement.setInt(10, toAdd.getSpiMod());
preparedStatement.setInt(11, toAdd.getExp());
preparedStatement.setInt(12, toAdd.getSkinColor());
preparedStatement.setInt(13, toAdd.getHairColor());
preparedStatement.setByte(14, toAdd.getHairStyle());
preparedStatement.setInt(15, toAdd.getBeardColor());
preparedStatement.setByte(16, toAdd.getBeardStyle());
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
ResultSet rs = preparedStatement.executeQuery();
2023-05-22 08:54:59 -04:00
2023-05-23 12:24:11 -04:00
if (rs.next()) {
int objectUUID = (int) rs.getLong("UID");
2023-05-22 08:54:59 -04:00
2023-05-23 12:24:11 -04:00
if (objectUUID > 0)
playerCharacter = GET_PLAYER_CHARACTER(objectUUID);
}
2023-05-23 14:29:08 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
return playerCharacter;
}
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
public boolean SET_IGNORE_LIST(int sourceID, int targetID, boolean toIgnore, String charName) {
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
String queryString = "";
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
if (toIgnore)
queryString = "INSERT INTO `dyn_character_ignore` (`accountUID`, `ignoringUID`, `characterName`) VALUES (?, ?, ?)";
else
queryString = "DELETE FROM `dyn_character_ignore` WHERE `accountUID` = ? && `ignoringUID` = ?";
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(queryString)) {
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setLong(1, sourceID);
preparedStatement.setLong(2, targetID);
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
if (toIgnore)
preparedStatement.setString(3, charName);
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
return (preparedStatement.executeUpdate() > 0);
2023-05-22 08:54:59 -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
2023-05-23 10:27:03 -04:00
public ArrayList<PlayerCharacter> GET_CHARACTERS_FOR_ACCOUNT(final int id) {
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
ArrayList<PlayerCharacter> characterList = new ArrayList<>();
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_character`.*, `object`.`parent` FROM `object` INNER JOIN `obj_character` ON `obj_character`.`UID` = `object`.`UID` WHERE `object`.`parent`=? && `obj_character`.`char_isActive`='1';")) {
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setLong(1, id);
ResultSet rs = preparedStatement.executeQuery();
characterList = getObjectsFromRs(rs, 10);
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
return characterList;
}
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
public ArrayList<PlayerCharacter> GET_ALL_CHARACTERS() {
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
ArrayList<PlayerCharacter> characterList = new ArrayList<>();
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_character`.*, `object`.`parent` FROM `object` INNER JOIN `obj_character` ON `obj_character`.`UID` = `object`.`UID` WHERE `obj_character`.`char_isActive`='1';")) {
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
ResultSet rs = preparedStatement.executeQuery();
characterList = getObjectsFromRs(rs, 2000);
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
return characterList;
}
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
/**
* <code>getFirstName</code> looks up the first name of a PlayerCharacter by
* first checking the GOM cache and then querying the database.
* PlayerCharacter objects that are not already cached won't be instantiated
* and cached.
*/
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
public ConcurrentHashMap<Integer, String> GET_IGNORE_LIST(final int objectUUID, final boolean skipActiveCheck) {
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
ConcurrentHashMap<Integer, String> ignoreList = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_ignore` WHERE `accountUID` = ?;")) {
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setLong(1, objectUUID);
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
ResultSet rs = preparedStatement.executeQuery();
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
while (rs.next()) {
int ignoreCharacterID = rs.getInt("ignoringUID");
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
if (ignoreCharacterID == 0)
continue;
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
String name = rs.getString("characterName");
ignoreList.put(ignoreCharacterID, name);
}
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
2023-05-22 08:54:59 -04:00
2023-05-23 10:27:03 -04:00
return ignoreList;
}
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
public PlayerCharacter GET_PLAYER_CHARACTER(final int objectUUID) {
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
if (objectUUID == 0)
return null;
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
PlayerCharacter playerCharacter = (PlayerCharacter) DbManager.getFromCache(Enum.GameObjectType.PlayerCharacter, objectUUID);
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
if (playerCharacter != null)
return playerCharacter;
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_character`.*, `object`.`parent` FROM `object` INNER JOIN `obj_character` ON `obj_character`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?")) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setLong(1, objectUUID);
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
ResultSet rs = preparedStatement.executeQuery();
playerCharacter = (PlayerCharacter) getObjectFromRs(rs);
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
return playerCharacter;
}
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
public boolean IS_CHARACTER_NAME_UNIQUE(final String firstName) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
boolean unique = true;
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `char_firstname` FROM `obj_character` WHERE `char_isActive`=1 && `char_firstname`=?")) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setString(1, firstName);
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
ResultSet rs = preparedStatement.executeQuery();
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
if (rs.next())
unique = false;
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
return unique;
}
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
public boolean UPDATE_NAME(String oldFirstName, String newFirstName, String newLastName) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_firstname`=?, `char_lastname`=? WHERE `char_firstname`=? AND `char_isActive`='1'")) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setString(1, newFirstName);
preparedStatement.setString(2, newLastName);
preparedStatement.setString(3, oldFirstName);
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
return (preparedStatement.executeUpdate() > 0);
2023-05-22 09:34:59 -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
2023-05-23 10:27:03 -04:00
public boolean SET_DELETED(final PlayerCharacter pc) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_isActive`=? WHERE `UID` = ?")) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setBoolean(1, !pc.isDeleted());
preparedStatement.setLong(2, pc.getObjectUUID());
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
return (preparedStatement.executeUpdate() > 0);
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
return false;
}
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
public boolean SET_ACTIVE(final PlayerCharacter pc, boolean status) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_isActive`=? WHERE `UID` = ?")) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setBoolean(1, status);
preparedStatement.setLong(2, pc.getObjectUUID());
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
return (preparedStatement.executeUpdate() > 0);
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
return false;
}
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
public boolean SET_BIND_BUILDING(final PlayerCharacter pc, int bindBuildingID) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_bindBuilding`=? WHERE `UID` = ?")) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setInt(1, bindBuildingID);
preparedStatement.setLong(2, pc.getObjectUUID());
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
return (preparedStatement.executeUpdate() > 0);
2023-05-22 09:34:59 -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
2023-05-23 10:27:03 -04:00
public boolean SET_ANNIVERSERY(final PlayerCharacter pc, boolean flag) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `anniversery`=? WHERE `UID` = ?")) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setBoolean(1, flag);
preparedStatement.setLong(2, pc.getObjectUUID());
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
return (preparedStatement.executeUpdate() > 0);
2023-05-22 09:34:59 -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
2023-05-23 10:27:03 -04:00
public boolean UPDATE_CHARACTER_EXPERIENCE(final PlayerCharacter pc) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_experience`=? WHERE `UID` = ?")) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setInt(1, pc.getExp());
preparedStatement.setLong(2, pc.getObjectUUID());
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
return (preparedStatement.executeUpdate() > 0);
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
return false;
}
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
public boolean UPDATE_GUILD(final PlayerCharacter pc, int guildUUID) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guildUID`=? WHERE `UID` = ?")) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setInt(1, guildUUID);
preparedStatement.setLong(2, pc.getObjectUUID());
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
return (preparedStatement.executeUpdate() > 0);
2022-04-30 09:41:17 -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
2023-05-23 10:27:03 -04:00
public boolean UPDATE_CHARACTER_STATS(final PlayerCharacter pc) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_strMod`=?, `char_dexMod`=?, `char_conMod`=?, `char_intMod`=?, `char_spiMod`=? WHERE `UID`=?")) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setInt(1, pc.getStrMod());
preparedStatement.setInt(2, pc.getDexMod());
preparedStatement.setInt(3, pc.getConMod());
preparedStatement.setInt(4, pc.getIntMod());
preparedStatement.setInt(5, pc.getSpiMod());
preparedStatement.setLong(6, pc.getObjectUUID());
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
return (preparedStatement.executeUpdate() > 0);
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
return false;
}
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
public String SET_PROPERTY(final PlayerCharacter playerCharacter, String name, Object new_value) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
String result = "";
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("CALL character_SETPROP(?,?,?)")) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setLong(1, playerCharacter.getObjectUUID());
preparedStatement.setString(2, name);
preparedStatement.setString(3, String.valueOf(new_value));
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
ResultSet rs = preparedStatement.executeQuery();
2023-05-23 14:29:08 -04:00
if (rs.next())
result = rs.getString("result");
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
return result;
}
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
public boolean SET_PROMOTION_CLASS(PlayerCharacter player, int promotionClassID) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_promotionClassID`=? WHERE `UID`=?;")) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setInt(1, promotionClassID);
preparedStatement.setInt(2, player.getObjectUUID());
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
return (preparedStatement.executeUpdate() > 0);
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
return false;
}
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
public boolean SET_INNERCOUNCIL(PlayerCharacter player, boolean isInnerCouncil) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isInnerCouncil`=? WHERE `UID`=?;")) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setBoolean(1, isInnerCouncil);
preparedStatement.setInt(2, player.getObjectUUID());
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
return (preparedStatement.executeUpdate() > 0);
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
return false;
}
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
public boolean SET_FULL_MEMBER(PlayerCharacter player, boolean isFullMember) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isFullMember`=? WHERE `UID`=?;")) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setBoolean(1, isFullMember);
preparedStatement.setInt(2, player.getObjectUUID());
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
return (preparedStatement.executeUpdate() > 0);
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
return false;
}
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
public boolean SET_TAX_COLLECTOR(PlayerCharacter player, boolean isTaxCollector) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isTaxCollector`=? WHERE `UID`=?;")) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setBoolean(1, isTaxCollector);
preparedStatement.setInt(2, player.getObjectUUID());
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
return (preparedStatement.executeUpdate() > 0);
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
return false;
}
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
public boolean SET_RECRUITER(PlayerCharacter player, boolean isRecruiter) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isRecruiter`=? WHERE `UID`=?;")) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setBoolean(1, isRecruiter);
preparedStatement.setInt(2, player.getObjectUUID());
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
return (preparedStatement.executeUpdate() > 0);
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
return false;
}
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
public boolean SET_GUILD_TITLE(PlayerCharacter player, int title) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_title`=? WHERE `UID`=?;")) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setInt(1, title);
preparedStatement.setInt(2, player.getObjectUUID());
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
return (preparedStatement.executeUpdate() > 0);
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
return false;
}
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
public boolean ADD_FRIEND(int source, long friend) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_friends` (`playerUID`, `friendUID`) VALUES (?, ?)")) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setLong(1, source);
preparedStatement.setLong(2, friend);
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
return (preparedStatement.executeUpdate() > 0);
2022-04-30 09:41:17 -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
2023-05-23 10:27:03 -04:00
public boolean REMOVE_FRIEND(int source, int friend) {
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_character_friends` WHERE (`playerUID`=?) AND (`friendUID`=?)")) {
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setLong(1, source);
preparedStatement.setLong(2, friend);
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
return (preparedStatement.executeUpdate() > 0);
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
return false;
}
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
public void LOAD_PLAYER_FRIENDS() {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
PlayerFriends playerFriend;
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM dyn_character_friends")) {
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
ResultSet rs = preparedStatement.executeQuery();
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
while (rs.next())
playerFriend = new PlayerFriends(rs);
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
2023-05-22 09:34:59 -04:00
2023-05-23 10:27:03 -04:00
}
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
public boolean ADD_HERALDY(int source, AbstractWorldObject character) {
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_character_heraldy` (`playerUID`, `characterUID`,`characterType`) VALUES (?, ?,?)")) {
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setLong(1, source);
preparedStatement.setLong(2, character.getObjectUUID());
preparedStatement.setInt(3, character.getObjectType().ordinal());
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
}
return false;
}
public boolean REMOVE_HERALDY(int source, int characterUID) {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_heraldy` WHERE (`playerUID`=?) AND (`characterUID`=?)")) {
preparedStatement.setLong(1, source);
preparedStatement.setLong(2, characterUID);
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
}
return false;
}
public void LOAD_HERALDY() {
Heraldry heraldy;
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM dyn_character_heraldy")) {
ResultSet rs = preparedStatement.executeQuery();
while (rs.next())
heraldy = new Heraldry(rs);
} catch (SQLException e) {
Logger.error(e);
}
}
2022-04-30 09:41:17 -04:00
}