Skip to content

Commit

Permalink
Allow /collectible find for collectible id/tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Gegy committed Nov 23, 2024
1 parent 286c775 commit 5f29551
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,12 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, Co
.then(literal("countdisguises").executes(CollectibleCommand::countDisguises))
.then(literal("find")
.executes(context -> findCollectibles(context.getSource(), stack -> true))
.then(argument("collectible", resourceOrTag(buildContext, ExtraRegistries.COLLECTIBLE))
.executes(context -> findCollectibles(context.getSource(), getResourceOrTag(context, "collectible", ExtraRegistries.COLLECTIBLE)))
)
.then(literal("item")
.then(argument("item", itemPredicate(buildContext))
.executes(context -> findCollectibles(context.getSource(), getItemPredicate(context, "item")))
.executes(context -> findCollectibles(context.getSource(), itemToCollectiblePredicate(getItemPredicate(context, "item"))))
)
)
)
Expand Down Expand Up @@ -224,10 +227,10 @@ private static int setLocked(CommandContext<CommandSourceStack> context, boolean
return 1;
}

private static int findCollectibles(CommandSourceStack source, Predicate<ItemStack> item) {
private static int findCollectibles(CommandSourceStack source, Predicate<Holder<Collectible>> predicate) {
MinecraftServer server = source.getServer();
GameProfileCache profileCache = server.getProfileCache();
CollectibleLister.listPlayersWithItem(server, item)
CollectibleLister.listPlayersWithItem(server, predicate)
.thenApplyAsync(
profileIds -> profileIds.stream().map(profileCache::get).flatMap(Optional::stream).toList(),
Util.backgroundExecutor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ public class CollectibleLister {
private static final String PLAYER_DATA_SUFFIX = ".dat";
private static final Logger LOGGER = LogUtils.getLogger();

public static CompletableFuture<List<UUID>> listPlayersWithItem(MinecraftServer server, Predicate<ItemStack> item) {
public static CompletableFuture<List<UUID>> listPlayersWithItem(MinecraftServer server, Predicate<Holder<Collectible>> predicate) {
return list(server).thenApplyAsync(entries -> {
List<UUID> profileIds = new ArrayList<>();
for (CollectibleLister.Entry entry : entries) {
for (Holder<Collectible> collectible : entry.data().collectibles()) {
ItemStack stack = Collectible.createItemStack(collectible, entry.profileId());
if (item.test(stack)) {
if (predicate.test(collectible)) {
profileIds.add(entry.profileId());
}
}
Expand Down

0 comments on commit 5f29551

Please sign in to comment.