Okay that really made me laugh. registerEvents(listener, plugin base) Also thankyou so much @jasonwynn10 for explaining, constructive criticism is the best way to learn imo
Massive facepalms... when attempting to register a class as a Listener in PocketMine, one must always implement the Listener Class and call the registerEvents() function. The reason it didn't work in your second attempt is because you didn't use any variables when you were registering the class. $this is the variable representation of the class. what you used $this->getServer()->getPluginManager()->registerEvents(listener, plugin base); are not variables or the proper inputs for the function. It's good to see that you are attempting to learn. Keep it up, but I recommend posting i the facepalm section due to the nature of these small programming mistakes.
I think these are questions, but I want to learn: 1. What is a Listener in PMMP? When do I need to use it? 2. I don't understand what this part of the code means: registerEvents($this, $this)
instance of Listener means listener is just something that implements(Look up PHP manual if you dont understand this keyword) class Listener registerEvents(instance of Listener,instance of BasePlugin) calling the function means you are telling PMMP that you want to be notified when there's an event that you have a valid event observer as mostly called in different parts of PHP community but here, we call it EventListener which you PMMP will scan all of your functions automatically if your class have any public class(Look up PHP manual if you dont understand this keyword) with only one arg PMMP will try to see if the class is instance of Event/smth around like it, if it's valid it will register it Instance of plugin base just references to a plugin, for crash handling or so... it's a way for PMMP to tell which plugin Owns the listener because some of us uses multiple classes like separated listener class
What is class Listener? Why do I need it or a plugin like this one? Does this have something to do with instanceof? If yes, what does that mean and do? Plus, why $this, $this? Why do I need two of these '$this's? What does that exactly mean?
A double $this refers to the Listener and the PluginBase. The registerEvents require both the Listener and the PluginBase. If the Listener is in the PluginBase, both the Listener and the PluginBase will be $this. If your Listener is in a separated class, the first $this would be replaced by an instance of the Listener you want to register. (new ListenerName($this), $this)
class listener is just a dummy class indicating it to be a event listener, nothing special but just so other can check using instanceof for instanceof i think the menaul could explain it better the first $this i the listener thr second $this is the base/owner
Is this now correct? Still doesn't work! PHP: <?phpnamespace pmmp\DropIt;use pocketmine\event\block\BlockBreakEvent;use pocketmine\plugin\PluginBase;use pocketmine\Server;use pocketmine\item\Item;use pocketmine\block\Block;use pocketmine\Player;use pocketmine\inventory\Inventory;use pocketmine\event\Listener;class Main extends PluginBase implements Listener { $this->getServer()->getPluginManager()->registerEvents($this, $this); public function onBreak(BlockBreakEvent $event) { if($event->getBlock()->getId() === 14) { $drops = array(); $drops[] = Item::get(Item::IRON_INGOT, 0, 1); $event->setDrops($drops); } }} I tried this here too, also didn't work: PHP: <?phpnamespace pmmp\DropIt;use pocketmine\event\block\BlockBreakEvent;use pocketmine\plugin\PluginBase;use pocketmine\Server;use pocketmine\item\Item;use pocketmine\block\Block;use pocketmine\Player;use pocketmine\inventory\Inventory;use pocketmine\event\Listener;class Main extends PluginBase implements Listener { public function onEnable() { $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onBreak(BlockBreakEvent $event) { if($event->getBlock()->getId() === 14) { $drops = array(); $drops[] = Item::get(Item::IRON_INGOT, 0, 1); $event->setDrops($drops); } }}
you should try to run only one plugin, you can archive it by moving all other phars into a folder named anything or "unloaded"
Like this? PHP: public function onDisable(CommandSender $sender) { $sender->sendMessage("DropIt turned off!");}
This? PHP: public function onDisable() { $this->getServer()->getPluginManager()->registerEvents($this, $this);}
Finally, it works... Question: Can I do it like this too? Like @jasonwynn10 said? PHP: drops[] = new Item(155) // Gives you a Quartz Block as drop Problem is, I cannot set how many Quartz Blocks it should drop...