11package net .azisaba .simplepoint ;
22
33import org .bukkit .Bukkit ;
4+ import org .bukkit .OfflinePlayer ;
5+ import org .bukkit .Sound ;
46import org .bukkit .command .Command ;
57import org .bukkit .command .CommandExecutor ;
68import org .bukkit .command .CommandSender ;
1012import org .bukkit .util .StringUtil ;
1113
1214import java .util .*;
15+ import java .util .stream .Collectors ;
1316
1417public 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 ;
0 commit comments