Mine reset variable blocks on list

Discussion in 'Plugin Development' started by tg95, Jun 6, 2016.

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

    tg95

    Hello i need help, i create plugin for my server, is reseting mines, and i have problem for reset blocks list.

    my code:
    Code:
                        } else if(args[0].equalsIgnoreCase("reset")) {
                            if(args.length == 2) {
                                if(getConfig().contains(args[1])) {
                                    String mname = args[1];
                                    int xmax1 = getConfig().getInt(mname+".xmax");
                                    int ymax1 = getConfig().getInt(mname+".ymax");
                                    int zmax1 = getConfig().getInt(mname+".zmax");
                                  
                                    int xmin1 = getConfig().getInt(mname+".xmin");
                                    int ymin1 = getConfig().getInt(mname+".ymin");
                                    int zmin1 = getConfig().getInt(mname+".zmin");
                                  
                                    World w = Bukkit.getWorld(getConfig().getString(mname+".world"));
                                    p.sendMessage("reset");
                                    for(int x1 = xmax1; x1 <= xmin1; x1++) {
                                    for(int y1 = ymin1; y1 <= ymax1; y1++) {
                                    for(int z1 = zmin1; z1 <= zmax1; z1++) {
                                        Block b = (Block)w.getBlockAt(x1,y1,z1);
                                        b.setType(Material.SAND);
                                    }
                                    }
                                    }
                                } else {
                                    p.sendMessage("dont exist");
                                }
                            } else {
                                p.sendMessage("ise: ");
                            }
    and my config.yml
    Code:
    test:
      world: world
      xmax: -44
      ymax: 72
      zmax: -68
      xmin: -40
      ymin: 68
      zmin: -73
      comp:
      '15:0': 0.05
      '73:0': 0.03
      '21:0': 0.06
      '16:0': 0.04
    ok my problem is, what i get comp list and reset mine whit this comp.

    comp example: 100% = 1.00 // 0.04 = 4%

    thanks for help and sorry for my bad english
     
    Last edited by a moderator: Jun 6, 2016
  2. Offline

    Lordloss

    why do you cast an Block to an Block?

    sorry i dont really get whats your problem. Where are you stuck at exactly? Did you get any errors?
     
  3. Offline

    tg95

    no, dont send any error, but this work fine, i only need how i can reset "area" whit determinate blocks list
     
  4. @tg95 you will have to make some sort of backup. use a Map<Location, Material> and save all locations of the blocks you want to reset later with their old material into the map. if you want to reset the blocks loop through the locations and set the material of the block at the location to the material mapped for the location in the map.
     
  5. Offline

    Xerox262

    @Shmobi I think he wants it to be random each time, with the percentage chance of the blocks being the numbers on the right.


    @tg95 Get the blocks from the comp, then use a random to choose which block will be placed.
     
  6. Offline

    tg95

    @Xerox262 yes i need do this, but i dont know how...
     
  7. @tg95 make a List<Material> of all materials you want possibly to be there. Generate a random number between 0 and 100 and then you can depending on your wish percentage for example say, if my random generated number is < 30 it is a 30% chance that the block wont keep its old state. if that should be the case, get a random material from your list to replace it with the old one, otherwise put the normal one from your map in.

    EDIT:
    Of course you only need the random chance to be between 0-100 if you want to be able to go for 1% steps so you could go for stuff like 3% chances. if you only wanna go for 10% steps it also works if you have the random chance between 0-10
     
  8. Offline

    tg95

    @Shmobi humm but i dont understand why i can do example:

    Area have 1000 blocks: and i put on config: 'stone':0.50 ( 0.50 = 50% of area ) 'diamond':0.50 and how i can do for this "area" put 50% stone and 50% diamond, 500 blocks of stone and 500 blocks diamond.
     
  9. Offline

    Lordloss

    there are multiple ways of doing this, just google how to use random. It doesnt seem like we could help you without promising code, which we wont do.
     
  10. Offline

    Xerox262

    @tg95 You can do that, you just never said that's what you wanted to do. Use blockAmount/area then check if it's >= the amount, if it is stop adding that type of block, if it's not then continue. You do still need to use a random though or else it'll be 500 blocks of stone on top of 500 blocks of diamond with no variation between them.
     
  11. @Xerox262 wouldn't work if there is a 60% chance for stone and a 60% chance for diamond
    @tg95 i don't want to be rude, but it seems to me as if you are new to java. maybe you should first learn basics like that before you go into plugin developement
     
Thread Status:
Not open for further replies.

Share This Page