Improved WindowBuilder

This commit is contained in:
NichtStudioCode 2023-01-28 17:55:26 +01:00
parent b6c09de2bc
commit 18113cc68a
34 changed files with 502 additions and 545 deletions

@ -3,10 +3,11 @@
package xyz.xenondevs.invui.window.type
import xyz.xenondevs.invui.window.Window
import xyz.xenondevs.invui.window.type.context.WindowContext
import xyz.xenondevs.invui.window.builder.WindowBuilder
import xyz.xenondevs.invui.window.builder.WindowType
fun <W : Window, C : WindowContext> WindowType<W, C>.create(contextConsumer: C.() -> Unit): W {
val ctx = createContext()
ctx.contextConsumer()
return createWindow(ctx)
fun <W : Window, B : WindowBuilder<W>> WindowType<W, B>.create(builderConsumer: B.() -> Unit): W {
val builder = builder()
builder.builderConsumer()
return builder.build()
}

@ -4,8 +4,9 @@ package xyz.xenondevs.invui.window.type.context
import net.kyori.adventure.text.Component
import xyz.xenondevs.inventoryaccess.component.AdventureComponentWrapper
import xyz.xenondevs.invui.window.builder.AbstractWindowBuilder
/**
* Sets the title of the window.
*/
fun AbstractWindowContext<*>.setTitle(title: Component) = setTitle(AdventureComponentWrapper(title))
fun AbstractWindowBuilder<*, *, *>.setTitle(title: Component) = setTitle(AdventureComponentWrapper(title))

@ -116,7 +116,7 @@ public class GuiBuilder<G extends Gui, C> {
return this;
}
public G build() {
public @NotNull G build() {
if (context.getStructure() == null)
throw new IllegalStateException("GuiContext has not been set yet.");

@ -1,9 +1,11 @@
package xyz.xenondevs.invui.gui.builder.guitype;
import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.invui.gui.Gui;
import xyz.xenondevs.invui.gui.PagedGui;
import xyz.xenondevs.invui.gui.ScrollGui;
import xyz.xenondevs.invui.gui.TabGui;
import xyz.xenondevs.invui.gui.builder.GuiBuilder;
import xyz.xenondevs.invui.gui.builder.GuiContext;
import xyz.xenondevs.invui.item.Item;
import xyz.xenondevs.invui.virtualinventory.VirtualInventory;
@ -19,11 +21,20 @@ public interface GuiType<G extends Gui, C> {
GuiType<ScrollGui<VirtualInventory>, VirtualInventory> SCROLL_INVENTORY = new ScrollVIGuiType();
/**
* Creates a {@link Gui} of type {@link G} with the given {@link GuiContext}
* Creates a {@link Gui} of type {@link G} with the given {@link GuiContext}.
*
* @param context The {@link GuiContext} to create the {@link G} from.
* @return The created {@link G}
* @param context The {@link GuiContext} to create the {@link Gui} from.
* @return The created {@link Gui}
*/
G createGui(GuiContext<C> context);
@NotNull G createGui(@NotNull GuiContext<C> context);
/**
* Creates a new {@link GuiBuilder} for this {@link GuiType}.
*
* @return The created {@link GuiBuilder}.
*/
default @NotNull GuiBuilder<G, C> builder() {
return new GuiBuilder<>(this);
}
}

@ -1,5 +1,6 @@
package xyz.xenondevs.invui.gui.builder.guitype;
import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.invui.gui.Gui;
import xyz.xenondevs.invui.gui.builder.GuiContext;
import xyz.xenondevs.invui.gui.impl.NormalGuiImpl;
@ -7,7 +8,7 @@ import xyz.xenondevs.invui.gui.impl.NormalGuiImpl;
class NormalGuiType implements GuiType<Gui, Void> {
@Override
public NormalGuiImpl createGui(GuiContext<Void> context) {
public @NotNull NormalGuiImpl createGui(@NotNull GuiContext<Void> context) {
NormalGuiImpl gui = new NormalGuiImpl(context.getStructure());
gui.setBackground(context.getBackground());
return gui;

@ -1,5 +1,6 @@
package xyz.xenondevs.invui.gui.builder.guitype;
import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.invui.gui.Gui;
import xyz.xenondevs.invui.gui.PagedGui;
import xyz.xenondevs.invui.gui.builder.GuiContext;
@ -8,7 +9,7 @@ import xyz.xenondevs.invui.gui.impl.PagedNestedGuiImpl;
class PagedGuisGuiType implements GuiType<PagedGui<Gui>, Gui> {
@Override
public PagedNestedGuiImpl createGui(GuiContext<Gui> context) {
public @NotNull PagedNestedGuiImpl createGui(@NotNull GuiContext<Gui> context) {
PagedNestedGuiImpl gui = new PagedNestedGuiImpl(context.getContent(), context.getStructure());
gui.setBackground(context.getBackground());
return gui;

@ -1,5 +1,6 @@
package xyz.xenondevs.invui.gui.builder.guitype;
import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.invui.gui.PagedGui;
import xyz.xenondevs.invui.gui.builder.GuiContext;
import xyz.xenondevs.invui.gui.impl.PagedItemsGuiImpl;
@ -8,7 +9,7 @@ import xyz.xenondevs.invui.item.Item;
class PagedItemsGuiType implements GuiType<PagedGui<Item>, Item> {
@Override
public PagedItemsGuiImpl createGui(GuiContext<Item> context) {
public @NotNull PagedItemsGuiImpl createGui(@NotNull GuiContext<Item> context) {
PagedItemsGuiImpl gui = new PagedItemsGuiImpl(context.getContent(), context.getStructure());
gui.setBackground(context.getBackground());
return gui;

@ -1,5 +1,6 @@
package xyz.xenondevs.invui.gui.builder.guitype;
import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.invui.gui.Gui;
import xyz.xenondevs.invui.gui.ScrollGui;
import xyz.xenondevs.invui.gui.builder.GuiContext;
@ -8,7 +9,7 @@ import xyz.xenondevs.invui.gui.impl.ScrollNestedGuiImpl;
class ScrollGuisGuiType implements GuiType<ScrollGui<Gui>, Gui> {
@Override
public ScrollNestedGuiImpl createGui(GuiContext<Gui> context) {
public @NotNull ScrollNestedGuiImpl createGui(@NotNull GuiContext<Gui> context) {
ScrollNestedGuiImpl gui = new ScrollNestedGuiImpl(context.getContent(), context.getStructure());
gui.setBackground(gui.getBackground());
return gui;

@ -1,5 +1,6 @@
package xyz.xenondevs.invui.gui.builder.guitype;
import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.invui.gui.ScrollGui;
import xyz.xenondevs.invui.gui.builder.GuiContext;
import xyz.xenondevs.invui.gui.impl.ScrollItemsGuiImpl;
@ -8,7 +9,7 @@ import xyz.xenondevs.invui.item.Item;
class ScrollItemsGuiType implements GuiType<ScrollGui<Item>, Item> {
@Override
public ScrollItemsGuiImpl createGui(GuiContext<Item> context) {
public @NotNull ScrollItemsGuiImpl createGui(@NotNull GuiContext<Item> context) {
ScrollItemsGuiImpl gui = new ScrollItemsGuiImpl(context.getContent(), context.getStructure());
gui.setBackground(context.getBackground());
return gui;

@ -1,5 +1,6 @@
package xyz.xenondevs.invui.gui.builder.guitype;
import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.invui.gui.ScrollGui;
import xyz.xenondevs.invui.gui.builder.GuiContext;
import xyz.xenondevs.invui.gui.impl.ScrollVIGuiImpl;
@ -8,7 +9,7 @@ import xyz.xenondevs.invui.virtualinventory.VirtualInventory;
class ScrollVIGuiType implements GuiType<ScrollGui<VirtualInventory>, VirtualInventory> {
@Override
public ScrollVIGuiImpl createGui(GuiContext<VirtualInventory> context) {
public @NotNull ScrollVIGuiImpl createGui(@NotNull GuiContext<VirtualInventory> context) {
ScrollVIGuiImpl gui = new ScrollVIGuiImpl(context.getContent(), context.getStructure());
gui.setBackground(context.getBackground());
return gui;

@ -1,5 +1,6 @@
package xyz.xenondevs.invui.gui.builder.guitype;
import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.invui.gui.Gui;
import xyz.xenondevs.invui.gui.TabGui;
import xyz.xenondevs.invui.gui.builder.GuiContext;
@ -8,7 +9,7 @@ import xyz.xenondevs.invui.gui.impl.TabGuiImpl;
class TabGuiType implements GuiType<TabGui, Gui> {
@Override
public TabGuiImpl createGui(GuiContext<Gui> context) {
public @NotNull TabGuiImpl createGui(@NotNull GuiContext<Gui> context) {
TabGuiImpl gui = new TabGuiImpl(context.getContent(), context.getStructure());
gui.setBackground(context.getBackground());
return gui;

@ -6,7 +6,7 @@ import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.xenondevs.inventoryaccess.component.ComponentWrapper;
import xyz.xenondevs.invui.window.type.WindowType;
import xyz.xenondevs.invui.window.builder.WindowType;
import java.util.UUID;

@ -0,0 +1,30 @@
package xyz.xenondevs.invui.window.builder;
import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.invui.gui.Gui;
import xyz.xenondevs.invui.gui.builder.GuiBuilder;
import xyz.xenondevs.invui.window.Window;
import java.util.function.Supplier;
public abstract class AbstractSingleWindowBuilder<W extends Window, V, S extends AbstractSingleWindowBuilder<W, V, S>> extends AbstractWindowBuilder<W, V, S> {
protected Supplier<Gui> guiSupplier;
public S setGui(@NotNull Supplier<Gui> guiSupplier) {
this.guiSupplier = guiSupplier;
return getThis();
}
public S setGui(@NotNull Gui gui) {
this.guiSupplier = () -> gui;
return getThis();
}
public S setGui(@NotNull GuiBuilder<?, ?> builder) {
this.guiSupplier = builder::build;
return getThis();
}
}

@ -0,0 +1,45 @@
package xyz.xenondevs.invui.window.builder;
import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.invui.gui.Gui;
import xyz.xenondevs.invui.gui.builder.GuiBuilder;
import xyz.xenondevs.invui.window.Window;
import java.util.function.Supplier;
public abstract class AbstractSplitWindowBuilder<W extends Window, V, S extends AbstractSplitWindowBuilder<W, V, S>> extends AbstractWindowBuilder<W, V, S> {
protected Supplier<Gui> upperGuiSupplier;
protected Supplier<Gui> lowerGuiSupplier;
public S setUpperGui(@NotNull Supplier<Gui> guiSupplier) {
this.upperGuiSupplier = guiSupplier;
return getThis();
}
public S setUpperGui(@NotNull Gui gui) {
this.upperGuiSupplier = () -> gui;
return getThis();
}
public S setUpperGui(@NotNull GuiBuilder<?, ?> builder) {
this.upperGuiSupplier = builder::build;
return getThis();
}
public S setLowerGui(@NotNull Supplier<Gui> guiSupplier) {
this.lowerGuiSupplier = guiSupplier;
return getThis();
}
public S setLowerGui(@NotNull Gui gui) {
this.lowerGuiSupplier = () -> gui;
return getThis();
}
public S setLowerGui(@NotNull GuiBuilder<?, ?> builder) {
this.lowerGuiSupplier = builder::build;
return getThis();
}
}

@ -0,0 +1,72 @@
package xyz.xenondevs.invui.window.builder;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.inventoryaccess.component.BaseComponentWrapper;
import xyz.xenondevs.inventoryaccess.component.ComponentWrapper;
import xyz.xenondevs.invui.window.Window;
import java.util.ArrayList;
import java.util.List;
public abstract class AbstractWindowBuilder<W extends Window, V, S extends AbstractWindowBuilder<W, V, S>> implements WindowBuilder<W> {
protected V viewer;
protected ComponentWrapper title;
protected boolean closeable = true;
protected boolean retain = false;
protected List<Runnable> closeHandlers;
public S setViewer(@NotNull V viewer) {
this.viewer = viewer;
return getThis();
}
public S setTitle(@NotNull ComponentWrapper title) {
this.title = title;
return getThis();
}
public S setTitle(@NotNull BaseComponent @NotNull [] title) {
this.title = new BaseComponentWrapper(title);
return getThis();
}
public S setTitle(@NotNull String title) {
this.title = new BaseComponentWrapper(TextComponent.fromLegacyText(title));
return getThis();
}
public S setCloseable(boolean closeable) {
this.closeable = closeable;
return getThis();
}
public S setRetain(boolean retain) {
this.retain = retain;
return getThis();
}
public S setCloseHandlers(List<Runnable> closeHandlers) {
this.closeHandlers = closeHandlers;
return getThis();
}
public S addCloseHandler(Runnable closeHandler) {
if (closeHandlers == null)
closeHandlers = new ArrayList<>();
closeHandlers.add(closeHandler);
return getThis();
}
protected void applyChanges(W window) {
if (closeHandlers != null) {
closeHandlers.forEach(window::addCloseHandler);
}
}
protected abstract S getThis();
}

@ -0,0 +1,43 @@
package xyz.xenondevs.invui.window.builder;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.invui.gui.AbstractGui;
import xyz.xenondevs.invui.window.AnvilWindow;
import xyz.xenondevs.invui.window.impl.AnvilSingleWindowImpl;
import java.util.function.Consumer;
public final class AnvilSingleWindowBuilder extends AbstractSingleWindowBuilder<AnvilWindow, Player, AnvilSingleWindowBuilder> {
private Consumer<String> renameHandler;
AnvilSingleWindowBuilder() {
}
public void setRenameHandler(@NotNull Consumer<String> renameHandler) {
this.renameHandler = renameHandler;
}
@Override
public @NotNull AnvilWindow build() {
var window = new AnvilSingleWindowImpl(
viewer,
title,
(AbstractGui) guiSupplier.get(),
renameHandler,
closeable,
retain
);
applyChanges(window);
return window;
}
@Override
protected AnvilSingleWindowBuilder getThis() {
return null;
}
}

@ -0,0 +1,45 @@
package xyz.xenondevs.invui.window.builder;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.invui.gui.AbstractGui;
import xyz.xenondevs.invui.window.AnvilWindow;
import xyz.xenondevs.invui.window.impl.AnvilSplitWindowImpl;
import java.util.function.Consumer;
public final class AnvilSplitWindowBuilder extends AbstractSplitWindowBuilder<AnvilWindow, Player, AnvilSplitWindowBuilder> {
private Consumer<String> renameHandler;
AnvilSplitWindowBuilder() {
}
public AnvilSplitWindowBuilder setRenameHandler(@NotNull Consumer<String> renameHandler) {
this.renameHandler = renameHandler;
return this;
}
@Override
public @NotNull AnvilWindow build() {
var window = new AnvilSplitWindowImpl(
viewer,
title,
(AbstractGui) upperGuiSupplier.get(),
(AbstractGui) lowerGuiSupplier.get(),
renameHandler,
closeable,
retain
);
applyChanges(window);
return window;
}
@Override
protected AnvilSplitWindowBuilder getThis() {
return this;
}
}

@ -0,0 +1,34 @@
package xyz.xenondevs.invui.window.builder;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.invui.gui.AbstractGui;
import xyz.xenondevs.invui.window.CartographyWindow;
import xyz.xenondevs.invui.window.impl.CartographySingleWindowImpl;
public final class CartographySingleWindowBuilder extends AbstractSingleWindowBuilder<CartographyWindow, Player, CartographySingleWindowBuilder> {
CartographySingleWindowBuilder() {
}
@Override
public @NotNull CartographyWindow build() {
var window = new CartographySingleWindowImpl(
viewer,
title,
(AbstractGui) guiSupplier.get(),
closeable,
retain
);
applyChanges(window);
return window;
}
@Override
protected CartographySingleWindowBuilder getThis() {
return this;
}
}

@ -0,0 +1,35 @@
package xyz.xenondevs.invui.window.builder;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.invui.gui.AbstractGui;
import xyz.xenondevs.invui.window.CartographyWindow;
import xyz.xenondevs.invui.window.impl.CartographySplitWindowImpl;
public final class CartographySplitWindowBuilder extends AbstractSplitWindowBuilder<CartographyWindow, Player, CartographySplitWindowBuilder> {
CartographySplitWindowBuilder() {
}
@Override
public @NotNull CartographyWindow build() {
var window = new CartographySplitWindowImpl(
viewer,
title,
(AbstractGui) upperGuiSupplier.get(),
(AbstractGui) lowerGuiSupplier.get(),
closeable,
retain
);
applyChanges(window);
return window;
}
@Override
protected CartographySplitWindowBuilder getThis() {
return this;
}
}

@ -0,0 +1,34 @@
package xyz.xenondevs.invui.window.builder;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.invui.gui.AbstractGui;
import xyz.xenondevs.invui.window.Window;
import xyz.xenondevs.invui.window.impl.NormalMergedWindowImpl;
public final class NormalMergedWindowBuilder extends AbstractSingleWindowBuilder<Window, Player, NormalMergedWindowBuilder> {
NormalMergedWindowBuilder() {
}
@Override
public @NotNull Window build() {
var window = new NormalMergedWindowImpl(
viewer,
title,
(AbstractGui) guiSupplier.get(),
closeable,
retain
);
applyChanges(window);
return window;
}
@Override
protected NormalMergedWindowBuilder getThis() {
return this;
}
}

@ -0,0 +1,41 @@
package xyz.xenondevs.invui.window.builder;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.invui.gui.AbstractGui;
import xyz.xenondevs.invui.window.Window;
import xyz.xenondevs.invui.window.impl.NormalSingleWindowImpl;
import java.util.UUID;
public final class NormalSingleWindowBuilder extends AbstractSingleWindowBuilder<Window, UUID, NormalSingleWindowBuilder> {
NormalSingleWindowBuilder() {
}
public NormalSingleWindowBuilder setViewer(@NotNull OfflinePlayer player) {
setViewer(player.getUniqueId());
return this;
}
@Override
public @NotNull Window build() {
var window = new NormalSingleWindowImpl(
viewer,
title,
(AbstractGui) guiSupplier.get(),
closeable,
retain
);
applyChanges(window);
return window;
}
@Override
protected NormalSingleWindowBuilder getThis() {
return this;
}
}

@ -0,0 +1,35 @@
package xyz.xenondevs.invui.window.builder;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.invui.gui.AbstractGui;
import xyz.xenondevs.invui.window.Window;
import xyz.xenondevs.invui.window.impl.NormalSplitWindowImpl;
public final class NormalSplitWindowBuilder extends AbstractSplitWindowBuilder<Window, Player, NormalSplitWindowBuilder> {
NormalSplitWindowBuilder() {
}
@Override
public @NotNull Window build() {
var window = new NormalSplitWindowImpl(
viewer,
title,
(AbstractGui) upperGuiSupplier.get(),
(AbstractGui) lowerGuiSupplier.get(),
closeable,
retain
);
applyChanges(window);
return window;
}
@Override
protected NormalSplitWindowBuilder getThis() {
return this;
}
}

@ -0,0 +1,10 @@
package xyz.xenondevs.invui.window.builder;
import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.invui.window.Window;
public interface WindowBuilder<W extends Window> {
@NotNull W build();
}

@ -0,0 +1,39 @@
package xyz.xenondevs.invui.window.builder;
import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.invui.window.AnvilWindow;
import xyz.xenondevs.invui.window.CartographyWindow;
import xyz.xenondevs.invui.window.Window;
import java.util.function.Consumer;
public interface WindowType<W extends Window, B extends WindowBuilder<W>> {
WindowType<Window, NormalSingleWindowBuilder> NORMAL = NormalSingleWindowBuilder::new;
WindowType<Window, NormalMergedWindowBuilder> NORMAL_MERGED = NormalMergedWindowBuilder::new;
WindowType<Window, NormalSplitWindowBuilder> NORMAL_SPLIT = NormalSplitWindowBuilder::new;
WindowType<AnvilWindow, AnvilSingleWindowBuilder> ANVIL = AnvilSingleWindowBuilder::new;
WindowType<AnvilWindow, AnvilSplitWindowBuilder> ANVIL_SPLIT = AnvilSplitWindowBuilder::new;
WindowType<CartographyWindow, CartographySingleWindowBuilder> CARTOGRAPHY = CartographySingleWindowBuilder::new;
WindowType<CartographyWindow, CartographySplitWindowBuilder> CARTOGRAPHY_SPLIT = CartographySplitWindowBuilder::new;
/**
* Creates a new {@link WindowBuilder} for this {@link WindowType}.
*
* @return The new {@link WindowBuilder}.
*/
@NotNull B builder();
/**
* Creates a new {@link Window} after modifying the {@link WindowBuilder} with the given {@link Consumer}.
*
* @param builderConsumer The {@link Consumer} which modifies the {@link WindowBuilder}.
* @return The new {@link Window}.
*/
default @NotNull W createWindow(Consumer<B> builderConsumer) {
B builder = builder();
builderConsumer.accept(builder);
return builder.build();
}
}

@ -1,170 +0,0 @@
package xyz.xenondevs.invui.window.type;
import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.invui.gui.AbstractGui;
import xyz.xenondevs.invui.window.AnvilWindow;
import xyz.xenondevs.invui.window.CartographyWindow;
import xyz.xenondevs.invui.window.Window;
import xyz.xenondevs.invui.window.impl.*;
import xyz.xenondevs.invui.window.type.context.*;
import java.util.function.Consumer;
public interface WindowType<W extends Window, C extends WindowContext> {
WindowType<Window, NormalSingleWindowContext> NORMAL = new WindowType<>() {
@Override
public @NotNull NormalSingleWindowContext createContext() {
return new NormalSingleWindowContext();
}
@Override
public @NotNull Window createWindow(@NotNull NormalSingleWindowContext context) {
return new NormalSingleWindowImpl(
context.getViewer(),
context.getTitle(),
(AbstractGui) context.getGui(),
context.isCloseable(),
context.isRetain()
);
}
};
WindowType<Window, NormalCombinedWindowContext> NORMAL_MERGED = new WindowType<>() {
@Override
public @NotNull NormalCombinedWindowContext createContext() {
return new NormalCombinedWindowContext();
}
@Override
public @NotNull Window createWindow(@NotNull NormalCombinedWindowContext context) {
return new NormalMergedWindowImpl(
context.getViewer(),
context.getTitle(),
(AbstractGui) context.getGui(),
context.isCloseable(),
context.isRetain()
);
}
};
WindowType<Window, NormalSplitWindowContext> NORMAL_SPLIT = new WindowType<>() {
@Override
public @NotNull NormalSplitWindowContext createContext() {
return new NormalSplitWindowContext();
}
@Override
public @NotNull Window createWindow(@NotNull NormalSplitWindowContext context) {
return new NormalSplitWindowImpl(
context.getViewer(),
context.getTitle(),
(AbstractGui) context.getUpperGui(),
(AbstractGui) context.getLowerGui(),
context.isCloseable(),
context.isRetain()
);
}
};
WindowType<AnvilWindow, AnvilSingleWindowContext> ANVIL = new WindowType<>() {
@Override
public @NotNull AnvilSingleWindowContext createContext() {
return new AnvilSingleWindowContext();
}
@Override
public @NotNull AnvilWindow createWindow(@NotNull AnvilSingleWindowContext context) {
return new AnvilSingleWindowImpl(
context.getViewer(),
context.getTitle(),
(AbstractGui) context.getGui(),
context.getRenameHandler(),
context.isCloseable(),
context.isRetain()
);
}
};
WindowType<AnvilWindow, AnvilSplitWindowContext> ANVIL_SPLIT = new WindowType<>() {
@Override
public @NotNull AnvilSplitWindowContext createContext() {
return new AnvilSplitWindowContext();
}
@Override
public @NotNull AnvilWindow createWindow(@NotNull AnvilSplitWindowContext context) {
return new AnvilSplitWindowImpl(
context.getViewer(),
context.getTitle(),
(AbstractGui) context.getUpperGui(),
(AbstractGui) context.getLowerGui(),
context.getRenameHandler(),
context.isCloseable(),
context.isRetain()
);
}
};
WindowType<CartographyWindow, CartographySingleWindowContext> CARTOGRAPHY = new WindowType<>() {
@Override
public @NotNull CartographySingleWindowContext createContext() {
return new CartographySingleWindowContext();
}
@Override
public @NotNull CartographyWindow createWindow(@NotNull CartographySingleWindowContext context) {
return new CartographySingleWindowImpl(
context.getViewer(),
context.getTitle(),
(AbstractGui) context.getGui(),
context.isCloseable(),
context.isRetain()
);
}
};
WindowType<CartographyWindow, CartographySplitWindowContext> CARTOGRAPHY_SPLIT = new WindowType<>() {
@Override
public @NotNull CartographySplitWindowContext createContext() {
return new CartographySplitWindowContext();
}
@Override
public @NotNull CartographyWindow createWindow(@NotNull CartographySplitWindowContext context) {
return new CartographySplitWindowImpl(
context.getViewer(),
context.getTitle(),
(AbstractGui) context.getUpperGui(),
(AbstractGui) context.getLowerGui(),
context.isCloseable(),
context.isRetain()
);
}
};
@NotNull C createContext();
@NotNull W createWindow(@NotNull C context);
default @NotNull W createWindow(Consumer<C> contextConsumer) {
C context = createContext();
contextConsumer.accept(context);
return createWindow(context);
}
}

@ -1,59 +0,0 @@
package xyz.xenondevs.invui.window.type.context;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.xenondevs.inventoryaccess.component.BaseComponentWrapper;
import xyz.xenondevs.inventoryaccess.component.ComponentWrapper;
public abstract class AbstractWindowContext<V> implements WindowContext {
protected boolean closeable = true;
protected boolean retain = false;
protected ComponentWrapper title;
protected V viewer;
public boolean isCloseable() {
return closeable;
}
public void setCloseable(boolean closeable) {
this.closeable = closeable;
}
public boolean isRetain() {
return retain;
}
public void setRetain(boolean retain) {
this.retain = retain;
}
@Nullable
public ComponentWrapper getTitle() {
return title;
}
public void setTitle(@NotNull ComponentWrapper title) {
this.title = title;
}
public void setTitle(@NotNull BaseComponent @NotNull [] title) {
this.title = new BaseComponentWrapper(title);
}
public void setTitle(@NotNull String title) {
this.title = new BaseComponentWrapper(TextComponent.fromLegacyText(title));
}
@Nullable
public V getViewer() {
return viewer;
}
public void setViewer(@NotNull V viewer) {
this.viewer = viewer;
}
}

@ -1,41 +0,0 @@
package xyz.xenondevs.invui.window.type.context;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.xenondevs.invui.gui.Gui;
import xyz.xenondevs.invui.gui.builder.GuiBuilder;
import java.util.function.Consumer;
import java.util.function.Supplier;
public final class AnvilSingleWindowContext extends AbstractWindowContext<Player> {
private Supplier<Gui> guiSupplier;
private Consumer<String> renameHandler;
public @Nullable Gui getGui() {
return guiSupplier.get();
}
public void setGui(@NotNull Supplier<Gui> guiSupplier) {
this.guiSupplier = guiSupplier;
}
public void setGui(@NotNull Gui gui) {
this.guiSupplier = () -> gui;
}
public void setGui(@NotNull GuiBuilder<?, ?> builder) {
this.guiSupplier = builder::build;
}
public @Nullable Consumer<String> getRenameHandler() {
return renameHandler;
}
public void setRenameHandler(@NotNull Consumer<String> renameHandler) {
this.renameHandler = renameHandler;
}
}

@ -1,58 +0,0 @@
package xyz.xenondevs.invui.window.type.context;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.xenondevs.invui.gui.Gui;
import xyz.xenondevs.invui.gui.builder.GuiBuilder;
import java.util.function.Consumer;
import java.util.function.Supplier;
public final class AnvilSplitWindowContext extends AbstractWindowContext<Player> {
private Supplier<Gui> upperGuiSupplier;
private Supplier<Gui> lowerGuiSupplier;
private Consumer<String> renameHandler;
public @Nullable Gui getUpperGui() {
return upperGuiSupplier.get();
}
public void setUpperGui(@NotNull Supplier<Gui> guiSupplier) {
this.upperGuiSupplier = guiSupplier;
}
public void setUpperGui(@NotNull Gui gui) {
this.upperGuiSupplier = () -> gui;
}
public void setUpperGui(@NotNull GuiBuilder<?, ?> builder) {
this.upperGuiSupplier = builder::build;
}
public @Nullable Gui getLowerGui() {
return lowerGuiSupplier.get();
}
public void setLowerGui(@NotNull Supplier<Gui> guiSupplier) {
this.lowerGuiSupplier = guiSupplier;
}
public void setLowerGui(@NotNull Gui gui) {
this.lowerGuiSupplier = () -> gui;
}
public void setLowerGui(@NotNull GuiBuilder<?, ?> builder) {
this.lowerGuiSupplier = builder::build;
}
public @Nullable Consumer<String> getRenameHandler() {
return renameHandler;
}
public void setRenameHandler(@NotNull Consumer<String> renameHandler) {
this.renameHandler = renameHandler;
}
}

@ -1,31 +0,0 @@
package xyz.xenondevs.invui.window.type.context;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.xenondevs.invui.gui.Gui;
import xyz.xenondevs.invui.gui.builder.GuiBuilder;
import java.util.function.Supplier;
public final class CartographySingleWindowContext extends AbstractWindowContext<Player> {
private Supplier<Gui> guiSupplier;
public @Nullable Gui getGui() {
return guiSupplier.get();
}
public void setGui(@NotNull Supplier<Gui> guiSupplier) {
this.guiSupplier = guiSupplier;
}
public void setGui(@NotNull Gui gui) {
this.guiSupplier = () -> gui;
}
public void setGui(@NotNull GuiBuilder<?, ?> builder) {
this.guiSupplier = builder::build;
}
}

@ -1,48 +0,0 @@
package xyz.xenondevs.invui.window.type.context;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.xenondevs.invui.gui.Gui;
import xyz.xenondevs.invui.gui.builder.GuiBuilder;
import java.util.function.Supplier;
public final class CartographySplitWindowContext extends AbstractWindowContext<Player> {
private Supplier<Gui> upperGuiSupplier;
private Supplier<Gui> lowerGuiSupplier;
public @Nullable Gui getUpperGui() {
return upperGuiSupplier.get();
}
public void setUpperGui(@NotNull Supplier<Gui> guiSupplier) {
this.upperGuiSupplier = guiSupplier;
}
public void setUpperGui(@NotNull Gui gui) {
this.upperGuiSupplier = () -> gui;
}
public void setUpperGui(@NotNull GuiBuilder<?, ?> builder) {
this.upperGuiSupplier = builder::build;
}
public @Nullable Gui getLowerGui() {
return lowerGuiSupplier.get();
}
public void setLowerGui(@NotNull Supplier<Gui> guiSupplier) {
this.lowerGuiSupplier = guiSupplier;
}
public void setLowerGui(@NotNull Gui gui) {
this.lowerGuiSupplier = () -> gui;
}
public void setLowerGui(@NotNull GuiBuilder<?, ?> builder) {
this.lowerGuiSupplier = builder::build;
}
}

@ -1,31 +0,0 @@
package xyz.xenondevs.invui.window.type.context;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.xenondevs.invui.gui.Gui;
import xyz.xenondevs.invui.gui.builder.GuiBuilder;
import java.util.function.Supplier;
public final class NormalCombinedWindowContext extends AbstractWindowContext<Player> {
private Supplier<Gui> guiSupplier;
public @Nullable Gui getGui() {
return guiSupplier.get();
}
public void setGui(@NotNull Supplier<Gui> guiSupplier) {
this.guiSupplier = guiSupplier;
}
public void setGui(@NotNull Gui gui) {
this.guiSupplier = () -> gui;
}
public void setGui(@NotNull GuiBuilder<?, ?> builder) {
this.guiSupplier = builder::build;
}
}

@ -1,36 +0,0 @@
package xyz.xenondevs.invui.window.type.context;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.xenondevs.invui.gui.Gui;
import xyz.xenondevs.invui.gui.builder.GuiBuilder;
import java.util.UUID;
import java.util.function.Supplier;
public final class NormalSingleWindowContext extends AbstractWindowContext<UUID> {
private Supplier<Gui> guiSupplier;
public @Nullable Gui getGui() {
return guiSupplier.get();
}
public void setGui(@NotNull Supplier<Gui> guiSupplier) {
this.guiSupplier = guiSupplier;
}
public void setGui(@NotNull Gui gui) {
this.guiSupplier = () -> gui;
}
public void setGui(@NotNull GuiBuilder<?, ?> builder) {
this.guiSupplier = builder::build;
}
public void setViewer(@NotNull OfflinePlayer player) {
this.viewer = player.getUniqueId();
}
}

@ -1,48 +0,0 @@
package xyz.xenondevs.invui.window.type.context;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.xenondevs.invui.gui.Gui;
import xyz.xenondevs.invui.gui.builder.GuiBuilder;
import java.util.function.Supplier;
public final class NormalSplitWindowContext extends AbstractWindowContext<Player> {
private Supplier<Gui> upperGuiSupplier;
private Supplier<Gui> lowerGuiSupplier;
public @Nullable Gui getUpperGui() {
return upperGuiSupplier.get();
}
public void setUpperGui(@NotNull Supplier<Gui> guiSupplier) {
this.upperGuiSupplier = guiSupplier;
}
public void setUpperGui(@NotNull Gui gui) {
this.upperGuiSupplier = () -> gui;
}
public void setUpperGui(@NotNull GuiBuilder<?, ?> builder) {
this.upperGuiSupplier = builder::build;
}
public @Nullable Gui getLowerGui() {
return lowerGuiSupplier.get();
}
public void setLowerGui(@NotNull Supplier<Gui> guiSupplier) {
this.lowerGuiSupplier = guiSupplier;
}
public void setLowerGui(@NotNull Gui gui) {
this.lowerGuiSupplier = () -> gui;
}
public void setLowerGui(@NotNull GuiBuilder<?, ?> builder) {
this.lowerGuiSupplier = builder::build;
}
}

@ -1,4 +0,0 @@
package xyz.xenondevs.invui.window.type.context;
public interface WindowContext {
}