|
33 | 33 | import world.bentobox.controlpanel.database.objects.ControlPanelObject.ControlPanelButton; |
34 | 34 | import world.bentobox.controlpanel.panels.GuiUtils; |
35 | 35 | import world.bentobox.controlpanel.utils.Constants; |
| 36 | +import world.bentobox.controlpanel.utils.ItemsAdderParse; |
36 | 37 | import world.bentobox.controlpanel.utils.Utils; |
37 | 38 |
|
38 | 39 |
|
@@ -247,7 +248,6 @@ public void importControlPanels(@Nullable User user, @NotNull GameModeAddon addo |
247 | 248 | * @param user - user |
248 | 249 | * @param gameModeName - gamemode name where ControlPanels must be imported. |
249 | 250 | * @param fileName Specifies from which file control panel will be loaded |
250 | | - * @return true if successful |
251 | 251 | */ |
252 | 252 | private void importControlPanels(@Nullable User user, String gameModeName, @NotNull String fileName) |
253 | 253 | { |
@@ -356,48 +356,53 @@ private void readControlPanel(YamlConfiguration config, @Nullable User user, fin |
356 | 356 | if (buttonListSection != null) |
357 | 357 | { |
358 | 358 | buttonListSection.getKeys(false).forEach(slotReference -> { |
359 | | - ControlPanelButton button = new ControlPanelButton(); |
360 | | - button.setSlot(Integer.parseInt(slotReference)); |
| 359 | + for (int slotNum : Utils.readIntArray(List.of(slotReference))) { |
| 360 | + ControlPanelButton button = new ControlPanelButton(); |
| 361 | + button.setSlot(slotNum); |
361 | 362 |
|
362 | | - ConfigurationSection buttonSection = |
363 | | - buttonListSection.getConfigurationSection(slotReference); |
| 363 | + ConfigurationSection buttonSection = |
| 364 | + buttonListSection.getConfigurationSection(slotReference); |
364 | 365 |
|
365 | | - if (buttonSection != null) |
366 | | - { |
367 | | - button.setName(buttonSection.getString("name")); |
368 | | - button.setCommand(buttonSection.getString("command", "[user_command]")); |
369 | | - |
370 | | - // Create empty list |
371 | | - button.setDescriptionLines(new ArrayList<>()); |
372 | | - |
373 | | - if (buttonSection.isList("description")) |
374 | | - { |
375 | | - // Read description by each line |
376 | | - buttonSection.getStringList("description").forEach(line -> |
377 | | - button.getDescriptionLines().add( |
378 | | - line.replace("[gamemode]", gameMode.toLowerCase()))); |
379 | | - } |
380 | | - else if (buttonSection.isString("description")) |
| 366 | + if (buttonSection != null) |
381 | 367 | { |
382 | | - // Check if description is not defined as simple string |
383 | | - String input = buttonSection.getString("description", ""); |
| 368 | + button.setName(buttonSection.getString("name")); |
| 369 | + button.setCommand(buttonSection.getString("command", "[user_command]")); |
384 | 370 |
|
385 | | - if (input != null && !input.isEmpty()) |
| 371 | + // Create empty list |
| 372 | + button.setDescriptionLines(new ArrayList<>()); |
| 373 | + |
| 374 | + if (buttonSection.isList("description")) |
386 | 375 | { |
387 | | - button.getDescriptionLines().add( |
388 | | - input.replace("[gamemode]", gameMode.toLowerCase())); |
| 376 | + // Read description by each line |
| 377 | + buttonSection.getStringList("description").forEach(line -> |
| 378 | + button.getDescriptionLines().add( |
| 379 | + line.replace("[gamemode]", gameMode.toLowerCase()))); |
| 380 | + } |
| 381 | + else if (buttonSection.isString("description")) |
| 382 | + { |
| 383 | + // Check if description is not defined as simple string |
| 384 | + String input = buttonSection.getString("description", ""); |
| 385 | + |
| 386 | + if (!input.isEmpty()) |
| 387 | + { |
| 388 | + button.getDescriptionLines().add( |
| 389 | + input.replace("[gamemode]", gameMode.toLowerCase())); |
| 390 | + } |
| 391 | + } |
| 392 | + else |
| 393 | + { |
| 394 | + this.addon.logWarning("Description for button " |
| 395 | + + button.getSlot() + " could not be read."); |
389 | 396 | } |
390 | | - } |
391 | | - else |
392 | | - { |
393 | | - this.addon.logWarning("Description for button " + |
394 | | - + button.getSlot() + " could not be read."); |
395 | | - } |
396 | 397 |
|
397 | | - button.setMaterial(Material.matchMaterial(buttonSection.getString("material", "GRASS"))); |
398 | | - button.setIcon(ItemParser.parse("icon", new ItemStack(Material.PAPER))); |
| 398 | + button.setMaterial(Material.matchMaterial(buttonSection.getString("material", "GRASS"))); |
| 399 | + if(buttonSection.getString("icon") != null) |
| 400 | + button.setIcon(ItemParser.parse(buttonSection.getString("icon"), new ItemStack(Material.PAPER))); |
| 401 | + if(buttonSection.getString("itemsadder") != null) |
| 402 | + button.setIcon(ItemsAdderParse.parse(buttonSection.getString("itemsadder"))); |
399 | 403 |
|
400 | | - buttonList.add(button); |
| 404 | + buttonList.add(button); |
| 405 | + } |
401 | 406 | } |
402 | 407 | }); |
403 | 408 | } |
@@ -501,15 +506,15 @@ public ControlPanelObject getUserControlPanel(User user, World world, String per |
501 | 506 | /** |
502 | 507 | * Control Panel Addon instance. |
503 | 508 | */ |
504 | | - private ControlPanelAddon addon; |
| 509 | + private final ControlPanelAddon addon; |
505 | 510 |
|
506 | 511 | /** |
507 | 512 | * This database allows to access to all stored control panels. |
508 | 513 | */ |
509 | | - private Database<ControlPanelObject> controlPanelDatabase; |
| 514 | + private final Database<ControlPanelObject> controlPanelDatabase; |
510 | 515 |
|
511 | 516 | /** |
512 | 517 | * This map contains all control panel object linked to their reference game mode. |
513 | 518 | */ |
514 | | - private Map<String, ControlPanelObject> controlPanelCache; |
| 519 | + private final Map<String, ControlPanelObject> controlPanelCache; |
515 | 520 | } |
0 commit comments