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

lock doors

Comments in 'Plugin Development' started by WillotheBlessed, Oct 1, 2014.

  1. WillotheBlessed
    Offline

    WillotheBlessed Active Member

    Joined:
    Sep 17, 2014
    Posts:
    69
    Minecraft User:
    will
    I'm trying to create an area with locked doors that will be opened on my command, but the doors don't stay locked. They either open then close again, or just stay open. Also, if they player is moving, they just stay open. In other words, it's effectively just annoying and not actually locking the door. Here's my code.

    Code:
    public function onPlayerInteract(PlayerInteractEvent $event)
        {
            if ($this->doorsOpen == true)
            {
                $this->getLogger()->info("door opened!");
                return true;
               
            }
            if ($event->getBlock()->getID() == Block::WOODEN_DOOR_BLOCK )
            {
                $this->getLogger()->info("Tried to open door - access, denied!");
                $event->setCancelled();
            }
        }
    
    Thanks in advance!
    Smarticles101, LDX and MegaSamNinja like this.
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Well, one important but I-don't-think-relavent-to-your-question issue is that there can be multiple doors in an area and you must store the data in an array instead of a single boolean field.
    EvolSoft and Blue Electric like this.
  3. Blue Electric
    Offline

    Blue Electric New Member

    Joined:
    Oct 27, 2013
    Posts:
    27
    Minecraft User:
    BE__
    i think client send door-open signal and open door without server transmittion,

    so... may you try

    PHP:
                $this->getLogger()->info("Tried to open door - access, denied!");
                
    $event->getBlock()->onActivate(null$event->getPlayer());
    to close door, i'm can't test this code because i'm in school
    EvolSoft and LDX like this.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I agree. You can't just cancel the event. You need to additionally send a packet that the door be closed again.

    Still, people can pass through the door during the several hundreds of milliseconds of latency.
    EvolSoft, LDX, Falk and 1 other person like this.
  5. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    I figure you could fix the latency in one of two ways:
    • Detect the layout of the room (or just x blocks, because they can't walk that far) behind the door (you would update it on reload) and then check that the player isn't there. You could have a repeating task and once a player attempts to open a door they are added to the task and will be actively barred from the room for the next x iterations of the task.
    • If a user attempts to open the door you teleport them to themselves (possibly wait a few ticks). Not sure how well that works but it's a lot simpler :)
    Sorry if that makes no sense, it's late :p
    Last edited: Oct 1, 2014
    PEMapModder likes this.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The simplest method is good, but even better if we wait for the player's ping time.
  7. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Why? The teleport is later in the queue than the update packet so it should be sent after and therefore apply after (if we worked with a reliable protocol). It would be best if we could send the teleport when the door update is ACKed or ensure the packets were bundled into one but that doesn't seem possible with RakLib. If you could wait for ACKs on packets then we could block the player from interacting with containers until we get the teleport ACKed (which would be pretty).
    Last edited: Oct 1, 2014
    64FF00 likes this.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    If we send a direct packet...
    64FF00 likes this.
  9. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    I thought of that you have no way of ensuring that one arrives before the other.
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    If they are both in the same CustomPacket, it should have the correct queue.
  11. WillotheBlessed
    Offline

    WillotheBlessed Active Member

    Joined:
    Sep 17, 2014
    Posts:
    69
    Minecraft User:
    will
    This is a nice bit of code. Basically, send another activation message to the door at the exact same moment... and in theory, it will close the door again. Unfortunately, you can still get through the door by pushing against it as you open it, since the door does open on clientside first...

    It seems the only way to do this would be to create a new type of door that can be locked, but I'm not sure that new block types are available yet? Or perhaps it's possible with some php magic to place an override method on all the doors?
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    @Falk and I were talking about after closing the door to the client teleport back the player. We're just having trouble with UDP, which doesn't always send packets in the correct order.
  13. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    As mentioned above, there are multiple ways to prevent a lagging players from going through the door, but at the client side it will look glichy. A solution would be to replace the wooden door with an iron one when someone protects it.
    PEMapModder and LDX like this.
  14. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
    That's genius! That way the client won't even try to open the door, the server will. But can iron doors even be opened yet?
    EvolSoft likes this.
  15. SpiderPig
    Offline

    SpiderPig Active Member

    Joined:
    Sep 21, 2013
    Posts:
    128
    Minecraft User:
    SpiderPig
  16. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
    Last edited: Oct 2, 2014
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Open it when it can be clicked.
    EvolSoft and LDX like this.
  18. WillotheBlessed
    Offline

    WillotheBlessed Active Member

    Joined:
    Sep 17, 2014
    Posts:
    69
    Minecraft User:
    will
    I fixed this issue by putting Sandstone in front of the door, and then lowering the Sandstone in increments of slabs of Sandstone... so it looks cool, and stops them from getting through. IMO, sandstone is pretty good for this. Very Indiana Jones.
    LDX likes this.

Share This Page

Advertisement