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

Event Not Canceling

Discussion in 'Development' started by Junkdude, Jan 7, 2017.

  1. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Im working ona custom protection plugin and the event isnt cancelling/working, the coords are right in the config and everything, no errors, just doesnt work,CODE:
    PHP:
    <?php
    namespace Junkdude;
    use 
    Junkdude\Shop;
    use 
    Junkdude\EntityDamage;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\event\block\SignChangeEvent;
    use 
    pocketmine\event\player\{
        
    PlayerGameModeChangeEventPlayerChatEventPlayerCommandPreprocessEventPlayerDeathEventPlayerHungerChangeEventPlayerInteractEventPlayerItemConsumeEventPlayerItemHeldEventPlayerLoginEventPlayerQuitEventPlayerDropItemEvent
    };
    use 
    pocketmine\event\entity\{
        
    EntityArmorChangeEventEntityDamageByEntityEventEntityDamageEventEntityTeleportEventEntityExplodeEventExplosionPrimeEventEntitySpawnEventEntityRegainHealthEvent
    };
    use 
    pocketmine\level\particle\{
        
    AngryVillagerParticleBubbleParticleCriticalParticleDustParticleEnchantParticleEnchantmentTableParticleExplodeParticleFlameParticleFloatingTextParticleGenericParticleHappyVillagerParticleHeartParticleHugeExplodeParticleInkParticleInstantEnchantParticleItemBreakParticleLargeExplodeParticleLavaDripParticleLavaParticleMobSpawnParticleParticlePortalParticleRedstoneParticleSmokeParticleSplashParticleSporeParticleTerrainParticleWaterDripParticleWaterParticle
    };
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\item\enchantment\Enchantment;
    use 
    pocketmine\inventory\ShapedRecipe;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\TextFormat as TF;
    use 
    pocketmine\Server;
    use 
    pocketmine\nbt\NBT;
    use 
    pocketmine\level\format\FullChunk;
    use 
    pocketmine\entity\Entity;
        use 
    pocketmine\entity\Human;
        use 
    pocketmine\nbt\tag\ByteTag;
        use 
    pocketmine\nbt\tag\CompoundTag;
        use 
    pocketmine\nbt\tag\DoubleTag;
        use 
    pocketmine\nbt\tag\FloatTag;
        use 
    pocketmine\nbt\tag\IntTag;
        use 
    pocketmine\nbt\tag\ListTag;
        use 
    pocketmine\nbt\tag\ShortTag;
        use 
    pocketmine\nbt\tag\StringTag;
        use 
    pocketmine\entity\Villager;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\tile\{
        
    TileChestMobSpawner
    };
    use 
    pocketmine\math\AxisAlignedBB;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\event\block\BlockPlaceEvent;
    use 
    pocketmine\command\{
        
    CommandCommandSenderConsoleCommandSender
    };
    class 
    Main extends PluginBase implements Listener{
        public function 
    onEnable() {
        
    ##EXTERNAL PLUGIN ROUTES###
        
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        
    $this->getServer()->getPluginManager()->registerEvents(new Rewards($this), $this);
        
    $this->getServer()->getPluginManager()->registerEvents(new EntityDamage($this), $this);
        
    $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this);
        
    ##CONFIG STUFF##
            
    @mkdir($this->getDataFolder());
            
    $cfg = new Config($this->getDataFolder() . "xyz.yml"Config::YAML);
            
    $data $cfg->get("X1""X2""Y1""Y2""Z1""Z2");
            
    $file = ($this->getdatafolder() . "xyz.yml");
            if(!
    file_exists($file)){
                   
    $cfg->set("X1"100);
            
    $cfg->set("X2"100);
            
    $cfg->set("Y1"100);
            
    $cfg->set("Y2"100);
            
    $cfg->set("Z1"100);
            
    $cfg->set("Z2"100);
            
    $cfg->save();
            }
    }

    public function break(
    BlockBreakEvent $event){
        
    $p $event->getPlayer();
        
    $cfg = new Config($this->getDataFolder() . "xyz.yml"Config::YAML);
        
    $x $p->getX();
        
    $y $p->getY();
        
    $z $p->getZ();
        
    $x1 $cfg->get("X1");
        
    $x2 $cfg->get("X2");
        
    $y1 $cfg->get("Y1");
        
    $y2 $cfg->get("Y2");
        
    $z1 $cfg->get("Z1");
        
    $z2 $cfg->get("Z2");
        if(
    $x1 <= $x and $x <= $x2 and $y1 <= $y and $y <= $y2 and $z1 <= $z and $z <= $z2){
            
    $event->setCancelled(true);
            
    $p->sendmessage("test");
        }else if(!
    $x1 <= $x and $x <= $x2 and $y1 <= $y and $y <= $y2 and $z1 <= $z and $z <= $z2){
            
    $p->sendmessage("NBHKMBL");
        }
    }
    }
     
  2. imYannic

    imYannic Baby Zombie

    Messages:
    113
    Debug after every if condition!
    // var_dump("Still works at line ".__LINE__);
     
    applqpak likes this.
  3. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    wut do i put as _LINE_
     
  4. imYannic

    imYannic Baby Zombie

    Messages:
    113
    __LINE__ is a magic constant of PHP, just leave it like this, it shows the line of itself.
     
    Muqsit, HimbeersaftLP and applqpak like this.
  5. applqpak

    applqpak Spider Jockey

    Messages:
    27
    GitHub:
    applqpak
    Nothing, it's a magic constant... are you sure you know the basics of PHP yet? why are you developing plugins?
     
    Muqsit and HimbeersaftLP like this.
  6. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    nope
    , isnt dumping it
     
  7. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    No, i dont know the basics of php, again I learned/learning by looking at plugins
     
  8. imYannic

    imYannic Baby Zombie

    Messages:
    113
    The use print_r(), Player::sendMessage(), $this->getLogger()->info() or $this->getServer()->broadcastMessage() instead of var_dump().
     
    applqpak likes this.
  9. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    I alread have sendmessage on there
     
  10. imYannic

    imYannic Baby Zombie

    Messages:
    113
    Me too, same goes for my first programming language I learned, but I cant go without PHP.net, seriously have you never wondered how to chunk an array in parts or what functions a library has? You will surely need it in the future.
     
    HimbeersaftLP and applqpak like this.
  11. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    I probably will, one issue at a time though i guess
     
  12. imYannic

    imYannic Baby Zombie

    Messages:
    113
    And what does it output?


    If __LINE__ somehow doesn't work, then use numbers for each dump, so you can identify them by the number and look up which conditions were executed by checking if their dump was broadcasted.
     
    applqpak likes this.
  13. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    it outputs absolutely nothing, it just doesnt run...
     
  14. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    KKm i took out the lines that are hashtagged and it worked, it has something to do with the lines or variables
    PHP:
    public function break(BlockBreakEvent $event){
        
    $p $event->getPlayer();
        
    $cfg = new Config($this->getDataFolder() . "xyz.yml"Config::YAML);
        
    $x $p->getX();
        
    $y $p->getY();
        
    $z $p->getZ();
        
    $x1 $cfg->get("X1");
        
    $x2 $cfg->get("X2");
        
    $y1 $cfg->get("Y1");
        
    $y2 $cfg->get("Y2");
        
    $z1 $cfg->get("Z1");
        
    $z2 $cfg->get("Z2");
        
    ##if($x1 <= $x and $x <= $x2 and $y1 <= $y and $y <= $y2 and $z1 <= $z and $z <= $z2){
            
    $p->sendmessage("test");
        
    ##}else if(!$x1 <= $x and $x <= $x2 and $y1 <= $y and $y <= $y2 and $z1 <= $z and $z <= $z2){
            
    $p->sendmessage("NBHKMBL");

        
    ##}
    }
    }
     
  15. eDroid

    eDroid Witch

    Messages:
    59
    GitHub:
    edroiid
    what are you trying to do? also can you give an example of what x x1 x2 etc values are?
     
    applqpak likes this.
  16. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    trying to cancel an event if a player is in those coords/out of them. The values are in my config
    Code:
    ---
    X1: 214
    Y1: 74
    Z1: 1
    X2: 210
    Y2: 69
    Z2: 4
    ...
    
     
  17. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
  18. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
  19. xZeroMCPE

    xZeroMCPE Witch

    Messages:
    67
    GitHub:
    xZeroMCPE
    Here's something:

    PHP:
    if($p->>= $this->min[0] and $p-><= $this->max[0] and $p->>= $this->min[1] and $p-><= $this->max[1] and $p->>= $this->min[2] and $p-><= $this->max[2]){

    $p->sendMessage("You are in a region");

    } else {

    $p->sendMessage("You are not in a region!");

    }
    }
    Don't copy it, but instead, learn from it...

    Well, You can. Just define the vars, and such....
     
    applqpak likes this.
  20. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Still not doing anything
    PHP:
    public function break(BlockBreakEvent $event){
        
    $p $event->getPlayer();
        
    $cfg = new Config($this->getDataFolder() . "xyz.yml"Config::YAML);
        
    $x $p->getX();
        
    $y $p->getY();
        
    $z $p->getZ();
        
    $x1 214;
        
    $x2 210;
        
    $y1 74;
        
    $y2 69;
        
    $z1 1;
        
    $z2 4;
        if(
    $x >= $x1 and $x <= $x2 and $y >= $y1 and $y <= $y2 and $z >= $z1 and $z <= $z2){

            
    $p->sendmessage("In Region");
        }else if(!
    $x >= $x1 and $x <= $x2 and $y >= $y1 and $y <= $y2 and $z >= $z1 and $z <= $z2){
            
    $p->sendmessage("Not In Region");

        }
    }
     
  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.