impl tab completion on player color command
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
package cc.fascinated.account;
|
package cc.fascinated.account;
|
||||||
|
|
||||||
|
import cc.fascinated.command.Command;
|
||||||
import cc.fascinated.utils.Manager;
|
import cc.fascinated.utils.Manager;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
@ -12,6 +13,11 @@ public abstract class Profile extends Manager {
|
|||||||
*/
|
*/
|
||||||
private final Account account;
|
private final Account account;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The configuration section for this profile.
|
||||||
|
*/
|
||||||
|
private final ConfigurationSection section;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor is used for loading a profile from file.
|
* This constructor is used for loading a profile from file.
|
||||||
*
|
*
|
||||||
@ -20,6 +26,7 @@ public abstract class Profile extends Manager {
|
|||||||
*/
|
*/
|
||||||
public Profile(Account account, ConfigurationSection section) {
|
public Profile(Account account, ConfigurationSection section) {
|
||||||
this.account = account;
|
this.account = account;
|
||||||
|
this.section = section;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -5,11 +5,15 @@ import cc.fascinated.account.AccountManager;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public abstract class Command implements CommandExecutor {
|
public abstract class Command implements CommandExecutor, TabCompleter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The command name
|
* The command name
|
||||||
@ -30,6 +34,25 @@ public abstract class Command implements CommandExecutor {
|
|||||||
this.command = command;
|
this.command = command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the command.
|
||||||
|
*
|
||||||
|
* @param account The account executing the command.
|
||||||
|
* @param args The arguments of the command.
|
||||||
|
*/
|
||||||
|
public abstract void execute(Account account, String[] args);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tab completes the command.
|
||||||
|
*
|
||||||
|
* @param account The account executing the command.
|
||||||
|
* @param args The arguments of the command.
|
||||||
|
* @return The tab completions.
|
||||||
|
*/
|
||||||
|
public List<String> tabComplete(Account account, String[] args) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender commandSender, org.bukkit.command.@NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
public boolean onCommand(@NotNull CommandSender commandSender, org.bukkit.command.@NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
||||||
if (this.permission != null && !commandSender.hasPermission(permission)) {
|
if (this.permission != null && !commandSender.hasPermission(permission)) {
|
||||||
@ -43,11 +66,14 @@ public abstract class Command implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Executes the command.
|
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, org.bukkit.command.@NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
||||||
*
|
if (this.permission != null && !commandSender.hasPermission(permission)) {
|
||||||
* @param account The account executing the command.
|
return null;
|
||||||
* @param args The arguments of the command.
|
}
|
||||||
*/
|
|
||||||
public abstract void execute(Account account, String[] args);
|
Player player = (Player) commandSender;
|
||||||
|
Account account = AccountManager.getAccount(player.getUniqueId());
|
||||||
|
return this.tabComplete(account, strings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,5 +24,6 @@ public class CommandManager {
|
|||||||
throw new IllegalArgumentException("Command " + command.getCommand() + " does not exist.");
|
throw new IllegalArgumentException("Command " + command.getCommand() + " does not exist.");
|
||||||
}
|
}
|
||||||
pluginCommand.setExecutor(command);
|
pluginCommand.setExecutor(command);
|
||||||
|
pluginCommand.setTabCompleter(command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import cc.fascinated.playercolor.PlayerColorManager;
|
|||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PlayerColorCommand extends Command {
|
public class PlayerColorCommand extends Command {
|
||||||
@ -46,4 +47,16 @@ public class PlayerColorCommand extends Command {
|
|||||||
playerColorProfile.setColor(color);
|
playerColorProfile.setColor(color);
|
||||||
account.sendMessage(Component.text("§b§lPLAYERCOLOR §7» §fYour color has been set to: ").append(Component.text(playerColorProfile.getColor().toString()).color(playerColorProfile.getColor())));
|
account.sendMessage(Component.text("§b§lPLAYERCOLOR §7» §fYour color has been set to: ").append(Component.text(playerColorProfile.getColor().toString()).color(playerColorProfile.getColor())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> tabComplete(Account account, String[] args) {
|
||||||
|
List<NamedTextColor> colors = PlayerColorManager.getValidColors();
|
||||||
|
|
||||||
|
if (args.length == 1) {
|
||||||
|
List<String> list = new ArrayList<>(colors.stream().map(NamedTextColor::toString).toList());
|
||||||
|
list.add("random");
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user