Arena's made and detect chest then randomize

Discussion in 'Plugin Development' started by Deckerz, Dec 16, 2012.

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

    Deckerz

    Hey,

    how do you make when a arena is created, it detects the chests, logs their locations and when it starts randomizes the contents?

    many thanks


    (i would try myself and code it but i have no idea how to do it, the arena i have a way to do it, its just more the chest thing i need to know how to do it)
     
  2. Offline

    tommycake50

    if(block.getType().equals(material.chest)){
    //its a chest
    }
     
  3. Offline

    Deckerz

    its more how to loop through the selected arenas block to detect the chest
     
  4. Offline

    Barinade

    That depends on if you want to do a radial search or if you're saving the 'arena' in a cuboid/2 corner locations

    How do you save the 'arena'? Just a location for players to spawn?
     
  5. Offline

    Deckerz

    the arena is two corners, and the two corners get save and the spawns have to be set in the area
     
  6. Offline

    Kazzababe

    What I do is just create a command that when executed will toggle the ability to right click a chest and save its location to the config.

    Code:
    @EventHandler
    public void onPlayerInteract(PlayerInteractEvent event) {
        Player player = event.getPlayer();
        String playerName = player.getName();
    
        if(event.getClickedBlock() != null && this.HashMapName.get(playerName)) {
            Block block = event.getClickedBlock();
            if(block.getType() == Material.CHEST) {
                Location loc = block.getLocation();
                //Save location to config
            }
        }
    }
    
    You can always of course just loop through all the blocks in a cuboid region and check if the block is a chest.
    Need help with anything else?
     
  7. Offline

    Barinade

    Sort out the max xyz and min xyz of the two positions, you could probably use a comparator and switch to ease the process, unless fireblast709 has a better method (that isn't a radial search)

    Then you can do:
    for(int x=minx;x<maxx;x++) {
    for (int y=miny;y<maxy;y++) {
    for (int z=minz;z<maxz;z++) {
    if (blockat xyz is chest) {
    //do things
    }
    }
    }
    }
     
  8. Offline

    fireblast709

    Barinade the method I know is Math.min(x,y) and Math.max(x,y)
     
  9. Offline

    Barinade

    In this case you could use
    for (int x=Math.min(x1,x2);x<=Math.max(x1,x2);x++) { //x1 and x2 are the given x coordinates in both locations
    //within range of the x coordinates, do the same for y1/y2 and z1/z2 for cuboid
    }
    Right?
     
  10. Offline

    fireblast709

Thread Status:
Not open for further replies.

Share This Page