Start of the group config guis.

This commit is contained in:
alexcrea 2024-04-18 02:20:46 +02:00
parent 8c90ae2184
commit 2c6349735b
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
6 changed files with 205 additions and 4 deletions

View file

@ -82,15 +82,15 @@ public class MainConfigGui extends ChestGui {
GuiItem enchantConflictItem = GuiGlobalItems.goToGuiItem(EnchantConflictItemstack, EnchantConflictGui.INSTANCE);
pane.bindItem('4', enchantConflictItem);
// WIP configuration items
// Group config items
ItemStack wipItemstack = new ItemStack(Material.BARRIER);
ItemMeta wipMeta = wipItemstack.getItemMeta();
wipMeta.setDisplayName("\u00A7cWIP");
wipItemstack.setItemMeta(wipMeta);
GuiItem wip = new GuiItem(wipItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
GuiItem groupConfigItem = GuiGlobalItems.goToGuiItem(wipItemstack, GroupConfigGui.INSTANCE);
pane.bindItem('5', wip);
pane.bindItem('5', groupConfigItem);
// Unit repair item
ItemStack unirRepairItemstack = new ItemStack(Material.DIAMOND);

View file

@ -0,0 +1,67 @@
package xyz.alexcrea.cuanvil.gui.config.global;
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.group.AbstractMaterialGroup;
import xyz.alexcrea.cuanvil.group.IncludeGroup;
import xyz.alexcrea.cuanvil.gui.config.list.MappedGuiListConfigGui;
import xyz.alexcrea.cuanvil.gui.config.list.elements.ConflictSubSettingGui;
import java.util.ArrayList;
import java.util.List;
public class GroupConfigGui extends MappedGuiListConfigGui<AbstractMaterialGroup, ConflictSubSettingGui> {
public final static GroupConfigGui INSTANCE = new GroupConfigGui();
static {
INSTANCE.init();
}
public GroupConfigGui() {
super("Group Config");
}
@Override
protected ItemStack createItemForGeneric(AbstractMaterialGroup group) {
ItemStack item = new ItemStack(group.getRepresentativeMaterial());
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(group.getName());
item.setItemMeta(meta);
return item;
}
@Override
protected List<AbstractMaterialGroup> getEveryDisplayableInstanceOfGeneric() {
ArrayList<AbstractMaterialGroup> includeGroups = new ArrayList<>();
for (AbstractMaterialGroup group : ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values()) {
if(group instanceof IncludeGroup){
includeGroups.add(group);
}
}
return includeGroups;
}
@Override
protected ConflictSubSettingGui newInstanceOfGui(AbstractMaterialGroup group, GuiItem item) {
return new ConflictSubSettingGui(this, group, item);
}
@Override
protected String genericDisplayedName() {
return "material group";
}
@Override
protected AbstractMaterialGroup createAndSaveNewEmptyGeneric(String name) {
return null;
}
}

View file

@ -81,6 +81,7 @@ public abstract class MappedGuiListConfigGui< T, S extends ElementMappedToListGu
}
T generic = createAndSaveNewEmptyGeneric(message);
if(generic == null) return;// we don't know what to do
updateValueForGeneric(generic, true);

View file

@ -0,0 +1,129 @@
package xyz.alexcrea.cuanvil.gui.config.list.elements;
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
import com.github.stefvanschie.inventoryframework.pane.PatternPane;
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
import io.delilaheve.CustomAnvil;
import org.bukkit.Bukkit;
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.config.ConfigHolder;
import xyz.alexcrea.cuanvil.group.AbstractMaterialGroup;
import xyz.alexcrea.cuanvil.group.ItemGroupManager;
import xyz.alexcrea.cuanvil.gui.config.ask.ConfirmActionGui;
import xyz.alexcrea.cuanvil.gui.config.global.GroupConfigGui;
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.recipe.CustomAnvilRecipeManager;
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
import java.util.Collections;
import java.util.function.Consumer;
import java.util.function.Supplier;
public class ConflictSubSettingGui extends MappedToListSubSettingGui {
private final GroupConfigGui parent;
private final AbstractMaterialGroup group;
private final PatternPane pane;
public ConflictSubSettingGui(
@NotNull GroupConfigGui parent,
@NotNull AbstractMaterialGroup group,
@NotNull GuiItem item) {
super(item, 3, group.getName());
this.parent = parent;
this.group = group;
Pattern pattern = new Pattern(
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
"00102000D",
"B00000000"
);
this.pane = new PatternPane(0, 0, 9, 3, pattern);
addPane(this.pane);
prepareStaticValues();
}
private void prepareStaticValues() {
GuiGlobalItems.addBackItem(this.pane, this.parent);
GuiGlobalItems.addBackgroundItem(this.pane);
// Delete item
ItemStack deleteItem = new ItemStack(Material.RED_TERRACOTTA);
ItemMeta deleteMeta = deleteItem.getItemMeta();
deleteMeta.setDisplayName("\u00A74DELETE RECIPE");
deleteMeta.setLore(Collections.singletonList("\u00A7cCaution with this button !"));
deleteItem.setItemMeta(deleteMeta);
this.pane.bindItem('D', new GuiItem(deleteItem, GuiGlobalActions.openGuiAction(createDeleteGui()), CustomAnvil.instance));
}
private @NotNull Consumer<InventoryClickEvent> openGuiAction() {
ConfirmActionGui deleteGui = createDeleteGui();
return event -> {
event.setCancelled(true);
HumanEntity player = event.getWhoClicked();
// Do not allow to open inventory if player do not have edit configuration permission
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.closeInventory();
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
return;
}
// TODO test if group is used & cancel if so
deleteGui.show(player);
};
}
private @NotNull ConfirmActionGui createDeleteGui() {
Supplier<Boolean> deleteSupplier = () -> {
ItemGroupManager manager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager();
// TODO test if group is used & cancel if so
// TODO remove group
Bukkit.broadcastMessage("todo");
// Save
boolean success = true;
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
success = ConfigHolder.CONFLICT_HOLDER.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
}
return success;
};
return new ConfirmActionGui("\u00A7cDelete \u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(this.group.toString()) + "\u00A7c?",
"\u00A77Confirm that you want to delete this group.",
this, this.parent, deleteSupplier
);
}
@Override
public void updateGuiValues() {
// TODO update value from config to conflict
// Parent should call updateLocal with this call
this.parent.updateValueForGeneric(this.group, true);
}
@Override
public void updateLocal() {
}
@Override
public void cleanAndBeUnusable() {
}
}

View file

@ -97,6 +97,7 @@ public class GuiGlobalActions {
*/
public static @NotNull Consumer<InventoryClickEvent> openGuiAction(@NotNull Gui goal) {
return event -> {
event.setCancelled(true);
HumanEntity player = event.getWhoClicked();
// Do not allow to open inventory if player do not have edit configuration permission
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
@ -104,7 +105,6 @@ public class GuiGlobalActions {
player.sendMessage(NO_EDIT_PERM);
return;
}
event.setCancelled(true);
goal.show(player);
};
}