11package com .trassert .recallpotion .commands ;
22
33import com .trassert .recallpotion .RecallPotionPlugin ;
4+ import org .bukkit .Bukkit ;
45import org .bukkit .command .Command ;
56import org .bukkit .command .CommandExecutor ;
67import org .bukkit .command .CommandSender ;
8+ import org .bukkit .entity .Player ;
9+ import org .bukkit .inventory .ItemStack ;
10+ import org .bukkit .command .TabCompleter ;
11+ import java .util .ArrayList ;
12+ import java .util .Collections ;
13+ import java .util .List ;
14+ import java .util .stream .Collectors ;
715
8- public class RecallPotionCommand implements CommandExecutor {
16+ public class RecallPotionCommand implements CommandExecutor , TabCompleter {
917
1018 private final RecallPotionPlugin plugin ;
1119
@@ -24,10 +32,37 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
2432
2533 if (args .length == 0 ) {
2634 sender .sendMessage ("§6RecallPotion Plugin v" + version );
27- sender .sendMessage ("§7Использование: /" + label + " reload" );
35+ String usage = plugin .getConfigManager ().getMessage ("usage" ).replace ("{label}" , label );
36+ sender .sendMessage (usage );
2837 return true ;
2938 }
3039
40+ if (args [0 ].equalsIgnoreCase ("give" )) {
41+ if (args .length == 1 ) {
42+ if (!(sender instanceof Player )) {
43+ sender .sendMessage (plugin .getConfigManager ().getMessage ("player-only" ));
44+ return true ;
45+ }
46+ Player player = (Player ) sender ;
47+ ItemStack potion = plugin .getRecipeManager ().createRecallPotion ();
48+ player .getInventory ().addItem (potion );
49+ player .sendMessage (plugin .getConfigManager ().getMessage ("potion-obtained" ));
50+ player .sendMessage (plugin .getConfigManager ().getMessage ("give-self" ));
51+ return true ;
52+ } else {
53+ Player target = Bukkit .getPlayerExact (args [1 ]);
54+ if (target == null ) {
55+ sender .sendMessage (plugin .getConfigManager ().getMessage ("player-not-found" ).replace ("{player}" , args [1 ]));
56+ return true ;
57+ }
58+ ItemStack potion = plugin .getRecipeManager ().createRecallPotion ();
59+ target .getInventory ().addItem (potion );
60+ target .sendMessage (plugin .getConfigManager ().getMessage ("potion-obtained" ));
61+ sender .sendMessage (plugin .getConfigManager ().getMessage ("give-other" ).replace ("{player}" , target .getName ()));
62+ return true ;
63+ }
64+ }
65+
3166 if (args [0 ].equalsIgnoreCase ("reload" )) {
3267 plugin .getConfigManager ().reloadConfig ();
3368 sender .sendMessage (plugin .getConfigManager ().getMessage ("config-reloaded" ));
@@ -37,4 +72,25 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
3772 sender .sendMessage ("§cНеизвестная команда. Используйте: /" + label + " reload" );
3873 return true ;
3974 }
75+
76+ @ Override
77+ public List <String > onTabComplete (CommandSender sender , Command command , String alias , String [] args ) {
78+ if (args .length == 1 ) {
79+ List <String > subs = new ArrayList <>();
80+ subs .add ("give" );
81+ subs .add ("reload" );
82+ String pref = args [0 ].toLowerCase ();
83+ return subs .stream ().filter (s -> s .startsWith (pref )).collect (Collectors .toList ());
84+ }
85+
86+ if (args .length == 2 && args [0 ].equalsIgnoreCase ("give" )) {
87+ String pref = args [1 ].toLowerCase ();
88+ return Bukkit .getOnlinePlayers ().stream ()
89+ .map (Player ::getName )
90+ .filter (n -> n .toLowerCase ().startsWith (pref ))
91+ .collect (Collectors .toList ());
92+ }
93+
94+ return Collections .emptyList ();
95+ }
4096}
0 commit comments