Added command completions for give command

This commit is contained in:
Niels Vergucht 2018-12-26 23:37:41 +01:00
parent 0c51507c3f
commit bc72b101c7
3 changed files with 39 additions and 3 deletions

View File

@ -2,6 +2,7 @@ package com.songoda.epicbuckets;
import co.aikar.commands.BukkitCommandManager; import co.aikar.commands.BukkitCommandManager;
import com.songoda.epicbuckets.command.CommandGenbucket; import com.songoda.epicbuckets.command.CommandGenbucket;
import com.songoda.epicbuckets.command.CommandTabbing;
import com.songoda.epicbuckets.file.ConfigManager; import com.songoda.epicbuckets.file.ConfigManager;
import com.songoda.epicbuckets.genbucket.GenbucketManager; import com.songoda.epicbuckets.genbucket.GenbucketManager;
import com.songoda.epicbuckets.listener.GenbucketPlaceListener; import com.songoda.epicbuckets.listener.GenbucketPlaceListener;
@ -61,6 +62,7 @@ public class EpicBuckets extends ExtendedJavaPlugin {
inventoryManager = new InventoryManager(this); inventoryManager = new InventoryManager(this);
inventoryManager.init(); inventoryManager.init();
CommandTabbing.registerCommandCompletions();
commandManager.registerCommand(new CommandGenbucket()); commandManager.registerCommand(new CommandGenbucket());
getServer().getPluginManager().registerEvents(new GenbucketPlaceListener(), this); getServer().getPluginManager().registerEvents(new GenbucketPlaceListener(), this);

View File

@ -2,6 +2,7 @@ package com.songoda.epicbuckets.command;
import co.aikar.commands.BaseCommand; import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*; import co.aikar.commands.annotation.*;
import co.aikar.commands.contexts.OnlinePlayer;
import com.songoda.epicbuckets.EpicBuckets; import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.gui.GUIMain; import com.songoda.epicbuckets.gui.GUIMain;
import com.songoda.epicbuckets.gui.GUIPanel; import com.songoda.epicbuckets.gui.GUIPanel;
@ -38,8 +39,9 @@ public class CommandGenbucket extends BaseCommand {
} }
@Subcommand("give") @Subcommand("give")
@CommandCompletion("@players @traits @genitems")
@Description("Gives a genbucket to a player") @Description("Gives a genbucket to a player")
public void give(CommandSender sender, ) { public void give(CommandSender sender, OnlinePlayer onlinePlayer, String trait, String genitem, @Optional int cost) {
} }

View File

@ -3,13 +3,45 @@ package com.songoda.epicbuckets.command;
import co.aikar.commands.BukkitCommandCompletionContext; import co.aikar.commands.BukkitCommandCompletionContext;
import co.aikar.commands.CommandCompletions; import co.aikar.commands.CommandCompletions;
import com.songoda.epicbuckets.EpicBuckets; import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.shop.Shop;
import com.songoda.epicbuckets.shop.SubShop;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class CommandTabbing { public class CommandTabbing {
public static void registerCommandCompletions() { public static void registerCommandCompletions() {
CommandCompletions<BukkitCommandCompletionContext> commandCompletions = EpicBuckets.getInstance().getCommandManager().getCommandCompletions(); CommandCompletions<BukkitCommandCompletionContext> commandCompletions = EpicBuckets.getInstance().getCommandManager().getCommandCompletions();
commandCompletions.registerCompletion("") commandCompletions.registerCompletion("traits", c -> {
if (c.getSender() instanceof Player) {
List<String> traits = new ArrayList<>();
for (Shop shop : EpicBuckets.getInstance().getShopManager().getShops()) {
if (!traits.contains(shop.getTrait().name())) {
traits.add(shop.getTrait().name());
}
}
return traits;
}
return null;
});
commandCompletions.registerCompletion("genitems", c -> {
if (c.getSender() instanceof Player) {
List<String> genitems = new ArrayList<>();
for (Shop shop : EpicBuckets.getInstance().getShopManager().getShops()) {
for (SubShop subShop : shop.getSubShops()) {
if (!genitems.contains(subShop.getGenItem().getType().name())) {
genitems.add(subShop.getGenItem().getType().name());
}
}
}
return genitems;
}
return null;
});
} }
} }