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

Solved Event Listener Question...

Discussion in 'Development' started by LinuxLogo, Dec 12, 2017.

  1. LinuxLogo

    LinuxLogo Spider

    Messages:
    8
    GitHub:
    jrodr10
    Hello i'm simply trying to cancel the ability for a player to break a block in a set region. That has been accomplished although there is a bug. I was wondering if someone could help me squash it.

    Bug: When player breaks the block the event is canceled so they block ins't broken but the item still goes to the players inventory. I'd like to know how i can make it so either
    A. That doesn't happen
    or
    B. it check the item that was placed in the inventory and replaces it with air

    PHP:
        public function onPlayerInteract(PlayerInteractEvent $event) : void
        
    {
            
    $region $this->plugin->getRegionFromPos($event->getBlock());
            if (
    $region !== null) {
                if (!
    $region->canEdit($event->getPlayer())) {
                    
    $event->setCancelled();
                }
            }
        }
      
        public function 
    onPlayerExhaust(PlayerExhaustEvent $event) : void
        
    {
            
    $player $event->getPlayer();
            if (isset(
    $this->playerRegions[$k $player->getId()]) && $this->playerRegions[$k]->hasFlag(RegionFlags::NO_HUNGER)) {
                
    $event->setCancelled();
            }
        }

        public function 
    onBlockPlace(BlockPlaceEvent $event) : void
        
    {
            
    $region $this->plugin->getRegionFromPos($event->getBlock());
            if (
    $region !== null) {
                if (!
    $region->canEdit($event->getPlayer())) {
                    
    $event->setCancelled(true);
                }
            }
        }

        public function 
    onBlockBreak(BlockBreakEvent $event) : void
        
    {
            
    $region $this->plugin->getRegionFromPos($event->getBlock());
            if (
    $region !== null) {
                if (!
    $region->canEdit($event->getPlayer())) {
                    
    $event->setCancelled();
                }
            }
        }
     
    Last edited by a moderator: Dec 12, 2017
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Do you mean the block goes to the player's inventory or the block is dropped?
     
    LinuxLogo likes this.
  3. LinuxLogo

    LinuxLogo Spider

    Messages:
    8
    GitHub:
    jrodr10
    The block goes into the players inventory
     
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Are you using a plugin that automatically sends the block to the player's inventory rather than dropping?
     
  5. Remarkabless

    Remarkabless Slime

    Messages:
    83
    GitHub:
    Remakem
    Set the block drops to air.
     
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    You may want to have a look at the event priorities.
     
  7. LinuxLogo

    LinuxLogo Spider

    Messages:
    8
    GitHub:
    jrodr10
    That was the problem, my core plugin for some strange reason i added it to set a block to player inventory on break.. i'll have to test more to see if i broke anything but thank you for the help guys
     
  8. LinuxLogo

    LinuxLogo Spider

    Messages:
    8
    GitHub:
    jrodr10
    is there a new method for Explosions or Position?

    public function add5(Block $block){
    $task = new timeBomb($this->main, $block, 6);
    $h = $this->main->getServer()->getScheduler()->scheduleRepeatingTask($task, 10);
    $task->setHandler($h);
    }
    this make it the torch tick but no explosion is caused
     
  9. XenialDan

    XenialDan Baby Zombie

    Messages:
    141
    GitHub:
    thebigsmilexd
    Does that still relate to the first issue, or has the first issue been fixed?

    BTW, some microoptimisation:
    PHP:
    $event->setCancelled($region->canEdit($event->getPlayer()));
     
  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.