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

Help me, my plugin won't work

Comments in 'Plugin Development' started by applqpak, Dec 24, 2015.

  1. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    Help meeeeeeee. Okay, so...

    I made a plugin(WarnPlayers); so you type /warn <player> <reason> and it sends a message to the player, the sender and broadcasts a message to the server, but when I load it into my server, I type the command but NOTHING HAPPENS! Lol, I'm too tired to figure it out. Anyways... Files:

    PHP:
    <?php

      
    namespace applqpak\WarnPlayer;
      
      use 
    pocketmine\Server;
      use 
    pocketmine\command\Command;
      use 
    pocketmine\command\CommandSender;
      use 
    pocketmine\command\CommandExecutor;
      use 
    pocketmine\utils\TextFormat as Colour;
      use 
    pocketmine\plugin\PluginBase;
      
      class 
    WarnPlayer extends PluginBase {
      
        public function 
    onEnable() {
        
          
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
          
        }
        
        public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args) {
        
          if(
    strtolower($cmd->getName()) === "warn") {
          
            if(
    count($args[0]) != || count($args[1]) != 1) {
            
              
    $sender->sendMessage(Colour::RED "Insufficient Amount Of Args.");
              
    $sender->sendMessage(Colour::RED "Usage: /warn <player> <reason>");
              
            } else {
            
              
    $player $args[0];
              
              if(!(
    $player instanceof Player)) {
              
                
    $sender->sendMessage(Colour::RED "Sorry, but " $player " isn't online!");
                
              } else {
              
                
    $player->sendMessage(Colour::RED "You have been warned by " $sender->getName() . "For " $args[1] . "!");
                
    $sender->sendMessage(Colour::RED $player " Has been warned for " $args[1] . "!");
                
    $this->owner->getServer()->broadcastMessage(Colour::RED $player " Has been warned by " $sender->getName() . "For " $args[1] . "!");
                
              }
              
            }
            
          }
          
        }
        
      }
      
    ?>
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    count($args[0])
    Use
    PHP:
    count($args)
    And well, what's
    PHP:
    $this->owner
    ?
    applqpak likes this.
  3. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    Oh, thanks lol. I thought it would be something simple... I'm too tired to think.
  4. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    So this..?

    PHP:
    <?php

      
    namespace applqpak\WarnPlayer;
      use 
    pocketmine\Server;
      use 
    pocketmine\command\Command;
      use 
    pocketmine\command\CommandSender;
      use 
    pocketmine\command\CommandExecutor;
      use 
    pocketmine\utils\TextFormat as Colour;
      use 
    pocketmine\plugin\PluginBase;
      class 
    WarnPlayer extends PluginBase {
        public function 
    onEnable() {
      
          
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
        
        }
      
        public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args) {
      
          if(
    strtolower($cmd->getName()) === "warn") {
        
            if(
    count($args) != 2) {
          
              
    $sender->sendMessage(Colour::RED "Insufficient Amount Of Args.");
              
    $sender->sendMessage(Colour::RED "Usage: /warn <player> <reason>");
            
            } else {
          
              
    $player $args[0];
            
              if(!(
    $player instanceof Player)) {
            
                
    $sender->sendMessage(Colour::RED "Sorry, but " $player " isn't online!");
              
              } else {
            
                
    $player->sendMessage(Colour::RED "You have been warned by " $sender->getName() . "For " $args[1] . "!");
                
    $sender->sendMessage(Colour::RED $player " Has been warned for " $args[1] . "!");
                
    $this->getServer()->broadcastMessage(Colour::RED $player " Has been warned by " $sender->getName() . "For " $args[1] . "!");
              
              }
            
            }
          
          }
        
        }
      
      }
    ?>
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Yea. Though, for registering Events, the Class has to implement Listener.
  6. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    Ohhh, Thanks mate, I'm following you. ;)
  7. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    Hm.. Still doesn't work...

    PHP:
    PHP:
    <?php

      
    namespace applqpak\WarnPlayer;
      use 
    pocketmine\Server;
      use 
    pocketmine\command\Command;
      use 
    pocketmine\command\CommandSender;
      use 
    pocketmine\command\CommandExecutor;
      use 
    pocketmine\utils\TextFormat as Colour;
      use 
    pocketmine\plugin\PluginBase;
      use 
    pocketmine\event\Listener;
      class 
    WarnPlayer extends PluginBase implements Listener {
        public function 
    onEnable() {
       
          
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
         
        }
       
        public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args) {
       
          if(
    strtolower($cmd->getName()) === "warn") {
         
            if(
    count($args) != 2) {
           
              
    $sender->sendMessage(Colour::RED "Insufficient Amount Of Args.");
              
    $sender->sendMessage(Colour::RED "Usage: /warn <player> <reason>");
             
            } else {
           
              
    $player $args[0];
             
              if(!(
    $player instanceof Player)) {
             
                
    $sender->sendMessage(Colour::RED "Sorry, but " $player " isn't online!");
               
              } else {
             
                
    $player->sendMessage(Colour::RED "You have been warned by " $sender->getName() . "For " $args[1] . "!");
                
    $sender->sendMessage(Colour::RED $player " Has been warned for " $args[1] . "!");
                
    $this->getServer()->broadcastMessage(Colour::RED $player " Has been warned by " $sender->getName() . "For " $args[1] . "!");
               
              }
             
            }
           
          }
         
        }
       
      }
    ?>
    YML:
    Code:
    name: WarnPlayer
    version: 1.0.0
    api: [1.0.0]
    author: applqpak
    main: applqpak\WarnPlayer\WarnPlayer
    commands:
      warn:
        usage: "/warn <player> <reason>"
        description: "Warns a player"
        permission: warn.command
    permissions:
      warn.command:
        description: "Warns a player"
        default: op

    Attached Files:

  8. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Any error messages in server.log?
  9. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    I'll check, hang on 2 secs
  10. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    Nope.
  11. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    Could be my server I Don't Know
  12. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    I reloaded the server,

    Code:
    2015-12-24 [11:19:39] [Server Thread/NOTICE]: RuntimeException: "Argument 1 passed to pocketmine\plugin\PluginManager::registerEvents() must implement interface pocketmine\event\Listener, instance of applqpak\WarnPlayer\WarnPlayer given, called in phar:///minecraft/plugins/WarnPlayer_v1.0.0.phar/src/applqpak/WarnPlayer/WarnPlayer.php on Line 16 and defined" (E_RECOVERABLE_ERROR) in "/src/pocketmine/plugin/PluginManager" at line 698
  13. Ragnok123
    Offline

    Ragnok123 Banned

    Joined:
    Sep 14, 2015
    Posts:
    21
    Minecraft User:
    Ragnok123
    Hmm, Im using command without case.
    use example that:

    PHP:
    <?php

    namespace Ragnok123//Namespace

    //Basic
    use pocketmine\plugin\PluginBase        //Base
    use pocketmine\plugin\Listener;         //Listener
    use pocketmine\plugin\PluginTask;       //Timer

    //Event
    use pocketmine\command\Command;         //Command
    use pocketmine\command\CommandSender    //CommandSender
    use pocketmine\event\player\PlayerInteractEvent//Interact

    //Others
    use pocketmine\utils\TextFormat;    ^   //TextFormat
    use pocketmine\level\Level;             //Level
    use pocketmine\block\Block;             //Block
    use pocketmine\math\Vector;             //Vector
    use pocketmine\level\Position;        //Position
    use WallCore\WallCore;      //WallCore
    use WallCore\WallCoreMySQLManager;       /MySQL
    use WallGun\WallGun;        //Guns for CS
    use WallCase\WallCase;      //Cases like in CS:GO

    class CounterStrike extends PluginBase implements Listener; {  //Class definition
       
    public $prefix TextFormat::BLUE "[" TextFormat::RED "CounterStrike" TextFormat::VLUE "]" TextFormat::RESET//A prefix for every chat message send my the plugin
    public $mode O//Will be used as a counter for the current phase of the arena setup
    public $arenaname//Saves the arenaname

    //Spectator positions
    public $swatSpectatorSpawn;
    public 
    $terrorSpectatorSpawn;

    //Spawn positions
    public $swatSpawn;
    public 
    $terrorSpawn;

    public function 
    onEnable() {    //Called when plugin gets loaded
        
    $this->getServer()->getPluginManager()->registerEvents($this$this); //Register the PocketMine events
        
    $this->getLogger()info($this->prefix "Loaded"); //Send a message to the console
    }

    public function 
    onCommand(CommandSender $playercommand $cmd$label, array $args) { //Called when a command was used (eg. '/test')
        
    switch($cmd->getName()) //Switch the commands
        
    {
            case 
    "cs":  //If the command is 'cs''
    with cases its easy

    PHP:
    public function onCommand(CommandSender $playercommand $cmd$label, array $args) { //Called when a command was used (eg. '/test')
        
    switch($cmd->getName()) //Switch the commands
        
    {
            case 
    "cs":  //If the command is 'cs''
  14. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    I prefer not to use switch() {}.
  15. Ragnok123
    Offline

    Ragnok123 Banned

    Joined:
    Sep 14, 2015
    Posts:
    21
    Minecraft User:
    Ragnok123
    So you can use this:

    PHP:
     public function onCommand(CommandSender $senderCommand $cmd$label, array $args) {
       
          switch
    $cmd->getName())
          {
                        case
    "warn":
  16. Ragnok123
    Offline

    Ragnok123 Banned

    Joined:
    Sep 14, 2015
    Posts:
    21
    Minecraft User:
    Ragnok123
    PHP:
      public function onCommand(CommandSender $senderCommand $cmd$label, array $args) {
      
          switch(
    $cmd->getName())
          {
                        case
    "warn"
    *
  17. TheDeibo
    Offline

    TheDeibo Notable Member Plugin Developer

    Joined:
    Sep 8, 2014
    Posts:
    692
    Plugins:
    1
    Minecraft User:
    TheDeibo
    PHP:
    <?php

      
    namespace applqpak\WarnPlayer;
      use 
    pocketmine\Server;
      use 
    pocketmine\command\Command;
      use 
    pocketmine\command\CommandSender;
      use 
    pocketmine\command\CommandExecutor;
      use 
    pocketmine\utils\TextFormat as Colour;
      use 
    pocketmine\plugin\PluginBase;
      use 
    pocketmine\event\Listener;
      class 
    WarnPlayer extends PluginBase implements Listener{
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getLogger()->info(TextFormat::RED "Warn Player Is active!!!");
        }
      
        public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args){
      
          if(
    strtolower($cmd->getName()) === "warn"){
        
            if(
    count($args) != 2){
          
              
    $sender->sendMessage(Colour::RED "Insufficient Amount Of Args.");
              
    $sender->sendMessage(Colour::RED "Usage: /warn <player> <reason>");
            
            }else{
          
              
    $player $args[0];
            
              if(!(
    $player instanceof Player)){
            
                
    $sender->sendMessage(Colour::RED "Sorry, but " $player " isn't online!");
              
              }else{
            
                
    $player->sendMessage(Colour::RED "You have been warned by " $sender->getName() . "For " $args[1] . "!");
                
    $sender->sendMessage(Colour::RED $player " Has been warned for " $args[1] . "!");
                
    $this->getServer()->broadcastMessage(Colour::RED $player " Has been warned by " $sender->getName() . "For " $args[1] . "!");
              
              }
            
            }
          
          }
        
        }
      
      }
    Try this.
    I got rid of a dreadful ugly looking space....

    (for example, from "public function onEnable() {" to "public function onEnable(){"
    also added a plugin loaded message. and also, got rid of the unwanted "?>". Its not really needed.
  18. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Don't reload. Restart.
    luca28pet likes this.
  19. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    I have, multiple times. It doesn't make a difference wether it's a reload or a restart...
  20. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    Lol, it's pretty much the same...

Share This Page

Advertisement