Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom selector filters #2195

Open
dualspiral opened this issue Jul 30, 2020 · 4 comments
Open

Allow custom selector filters #2195

dualspiral opened this issue Jul 30, 2020 · 4 comments
Labels
api: 8 (u) version: 1.16 (unsupported since Oct 17th 2023) priority: low Low priority system: command type: feature request A feature request

Comments

@dualspiral
Copy link
Contributor

Caveat: I do not know how well this will work with Minecraft client completion... yet.

It would be nice to be able to add selector filters. For example, in a skills plugin, it might be nice to support the following:

@p[skill_woodcutting=35..]

allowing for the selection of the nearest player with a skill level of 35 or over.

As an implementation note: I'd want to do this by registering more objects into the EntityOptions class.

We may also be able to support other selector types, such as @c for cause stack member, for example, but again, that requires more thought and looking into the system. I'm not sure if multi letter selector strings will work though looking at the impl. All for investigation though!

@dualspiral dualspiral added system: command priority: low Low priority type: feature request A feature request api: 8 (u) version: 1.16 (unsupported since Oct 17th 2023) labels Jul 30, 2020
@thibaulthenry
Copy link
Contributor

Hey,

I dig up this issue to know if you had any plans about this and to ask if this would be possible to look for the problem I encoutered about scoreboards filters that only rely on the server scoreboard.

Also, I wonder why the Selector class isn't generic. The current implementation is based on the fact every selectors are EntitySelector.
For example, I can't build a custom selector @w to select all worlds. Someone asked me this for my plugin, because it can be annoying to setup properties or world settings world by world.

@dualspiral
Copy link
Contributor Author

I dig up this issue to know if you had any plans about this and to ask if this would be possible to look for the problem I encoutered about scoreboards filters that only rely on the server scoreboard.

That doesn't really belong here, if you can do that in Vanilla but not using this system, that's an entirely different issue.

Also, I wonder why the Selector class isn't generic. The current implementation is based on the fact every selectors are EntitySelector.

Which they are - this is exposing something in Vanilla. A selector is for selecting entities, not anything else. If you want to build your own selector for selecting something other than an entity, you need to do it yourself.

@thibaulthenry
Copy link
Contributor

That doesn't really belong here, if you can do that in Vanilla but not using this system, that's an entirely different issue.

I may write a new issue for this so. The Vanilla system is completly stuck to the server scoreboard.
Thing is in API-8 we are only using this Vanilla system, whereas in API-7 we had method to describe filter behaviors

Even API-7 was stuck with server scoreboard, and I never realized that :

private void addTeamFilters(List<Predicate<Entity>> filters) {
    Optional<Invertible<String>> teamOpt = this.selector.getArgument(ArgumentTypes.TEAM);
    if (teamOpt.isPresent()) {
        Invertible<String> teamArg = teamOpt.get();
        final boolean inverted = teamArg.isInverted();
        filters.add(input -> {
            if (!(input instanceof TeamMember)) return teamArg.getValue().isEmpty() && inverted;

            Optional<Scoreboard> scoreboard = Sponge.getGame().getServer().getServerScoreboard();
            if (!scoreboard.isPresent()) return false;

            Optional<Team> team = scoreboard.get().getMemberTeam(((TeamMember) input).getTeamRepresentation());
            if (teamArg.getValue().isEmpty()) {
                return inverted ^ team.isPresent();
            } else {
                return inverted ^ (team.isPresent() && team.get().getName().equals(teamArg.getValue()));
            }
        });
    }
}

But at least we could have fix this pretty easily. Here I don't see any solution to my problems.
There is no concept of "multiple scoreboard" in Vanilla

Which they are - this is exposing something in Vanilla. A selector is for selecting entities, not anything else. If you want to build your own selector for selecting something other than an entity, you need to do it yourself.

I don't completely agree with that. It's true that currently, there is only one type of selector in Minecraft, which is the entity selector.
So we can admit that a Selector (Sponge) is an EntitySelector (Minecraft), but the day they decide to implement a new type, you have to break the api :

selector

@dualspiral
Copy link
Contributor Author

dualspiral commented Feb 6, 2021

What you're asking is pretty much nothing to do with this issue, but I'll explain why that's not something I think we should be doing.

I wonder why the Selector class isn't generic

Almost all of the methods on the selector builder are specific to entities. A generic here adds little to no value and adds some complexity. If a world selector was created, I don't think it'd use any of these filters.

I don't completely agree with that. It's true that currently, there is only one type of selector in Minecraft, which is the entity selector.
So we can admit that a Selector (Sponge) is an EntitySelector (Minecraft), but the day they decide to implement a new type, you have to break the api

So we'll break the API. We're not really interested in doing an API 7->8 style break again, but such a thing would be minor enough that we could do it if it made sense to do so (it may very well be that we just crreate a WorldSelector instead).

However, I don't think they will.

To go back on topic slightly:

But at least we could have fix this pretty easily. Here I don't see any solution to my problems.
There is no concept of "multiple scoreboard" in Vanilla

That's a new issue really. This issue is about custom (aka plugin provided) selection filters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: 8 (u) version: 1.16 (unsupported since Oct 17th 2023) priority: low Low priority system: command type: feature request A feature request
Projects
None yet
Development

No branches or pull requests

2 participants