Skip to content

Commit

Permalink
feat(grid): 拼音搜索
Browse files Browse the repository at this point in the history
  • Loading branch information
ybw0014 committed Jul 29, 2024
1 parent 3f552c9 commit a98e175
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.houbb</groupId>
<artifactId>pinyin</artifactId>
<version>0.4.0</version>
<scope>compile</scope>
</dependency>

<!-- Supported Plugins -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.sefiraat.networks.slimefun.network.grid;

import com.github.houbb.pinyin.constant.enums.PinyinStyleEnum;
import com.github.houbb.pinyin.util.PinyinHelper;
import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunBlockData;
import io.github.sefiraat.networks.NetworkStorage;
import io.github.sefiraat.networks.network.GridItemRequest;
Expand Down Expand Up @@ -219,7 +221,9 @@ protected List<Map.Entry<ItemStack, Integer>> getEntries(@Nonnull NetworkRoot ne

final ItemStack itemStack = entry.getKey();
String name = ChatColor.stripColor(ItemStackHelper.getDisplayName(itemStack).toLowerCase(Locale.ROOT));
return name.contains(cache.getFilter());
final String pyName = PinyinHelper.toPinyin(name, PinyinStyleEnum.INPUT, "");
final String pyFirstLetter = PinyinHelper.toPinyin(name, PinyinStyleEnum.FIRST_LETTER, "");
return name.contains(cache.getFilter()) || pyName.contains(cache.getFilter()) || pyFirstLetter.contains(cache.getFilter());
})
.sorted(cache.getSortOrder() == GridCache.SortOrder.ALPHABETICAL ? ALPHABETICAL_SORT : NUMERICAL_SORT.reversed())
.toList();
Expand Down Expand Up @@ -369,7 +373,7 @@ private static List<String> getLoreAddition(int amount) {
final MessageFormat format = new MessageFormat("{0}数量: {1}{2}", Locale.ROOT);
return List.of(
"",
format.format(new Object[]{Theme.CLICK_INFO.getColor(), Theme.PASSIVE.getColor(), amount}, new StringBuffer(), null).toString()
format.format(new Object[] {Theme.CLICK_INFO.getColor(), Theme.PASSIVE.getColor(), amount}, new StringBuffer(), null).toString()
);
}
}

0 comments on commit a98e175

Please sign in to comment.