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

Solved Allow players to hit staff in Hub

Discussion in 'Development' started by KinokiYT, May 7, 2020.

  1. KinokiYT

    KinokiYT Spider Jockey

    Messages:
    25
    GitHub:
    kinokiyt
    Hello, I'm making a plugin where certain ranked players with permission can be able to hit staff in the world "Hub". If they have permission, they can be able to hit staff. It will only be knockback; there will be no damage implemented. Is there any way to do that? Thank you!
     
  2. xZeroMCPE

    xZeroMCPE Witch

    Messages:
    67
    GitHub:
    xZeroMCPE
    Code:
        public function staffHit(EntityDamageEvent $event) {
        
            $entity = $event->getEntity();
            
            
            if($entity->getLevel()->getName() == "Your lobby world name?") { // Update this to your lobby world name
                if($entity instanceof Player) {
                    if($event instanceof EntityDamageByEntityEvent) {
                        $player = $event->getDamager();
                        if($player instanceof Player) {
                            if($entity->hasPermission("xzero.staff")) { // Update this to the permission you'd want.
                                $event->setBaseDamage(0);
                                $player->sendMessage("Woah! You hit " . $entity->getName() . ", be a good boy!"); // A little extra
                            }
                        }
                    }
                }
            }
        }
     
  3. KinokiYT

    KinokiYT Spider Jockey

    Messages:
    25
    GitHub:
    kinokiyt
    How would I make it so that the player has to have permission to hit the staff member, and the staff takes knockback?
     
  4. xZeroMCPE

    xZeroMCPE Witch

    Messages:
    67
    GitHub:
    xZeroMCPE
    Duplicate the permission line, but invert the entity, with player.
     
    Draglor56 likes this.
  5. KinokiYT

    KinokiYT Spider Jockey

    Messages:
    25
    GitHub:
    kinokiyt
    Okay, done. What about the knockback?

    [EDIT] I found out from a past thing I made, thanks for the help!
     
    Last edited: May 7, 2020
  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.