-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add /realname command * Better message for /realname
- Loading branch information
1 parent
d769ce3
commit 47d39f6
Showing
3 changed files
with
69 additions
and
0 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
64 changes: 64 additions & 0 deletions
64
src/main/java/net/laboulangerie/laboulangeriecore/commands/RealNameCommand.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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package net.laboulangerie.laboulangeriecore.commands; | ||
|
||
import java.util.List; | ||
import java.util.ArrayList; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.command.TabCompleter; | ||
import org.bukkit.configuration.file.YamlConfiguration; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import net.laboulangerie.laboulangeriecore.core.UsersData; | ||
|
||
public class RealNameCommand implements CommandExecutor, TabCompleter { | ||
|
||
@Override | ||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String alias, | ||
@NotNull String[] args) { | ||
if (args.length != 1) { | ||
return false; | ||
} | ||
|
||
String nick = args[0]; | ||
|
||
for (Player player : Bukkit.getServer().getOnlinePlayers()) { | ||
YamlConfiguration userData = UsersData.getOrCreate(player); | ||
String playerNick = userData.getString("nick"); | ||
|
||
if (playerNick != null && playerNick.equals(nick)) { | ||
sender.sendMessage(nick + " est joué par " + player.getName()); | ||
return true; | ||
} | ||
} | ||
|
||
sender.sendMessage("Nick inconnu."); | ||
return true; | ||
} | ||
|
||
@Override | ||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, | ||
@NotNull String alias, @NotNull String[] args) { | ||
if (args.length != 1) { | ||
return null; | ||
} | ||
|
||
List<String> onlineNicks = new ArrayList<>(); | ||
|
||
for (Player player : Bukkit.getServer().getOnlinePlayers()) { | ||
YamlConfiguration userData = UsersData.getOrCreate(player); | ||
String nick = userData.getString("nick"); | ||
|
||
if (nick != null) { | ||
onlineNicks.add(nick); | ||
} | ||
} | ||
|
||
return onlineNicks; | ||
} | ||
|
||
} |
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