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

Plugin Crashes Server on startup

Comments in 'Plugin Development' started by Devin5411, Sep 19, 2015.

  1. Devin5411
    Offline

    Devin5411 Active Member

    Joined:
    Oct 9, 2014
    Posts:
    113
    Minecraft User:
    MC_DevinYT
    I used PEMapModders Inspection and got this:

    Inspections
    • Classpath
      • Inspection result: Warning
      • Warnings
        • Namespace declaration namespace WarnSystem not found
        • Namespace declaration as WarnSystem for src/WarnSystem/Main.php missing
      • Info
        • Main class scanned: WarnSystem\Main
        • Main class file found at src/WarnSystem/Main.php
      • Bad practice
        • Inspection result: Passed
      • Syntax errors
        • Inspection result: Error
        • Errors
          • PHP Parse error: syntax error, unexpected '/', expecting \\ (T_NS_SEPARATOR) or ';' or '{' in /var/www/tmp/5/WarnSystem/src/WarnSystem/Main.php on line 1
            Errors parsing /var/www/tmp/5/WarnSystem/src/WarnSystem/Main.php
        • Info
          • 0 good PHP file(s) and 1 bad PHP file(s) found.
          • Checked with PHP 5.6.11-1+deb.sury.org~trusty+1
    End of inspections
  2. Devin5411
    Offline

    Devin5411 Active Member

    Joined:
    Oct 9, 2014
    Posts:
    113
    Minecraft User:
    MC_DevinYT
    My Main.php (Sorry I don't know how to do the little PHP: Code box Would like to know how though)
    PHP:
    <?php

    namespace devin5411/WarnSystem;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandExecutor;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\ConsoleCommandSender;
    use 
    pocketmine\command\ConsoleCommandExecutor;
    use 
    pocketmine\Player;
    use 
    pocketmine\utils\Config;

    class 
    Main extends PluginBase implements CommandExecutor{
    public 
    funtion onEnable(){
        
    $this->saveDefaultConfig();
        
    $this->getResource("config.yml");
        if(!
    file_exists($this->plugin->getDataFolder() . "Warns/")){
            @
    mkdir($this->plugin->getDataFolder() . "Warns/");
        }
          
    $this->getLogger()->info("WarnSystem Loaded!");
    }
    public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args){
        switch(
    $cmd->getName()){
            case 
    "warn":
                if(isset(
    $args[0])){
                    
    $player $args[0];
                      if((
    $player->getServer()->getPlayer($name)) instanceof Player){
                            if(!
    file_exists($this->plugin->getDataFolder() . "Warns/$player.yml")){
                            
    $warns = new Config($this->plugin->getDataFolder() . "Warns/$player.yml"Config::YAML);
                              
    $warns->set("warns""0");
                              
    $warns->save();
                            }else{
                              
    $warns = new Config($this->plugin->getDataFolder() . "Warnss/$player.yml"Config::YAML);
                            }
                        if(isset(
    $args[1])){
                              
    $reason implode($args[1]);
                              
    $warns->set("warns"$warns->get("warns") + 1);
                              
    $warns->save();
                              
    $this->getServer()->broadcastMessage("[WarnSystem] Warning, ".$player.", ".$reason."!");
                              if(
    $warns->get("warns") >= $this->config->get("MaxWarns")){
                                    
    $BanType $this->config->get("BanType");
                                    if(
    $BanType "name"){
                                      
    $sender->getServer()->getNameBans()->addBan($player$reasonnull$sender->getName());
                                    
    $player->kick($reason);
                                    }elseif(
    $BanType "ip"){
                                          
    $ip $player->getAddress();
                                      
    $sender->getServer()->getIPBans()->addBan($ip$reasonnull$sender->getName());
                                      foreach(
    $sender->getServer()->getOnlinePlayers() as $all){
                                          if(
    $all->getAddress() === $ip){
                                                  
    $all->kick($reason);
                                          }
                                    }
                                    }
                              }
                        }else{
                              
    $warns->set("warns"$warns->get("warns") + 1);
                              
    $warns->save();
                              
    $this->getServer()->broadcastMessage("[WarnSystem] Warning, ".$player."!");
                              if(
    $warns->get("warns") >= $this->config->get("MaxWarns")){
                                    
    $BanType $this->config->get("BanType");
                                    if(
    $BanType "name"){
                                      
    $sender->getServer()->getNameBans()->addBan($player"You Were Warned!"null$sender->getName());
                                    
    $player->kick("You Were Warned!");
                                    }elseif(
    $BanType "ip"){
                                      
    $ip $player->getAddress();
                                      
    $sender->getServer()->getIPBans()->addBan($ip"You Were Warned!"null$sender->getName());
                                      foreach(
    $sender->getServer()->getOnlinePlayers() as $all){
                                          if(
    $all->getAddress() === $ip){
                                                  
    $all->kick("You Were Warned!");
                                          }
                                    }
                                    }
                              }
                      }
                  }else{
                        
    $sender->sendMessage("[WarnSystem] Player ".$player." is not Online!");
                  }
                }else{
                  
    $sender->sendMessage("Usage: /warn <player> [reason]");
                  return 
    true;
                }
              break;
          }
    }
    public function 
    onDisable(){
       
    $this->getConfig()->save();
       
    $this->getLogger()->info("WarnSystem Unloaded!");
    }
    }
    ?>

    Code:
    [php][/php]

    Here is my plugin.yml:
    Code:
    ---
    name: WarnSystem
    author: ~Devin5411
    version: "1.0"
    api:
    - 1.12.0
    main: WarnSystem\Main
    commands:
       warn:
           description: "Warn a player!"
           usage: "/warn <player> [reason]"
           permission: warnsystem.warn
    permissions:
       warnsystem.warn:
           description: "Allows a player to warn someone"
           default: op
    
    ...
    
    Last edited by a moderator: Sep 19, 2015
  3. Devin5411
    Offline

    Devin5411 Active Member

    Joined:
    Oct 9, 2014
    Posts:
    113
    Minecraft User:
    MC_DevinYT
    This plugin is originally by @Comedyman937, but I am trying to recreate it.
  4. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    For namespace, change it to devin5412\WarnSystem
  5. Devin5411
    Offline

    Devin5411 Active Member

    Joined:
    Oct 9, 2014
    Posts:
    113
    Minecraft User:
    MC_DevinYT
    When I run through the Inspection again I get the same results.
  6. Devin5411
    Offline

    Devin5411 Active Member

    Joined:
    Oct 9, 2014
    Posts:
    113
    Minecraft User:
    MC_DevinYT
    Any other things you can think of @MCPEPIG
  7. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    - Register events
    - Use [php]Code here[/php]
    - Remove "?>" from the end
  8. Devin5411
    Offline

    Devin5411 Active Member

    Joined:
    Oct 9, 2014
    Posts:
    113
    Minecraft User:
    MC_DevinYT
    How do I register the events
  9. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    Add this to onEnable:
    PHP:
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    Legoboy0215 and Devin5411 like this.
  10. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
  11. Devin5411
    Offline

    Devin5411 Active Member

    Joined:
    Oct 9, 2014
    Posts:
    113
    Minecraft User:
    MC_DevinYT
  12. Devin5411
    Offline

    Devin5411 Active Member

    Joined:
    Oct 9, 2014
    Posts:
    113
    Minecraft User:
    MC_DevinYT
    I'll edit it so instead of the prefix LegoCraft it will say WarnSystem @Legoboy0215
    Legoboy0215 likes this.
  13. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    That is not a edit at all. I did try to submit but got rejected. This was my first test :p
    BTW, if you even DARE submit it then I will file a DMCA complaint :)
    Learn PHP!
  14. Devin5411
    Offline

    Devin5411 Active Member

    Joined:
    Oct 9, 2014
    Posts:
    113
    Minecraft User:
    MC_DevinYT
    Haha I just asked you could of said no
    Legoboy0215 likes this.
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Please read about namespaces on http://lgpe.co/tut ; you are using them wrongly.
    Do you even know what DMCA is? Who are you going to file it to?
    Devin5411 and jojoe77777 like this.
  16. Devin5411
    Offline

    Devin5411 Active Member

    Joined:
    Oct 9, 2014
    Posts:
    113
    Minecraft User:
    MC_DevinYT

Share This Page

Advertisement