Skip to content

Commit 9f06bba

Browse files
committed
remove click predicate in PredicateButton
It's too bloated for a predicate button
1 parent 6ef8a16 commit 9f06bba

File tree

1 file changed

+2
-79
lines changed

1 file changed

+2
-79
lines changed

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

Lines changed: 2 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77
import org.jetbrains.annotations.Nullable;
88

99
import java.util.UUID;
10-
import java.util.function.BiPredicate;
1110
import java.util.function.Predicate;
1211

1312
/**
14-
* The button with predicates
13+
* The conditional button that chooses a button based on a specific predicate
1514
*/
1615
public class PredicateButton implements Element, Button {
1716
private @Nullable Button button = null;
1817
private @Nullable Button fallbackButton = null;
1918
private @Nullable Predicate<UUID> viewPredicate = null;
20-
private @Nullable Predicate<Object> actionPredicate = null;
2119

2220
/**
2321
* Get the view predicate
@@ -37,71 +35,6 @@ public void setViewPredicate(@NotNull Predicate<@NotNull UUID> viewPredicate) {
3735
this.viewPredicate = viewPredicate;
3836
}
3937

40-
/**
41-
* Get the action predicate
42-
*
43-
* @return the action predicate
44-
*/
45-
public @Nullable Predicate<@NotNull Object> getActionPredicate() {
46-
return actionPredicate;
47-
}
48-
49-
/**
50-
* Set the action predicate
51-
*
52-
* @param actionPredicate the action predicate
53-
*/
54-
public void setActionPredicate(@Nullable Predicate<@NotNull Object> actionPredicate) {
55-
this.actionPredicate = actionPredicate;
56-
}
57-
58-
/**
59-
* Set the action predicate for a specific event class
60-
*
61-
* @param eventClass the event class
62-
* @param actionPredicate the action predicate
63-
* @param <E> the event type
64-
*/
65-
public <E> void setActionPredicate(@NotNull Class<E> eventClass, @NotNull Predicate<@NotNull E> actionPredicate) {
66-
Predicate<Object> oldActionPredicate = this.actionPredicate;
67-
this.actionPredicate = event -> {
68-
if (eventClass.isInstance(event) && !actionPredicate.test(eventClass.cast(event))) {
69-
return false;
70-
}
71-
return oldActionPredicate == null || oldActionPredicate.test(event);
72-
};
73-
}
74-
75-
/**
76-
* Expand the action predicate
77-
*
78-
* @param actionPredicate the action predicate
79-
*/
80-
public void expandActionPredicate(@NotNull BiPredicate<@NotNull Object, @Nullable Predicate<Object>> actionPredicate) {
81-
Predicate<Object> oldActionPredicate = this.actionPredicate;
82-
this.actionPredicate = event -> actionPredicate.test(event, oldActionPredicate);
83-
}
84-
85-
/**
86-
* Expand the action predicate for a specific event class
87-
*
88-
* @param eventClass the event class
89-
* @param actionPredicate the action predicate
90-
* @param <E> the event type
91-
*/
92-
public <E> void expandActionPredicate(@NotNull Class<E> eventClass, @NotNull BiPredicate<@NotNull E, @Nullable Predicate<Object>> actionPredicate) {
93-
Predicate<Object> oldActionPredicate = this.actionPredicate;
94-
this.actionPredicate = event -> {
95-
if (eventClass.isInstance(event)) {
96-
if (!actionPredicate.test(eventClass.cast(event), oldActionPredicate)) {
97-
return false;
98-
}
99-
}
100-
return oldActionPredicate == null || oldActionPredicate.test(event);
101-
};
102-
}
103-
104-
10538
/**
10639
* Get the button
10740
*
@@ -144,17 +77,7 @@ public boolean apply(@NotNull UUID uuid, @NotNull ActionItem actionItem) {
14477
if (buttonToUse == null) {
14578
return false;
14679
}
147-
148-
boolean result = buttonToUse.apply(uuid, actionItem);
149-
if (actionPredicate != null) {
150-
actionItem.extendAction((event, action) -> {
151-
if (actionPredicate.test(event)) {
152-
action.accept(event);
153-
}
154-
});
155-
return true;
156-
}
157-
return result;
80+
return buttonToUse.apply(uuid, actionItem);
15881
}
15982

16083
@Override

0 commit comments

Comments
 (0)