mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-27 09:42:46 +01:00
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:
parent
178529adb1
commit
90ebe103c4
@ -46,6 +46,8 @@ public class TemplatedPanel extends Panel
|
|||||||
this.typeIndex = new HashMap<>(builder.getObjectCreatorMap().size());
|
this.typeIndex = new HashMap<>(builder.getObjectCreatorMap().size());
|
||||||
this.typeSlotMap = new HashMap<>(builder.getObjectCreatorMap().size());
|
this.typeSlotMap = new HashMap<>(builder.getObjectCreatorMap().size());
|
||||||
|
|
||||||
|
this.parameters = builder.getParameters().toArray(new String[0]);
|
||||||
|
|
||||||
if (this.panelTemplate == null)
|
if (this.panelTemplate == null)
|
||||||
{
|
{
|
||||||
BentoBox.getInstance().logError("Cannot generate panel because template is not loaded.");
|
BentoBox.getInstance().logError("Cannot generate panel because template is not loaded.");
|
||||||
@ -69,7 +71,7 @@ public class TemplatedPanel extends Panel
|
|||||||
case DROPPER -> this.populateDropperPanel();
|
case DROPPER -> this.populateDropperPanel();
|
||||||
};
|
};
|
||||||
|
|
||||||
super.makePanel(this.user.getTranslation(this.panelTemplate.title()),
|
super.makePanel(this.user.getTranslation(this.panelTemplate.title(), this.parameters),
|
||||||
items,
|
items,
|
||||||
items.keySet().stream().max(Comparator.naturalOrder()).orElse(9),
|
items.keySet().stream().max(Comparator.naturalOrder()).orElse(9),
|
||||||
this.user,
|
this.user,
|
||||||
@ -527,4 +529,10 @@ public class TemplatedPanel extends Panel
|
|||||||
* Stores the number of items with given type in whole panel.
|
* Stores the number of items with given type in whole panel.
|
||||||
*/
|
*/
|
||||||
private final Map<String, Integer> typeSlotMap;
|
private final Map<String, Integer> typeSlotMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the parameters for panel title object.
|
||||||
|
* @since 1.20.0
|
||||||
|
*/
|
||||||
|
private final String[] parameters;
|
||||||
}
|
}
|
||||||
|
@ -8,11 +8,11 @@ package world.bentobox.bentobox.api.panels.builders;
|
|||||||
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||||
import world.bentobox.bentobox.api.panels.PanelListener;
|
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.
|
* 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.
|
* Gets listener.
|
||||||
*
|
*
|
||||||
@ -197,6 +226,11 @@ public class TemplatedPanelBuilder
|
|||||||
*/
|
*/
|
||||||
private PanelListener listener;
|
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.
|
* Map that links objects with their panel item creators.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user