start of the guis

This commit is contained in:
alexcrea 2024-02-27 18:56:24 +01:00 committed by alexcrea
parent ae3971d14a
commit 6259eaa2cd
4 changed files with 161 additions and 0 deletions

View file

@ -0,0 +1,45 @@
package xyz.alexcrea.cuanvil.gui.gui;
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
import org.bukkit.event.inventory.InventoryClickEvent;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.function.Consumer;
public class GuiGlobalActions {
public static Consumer<InventoryClickEvent> stayInPlace = (event) -> event.setCancelled(true);
public static Consumer<InventoryClickEvent> openGuiFactory(
Class<? extends Gui> clazz,
Class<?>[] argClass,
Object... args){
return event -> {
event.setCancelled(true);
try {
Constructor<? extends Gui> constructor = clazz.getConstructor(argClass);
// Assume constructor is accessible
Gui gui = constructor.newInstance(args);
gui.show(event.getWhoClicked());
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException |
InstantiationException e) {
throw new RuntimeException(e);
}
};
}
public static Consumer<InventoryClickEvent> openGuiFactory(
Class<? extends Gui> clazz){
return openGuiFactory(clazz, new Class<?>[0]);
}
public static Consumer<InventoryClickEvent> openGuiFactory(Gui goal) {
return event -> {
event.setCancelled(true);
goal.show(event.getWhoClicked());
};
}
}

View file

@ -0,0 +1,34 @@
package xyz.alexcrea.cuanvil.gui.gui;
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
import com.github.stefvanschie.inventoryframework.pane.PatternPane;
import io.delilaheve.CustomAnvil;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class GuiGlobalItems {
// return
public static GuiItem toGuiItem(ItemStack item, Gui goal){
return new GuiItem(item, GuiGlobalActions.openGuiFactory(goal), CustomAnvil.instance);
}
// statically create back itemstack
private static final ItemStack BACK_ITEM = new ItemStack(Material.BARRIER);
static {
// todo add what I need to add to the back item
ItemMeta meta = BACK_ITEM.getItemMeta();
meta.setDisplayName("§cBack");
BACK_ITEM.setItemMeta(meta);
}
public static GuiItem backItem(Gui goal){
// simple go back item
return toGuiItem(BACK_ITEM, goal);
}
public static void addBackItem(PatternPane target, Gui goal){
target.bindItem('B', backItem(goal));
}
}

View file

@ -0,0 +1,53 @@
package xyz.alexcrea.cuanvil.gui.gui;
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
import com.github.stefvanschie.inventoryframework.pane.PatternPane;
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
import io.delilaheve.CustomAnvil;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import xyz.alexcrea.cuanvil.gui.gui.config.BasicConfigGui;
public class MainConfigGui extends ChestGui {
public final static MainConfigGui INSTANCE = new MainConfigGui();
private MainConfigGui() {
super(3, "§8Anvil Config", CustomAnvil.instance);
Pattern pattern = new Pattern(
"111111111",
"112345611",
"111111111"
);
PatternPane pane = new PatternPane(0, 0, 9, 3, pattern);
addPane(pane);
ItemStack backgroundBukkit = new ItemStack(Material.GRAY_STAINED_GLASS_PANE);
GuiItem background = new GuiItem(backgroundBukkit,GuiGlobalActions.stayInPlace, CustomAnvil.instance);
pane.bindItem('1', background);
ItemStack stonePlaceholder = new ItemStack(Material.STONE);
GuiItem placeholder1 = GuiGlobalItems.toGuiItem(stonePlaceholder, BasicConfigGui.INSTANCE);
GuiItem placeholder2 = new GuiItem(stonePlaceholder,CustomAnvil.instance);
GuiItem placeholder3 = new GuiItem(stonePlaceholder,CustomAnvil.instance);
GuiItem placeholder4 = new GuiItem(stonePlaceholder,CustomAnvil.instance);
GuiItem placeholder5 = new GuiItem(stonePlaceholder,CustomAnvil.instance);
pane.bindItem('2', placeholder1);
pane.bindItem('3', placeholder2);
pane.bindItem('4', placeholder3);
pane.bindItem('5', placeholder4);
pane.bindItem('6', placeholder5);
}
}

View file

@ -0,0 +1,29 @@
package xyz.alexcrea.cuanvil.gui.gui.config;
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
import com.github.stefvanschie.inventoryframework.pane.PatternPane;
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
import io.delilaheve.CustomAnvil;
import xyz.alexcrea.cuanvil.gui.gui.GuiGlobalItems;
import xyz.alexcrea.cuanvil.gui.gui.MainConfigGui;
public class BasicConfigGui extends ChestGui {
public final static BasicConfigGui INSTANCE = new BasicConfigGui();
private BasicConfigGui(){
super(3, "Basic Config GUI", CustomAnvil.instance);
Pattern pattern = new Pattern(
"111111111",
"111111111",
"B11111111"
);
PatternPane pane = new PatternPane(0, 0, 9, 3, pattern);
addPane(pane);
GuiGlobalItems.addBackItem(pane, MainConfigGui.INSTANCE);
}
}