Solved Best way for Block-Update?

Discussion in 'Spigot Plugin Development' started by abilnfMC, May 6, 2017.

  1. Hello!
    I tried to make a block-placer plugin, and now I have a problem:
    If for example a seed is placed, it can be in the air, on stone,...
    So I tried to make a block-update by replacing and placing the block next to it.
    But if there is a chest, all items will drop.
    Any Idea for a fix or better block-update?

    EDIT: Just fixed it by changing the Data of a nearby block and changing it Back
     
    #1 abilnfMC, May 6, 2017
    Last edited: May 8, 2017
  2. Well when you set the type add a true at the end. Like so
    Block#setType (Material.whatever,true);
    That will apply physics to the object aka do a block update
     
  3. Tried it, but didn't work.
     
  4. Sorry for my late response :/
    No, I have no other plugins on the server.
     
  5. Maybe do something like this, I don't really know
    Code (Text):
    Block b = (Block) Bukkit.getServer().getWorld(WORLD).getBlockAt(COORDS);
    b.update();
     
  6. That does not exist xD
    But you could try
    Block#getState.update()
     
  7. Nope, doesn't work, too.
    I tried updating to the newest spigot version, but no change.
    And I also tried making a completly new Server... no change.
     
    #8 abilnfMC, May 8, 2017
    Last edited: May 8, 2017
  8. *sigh* I will give you a method from one of my private plugins. It works 100% for me on 1.11 but it should technically work across some other versions as well. Hopefully this solves your issue. (If it doesnt help, try setting the boolean to true in the setType(Material,Boolean) just above using this method, maybe)

    Code (Text):
    public void forceUpdate(org.bukkit.block.Block block) {
        ((CraftWorld)block.getWorld()).getHandle().applyPhysics(
          new BlockPosition(block.getX(), block.getY(), block.getZ()),
          CraftMagicNumbers.getBlock(block).fromLegacyData(block.getData()).getBlock(), true);
      }
    That should work. Worked for me when I used it.
     
  9. Sorry for annoying you, but I found this snippet 20mins ago in the internet and tried it (also yours), but it didn't work. Tried it in 1.11 too.
     
  10. Are you using a command or an event? If it's an event be sure of use the @EventHandler (priority = EventPriority.HIGHEST)
     
  11. I know, I'm using an event. I'm making a Block-Placer plugin... And everything worked except that.
    But I found a solution to fix it.
    Just change the data of a nearby block and change it back. That causes a block update.
    Thanks.
     
  12. Okay, please mark the thread as Solved
     
  13. Yes, I just wanted to do it.
     
  14. Okay, and if you don't care edit the question and add how you fixed it for future users.