Trap player in blocks

Discussion in 'Plugin Development' started by jimbo8, Aug 12, 2014.

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

    jimbo8

    Hi! :)

    I'm currently developing a MMO-plugin and most of it is doing good.

    I have a ice wand which is supposed to freeze players when they are hit, but i don't really know where to start. I believe i need a for-loop and loop through every block around the player, but my math is really, really terrible. :p

    I only need the for-loop, as saving the blocks to a hashmap is no problem.

    Are there any snippets anyone wants to share?

    Thanks :)
     
  2. Offline

    guangong4

    This returns a cube around a location. Have fun :D
    Code:java
    1. public static Location[] getCube(Location l, int rad) {
    2. HashSet<Location> list = new HashSet<Location>();
    3. for (int i = -rad; i <= rad; i++) {
    4. for (int y = -rad; y <= rad; y++) {
    5. list.add(l.clone().add(-rad, y, i));
    6. list.add(l.clone().add(rad, y, i));
    7. list.add(l.clone().add(y, -rad, i));
    8. list.add(l.clone().add(y, rad, i));
    9. list.add(l.clone().add(i, y, -rad));
    10. list.add(l.clone().add(i, y, rad));
    11. }
    12. }
    13. return list.toArray(new Location[list.size()]);
    14. }

    You'll need to use the block.setType(Material) method, and a delayed task for setting the type back to the original.
     
Thread Status:
Not open for further replies.

Share This Page