From bd46ce7df71303f543f8bd9c315e3d4941cbb16c Mon Sep 17 00:00:00 2001 From: Teriuihi Date: Wed, 22 Dec 2021 20:58:50 +0100 Subject: [PATCH] Changed updateUserPoints to be settings points instead of adding to existing points and doing it for all points a user has in one go --- src/main/java/com/alttd/database/Queries.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/alttd/database/Queries.java b/src/main/java/com/alttd/database/Queries.java index 3cbcfbd..80fb85e 100644 --- a/src/main/java/com/alttd/database/Queries.java +++ b/src/main/java/com/alttd/database/Queries.java @@ -44,15 +44,15 @@ public class Queries { * NOTE: run async * Add a specified amount of points to the user for the given villager type * - * @param uuid Uuid for the user you want to add the points to - * @param villagerType Type of villager you want to add the points to - * @param points The amount of points to add - * @return success + * @param uuid Uuid for the user you want to add the points to + * @param pointsMap Contains all (villagerType, points) entries for user + * @return success */ - public static boolean updateUserPoints(UUID uuid, String villagerType, int points) { - String sql = "UPDATE user_points SET points = points + ? " + - "WHERE UUID = ? " + - "AND villager_type = ?;"; + public static boolean updateUserPoints(UUID uuid, Object2ObjectArrayMap pointsMap) { + String sql = "INSERT INTO user_points " + + "(uuid, villager_type, points) " + + "VALUES (?, ?, ?) " + + "ON DUPLICATE KEY UPDATE points = ?"; try { PreparedStatement preparedStatement = Database.connection.prepareStatement(sql);