Block replacing blockBreakEvent (i think)

Discussion in 'Plugin Development' started by nastasescu, Jul 1, 2014.

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

    nastasescu

    All i want is a little code.
    When a player breaks any block, the block will respawn after... 1 minute i think.
    Is that possible I think... (Mineplex).
     
  2. Offline

    Traks

    Just create a sync BukkitRunnable with a delay of 1 minute whenever a block is broken...
     
  3. Offline

    MoeMix

    nastasescu
    Definitely possible. So on a block break event, create a runnable that cancels the event after 1 minute. I'm not on my pc so I can't really code it for you atm. However, if that method doesn't work then on a block break event, get the block that was broken and the location of that block. Then, after 1 minute, spawn that same block at that location.
     
  4. Offline

    hankered

    uh apparently it was wrong.
     
  5. Offline

    nastasescu

    hankered Thank you, i will try.

    Code:java
    1. @EventHandler
    2. public void onPlayerBreak(final BlockBreakEvent e) {
    3. BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
    4. scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
    5. @Override
    6. public void run() {
    7. Block bl = e.getBlock();
    8. Material mat = e.getBlock().getType();
    9. bl.setType(mat);
    10. Bukkit.broadcastMessage("test");
    11. }
    12. }, 0L, 600L);
    13. }
    14.  

    Don't work. When i break a block, it says test in a milisecond and nothing happened.

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

    Zupsub

    You made a repeating task which is not needed and startet straight after the break event. Read the given information from the link again.

    Then you fetch the current material of the block in the runnable, when it is of course already AIR. You have to fetch it in the block break event and set it back to that after the delay in the runnable.
     
  7. Offline

    mythbusterma

    hankered

    The only thing worse than spoonfeeding is spoonfeeding when you don't even know what you're doing.

    nastasescu

    Learn Java, then read the JavaDocs, the read the BukkitScheduler tutorial that Google is so kind to link you to with a simple search.
    Whatever you do, don't listen to hankered's advice.
     
  8. hankered No. Just stop.
    Thank you! Learn a little Java before you come here people. It'll make your life easier as well as ours.
     
  9. Offline

    nastasescu

    Code:java
    1. @EventHandler
    2. public void onPlayerBreak(BlockBreakEvent e) {
    3. Location blockl = e.getBlock().getLocation();
    4. final Material block = e.getBlock().getType();
    5. final Block blockb = e.getPlayer().getWorld().getBlockAt(blockl);
    6. BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
    7. scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
    8. @Override
    9. public void run() {
    10. blockb.setType(block);
    11. }
    12. }, 0L, 100L);
    13. }


    That's it, but when i broke a block, it will be replaced in a milisecond.
     
  10. nastasescu Well yeah, your code is telling it to immediately replace it, and then replace it every 100 ticks after that
     
  11. Offline

    fefe2008

    nastasescu Dude. Three words: Scheduled. Delayed. Task.
     
  12. Offline

    unon1100

    Here's a nice playlist on how you can learn Java basics. Once you complete this playlist. It's a nice laid-back tutorial on how to Java. If you watch this playlist first it will make things MUCH easier for you and us combined! It's quite a long playlist but it is important that you understand as much as you can about Java before coding with Bukkit. https://youtube.com/playlist?list=PLFE2CE09D83EE3E28
     
Thread Status:
Not open for further replies.

Share This Page