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

Breaking blocks is not blocked

Comments in 'Plugin Development' started by pub4game, Sep 22, 2015.

Thread Status:
Not open for further replies.
  1. pub4game
    Offline

    pub4game New Member

    Joined:
    Feb 28, 2015
    Posts:
    30
    Why not block breaking blocks?


    PHP:
    <?php

    namespace LDX\BanItem;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Player;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\event\block\BlockPlaceEvent;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\event\entity\EntityDamageEvent;
    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;
    use 
    pocketmine\event\player\PlayerItemConsumeEvent;
    use 
    pocketmine\event\entity\EntityShootBowEvent;
    use 
    pocketmine\utils\TextFormat;

    class 
    Main extends PluginBase implements Listener {

      public function 
    onEnable() {
        
    $this->saveItems();
        
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
        
    $this->getLogger()->info("§aBanItem §aуспешно загружен!");
      }

        public function 
    onDisable(){
            
    $this->getLogger()->info("§cBanItem §cуспешно выключен!");
        }

      public function 
    onTouch(PlayerInteractEvent $event) {
        
    $p $event->getPlayer();
        if(
    $this->isBanned($event->getItem())) {
          if(!(
    $p->hasPermission("banitem") || $p->hasPermission("banitem.*") || $p->hasPermission("banitem.bypass"))) {
            
    $p->sendMessage(TextFormat::RED "[BanItem] Данный предмет заблокирован!");
            
    $event->setCancelled();
          }
        }
      }

      public function 
    onBlockPlace(BlockPlaceEvent $event) {
        
    $p $event->getPlayer();
        if(
    $this->isBanned($event->getItem())) {
          if(!(
    $p->hasPermission("banitem") || $p->hasPermission("banitem.*") || $p->hasPermission("banitem.bypass"))) {
            
    $event->setCancelled();
          }
        }
      }

      public function 
    onBlockBreak(BlockBreakEvent $event) {
        
    $p $event->getPlayer();
        if(
    $this->isBanned($event->getItem())) {
          if(!(
    $p->hasPermission("banitem") || $p->hasPermission("banitem.*") || $p->hasPermission("banitem.bypass"))) {
            
    $event->setCancelled();
          }
        }
      }

      public function 
    onHurt(EntityDamageEvent $event) {
        if(
    $event instanceof EntityDamageByEntityEvent && $event->getDamager() instanceof Player) {
          
    $p $event->getDamager();
          if(
    $this->isBanned($p->getInventory()->getItemInHand())) {
            if(!(
    $p->hasPermission("banitem") || $p->hasPermission("banitem.*") || $p->hasPermission("banitem.bypass"))) {
              
    $p->sendMessage(TextFormat::RED "[BanItem] Данный предмет заблокирован!");
              
    $event->setCancelled();
            }
          }
        }
      }

      public function 
    onEat(PlayerItemConsumeEvent $event) {
        
    $p $event->getPlayer();
        if(
    $this->isBanned($event->getItem())) {
          if(!(
    $p->hasPermission("banitem") || $p->hasPermission("banitem.*") || $p->hasPermission("banitem.bypass"))) {
            
    $p->sendMessage(TextFormat::RED "[BanItem] Данный предмет заблокирован!");
            
    $event->setCancelled();
          }
        }
      }

      public function 
    onShoot(EntityShootBowEvent $event) {
        if(
    $event->getEntity() instanceof Player) {
          
    $p $event->getEntity();
          if(
    $this->isBanned($event->getBow())) {
            if(!(
    $p->hasPermission("banitem") || $p->hasPermission("banitem.*") || $p->hasPermission("banitem.bypass"))) {
              
    $p->sendMessage(TextFormat::RED "[BanItem] Данный предмет заблокирован!");
              
    $event->setCancelled();
            }
          }
        }
      }

      public function 
    onCommand(CommandSender $p,Command $cmd,$label,array $args) {
        if(!isset(
    $args[0]) || !isset($args[1])) {
          return 
    false;
        }
        
    $item explode(":",$args[1]);
        if(!
    is_numeric($item[0]) || (isset($item[1]) && !is_numeric($item[1]))) {
          
    $p->sendMessage(TextFormat::GREEN "[BanItem] Пожалуйста,используйте ID предмета и повреждения, если это необходимо.");
          return 
    true;
        }
        if(
    $args[0] == "ban") {
          
    $i $item[0];
          if(isset(
    $item[1])) {
            
    $i $i "#" $item[1];
          }
          if(
    in_array($i,$this->items)) {
            
    $p->sendMessage(TextFormat::RED "[BanItem] Данный предмет уже заблокирован!");
          } else {
            
    array_push($this->items,$i);
            
    $this->saveItems();
            
    $p->sendMessage(TextFormat::RED "[BanItem] Данный предмет " str_replace("#",":",$i) . " был заблокирован.");
          }
        } else if(
    $args[0] == "unban") {
          
    $i $item[0];
          if(isset(
    $item[1])) {
            
    $i $i "#" $item[1];
          }
          if(!
    in_array($i,$this->items)) {
            
    $p->sendMessage(TextFormat::RED "[BanItem] Данный предмет не был заблокирован!");
          } else {
            
    array_splice($this->items,array_search($i,$this->items),1);
            
    $this->saveItems();
            
    $p->sendMessage(TextFormat::GREEN "[BanItem] Данный предмет " str_replace("#",":",$i) . " был разблокирован.");
          }
        } else {
          return 
    false;
        }
        return 
    true;
      }

      public function 
    isBanned($i) {
        if(
    in_array(strval($i->getID()),$this->items,true) || in_array(($i->getID() . "#" $i->getDamage()),$this->items,true)) {
          return 
    true;
        }
        return 
    false;
      }

      public function 
    saveItems() {
        if(!isset(
    $this->items)) {
          if(!
    file_exists($this->getDataFolder() . "items.json")) {
            @
    mkdir($this->getDataFolder());
            
    file_put_contents($this->getDataFolder() . "items.json",json_encode(array()));
          }
          
    $this->items json_decode(file_get_contents($this->getDataFolder() . "items.json"),true);
        }
        @
    mkdir($this->getDataFolder());
        
    file_put_contents($this->getDataFolder() . "items.json",json_encode($this->items));
      }

    }
    ?>
  2. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    event is not cancelled?
  3. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    1- the item your are hold is not banned
    2- maybe permission bug ?
  4. pub4game
    Offline

    pub4game New Member

    Joined:
    Feb 28, 2015
    Posts:
    30
    Yes, the blocks still break
  5. pub4game
    Offline

    pub4game New Member

    Joined:
    Feb 28, 2015
    Posts:
    30
    The unit accurately blocked, it is not put, but breaks down
  6. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Wait for @LDX to push an update to it.
  7. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    The events need to be cancelled.

    PHP:
    $event->setCancelled(true);
  8. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    Are you op?
  9. pub4game
    Offline

    pub4game New Member

    Joined:
    Feb 28, 2015
    Posts:
    30
    No
  10. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    251
    Minecraft User:
    RekkuzaRage
    I haven't seen @LDX lately. He is always busy.
Thread Status:
Not open for further replies.

Share This Page

Advertisement