Skip to content

Commit

Permalink
⚡ Added tab completer and finished the ItemCreator command
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsTheSky committed Feb 5, 2022
1 parent 77247ae commit 633ff02
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/main/java/info/itsthesky/itemcreator/ItemCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void onEnable() {
getServer().getPluginManager().registerEvents(new MainListener(this), this);

getCommand("itemcreator").setExecutor(new CreatorCommand());
getCommand("itemcreator").setTabCompleter(new CreatorCommand());

getLogger().info("ItemCreator as been loaded!");
}
Expand Down
49 changes: 45 additions & 4 deletions src/main/java/info/itsthesky/itemcreator/core/CreatorCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
import org.bukkit.command.TabCompleter;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;

public class CreatorCommand implements CommandExecutor, TabCompleter {

Expand Down Expand Up @@ -65,24 +69,61 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
sender.sendMessage(Utils.colored("&6List of enchantments &e("+ Enchantment.values().length +")&6:"));
for (Enchantment enchantment : Enchantment.values())
sender.sendMessage(Utils.colored(" &6→ &e" +
WordUtils.capitalize(enchantment.getKey().getKey().replace('_', ' ').toLowerCase(Locale.ENGLISH))
WordUtils.capitalize(enchantment.getKey().getKey().replace('_', ' ').toLowerCase(Locale.ENGLISH))
+ " &7(ID: "+enchantment.getName()+")"));
return true;
}
case "potion_effects" -> {
sender.sendMessage(Utils.colored("&6List of Potion Effects &e("+ PotionEffectType.values().length +")&6:"));
for (PotionEffectType enchantment : PotionEffectType.values())
sender.sendMessage(Utils.colored(" &6→ &e" +
WordUtils.capitalize(enchantment.getName().replace('_', ' ').toLowerCase(Locale.ENGLISH))
+ " &7(ID: "+enchantment.getId()+")"));
return true;
}
}
}
}

sendHelp(sender);
return true;
}

public void sendHelp(CommandSender sender) {

sender.sendMessage(Utils.colored("&6&lItemCreator &ev" + ItemCreator.getInstance().getDescription().getVersion()
+ "&e made by &6ItsTheSky#1234:"));
sender.sendMessage(
Utils.colored("&1"),
Utils.colored("&6/ic help &7- &eShow this help page"),
Utils.colored("&6/ic get <item id> &7- &eGet the specified custom item"),
Utils.colored("&6/ic menu &7- &eOpen the main ItemCreator menu"),
Utils.colored("&6/ic list (enchantments|potion_effects) &7- &eList possible values of enumeration"),
Utils.colored("&1")
);
}

@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
return null;
final List<String> completions = new ArrayList<>();
if (args.length == 1)
completions.addAll(Arrays.asList("help", "get", "menu", "list"));
else {
if (args.length == 2) {
switch (args[0]) {
case "get":
completions.addAll(ItemCreator
.getInstance()
.getApi()
.loadAllItems()
.stream()
.map(CustomItem::getId)
.toList());
break;
case "list":
completions.addAll(Arrays.asList("enchantments", "potion_effects"));
}
}
}
return completions;
}

}

0 comments on commit 633ff02

Please sign in to comment.