Skip to content

Instantly share code, notes, and snippets.

@gepron1x
Created December 18, 2020 20:59
Show Gist options
  • Save gepron1x/cc85a386237d5092ef882760603923be to your computer and use it in GitHub Desktop.
Save gepron1x/cc85a386237d5092ef882760603923be to your computer and use it in GitHub Desktop.
package me.gepron1x.advancedcustomitems.crafting;
import me.gepron1x.advancedcustomitems.items.CustomMaterial;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class CraftingBenchGUI implements InventoryHolder {
private static final byte matrixSize = 0;
private static byte[][] matrixCoords = new byte[][] {{10, 11, 12}, {19, 20, 21}, {28, 29, 30}};
private Inventory handle;
public CraftingBenchGUI() {
handle = Bukkit.createInventory(this,6 * 9,"Верстак");
}
@Override
public Inventory getInventory() {
return handle;
}
public void open(Player p) {
p.openInventory(handle);
}
private static ItemStack filler() {
ItemStack item = new ItemStack(Material.BLACK_STAINED_GLASS_PANE);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("");
item.setItemMeta(meta);
return item;
}
public void onUse(InventoryClickEvent e) {
CustomMaterial[][] matrix = getMatrix();
for(Recipe recipe : Recipe.getRecipes()) {
if(recipe.getMatrix().equals(matrix)) {
((Player) e.getWhoClicked()).getInventory().addItem(new ItemStack(Material.IRON_SWORD));
}
}
}
private CustomMaterial[][] getMatrix() {
CustomMaterial[][] rs = new CustomMaterial[3][3];
for(int i = 0; i < matrixCoords.length; i++) {
for(int j = 0; j < matrixCoords[i].length; j++) {
rs[i][j] = CustomMaterial.of(handle.getItem((int) matrixCoords[i][j]));
}
}
return rs;
}
}
package me.gepron1x.advancedcustomitems.crafting;
import me.gepron1x.advancedcustomitems.AdvancedCustomItems;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
public class CraftListener implements Listener {
public CraftListener(AdvancedCustomItems plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
if(e.getClickedInventory().getHolder() instanceof CraftingBenchGUI) {
CraftingBenchGUI craftingBench = (CraftingBenchGUI) e.getClickedInventory().getHolder();
craftingBench.onUse(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment