Solved How to call a piece of code

Discussion in 'Plugin Development' started by Roelyboely12, Aug 22, 2014.

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

    Roelyboely12

    I want a certain piece of code to be called over and over again until my plugin is done calculating, how do i do this? (i think it's really simple but i can't figure out)
     
  2. Offline

    DevSock

    Roelyboely12 Depending on what you're wanting done, any number of the basic Java loops could help you. What exactly do you need to calculate? Do you know how many times you have to calculate? A few more details would be nice to have and would help us answer you better.
     
  3. Offline

    Roelyboely12

    let's say i have a cube a array calculates everything and if it's not glass it will check the neighbour blocks if their glass until the cube is filled

    DevSock
    Code:java
    1. @EventHandler
    2. public void JarProtector(BlockPlaceEvent event)
    3. {
    4. if (event.getBlockPlaced().getType() == Material.SPONGE)
    5. {
    6. if (event.getPlayer().getGameMode() == GameMode.CREATIVE)
    7. {
    8. Location loc=event.getBlockPlaced().getLocation();
    9. int type = 0;
    10. if (event.getBlock().getType() == Material.GLASS) {type=1;}
    11.  
    12. double loc_x = loc.getBlockX();
    13. double loc_y = loc.getBlockY();
    14. double loc_z = loc.getBlockZ();
    15. //here the loop must begin
    16. jar_array[I][0]= loc_x;[/I]
    17. [I]jar_array[I][1]= loc_y;[/I][/I]
    18. [I]jar_array[I][2]= loc_z;[/I][/I]
    19. [I]jar_array[I][3]= type;[/I][/I]
    20. [I]i+=1;[/I]
    21.  
    22. [I]Material matAtLocation = new Location(event.getBlockPlaced().getWorld(),loc_x+1,loc_y,loc_z).getBlock().getType();[/I]
    23. [I]if (matAtLocation == Material.GLASS)[/I]
    24. [I]{type=1;}[/I]
    25. [I]else[/I]
    26. [I]{type=0;}[/I]
    27. [I]//i want to call it right here[/I]


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

    Onlineids

    Roelyboely12 Just run it how many times you see fit, here is a loop that broadcasts hi 50 times:
    Code (open)

    Code:java
    1. for(int i = 0; i < 50; i++){
    2. Bukkit.broadcastMessage("hi");
    3. }
     
  5. Offline

    Roelyboely12

Thread Status:
Not open for further replies.

Share This Page