So basically, I have 3 .php files, Main, Commands, And Interact. The plugin.yml isnt wrong, as I've looked it over a couple of times. Here is what the files code is Spoiler: Main.php PHP: <?phpnamespace CustomEnchantments;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\event\entity\{EntityArmorChangeEvent, EntityDamageByEntityEvent, EntityDamageEvent};use pocketmine\event\player\PlayerDeathEvent;use pocketmine\level\sound\ExpPickupSound;use pocketmine\utils\TextFormat as c;use pocketmine\level\sound\GhastSound;use pocketmine\Player;use pocketmine\level\Level;use pocketmine\level\sound;use pocketmine\event\player\PlayerInteractEvent;use pocketmine\math\Vector3;use pocketmine\level\Position;use pocketmine\Server;use pocketmine\command\CommandSender;use pocketmine\command\ConsoleCommandSender;use pocketmine\entity\Effect;use pocketmine\level\particle\FlameParticle;use pocketmine\level\sound\ExplodeSound;use pocketmine\item\enchantment\Enchantment;use pocketmine\item\Item;class Main extends PluginBase implements Listener{ public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->getServer()->getLogger()->notice(c::AQUA . "CustomEnchantments Have Been Enabled!"); } public function onDamage(EntityDamageEvent $e) { if ($e instanceof EntityDamageByEntityEvent) { $damager = $e->getDamager(); $p = $e->getEntity(); $thing = $damager->getInventory()->getItemInHand(); if ($thing->getId() === 276 and $thing->getCustomName() === "Snakes Blade") { switch (mt_rand(1,5)) { case 1: return; case 2: return; case 3: return; case 4: return; case 5: $p->addEffect(Effect::getEffect(19)->setDuration(20)->setAmplifier(1)); } } if ($thing->getId() === 276 and $thing->getCustomName() === "Za Roc") { $x = $p->getX(); $y = $p->getY(); $z = $p->getZ(); $level = $damager->getLevel(); $damager = $e->getDamager(); $p = $e->getEntity(); switch (mt_rand(1,3)) { case 1: $level->addParticle(new FlameParticle(new Vector3($x, $y + 1, $z))); $level->addSound(new ExplodeSound(new Vector3($x, $y + 1, $z))); $damager->sendMessage(c::RED . "Explosive Hit!"); $p->setHealth(15); case 2: return; case 3: $p->addEffect(Effect::getEffect(20)->setDuration(13 * 20)->setAmplifier(1)); $level->addSound(new GhastSound(new Vector3($x, $y + 1, $z))); $damager->sendMessage(c::RED . "You have unleashed the forces of evil upon your enemy"); } } } }} Spoiler: Commands.php PHP: <?phpnamespace CustomEnchantments;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\utils\TextFormat as c;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\command\ConsoleCommandSender;use pocketmine\Item\Item;use pocketmine\Player;use pocketmine\Server;class Commands { public function onCommand(CommandSender $sender,Command $cmd,$label,array $args){ if($cmd->getName() == "buy_zaroc"){//COMMAND #1 $player = $this->getServer()->getPlayer($sender->getName()); $item1 = Item::get(Item::DIAMOND_SWORD, 0, 1); $itemname1 = $item1->setCustomName("Za Roc"); $money = $this->getServer()->getPluginManager()->getPlugin("EconomyAPI")->myMoney($sender); if($money < 2500) { $sender->sendMessage(c::RED ."Not Enough Money!"); return false; }else{ $this->getServer()->getPluginManager()->getPlugin("EconomyAPI")->reduceMoney($sender->getName(), 1500); $sender->getInventory()->addItem($item1); $sender->sendMessage(c::GREEN . "Za Roc Has Been Bought!"); $item1->setCustomName($itemname1); return true; } }}} Spoiler: Interact.php PHP: <?phpnamespace CustomEnchantments;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\event\entity\{EntityArmorChangeEvent, EntityDamageByEntityEvent, EntityDamageEvent};use pocketmine\event\player\PlayerDeathEvent;use pocketmine\level\sound\ExpPickupSound;use pocketmine\utils\TextFormat as c;use pocketmine\level\sound\GhastSound;use pocketmine\Player;use pocketmine\level\Level;use pocketmine\level\sound;use pocketmine\event\player\PlayerInteractEvent;use pocketmine\math\Vector3;use pocketmine\level\Position;use pocketmine\Server;use pocketmine\entity\Effect;use pocketmine\level\particle\FlameParticle;use pocketmine\level\sound\ExplodeSound;use pocketmine\item\enchantment\Enchantment;use pocketmine\item\Item;class Interact { public function onInteract(PlayerInteractEvent $event){ $name = $event->getPlayer()->getName(); $x = $name->getX(); $y = $name->getY(); $z = $name->getZ(); $thing = $name->getInventory()->getItemInHand(); if ($thing->getId() === 276 and $thing->getCustomName() === "XP Book"){ $player->addXpLevel(25); $level->addSound(new ExpPickupSound(new Vector3($x, $y + 1, $z))); } }} If anyone of you could help me that would be awesome! Thank you!
You have to register the events of your interact class ( and construct it ) and make your command class extend CommandExecutor, then register the command in your main file on Enable.
Okay so the command class would be class Commands extends CommandExecutor{ instead of just class Commands { correct?
That's right, add this code in your main class to register the command onEnable: PHP: $this->getCommand("buy_zaroc")->setExecutor(new Commands($this));
I'm sorry to say I'm not sure if/how it's possible to add more listeners, but you can move that part onInteract in the Main class.
New error Fatal error: Class CustomEnchantments\Commands cannot extend from interface pocketmine\command\CommandExecutor in C:\Users\Conner\Desktop\GensisyTestServer\plugins\CustomEnchantments\src\CustomEnchantments\Commands.php on line 0
you can registerevent(new EventListener($this,(and stuff)),$this) the first arg is a listener to do that just make a class and extend eventlistener and the stuff is the things the listener needs commonly we pass the main class and the last this is for who registered that thing I am sorry to say that this code needs some fixing 1 i am unsure of what methods you are trying to use to register the command guess: the most easy way is to do that is put the command in plugin.yml and add a function called onCommand under main 2 the interact did is not registered nor extended Listener fix: you should just merge it into main
Code: PHP: <?phpnamespace CustomEnchantments;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\event\entity\{EntityArmorChangeEvent, EntityDamageByEntityEvent, EntityDamageEvent};use pocketmine\event\player\PlayerDeathEvent;use pocketmine\level\sound\ExpPickupSound;use pocketmine\utils\TextFormat as c;use pocketmine\level\sound\GhastSound;use pocketmine\Player;use pocketmine\level\Level;use pocketmine\level\sound;use pocketmine\event\player\PlayerInteractEvent;use pocketmine\math\Vector3;use pocketmine\level\Position;use pocketmine\Server;use pocketmine\entity\Effect;use pocketmine\level\particle\FlameParticle;use pocketmine\level\sound\ExplodeSound;use pocketmine\item\enchantment\Enchantment;use pocketmine\item\Item;use CustomEnchantments\Main;class Interact extends Listener { public function onInteract(PlayerInteractEvent $event){ $name = $event->getPlayer()->getName(); $x = $name->getX(); $y = $name->getY(); $z = $name->getZ(); $thing = $name->getInventory()->getItemInHand(); if ($thing->getId() === 276 and $thing->getCustomName() === "XP Book"){ $name->addXpLevel(25); $level->addSound(new ExpPickupSound(new Vector3($x, $y + 1, $z))); } }} No error, doesnt do anything
PHP: <?phpnamespace CustomEnchantments;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\utils\TextFormat as c;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\command\ConsoleCommandSender;use pocketmine\Item\Item;use pocketmine\Player;use pocketmine\Server;use pocketmine\command\CommandExecutor;class Commands implements CommandExecutor { public function onCommand(CommandSender $sender,Command $cmd,$label,array $args){ if($cmd->getName() == "buy_zaroc"){//COMMAND #1 $item1 = Item::get(Item::DIAMOND_SWORD, 0, 1); $itemname1 = $item1->setCustomName("Za Roc"); $money = $this->getServer()->getPluginManager()->getPlugin("EconomyAPI")->myMoney($sender); if($money < 2500) { $sender->sendMessage(c::RED ."Not Enough Money!"); return false; }else{ $this->getServer()->getPluginManager()->getPlugin("EconomyAPI")->reduceMoney($sender->getName(), 1500); $sender->getInventory()->addItem($item1); $sender->sendMessage(c::GREEN . "Za Roc Has Been Bought!"); $item1->setCustomName($itemname1); return true; } }}} Error Error: "Call to undefined method CustomEnchantments\Commands::getServer()" (EXCEPTION) in "/CustomEnchantments/src/CustomEnchantments/Commands" at line 24