Skip to content

Commit d9d326d

Browse files
committed
小修正
1 parent cf0c215 commit d9d326d

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

src/main/java/dev/felnull/pointed/teams/manager/reward/RewardAdminService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,8 @@ void dispatchByBuckets(long teamSubjectId, String scope,
7777
RewardDetail getRewardDetail(int rewardId, boolean onlyEnabledCommands) throws SQLException;
7878

7979
/** 過去にその報酬を配布したか */
80-
boolean hasEverDistributedRewardToPlayer(long playerSubjectId, int rewardId) throws SQLException;
80+
boolean hasEverDistributedRewardToPlayerByUuid(UUID playerUuid, int rewardId);
81+
82+
// === 既存シグネチャ互換の非Tx版(内部で接続取得)===
83+
boolean hasEverDistributedRewardToPlayer(long teamId, int rewardId) throws SQLException;
8184
}

src/main/java/dev/felnull/pointed/teams/manager/reward/impl/RewardAdminServiceImpl.java

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import dev.felnull.pointed.teams.manager.reward.RewardAdminService;
88
import dev.felnull.pointed.teams.manager.reward.data.*;
99
import org.bukkit.Bukkit;
10-
import org.bukkit.OfflinePlayer;
11-
import org.jetbrains.annotations.Nullable;
1210

1311
import javax.sql.DataSource;
1412
import java.sql.*;
@@ -785,11 +783,33 @@ public boolean rewardExistsByName(Connection con, String name) throws SQLExcepti
785783
}
786784

787785
@Override
788-
public boolean hasEverDistributedRewardToPlayer(
789-
long playerSubjectId,
790-
int rewardId
791-
) throws SQLException {
792-
Connection con = Db.get().getConnection();
786+
public boolean hasEverDistributedRewardToPlayerByUuid(UUID playerUuid, int rewardId) {
787+
final String subjectType = "PLAYER";
788+
final String subjectKey = playerUuid.toString();
789+
790+
try (Connection con = Db.get().getConnection()) {
791+
// subjects.id を拾う(無ければ未配布扱い)
792+
final String q = "SELECT id FROM " + Names.t("subjects") +
793+
" WHERE type = ? AND subject_key = ? LIMIT 1";
794+
Long subjectId = null;
795+
try (PreparedStatement ps = con.prepareStatement(q)) {
796+
ps.setString(1, subjectType);
797+
ps.setString(2, subjectKey);
798+
try (ResultSet rs = ps.executeQuery()) {
799+
if (rs.next()) subjectId = rs.getLong(1);
800+
}
801+
}
802+
if (subjectId == null) return false;
803+
return hasEverDistributedRewardToPlayer(con, subjectId, rewardId);
804+
} catch (SQLException e) {
805+
throw new RuntimeException(e);
806+
}
807+
}
808+
809+
// === Tx内で使える版(同一接続を使い回す用)===
810+
public boolean hasEverDistributedRewardToPlayer(Connection con,
811+
long playerSubjectId,
812+
int rewardId) throws SQLException {
793813
final String sql =
794814
"SELECT 1 FROM " + Names.t("reward_dispatch_log") +
795815
" WHERE player_subject_id = ? AND reward_id = ? LIMIT 1";
@@ -802,4 +822,12 @@ public boolean hasEverDistributedRewardToPlayer(
802822
}
803823
}
804824

825+
// === 既存シグネチャ互換の非Tx版(内部で接続取得)===
826+
@Override
827+
public boolean hasEverDistributedRewardToPlayer(long playerSubjectId, int rewardId) throws SQLException {
828+
try (Connection con = Db.get().getConnection()) {
829+
return hasEverDistributedRewardToPlayer(con, playerSubjectId, rewardId);
830+
}
831+
}
832+
805833
}

0 commit comments

Comments
 (0)