Getting a blocks direction and meta vlue

Discussion in 'Plugin Development' started by bobthefish, Jun 6, 2014.

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

    bobthefish

    Hi, Im making a plugin that has a feature that makes it so then when you destroy a block, it gives the block to you, but then a set amount of time later, the block rests. Here is my code, but as you could have guessed, it doesnt work properly.
    Code:java
    1. @EventHandler
    2. public void onBreak(final BlockBreakEvent e){
    3. Player p = e.getPlayer();
    4. if(e.getBlock().getType() == Material.LOG){
    5. p.getInventory().addItem(new ItemStack(Material.LOG));
    6. p.giveExp(2);
    7. new BukkitRunnable(){
    8. public void run(){
    9. e.getBlock().setType(Material.LOG);
    10. }
    11. }.runTaskLater(plugin, 20L);
    12. }
    13. }


    The code works fine, but when i destroy for example, a birch wood block, it replaces it with oak, and if its sideways, then it replaces it up and down

    any help?
     
  2. Offline

    xTigerRebornx

    bobthefish Store the current BlockState when the event is executed, then in your scheduler, call update() on it
     
  3. Offline

    bobthefish

    xTigerRebornx Someone else told me to do that, But Im not sure how to call the update method, where do I put it?
     
  4. Offline

    xTigerRebornx

    bobthefish In the run method that is in your BukkitRunnable, so that it is called at the end of the delay
     
  5. Offline

    bobthefish

    xTigerRebornx OK, so something like:
    Code:java
    1. @EventHandler
    2. public void onBreak(final BlockBreakEvent e){
    3. Player p = e.getPlayer();
    4. if(e.getBlock().getType() == Material.LOG){
    5. p.getInventory().addItem(new ItemStack(Material.LOG));
    6. final BlockState b = e.getBlock().getState();
    7. p.giveExp(2);
    8. new BukkitRunnable(){
    9. public void run(){
    10. b.update();
    11. }
    12. }.runTaskLater(plugin, 20L);
    13. }
     
  6. Offline

    xTigerRebornx

    bobthefish Yeah, that looks like it would be fine.
     
  7. Offline

    bobthefish

    xTigerRebornx It doesnt work, the block never comes back again
     
  8. Offline

    xTigerRebornx

    bobthefish One thing I noticed, use update(true) so that it forces the update, as calling it with no parameters won't update it if the type is different.
     
  9. Offline

    bobthefish

    @ xTigerRebornx Ok OK, Ill try that

    xTigerRebornx Nope, same effect :/

    can anybody else help me?

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

    xTigerRebornx

  11. Offline

    bobthefish

    xTigerRebornx here it is:
    Code:java
    1. @EventHandler
    2. public void onBreak(final BlockBreakEvent e){
    3. Player p = e.getPlayer();
    4. if(e.getBlock().getType() == Material.LOG){
    5. p.getInventory().addItem(new ItemStack(Material.LOG));
    6. final BlockState b = e.getBlock().getState();
    7. p.giveExp(2);
    8. new BukkitRunnable(){
    9. public void run(){
    10. b.update(true);
    11. }
    12. }.runTaskLater(plugin, 20L);
    13. }
    14. }


    Bump?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 30, 2016
Thread Status:
Not open for further replies.

Share This Page