Templated Panel Title Parameters (#1934)

* Implement parameter adding to the templated panel title.

There was an issue when templated panels were always static, and api did not have a way how to change it. This will allow passing parameters to the tile, and allow adding dynamic texts.

* Implement parameter adding to the templated panel title.

There was an issue when templated panels were always static, and api did not have a way how to change it. This will allow passing parameters to the tile, and allow adding dynamic texts.
This commit is contained in:
BONNe 2022-01-29 04:43:14 +02:00 committed by GitHub
parent 178529adb1
commit 90ebe103c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 3 deletions

View File

@ -46,6 +46,8 @@ public class TemplatedPanel extends Panel
this.typeIndex = new HashMap<>(builder.getObjectCreatorMap().size());
this.typeSlotMap = new HashMap<>(builder.getObjectCreatorMap().size());
this.parameters = builder.getParameters().toArray(new String[0]);
if (this.panelTemplate == null)
{
BentoBox.getInstance().logError("Cannot generate panel because template is not loaded.");
@ -69,7 +71,7 @@ public class TemplatedPanel extends Panel
case DROPPER -> this.populateDropperPanel();
};
super.makePanel(this.user.getTranslation(this.panelTemplate.title()),
super.makePanel(this.user.getTranslation(this.panelTemplate.title(), this.parameters),
items,
items.keySet().stream().max(Comparator.naturalOrder()).orElse(9),
this.user,
@ -527,4 +529,10 @@ public class TemplatedPanel extends Panel
* Stores the number of items with given type in whole panel.
*/
private final Map<String, Integer> typeSlotMap;
/**
* Stores the parameters for panel title object.
* @since 1.20.0
*/
private final String[] parameters;
}

View File

@ -8,11 +8,11 @@ package world.bentobox.bentobox.api.panels.builders;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import java.util.function.BiFunction;
import org.bukkit.World;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.PanelListener;
@ -74,6 +74,24 @@ public class TemplatedPanelBuilder
}
/**
* Parameters for title of templated panel.
*
* @param parameters the parameters for title
* @return the templated panel builder
* @since 1.20.0
*/
public TemplatedPanelBuilder parameters(@NonNull String... parameters)
{
if (parameters.length > 0)
{
this.parameters.addAll(Arrays.stream(parameters).toList());
}
return this;
}
/**
* Adds the panel listener for template panel builder.
*
@ -150,6 +168,17 @@ public class TemplatedPanelBuilder
}
/**
* Get title parameters for panel title.
*
* @return the list of parameters for title.
*/
public List<String> getParameters()
{
return this.parameters;
}
/**
* Gets listener.
*
@ -197,6 +226,11 @@ public class TemplatedPanelBuilder
*/
private PanelListener listener;
/**
* The list of parameters for title object.
*/
private final List<String> parameters = new ArrayList<>(0);
/**
* Map that links objects with their panel item creators.
*/