The best way to do this

Discussion in 'Plugin Development' started by mrkirby153, May 21, 2014.

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

    mrkirby153

    Hello everyone!

    I am working on a minigame plugin and I wanted to know the best way to do this:

    I want to know if a location is inside of an arena. I was thinking that I could put all the locations in the arena into an array list and then check if the array list contains the location and if it does do stuff. However, I think that it would get kinda slow if there are a lot of arenas that are fairly big. So is there a faster and less server intensive way of doing this?
     
  2. Offline

    RegalMachine

    There are many, many ways to do this mrkirby153 ... It really depends on how you want the areas to be defined. If you are going to make a plugin that takes 2 locations and makes a rectangle from bedrock to skylimit, you can check to see if the player x value is inbetween the x values of the two locations, and if the players z value is inbetween the z values of the two locations. Of course, if you are going to dynamically make a ton of regions with little manual config editing, something a little more complex might have to be done, but thats the basis of it.
     
    Garris0n and 1Rogue like this.
  3. Offline

    AstramG

    Make a cuboid selection in the arena creation. Then replace all air blocks with 0:8 or any data value. Then when you check if they are in the arena get the nearest air block of the player and check if the data value is that value. Untested method, but I know that in Vanilla single player air with different data can be singled out.
     
  4. Offline

    RegalMachine

    AstramG the only issue with this is that the regions wouldnt hold up through block changes. When a block gets destroyed, its replaced with 0:0 by default.
     
  5. Offline

    AstramG

    RegalMachine
    Yeah I was assuming that you didn't want blocks to break. The best way is probably just checking if the players location is within the cuboid.
     
  6. Offline

    mrkirby153

  7. mrkirby153 Get the player's location as a vector, and then check using that method where min and max are the two corners.
     
  8. Offline

    mrkirby153

    AdamQpzm
    Code:java
    1. public static boolean isProtected(Vector vector) {
    2. ArrayList<Arena> arenas = Arenas.arenas;
    3. for (Arena a : arenas) {
    4. Location min = a.getPt1();
    5. Location max = a.getPt2();
    6. System.out.println(min.toString());
    7. System.out.println(max.toString());
    8. System.out.println("---");
    9. if (vector.isInAABB(min.toVector(), max.toVector()))
    10. return true;
    11. }
    12. return false;
    13. }

    Does not work when passing in a vector that is clearly inside an arena.
     
  9. mrkirby153 Try printing out the vector that you pass it as well, so that you can be it is
     
  10. Offline

    mrkirby153

    AdamQpzm
    The vector is what it should be and is still inside the arena
     
Thread Status:
Not open for further replies.

Share This Page