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

How to Lock item position in player's inventory?

Comments in 'Plugin Development' started by korado531m7, Mar 20, 2016.

  1. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    How?
    Player cannot change inventory item position.
    please tell me.
    thank you for answering.
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    What do you mean? Please describe more.
    Primus likes this.
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Handle InventoryTransactionEvent. If one of the transactions involves that certain slot, cancel event.
    Skullex likes this.
  4. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    I personally recommend @PEMapModder 's theory but here is something you could also use...

    PHP:
        public function onHeld(PlayerItemHeldEvent $event){
            
    $cfg $this->getConfig();
            
    $player $event->getPlayer();
            
    $hidetask = new PlayerHideTask($this$player);
            
    $item $event->getItem()->getId();
                switch(
    $item){
                    case 
    $cfg->get("HidePlayers-Item"):
                        
    $this->task $this->getServer()->getScheduler()->scheduleRepeatingTask($hidetask20);
                        
    $player->sendPopup(TextFormat::YELLOW $cfg->get("HidePlayer-Message"));
                        
    $event->setCancelled(true);
                        break;
                    case 
    $cfg->get("ShowPlayers-Item"):
                        
    $this->getServer()->getScheduler()->cancelTask($this->task->getTaskId());
                        foreach (
    $this->getServer()->getOnlinePlayers() as $onl){
                            
    $player->showPlayer($onl);
                            
    $player->sendPopup(TextFormat::GREEN $cfg->get("ShowPlayer-Message"));
                            
    $event->setCancelled(true);
                            }
                        break;
            }
        }
    }
    Code:
    $event->setCancelled(true);
    
    Cancels the 'PlayerItemHeldEvent $event' so the item get's placed back to where it was in the Inventory.
  5. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    Sorry, lock hotbar items.
    How to write this?
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You don't have to hold an item to move it.
    Skullex likes this.
  7. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    Yes.but, i want to this.

Share This Page

Advertisement