Check if a region is overlapping with another region

Discussion in 'Plugin Development' started by Irantwomiles, Dec 5, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    Irantwomiles

    I want to create a plugin that will allow players to claim land, but I don't want them to be able to claim over other peoples land. I've coded something like this before, but it was done in a triple nested for loop and I want to avoid that completely. The claiming wont be done via chunks, so its a little more difficult, but I'm just really looking for ideas on how this can be achieved with a better run time.
     
  2. Offline

    Vassilios

    Since you're not using chunks I think it would be better if you explained how it works.
     
  3. Offline

    Irantwomiles

    Two corners creating a rectangular region.
     
  4. Offline

    knokko

    To check if two rectangle regions overlap, you need to find the minimum and maximum x & z coordinates of both regions. If some rectangle region is defined by two points (x1,z1) and (x2,z2), the minimum x is just Math.min(x1,x2). (The same applies to the z-coord and the maximum.) They overlap if (and only if) rect1.minimumX <= rect2.maximumX && rect1.minimumZ <= rect2.maximumZ && rect2.minimumX <= rect1.maximumX && rect2.minimumZ <= rect1.minimumZ.
     
Thread Status:
Not open for further replies.

Share This Page