1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Interact Spam?

Discussion in 'Development' started by DanDen, Jun 11, 2018.

  1. DanDen

    DanDen Spider

    Messages:
    11
    Hello, I'm creating a give-kit with PlayerInteractEvent I realized that the function is repeated several times.
    Is it a bug or am I doing something wrong?
    PHP:
     public function onInteract(PlayerInteractEvent $event) {
    $event->getPlayer()->getInventory()->addItem(Item::get(30,0));
    }
     
  2. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    can you explain more? when player interacts with something it will give that item with id 30, that is what i see in your code..
    how it should really work for you?
     
  3. DanDen

    DanDen Spider

    Messages:
    11
    When I run the event the item is given to me 5 times!
     
  4. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    is because you have to identify what you need to interact, there are several modes of interaction in this event and it must be why you receive 5 times the same item, another way would be by adding an array and blocking from receiving the item more than once
     
  5. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Yes it's a bug because the game doesn't provide a legitimate way for servers to find out whether the player right clicked a block.
     
    Last edited: Aug 1, 2018
    corytortoise, Winchester and DanDen like this.
  7. Winchester

    Winchester Baby Zombie

    Messages:
    133
    Has anyone discovered any way to combat this problem?
     
  8. Aviv

    Aviv Baby Zombie

    Messages:
    156
    Make a delay for the event to the player that has right clicked a block OR disable all right click block interact events that are being runned from the same player in a 100ms window(So the event runs once, and after that it gets ignored)(This doesn't fully work because a player can just look at air and look at blocks back and it counts as another interaction)

    You can't fully counter it because Mojang did a /f*** all

    EDIT: OH WAIT! This thread is 2 months old? Bruh
     
    Last edited: Aug 1, 2018
  9. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    PHP:
    switch(mt_rand(15)){
        case 
    5:
            
    $event->setCancelled(false);
            break;
        default:
            
    $event->setCancelled();
            break;
    }
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.