mirror of
https://github.com/CivMC/Civ.git
synced 2026-07-18 00:20:44 +00:00
add custom item support to /item
This commit is contained in:
@@ -4,9 +4,16 @@ import co.aikar.commands.BukkitCommandCompletionContext;
|
||||
import co.aikar.commands.CommandCompletions;
|
||||
import com.github.igotyou.FactoryMod.FactoryMod;
|
||||
import com.github.igotyou.FactoryMod.eggs.IFactoryEgg;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import vg.civcraft.mc.civmodcore.commands.CommandManager;
|
||||
import vg.civcraft.mc.civmodcore.inventory.CustomItem;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class FMCommandManager extends CommandManager {
|
||||
|
||||
@@ -29,5 +36,13 @@ public class FMCommandManager extends CommandManager {
|
||||
super.registerCompletions(completions);
|
||||
completions.registerCompletion("FM_Factories", (context) -> FactoryMod.getInstance().getManager().getAllFactoryEggs().stream().map(
|
||||
IFactoryEgg::getName).toList());
|
||||
completions.registerCompletion("materials_and_custom_items", (context) -> {
|
||||
Set<String> allCompletions = new TreeSet<>();
|
||||
for (Material m : Material.values()) {
|
||||
allCompletions.add(m.name().toLowerCase());
|
||||
}
|
||||
allCompletions.addAll(CustomItem.getKeys());
|
||||
return allCompletions;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,25 +11,27 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import vg.civcraft.mc.civmodcore.inventory.CustomItem;
|
||||
|
||||
public class ItemUseMenu extends BaseCommand {
|
||||
|
||||
@CommandAlias("item")
|
||||
@Syntax("[material]")
|
||||
@Description("Opens a GUI allowing you to browse all recipes which use or output the item in your main hand")
|
||||
@CommandCompletion("@materials")
|
||||
@CommandCompletion("@materials_and_custom_items")
|
||||
public void execute(Player p, @Optional String material) {
|
||||
if (material == null) {
|
||||
ItemUseGUI gui = new ItemUseGUI(p);
|
||||
gui.showItemOverview(p.getInventory().getItemInMainHand());
|
||||
} else {
|
||||
} else if (Material.matchMaterial(material) != null) {
|
||||
Material mat = Material.matchMaterial(material);
|
||||
if (mat == null) {
|
||||
p.sendMessage(ChatColor.RED + "The item " + material + " does not exist");
|
||||
return;
|
||||
}
|
||||
ItemUseGUI gui = new ItemUseGUI(p);
|
||||
gui.showItemOverview(new ItemStack(mat));
|
||||
} else if (CustomItem.getCustomItem(material.toLowerCase()) != null) {
|
||||
ItemUseGUI gui = new ItemUseGUI(p);
|
||||
gui.showItemOverview(CustomItem.getCustomItem(material.toLowerCase()));
|
||||
} else {
|
||||
p.sendMessage(ChatColor.RED + "The item " + material + " does not exist");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,11 +150,11 @@ public class ItemUseGUI {
|
||||
ItemUtils.setDisplayName(is, ChatColor.DARK_GREEN + fccEgg.getName());
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(ChatColor.DARK_AQUA + recipe.getName());
|
||||
lore.add(ChatColor.GOLD + "input:");
|
||||
lore.add(ChatColor.GOLD + "Input:");
|
||||
for (String input : recipe.getTextualInputRepresentation(null, null)) {
|
||||
lore.add(formatIngredient(input, item));
|
||||
}
|
||||
lore.add(ChatColor.GOLD + "output:");
|
||||
lore.add(ChatColor.GOLD + "Output:");
|
||||
for (String output : recipe.getTextualOutputRepresentation(null, null)) {
|
||||
lore.add(formatIngredient(output, item));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user