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

Add query methods to get values from MapFlags #1650

Merged
merged 4 commits into from
Jan 24, 2021

Conversation

Joo200
Copy link
Collaborator

@Joo200 Joo200 commented Oct 15, 2020

I added some query methods to query value from MapFlags.
Usage:

  • register the map flag (added in WorldGuard's Flags class):
public static final MapFlag<ItemType, StateFlag.State> ITEM_PICKUP_TYPE =
            register(new MapFlag<>("item-material-pickup", new RegistryFlag<>(null, ItemType.REGISTRY), new StateFlag(null, true)));
  • Use it in the code (changed RegionProtectionListener#onDestroyEntity for the test, just as test and should be cleaned up a little bit)
        /* Item pickup */
        } else if (event.getEntity() instanceof Item) {
            ItemType itemType = BukkitAdapter.adapt(((Item)event.getEntity()).getItemStack()).getType();
            canDestroy = query.testBuild(BukkitAdapter.adapt(target), associable, Flags.ITEM_PICKUP_TYPE, itemType, Flags.ITEM_PICKUP, combine(event));
            what = "pick up items";

        /* Experience orb */
        } else if (event.getEntity() instanceof ExperienceOrb) {
  • Compile and use the flags ingame

grafik

The regions are overlapping. Flag item-pickup is set to deny, so nobody can pickup items by default. The flag item-material-pickup is set on two regions:

  • You can pickup dirt and anvils but you can't pickup stone.

The implementation does work with region inheritance and region priorities. It does search for the matched key with the highest priority.

@Joo200
Copy link
Collaborator Author

Joo200 commented Oct 15, 2020

Should be helpful for #417

@wizjany
Copy link
Collaborator

wizjany commented Oct 17, 2020

Think I'm going to have to double/triple-check the logic and docs here, as there's a lot of weird edge cases to cover. Possibly we should have some tests for this.
E.g., in cases where the V is a State, we should do a queryState-esque check where states are resolved against each other at equal priority. More generically, two of the same K that apply to a query with different values for V should use Flag#chooseValue to resolve V.

@Joo200
Copy link
Collaborator Author

Joo200 commented Oct 18, 2020

  • I added some test cases to the PR. They should cover the basic logic things. Maybe I'll add some more tests.
  • I changed the lookup process to use Flag#chooseValue instead of using the first available value.
  • I added some sort of fallback flag to check for a Flag with same or higher priority.
    E.g. the item-pickup flag could be set to deny on a higher prioritized region which will block item-pickups generally.

With the new methods in RegionQuery it should be easy to check for a MapFlag with a fallback flag. I added a method RegionQuery#testBuild for a method with MapFlag.

@wizjany wizjany added the status:accepted Will be fixed / added to WorldGuard, eventually label Nov 8, 2020
@wizjany
Copy link
Collaborator

wizjany commented Jan 24, 2021

There's some lingering javadoc and formatting issues but the implementation looks complete, so I'm going to merge this now while I'm looking at stuff since who knows when I'll look next.
I'm sure the javadoc issues will get fixed...eventually...eh heh.

@wizjany wizjany merged commit b1674e5 into EngineHub:master Jan 24, 2021
@Joo200 Joo200 deleted the mapquery branch January 24, 2021 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:accepted Will be fixed / added to WorldGuard, eventually
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants