Solved Make player mine a block

Discussion in 'Spigot Plugin Development' started by DonErtAZ, Jun 8, 2017.

  1. Is there a way to break a block in the World with the plugin, but make it seem like a player did it? So it would run the blockbreak even automatically.

    Probably a poor explanation, but I don't really know how to explain it otherwise.

    I've tried
    Code (Text):
    this just breaks the block and drops it, enchantments on the item doesn't affect the drops and the blockbreak event doesn't run because of it. Is there another way?
  2. You can create any event you like and send it into the server via:


    If you do this in a listener for the same event you want to inject into the server then you'll want to create your own class which extends it so your listener doesn't recursively call itself until the stack pops. For example:

    For an example of injecting the event:
    • Informative Informative x 1
  3. @basicmark Thanks for your reply!
    I don't want to make a new event. If there's a way to do it, I want to break a block at a certain location, but make it as if it was a player who broke it, so it would trigger blockbreak event, so other plugins could do their thing on the block break. Does that make sense?
    • Creative Creative x 1
  4. What are you trying to make?
  5. It's a Little complicated but all in all it's just that I have a location, where there is a block, which I want it to seem like a player mined without actually doing it, so it would apply enchantments of the pickaxe in hand and other plugins could do their thing with blockbreak event and stuff..
    Just wondering if there's a way to do it like that, or if I would have to find another way?
  6. Code (Text):
    getServer().getPluginManager().callEvent(new BlockBreakEvent(block, player) );
    I don't think there is a way around calling a new event, but you basically just have to give the block and the player in order for the other plugins to recognize the block break
    • Informative Informative x 1
  7. @ChristopherSend
    Oh I must of understood it wrong when @basicmark was telling me about calling the event. I understood it as doing something different than what I wanted, but calling the BlockBreakEvent Works perfectly the way I need it to. Thanks to you both!

    Solved thanks to @basicmark and @ChristopherSend :)
    Solved using:
    Code (Text):
    getServer().getPluginManager().callEvent(new BlockBreakEvent(location.getBlock(), player));
    • Like Like x 1
    • Friendly Friendly x 1