Make name optional in API.addCollapsibleGroup (#1114)

This commit is contained in:
slprime authored and GitHub committed 2026-11-08 18:13:37 +02:00
1 parent d04e1c8e83
commit 84d42de15f
2 files changed
+35 -19

No files matched your search

@@ -67,6 +67,16 @@ public class CollapsibleItems {
}
}
public static class ApiGroup {
private String unlocalizedName;
public ApiGroup setName(String unlocalizedName) {
this.unlocalizedName = unlocalizedName;
return this;
}
}
private static final String STATE_KEY = "collapsibleitems";
protected static File statesFile;
@@ -107,36 +117,42 @@ public class CollapsibleItems {
loadStates();
}
public static void registerGroup(String unlocalizedName, String filter) {
public static ApiGroup registerGroup(String filter) {
final ApiGroup apiGroup = new ApiGroup();
CollapsibleItems.apiGroups.add(() -> {
GroupItem group = new GroupItem();
group.setFilter(filter);
group.unlocalizedName = unlocalizedName;
group.unlocalizedName = apiGroup.unlocalizedName;
return group;
});
return apiGroup;
}
public static void registerGroup(String unlocalizedName, Iterable<ItemStack> items) {
public static ApiGroup registerGroup(Iterable<ItemStack> items) {
final ApiGroup apiGroup = new ApiGroup();
final ItemStackSet filter = new ItemStackSet();
for (ItemStack stack : items) {
if (stack != null) filter.add(stack.copy());
}
if (filter.isEmpty()) return;
if (filter.isEmpty()) return apiGroup;
final String key = unlocalizedName + ";"
+ filter.keys().stream()
.map(stack -> Item.itemRegistry.getNameForObject(stack.getItem()) + ":" + stack.getItemDamage())
.sorted().collect(Collectors.joining(","));
final String key = filter.keys().stream()
.map(stack -> Item.itemRegistry.getNameForObject(stack.getItem()) + ":" + stack.getItemDamage())
.sorted().collect(Collectors.joining(","));
final String guid = UUID.nameUUIDFromBytes(key.getBytes()).toString();
CollapsibleItems.apiGroups.add(() -> {
GroupItem group = new GroupItem();
group.setFilter(filter, guid);
group.unlocalizedName = unlocalizedName;
group.unlocalizedName = apiGroup.unlocalizedName;
return group;
});
return apiGroup;
}
private static void parseFile(List<String> itemStrings) {
+10 -10
View File
@@ -347,23 +347,23 @@ public class API {
* the lowest priority: an item that matches a preset or a collapsibleitems.cfg group stays there. They are active
* only while the Collapsible Items option is enabled. Must be called while plugins are loading.
*
* @param unlocalizedName Translation key of the name shown for the group
* @param filter A search string for matching items that belong to this group. Also identifies the group
* when its expanded state is saved, so changing it resets the saved state.
* @param filter A search string for matching items that belong to this group. Also identifies the group when its
* expanded state is saved, so changing it resets the saved state.
* @return A handle to optionally set the name shown for the group
*/
public static void addCollapsibleGroup(String unlocalizedName, String filter) {
CollapsibleItems.registerGroup(unlocalizedName, filter);
public static CollapsibleItems.ApiGroup addCollapsibleGroup(String filter) {
return CollapsibleItems.registerGroup(filter);
}
/**
* Same as {@link #addCollapsibleGroup(String, String)}, but the group is given as a list of item stacks. The stacks
* Same as {@link #addCollapsibleGroup(String)}, but the group is given as a list of item stacks. The stacks
* identify the group when its expanded state is saved, so changing them resets the saved state.
*
* @param unlocalizedName Translation key of the name shown for the group
* @param items Item stacks that belong to this group
* @param items Item stacks that belong to this group
* @return A handle to optionally set the name shown for the group
*/
public static void addCollapsibleGroup(String unlocalizedName, Iterable<ItemStack> items) {
CollapsibleItems.registerGroup(unlocalizedName, items);
public static CollapsibleItems.ApiGroup addCollapsibleGroup(Iterable<ItemStack> items) {
return CollapsibleItems.registerGroup(items);
}
@Deprecated