-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathButtonStateDefault.java
More file actions
97 lines (80 loc) · 3.47 KB
/
ButtonStateDefault.java
File metadata and controls
97 lines (80 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* WolfyUtilities, APIs and Utilities for Minecraft Spigot plugins
* Copyright (C) 2021 WolfyScript
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.wolfyscript.utilities.common.gui;
import com.google.common.base.Preconditions;
import com.wolfyscript.utilities.common.gui.callback.InteractionCallback;
import com.wolfyscript.utilities.common.gui.callback.RenderCallback;
import com.wolfyscript.utilities.common.gui.components.ButtonState;
import java.util.Objects;
public class ButtonStateDefault implements ButtonState {
private final String key;
private final InteractionCallback interactionCallback;
private final RenderCallback renderCallback;
protected ButtonStateDefault(String key, InteractionCallback interactionCallback, RenderCallback renderCallback) {
this.key = key;
this.interactionCallback = interactionCallback;
this.renderCallback = renderCallback;
}
@Override
public InteractionCallback interactCallback() {
return interactionCallback;
}
@Override
public RenderCallback renderCallback() {
return renderCallback;
}
@Override
public String key() {
return key;
}
public static class Builder implements ButtonState.Builder<ButtonState> {
private String key;
private InteractionCallback interactionCallback;
private RenderCallback renderCallback;
protected Builder(String ownerID) {
this.key = ownerID;
}
@Override
public Builder subKey(String subKey) {
this.key += "." + subKey;
return this;
}
@Override
public Builder key(String key) {
this.key = key;
return this;
}
@Override
public Builder interact(InteractionCallback interactionCallback) {
this.interactionCallback = interactionCallback;
return this;
}
@Override
public Builder render(RenderCallback renderCallback) {
this.renderCallback = renderCallback;
return null;
}
@Override
public ButtonStateDefault create() {
Preconditions.checkNotNull(renderCallback, "Cannot create Component without a RenderCallback!");
final var interactCallback = Objects.requireNonNullElseGet(this.interactionCallback, () -> (holder, details) -> InteractionResult.def());
final var renderCallback = Objects.requireNonNullElseGet(this.renderCallback, () -> (holder) -> {});
return new ButtonStateDefault(key, interactCallback, renderCallback);
}
}
}