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

[SELF-SOLVED] Disallow Item Frame Griefing

Discussion in 'Development' started by Muqsit, Feb 10, 2017.

  1. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Okay, this is rather a help thread than a question. This was/had been a huge problem on my server for a whole month. I never bothered on *fixing* this because... WHO REALLY CARES ABOUT ITEM FRAMES? But then it started getting a bit annoying, seeing soon many item frames just empty.
    So here you go until we get an ItemFrameDropItemEvent.
    PHP:
    public function onDataReceive(\pocketmine\event\server\DataPacketReceiveEvent $event){
        if((
    $pk $event->getPacket())::NETWORK_ID === \pocketmine\network\protocol\Info::ITEM_FRAME_DROP_ITEM_PACKET){
            if(!
    $event->getPlayer()->isOp()){//or some other criteria.
                
    $event->setCancelled();
                
    $event->getPlayer()->getLevel()->getTile(new \pocketmine\math\Vector3($pk->x$pk->y$pk->z))->spawnTo($event->getPlayer());
            }
        }
    }
     
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    This works too
    PHP:
    public function playerBlockTouch(PlayerInteractEvent $event){
        if(
    $event->getBlock()->getId() === Block::ITEM_FRAME_BLOCK && $event->getAction() === PlayerInteractEvent::LEFT_CLICK_BLOCK){
               
    $event->setCancelled();
        }
    }
     
  3. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Left clicks aren't implemented. That won't work.
    https://github.com/pmmp/PocketMine-MP/issues/339
     
  4. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    dktapps likes this.
  6. Tolo

    Tolo Silverfish

    Messages:
    15
    GitHub:
    Tolo0
    can't someone make a plugin for this?
     
  7. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    shouldnt these be in resources section?
    or maybe a new tag for howto
     
  8. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    I have a shop, with a hundreds of ItemFrames. I extra put Glass in front of the ItemFrames that players cannot get them out. But they still can! Glass is easy enough to break and then after a few seconds the item inside the ItemFrame jumps out. Then they can collect it. How can I stop people doing this?
     
  9. Kabluinc

    Kabluinc Baby Zombie

    Messages:
    129
    Use the code above or use invisible bedrock. Not implemented in pmmp yet but u cud add it yourself. Placing invisible bedrock is permanent though.
     
  10. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    How can I place those Invisible Bedrock? Plus, I don't think this is a good idea.
     
  11. Tolo

    Tolo Silverfish

    Messages:
    15
    GitHub:
    Tolo0
    Cant that code above be turned into a plugin?
     
  12. Tolo

    Tolo Silverfish

    Messages:
    15
    GitHub:
    Tolo0
    Use MagicWE. Place Stone blocks then do //replace 1 95
    the stone will be replaced with invisible bedrock
     
  13. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    I know that, but:
    • MagicWE says he doesn't know that block (I don't extra want to edit the code for that),
    • I want to find another way to fix this problem.
    PHP:
    public function onInteract(PlayerInteractEvent $event) {
        
    $block $event->getBlock();
        if(
    $block === "102") {
            
    $event->setCancelled();
        }
    }
     
  14. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    I don't know what you are trying to do, since PlayerInteractEvent currently can't prevent Item Frame griefing, but $event->getBlock() will be a Block object, not the string "102".
     
  15. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    OK, wait, I'll try again...
    PHP:
    public function onInteract(PlayerInteractEvent $event) {
        
    $block $event->getBlock();
        
    $level $event->getLevel();
        if(
    $level->getName() === "Shop" && $block->getId() === 102) { // if player is in Shop and tries to break the GlassPane/ItemFrame
            
    $event->setCancelled();
        }
    }
     
  16. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Then I'll write a bot that ignores the invisible bedrock, or simply a mod that treats invisible bedrock as air.
     
  17. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    i guess i am right on the assumption that PMMP dont check if player actually have access to a block before allowing it to be broken
     
    jasonwynn10 likes this.
  18. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    @SOFe Can you make a PlayerItemFrameDropEvent? Then you can cancel the event.
    Or maybe my code will work.
     
  19. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    You'd be delighted when you learn that I don't even have MCPE installed in my phone :) Therefore I can't even test anything directly related to the client.
     
    jasonwynn10 and Muqsit like this.
  20. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Um, maybe my code will work? Before the player tries to break the block (touching only), it cancels the event.
    @SOFe If that will work, then PlayerItemFrameDropEvent is not needed...?
     
  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.