Problem: When i start the server there's no error but when i click a book, its crashing the game & giving me internal server error Error: [Server thread/CRITICAL]: Error: "Call to undefined method Alexander\PurpleCraftPlugin\Main: OpenServerForm()" (EXCEPTION) in "plugins/PurpleCraftPlugin/src/Alexander/PurpleCraftPlugin/Main" at line 114 Line 114 -> $this->openServerForm ($player); PHP: public function onCommand(CommandSender $sender, Command $cmd, string $label, array $args) : bool{ switch($cmd->getName()){ case "info" : if ($sender instanceof Player){ $this->openServerForm ($sender); } break; } } public function openMyCustomToggleForm(Player $player){ $api = $this->getServer()->getPluginManager()->getPlugin( "FormAPI" ); $form = $api->createSimpleForm(function (Player $player, int $data = null){ if ($data === null){ return true; } }); $form->setTitle("Title here"); $form->setLabel("Label here"); $form->sendToPlayer($player); return $form; } public function onInteract (PlayerInteractEvent $event){ $player = $event->getPlayer(); $item = $event->getItem(); if($item->getId() == 340){ if(!isset($this->interactDelay[$player->getName()])){ $this->interactDelay[$player->getName()] = time() + 1; $this->openServerForm ($player); } else{ if(time() >=$this->interactDelay[$player->getName()]){ unset ($this->interactDelay[$player->getName()]); } } }}}
ur issue is that that the function u made is named openMyCustomToggleForm but your using a method called openServerForm
and ur using old methods of youtube the new way to create forms is by using Code: $form = new \jojoe77777\FormAPI\SimpleForm(function (Player $sender, $data){ if ($data === null) { return true; } switch($data) { case 0: $this->getServer()->loadLevel("nodebuff"); $sender->teleport($this->getServer()->getLevelByName("nodebuff")->getSpawnLocation()); $sender->sendMessage(TextFormat::RED.$this->prefix." You Have Joined The FFA nodebuff Arena!"); return true; break; case 1: $this->getServer()->loadLevel("gapple"); $sender->teleport($this->getServer()->getLevelByName("gapple")->getSpawnLocation()); $sender->sendMessage(TextFormat::YELLOW.$this->prefix." You Have Joined The FFA Gapple Arena!"); return true; break; } return true; }); $form->setTitle("FFA Arenas"); $form->setContent("Please Select A Free for all arena!"); $form->addButton(TextFormat::LIGHT_PURPLE."No-Debuff \nPlayers In This Arena: {$this->playersinnodebuff}"); $form->addButton(TextFormat::YELLOW."Gapple \nPlayers In This Arena: {$this->playersingapple}"); $form->sendToPlayer($player); } this code allows for easier making of simple forms simple only allows buttons while modal allows for other types of buttons and custom allows for use of all the $form->attributes like dropdown menus and also switches and others.
Ok thanks but what should i delete? I only want a title and some text inside (Im trying to create a menu for /info) !!! ----> THIS IS SOLVED, I FOUND OUT BY MYSELF! Also, how i can make the item to be forced to stay in a slot? Even if players try to change the slot of an item, the item will go back where it was, not in another slot and how to enchant the item that execute the menu?
just delete the buttons and cases and for the force slot i would use this taken from my practice core PHP: public function onDrop(PlayerDropItemEvent $e) { $player = $e->getPlayer(); $name = $player->getName(); $player->sendMessage($this->prefix . "Dropping Items Is Not Allowed In This Server"); if ($player->isOp()) { $e->setCancelled(false); } else { $e->setCancelled(true); } } ,but to use this make sure your plugin has a public $variable; before any function and then make it equal something when ur plugin is enabled. This Code Only allows Operators to drop items. Spoiler: Code For Prefix public $prefix; public function onEnable() { $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->getLogger()->info(TextFormat::GREEN . "Practice Core Is Now Online"); $this->prefix = TextFormat::AQUA . "[" . TextFormat::RED . "Practice Core" . TextFormat::AQUA . "] "; }
Yes, but actually im looking for something that wont let players change the slot of an item, like the compass of NaviCompass plugin
use this i just wrote it for my server core and used a few things for NaviCompass It Uses Lores To Identify The Items U Dont Want Moved So Just Put The Lore on the item to something consistent i have also put in a way for u to check for a second lore at the same time. CODE: PHP: public function onInvMove (InventoryTransactionEvent $e) { $transaction = $e->getTransaction(); foreach ($transaction->getActions() as $action) { $item = $action->getSourceItem(); $source = $transaction->getSource(); if ($source instanceof Player && $this->isSelectorItem($item)) { if ($action instanceof SlotChangeAction || $action instanceof DropItemAction) { $e->setCancelled(); } } } } private function isSelectorItem(Item $item): bool { if ($item->getLore() == TextFormat::AQUA."Click!" || $item->getLore() == TextFormat::RED."Click!"){ return true; } return false; }
I tried it but nothing is happening, like the code does nothing.. I changed $transaction = $e->getTransaction(); to $transaction = $e->getTransactions(); and when i try to change the slot of item, internal server error
found the issue Lore is returned as a string[] so just put the $item->getlore() == [(TheLoreYourItemHas)] make sure its wrapped in brackets like i have put in the example
use this instead for the code: PHP: public function onInvMove (InventoryTransactionEvent $e) { $transaction = $e->getTransaction(); foreach ($transaction->getActions() as $action) { $item = $action->getSourceItem(); $source = $transaction->getSource(); if ($source instanceof Player && $this->isSelectorItem($item)) { if ($action instanceof SlotChangeAction || $action instanceof DropItemAction) { $e->setCancelled(); } } } } private function isSelectorItem(Item $item): bool { if ($item->getLore() == [TextFormat::AQUA."Click!"] || $item->getLore() == [TextFormat::RED."Click!"]){ return true; } return false; }
id? just give the item u want to not be moved a lore using $item->setlore([(LORE YOU WANT)]) EXAMPLE: PHP: $item->setLore([TextFormat::RED."Click!"]);
I think now i understand what you're trying to say but.. So, $item was undefined and i did this: PHP: $player->getInventory()->setItem(2, Item::get(340, 0, 1)->setCustomName("§5Info")); //This is just the code to give item onJoin $item = $player->getInventory()->setItem(2, Item::get(340, 0, 1)->setCustomName("§5Info")); //This is what i did $item->setLore[("§5§l• §fClick for informations §5§l•")]; } But now there's another error: [11:55:20] [Server thread/CRITICAL]: ErrorException: "Trying to get property 'setLore' of non-object" (EXCEPTION) in "plugins/PurpleCraftPlugin/src/Alexander/PurpleCraftPlugin/Main" at line 72
ITs because ur using ids of the items for the item the best way to get items is to do this code: Code: $item = Item::get(Item::ITEMNAME); $item->setlore([LORE]); $pinv = $player->getinventory(); $pinv->setItem(0,$item);
here u go PHP: public function onInvMove (InventoryTransactionEvent $e) { $transaction = $e->getTransaction(); foreach ($transaction->getActions() as $action) { $item = $action->getSourceItem(); $source = $transaction->getSource(); if ($source instanceof Player && $this->isSelectorItem($item)) { if ($action instanceof SlotChangeAction || $action instanceof DropItemAction) { $world = $source->getLevel()->getName(); if ($world == 'spawn') { $e->setCancelled(true); $source->sendMessage($this->prefix . "Moving Items Is Not Allowed In This Server"); } } } } } private function isSelectorItem(Item $item): bool { if ($item->getLore() == [TextFormat::AQUA."Click!"] || $item->getLore() == [TextFormat::RED."Click!"]) { return true; } return false; }