mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-27 02:49:08 +00:00
Added tab completions to dye command
This commit is contained in:
@@ -4,6 +4,7 @@ import com.comphenix.protocol.ProtocolLib;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import io.github.fisher2911.hmccosmetics.command.CosmeticsCommand;
|
||||
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
|
||||
import io.github.fisher2911.hmccosmetics.gui.CosmeticsMenu;
|
||||
import io.github.fisher2911.hmccosmetics.listener.ClickListener;
|
||||
import io.github.fisher2911.hmccosmetics.listener.JoinListener;
|
||||
@@ -14,7 +15,9 @@ import io.github.fisher2911.hmccosmetics.user.UserManager;
|
||||
import me.mattstudios.mf.base.CommandManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class HMCCosmetics extends JavaPlugin {
|
||||
|
||||
@@ -64,6 +67,13 @@ public class HMCCosmetics extends JavaPlugin {
|
||||
)
|
||||
|
||||
);
|
||||
this.commandManager.getCompletionHandler().register("#types",
|
||||
resolver ->
|
||||
Arrays.stream(ArmorItem.Type.
|
||||
values()).
|
||||
map(ArmorItem.Type::toString).
|
||||
collect(Collectors.toList())
|
||||
);
|
||||
this.commandManager.register(new CosmeticsCommand(this));
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.github.fisher2911.hmccosmetics.message.Messages;
|
||||
import io.github.fisher2911.hmccosmetics.user.User;
|
||||
import io.github.fisher2911.hmccosmetics.user.UserManager;
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Completion;
|
||||
import me.mattstudios.mf.annotations.Default;
|
||||
import me.mattstudios.mf.annotations.Permission;
|
||||
import me.mattstudios.mf.annotations.SubCommand;
|
||||
@@ -59,7 +60,7 @@ public class CosmeticsCommand extends CommandBase {
|
||||
|
||||
@SubCommand("dye")
|
||||
@Permission(io.github.fisher2911.hmccosmetics.message.Permission.DYE_COMMAND)
|
||||
public void dyeArmor(final Player player, String typeString) {
|
||||
public void dyeArmor(final Player player, @Completion("#types") String typeString) {
|
||||
|
||||
final Optional<User> optionalUser = this.userManager.get(player.getUniqueId());
|
||||
|
||||
@@ -67,16 +68,22 @@ public class CosmeticsCommand extends CommandBase {
|
||||
return;
|
||||
}
|
||||
|
||||
final ArmorItem.Type type = ArmorItem.Type.valueOf(typeString);
|
||||
try {
|
||||
final ArmorItem.Type type = ArmorItem.Type.valueOf(typeString.toUpperCase());
|
||||
|
||||
final User user = optionalUser.get();
|
||||
final User user = optionalUser.get();
|
||||
|
||||
final ArmorItem armorItem = switch (type) {
|
||||
case HAT -> user.getPlayerArmor().getHat();
|
||||
case BACKPACK -> user.getPlayerArmor().getBackpack();
|
||||
};
|
||||
final ArmorItem armorItem = switch (type) {
|
||||
case HAT -> user.getPlayerArmor().getHat();
|
||||
case BACKPACK -> user.getPlayerArmor().getBackpack();
|
||||
};
|
||||
|
||||
this.cosmeticsMenu.openDyeSelectorGui(user, armorItem);
|
||||
this.cosmeticsMenu.openDyeSelectorGui(user, armorItem);
|
||||
} catch (final IllegalArgumentException exception) {
|
||||
this.messageHandler.sendMessage(
|
||||
player,
|
||||
Messages.INVALID_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,4 +16,6 @@ public class Messages {
|
||||
new Message("must-be-player", "You must be a player to do this!");
|
||||
public static final Message RELOADED =
|
||||
new Message("reloaded", "Config reloaded");
|
||||
public static final Message INVALID_TYPE =
|
||||
new Message("invalid-type", "Invalid type");
|
||||
}
|
||||
|
||||
@@ -4,4 +4,5 @@ removed-hat: "<green>Removed Hat"
|
||||
set-backpack: "<green>Set Backpack!"
|
||||
removed-backpack: "<green>Removed Backpack"
|
||||
must-be-player: "You must be a player to do this!"
|
||||
reloaded: "<green>Config files reloaded"
|
||||
reloaded: "<green>Config files reloaded"
|
||||
invalid-type: "<red>Invalid cosmetic type, please use hat or backpack"
|
||||
Reference in New Issue
Block a user