Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix - DB fix resulting in plugin now loading correctly #11

Merged
merged 1 commit into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public abstract class DatabaseQueries {


/**
* Attempts to save skill category exp to DB.
* Attempts to save skill category experience to DB.
*
* @param uuid
* @param skillCategoryId
* @param exp
* @param experience
*/

public static void saveSkillCategoryExp(UUID uuid, int skillCategoryId, Float exp) {
public static void saveSkillCategoryExperience(UUID uuid, int skillCategoryId, Float experience) {
try (
Connection con = DB.getConnection()
) {
Expand All @@ -42,22 +42,22 @@ public static void saveSkillCategoryExp(UUID uuid, int skillCategoryId, Float ex
.insertInto(PLAYER_SKILLCATEGORYINFO,
PLAYER_SKILLCATEGORYINFO.UUID,
PLAYER_SKILLCATEGORYINFO.SKILLCATEGORYID,
PLAYER_SKILLCATEGORYINFO.EXP)
PLAYER_SKILLCATEGORYINFO.EXPERIENCE)
.values(
convertUUIDToBytes(uuid),
skillCategoryId,
exp.doubleValue()
experience.doubleValue()
)
.onDuplicateKeyUpdate()
.set(PLAYER_SKILLCATEGORYINFO.EXP, exp.doubleValue())
.set(PLAYER_SKILLCATEGORYINFO.EXPERIENCE, experience.doubleValue())
.execute();
} catch (SQLException e) {
Logger.get().error("SQL Query threw an error!", e);
}
}

public static void saveSkillCategoryExp(Player p, int skillCategoryId, float exp) {
saveSkillCategoryExp(p.getUniqueId(), skillCategoryId, exp);
public static void saveSkillCategoryExperience(Player p, int skillCategoryId, float experience) {
saveSkillCategoryExperience(p.getUniqueId(), skillCategoryId, experience);
}

/**
Expand Down Expand Up @@ -92,21 +92,21 @@ public static void saveSkillInfo(Player p, int skillId) {
}

/**
* Fetches skill category exp.
* Fetches skill category experience.
*
* @param uuid
* @param skillCategoryId
* @return record containing skill category exp.
* @return record containing skill category experience.
*/

public static Record1<Double> getSkillCategoryExp(UUID uuid, int skillCategoryId) {
public static Record1<Double> getSkillCategoryExperience(UUID uuid, int skillCategoryId) {
try (
Connection con = DB.getConnection()
) {
DSLContext context = DB.getContext(con);

return context
.select(PLAYER_SKILLCATEGORYINFO.EXP)
.select(PLAYER_SKILLCATEGORYINFO.EXPERIENCE)
.from(PLAYER_SKILLCATEGORYINFO)
.where(PLAYER_SKILLCATEGORYINFO.UUID.equal(convertUUIDToBytes(uuid)))
.and(PLAYER_SKILLCATEGORYINFO.SKILLCATEGORYID.equal(skillCategoryId))
Expand All @@ -117,24 +117,24 @@ public static Record1<Double> getSkillCategoryExp(UUID uuid, int skillCategoryId
}
}

public static Record1<Double> getSkillCategoryExp(Player p, int skillCategoryId) {
return getSkillCategoryExp(p.getUniqueId(), skillCategoryId);
public static Record1<Double> getSkillCategoryExperience(Player p, int skillCategoryId) {
return getSkillCategoryExperience(p.getUniqueId(), skillCategoryId);
}

/**
* Convenience method for {@link #getSkillCategoryExp(UUID, int)}
* Convenience method for {@link #getSkillCategoryExperience(UUID, int)}
*
* @param uuid
* @param skillCategoryId
* @return skill category exp as float.
* @return skill category experience as float.
*/

public static float getSkillCategoryExpFloat(UUID uuid, int skillCategoryId) {
return (float) getSkillCategoryExp(uuid, skillCategoryId).getValue("EXP");
public static float getSkillCategoryExperienceFloat(UUID uuid, int skillCategoryId) {
return (float) getSkillCategoryExperience(uuid, skillCategoryId).getValue("EXP");
}

public static float getSkillCategoryExpFloat(Player p, int skillCategoryId) {
return getSkillCategoryExpFloat(p.getUniqueId(), skillCategoryId);
public static float getSkillCategoryExperienceFloat(Player p, int skillCategoryId) {
return getSkillCategoryExperienceFloat(p.getUniqueId(), skillCategoryId);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public final class JooqContext {
JooqLogger.globalThreshold(Log.Level.ERROR); // Silence JOOQ warnings
}

private static final String TABLE_PREFIX = Cfg.get().getOrDefault("db.prefix", "example_"); // The table prefix as grabbed from config
private static final String TABLE_PREFIX = Cfg.get().getOrDefault("db.prefix", "alathras_skills_"); // The table prefix as grabbed from config
private static final Pattern MATCH_ALL_EXCEPT_INFORMATION_SCHEMA = Pattern.compile("^(?!INFORMATION_SCHEMA)(.*?)$");
private static final Pattern MATCH_ALL = Pattern.compile("^(.*?)$");
private static final String REPLACEMENT = "%s$0".formatted(TABLE_PREFIX); //
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/db/migration/V1__create_tables.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CREATE TABLE IF NOT EXISTS ${tablePrefix}player_skillcategoryinfo (
uuid ${uuidType} NOT NULL,
skillcategoryid INT NOT NULL,
exp FLOAT NOT NULL,
experience FLOAT NOT NULL,
PRIMARY KEY (uuid, skillcategoryid)
)${tableDefaults};

Expand Down