Skip to content

Commit c09f3c6

Browse files
committed
update javadoc with examples
1 parent ff00f55 commit c09f3c6

File tree

30 files changed

+407
-39
lines changed

30 files changed

+407
-39
lines changed

animation/src/main/java/io/github/projectunified/craftux/animation/Animation.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
import java.util.concurrent.atomic.AtomicLong;
66

77
/**
8-
* The animation that gets the frame based on the period
8+
* Manages a sequence of frames that cycle over time with a specified period.
9+
* Provides methods to get the current frame based on elapsed time and reset the animation.
10+
*
11+
* <p>Example usage:</p>
12+
* <pre>{@code
13+
* List<String> frames = Arrays.asList("Frame1", "Frame2", "Frame3");
14+
* Animation<String> animation = new Animation<>(frames, 1000); // 1 second per frame
15+
* String current = animation.getCurrentFrame(); // Gets current frame based on time
16+
* }</pre>
917
*
1018
* @param <T> the frame type
1119
*/
@@ -15,10 +23,11 @@ public class Animation<T> {
1523
private final AtomicLong startMillis = new AtomicLong(-1);
1624

1725
/**
18-
* Create a new animation
26+
* Creates a new Animation with the specified frames and period.
1927
*
20-
* @param frames the frames
21-
* @param periodMillis the period in milliseconds
28+
* @param frames the list of frames to cycle through
29+
* @param periodMillis the period in milliseconds between frame changes
30+
* @throws IllegalArgumentException if frames is empty or periodMillis is not positive
2231
*/
2332
public Animation(List<T> frames, long periodMillis) {
2433
if (frames.isEmpty()) {

button/src/main/java/io/github/projectunified/craftux/button/AnimatedButton.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,28 @@
1010
import java.util.concurrent.ConcurrentHashMap;
1111

1212
/**
13-
* The animated button with child buttons as frames
13+
* A button that cycles through a list of buttons as animation frames over time.
14+
* Each frame is displayed for a configurable period, creating an animated effect.
15+
*
16+
* <p>Example usage:</p>
17+
* <pre>{@code
18+
* AnimatedButton animatedButton = new AnimatedButton();
19+
* animatedButton.addButton(
20+
* new SimpleButton(new ItemStack(Material.DIAMOND)),
21+
* new SimpleButton(new ItemStack(Material.EMERALD))
22+
* );
23+
* animatedButton.setPeriodMillis(100); // 100ms per frame
24+
* }</pre>
1425
*/
1526
public class AnimatedButton extends MultiButton {
1627
private final Map<UUID, Animation<Button>> animationMap = new ConcurrentHashMap<>();
1728
private long periodMillis = 50L;
1829

1930
/**
20-
* Set the period of the animation
31+
* Sets the period of the animation between frame changes.
2132
*
2233
* @param periodMillis the period in milliseconds
34+
* @throws IllegalArgumentException if periodMillis is not positive
2335
*/
2436
public void setPeriodMillis(long periodMillis) {
2537
if (periodMillis <= 0) {

button/src/main/java/io/github/projectunified/craftux/button/ListButton.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,18 @@
99
import java.util.concurrent.ConcurrentHashMap;
1010

1111
/**
12-
* The button that loops through the list of child buttons
12+
* A button that applies actions from a list of child buttons, cycling through them.
13+
* It can optionally remember the current button index per player UUID.
14+
*
15+
* <p>Example usage:</p>
16+
* <pre>{@code
17+
* ListButton listButton = new ListButton();
18+
* listButton.addButton(
19+
* new SimpleButton(new ItemStack(Material.STONE)),
20+
* new SimpleButton(new ItemStack(Material.COBBLESTONE))
21+
* );
22+
* listButton.setKeepCurrentIndex(true); // Remember choice per player
23+
* }</pre>
1324
*/
1425
public class ListButton extends MultiButton {
1526
private final Map<UUID, Integer> currentIndexMap = new ConcurrentHashMap<>();

button/src/main/java/io/github/projectunified/craftux/button/MultiButton.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,18 @@
77
import java.util.*;
88

99
/**
10-
* A base button that handles multiple child buttons
10+
* A base class for buttons that manage multiple child buttons.
11+
* Provides functionality to add, retrieve, and manage lifecycle of child buttons.
12+
*
13+
* <p>Example usage:</p>
14+
* <pre>{@code
15+
* MultiButton multiButton = new MyMultiButton();
16+
* multiButton.addButton(
17+
* new SimpleButton(new ItemStack(Material.RED_WOOL)),
18+
* new SimpleButton(new ItemStack(Material.BLUE_WOOL))
19+
* );
20+
* List<Button> buttons = multiButton.getButtons();
21+
* }</pre>
1122
*/
1223
public abstract class MultiButton implements Element, Button {
1324
protected final List<Button> buttons = new ArrayList<>();

button/src/main/java/io/github/projectunified/craftux/button/PredicateButton.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@
1010
import java.util.function.Predicate;
1111

1212
/**
13-
* The conditional button that chooses a button based on a specific predicate
13+
* A button that conditionally applies actions from one of two buttons based on a predicate
14+
* evaluated against the player's UUID. Uses a fallback button if the predicate fails.
15+
*
16+
* <p>Example usage:</p>
17+
* <pre>{@code
18+
* PredicateButton predicateButton = new PredicateButton();
19+
* predicateButton.setButton(new SimpleButton(new ItemStack(Material.COMMAND_BLOCK)));
20+
* predicateButton.setFallbackButton(new SimpleButton(new ItemStack(Material.CHEST)));
21+
* predicateButton.setViewPredicate(uuid -> isAdmin(uuid)); // Check if player is admin
22+
* }</pre>
1423
*/
1524
public class PredicateButton implements Element, Button {
1625
private @Nullable Button button = null;

common/src/main/java/io/github/projectunified/craftux/common/ActionItem.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@
88
import java.util.function.UnaryOperator;
99

1010
/**
11-
* The action item
11+
* Represents an item with an associated action that can be triggered.
12+
* The item can be of any type, and the action is a Consumer that accepts an event object.
13+
* This class provides methods to set, get, and extend both the item and the action.
14+
*
15+
* <p>Example usage:</p>
16+
* <pre>{@code
17+
* ActionItem actionItem = new ActionItem();
18+
* actionItem.setItem("My Item");
19+
* actionItem.setAction(event -> System.out.println("Clicked: " + event));
20+
* actionItem.callAction("click");
21+
* }</pre>
1222
*/
1323
public final class ActionItem {
1424
private @Nullable Object item;

common/src/main/java/io/github/projectunified/craftux/common/Button.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,20 @@
66
import java.util.function.Consumer;
77

88
/**
9-
* The button
9+
* Represents a button that can apply actions to an ActionItem based on a player's UUID.
10+
* Buttons are used in GUI systems to define interactive elements that respond to player actions.
11+
*
12+
* <p>Example implementation:</p>
13+
* <pre>{@code
14+
* public class MyButton implements Button {
15+
* @Override
16+
* public boolean apply(UUID uuid, ActionItem actionItem) {
17+
* actionItem.setItem("My Button");
18+
* actionItem.setAction(event -> System.out.println("Button clicked by " + uuid));
19+
* return true;
20+
* }
21+
* }
22+
* }</pre>
1023
*/
1124
public interface Button {
1225
/**

common/src/main/java/io/github/projectunified/craftux/common/Element.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,23 @@
44
import java.util.function.Consumer;
55

66
/**
7-
* An element of the GUI
7+
* Represents an element in the GUI that can be initialized and stopped.
8+
* Elements are components that make up the user interface and may require lifecycle management.
9+
*
10+
* <p>Example usage:</p>
11+
* <pre>{@code
12+
* public class MyElement implements Element {
13+
* @Override
14+
* public void init() {
15+
* // Initialize resources
16+
* }
17+
*
18+
* @Override
19+
* public void stop() {
20+
* // Clean up resources
21+
* }
22+
* }
23+
* }</pre>
824
*/
925
public interface Element {
1026
/**

common/src/main/java/io/github/projectunified/craftux/common/Mask.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,23 @@
99
import java.util.stream.Collectors;
1010

1111
/**
12-
* The mask that maps positions to action item consumers
12+
* Represents a mask that maps positions to action item consumers for a given player UUID.
13+
* Masks define the layout and behavior of GUI elements in a grid-based interface.
14+
*
15+
* <p>Example implementation:</p>
16+
* <pre>{@code
17+
* public class MyMask implements Mask {
18+
* @Override
19+
* public Map<Position, Consumer<ActionItem>> apply(UUID uuid) {
20+
* Map<Position, Consumer<ActionItem>> map = new HashMap<>();
21+
* map.put(Position.of(0, 0), actionItem -> {
22+
* actionItem.setItem("Button at 0,0");
23+
* actionItem.setAction(event -> System.out.println("Clicked at 0,0"));
24+
* });
25+
* return map;
26+
* }
27+
* }
28+
* }</pre>
1329
*/
1430
public interface Mask {
1531
/**

common/src/main/java/io/github/projectunified/craftux/common/Position.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
import java.util.Objects;
44

55
/**
6-
* The position
6+
* Represents a 2D position with x and y coordinates in the GUI grid.
7+
* Positions are used to locate elements in the interface.
8+
*
9+
* <p>Example usage:</p>
10+
* <pre>{@code
11+
* Position pos = Position.of(1, 2);
12+
* int x = pos.getX(); // 1
13+
* int y = pos.getY(); // 2
14+
* }</pre>
715
*/
816
public class Position {
917
private final int x;

0 commit comments

Comments
 (0)