Discussion in 'Plugin Help' started by FiraasMCPE, Jul 18, 2020.

1. FiraasMCPECreeper

Messages:
4
GitHub:
firaasmcpe
I am trying to give a player an enchanted diamond sword every time they join the server, but this error shows up as an internal server error:

Does anyone have a solution for it?

These are the classes I am using:
use pocketmine\plugin\PluginBase;
use pocketmine\Player;
use pocketmine\Server;
use pocketmine\event\Listener;
use pocketmine\event\HandlerList;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\item\enchantment\Enchantment;
use pocketmine\item\enchantment\EnchantmentInstance;
use pocketmine\item\enchantment\SharpnessEnchantment;
use pocketmine\item\enchantment\EnchantmentEntry;
use pocketmine\item\enchantment\EnchantmentList;
use pocketmine\item\Item;

The code that's causing the error:
Public function onJoin(PlayerJoinEvent $event){$this->getLogger()->info("working");
$player =$event->getPlayer();
$player->getInventory()->clearAll();$item = Item::get(276);
$enchantment= Enchantment::getEnchantment(9);$level = 50;

3. FiraasMCPECreeper

Messages:
4
GitHub:
firaasmcpe
Ok, what class should I delete and what should I use?

4. GodWeedZaoZombie Pigman

Messages:
407
GitHub:
godweedzao
Hello, why you didnt send your code with php format? (its hard to read)
wait, i'll open it in my ide.

5. GodWeedZaoZombie Pigman

Messages:
407
GitHub:
godweedzao
so, for enchanting item use this code (im not in my pc, ican't read your own code) but you can just replace my code in to your plugin:
PHP:
 use pocketmine\item\enchantment\Enchantment;use pocketmine\item\enchantment\EnchantmentInstance;use pocketmine\item\Item;//these are all use's for enchant Item in my Own Code :) 
and for example now i enchanting Bow for you:
PHP:
 $BOW = Item::get(Item::BOW);$BOW->addEnchantment(new EnchantmentInstance(Enchantment::getEnchantment(Enchantment::FIRE_PROTECTION), 5));//5 is the level of enchant. 
and its DONE
@FiraasMCPE