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

Cancel damage

Comments in 'Plugin Development' started by AndrewBit, Dec 27, 2015.

  1. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    I want to make all players invencible in a map.
    I don't know why my code isn't working. Can anyone tell me how?
  2. MichaelM04
    Offline

    MichaelM04 Active Member Plugin Developer

    Joined:
    Nov 12, 2015
    Posts:
    213
    Plugins:
    1
    Minecraft User:
    Michael
    Why not just disable PvP in that world?
  3. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    It's a gamemode. But...
    How I can disable the PvP in that world by PHP? I'm not pretty sure how...
  4. MichaelM04
    Offline

    MichaelM04 Active Member Plugin Developer

    Joined:
    Nov 12, 2015
    Posts:
    213
    Plugins:
    1
    Minecraft User:
    Michael
    I'll go check from mine but why not just use a plugin like (PvPWorlds)?
  5. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    I want 100% of the source of my plugin made by me.
  6. MichaelM04
    Offline

    MichaelM04 Active Member Plugin Developer

    Joined:
    Nov 12, 2015
    Posts:
    213
    Plugins:
    1
    Minecraft User:
    Michael
    here's what you might need
    Code:
    public function onPvP(EntityDamageEvent $eventPvP){
       
            if($eventPvP instanceof EntityDamageByEntityEvent){
    
                if($eventPvP->getEntity() instanceof Player && $eventPvP->getDamager() instanceof Player){
                   
                    $map = $eventPvP->getEntity()->getLevel()->getFolderName();
                   
                    if(in_array($map, $this->worlds)){
                       
                        $player = $eventPvP->getDamager();
                       
                        if($this->error == ""){
                           
                            if($this->oppvp == "true" && !$player->isOP() || $this->oppvp != "true"){
                           
                                    $eventPvP->setCancelled();
    
  7. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    if you want DisablePVP ?
    PHP:
    public function onDamage(EntityDamageEvent $los){
    if(
    $los instanceof EntityDamageByEntityEvent) {
    $player $los->getEntity();
    $damger $los->getDamager();
    if(
    $damger instanceof Player) {
    if(
    $this->getServer()->getLevelByName("FLAT")){
    $los->setCancelled();
    $damager->sendMessage("Disable PVP IN The World");
    }
    }
    }
    }
    Skullex and Omar2s2 like this.
  8. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    getLevelByName() returns a level, so it wouldn't work by itself, you gotta make it equal to something.
    PHP:
    public function onDamage(EntityDamageEvent $ede)
    {
    $target $ede->getEntity();
    $damager $ede->getDamager();
    if(
    $damager instanceof Player && $target instanceof Player){
    if(
    $damager->getLevel()->getName()==="levelname"){
    $e->setCancelled();
    }
    }
    }
    Last edited: Dec 28, 2015
  9. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Actually if($this->getServer()->getLevelByName("FLAT")) will work, its because the level object returned will be treated as true, if the returned is null then it will be treated as false. Your code is comparing a level object with a string, which won't work at all and you have a typo at $damage instanceof Player
  10. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    Oh yeah, sirry, I get confused with the api sometimes.

    But that will just check if the level exists and not if the damager is in that world.
  11. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Oh yea, I didn't think about that haha :p

Share This Page

Advertisement