1.12.2 Supporting both WorldGuard 6 & 7?

Discussion in 'Spigot Plugin Development' started by Sean0402, Jan 28, 2020.

  1. Hello,

    I'm wanting to support WorldGuard 6 & 7 with my plugin. I'm just having issues with the thought process of it.

    What route is the best for my situation;
    I currently have a hashmap which does at the name suggest, saves a players selection with a number so I can know which selection it is;
    Code (Java):
    // location saving
        public static HashMap<Player, HashMap<Integer, Location>> selectedLocations = new HashMap<>();
    What I want to do is be able to support WG 6 & 7 and check if my List<Block> is in a worldguard region and cancel it.

    This is how I grab my locations;
    Code (Java):
    List<Block> blocksList = FactionWorldedit.getInstance().getLocationMethod().blocksFromTwoPoints(FactionWorldedit.selectedLocations.get(player).get(0), FactionWorldedit.selectedLocations.get(player).get(1));
    Would I create an interface with a method such as:
    Code (Java):
    public void checkPlayerSelection(Player player, List<Block> block)
    Could I just iterate through that and if it's in the RegionManager, return?

    I'd also like to know how to support WorldGuard 6 & 7 depending on which version they are using which is why I was thinking of using an interface, and if they are on version 1.8.8 to 1.12, use 6.x.x (I think?), else if it's 1.13+, use 7.x.x?

    My example code;
    Code (Java):
        public void checkPlayerSelection(List<Block> blocks) {
            ListIterator<Block> blockIterator = blocks.listIterator();
            while(blockIterator.hasNext()) {
                Block block = blockIterator.next();
    would something like this work?

    Any guidance towards this is appreciated hugely!
    #1 Sean0402, Jan 28, 2020
    Last edited: Jan 28, 2020
  2. The way you are explaining your question makes little sense. Please try rephrasing it.
  3. I want to check if my List<Block> is in a worldguard region.

    A player can type /set <Block> and it'll start setting the blocks, I want to do a check to see if the block they are setting is inside a region while also supporting WG 6 & 7.
  4. TeamBergerhealer


    I assume the interface to check whether one of your blocks is inside a region differs between WG 6 and 7. I know several ways to do it but the most accepted and proper way is:
    1. If you arent using maven already, use maven, otherwise this is too complicated
    2. Create an interface for worldguard with the methods your plugin needs ('isinregion(list<block>)') as its own small maven sub project
    3. Create two maven sub projects that depend on the sub project of 2). One with a maven pom dependency for worldguard version 6, the other for version 7. Both contain a single class that implements your interface.
    4. Depend on the three sub projects in your main plugin maven project
    5. In your plugin, create either implementation class depending on what version of worldguard is installed
    6. Use the maven shade plugin to include the sub-modules into your main plugin jar
    What happens here is that your sub-projects can compile against their version of worldguard, while all your main plugin sees is the interface methods.

    Another option is to make the implementations fully self-contained, and register themselves somewhere or automatically detect whether the version of worldguard it is meant for is enabled. But thats the 'nice haves'