From bc72b101c725ac6ecbebd3db190cb2a11d95e39f Mon Sep 17 00:00:00 2001 From: Niels Vergucht Date: Wed, 26 Dec 2018 23:37:41 +0100 Subject: [PATCH] Added command completions for give command --- .../com/songoda/epicbuckets/EpicBuckets.java | 2 ++ .../epicbuckets/command/CommandGenbucket.java | 6 ++-- .../epicbuckets/command/CommandTabbing.java | 34 ++++++++++++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/songoda/epicbuckets/EpicBuckets.java b/src/main/java/com/songoda/epicbuckets/EpicBuckets.java index 857a46e..c7ce853 100644 --- a/src/main/java/com/songoda/epicbuckets/EpicBuckets.java +++ b/src/main/java/com/songoda/epicbuckets/EpicBuckets.java @@ -2,6 +2,7 @@ package com.songoda.epicbuckets; import co.aikar.commands.BukkitCommandManager; import com.songoda.epicbuckets.command.CommandGenbucket; +import com.songoda.epicbuckets.command.CommandTabbing; import com.songoda.epicbuckets.file.ConfigManager; import com.songoda.epicbuckets.genbucket.GenbucketManager; import com.songoda.epicbuckets.listener.GenbucketPlaceListener; @@ -61,6 +62,7 @@ public class EpicBuckets extends ExtendedJavaPlugin { inventoryManager = new InventoryManager(this); inventoryManager.init(); + CommandTabbing.registerCommandCompletions(); commandManager.registerCommand(new CommandGenbucket()); getServer().getPluginManager().registerEvents(new GenbucketPlaceListener(), this); diff --git a/src/main/java/com/songoda/epicbuckets/command/CommandGenbucket.java b/src/main/java/com/songoda/epicbuckets/command/CommandGenbucket.java index a4053b9..16e91a6 100644 --- a/src/main/java/com/songoda/epicbuckets/command/CommandGenbucket.java +++ b/src/main/java/com/songoda/epicbuckets/command/CommandGenbucket.java @@ -2,6 +2,7 @@ package com.songoda.epicbuckets.command; import co.aikar.commands.BaseCommand; import co.aikar.commands.annotation.*; +import co.aikar.commands.contexts.OnlinePlayer; import com.songoda.epicbuckets.EpicBuckets; import com.songoda.epicbuckets.gui.GUIMain; import com.songoda.epicbuckets.gui.GUIPanel; @@ -38,9 +39,10 @@ public class CommandGenbucket extends BaseCommand { } @Subcommand("give") + @CommandCompletion("@players @traits @genitems") @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) { + } @Subcommand("shop") diff --git a/src/main/java/com/songoda/epicbuckets/command/CommandTabbing.java b/src/main/java/com/songoda/epicbuckets/command/CommandTabbing.java index 9e9b321..353b80d 100644 --- a/src/main/java/com/songoda/epicbuckets/command/CommandTabbing.java +++ b/src/main/java/com/songoda/epicbuckets/command/CommandTabbing.java @@ -3,13 +3,45 @@ package com.songoda.epicbuckets.command; import co.aikar.commands.BukkitCommandCompletionContext; import co.aikar.commands.CommandCompletions; 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 static void registerCommandCompletions() { CommandCompletions commandCompletions = EpicBuckets.getInstance().getCommandManager().getCommandCompletions(); - commandCompletions.registerCompletion("") + commandCompletions.registerCompletion("traits", c -> { + if (c.getSender() instanceof Player) { + List 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 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; + }); } }