send popup when breaking blocks and remove when not breaking blocks

Discussion in 'Plugin Development' started by dxrknez, Apr 9, 2018.

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

    dxrknez

    hi, im trying to create a plugin that sends you popup when you break blocks but disables the HUD if you have it on you. And when you stop breaking blocks the HUD shows up in your screen again.

    my code
    Code:
    @EventHandler
    public void onBlockBreak(BlockBreakEvent e) {
    Player p = e.getPlayer();
    
                if (hud.contains(p.getUniqueId())) {
                    p.sendPopup("" + map.get(p.getName()));
    hud.remove(p.getUniqueId());
                }
       //and when they are not breaking blocks anymore i want to send the Hud back up
    }
    
            
    Code:
        public ArrayList<UUID> hud = new ArrayList<UUID>();
    can i get this accepted please

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 10, 2018
  2. Offline

    Zombie_Striker

    @dxrknez
    And what do you need help with? Do you need help trying to detect when the stop digging, or do you need help showing/hiding the HUD?
     
    dxrknez likes this.
  3. Offline

    dxrknez

    detect when the player stops digging
     
  4. Offline

    Zombie_Striker

    @dxrknez
    Listen to PlayerInteractEvent. Detect when a player starts digging with playerinteractevent. Since digging triggers playerinteractevent every half second, if the last time the event was called was more than a second ago, then the player has stopped digging.
     
  5. Offline

    dxrknez

    can't i use blockbreakevent?
     
  6. Offline

    Zombie_Striker

    @dxrknez
    No. BlockBreakEvent is only triggered after you break a block. If the player start to mine a block, blockbreakevent will not trigger.
     
  7. Offline

    dxrknez

    but doesn't PlayerInteractEvent triggers everytime you click?
     
  8. @dxrknez
    Yes but you could check if they are holding a pickaxe
     
  9. Offline

    MightyOne

    I typically use a BukkitRunnable in such cases that perhaps runs every second? In parallel i would use a HashMap<Player, Long> where I store the last time, the system time, a player clicked something. And, well, if the runnable detects that last time is more than... probably half a second ago or the held item changed I'd send the popup
     
Thread Status:
Not open for further replies.

Share This Page