mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
add utils and fix package
This commit is contained in:
parent
7154748455
commit
69dde21529
6 changed files with 95 additions and 63 deletions
|
|
@ -1,7 +1,8 @@
|
||||||
package xyz.alexcrea.cuanvil.gui.gui;
|
package xyz.alexcrea.cuanvil.gui;
|
||||||
|
|
||||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
@ -12,10 +13,10 @@ public class GuiGlobalActions {
|
||||||
public static Consumer<InventoryClickEvent> stayInPlace = (event) -> event.setCancelled(true);
|
public static Consumer<InventoryClickEvent> stayInPlace = (event) -> event.setCancelled(true);
|
||||||
|
|
||||||
|
|
||||||
public static Consumer<InventoryClickEvent> openGuiFactory(
|
public static @NotNull Consumer<InventoryClickEvent> openGuiFactory(
|
||||||
Class<? extends Gui> clazz,
|
@NotNull Class<? extends Gui> clazz,
|
||||||
Class<?>[] argClass,
|
@NotNull Class<?>[] argClass,
|
||||||
Object... args){
|
@NotNull Object... args){
|
||||||
return event -> {
|
return event -> {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
try {
|
try {
|
||||||
|
|
@ -31,12 +32,12 @@ public class GuiGlobalActions {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Consumer<InventoryClickEvent> openGuiFactory(
|
public static @NotNull Consumer<InventoryClickEvent> openGuiFactory(
|
||||||
Class<? extends Gui> clazz){
|
@NotNull Class<? extends Gui> clazz){
|
||||||
return openGuiFactory(clazz, new Class<?>[0]);
|
return openGuiFactory(clazz, new Class<?>[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Consumer<InventoryClickEvent> openGuiFactory(Gui goal) {
|
public static @NotNull Consumer<InventoryClickEvent> openGuiFactory(@NotNull Gui goal) {
|
||||||
return event -> {
|
return event -> {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
goal.show(event.getWhoClicked());
|
goal.show(event.getWhoClicked());
|
||||||
56
src/main/java/xyz/alexcrea/cuanvil/gui/GuiGlobalItems.java
Normal file
56
src/main/java/xyz/alexcrea/cuanvil/gui/GuiGlobalItems.java
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
package xyz.alexcrea.cuanvil.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;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
// maybe use builder patern ?
|
||||||
|
public class GuiGlobalItems {
|
||||||
|
|
||||||
|
// return
|
||||||
|
public static GuiItem toGuiItem(@NotNull ItemStack item, @NotNull 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("\u00A7cBack");
|
||||||
|
BACK_ITEM.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
public static GuiItem backItem(@NotNull Gui goal){
|
||||||
|
// simple go back item
|
||||||
|
return toGuiItem(BACK_ITEM, goal);
|
||||||
|
}
|
||||||
|
public static void addBackItem(@NotNull PatternPane target,
|
||||||
|
@NotNull Gui goal){
|
||||||
|
target.bindItem('B', backItem(goal));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Material DEFAULT_BACKGROUND_MAT = Material.LIGHT_GRAY_STAINED_GLASS_PANE;
|
||||||
|
public static GuiItem backgroundItem(Material backgroundMat){
|
||||||
|
ItemStack item = new ItemStack(backgroundMat);
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
meta.setDisplayName("\u00A7c");
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
return new GuiItem(item, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
|
||||||
|
}
|
||||||
|
public static GuiItem backgroundItem(){
|
||||||
|
return backgroundItem(DEFAULT_BACKGROUND_MAT);
|
||||||
|
}
|
||||||
|
public static void addBackgroundItem(@NotNull PatternPane target,
|
||||||
|
@NotNull Material backgroundMat){
|
||||||
|
target.bindItem('0', backgroundItem(backgroundMat));
|
||||||
|
}
|
||||||
|
public static void addBackgroundItem(@NotNull PatternPane target){
|
||||||
|
addBackgroundItem(target, DEFAULT_BACKGROUND_MAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package xyz.alexcrea.cuanvil.gui.gui;
|
package xyz.alexcrea.cuanvil.gui;
|
||||||
|
|
||||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
|
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
|
||||||
|
|
@ -7,29 +7,30 @@ import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
||||||
import io.delilaheve.CustomAnvil;
|
import io.delilaheve.CustomAnvil;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import xyz.alexcrea.cuanvil.gui.gui.config.BasicConfigGui;
|
import xyz.alexcrea.cuanvil.gui.config.BasicConfigGui;
|
||||||
|
|
||||||
public class MainConfigGui extends ChestGui {
|
public class MainConfigGui extends ChestGui {
|
||||||
|
|
||||||
public final static MainConfigGui INSTANCE = new MainConfigGui();
|
public final static MainConfigGui INSTANCE = new MainConfigGui();
|
||||||
|
|
||||||
|
static {
|
||||||
|
INSTANCE.init();
|
||||||
|
}
|
||||||
private MainConfigGui() {
|
private MainConfigGui() {
|
||||||
super(3, "§8Anvil Config", CustomAnvil.instance);
|
super(3, "\u00A7cAnvil Config", CustomAnvil.instance);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init(){
|
||||||
Pattern pattern = new Pattern(
|
Pattern pattern = new Pattern(
|
||||||
"111111111",
|
"000000000",
|
||||||
"112345611",
|
"001234500",
|
||||||
"111111111"
|
"000000000"
|
||||||
);
|
);
|
||||||
PatternPane pane = new PatternPane(0, 0, 9, 3, pattern);
|
PatternPane pane = new PatternPane(0, 0, 9, 3, pattern);
|
||||||
addPane(pane);
|
addPane(pane);
|
||||||
|
|
||||||
ItemStack backgroundBukkit = new ItemStack(Material.GRAY_STAINED_GLASS_PANE);
|
GuiGlobalItems.addBackgroundItem(pane);
|
||||||
|
|
||||||
GuiItem background = new GuiItem(backgroundBukkit,GuiGlobalActions.stayInPlace, CustomAnvil.instance);
|
|
||||||
|
|
||||||
|
|
||||||
pane.bindItem('1', background);
|
|
||||||
|
|
||||||
|
|
||||||
ItemStack stonePlaceholder = new ItemStack(Material.STONE);
|
ItemStack stonePlaceholder = new ItemStack(Material.STONE);
|
||||||
|
|
@ -1,28 +1,36 @@
|
||||||
package xyz.alexcrea.cuanvil.gui.gui.config;
|
package xyz.alexcrea.cuanvil.gui.config;
|
||||||
|
|
||||||
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
|
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
|
||||||
import com.github.stefvanschie.inventoryframework.pane.PatternPane;
|
import com.github.stefvanschie.inventoryframework.pane.PatternPane;
|
||||||
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
||||||
import io.delilaheve.CustomAnvil;
|
import io.delilaheve.CustomAnvil;
|
||||||
import xyz.alexcrea.cuanvil.gui.gui.GuiGlobalItems;
|
import xyz.alexcrea.cuanvil.gui.MainConfigGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.gui.MainConfigGui;
|
import xyz.alexcrea.cuanvil.gui.GuiGlobalItems;
|
||||||
|
|
||||||
public class BasicConfigGui extends ChestGui {
|
public class BasicConfigGui extends ChestGui {
|
||||||
|
|
||||||
public final static BasicConfigGui INSTANCE = new BasicConfigGui();
|
public final static BasicConfigGui INSTANCE = new BasicConfigGui();
|
||||||
|
|
||||||
private BasicConfigGui(){
|
static {
|
||||||
super(3, "Basic Config GUI", CustomAnvil.instance);
|
INSTANCE.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private BasicConfigGui(){
|
||||||
|
super(3, "\u00A7cBasic Config GUI", CustomAnvil.instance);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init(){
|
||||||
Pattern pattern = new Pattern(
|
Pattern pattern = new Pattern(
|
||||||
"111111111",
|
"000000000",
|
||||||
"111111111",
|
"000000000",
|
||||||
"B11111111"
|
"B00000000"
|
||||||
);
|
);
|
||||||
PatternPane pane = new PatternPane(0, 0, 9, 3, pattern);
|
PatternPane pane = new PatternPane(0, 0, 9, 3, pattern);
|
||||||
addPane(pane);
|
addPane(pane);
|
||||||
|
|
||||||
GuiGlobalItems.addBackItem(pane, MainConfigGui.INSTANCE);
|
GuiGlobalItems.addBackItem(pane, MainConfigGui.INSTANCE);
|
||||||
|
GuiGlobalItems.addBackgroundItem(pane);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -4,7 +4,7 @@ import org.bukkit.command.Command
|
||||||
import org.bukkit.command.CommandExecutor
|
import org.bukkit.command.CommandExecutor
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
import org.bukkit.entity.HumanEntity
|
import org.bukkit.entity.HumanEntity
|
||||||
import xyz.alexcrea.cuanvil.gui.gui.MainConfigGui
|
import xyz.alexcrea.cuanvil.gui.MainConfigGui
|
||||||
|
|
||||||
class TestExecutor : CommandExecutor {
|
class TestExecutor : CommandExecutor {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue