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

Solved Need help with my Plugin

Discussion in 'Development' started by WinterBuild7074, May 2, 2017.

  1. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Uhmm, why not just protect the Item Frames?
     
  2. Lowkey

    Lowkey Slime

    Messages:
    94
    Why not just put the item frames out of reach behind the glass pane?
     
  3. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    Yep, I'd do it like that. How about cancelling PlayerInteractEvent when a player taps on an item frame?
     
  4. AnkitM252

    AnkitM252 Spider Jockey

    Messages:
    29
    GitHub:
    AnkitM252
    It will cancel the event but the items can drop! (I saw it somewhere but not sure)
     
  5. Az928

    Az928 Baby Zombie

    Messages:
    140
    GitHub:
    theaz928
    For Player events
    Code:
    $player = $event->getPlayer();
    $level = $player->getLevel(); 
    For Entity events:
    Code:
    $entity = $event->getEntity();
    $level = $entity->getLevel(); 
    Also check how pocketmine uses it...
     
  6. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Yes, but protector plugins doesn't protect the Item Frames...

    I tried doing that, but that doesn't work. If it's impossible to stop the breaking-animation, what shall I do then?
    I saw on BuildMCPE around 5 months ago that it had an Item Frame protection. I tried getting out the item, but I can't – which Item Frame protector did they use? Or did they use one?
     
  7. MioTaku

    MioTaku Witch

    Messages:
    69
    GitHub:
    uselesswaifu
    sorry to randomly jump into this chat (im bored)
    1. The animation has no relationship with wheather the item drops or not.
    2. Just cancel BlockBreak and PlayerInteract Event when the player interacts with a ItemFrame
     
    jasonwynn10 likes this.
  8. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    WinterBuild7074 likes this.
  9. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Code:
    [Server thread/CRITICAL]: ReflectionException: "Class ExtraProtector\BlockBreakEvent does not exist" (EXCEPTION) in "/src/pocketmine/plugin/PluginManager" at line 723
    PHP:
        public function onBreak(BlockBreakEvent $event) {
            
    $block $event->getPlayer();
            
    $player $event->getPlayer();
            
    $level $player->getLevel();
            if(
    $level->getName() === "Shopp") {
                if(
    $block->getId() === 389 || $block->getId() === 102) {
                    
    $event->setCancelled();
                }
            }
        }
    Fix?
     
    Last edited: May 9, 2017
  10. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    PHP:
    public function onBreak(\pocketmine\event\block\BlockBreakEvent $event){
        
    //...
    }
     
  11. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Oh, it's still popping out of the Item Frame. Sometimes it's a bit slow and I can easily take the Item out. What can I do? I think I saw I still better Item Frame protection...
     
  12. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Item frames don't call BlockBreakEvent when the item gets removed, did you even look at the commit link I sent? It calls PlayerInteractEvent, you may take a look at the code used in "Tests" here...
     
    Muqsit likes this.
  13. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    OK, is there anything wrong in my code here? I used BlockBreakEvent and PlayerInteractEvent for both blocks (Glass Panes and ItemFrames, just to be sure that both blocks are 'protected'):
    PHP:
    public function onTouch(PlayerInteractEvent $event) {
        
    $block $event->getPlayer();
        
    $player $event->getPlayer();
        
    $level $player->getLevel();
        if(
    $level->getName() === "Shopp") {
            if(
    $block->getId() === 389 || $block->getId() === 102) {
                
    $event->setCancelled();
            }
        }
    }
       
    public function 
    onBreak(\pocketmine\event\block\BlockBreakEvent $event) {
        
    $block $event->getPlayer();
        
    $player $event->getPlayer();
        
    $level $player->getLevel();
        if(
    $level->getName() === "Shopp") {
            if(
    $block->getId() === 389 || $block->getId() === 102) {
                
    $event->setCancelled();
            }
        }
    }
     
  14. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Why don't you test it yourself?
     
  15. Intyre

    Intyre Administrator Staff Member PMMP Team

    Messages:
    81
    GitHub:
    Intyre
    PHP:
    $block->getId() === 389 // This is bad
    $block->getId() === 102 // This is bad
    Why? What if the id's change? Better use
    PHP:
    $block->getId() === Item::ITEM_FRAME
    $block
    ->getId() === Item::GLASS_PANEL
    Easier to read and you don't have to lookup the id.
     
    jasonwynn10 likes this.
  16. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    I did, but I can still take out the items.
     
  17. Intyre

    Intyre Administrator Staff Member PMMP Team

    Messages:
    81
    GitHub:
    Intyre
    Since when is a player a block? Maybe you should learn how to debug your plugin!
    PHP:
    echo
    var_dump
    Learn how to use PHP before writing a plugin.
     
  18. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    :facepalm:...Lol, I fixed it :p
     
  19. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    I can still take out the item!
    Plus, that mistake was a silly and stupid one, I didn't see it...
    PHP:
    public function onTouch(PlayerInteractEvent $event) {
            
    $block $event->getBlock();
            
    $player $event->getPlayer();
            
    $level $player->getLevel();
            if(
    $level->getName() === "Shopp") {
                if(
    $block->getId() === Item::ITEM_FRAME || $block->getId() === Item::GLASS_PANE) {
                    
    $event->setCancelled();
                }
            }
        }
       
        public function 
    onBreak(\pocketmine\event\block\BlockBreakEvent $event) {
            
    $block $event->getBlock();
            
    $player $event->getPlayer();
            
    $level $player->getLevel();
            if(
    $level->getName() === "Shopp") {
                if(
    $block->getId() === Item::ITEM_FRAME || $block->getId() === Item::GLASS_PANE) {
                    
    $event->setCancelled();
                }
            }
        }
     
  20. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Do some research on item IDs vs block IDs (not being rude, though I might sound so).
    At times, item IDs aren't the same as their block IDs (this goes for most of the tile blocks such as Cauldrons, Enchantment tables, Brewing Stands...)
    PHP:
    //function onTouch()
    if($block->getId() === Block::ITEM_FRAME_BLOCK || $block->getId() === ITEM::GLASS_PANE){
        
    $event->setCancelled();
    }
     
    WinterBuild7074 likes this.
  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.