-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
TemplatedPanelBuilder.java
204 lines (165 loc) · 4.41 KB
/
TemplatedPanelBuilder.java
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
//
// Created by BONNe
// Copyright - 2021
//
package world.bentobox.bentobox.api.panels.builders;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiFunction;
import org.bukkit.World;
import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.PanelListener;
import world.bentobox.bentobox.api.panels.TemplatedPanel;
import world.bentobox.bentobox.api.panels.reader.ItemTemplateRecord;
import world.bentobox.bentobox.api.panels.reader.PanelTemplateRecord;
import world.bentobox.bentobox.api.panels.reader.TemplateReader;
import world.bentobox.bentobox.api.user.User;
/**
* Builds {@link TemplatedPanel}'s
* @author BONNe
* @since 1.17.3
*/
public class TemplatedPanelBuilder
{
// ---------------------------------------------------------------------
// Section: Builder
// ---------------------------------------------------------------------
/**
* Adds the template that must be loaded for Template panel builder.
*
* @param guiName the gui name
* @param dataFolder the data folder
* @return the template panel builder
*/
public TemplatedPanelBuilder template(String guiName, File dataFolder)
{
this.panelTemplate = TemplateReader.readTemplatePanel(guiName, dataFolder);
return this;
}
/**
* Adds the user for template panel builder.
*
* @param user the user
* @return the template panel builder
*/
public TemplatedPanelBuilder user(User user)
{
this.user = user;
return this;
}
/**
* Adds the world for template panel builder.
*
* @param world the world
* @return the template panel builder
*/
public TemplatedPanelBuilder world(World world)
{
this.world = world;
return this;
}
/**
* Adds the panel listener for template panel builder.
*
* @param listener the listener
* @return the template panel builder
*/
public TemplatedPanelBuilder listener(PanelListener listener)
{
this.listener = listener;
return this;
}
/**
* Registers new button type builder for template panel builder.
*
* @param type the type
* @param buttonCreator the button creator
* @return the template panel builder
*/
public TemplatedPanelBuilder registerTypeBuilder(String type, BiFunction<ItemTemplateRecord, TemplatedPanel.ItemSlot, PanelItem> buttonCreator)
{
this.objectCreatorMap.put(type, buttonCreator);
return this;
}
/**
* Build templated panel.
*
* @return the templated panel
*/
public TemplatedPanel build()
{
return new TemplatedPanel(this);
}
// ---------------------------------------------------------------------
// Section: Getters
// ---------------------------------------------------------------------
/**
* Gets panel template.
*
* @return the panel template
*/
public PanelTemplateRecord getPanelTemplate()
{
return this.panelTemplate;
}
/**
* Gets user.
*
* @return the user
*/
public User getUser()
{
return this.user;
}
/**
* Gets world.
*
* @return the world
*/
public World getWorld()
{
return this.world;
}
/**
* Gets listener.
*
* @return the listener
*/
public PanelListener getListener()
{
return this.listener;
}
/**
* Gets object creator map.
*
* @return the object creator map
*/
public Map<String, BiFunction<ItemTemplateRecord, TemplatedPanel.ItemSlot, PanelItem>> getObjectCreatorMap()
{
return this.objectCreatorMap;
}
// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------
/**
* The GUI template record.
*/
private PanelTemplateRecord panelTemplate;
/**
* The user who opens the GUI.
*/
private User user;
/**
* The world where GUI operates.
*/
private World world;
/**
* Panel Listener
*/
private PanelListener listener;
/**
* Map that links objects with their panel item creators.
*/
private final Map<String, BiFunction<ItemTemplateRecord, TemplatedPanel.ItemSlot, PanelItem>> objectCreatorMap = new HashMap<>();
}