Skip to content

Commit bd39f22

Browse files
committed
scope一覧取得機能を追加
1 parent 60494b8 commit bd39f22

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

src/main/java/dev/felnull/pointed/core/commands/PtCommand.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package dev.felnull.pointed.core.commands;
22

3+
import dev.felnull.pointed.Pointed;
4+
import dev.felnull.pointed.core.database.api.PointServiceImpl;
35
import dev.felnull.pointed.core.database.data.RankRow;
46
import dev.felnull.pointed.core.database.api.PointService;
57
import dev.felnull.pointed.core.util.Util;
8+
import dev.felnull.pointed.teams.manager.reward.RewardAdminService;
69
import org.bukkit.Bukkit;
710
import org.bukkit.OfflinePlayer;
811
import org.bukkit.command.Command;
@@ -231,10 +234,17 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
231234
shown++;
232235
}
233236
}
234-
235237
default -> sender.sendMessage(Util.f("&e/pt rank <daily|weekly|global> <PLAYER|TEAM|SYSTEM> <スコープ> [...]"));
236238
}
237239
}
240+
case "scope" -> {
241+
PointServiceImpl pointService = Pointed.getInstance().getPointService();
242+
sender.sendMessage("====Scope一覧====");
243+
for(String scope : pointService.listAllScopes()){
244+
sender.sendMessage("・ " + scope);
245+
}
246+
sender.sendMessage("=================");
247+
}
238248

239249
}
240250

@@ -244,7 +254,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
244254
@Override
245255
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
246256
if (args.length == 1) {
247-
return List.of("getnow", "gettotal", "get", "add", "sub", "set", "rank");
257+
return List.of("getnow", "gettotal", "get", "add", "sub", "set", "rank", "scope");
248258
}
249259
// サブコマンド毎の type 補完
250260
if (args.length == 2 && List.of("getnow","gettotal","get","add","sub","set").contains(args[0].toLowerCase())) {

src/main/java/dev/felnull/pointed/core/database/api/PointService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import dev.felnull.pointed.core.database.data.RankRow;
44

5+
import java.util.List;
6+
57
public interface PointService {
68

79
//subjectType = "PLAYER"とか"TEAM"とか
@@ -29,4 +31,7 @@ public interface PointService {
2931

3032
//すべての scope で subject を完全削除(accounts/履歴を消し、subjects も削除
3133
boolean deleteSubjectEverywhere(String subjectType, String subjectKey);
34+
35+
List<String> listScopes(String subjectType, String subjectKey);
36+
List<String> listAllScopes();
3237
}

src/main/java/dev/felnull/pointed/core/database/api/PointServiceImpl.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,4 +443,42 @@ public boolean deleteSubjectEverywhere(String subjectType, String subjectKey) {
443443
throw new RuntimeException(e);
444444
}
445445
}
446+
447+
@Override
448+
public List<String> listScopes(String subjectType, String subjectKey) {
449+
List<String> scopes = new ArrayList<>();
450+
try (Connection con = ds.getConnection();
451+
PreparedStatement ps = con.prepareStatement(
452+
"SELECT a.scope FROM " + Names.t("accounts") + " a " +
453+
"JOIN " + Names.t("subjects") + " s ON s.id=a.subject_id " +
454+
"WHERE s.type=? AND s.subject_key=?")) {
455+
ps.setString(1, subjectType);
456+
ps.setString(2, subjectKey);
457+
try (ResultSet rs = ps.executeQuery()) {
458+
while (rs.next()) {
459+
scopes.add(rs.getString(1));
460+
}
461+
}
462+
} catch (SQLException e) {
463+
throw new RuntimeException(e);
464+
}
465+
return scopes;
466+
}
467+
468+
@Override
469+
public List<String> listAllScopes() {
470+
List<String> scopes = new ArrayList<>();
471+
try (Connection con = ds.getConnection();
472+
PreparedStatement ps = con.prepareStatement(
473+
"SELECT DISTINCT scope FROM " + Names.t("accounts"))) {
474+
try (ResultSet rs = ps.executeQuery()) {
475+
while (rs.next()) {
476+
scopes.add(rs.getString(1));
477+
}
478+
}
479+
} catch (SQLException e) {
480+
throw new RuntimeException(e);
481+
}
482+
return scopes;
483+
}
446484
}

0 commit comments

Comments
 (0)