Solved How to get a plot of land

Discussion in 'Plugin Development' started by bobthefish, Jun 2, 2014.

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

    bobthefish

    Hi,

    I have in my config.yml 4 points, x1,y1,x2,y2. I would like to create a rectangle of land in that area that goes from void to sky, i also need to be able to do things like cancel events in that area. Anyone know How I can do this?
     
  2. Offline

    ksbdude

    You could tap into worldedit
     
  3. Offline

    Nateb1121

    ksbdude 's way would be the simplest depending on how much you do with the rectangle and how you implement it, but if you don't want to depend on WorldEdit you have a lot of leg work to do.

    The easiest (though not most efficient way) to do this would for any event you DO NOT want in the area do something like:

    Code:java
    1.  
    2. public void eventHandle(EventHere evt){
    3. int x = evt.getPlayer().getLocation().getBlockX();
    4. int z = evt.getPlayer().getLocation().getBlockZ();
    5.  
    6. //Only need to do x, z since you said the y is from bedrock to sky
    7. boolean isXOkay = isBetween(configLowX, x, configHighX);
    8. boolean isZOkay = isBetween(configLowZ, z, configHighZ);
    9.  
    10. evt.setCancled(isXOkay && isZOkay);
    11.  
    12. }
    13.  
    14. public boolean isBetween(int low, int testPoint, int high){
    15.  
    16. return (low <= testPoint) && ( testPoint <= high);
    17.  
    18. }
     
    bobthefish likes this.
  4. Offline

    bobthefish

    ksbdude Id rather not use world edit If I can help it. Nateb1121 Thank you for that, however i have a question
    what are the parameters in the isBetween Method? and another thing is, how could I get who the region was made by?

    Thank you so much for your help

    Nevermind, I think that I could figure out the ownership thing, but still confused on the other part

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 30, 2016
  5. Offline

    Nateb1121

    bobthefish Whatcha mean? It just takes in a low number, a high number and a number to test if it's between the low and high number (line 14).

    To get who the region was made by you'd have to add something in your code that stores that in the config.yml
     
  6. Offline

    bobthefish

    Nateb1121 oh I see, sorry, Im tired, so the low would be the region min and the high would be the region max?


    so it could be like

    if(isBetwwenX && isBetweenY){
    //disallow stuff or do other things
    }
     
  7. Offline

    Nateb1121

    bobthefish You're spot on. :) Just remember, if you want the box to go from void to sky, you don't really need to check the y coordinate ;)

    If you wanted to be lazy and not check if you're giving it the high and low points in the right order you can use this:
    Code:java
    1.  
    2. public boolean isBetween(int low, int testPoint, int high){
    3. if(low > high){
    4. return isBetween(high, testPoint, low);
    5. } else {
    6. return (low <= testPoint) && ( testPoint <= high);
    7. }
    8. }
     
  8. Offline

    bobthefish

    Nateb1121 yes I know I dont need y, I just keep forgetting because im used to 2d graphs with x and y, so I keep saying it, thanks for the help and sorry for the confusion
     
    Nateb1121 likes this.
Thread Status:
Not open for further replies.

Share This Page