[LIB] ZoneLib

Discussion in 'Resources' started by Sabersamus, Feb 18, 2014.

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

    Sabersamus

    I've seen some people struggling to make zone plugins, so I figured I'd help them out a little bit.

    You can download the library here: http://www.bytecraft.info/zoneLib.zip

    view on github

    And here's how to use it :)

    For 3D zones/areas

    For this example, we're going to imagine two HashMap<String, Location>'s have been set,
    as a way to select the two points, and in the main plugin file there's a List<Cube> to store cubes.

    (you can store the points to config and load later, however we wont for the example)
    Code:java
    1.  
    2.  
    3. HashMap<String, Location> map1 = plugin.getMap1();
    4. HashMap<String, Location> map2 = plugin.getMap2();
    5.  
    6. //check if players name is in both maps!
    7.  
    8. Location l1 = map1.get(player.getName());
    9. Location l2 = map2.get(player.getName());
    10.  
    11. Point point1 = new Point(l1.getBlockX(), l1.getBlockY(), l1.getBlockZ());
    12. Point point2 = new Point(l2.getBlockX(), l2.getBlockY(), l2.getBlockZ());
    13. //now we have two points, we can create a cube
    14.  
    15. Cube cube = new Cube(point1, point2);
    16.  
    17. plugin.addCube(cube);
    18.  
    19. //now to actually use it, very badly
    20.  
    21. public void onBreak(BlockBreakEvent event){
    22. Block block = event.getBlock();
    23. //Create a new point for the block
    24. Point p = new Point(block.getX(), block.getY(), block.getZ());
    25. for(Cube cube: plugin.getCubes()){//this is very bad, dont do it exactly like this!
    26. if(cube.contains(p)){
    27. player.sendMessage("You broke a block inside a cube");
    28. }
    29. }
    30. }
    31.  


    You can do the same thing with Plane's, except the Y-Axis doesn't come into play when checking if it contains a point.

    So how do you use it? Well thats up to you.

    Just download the .zip, extract it to your plugin, and you can start using it.

    Let me know what you think, or if anything doesn't work exactly how its supposed to.

    //EDIT: Updated to suggestion by kumpelblase2
     
    Wizehh likes this.
  2. You should evaluate the highest and lowest point on cube creation, not on the contains check. Because now you'd need to re-evaluate the highest and lowest point every time the method gets called, which is pretty resource intensive after a certain amount.
     
    Garris0n likes this.
  3. Offline

    xTrollxDudex

  4. Offline

    Sabersamus

    Thanks, I wasnt sure what to put it under.

    Alright, thanks for the tip. I'll get right on that

    I've added a method to Plane and Cube to check intersections

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

    MrInspector

    Fix'd.

    Don't worry, I got your back. ;)
     
  6. Offline

    Sabersamus

  7. Offline

    MrInspector

    You were missing an @EventHandler
     
  8. Offline

    Sabersamus

    :p I wasn't too worried about it, it wasn't exactly code that people would be using.
     
    MrInspector likes this.
Thread Status:
Not open for further replies.

Share This Page