Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Messages are being sent twice

Comments in 'Plugin Development' started by minebuilder0110, Dec 20, 2015.

  1. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    The plugin I have recently created uses sendMessage to send a message(obviously). However, what I have noticed is that the plugin sends the message twice. I don't even know how to code it so that it repeats like that, so it is not done on purpose. This have never happened with other plugins I have created. The message is sent when the PlayerInteractEvent is triggered. I cannot access my laptop yet, and therefore I cannot provide the code.
    (I know there must be like 20 other people who had same issue. I tried searching, but it only returned results that contains the word message only. Then I tried searching the word 'twice' and 'sent twice', but it says it is too common. WTF?)
  2. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    That's lag
    AndrewBit likes this.
  3. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    No -_-
    I get the message back instantly and I tested it multiple times. If it was lag, I would obviously know that.
  4. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Show your code please (or parts of it) and it could be a pocketmine bug
  5. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    PHP:
        public function onPlayerTouch(PlayerInteractEvent $event){
            
    $player $event->getPlayer();
            
    $block $event->getBlock();
            
    $name $event->getPlayer()->getName();
            if(
    $block->getID() == 63 || $block->getID() == 68){
                
    $player->sendMessage("Step 1");
    //This is sent twice
                
    $sign $block->getLevel()->getTile($block);
                
    $text $sign->getText();
                if(
    strtolower($text[0]) === "[checkpoint]"){
                
    $this->cp->setNested($text[1] . "." $text[2], $name);
                
    $this->cp->save();
                
    $player->sendMessage("Step 2!");
    //This is sent twice
                
    switch(substr($text[2], -1)){
                    case 
    "1":
                    if(
    $text[2] === 11) {
                        
    $th "th";
                        }
                        else {
                        
    $th "st";
                        }
                        break;
                    case 
    "2":
                    if(
    $text[2] === 12) {
                        
    $th "th";
                        }
                        else {
                        
    $th "nd";
                        }
                        break;
                    case 
    "3":
                    if(
    $text[2] === 13) {
                        
    $th "th";
                        }
                        else {
                        
    $th "rd";
                        }
                        break;
                    default:
                    
    $th "th";
                    break;
                }
    //My coding style sucks :(
                
    $player->sendMessage("You have arrived at the " $text[2] . $th " checkpoint in the parkour " $text[1] . ".");
    //This is sent twice
                
    }
            }
        }
    The message saying step 1 and step 2 was for debug purpose previously. They are being displayed twice too.
  6. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    As @Skullex said, this is lag.
    Maybe it's not your fault, the problem can be on your server hosting.
  7. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    If it is lag, doesn't the message have delays?

    The thing is, that people had similar issue before, but the solution there wasn't suitable for $this. I hosted it locally, the ping is pretty low, yet it still does that. The most important point is that it doesn't happen with other plugins.

    EDIT: Just found someone with same issue:
    https://forums.pocketmine.net/threads/playerchatevent-runs-twice.10177/
    Last edited: Dec 20, 2015
    Vaivez66 likes this.
  8. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    I thought you meant like, when you type a command like to and it says you have teleported to player at least 5 times. Sorry xD
  9. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Hm… I tried your code in my plugin for testing and it was ony sent once. Either your PC is laggy or the client has bad connection.
  10. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    its a client bug
    HotFireyDeath likes this.
  11. Timmpann
    Offline

    Timmpann New Member

    Joined:
    Feb 5, 2015
    Posts:
    24
    Minecraft User:
    Timmpann
    That's my thread, and I found out what was wrong, an epic fail by me. I had registered events twice by mistake.

    Check if you have this line on more than one place in the plugin:
    PHP:
    $this->getServer()->getPluginManager()->registerEvents($this$this);
  12. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    I'm having the same problem; it's weird.
    minebuilder0110 likes this.
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No. If you register more than once, on the same Listener instance, PocketMine will reject it the second time.
    Any two handlers that belong to the same object (actually, or two objects with the same spl_object_hash) with the same priority and event (forgot if ignore cancelled matters), even if of different method names and/or different instances (but same properties can make them have the same hash), will be recognized as identical event handlers.
  14. Timmpann
    Offline

    Timmpann New Member

    Joined:
    Feb 5, 2015
    Posts:
    24
    Minecraft User:
    Timmpann
    Okay, weird. My problem was fixed by removing one of them.

Share This Page

Advertisement