Solved WorldGuard API for 1.13?

Discussion in 'Spigot Plugin Development' started by Jagerborn, Aug 9, 2018.

  1. Hello

    I am having some problems getting the WorldGuard API to work on 1.13 plugins.

    The only way I can get both WorldEdit and WorldGuard to work on a 1.13 spigot server is by using the latest experimental development builds from The problem in this case is that my plugins are not able to use the WorldGuard API like it used to be able to.

    I can use an older version of WorldGuard to make the API work again but older versions of WorldEdit does not work. I would prefer updating and being able to use both WorldGuard and WorldEdit on a 1.13 server.

    Specifically, I used the WorldGuard API to get regions in a certain location and check for a flag value.

    I used to be able to do this to check if PvP was enabled at a location:
    Code (Text):
    public static boolean canPvPHere(Location location) {

            RegionContainer container = Main.getWorldGuard().getRegionContainer();
            RegionQuery query = container.createQuery();
            ApplicableRegionSet set = query.getApplicableRegions(location);
            return set.allows(DefaultFlag.PVP);
    This does not work on the latest version of WorldGuard

    Any ideas on how I can do this with the latest version of WorldGuard?

    Thanks for your time.

    EDIT: Solution below
    #1 Jagerborn, Aug 9, 2018
    Last edited: Aug 9, 2018
  2. They completely changed the internal structure of the plugins, whatever "API" may have existed before is now changed. There is no clean way to support pre-WG7 and WG7 together.

    If you really need to be able to do that, you have the same basic options as using NMS: reflection or multi-module. I'd suggest avoiding this, assuming you're updating your plugin for 1.13 anyway it probably won't be backwards compatible, in which case just update it to use the WG7/WE7 API.

    The main thing that has changed is how to get a RegionManager- you need to use WorldGuard.getPlatform().getRegionContainer().get(World). That and you need to use BukkitAdapter.adapt(...) to convert Bukkit classes to WorldEdit classes (Location, World, etc). WorldGuardPlugin.wrapPlayer is still needed to get a LocalPlayer, not sure why that one's not in BukkitAdapter but maybe just a temporary oversight.

    Most of the rest of the changes should be pretty obvious if you've got a decent IDE, it'll help you update packages. Mostly everything has moved to non-Bukkit-specific packages.
    • Informative Informative x 3
  3. Thanks for pointing that out, so the only way for 1.13- support is too drop worldedit from my plugins.

    Do you maybe know if is there WE 7 java doc anywhere?
  4. No idea on the javadoc, sorry. I just look through the code from their github repo. I honestly don't get the impression they really have an API, or at least not one they care not to break between major versions.

    But no you can 100% support WE7 and 1.13 at the same time.

    What's more challenging is to support both WE6/1.12 (or lower) and WE7/1.13 in the same plugin version.
    • Like Like x 1
  5. Thank you NathanWolf for the help.

    I was able to solve this issue. First I removed all my previous imports in the plugin.

    For example:
    import com.sk89q.worldguard.bukkit.RegionContainer;

    was updated to:

    After that, it is much easier to play around with the plugin and see what works. This is the working code for the original example:
    Code (Text):
    public static boolean canPvPHere(Location location) {
            RegionContainer container = com.sk89q.worldguard.WorldGuard.getInstance().getPlatform().getRegionContainer();
            RegionQuery query = container.createQuery();
            ApplicableRegionSet set = query.getApplicableRegions(BukkitAdapter.adapt(location));
            return set.testState(null, new StateFlag[] { Flags.PVP });
    • Like Like x 5
    • Informative Informative x 1
    • Useful Useful x 1
  6. Oh I guess I could've been nice and shared some code too :D

    Yes, this is ugly AF but if you really need to support both versions, this is what I'm using:

    You could probably take most of that and use it as-is, just strip out the flag-specific stuff that's just for my plugin. It supports queries for build, pvp and exit permissions.
    • Like Like x 1
    • Useful Useful x 1