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

Action for only one chest

Comments in 'Plugin Development' started by BlockMC, Aug 31, 2015.

  1. BlockMC
    Offline

    BlockMC New Member

    Joined:
    Aug 21, 2015
    Posts:
    6
    Minecraft User:
    BlockMC
    Hi,

    I made a crate key plugin that works when a player taps with an egg on a chest. Now I ran into the problem that players can't open other chests.

    Is there any solution for this?
  2. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    You could add a config where you save the xyz for that specific chest, and when you run your code you check, if the player taps the chest with an egg and cancel the opening action, else you dont cancel it.
  3. BlockMC
    Offline

    BlockMC New Member

    Joined:
    Aug 21, 2015
    Posts:
    6
    Minecraft User:
    BlockMC
    Does anyone have a code for that?
  4. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    I could create a snippet or edit your current code, i would prefer the second option
  5. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    PHP:
    public function onTouch(PlayerInteractEvent $event) {
                    
    $block $event->getBlock();
                if(
    $block->getId() == $chestid && $player->getInventory()->getItemInHand()->getId() == $eggid) {
                     
    /* $coordX = Chest X coordinate you saved
                        $coordY = Chest Y coordinate you saved
                        $coordZ = Chest Y coordinate you saved
                     */
                     
    if($block->getX() == $coordX && $block->getY() == $coordY && $block->getZ() == $coordZ) {
                        
    $event->setCancelled(true);
                        
    // Your crate code
                        
    }
                        else {
                            
    // Do something if it is not a crate
                        
    }
                    }
    thebigsmileXD likes this.

Share This Page

Advertisement