How to create boundaries(regions) without WorldGuard

Discussion in 'Spigot Plugin Development' started by iabuse_, Sep 12, 2017.

  1. Hello, I am a developer (obviously) and I am wondering how I can create boundaries with a repeating task. To test if a player is in a specific region

    I don't want to use any kind of API

    If you can help, it'll be greatly appreciated.

    - SSync
     
  2. Simply use the location of the player compared to the two locations on opposite ends of your area.
     
  3. The answer to your question depends on the type of arena you want. For cuboid you can just save the world minx miny minz maxx maxy maxz. For circular you can save the world centerx centery centerz and radius.
     
  4. Thanks for your help, I found the moderators method worked quite well. However, it'd be nice to know how to do a circular space. Could you provide an example for me?
     
  5. Remember to leave positive reactions when someone helps you :)
     
  6. Circular is done just like on a square, however with a radius from the center.
    You iterate over the exact same blocks and need to know the center point.
    if the distance from center > the radius then they're out of the area.

    Code (Text):
    XXXOXXX
    XXOOOXX
    XOOOOOX
    OOOCOOO
    XOOOOOX
    XXOOOXX
    XXXOXXX

    For reference, obviously this isn't exact
    X's are out of the area, O's are in the area
    C is the center, the radius of this area is: 3
     
    Edit: that being said, you should really consider using worldguard you'll not write a faster or more efficient storage system for your custom regions than worldguard did. You can create/delete regions on the fly with code, quickly get their min/max points to find blocks or set them or just detect player presence.
     
    #6 dNiym, Sep 13, 2017
    Last edited: Sep 13, 2017
  7. Instead of a repeating task you could use PlayerMoveEvent
     
  8. Absolutely not! Do not use onplayermove event for this! That event can fire THOUSANDS of times per second, you don't want to be iterating over piles of blocks or locations to see if a player is there! Just wiggling your mouse fires that event a TON of times. It fires a ton of times when moving across ONE block.

    The only thing worse you could possibly do is schedule bukkit runnables in on player move or do database lookups!
     
  9. WorldGuard uses PlayerMoveEvent, it has a config to not use it if you don't want several of the flags to not work. I believe towny uses it also.
     
  10. No doubt plugins do use the playerMoveEvent but they're coded in a way that ensures efficiency and avoids unnecessary executions. Blindly looping over a couple thousand blocks every time onplayermove fires will most definitely cause you some TPS issues, multiply that by 10 players and it becomes crippling.
     
  11. What goal would require looping over thousands of blocks on playerMoveEvent?o_O
     
  12. OP is creating an arena, and trying to detect if his players are in it or not, thus he will have a couple bounding locations and either iterate over them all OR do some math to determine if they're inside the area. If he does store all those locations or worse block objects and checking int in onPlayerMove it'll get expensive fast. He didn't specify the size of this arena, thus it could easily be 50 blocks or 50,000 blocks (locations) looping through 50k location objects or blocks a couple thousand times a second with a player moving fast will take its toll on the server if this method fires every single onPlayerMoveEvent which as stated happens A LOT.

    But in answer to your question there should be NO goal that should require looping thousands of blocks in onPlayerMove, but people write crazy things all the time. On player move should be respected because it is called so frequently.
     
  13. NavyDev

    NavyDev Previously NavyLP

    Could have these blocks saved in a preloaded list that has been loaded upon arena/server/plugin start. Then you just have to check if the player's location is contained in the list.
     

Share This Page