-
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathValuePanel.java
More file actions
819 lines (682 loc) · 27.1 KB
/
ValuePanel.java
File metadata and controls
819 lines (682 loc) · 27.1 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
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
package world.bentobox.level.panels;
import java.io.File;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.Tag;
import org.bukkit.World;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import com.google.common.base.Enums;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.TemplatedPanel;
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
import world.bentobox.bentobox.api.panels.builders.TemplatedPanelBuilder;
import world.bentobox.bentobox.api.panels.reader.ItemTemplateRecord;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.hooks.ItemsAdderHook;
import world.bentobox.bentobox.util.Util;
import world.bentobox.level.Level;
import world.bentobox.level.util.ConversationUtils;
import world.bentobox.level.util.Utils;
/**
* This class opens GUI that shows generator view for user.
*/
public class ValuePanel
{
// ---------------------------------------------------------------------
// Section: Enums
// ---------------------------------------------------------------------
/**
* Sorting order of blocks.
*/
private enum Filter {
/**
* By name asc
*/
NAME_ASC,
/**
* By name desc
*/
NAME_DESC,
/**
* By value asc
*/
VALUE_ASC,
/**
* By value desc
*/
VALUE_DESC,
}
private record BlockRecord(String keyl, Integer value, Integer limit) {
}
// ---------------------------------------------------------------------
// Section: Constants
// ---------------------------------------------------------------------
private static final String BLOCK = "BLOCK";
// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------
/**
* This variable allows to access addon object.
*/
private final Level addon;
/**
* This variable holds user who opens panel. Without it panel cannot be opened.
*/
private final User user;
/**
* This variable holds a world to which gui referee.
*/
private final World world;
/**
* This variable stores the list of elements to display.
*/
private final List<BlockRecord> blockRecordList = new ArrayList<>();
/**
* This variable stores the list of elements to display.
*/
private List<BlockRecord> elementList;
/**
* This variable holds current pageIndex for multi-page generator choosing.
*/
private int pageIndex;
/**
* This variable stores which tab currently is active.
*/
private String searchText;
/**
* This variable stores active filter for items.
*/
private Filter activeFilter;
/**
* This is internal constructor. It is used internally in current class to avoid creating objects everywhere.
*
* @param addon Level object
* @param world World where user is operating
* @param user User who opens panel
*/
private ValuePanel(Level addon,
World world,
User user)
{
this.addon = addon;
this.world = world;
this.user = user;
this.activeFilter = Filter.NAME_ASC;
addon.getBlockConfig().getBlockValues().entrySet().stream()
.filter(en -> this.getIcon(en.getKey()) != null)
.filter(en -> addon.getBlockConfig().isNotHiddenBlock(en.getKey()))
.forEach(en -> blockRecordList
.add(new BlockRecord(en.getKey(), Objects.requireNonNullElse(en.getValue(), 0),
Objects.requireNonNullElse(addon.getBlockConfig().getLimit(en.getKey()), 0))));
this.elementList = new ArrayList<>();
this.searchText = "";
this.updateFilters();
}
/**
* This method builds this GUI.
*/
private void build()
{
// Start building panel.
TemplatedPanelBuilder panelBuilder = new TemplatedPanelBuilder();
panelBuilder.user(this.user);
panelBuilder.world(this.user.getWorld());
panelBuilder.template("value_panel", new File(this.addon.getDataFolder(), "panels"));
panelBuilder.registerTypeBuilder("NEXT", this::createNextButton);
panelBuilder.registerTypeBuilder("PREVIOUS", this::createPreviousButton);
panelBuilder.registerTypeBuilder(BLOCK, this::createMaterialButton);
panelBuilder.registerTypeBuilder("FILTER", this::createFilterButton);
panelBuilder.registerTypeBuilder("SEARCH", this::createSearchButton);
// Register unknown type builder.
panelBuilder.build();
}
/**
* This method updates filter of elements based on tabs.
*/
private void updateFilters()
{
Comparator<BlockRecord> sorter;
switch (this.activeFilter)
{
case VALUE_ASC ->
sorter = (o1, o2) ->
{
if (o1.value().equals(o2.value()))
{
String o1Name = Utils.prettifyObject(o1.keyl(), this.user);
String o2Name = Utils.prettifyObject(o2.keyl(), this.user);
return String.CASE_INSENSITIVE_ORDER.compare(o1Name, o2Name);
}
else
{
return Integer.compare(o1.value(), o2.value());
}
};
case VALUE_DESC ->
sorter = (o1, o2) ->
{
if (o1.value().equals(o2.value()))
{
String o1Name = Utils.prettifyObject(o1.keyl(), this.user);
String o2Name = Utils.prettifyObject(o2.keyl(), this.user);
return String.CASE_INSENSITIVE_ORDER.compare(o1Name, o2Name);
}
else
{
return Integer.compare(o2.value(), o1.value());
}
};
case NAME_DESC ->
sorter = (o1, o2) ->
{
String o1Name = Utils.prettifyObject(o1.keyl(), this.user);
String o2Name = Utils.prettifyObject(o2.keyl(), this.user);
return String.CASE_INSENSITIVE_ORDER.compare(o2Name, o1Name);
};
default ->
sorter = (o1, o2) ->
{
String o1Name = Utils.prettifyObject(o1.keyl(), this.user);
String o2Name = Utils.prettifyObject(o2.keyl(), this.user);
return String.CASE_INSENSITIVE_ORDER.compare(o1Name, o2Name);
};
}
this.blockRecordList.sort(sorter);
if (!this.searchText.isBlank())
{
this.elementList = new ArrayList<>(this.blockRecordList.size());
final String text = this.searchText.toLowerCase();
this.blockRecordList.forEach(rec ->
{
if (rec.keyl.toLowerCase(Locale.ENGLISH).contains(text)
|| Utils.prettifyObject(rec.keyl(), this.user).toLowerCase().contains(text))
{
this.elementList.add(rec);
}
});
}
else
{
this.elementList = this.blockRecordList;
}
this.pageIndex = 0;
}
// ---------------------------------------------------------------------
// Section: Tab Button Type
// ---------------------------------------------------------------------
/**
* Create tab button panel item.
*
* @param template the template
* @param slot the slot
* @return the panel item
*/
private PanelItem createSearchButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot)
{
PanelItemBuilder builder = new PanelItemBuilder();
if (template.icon() != null)
{
// Set icon
builder.icon(template.icon().clone());
}
if (template.title() != null)
{
// Set title
builder.name(this.user.getTranslation(this.world, template.title(), "[text]", this.searchText));
}
if (template.description() != null)
{
// Set description
builder.description(this.user.getTranslation(this.world, template.description(), "[text]", this.searchText));
}
// Get only possible actions, by removing all inactive ones.
List<ItemTemplateRecord.ActionRecords> activeActions = new ArrayList<>(template.actions());
activeActions.removeIf(action ->
"CLEAR".equalsIgnoreCase(action.actionType()) && this.searchText.isBlank());
// Add Click handler
builder.clickHandler((panel, user, clickType, i) ->
{
for (ItemTemplateRecord.ActionRecords action : activeActions)
{
if (clickType == action.clickType() || ClickType.UNKNOWN.equals(action.clickType()))
{
if ("CLEAR".equalsIgnoreCase(action.actionType()))
{
this.searchText = "";
// Update filters.
this.updateFilters();
this.build();
}
else if ("INPUT".equalsIgnoreCase(action.actionType()))
{
// Create consumer that process description change
Consumer<String> consumer = value ->
{
if (value != null)
{
this.searchText = value;
this.updateFilters();
}
this.build();
};
// start conversation
ConversationUtils.createStringInput(consumer,
user,
user.getTranslation("level.conversations.write-search"),
user.getTranslation("level.conversations.search-updated"));
}
}
}
return true;
});
// Collect tooltips.
List<String> tooltips = activeActions.stream().
filter(action -> action.tooltip() != null).
map(action -> this.user.getTranslation(this.world, action.tooltip())).
filter(text -> !text.isBlank()).
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
// Add tooltips.
if (!tooltips.isEmpty())
{
// Empty line and tooltips.
builder.description("");
builder.description(tooltips);
}
builder.glow(!this.searchText.isBlank());
return builder.build();
}
/**
* Create next button panel item.
*
* @param template the template
* @param slot the slot
* @return the panel item
*/
private PanelItem createFilterButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot)
{
PanelItemBuilder builder = new PanelItemBuilder();
if (template.icon() != null)
{
// Set icon
builder.icon(template.icon().clone());
}
String filterName = String.valueOf(template.dataMap().get("filter"));
final String reference = "level.gui.buttons.filters.";
if (template.title() != null)
{
// Set title
builder.name(this.user.getTranslation(this.world, template.title()));
}
else
{
builder.name(this.user.getTranslation(this.world, reference + filterName.toLowerCase() + ".name"));
}
if (template.description() != null)
{
// Set description
builder.description(this.user.getTranslation(this.world, template.description()));
}
else
{
builder.name(this.user.getTranslation(this.world, reference + filterName.toLowerCase() + ".description"));
}
// Get only possible actions, by removing all inactive ones.
List<ItemTemplateRecord.ActionRecords> activeActions = new ArrayList<>(template.actions());
activeActions.removeIf(action -> {
if (this.activeFilter.name().startsWith(filterName))
{
return this.activeFilter.name().endsWith("ASC") && "ASC".equalsIgnoreCase(action.actionType()) ||
this.activeFilter.name().endsWith("DESC") && "DESC".equalsIgnoreCase(action.actionType());
}
else
{
return "DESC".equalsIgnoreCase(action.actionType());
}
});
// Add Click handler
builder.clickHandler((panel, user, clickType, i) ->
{
for (ItemTemplateRecord.ActionRecords action : activeActions)
{
if (clickType == action.clickType() || ClickType.UNKNOWN.equals(action.clickType()))
{
if ("ASC".equalsIgnoreCase(action.actionType()))
{
this.activeFilter = Enums.getIfPresent(Filter.class, filterName + "_ASC").or(Filter.NAME_ASC);
// Update filters.
this.updateFilters();
this.build();
}
else if ("DESC".equalsIgnoreCase(action.actionType()))
{
this.activeFilter = Enums.getIfPresent(Filter.class, filterName + "_DESC").or(Filter.NAME_DESC);
// Update filters.
this.updateFilters();
this.build();
}
}
}
return true;
});
// Collect tooltips.
List<String> tooltips = activeActions.stream().
filter(action -> action.tooltip() != null).
map(action -> this.user.getTranslation(this.world, action.tooltip())).
filter(text -> !text.isBlank()).
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
// Add tooltips.
if (!tooltips.isEmpty())
{
// Empty line and tooltips.
builder.description("");
builder.description(tooltips);
}
builder.glow(this.activeFilter.name().startsWith(filterName.toUpperCase()));
return builder.build();
}
// ---------------------------------------------------------------------
// Section: Create common buttons
// ---------------------------------------------------------------------
/**
* Create next button panel item.
*
* @param template the template
* @param slot the slot
* @return the panel item
*/
private PanelItem createNextButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot)
{
long size = this.elementList.size();
if (size <= slot.amountMap().getOrDefault(BLOCK, 1) ||
1.0 * size / slot.amountMap().getOrDefault(BLOCK, 1) <= this.pageIndex + 1)
{
// There are no next elements
return null;
}
int nextPageIndex = this.pageIndex + 2;
PanelItemBuilder builder = new PanelItemBuilder();
if (template.icon() != null)
{
ItemStack clone = template.icon().clone();
if (Boolean.TRUE.equals(template.dataMap().getOrDefault("indexing", false)))
{
clone.setAmount(nextPageIndex);
}
builder.icon(clone);
}
if (template.title() != null)
{
builder.name(this.user.getTranslation(this.world, template.title()));
}
if (template.description() != null)
{
builder.description(this.user.getTranslation(this.world, template.description(),
TextVariables.NUMBER, String.valueOf(nextPageIndex)));
}
// Add ClickHandler
builder.clickHandler((panel, user, clickType, i) ->
{
for (ItemTemplateRecord.ActionRecords action : template.actions())
{
if ((clickType == action.clickType() || ClickType.UNKNOWN.equals(action.clickType()))
&& "NEXT".equalsIgnoreCase(action.actionType()))
{
this.pageIndex++;
this.build();
}
}
// Always return true.
return true;
});
// Collect tooltips.
List<String> tooltips = template.actions().stream().
filter(action -> action.tooltip() != null).
map(action -> this.user.getTranslation(this.world, action.tooltip())).
filter(text -> !text.isBlank()).
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
// Add tooltips.
if (!tooltips.isEmpty())
{
// Empty line and tooltips.
builder.description("");
builder.description(tooltips);
}
return builder.build();
}
/**
* Create previous button panel item.
*
* @param template the template
* @param slot the slot
* @return the panel item
*/
private PanelItem createPreviousButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot)
{
if (this.pageIndex == 0)
{
// There are no next elements
return null;
}
int previousPageIndex = this.pageIndex;
PanelItemBuilder builder = new PanelItemBuilder();
if (template.icon() != null)
{
ItemStack clone = template.icon().clone();
if (Boolean.TRUE.equals(template.dataMap().getOrDefault("indexing", false)))
{
clone.setAmount(previousPageIndex);
}
builder.icon(clone);
}
if (template.title() != null)
{
builder.name(this.user.getTranslation(this.world, template.title()));
}
if (template.description() != null)
{
builder.description(this.user.getTranslation(this.world, template.description(),
TextVariables.NUMBER, String.valueOf(previousPageIndex)));
}
// Add ClickHandler
builder.clickHandler((panel, user, clickType, i) ->
{
for (ItemTemplateRecord.ActionRecords action : template.actions())
{
if ((clickType == action.clickType() || ClickType.UNKNOWN.equals(action.clickType()))
&& "PREVIOUS".equalsIgnoreCase(action.actionType()))
{
this.pageIndex--;
this.build();
}
}
// Always return true.
return true;
});
// Collect tooltips.
List<String> tooltips = template.actions().stream().
filter(action -> action.tooltip() != null).
map(action -> this.user.getTranslation(this.world, action.tooltip())).
filter(text -> !text.isBlank()).
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
// Add tooltips.
if (!tooltips.isEmpty())
{
// Empty line and tooltips.
builder.description("");
builder.description(tooltips);
}
return builder.build();
}
// ---------------------------------------------------------------------
// Section: Create Material Button
// ---------------------------------------------------------------------
/**
* Create material button panel item.
*
* @param template the template
* @param slot the slot
* @return the panel item
*/
private PanelItem createMaterialButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot)
{
if (this.elementList.isEmpty())
{
// Does not contain any.
return null;
}
int index = this.pageIndex * slot.amountMap().getOrDefault(BLOCK, 1) + slot.slot();
if (index >= this.elementList.size())
{
// Out of index.
return null;
}
return this.createMaterialButton(template, this.elementList.get(index));
}
private Material getIcon(String key) {
// Filter out some names
key = key.replaceAll("wall_", "");
key = key.replaceAll("_hanging", "");
Material icon = Registry.MATERIAL.get(NamespacedKey.fromString(key));
if (icon == null && key.endsWith("_spawner")) {
icon = Registry.MATERIAL.get(NamespacedKey.fromString(key.substring(0, key.length() - 2) + "_egg"));
}
// ItemsAdder
if (icon == null && addon.isItemsAdder() && ItemsAdderHook.isInRegistry(key)) {
icon = ItemsAdderHook.getItemStack(key).map(ItemStack::getType).orElse(null);
}
if (icon != null && icon.isItem()) {
return icon;
}
// Not an item, but maybe still something
if (icon != null) {
switch (icon) {
case BUBBLE_COLUMN: return Material.WATER_BUCKET;
case NETHER_PORTAL: return Material.PURPLE_STAINED_GLASS_PANE;
case END_GATEWAY: return Material.BLACK_STAINED_GLASS_PANE;
case END_PORTAL: return Material.BLACK_STAINED_GLASS_PANE;
case SOUL_FIRE: return Material.SOUL_TORCH;
case WALL_TORCH: return Material.TORCH;
case TWISTING_VINES_PLANT: return Material.VINE;
case CAVE_VINES_PLANT: return Material.VINE;
case BAMBOO_SAPLING: return Material.BAMBOO;
case KELP_PLANT: return Material.KELP;
case SWEET_BERRY_BUSH: return Material.SWEET_BERRIES;
case LAVA, FIRE: return Material.LAVA_BUCKET;
case PISTON_HEAD: return Material.PISTON;
case REDSTONE_WIRE: return Material.REDSTONE;
case TORCHFLOWER_CROP: return Material.TORCHFLOWER_SEEDS;
case TALL_SEAGRASS: return Material.SEAGRASS;
case WATER: return Material.WATER_BUCKET;
case VOID_AIR: return Material.BARRIER;
case COCOA: return Material.COCOA_BEANS;
case TRIPWIRE: return Material.TRIPWIRE_HOOK;
case BEETROOTS: return Material.BEETROOT_SEEDS;
case POTATOES: return Material.POTATO;
case CARROTS: return Material.CARROT;
case PITCHER_CROP: return Material.PITCHER_POD;
case BIG_DRIPLEAF_STEM: return Material.BIG_DRIPLEAF;
default: {}
}
if (Tag.FLOWER_POTS.isTagged(icon)) {
return Material.FLOWER_POT;
}
if (Tag.WALL_SIGNS.isTagged(icon) || Tag.ALL_HANGING_SIGNS.isTagged(icon)) {
return Material.OAK_SIGN;
}
if (Tag.CANDLE_CAKES.isTagged(icon)) {
return Material.CAKE;
}
if (Tag.CAULDRONS.isTagged(icon)) {
return Material.CAULDRON;
}
if (Tag.ICE.isTagged(icon)) {
return Material.ICE;
}
}
// Try Oraxen
if (key.startsWith("oraxen:") && BentoBox.getInstance().getHooks().getHook("Oraxen").isPresent()) {
return Material.PAPER;
}
return null;
}
/**
* Creates a material button based on the provided template and block record.
*
* @param template The button template.
* @param blockCount The block record containing count details.
* @return The created PanelItem button.
*/
private PanelItem createMaterialButton(ItemTemplateRecord template, BlockRecord blockCount) {
PanelItemBuilder builder = new PanelItemBuilder();
final String baseKey = "level.gui.buttons.material.";
// Extract values from blockCount
String key = blockCount.keyl();
int blockValue = blockCount.value();
int blockLimit = blockCount.limit();
double underwaterMultiplier = this.addon.getSettings().getUnderWaterMultiplier();
// Build translation strings
String blockId = user.isOp() ? this.user.getTranslationOrNothing(baseKey + "id", "[id]", key) : "";
String description = Utils.prettifyDescription(key, this.user);
String valueTranslation = this.user.getTranslationOrNothing(baseKey + "value", TextVariables.NUMBER,
String.valueOf(blockValue));
String limitTranslation = blockLimit > 0
? this.user.getTranslationOrNothing(baseKey + "limit", TextVariables.NUMBER, String.valueOf(blockLimit))
: "";
// Determine icon and display material text
Material icon = getIcon(key);
builder.icon((icon == null || icon == Material.AIR) ? Material.PAPER : icon);
if (key.startsWith("oraxen:")) {
key = key.substring(7);
}
String displayMaterial = (icon == null) ? Util.prettifyText(key) : Utils.prettifyObject(key, user);
// Special handling for spawn eggs
if (icon != null && icon.name().endsWith("_SPAWN_EGG")) {
displayMaterial = Util.prettifyText(key);
}
// Set button title if available
if (template.title() != null) {
builder.name(this.user.getTranslation(this.world, template.title(), TextVariables.NUMBER,
String.valueOf(blockValue), "[material]", displayMaterial));
}
// Calculate underwater value if applicable
String underWater = underwaterMultiplier != 1.0 ? this.user.getTranslationOrNothing(baseKey + "underwater",
TextVariables.NUMBER, String.valueOf(blockValue * underwaterMultiplier)) : "";
// Set button description if provided
if (template.description() != null) {
String translatedDescription = this.user
.getTranslation(this.world, template.description(), "[description]", description, "[id]", blockId,
"[value]", valueTranslation, "[underwater]", underWater, "[limit]", limitTranslation)
.replaceAll("(?m)^[ \\t]*\\r?\\n", "").replaceAll("(?<!\\\\)\\|", "\n").replace("\\\\\\|", "|");
builder.description(translatedDescription);
}
return builder.build();
}
// ---------------------------------------------------------------------
// Section: Other Methods
// ---------------------------------------------------------------------
/**
* This method is used to open UserPanel outside this class. It will be much easier to open panel with single method
* call then initializing new object.
*
* @param addon Level object
* @param world World where user is operating
* @param user User who opens panel
*/
public static void openPanel(Level addon,
World world,
User user)
{
new ValuePanel(addon, world, user).build();
}
}