Skip to content

Commit

Permalink
add Javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Feb 20, 2025
1 parent dd90455 commit 204f19e
Show file tree
Hide file tree
Showing 54 changed files with 263 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class InputButton implements Button {
private BiFunction<@NotNull UUID, @Nullable ItemStack, @Nullable ItemStack> displayItemFunction = (uuid, item) -> item;

@Override
public @Nullable ActionItem getItem(InventoryContext context) {
public @Nullable ActionItem getItem(@NotNull InventoryContext context) {
UUID uuid = context.getViewerID();
return new ActionItem()
.setItem(displayItemFunction.apply(uuid, getInputItem(uuid)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class OutputButton implements Button {
private BiFunction<@NotNull UUID, @Nullable ItemStack, @Nullable ItemStack> displayItemFunction = (uuid, item) -> item;

@Override
public @Nullable ActionItem getItem(InventoryContext context) {
public @Nullable ActionItem getItem(@NotNull InventoryContext context) {
UUID uuid = context.getViewerID();
return new ActionItem()
.setItem(displayItemFunction.apply(uuid, getOutputItem(uuid)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* Contains the pre-made {@link me.hsgamer.hscore.minecraft.gui.button.Button}s for Bukkit
* Contains the pre-made {@link me.hsgamer.hscore.minecraft.gui.common.button.Button}s for Bukkit
*/
package me.hsgamer.hscore.bukkit.gui.button;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Collection;

/**
* The Drag event
* The Bukkit implementation of {@link DragEvent}
*/
public class BukkitDragEvent extends BukkitInventoryEvent<InventoryDragEvent> implements BukkitCancellableEvent, DragEvent {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* The events for the Bukkit GUI
*/
package me.hsgamer.hscore.bukkit.gui.common.event;
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public BukkitInventoryContext(UUID uuid, Inventory inventory) {
this.inventory = inventory;
}

/**
* Get the inventory
*
* @return the inventory
*/
public Inventory getInventory() {
return inventory;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* The package for information about the Bukkit inventory
*/
package me.hsgamer.hscore.bukkit.gui.common.inventory;
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,40 @@
import java.util.UUID;
import java.util.function.BiFunction;

/**
* The {@link GUIHolder} for Bukkit
*/
public class BukkitGUIHolder extends GUIHolder<BukkitInventoryContext> {
private final BiFunction<UUID, BukkitGUIHolder, Inventory> inventoryFunction;
private boolean moveItemOnBottom = false;
private boolean cancelDragEvent = true;

/**
* Create a new holder
*
* @param viewerID the unique ID of the viewer
* @param buttonMap the button map
* @param inventoryFunction the function to create the inventory
*/
public BukkitGUIHolder(UUID viewerID, ButtonMap buttonMap, BiFunction<UUID, BukkitGUIHolder, Inventory> inventoryFunction) {
super(viewerID, buttonMap);
this.inventoryFunction = inventoryFunction;
}

/**
* Set whether to allow moving items in the bottom inventory
*
* @param moveItemOnBottom true to allow
*/
public void setMoveItemOnBottom(boolean moveItemOnBottom) {
this.moveItemOnBottom = moveItemOnBottom;
}

/**
* Set whether to cancel the drag event
*
* @param cancelDragEvent true to cancel
*/
public void setCancelDragEvent(boolean cancelDragEvent) {
this.cancelDragEvent = cancelDragEvent;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* Contains the Bukkit implementation of the {@link me.hsgamer.hscore.minecraft.gui.event}
* Contains the Bukkit implementation of the {@link me.hsgamer.hscore.minecraft.gui.holder.event} package
*/
package me.hsgamer.hscore.bukkit.gui.holder.event;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* Contains the providers for the {@link me.hsgamer.hscore.bukkit.gui.BukkitGUI}
* Contains the listeners for the GUI holder
*/
package me.hsgamer.hscore.bukkit.gui.holder.listener;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* The classes for the holder of the Bukkit GUI
*/
package me.hsgamer.hscore.bukkit.gui.holder;
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private Animation<Button> getAnimation(UUID uuid) {
}

@Override
public @Nullable ActionItem getItem(InventoryContext context) {
public @Nullable ActionItem getItem(@NotNull InventoryContext context) {
return getAnimation(context.getViewerID()).getCurrentFrame().getItem(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void addButton(@NotNull Button... button) {
}

/**
* Should the button keep the current index for the unique id on every {@link #getItem(InventoryContext)} times?
* Should the button keep the current index for the unique id on every {@link Button#getItem(InventoryContext)} times?
*
* @return true if it should
*/
Expand All @@ -46,7 +46,7 @@ public boolean isKeepCurrentIndex() {
}

/**
* Should the button keep the current index for the unique id on every {@link #getItem(InventoryContext)} times?
* Should the button keep the current index for the unique id on every {@link Button#getItem(InventoryContext)} times?
*
* @param keepCurrentIndex true if it should
*/
Expand Down Expand Up @@ -83,7 +83,7 @@ public void stop() {
}

@Override
public @Nullable ActionItem getItem(InventoryContext context) {
public @Nullable ActionItem getItem(@NotNull InventoryContext context) {
UUID uuid = context.getViewerID();
if (keepCurrentIndex && currentIndexMap.containsKey(uuid)) {
return buttons.get(currentIndexMap.get(uuid)).getItem(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void setFallbackButton(@NotNull Button fallbackButton) {
}

@Override
public @Nullable ActionItem getItem(InventoryContext context) {
public @Nullable ActionItem getItem(@NotNull InventoryContext context) {
UUID uuid = context.getViewerID();
ActionItem actionItem;
if (viewPredicate.test(uuid)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public SimpleButton(@Nullable Object item) {
}

@Override
public @NotNull ActionItem getItem(InventoryContext context) {
public @NotNull ActionItem getItem(@NotNull InventoryContext context) {
return new ActionItem()
.setItem(itemFunction.apply(context.getViewerID()))
.setAction(new Action() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* Contains the pre-made {@link me.hsgamer.hscore.minecraft.gui.button.Button}s for UI in Minecraft
* Contains the pre-made {@link me.hsgamer.hscore.minecraft.gui.common.button.Button} for GUI in Minecraft
*/
package me.hsgamer.hscore.minecraft.gui.button;
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,30 @@
import me.hsgamer.hscore.minecraft.gui.common.event.ClickEvent;
import me.hsgamer.hscore.minecraft.gui.common.event.DragEvent;

/**
* The action for the GUI
*/
public interface Action {
/**
* The empty action
*/
Action EMPTY = new Action() {
};

/**
* Handle the click event
*
* @param event the click event
*/
default void handleClick(ClickEvent event) {

}

/**
* Handle the drag event
*
* @param event the drag event
*/
default void handleDrag(DragEvent event) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@
import me.hsgamer.hscore.minecraft.gui.common.event.DragEvent;
import org.jetbrains.annotations.NotNull;

/**
* The delegate action. Used to override / extend the action
*/
public class DelegateAction implements Action {
private final @NotNull Action delegate;

/**
* Create a new delegate action
*
* @param delegate the delegate action
*/
public DelegateAction(@NotNull Action delegate) {
this.delegate = delegate;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Actions for the GUI
*/
package me.hsgamer.hscore.minecraft.gui.common.action;
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,24 @@
import me.hsgamer.hscore.minecraft.gui.common.element.GUIElement;
import me.hsgamer.hscore.minecraft.gui.common.inventory.InventoryContext;
import me.hsgamer.hscore.minecraft.gui.common.item.ActionItem;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* The button
*/
public interface Button extends GUIElement {
/**
* The empty button
*/
Button EMPTY = context -> null;

@Nullable ActionItem getItem(InventoryContext context);
/**
* Get the item
*
* @param context the inventory context
*
* @return the item, or null if it doesn't want to show for any reason
*/
@Nullable ActionItem getItem(@NotNull InventoryContext context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,26 @@
import me.hsgamer.hscore.minecraft.gui.common.element.GUIElement;
import me.hsgamer.hscore.minecraft.gui.common.inventory.InventoryContext;
import me.hsgamer.hscore.minecraft.gui.common.item.ActionItem;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Map;

/**
* The map of buttons
*/
public interface ButtonMap extends GUIElement {
/**
* The empty button map
*/
ButtonMap EMPTY = context -> null;

@Nullable Map<Integer, ActionItem> getItemMap(InventoryContext context);
/**
* Get the item map
*
* @param context the inventory context
*
* @return the item map, or null if it doesn't want to show for any reason
*/
@Nullable Map<Integer, ActionItem> getItemMap(@NotNull InventoryContext context);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* The classes for buttons in the GUI
*/
package me.hsgamer.hscore.minecraft.gui.common.button;
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package me.hsgamer.hscore.minecraft.gui.common.element;

/**
* An element of the GUI
*/
public interface GUIElement {
/**
* Initialize the element. Should be called before adding to the GUI.
*/
default void init() {
}

/**
* Stop the element. Should be called after removing from the GUI.
*/
default void stop() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* The package for the elements of the GUI
*/
package me.hsgamer.hscore.minecraft.gui.common.element;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.hsgamer.hscore.minecraft.gui.common.event;

/**
* The event when a player clicks on the UI
* The event when a player clicks on the GUI
*/
public interface ClickEvent extends ViewerEvent, CancellableEvent {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.util.Collection;

/**
* The event when a player drags on the GUI
*/
public interface DragEvent extends ViewerEvent, CancellableEvent {
/**
* Get the slots that are being dragged
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* Contains the necessary classes for the events in the UI
* Contains the necessary classes for the events in the GUI
*/
package me.hsgamer.hscore.minecraft.gui.common.event;
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,41 @@

import java.util.UUID;

/**
* The context of the inventory
*/
public interface InventoryContext {
/**
* Get the unique ID of the viewer
*
* @return the unique ID of the viewer
*/
UUID getViewerID();

/**
* Get the size of the inventory
*
* @return the size of the inventory
*/
int getSize();

/**
* Get the inventory slot from x and y coordinate
*
* @param x the x coordinate
* @param y the y coordinate
*
* @return the slot
*/
int getSlot(int x, int y);

/**
* Get the inventory slot from the position
*
* @param position the position
*
* @return the slot
*/
default int getSlot(InventoryPosition position) {
return getSlot(position.getX(), position.getY());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* The classes for information about the inventory GUI
*/
package me.hsgamer.hscore.minecraft.gui.common.inventory;
Loading

0 comments on commit 204f19e

Please sign in to comment.