Solved Player breaking block

Discussion in 'Plugin Development' started by Link_Awesomesause, May 17, 2016.

Thread Status:
Not open for further replies.
  1. I am not sure if the solution for this is already on bukkit.. but I did google search to no avail. What I want to do is make a player break a block, or atleast make the server and all other plugins think that way.

    You might say to use block.breakNaturally() but that breaks any block, including bedrock. I am making a plugin that had been requested on the forum for a pickaxe that broke blocks 3x3, and ran into this issue. If the pickaxe has fortune, the blocks should also be affected by this, is there any way to do this.. ?

    Sorry for long post.
     
  2. Offline

    Lolmewn

    Of course. Iterate over all blocks in the 3x3 radius and check if they can be broken (e.g. are not in a blacklist). Break em naturally, add the fortune effect yourself.
     
  3. Offline

    I Al Istannen

    @Link_Awesomesause
    Lolmewn's answer and you can read how fotune works here. Just go to ID 35, which is fortune.
     
  4. Another reason to do this is to make it easy to use with plugins that prevent players from breaking blocks outside a specific area. Your solution will work half way..
     
  5. Offline

    I Al Istannen

    @Link_Awesomesause
    I did the same with a plugin some time ago and ended up hooking into WorldGuard and Residence to solve this. I don't know any other way to solve this problem, without knowing and using the protection plugins in use.

    EDIT: You might also need to check if the player's tool can break the block. You don't want gold to drop if the user uses a wooden pickaxe. Block#breakNaturally(ItemStack) might do it for you though.
     
  6. Offline

    I Al Istannen

    @Link_Awesomesause
    As always, there might be a better way, but I don't know one. Maybe somebody else ;)
    What I said will work too though, so there is that.

    Good luck!
     
  7. Offline

    Lolmewn

    @I Al Istannen A possible fix is to call a BlockBreakEvent and see if it's cancelled when all plugins are done processing it. If not, breaking is allowed!
    As a nice side-effect, this will also then count as block breaks for Stats plugins.
     
    I Al Istannen likes this.
  8. Offline

    I Al Istannen

    @Lolmewn
    Oh yea. I did try that, but I think I had some errors with it. Couldn't possible occur because I used the BlockBreakEvent as the start for my block break methods, leading to an infinite number of method invocations...
    I will do this in the future if I stop being dumb. Thanks for that!
     
    Last edited: May 17, 2016
  9. Offline

    Lolmewn

    @I Al Istannen Heheh, yeah, I can see that happening. A fix would, of course, to store the Block/Location in a Set and check for that when the event is called (+ remove after, ofc). But oh well! Fun stuff :)
     
    I Al Istannen likes this.
Thread Status:
Not open for further replies.

Share This Page