-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge pull request #7 from akshualy/fix/bukkit-tab-complete
Fix & Improve Bukkit Tab Completion
Showing
2 changed files
with
18 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 17 additions & 10 deletions
27
src/main/java/it/frafol/cleanping/bukkit/commands/utils/TabComplete.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,36 @@ | ||
package it.frafol.cleanping.bukkit.commands.utils; | ||
|
||
import it.frafol.cleanping.bukkit.CleanPing; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.command.TabCompleter; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.metadata.MetadataValue; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class TabComplete implements TabCompleter { | ||
|
||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) { | ||
if (args.length != 1) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
final List<String> list = new ArrayList<>(); | ||
|
||
if (command.getName().equalsIgnoreCase("ping") | ||
|| command.getName().equalsIgnoreCase("cleanping")) { | ||
return sender.getServer().getOnlinePlayers().stream() | ||
.filter(player -> | ||
!isVanished(player) && player.getName().toLowerCase().startsWith(args[0].toLowerCase())) | ||
.map(Player::getName) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
for (Player players : CleanPing.getInstance().getServer().getOnlinePlayers()) { | ||
list.add(players.getName()); | ||
private boolean isVanished(Player player) { | ||
for (MetadataValue meta : player.getMetadata("vanished")) { | ||
if (meta.asBoolean()) { | ||
return true; | ||
} | ||
|
||
} | ||
return list; | ||
return false; | ||
} | ||
} |