Current mining block

Discussion in 'Spigot Plugin Development' started by Elikill58, Oct 12, 2019.

  1. Hello,

    I want to know what is the type of the current block which is mined by a specific player.
    How can i do it ?
    (I'm on 1.8)
    I know when the player is mining that to "ar" variable in "EntityPlayer", but i don't know what is the current item mined.
    • Like Like x 1
  2. I know on later versions you can check an armswing event, cant you do left click block on interactevent?
  3. I can use an InteractEvent because it's only on the first click, when you stay clicking, i haven't any event. When you stop, clicking, no event and if you change the block that you're mining, no event.
  4. Gadse

    Gadse Previously GummiBoat

    If you want to know, when a player leftclicked a block, use PlayerInteractEvent#getClickedBlock.
    If you want to know, when a player broke a block, use the BlockBreakEvent #getBlock
    You should really only use one of them, unless you want to calculate the time between clicking and breaking it, but I don't think that's what you actually need.
    • Like Like x 1
    • Agree Agree x 1
  5. I didnt understand his question. But i think hes wanting what block is being mined, but not fully broken?
  6. Use the BlockBreakEvent, if you don't want it to break just cancel it
  7. Hello,

    Yes, i want to now which block the player is mining, but not broken. That's why i cannot use BlockBreakEvent...
    I want to add the FastDigging potion effect when the player is mining obsidian.
  8. PlayerInteractEvent -> Action left click block -> p.addPotionEffect#PotionEffectType.DIG_SPEED

    not tested but I think this is the easiest way since it gets triggered once when clicking on it
  9. Yes but how to know when the player stop to click, to stop the effect ?
    • Agree Agree x 1
  10. With the API there is no way (Neither in the current version, for sure not in 1.8). You need to use ProtocolLib and work your way out with player digging packet, check for the type of dig, be sure is stop or abort and then remove the effect.
    • Informative Informative x 1
  11. So you think that analyze packet is the alone way to do that ?
  12. To know when a player has stopped mining, yes. The API only allow you to check when the block is broken.
    • Agree Agree x 1
  13. Do this, and on block break event if the player had the potion effect remove it. To prevent removing unwanted effects you could add player names to a list in the player interact event, and then check if the player was in the list in the block break event.

    Players could technically abuse this but it would require clicking an obsidian block before everytime they break a block.
  14. All you need to do is keep track of who you've given the effect to. If they break the block, you remove the effect. If they start breaking another block (interact with it), you remove the effect.
    • Agree Agree x 2
  15. The main problem is, if they start to break an obsidian, j'ai will get the effect. But, if they never break this block, they will always have the effect.
    That's a problem.
    But i will make it thanks to packets. I don't put my thread in solved, i will do it after editing my first post (and put in the code which solve the problem).
  16. You should be able to listen to the BlockDamageEvent for an API-only solution.

    Edit: Also, I believe you misunderstood drives_a_ford, that's a perfectly valid solution. On block interact, if obsidian give effect, else remove effect.
    • Agree Agree x 1
  17. Gadse

    Gadse Previously GummiBoat

    Why give them a fast digging potion effect, if you can use Block#breakNaturally ... Then you don't need to worry about taking it away either.
  18. Unless the OP wants it destroyed instantly (which he's not stated so I'll assume he doesn't), that would still require you to know whether or not the player has been continuously mining up until that point.

    The only thing I didn't mention was that you'd give the effect for a short amount of time - the amount it takes to do the mining (or slightly more just in case). But I thought that'd be obvious.
    • Agree Agree x 1
  19. Doesn't PlayerInteractEvent fire continuously while mining a block? Why not give a very short Haste effect so that it goes away as soon as you stop mining? Simply do that everytime the event fires.
  20. I was thinking the same, so i have make so test. But no, it's only on the first time.