mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Add display item for group and order them in create order
This commit is contained in:
parent
41235d3024
commit
e99fd4d640
5 changed files with 76 additions and 28 deletions
|
|
@ -19,10 +19,7 @@ import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
|||
import xyz.alexcrea.cuanvil.gui.config.SelectGroupContainer;
|
||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class GroupSelectSettingGui extends AbstractSettingGui{
|
||||
|
|
@ -30,7 +27,7 @@ public class GroupSelectSettingGui extends AbstractSettingGui{
|
|||
SelectGroupContainer groupContainer;
|
||||
int page;
|
||||
|
||||
HashSet<AbstractMaterialGroup> selectedGroups;
|
||||
Set<AbstractMaterialGroup> selectedGroups;
|
||||
|
||||
public GroupSelectSettingGui(@NotNull String title, ValueUpdatableGui parent, SelectGroupContainer groupContainer, int page) {
|
||||
super(6, title, parent);
|
||||
|
|
@ -63,13 +60,13 @@ public class GroupSelectSettingGui extends AbstractSettingGui{
|
|||
filledEnchant.setOrientation(Orientable.Orientation.HORIZONTAL);
|
||||
|
||||
Set<AbstractMaterialGroup> illegalGroup = this.groupContainer.illegalGroups();
|
||||
ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().forEach((name, group)->{
|
||||
for (AbstractMaterialGroup group : ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values()) {
|
||||
if(illegalGroup.contains(group)) {
|
||||
return;
|
||||
}
|
||||
filledEnchant.addItem(getGuiItemFromGroup(group));
|
||||
}
|
||||
|
||||
});
|
||||
addPane(filledEnchant);
|
||||
|
||||
}
|
||||
|
|
@ -77,7 +74,7 @@ public class GroupSelectSettingGui extends AbstractSettingGui{
|
|||
private GuiItem getGuiItemFromGroup(AbstractMaterialGroup group){
|
||||
boolean isIn = this.selectedGroups.contains(group);
|
||||
|
||||
Material usedMaterial = Material.PAPER;
|
||||
Material usedMaterial = group.getRepresentativeMaterial();
|
||||
ItemStack item = new ItemStack(usedMaterial);
|
||||
|
||||
setGroupItemMeta(item, group.getName(), isIn);
|
||||
|
|
@ -93,6 +90,14 @@ public class GroupSelectSettingGui extends AbstractSettingGui{
|
|||
public void setGroupItemMeta(ItemStack item, String name, boolean isIn){
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
if(meta == null){
|
||||
CustomAnvil.instance.getLogger().warning("Could not create item for group: "+name+":\n" +
|
||||
"Item do not gave item meta: "+item+". Using placeholder instead");
|
||||
item.setType(Material.PAPER);
|
||||
meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
}
|
||||
|
||||
meta.setDisplayName("\u00A7"+(isIn ? 'a' : 'c')+ CasedStringUtil.snakeToUpperSpacedCase(name));
|
||||
if(isIn){
|
||||
meta.addEnchant(Enchantment.DAMAGE_UNDEAD, 1, true);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import java.util.*
|
|||
|
||||
abstract class AbstractMaterialGroup(private val name: String) {
|
||||
protected val includedMaterial by lazy {createDefaultSet()}
|
||||
protected var groupChangeNotified = false
|
||||
|
||||
/**
|
||||
* Get the group default set
|
||||
|
|
@ -15,7 +14,7 @@ abstract class AbstractMaterialGroup(private val name: String) {
|
|||
/**
|
||||
* Get if a material is allowed following the group policy
|
||||
*/
|
||||
fun contain(mat : Material): Boolean {
|
||||
open fun contain(mat : Material): Boolean {
|
||||
return mat in includedMaterial
|
||||
}
|
||||
|
||||
|
|
@ -35,14 +34,28 @@ abstract class AbstractMaterialGroup(private val name: String) {
|
|||
abstract fun addToPolicy(other : AbstractMaterialGroup)
|
||||
|
||||
/**
|
||||
* Get the group as a set
|
||||
* Get the group contained material as a set
|
||||
*/
|
||||
abstract fun getMaterials(): MutableSet<Material>
|
||||
abstract fun getMaterials(): EnumSet<Material>
|
||||
|
||||
/**
|
||||
* Get the group non-inherited material as a set
|
||||
*/
|
||||
open fun getNonGroupInheritedMaterials(): EnumSet<Material> {
|
||||
return includedMaterial
|
||||
}
|
||||
/**
|
||||
* Get the group non-inherited material as a set
|
||||
*/
|
||||
open fun setNonGroupInheritedMaterials(materials: EnumSet<Material>) {
|
||||
this.includedMaterial.clear()
|
||||
this.includedMaterial.addAll(materials)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the group name in case something is wrong
|
||||
*/
|
||||
fun getName(): String {
|
||||
open fun getName(): String {
|
||||
return name
|
||||
}
|
||||
|
||||
|
|
@ -56,4 +69,22 @@ abstract class AbstractMaterialGroup(private val name: String) {
|
|||
*/
|
||||
abstract fun getGroups(): MutableSet<AbstractMaterialGroup>
|
||||
|
||||
open fun getRepresentativeMaterial() : Material {
|
||||
// Test inner material
|
||||
val matIterator = includedMaterial.iterator()
|
||||
while(matIterator.hasNext()){
|
||||
val material = matIterator.next();
|
||||
if(material.isAir) continue
|
||||
return material;
|
||||
}
|
||||
// Test included group representative material
|
||||
val groupIterator = getGroups().iterator()
|
||||
while (groupIterator.hasNext()){
|
||||
val groupMat = groupIterator.next().getRepresentativeMaterial()
|
||||
if(groupMat.isAir) continue
|
||||
return groupMat;
|
||||
}
|
||||
return Material.PAPER;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ class ExcludeGroup(name: String): AbstractMaterialGroup(name) {
|
|||
}
|
||||
|
||||
private var includedGroup: MutableSet<AbstractMaterialGroup> = HashSet()
|
||||
private val groupItems: MutableSet<Material> by lazy {createDefaultSet()}
|
||||
private val groupItems by lazy {createDefaultSet()}
|
||||
|
||||
override fun isReferencing(other: AbstractMaterialGroup): Boolean {
|
||||
for (materialGroup in includedGroup.iterator()) {
|
||||
|
|
@ -27,28 +27,28 @@ class ExcludeGroup(name: String): AbstractMaterialGroup(name) {
|
|||
|
||||
override fun addToPolicy(other: AbstractMaterialGroup) {
|
||||
includedGroup.add(other)
|
||||
groupItems.removeAll(other.getMaterials());
|
||||
groupItems.removeAll(other.getMaterials())
|
||||
}
|
||||
|
||||
override fun setGroups(groups: MutableSet<AbstractMaterialGroup>) {
|
||||
groupItems.clear()
|
||||
groupItems.addAll(includedMaterial)
|
||||
|
||||
includedGroup.clear();
|
||||
includedGroup.clear()
|
||||
groups.forEach { group ->
|
||||
if(!group.isReferencing(this)) {
|
||||
includedGroup.add(group);
|
||||
includedGroup.add(group)
|
||||
groupItems.removeAll(group.getMaterials())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getGroups(): MutableSet<AbstractMaterialGroup> {
|
||||
return includedGroup;
|
||||
return includedGroup
|
||||
}
|
||||
|
||||
override fun getMaterials(): MutableSet<Material> {
|
||||
return groupItems;
|
||||
override fun getMaterials(): EnumSet<Material> {
|
||||
return groupItems
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class IncludeGroup(name: String): AbstractMaterialGroup(name) {
|
|||
}
|
||||
|
||||
private var includedGroup: MutableSet<AbstractMaterialGroup> = HashSet()
|
||||
private val groupItems: MutableSet<Material> by lazy {createDefaultSet()}
|
||||
private val groupItems by lazy {createDefaultSet()}
|
||||
|
||||
override fun isReferencing(other: AbstractMaterialGroup): Boolean {
|
||||
for (materialGroup in includedGroup.iterator()) {
|
||||
|
|
@ -27,27 +27,38 @@ class IncludeGroup(name: String): AbstractMaterialGroup(name) {
|
|||
|
||||
override fun addToPolicy(other: AbstractMaterialGroup) {
|
||||
includedGroup.add(other)
|
||||
groupItems.addAll(other.getMaterials());
|
||||
groupItems.addAll(other.getMaterials())
|
||||
}
|
||||
|
||||
override fun setGroups(groups: MutableSet<AbstractMaterialGroup>) {
|
||||
groupItems.clear();
|
||||
groupItems.clear()
|
||||
groupItems.addAll(includedMaterial)
|
||||
|
||||
includedGroup.clear();
|
||||
includedGroup.clear()
|
||||
groups.forEach { group ->
|
||||
if(!group.isReferencing(this)){
|
||||
includedGroup.add(group);
|
||||
includedGroup.add(group)
|
||||
groupItems.addAll(group.getMaterials())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun setNonGroupInheritedMaterials(materials: EnumSet<Material>) {
|
||||
super.setNonGroupInheritedMaterials(materials)
|
||||
// Update group items
|
||||
groupItems.clear()
|
||||
groupItems.addAll(includedMaterial)
|
||||
|
||||
includedGroup.forEach { group ->
|
||||
groupItems.addAll(group.getMaterials())
|
||||
}
|
||||
}
|
||||
|
||||
override fun getGroups(): MutableSet<AbstractMaterialGroup> {
|
||||
return includedGroup
|
||||
}
|
||||
|
||||
override fun getMaterials(): MutableSet<Material> {
|
||||
override fun getMaterials(): EnumSet<Material> {
|
||||
return groupItems
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import io.delilaheve.CustomAnvil
|
|||
import org.bukkit.Material
|
||||
import org.bukkit.configuration.ConfigurationSection
|
||||
import java.util.*
|
||||
import kotlin.collections.LinkedHashMap
|
||||
|
||||
class ItemGroupManager {
|
||||
|
||||
|
|
@ -18,11 +19,11 @@ class ItemGroupManager {
|
|||
private val FUTURE_MATERIAL = setOf("PIGLIN_HEAD","BRUSH")
|
||||
}
|
||||
|
||||
lateinit var groupMap : HashMap<String, AbstractMaterialGroup>
|
||||
lateinit var groupMap : LinkedHashMap<String, AbstractMaterialGroup>
|
||||
|
||||
// Read and create material groups
|
||||
fun prepareGroups(config: ConfigurationSection){
|
||||
groupMap = HashMap()
|
||||
groupMap = LinkedHashMap()
|
||||
|
||||
val keys = config.getKeys(false)
|
||||
for (key in keys) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue