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

What is the problem?

Comments in 'Plugin Development' started by Legoboy0215, Jun 19, 2015.

  1. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    I have a problem with my protection plugin. Here is my code..
    PHP:
    <?php

    namespace AntiGrief;

    use 
    pocketmine\block\BurningFurnace;
    use 
    pocketmine\block\Chest;
    use 
    pocketmine\block\Furnace;
    use 
    pocketmine\block\IronDoor;
    use 
    pocketmine\block\Lava;
    use 
    pocketmine\block\Stonecutter;
    use 
    pocketmine\block\Trapdoor;
    use 
    pocketmine\block\Water;
    use 
    pocketmine\block\WoodDoor;
    use 
    pocketmine\block\Workbench;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\event\block\BlockPlaceEvent;
    use 
    pocketmine\event\player\PlayerBucketEmptyEvent;
    use 
    pocketmine\event\player\PlayerBucketFillEvent;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\Player;

    class 
    Main extends PluginBase implements Listener{
       
        public function 
    onEnable(){
                
    $this->getServer()->getPluginManager()->registerEvents($this$this);
                
    $this->getLogger()->info(TextFormat::GREEN."Enabling ".$this->getDescription()->getFullName()."...");
        }
       
        public function 
    onDisable(){
            
    $this->getLogger()->info(TextFormat::RED."Disabling ".$this->getDescription()->getFullName()."...");
        }
       
        public function 
    onPlaceBreak(BlockPlaceEvent $event){
            
    $player $event->getPlayer();
            if(
    $player->getLevel()->getName()=="survival"){
                
    $event->setCancelled(false);
            }else 
    $event->setCancelled(true);
        }
       
        public function 
    onBlockPlace(BlockPlaceEvent $event){
            
    $player $event->getPlayer();
            if(
    $player->getLevel()->getName()=="survival"){
                
    $event->setCancelled(false);
            }else 
    $event->setCancelled(true);
        }
       
        public function 
    onPlayerBucketEmpty(PlayerBucketEmptyEvent $event){
            
    $player $event->getPlayer();
            if(
    $player->getLevel()->getName()=="survival"){
                
    $event->setCancelled(false);
            }else 
    $event->setCancelled(true);
        }
       
        public function 
    onPlayerBucketFill(PlayerBucketFillEvent $event){
            
    $player $event->getPlayer();
            if(
    $player->getLevel()->getName()=="survival"){
                
    $event->setCancelled(false);
            }else 
    $event->setCancelled(true);
        }
    }
    But I can still break and place and do anything in the world called "spawn"!!! I am not op, but I can still do that.
  2. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    And if player getlevelbynane Or get name(I think is the first one) is survival, I think u should set cancelled true not false
    Last edited: Jun 19, 2015
  3. PixelGuy75
    Offline

    PixelGuy75 Notable Member Plugin Developer

    Joined:
    Feb 9, 2014
    Posts:
    316
    Plugins:
    2
    Minecraft User:
    PixelGuy75
    Try that. I changed getName() to get LevelByName()

    PHP:
    <?php

    namespace AntiGrief;

    use 
    pocketmine\block\BurningFurnace;
    use 
    pocketmine\block\Chest;
    use 
    pocketmine\block\Furnace;
    use 
    pocketmine\block\IronDoor;
    use 
    pocketmine\block\Lava;
    use 
    pocketmine\block\Stonecutter;
    use 
    pocketmine\block\Trapdoor;
    use 
    pocketmine\block\Water;
    use 
    pocketmine\block\WoodDoor;
    use 
    pocketmine\block\Workbench;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\event\block\BlockPlaceEvent;
    use 
    pocketmine\event\player\PlayerBucketEmptyEvent;
    use 
    pocketmine\event\player\PlayerBucketFillEvent;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\Player;

    class 
    Main extends PluginBase implements Listener{
      
        public function 
    onEnable(){
                
    $this->getServer()->getPluginManager()->registerEvents($this$this);
                
    $this->getLogger()->info(TextFormat::GREEN."Enabling ".$this->getDescription()->getFullName()."...");
        }
      
        public function 
    onDisable(){
            
    $this->getLogger()->info(TextFormat::RED."Disabling ".$this->getDescription()->getFullName()."...");
        }
      
        public function 
    onPlaceBreak(BlockPlaceEvent $event){
            
    $player $event->getPlayer();
            if(
    $player->getLevel()->getName()=="survival"){
                
    $event->setCancelled(false);
            }else 
    $event->setCancelled(true);
        }
      
        public function 
    onBlockPlace(BlockPlaceEvent $event){
            
    $player $event->getPlayer();
            if(
    $player->getLevel()->getName()=="survival"){
                
    $event->setCancelled(false);
            }else 
    $event->setCancelled(true);
        }
      
        public function 
    onPlayerBucketEmpty(PlayerBucketEmptyEvent $event){
            
    $player $event->getPlayer();
            if(
    $player->getLevel()->getLevelByName()=="survival"){
                
    $event->setCancelled(false);
            }else 
    $event->setCancelled(true);
        }
      
        public function 
    onPlayerBucketFill(PlayerBucketFillEvent $event){
            
    $player $event->getPlayer();
            if(
    $player->getLevel()->getLevelByName()=="survival"){
                
    $event->setCancelled(false);
            }else 
    $event->setCancelled(true);
        }
    }
    Falk likes this.
  4. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    I will try it... Thanks! &, I want people to build in only survival, so I think it is right..
  5. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    Your first code is correct. Its just that you have it checking to see if the player is in the world "survival" not "spawn".

    You also have two of the exact same events.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What the
    If you don't understand, don't reply. You are making the situation worse.

    The problem is, setCancelled() or setCancelled(true) cancels the event, and setCancelled(false) un-cancels the event.
    Last edited by a moderator: Jun 19, 2015
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Sorry. It was my fault. I forgot to change the blockplace to block break XD
  8. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    already explain all in #2

Share This Page

Advertisement