Skip to content

Commit

Permalink
Add /realname command (#19)
Browse files Browse the repository at this point in the history
* Add /realname command

* Better message for /realname
  • Loading branch information
PainOchoco authored Apr 2, 2024
1 parent d769ce3 commit 47d39f6
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.laboulangerie.laboulangeriecore.betonquest.RankCondition;
import net.laboulangerie.laboulangeriecore.commands.CoreCommand;
import net.laboulangerie.laboulangeriecore.commands.LinkCommands;
import net.laboulangerie.laboulangeriecore.commands.RealNameCommand;
import net.laboulangerie.laboulangeriecore.commands.SeenCmd;
import net.laboulangerie.laboulangeriecore.commands.SpawnCmd;
import net.laboulangerie.laboulangeriecore.commands.SpeedCommand;
Expand Down Expand Up @@ -143,6 +144,7 @@ public void onEnable() {
getCommand("seen").setExecutor(new SeenCmd());
getCommand("event").setExecutor(new EventCmd());
getCommand("speed").setExecutor(new SpeedCommand());
getCommand("realname").setExecutor(new RealNameCommand());
// Link or simple message commands
getCommand("wiki").setExecutor(new LinkCommands());
getCommand("youtube").setExecutor(new LinkCommands());
Expand Down
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;
}

}
3 changes: 3 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ commands:
speed:
description: Toggle speed paths
usage: /speed
realname:
description: Get the real name of a player
usage: /realname <nickname>
permissions:
laboulangeriecore.*:
default: op
Expand Down

0 comments on commit 47d39f6

Please sign in to comment.