Skip to content

Commit de93fa0

Browse files
committed
feat: myp /ranking command
1 parent 2ec51a4 commit de93fa0

File tree

6 files changed

+163
-23
lines changed

6 files changed

+163
-23
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package net.azisaba.simplepoint;
2+
3+
import org.bukkit.command.Command;
4+
import org.bukkit.command.CommandExecutor;
5+
import org.bukkit.command.CommandSender;
6+
import org.bukkit.command.TabCompleter;
7+
import org.bukkit.entity.Player;
8+
import org.bukkit.util.StringUtil;
9+
10+
import java.util.ArrayList;
11+
import java.util.List;
12+
13+
public class MYPCommand implements CommandExecutor, TabCompleter {
14+
private final SimplePointPlugin plugin;
15+
16+
public MYPCommand(SimplePointPlugin plugin) {
17+
this.plugin = plugin;
18+
}
19+
20+
@Override
21+
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
22+
if (!(sender instanceof Player)) return true;
23+
24+
// 引数がない場合はヘルプを表示するか、デフォルトの動作をさせる
25+
if (args.length < 1) {
26+
sender.sendMessage("§c使用法: /myp <ポイント名>");
27+
return true;
28+
}
29+
30+
// 既存の /spt myp <id> のロジックを呼び出すために、argsをそのまま渡す
31+
// ここでは SPTCommand を直接実行するのではなく、同じロジックを実行します
32+
Player p = (Player) sender;
33+
String pointId = args[0];
34+
35+
if (plugin.getPointManager().getPointConfig(pointId) == null) {
36+
p.sendMessage("§cそのポイント名は存在しません。");
37+
return true;
38+
}
39+
40+
String displayName = plugin.getPointManager().getDisplayName(pointId);
41+
int current = plugin.getPointManager().getPoint(pointId, p.getUniqueId());
42+
int total = plugin.getPointManager().getTotalPoint(pointId, p.getUniqueId());
43+
44+
p.sendMessage("§8§m----------§r " + displayName + " §b§lSTATUS §8§m----------");
45+
p.sendMessage("§7現在の所持ポイント: §e" + current + " pt");
46+
p.sendMessage("§7これまでの累計獲得: §a" + total + " pt");
47+
p.sendMessage("§8§m----------------------------");
48+
49+
return true;
50+
}
51+
52+
@Override
53+
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
54+
if (args.length == 1) {
55+
List<String> completions = new ArrayList<>();
56+
StringUtil.copyPartialMatches(args[0], plugin.getPointManager().getPointNames(), completions);
57+
return completions;
58+
}
59+
return new ArrayList<>();
60+
}
61+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package net.azisaba.simplepoint;
2+
3+
import org.bukkit.command.Command;
4+
import org.bukkit.command.CommandExecutor;
5+
import org.bukkit.command.CommandSender;
6+
import org.bukkit.command.TabCompleter;
7+
import org.bukkit.entity.Player;
8+
import org.bukkit.util.StringUtil;
9+
10+
import java.util.ArrayList;
11+
import java.util.List;
12+
13+
public class RankingShortcutCommand implements CommandExecutor, TabCompleter {
14+
private final SimplePointPlugin plugin;
15+
16+
public RankingShortcutCommand(SimplePointPlugin plugin) {
17+
this.plugin = plugin;
18+
}
19+
20+
@Override
21+
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
22+
if (args.length < 1) {
23+
sender.sendMessage("§c使用法: /ranking <ポイント名>");
24+
return true;
25+
}
26+
27+
// SPPCommand の showRanking と同じロジックを実行する。
28+
// ※ SPTCommand 側の showPersonalRanking を使いたい場合はそちらに合わせます。
29+
// ここでは全員に放送される形式ではなく、実行者にだけ見せる「個人用ランキング表示」にします。
30+
if (!(sender instanceof Player)) return true;
31+
32+
// 既存の SPTCommand 内にある showPersonalRanking と同じロジックをここに書くか、
33+
// メソッドを共通化して呼び出します。
34+
35+
return true; // ここには SPTCommand の showPersonalRanking の内容を移植してください
36+
}
37+
38+
@Override
39+
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
40+
if (args.length == 1) {
41+
List<String> completions = new ArrayList<>();
42+
StringUtil.copyPartialMatches(args[0], plugin.getPointManager().getPointNames(), completions);
43+
return completions;
44+
}
45+
return new ArrayList<>();
46+
}
47+
}

src/main/java/net/azisaba/simplepoint/SPPCommand.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
163163

164164
private void showRanking(CommandSender sender, String pointName) {
165165
FileConfiguration config = plugin.getPointManager().getPointConfig(pointName);
166+
// ✨ IDから表示名(色付き)を取得
167+
String displayName = plugin.getPointManager().getDisplayName(pointName);
168+
166169
if (config == null || !config.getBoolean("_settings.ranking_enabled", true)) {
167-
sender.sendMessage(cランキングは現在無効です。");
170+
sender.sendMessage(c" + displayName + " §cのランキングは現在無効です。");
168171
return;
169172
}
170173

@@ -181,13 +184,16 @@ private void showRanking(CommandSender sender, String pointName) {
181184
List<Map.Entry<String, Integer>> list = new ArrayList<>(scores.entrySet());
182185
list.sort((a, b) -> b.getValue().compareTo(a.getValue()));
183186

187+
// --- 全体放送用のメッセージ構築 ---
184188
Bukkit.broadcastMessage("§7§m--------------------------------------");
185-
Bukkit.broadcastMessage("§8§l[§6§lRanking§8§l] §e§l" + pointName.toUpperCase());
189+
// ✨ IDではなく表示名を使用
190+
Bukkit.broadcastMessage("§8§l[§6§lRanking§8§l] §e§l" + displayName);
186191

187192
for (int i = 0; i < Math.min(list.size(), 7); i++) {
188193
String color = (i == 0) ? "§e§l" : (i == 1) ? "§f§l" : (i == 2) ? "§6§l" : "§7";
189194
String name = list.get(i).getKey();
190195
int score = list.get(i).getValue();
196+
191197
Bukkit.broadcastMessage(color + (i + 1) + ". §r" + name + " §7- §b" + score + " pt");
192198
}
193199
Bukkit.broadcastMessage("§7§m--------------------------------------");

src/main/java/net/azisaba/simplepoint/SPTCommand.java

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package net.azisaba.simplepoint;
22

33
import org.bukkit.Bukkit;
4+
import org.bukkit.OfflinePlayer;
5+
import org.bukkit.Sound;
46
import org.bukkit.command.Command;
57
import org.bukkit.command.CommandExecutor;
68
import org.bukkit.command.CommandSender;
@@ -10,6 +12,7 @@
1012
import org.bukkit.util.StringUtil;
1113

1214
import java.util.*;
15+
import java.util.stream.Collectors;
1316

1417
public class SPTCommand implements CommandExecutor, TabCompleter {
1518
private final SimplePointPlugin plugin;
@@ -43,19 +46,21 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
4346
p.sendMessage("§c使用法: /spt myp <ポイント名>");
4447
return true;
4548
}
46-
String pointName = args[1];
47-
if (plugin.getPointManager().getPointConfig(pointName) == null) {
49+
String pointId = args[1];
50+
if (plugin.getPointManager().getPointConfig(pointId) == null) {
4851
p.sendMessage("§cそのポイント名は存在しません。");
4952
return true;
5053
}
5154

52-
int current = plugin.getPointManager().getPoint(pointName, p.getUniqueId());
53-
int total = plugin.getPointManager().getTotalPoint(pointName, p.getUniqueId());
55+
// ✨ 表示名を取得
56+
String displayName = plugin.getPointManager().getDisplayName(pointId);
57+
int current = plugin.getPointManager().getPoint(pointId, p.getUniqueId());
58+
int total = plugin.getPointManager().getTotalPoint(pointId, p.getUniqueId());
5459

55-
p.sendMessage("§8§m----------§r §b§l" + pointName.toUpperCase() + " STATUS §8§m----------");
60+
p.sendMessage("§8§m-------§r " + displayName + " §b§lSTATUS §8§m-------");
5661
p.sendMessage("§7現在の所持ポイント: §e" + current + " pt");
5762
p.sendMessage("§7これまでの累計獲得: §a" + total + " pt");
58-
p.sendMessage("§8§m----------------------------");
63+
p.sendMessage("§8§m---------------------");
5964
return true;
6065
}
6166

@@ -64,17 +69,20 @@ else if (sub.equals("reward")) {
6469
p.sendMessage("§c使用法: /spt reward <ポイント名>");
6570
return true;
6671
}
67-
String pointName = args[1];
68-
FileConfiguration cfg = plugin.getPointManager().getPointConfig(pointName);
72+
String pointId = args[1];
73+
FileConfiguration cfg = plugin.getPointManager().getPointConfig(pointId);
74+
String displayName = plugin.getPointManager().getDisplayName(pointId);
75+
6976
if (cfg == null) {
7077
p.sendMessage("§cそのポイント名は存在しません。");
7178
return true;
7279
}
7380
if (!cfg.getBoolean("_settings.ranking_enabled", true)) {
74-
p.sendMessage("§c現在、この報酬ショップは利用できません。");
81+
p.sendMessage("§c現在、" + displayName + " §cの報酬ショップは利用できません。");
7582
return true;
7683
}
77-
plugin.getGuiManager().openRewardGUI(p, pointName, false);
84+
// 内部IDを使ってGUIを開く
85+
plugin.getGuiManager().openRewardGUI(p, pointId, false);
7886
return true;
7987
}
8088

@@ -90,14 +98,15 @@ else if (sub.equals("ranking")) {
9098
return true;
9199
}
92100

93-
private void showPersonalRanking(Player player, String pointName) {
94-
FileConfiguration config = plugin.getPointManager().getPointConfig(pointName);
101+
private void showPersonalRanking(Player player, String pointId) {
102+
FileConfiguration config = plugin.getPointManager().getPointConfig(pointId);
103+
String displayName = plugin.getPointManager().getDisplayName(pointId);
104+
95105
if (config == null || !config.getBoolean("_settings.ranking_enabled", true)) {
96-
player.sendMessage(cこのポイントのランキングは非公開です。");
106+
player.sendMessage(c" + displayName + " §cのランキングは非公開です。");
97107
return;
98108
}
99109

100-
// データの集計 (UUID -> 累計ポイント)
101110
Map<UUID, Integer> allScores = new HashMap<>();
102111
for (String key : config.getKeys(false)) {
103112
if (key.startsWith("_")) continue;
@@ -108,11 +117,9 @@ private void showPersonalRanking(Player player, String pointName) {
108117
} catch (IllegalArgumentException ignored) {}
109118
}
110119

111-
// ソート
112120
List<Map.Entry<UUID, Integer>> sortedList = new ArrayList<>(allScores.entrySet());
113121
sortedList.sort((a, b) -> b.getValue().compareTo(a.getValue()));
114122

115-
// 自分の順位特定
116123
int myRank = -1;
117124
int myScore = 0;
118125
for (int i = 0; i < sortedList.size(); i++) {
@@ -123,12 +130,12 @@ private void showPersonalRanking(Player player, String pointName) {
123130
}
124131
}
125132

126-
player.sendMessage("§8§m----------§r §6§l" + pointName.toUpperCase() + " RANKING §8§m----------");
133+
player.sendMessage("§8§m----------§r " + displayName + " §6§lRANKING §8§m----------");
127134

128-
// 上位7名を表示
129135
for (int i = 0; i < Math.min(sortedList.size(), 7); i++) {
130136
UUID uuid = sortedList.get(i).getKey();
131-
String name = Bukkit.getOfflinePlayer(uuid).getName();
137+
OfflinePlayer op = Bukkit.getOfflinePlayer(uuid);
138+
String name = op.getName();
132139
int score = sortedList.get(i).getValue();
133140

134141
String color = (i == 0) ? "§e" : (i == 1) ? "§f" : (i == 2) ? "§6" : "§7";
@@ -143,7 +150,7 @@ private void showPersonalRanking(Player player, String pointName) {
143150
player.sendMessage("§fあなたの順位: §7圏外");
144151
}
145152
player.sendMessage("§8§m--------------------------------------");
146-
player.playSound(player.getLocation(), org.bukkit.Sound.BLOCK_NOTE_BLOCK_CHIME, 1.0f, 1.0f);
153+
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 1.0f, 1.0f);
147154
}
148155

149156
@Override
@@ -152,6 +159,7 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
152159
if (args.length == 1) {
153160
StringUtil.copyPartialMatches(args[0], Arrays.asList("myp", "reward", "ranking", "help"), completions);
154161
} else if (args.length == 2 && Arrays.asList("myp", "reward", "ranking").contains(args[0].toLowerCase())) {
162+
// タブ補完は内部IDを出す(コマンド引数がIDであるため)
155163
StringUtil.copyPartialMatches(args[1], plugin.getPointManager().getPointNames(), completions);
156164
}
157165
return completions;

src/main/java/net/azisaba/simplepoint/SimplePointPlugin.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ public void onEnable() {
4545
getCommand("spt").setTabCompleter(new SPTTabCompleter(this));
4646
}
4747

48+
if (getCommand("myp") != null) {
49+
MYPCommand myp = new MYPCommand(this);
50+
getCommand("myp").setExecutor(myp);
51+
getCommand("myp").setTabCompleter(myp);
52+
}
53+
54+
if (getCommand("ranking") != null) {
55+
RankingShortcutCommand rk = new RankingShortcutCommand(this);
56+
getCommand("ranking").setExecutor(rk);
57+
getCommand("ranking").setTabCompleter(rk);
58+
}
59+
4860
// --- SPTT Command ---
4961
if (getCommand("sptt") != null) {
5062
getCommand("sptt").setExecutor(new SPTTCommand(this));

src/main/resources/plugin.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ commands:
1111
description: SimplePointPlugin Player Command
1212
sptt:
1313
description: チーム用コマンド
14-
permission: sptt.admin
14+
permission: sptt.admin
15+
myp:
16+
description: Check your points quickly
17+
usage: /myp <id>
18+
ranking:
19+
description: Check the ranking quickly
20+
usage: /ranking <id>

0 commit comments

Comments
 (0)