mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Add an abstract layer for global config gui list.
This commit is contained in:
parent
8c936658a1
commit
0004f2426f
6 changed files with 320 additions and 245 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
package xyz.alexcrea.cuanvil.gui.config;
|
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||||
|
|
||||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
import com.github.stefvanschie.inventoryframework.pane.Orientable;
|
import com.github.stefvanschie.inventoryframework.pane.Orientable;
|
||||||
|
|
@ -0,0 +1,292 @@
|
||||||
|
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||||
|
|
||||||
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
|
import com.github.stefvanschie.inventoryframework.pane.Orientable;
|
||||||
|
import com.github.stefvanschie.inventoryframework.pane.OutlinePane;
|
||||||
|
import com.github.stefvanschie.inventoryframework.pane.Pane;
|
||||||
|
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.entity.HumanEntity;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public abstract class ElementListGlobalConfigGui< T > extends ValueUpdatableGui {
|
||||||
|
|
||||||
|
|
||||||
|
public ElementListGlobalConfigGui(int rows, @NotNull String title) {
|
||||||
|
super(rows, title, CustomAnvil.instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected OutlinePane firstPage;
|
||||||
|
protected ArrayList<OutlinePane> pages;
|
||||||
|
protected HashMap<UUID, Integer> pageMap;
|
||||||
|
protected PatternPane backgroundPane;
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
// Back item panel
|
||||||
|
Pattern pattern = new Pattern(
|
||||||
|
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||||
|
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||||
|
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||||
|
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||||
|
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||||
|
"B11L1R11C"
|
||||||
|
);
|
||||||
|
this.backgroundPane = new PatternPane(0, 0, 9, 6, Pane.Priority.LOW, pattern);
|
||||||
|
|
||||||
|
GuiGlobalItems.addBackItem(this.backgroundPane, MainConfigGui.INSTANCE);
|
||||||
|
|
||||||
|
GuiGlobalItems.addBackgroundItem(this.backgroundPane);
|
||||||
|
this.backgroundPane.bindItem('1', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
|
||||||
|
addPane(this.backgroundPane);
|
||||||
|
|
||||||
|
// Page init
|
||||||
|
this.pages = new ArrayList<>();
|
||||||
|
this.pageMap = new HashMap<>();
|
||||||
|
|
||||||
|
// enchant item panel
|
||||||
|
this.firstPage = createEmptyPage();
|
||||||
|
this.pages.add(this.firstPage);
|
||||||
|
|
||||||
|
prepareStaticValues();
|
||||||
|
reloadValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected GuiItem goLeftItem;
|
||||||
|
protected GuiItem goRightItem;
|
||||||
|
|
||||||
|
protected void prepareStaticValues(){
|
||||||
|
// Left item creation for consumer & bind
|
||||||
|
this.goLeftItem = new GuiItem(new ItemStack(Material.RED_TERRACOTTA), event -> {
|
||||||
|
HumanEntity viewer = event.getWhoClicked();
|
||||||
|
UUID playerUUID = viewer.getUniqueId();
|
||||||
|
int page = this.pageMap.getOrDefault(playerUUID, 0);
|
||||||
|
this.pageMap.put(playerUUID, page - 1);
|
||||||
|
|
||||||
|
ItemStack cursor = viewer.getItemOnCursor();
|
||||||
|
viewer.setItemOnCursor(new ItemStack(Material.AIR));
|
||||||
|
|
||||||
|
show(viewer);
|
||||||
|
|
||||||
|
viewer.setItemOnCursor(cursor);
|
||||||
|
}, CustomAnvil.instance);
|
||||||
|
|
||||||
|
// Right item creation for consumer & bind
|
||||||
|
this.goRightItem = new GuiItem(new ItemStack(Material.GREEN_TERRACOTTA), event -> {
|
||||||
|
HumanEntity viewer = event.getWhoClicked();
|
||||||
|
UUID playerUUID = viewer.getUniqueId();
|
||||||
|
int page = pageMap.getOrDefault(playerUUID, 0);
|
||||||
|
this.pageMap.put(playerUUID, page + 1);
|
||||||
|
|
||||||
|
ItemStack cursor = viewer.getItemOnCursor();
|
||||||
|
viewer.setItemOnCursor(new ItemStack(Material.AIR));
|
||||||
|
|
||||||
|
show(viewer);
|
||||||
|
|
||||||
|
viewer.setItemOnCursor(cursor);
|
||||||
|
}, CustomAnvil.instance);
|
||||||
|
|
||||||
|
this.backgroundPane.bindItem('C', prepareCreateNewItem());
|
||||||
|
}
|
||||||
|
protected void reloadValues(){
|
||||||
|
this.firstPage.clear();
|
||||||
|
this.pages.clear();
|
||||||
|
this.pages.add(this.firstPage);
|
||||||
|
|
||||||
|
for (T conflict : getEveryDisplayableInstanceOfGeneric()) {
|
||||||
|
updateValueForGeneric(conflict, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract GuiItem prepareCreateNewItem();
|
||||||
|
|
||||||
|
protected OutlinePane createEmptyPage() {
|
||||||
|
OutlinePane page = new OutlinePane(0, 0, 9, 5);
|
||||||
|
page.align(OutlinePane.Alignment.BEGIN);
|
||||||
|
page.setOrientation(Orientable.Orientation.HORIZONTAL);
|
||||||
|
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPlayerPageID(UUID uuid) {
|
||||||
|
int pageId = this.pageMap.getOrDefault(uuid, 0);
|
||||||
|
if (pageId >= this.pages.size()) {
|
||||||
|
pageId = this.pages.size() - 1;
|
||||||
|
}
|
||||||
|
return pageId;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addToPage(GuiItem guiItem) {
|
||||||
|
// Get first available page or create one
|
||||||
|
OutlinePane page = this.pages.get(this.pages.size() - 1);
|
||||||
|
if (page.getItems().size() >= 5 * 9) {
|
||||||
|
page = createEmptyPage();
|
||||||
|
this.pages.add(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
page.addItem(guiItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeFromPage(GuiItem guiItem) {
|
||||||
|
// get item page
|
||||||
|
OutlinePane page = null;
|
||||||
|
int pageID = 0;
|
||||||
|
while (pageID < this.pages.size()) {
|
||||||
|
OutlinePane tempPage = this.pages.get(pageID);
|
||||||
|
if (tempPage.getItems().contains(guiItem)) {
|
||||||
|
page = tempPage;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pageID++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (page == null) {// Why...
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
removeFromPage(page, pageID, guiItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeFromPage(OutlinePane page, int pageID, GuiItem guiItem) {
|
||||||
|
page.removeItem(guiItem);
|
||||||
|
|
||||||
|
// There is now a slot available, let fill it if possible
|
||||||
|
if (pageID < (this.pages.size() - 1)) {
|
||||||
|
OutlinePane newPage = this.pages.get(pageID + 1);
|
||||||
|
GuiItem nextPageItem = newPage.getItems().get(0);
|
||||||
|
|
||||||
|
removeFromPage(newPage, pageID + 1, nextPageItem);
|
||||||
|
|
||||||
|
OutlinePane thisPage = this.pages.get(pageID);
|
||||||
|
thisPage.addItem(nextPageItem);
|
||||||
|
} else if (pageID > 0 && page.getItems().isEmpty()) {
|
||||||
|
this.pages.remove(pageID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void placeArrow(int page, boolean customise) {
|
||||||
|
|
||||||
|
// Place left arrow
|
||||||
|
addPane(this.backgroundPane);
|
||||||
|
if (page > 0) {
|
||||||
|
if (customise) {
|
||||||
|
ItemStack leftItem = this.goLeftItem.getItem();
|
||||||
|
ItemMeta leftMeta = leftItem.getItemMeta();
|
||||||
|
|
||||||
|
leftMeta.setDisplayName("\u00A7eReturn to page " + (page));
|
||||||
|
|
||||||
|
leftItem.setItemMeta(leftMeta);
|
||||||
|
this.goLeftItem.setItem(leftItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.backgroundPane.bindItem('L', this.goLeftItem);
|
||||||
|
} else {
|
||||||
|
this.backgroundPane.bindItem('L', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Place right arrow
|
||||||
|
if (page < pages.size() - 1) {
|
||||||
|
if (customise) {
|
||||||
|
ItemStack rightItem = this.goRightItem.getItem();
|
||||||
|
ItemMeta rightMeta = rightItem.getItemMeta();
|
||||||
|
|
||||||
|
rightMeta.setDisplayName("\u00A7eGo to page " + (page + 2));
|
||||||
|
|
||||||
|
rightItem.setItemMeta(rightMeta);
|
||||||
|
this.goRightItem.setItem(rightItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.backgroundPane.bindItem('R', this.goRightItem);
|
||||||
|
} else {
|
||||||
|
this.backgroundPane.bindItem('R', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override // assume will not be called in multiple thread
|
||||||
|
public void show(@NotNull HumanEntity humanEntity) {
|
||||||
|
int pageID = getPlayerPageID(humanEntity.getUniqueId());
|
||||||
|
OutlinePane page = this.pages.get(pageID);
|
||||||
|
|
||||||
|
getPanes().clear();
|
||||||
|
|
||||||
|
// display the page arrow pane
|
||||||
|
placeArrow(pageID, true);
|
||||||
|
// and add actual page
|
||||||
|
addPane(page);
|
||||||
|
|
||||||
|
// set title
|
||||||
|
setTitle("Conflict Config (" + (pageID + 1) + "/" + (pages.size()) + ")");
|
||||||
|
|
||||||
|
super.show(humanEntity);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override // assume will not be called in multiple thread
|
||||||
|
public void click(@NotNull InventoryClickEvent event) {
|
||||||
|
int pageID = getPlayerPageID(event.getWhoClicked().getUniqueId());
|
||||||
|
OutlinePane page = this.pages.get(pageID);
|
||||||
|
|
||||||
|
getPanes().clear();
|
||||||
|
|
||||||
|
// set the page arrow pane
|
||||||
|
placeArrow(pageID, false);
|
||||||
|
// and add actual page
|
||||||
|
addPane(page);
|
||||||
|
|
||||||
|
super.click(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------
|
||||||
|
// Methods using generic T
|
||||||
|
// -------------------------
|
||||||
|
|
||||||
|
public void updateValueForGeneric(T generic, boolean shouldUpdate) {
|
||||||
|
ItemStack item = createItemForGeneric(generic);
|
||||||
|
|
||||||
|
updateGeneric(generic, item);
|
||||||
|
|
||||||
|
if (shouldUpdate) {
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeConflict(T generic) {
|
||||||
|
GuiItem item = findGuiItemForRemoval(generic);
|
||||||
|
if(item == null) return;
|
||||||
|
removeFromPage(item);
|
||||||
|
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract GuiItem findGuiItemForRemoval(T generic);
|
||||||
|
|
||||||
|
protected abstract ItemStack createItemForGeneric(T generic);
|
||||||
|
|
||||||
|
protected abstract void updateGeneric(T generic, ItemStack usedItem);
|
||||||
|
|
||||||
|
protected abstract List<T> getEveryDisplayableInstanceOfGeneric();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateGuiValues() {
|
||||||
|
// Not the optimised way to update this gui
|
||||||
|
// TODO maybe rework ValueUpdatableGui and it's dependency to allow a 1 item reload every time.
|
||||||
|
|
||||||
|
reloadValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,34 +1,28 @@
|
||||||
package xyz.alexcrea.cuanvil.gui.config.global;
|
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||||
|
|
||||||
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.pane.Orientable;
|
|
||||||
import com.github.stefvanschie.inventoryframework.pane.OutlinePane;
|
|
||||||
import com.github.stefvanschie.inventoryframework.pane.Pane;
|
|
||||||
import com.github.stefvanschie.inventoryframework.pane.PatternPane;
|
|
||||||
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.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
|
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
|
||||||
import xyz.alexcrea.cuanvil.group.IncludeGroup;
|
import xyz.alexcrea.cuanvil.group.IncludeGroup;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.settings.subsetting.EnchantConflictSubSettingGui;
|
import xyz.alexcrea.cuanvil.gui.config.settings.subsetting.EnchantConflictSubSettingGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class EnchantConflictGui extends ChestGui {
|
public class EnchantConflictGui extends ElementListGlobalConfigGui<EnchantConflictGroup> {
|
||||||
|
|
||||||
public final static EnchantConflictGui INSTANCE = new EnchantConflictGui();
|
public final static EnchantConflictGui INSTANCE = new EnchantConflictGui();
|
||||||
|
|
||||||
|
|
@ -39,80 +33,12 @@ public class EnchantConflictGui extends ChestGui {
|
||||||
private final HashMap<EnchantConflictGroup, EnchantConflictSubSettingGui> conflictGuiMap;
|
private final HashMap<EnchantConflictGroup, EnchantConflictSubSettingGui> conflictGuiMap;
|
||||||
|
|
||||||
private EnchantConflictGui() {
|
private EnchantConflictGui() {
|
||||||
super(6, "Conflict Config", CustomAnvil.instance);
|
super(6, "Conflict Config");
|
||||||
this.conflictGuiMap = new HashMap<>();
|
this.conflictGuiMap = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private OutlinePane firstPage;
|
@Override
|
||||||
private ArrayList<OutlinePane> pages;
|
protected GuiItem prepareCreateNewItem(){
|
||||||
private HashMap<UUID, Integer> pageMap;
|
|
||||||
private PatternPane backgroundPane;
|
|
||||||
|
|
||||||
private void init() {
|
|
||||||
// Back item panel
|
|
||||||
Pattern pattern = new Pattern(
|
|
||||||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
|
||||||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
|
||||||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
|
||||||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
|
||||||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
|
||||||
"B11L1R11C"
|
|
||||||
);
|
|
||||||
this.backgroundPane = new PatternPane(0, 0, 9, 6, Pane.Priority.LOW, pattern);
|
|
||||||
|
|
||||||
GuiGlobalItems.addBackItem(this.backgroundPane, MainConfigGui.INSTANCE);
|
|
||||||
|
|
||||||
GuiGlobalItems.addBackgroundItem(this.backgroundPane);
|
|
||||||
this.backgroundPane.bindItem('1', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
|
|
||||||
addPane(this.backgroundPane);
|
|
||||||
|
|
||||||
// Page init
|
|
||||||
this.pages = new ArrayList<>();
|
|
||||||
this.pageMap = new HashMap<>();
|
|
||||||
|
|
||||||
// enchant item panel
|
|
||||||
this.firstPage = createEmptyPage();
|
|
||||||
this.pages.add(this.firstPage);
|
|
||||||
|
|
||||||
prepareOtherValues();
|
|
||||||
reloadValues();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private GuiItem goLeftItem;
|
|
||||||
private GuiItem goRightItem;
|
|
||||||
|
|
||||||
private void prepareOtherValues() {
|
|
||||||
// Left item creation for consumer & bind
|
|
||||||
this.goLeftItem = new GuiItem(new ItemStack(Material.RED_TERRACOTTA), event -> {
|
|
||||||
HumanEntity viewer = event.getWhoClicked();
|
|
||||||
UUID playerUUID = viewer.getUniqueId();
|
|
||||||
int page = this.pageMap.getOrDefault(playerUUID, 0);
|
|
||||||
this.pageMap.put(playerUUID, page - 1);
|
|
||||||
|
|
||||||
ItemStack cursor = viewer.getItemOnCursor();
|
|
||||||
viewer.setItemOnCursor(new ItemStack(Material.AIR));
|
|
||||||
|
|
||||||
show(viewer);
|
|
||||||
|
|
||||||
viewer.setItemOnCursor(cursor);
|
|
||||||
}, CustomAnvil.instance);
|
|
||||||
|
|
||||||
// Right item creation for consumer & bind
|
|
||||||
this.goRightItem = new GuiItem(new ItemStack(Material.GREEN_TERRACOTTA), event -> {
|
|
||||||
HumanEntity viewer = event.getWhoClicked();
|
|
||||||
UUID playerUUID = viewer.getUniqueId();
|
|
||||||
int page = pageMap.getOrDefault(playerUUID, 0);
|
|
||||||
this.pageMap.put(playerUUID, page + 1);
|
|
||||||
|
|
||||||
ItemStack cursor = viewer.getItemOnCursor();
|
|
||||||
viewer.setItemOnCursor(new ItemStack(Material.AIR));
|
|
||||||
|
|
||||||
show(viewer);
|
|
||||||
|
|
||||||
viewer.setItemOnCursor(cursor);
|
|
||||||
}, CustomAnvil.instance);
|
|
||||||
|
|
||||||
// Create new conflict item
|
// Create new conflict item
|
||||||
ItemStack createItem = new ItemStack(Material.PAPER);
|
ItemStack createItem = new ItemStack(Material.PAPER);
|
||||||
ItemMeta createMeta = createItem.getItemMeta();
|
ItemMeta createMeta = createItem.getItemMeta();
|
||||||
|
|
@ -126,7 +52,7 @@ public class EnchantConflictGui extends ChestGui {
|
||||||
|
|
||||||
createItem.setItemMeta(createMeta);
|
createItem.setItemMeta(createMeta);
|
||||||
|
|
||||||
this.backgroundPane.bindItem('C', new GuiItem(createItem, (clickEvent) -> {
|
return new GuiItem(createItem, (clickEvent) -> {
|
||||||
clickEvent.setCancelled(true);
|
clickEvent.setCancelled(true);
|
||||||
HumanEntity player = clickEvent.getWhoClicked();
|
HumanEntity player = clickEvent.getWhoClicked();
|
||||||
|
|
||||||
|
|
@ -143,7 +69,7 @@ public class EnchantConflictGui extends ChestGui {
|
||||||
|
|
||||||
CustomAnvil.Companion.getChatListener().setListenedCallback(player, prepareCreateItemConsumer(player));
|
CustomAnvil.Companion.getChatListener().setListenedCallback(player, prepareCreateItemConsumer(player));
|
||||||
|
|
||||||
}, CustomAnvil.instance));
|
}, CustomAnvil.instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Consumer<String> prepareCreateItemConsumer(HumanEntity player) {
|
private Consumer<String> prepareCreateItemConsumer(HumanEntity player) {
|
||||||
|
|
@ -184,7 +110,7 @@ public class EnchantConflictGui extends ChestGui {
|
||||||
0);
|
0);
|
||||||
|
|
||||||
ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList().add(conflict);
|
ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList().add(conflict);
|
||||||
updateValueForConflict(conflict, true);
|
updateValueForGeneric(conflict, true);
|
||||||
|
|
||||||
// save empty conflict in config
|
// save empty conflict in config
|
||||||
String[] emptyStringArray = new String[0];
|
String[] emptyStringArray = new String[0];
|
||||||
|
|
@ -207,29 +133,16 @@ public class EnchantConflictGui extends ChestGui {
|
||||||
return selfCallback;
|
return selfCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
private OutlinePane createEmptyPage() {
|
@Override
|
||||||
OutlinePane page = new OutlinePane(0, 0, 9, 5);
|
|
||||||
page.align(OutlinePane.Alignment.BEGIN);
|
|
||||||
page.setOrientation(Orientable.Orientation.HORIZONTAL);
|
|
||||||
|
|
||||||
return page;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reloadValues() {
|
public void reloadValues() {
|
||||||
this.conflictGuiMap.forEach((conflict, gui) -> gui.cleanUnused());
|
this.conflictGuiMap.forEach((conflict, gui) -> gui.cleanUnused());
|
||||||
this.conflictGuiMap.clear();
|
this.conflictGuiMap.clear();
|
||||||
this.firstPage.clear();
|
|
||||||
this.pages.clear();
|
|
||||||
this.pages.add(this.firstPage);
|
|
||||||
|
|
||||||
for (EnchantConflictGroup conflict : ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList()) {
|
super.reloadValues();
|
||||||
updateValueForConflict(conflict, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update();
|
@Override
|
||||||
}
|
public ItemStack createItemForGeneric(EnchantConflictGroup conflict) {
|
||||||
|
|
||||||
public static ItemStack createItemForConflict(EnchantConflictGroup conflict) {
|
|
||||||
ItemStack item = new ItemStack(conflict.getRepresentativeMaterial());
|
ItemStack item = new ItemStack(conflict.getRepresentativeMaterial());
|
||||||
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
|
@ -245,14 +158,14 @@ public class EnchantConflictGui extends ChestGui {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateValueForConflict(EnchantConflictGroup conflict, boolean shouldUpdate) {
|
@Override
|
||||||
|
protected void updateGeneric(EnchantConflictGroup conflict, ItemStack usedItem) {
|
||||||
EnchantConflictSubSettingGui gui = this.conflictGuiMap.get(conflict);
|
EnchantConflictSubSettingGui gui = this.conflictGuiMap.get(conflict);
|
||||||
ItemStack item = createItemForConflict(conflict);
|
|
||||||
|
|
||||||
GuiItem guiItem;
|
GuiItem guiItem;
|
||||||
if (gui == null) {
|
if (gui == null) {
|
||||||
// Create new sub setting gui
|
// Create new sub setting gui
|
||||||
guiItem = new GuiItem(item, CustomAnvil.instance);
|
guiItem = new GuiItem(usedItem, CustomAnvil.instance);
|
||||||
gui = new EnchantConflictSubSettingGui(this, conflict, guiItem);
|
gui = new EnchantConflictSubSettingGui(this, conflict, guiItem);
|
||||||
|
|
||||||
guiItem.setAction(GuiGlobalActions.openGuiAction(gui));
|
guiItem.setAction(GuiGlobalActions.openGuiAction(gui));
|
||||||
|
|
@ -262,152 +175,24 @@ public class EnchantConflictGui extends ChestGui {
|
||||||
} else {
|
} else {
|
||||||
// Replace item with the updated one
|
// Replace item with the updated one
|
||||||
guiItem = gui.getParentItemForThisGui();
|
guiItem = gui.getParentItemForThisGui();
|
||||||
guiItem.setItem(item);
|
guiItem.setItem(usedItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.updateLocal();
|
gui.updateLocal();
|
||||||
if (shouldUpdate) {
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeConflict(EnchantConflictGroup conflict) {
|
@Override
|
||||||
|
protected GuiItem findGuiItemForRemoval(EnchantConflictGroup conflict) {
|
||||||
EnchantConflictSubSettingGui gui = this.conflictGuiMap.get(conflict);
|
EnchantConflictSubSettingGui gui = this.conflictGuiMap.get(conflict);
|
||||||
if (gui == null) return;
|
if (gui == null) return null;
|
||||||
|
|
||||||
this.conflictGuiMap.remove(conflict);
|
this.conflictGuiMap.remove(conflict);
|
||||||
removeFromPage(gui.getParentItemForThisGui());
|
return gui.getParentItemForThisGui();
|
||||||
|
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addToPage(GuiItem guiItem) {
|
@Override
|
||||||
// Get first available page or create one
|
protected List<EnchantConflictGroup> getEveryDisplayableInstanceOfGeneric() {
|
||||||
OutlinePane page = this.pages.get(this.pages.size() - 1);
|
return ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList();
|
||||||
if (page.getItems().size() >= 5 * 9) {
|
|
||||||
page = createEmptyPage();
|
|
||||||
this.pages.add(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
page.addItem(guiItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeFromPage(GuiItem guiItem) {
|
|
||||||
// get item page
|
|
||||||
OutlinePane page = null;
|
|
||||||
int pageID = 0;
|
|
||||||
while (pageID < this.pages.size()) {
|
|
||||||
OutlinePane tempPage = this.pages.get(pageID);
|
|
||||||
if (tempPage.getItems().contains(guiItem)) {
|
|
||||||
page = tempPage;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
pageID++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (page == null) {// Why...
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
removeFromPage(page, pageID, guiItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeFromPage(OutlinePane page, int pageID, GuiItem guiItem) {
|
|
||||||
page.removeItem(guiItem);
|
|
||||||
|
|
||||||
// There is now a slot available, let fill it if possible
|
|
||||||
if (pageID < (this.pages.size() - 1)) {
|
|
||||||
OutlinePane newPage = this.pages.get(pageID + 1);
|
|
||||||
GuiItem nextPageItem = newPage.getItems().get(0);
|
|
||||||
|
|
||||||
removeFromPage(newPage, pageID + 1, nextPageItem);
|
|
||||||
|
|
||||||
OutlinePane thisPage = this.pages.get(pageID);
|
|
||||||
thisPage.addItem(nextPageItem);
|
|
||||||
} else if (pageID > 0 && page.getItems().isEmpty()) {
|
|
||||||
this.pages.remove(pageID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int getPlayerPageID(UUID uuid) {
|
|
||||||
int pageId = this.pageMap.getOrDefault(uuid, 0);
|
|
||||||
if (pageId >= this.pages.size()) {
|
|
||||||
pageId = this.pages.size() - 1;
|
|
||||||
}
|
|
||||||
return pageId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void placeArrow(int page, boolean customise) {
|
|
||||||
|
|
||||||
// Place left arrow
|
|
||||||
addPane(this.backgroundPane);
|
|
||||||
if (page > 0) {
|
|
||||||
if (customise) {
|
|
||||||
ItemStack leftItem = this.goLeftItem.getItem();
|
|
||||||
ItemMeta leftMeta = leftItem.getItemMeta();
|
|
||||||
|
|
||||||
leftMeta.setDisplayName("\u00A7eReturn to page " + (page));
|
|
||||||
|
|
||||||
leftItem.setItemMeta(leftMeta);
|
|
||||||
this.goLeftItem.setItem(leftItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.backgroundPane.bindItem('L', this.goLeftItem);
|
|
||||||
} else {
|
|
||||||
this.backgroundPane.bindItem('L', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Place right arrow
|
|
||||||
if (page < pages.size() - 1) {
|
|
||||||
if (customise) {
|
|
||||||
ItemStack rightItem = this.goRightItem.getItem();
|
|
||||||
ItemMeta rightMeta = rightItem.getItemMeta();
|
|
||||||
|
|
||||||
rightMeta.setDisplayName("\u00A7eGo to page " + (page + 2));
|
|
||||||
|
|
||||||
rightItem.setItemMeta(rightMeta);
|
|
||||||
this.goRightItem.setItem(rightItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.backgroundPane.bindItem('R', this.goRightItem);
|
|
||||||
} else {
|
|
||||||
this.backgroundPane.bindItem('R', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override // assume will not be called in multiple thread
|
|
||||||
public void show(@NotNull HumanEntity humanEntity) {
|
|
||||||
int pageID = getPlayerPageID(humanEntity.getUniqueId());
|
|
||||||
OutlinePane page = this.pages.get(pageID);
|
|
||||||
|
|
||||||
getPanes().clear();
|
|
||||||
|
|
||||||
// display the page arrow pane
|
|
||||||
placeArrow(pageID, true);
|
|
||||||
// and add actual page
|
|
||||||
addPane(page);
|
|
||||||
|
|
||||||
// set title
|
|
||||||
setTitle("Conflict Config (" + (pageID + 1) + "/" + (pages.size()) + ")");
|
|
||||||
|
|
||||||
super.show(humanEntity);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override // assume will not be called in multiple thread
|
|
||||||
public void click(@NotNull InventoryClickEvent event) {
|
|
||||||
int pageID = getPlayerPageID(event.getWhoClicked().getUniqueId());
|
|
||||||
OutlinePane page = this.pages.get(pageID);
|
|
||||||
|
|
||||||
getPanes().clear();
|
|
||||||
|
|
||||||
// set the page arrow pane
|
|
||||||
placeArrow(pageID, false);
|
|
||||||
// and add actual page
|
|
||||||
addPane(page);
|
|
||||||
|
|
||||||
super.click(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
import xyz.alexcrea.cuanvil.enchant.EnchantmentProperties;
|
import xyz.alexcrea.cuanvil.enchant.EnchantmentProperties;
|
||||||
import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity;
|
import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.AbstractEnchantConfigGui;
|
|
||||||
import xyz.alexcrea.cuanvil.gui.config.settings.EnchantCostSettingsGui;
|
import xyz.alexcrea.cuanvil.gui.config.settings.EnchantCostSettingsGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.AbstractEnchantConfigGui;
|
|
||||||
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateGuiValues() {
|
public void updateGuiValues() {
|
||||||
this.parent.updateValueForConflict(this.enchantConflict, true);
|
this.parent.updateValueForGeneric(this.enchantConflict, true);
|
||||||
// Parent should call updateLocal
|
// Parent should call updateLocal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue