1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

help with plugin

Discussion in 'Help' started by sxkumo, Feb 17, 2021.

  1. sxkumo

    sxkumo Silverfish

    Messages:
    18
    GitHub:
    sxkumo
    [Server thread/CRITICAL]: ParseError: "syntax error, unexpected end of file, expecting function (T_FUNCTION) or const (T_CONST)" (EXCEPTION) in "plugins/CustomUi/src/kumo/CustomUi/Main" at line 64, is one of the errors i get ill show the code down here.
    <?php

    namespace kumo\CustomUi;

    use pocketmine\Server;
    use pocketmine\Player;
    use pocketmine\plugin\PluginBase;

    use pocketmine\command\Command;
    use pocketmine\command\CommandSender;

    use pocketmine\event\Listener;
    use pocketmine\event\player\PlayerInteractEvent;

    use pocketmine\utils\TextFormats;


    class Main extends PluginBase implements Lisener {

    public $interactdelay = [] ;

    public function onEnable() {
    $this->getServer()->getPluginManager()->registerEvents($this, $this);
    }

    public function onCommand(CommandSender $sender, Command $cmd, string $label, array $args) : bool{
    switch($cmd->getName()){
    case "test":
    if($sender instanceof Player) {
    $this->openServerForm($sender);
    }
    break;

    }
    return true;
    }

    public function onInteract (PlayerInteractEvent $event){
    $player = $event->getPlayer();
    $item = $event->getItem();



    if($item->getId() == 1){



    if(!isset($this->interactDelay[$player->getName()])){

    $this->interactDelay[$player->getName()] = time() + 1;

    $this->openServerForm($player);
    } else {


    if(time() >= $this->interactDelay[$player->getName()]){


    unset ($this->interactDelay[$player->getName()]);
    }
    }

    }
    }

    last line is 64. i dont understand what im doing wrong help please
     
  2. sxkumo

    sxkumo Silverfish

    Messages:
    18
    GitHub:
    sxkumo
    ALL ERRORS I GET

    [21:08:17] [Server thread/CRITICAL]: ParseError: "syntax error, unexpected end of file, expecting function (T_FUNCTION) or const (T_CONST)" (EXCEPTION) in "plugins/CustomUi/src/kumo/CustomUi/Main" at line 64

    [21:08:17] [Server thread/CRITICAL]: #0 pmsrc/vendor/pocketmine/classloader/src/BaseClassLoader(124): BaseClassLoader->loadClass(string[18] kumo\CustomUi\Main)

    [21:08:17] [Server thread/CRITICAL]: #1 (): BaseClassLoader->{closure}(string[18] kumo\CustomUi\Main)

    [21:08:17] [Server thread/CRITICAL]: #2 (): spl_autoload_call(string[18] kumo\CustomUi\Main)

    [21:08:17] [Server thread/CRITICAL]: #3 pmsrc/src/pocketmine/plugin/PluginManager(167): class_exists(string[18] kumo\CustomUi\Main, boolean 1)

    [21:08:17] [Server thread/CRITICAL]: #4 pmsrc/src/pocketmine/plugin/PluginManager(346): pocketmine\plugin\PluginManager->loadPlugin(string[31] /home/gs-41890/plugins/CustomUi, array[1])
     
  3. Primus

    Primus Zombie Pigman

    Messages:
    749
    There is one, not many errors in that particular messages. Rest of the log contains stack trace, a path of calls the code took to wind up where it did.

    Any half decent IDE (a Code editor) would show you the cause of that error. Sometimes it is tricky, because php can't pin point where you have missed a semi-colon or a curly bracket. The language itself is not space, newline or tab sensitive, so looking at example below
    PHP:
    echo "Hello, World!"
    $i++;

    // The parser sees this as one line
    echo "Hello, world" $i++;
    As you know the format for this language construct is "echo <scalar value>;" so having provided it with the string the statement is done and should be explicitly made clear with a semi-colon. However if you do not, it will go onto next line and see no reason why "$i++" is there and the parser will point at that line instead of the one where the colon is missing. It's better to seek reasoning behind why it happened rather than the solution, most of the time, that grants the other.

    echo is not a function, and thats a fact.

    In this case you're missing an extra semi colon at the end, the error message "unexpected end of file" makes it clear. I'm all for seeking help if needed, it just sad that I see no effort in resolving the issue or at least googling the error.

    A healthy example of someone asking help for the same issue: https://www.codeproject.com/Questions/1190928/Why-is-this-error-exist-Parse-error-syntax-error-u
    OP points out that he did try changing a lot of things, but couldn't see why it still occurred.
     
    minijaham likes this.
  4. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    ffs what’s so hard about learning php damn

    or even “coding” in general
     
  5. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Read the error. It says it right there that you wrote something wrong or like Primus said earlier, you are missing something.
    Every errors tells you what’s wrong in the FIRST line. Read :/
     
    Primus likes this.
  6. Primus

    Primus Zombie Pigman

    Messages:
    749
    and yet they know to group their imports, register listeners and handle commands
     
    minijaham likes this.
  7. sxkumo

    sxkumo Silverfish

    Messages:
    18
    GitHub:
    sxkumo
    jeez bro chill this is my first time and i do read ive been looking for the issue but each time i fix it it just say issue with like 63 or 65 it just keeps repeating
     
  8. sxkumo

    sxkumo Silverfish

    Messages:
    18
    GitHub:
    sxkumo
    honestly im trying to understand what youre saying but as me being pretty new its little hard i understand everything needs to be the right function and characters and stuff i just cant find the issue for this code even though ive been trying for hours now..
     
  9. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    I GOT YOU MATE!! Wait here!! Ill be fixing the code soon...
     
  10. sxkumo

    sxkumo Silverfish

    Messages:
    18
    GitHub:
    sxkumo
    thank you mate i would appreiate it also could the isue be with the yml file?cause i have done anything to it
     
  11. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    PHP:
    <?php

    namespace kumo\CustomUi;

    use 
    pocketmine\{
        
    Server,
        
    Player,
        
    plugin\PluginBase
    };
    use 
    pocketmine\command\{
        
    Command,
        
    CommandSender
    };

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerInteractEvent;

    use 
    pocketmine\utils\TextFormat;

    class 
    Main extends PluginBase implements Lisener {

        public 
    $interactdelay = [] ;

        public function 
    onEnable() {
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }

        public function 
    onCommand(CommandSender $senderCommand $cmdstring $label, array $args) : bool {
            switch(
    $cmd->getName()) {
                case 
    "test":
                if(
    $sender instanceof Player) {
                    
    $this->openServerForm($sender);
                }
            }
            return 
    true;
        }

        public function 
    onInteract(PlayerInteractEvent $event){
            
    $player $event->getPlayer();
            
    $item $event->getItem();
            if(
    $item->getId() == 1) {
                if(!isset(
    $this->interactDelay[$player->getName()])) {
                    
    $this->interactDelay[$player->getName()] = time() + 1;
                    
    $this->openServerForm($player);
                } else {
                    if(
    time() >= $this->interactDelay[$player->getName()]){
                        unset (
    $this->interactDelay[$player->getName()]);
                    }
                }
            }
        }
    }
    Test if this works. I got rid of the syntax errors and made some minor edits.
     
  12. sxkumo

    sxkumo Silverfish

    Messages:
    18
    GitHub:
    sxkumo
    wow thanks man ive been looking for the error i just couldnt find it..mind telling me what the problem was?also it loaded but now this came up
    }[08:20:03] [Server thread/ERROR]: Main class for plugin CustomUi not found

    [08:20:03] [Server thread/CRITICAL]: Could not load plugin 'CustomUi'
     
  13. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Show me your plugin.yml

    Do you have discord? I can tell you what to do there because it's much easier for me to communicate there
     
  14. sxkumo

    sxkumo Silverfish

    Messages:
    18
    GitHub:
    sxkumo
    yea i think thats the issue i dont know what to do with it.
     
  15. sxkumo

    sxkumo Silverfish

    Messages:
    18
    GitHub:
    sxkumo
    #Name of your plugin. This is self-explanatory. Plugin names SHOULD NOT contain spaces.
    name: CustomUi

    #Fully-qualified class-name of your plugin's main class. This is usually the one that extends PluginBase.
    #Since PocketMine-MP's autoloader is PSR-0, your plugin's main-class namespace will usually be the same as the folder path.
    main: kumo\CustomUi\Main

    #Version name/number of your plugin
    version: 0.0.1

    #API version that your plugin supports. If your plugin's API is not compatible with that of the server, the server will refuse to load your plugin.
    #The API version is changed when:
    # - Breaking changes are made to a development version, things that might cause your plugin to crash.
    # This is denoted by an API suffix, for example 3.0.0-ALPHA4. If the version does not match as a whole on a development version, the plugin will not be loaded. (Suffixes are non-case-sensitive.)
    # - Breaking changes are made to a release version, things that might cause your plugin to crash.
    # This usually warrants a major API bump, e.g. 2.0.0 -> 3.0.0. If the major version does not match, the plugin will not be loaded.
    # - Feature additions which do not break existing plugins.
    # This is denoted by a minor API bump, e.g. 2.0.0 -> 2.1.0. The server will load plugins with an equivalent or older minor version.
    # - Minor bug fixes or insignificant alterations to the API.
    # This is denoted by a patch bump, e.g. 1.13.0 -> 1.13.1
    api: 3.17.5

    #When to load the plugin. There are currently two options for this: STARTUP and POSTWORLD. Usually POSTWORLD will do fine.
    load: POSTWORLD

    #Name of the person who wrote the plugin. This can be anything you like.
    author: kumo

    #Simple description of what the plugin is or does. Try to keep this short.
    description: Custom UI Items

    #Website for your plugin. This could be a GitHub repository URL, a website of your own, or anything you like. This is optional.
    website: https://github.com/pmmp/PocketMine-DevTools

    #Commands that your plugin has. You can capture the execution of these via the `onCommand()` method in your PluginBase, or the registered CommandExecutor for the command.
    #This node is optional and can be removed if your plugin will not have any commands.
    commands:
    #Name of the command. This is what people will type to execute the command.
    examplecommand:
    #Description to show in the Help command
    description: "Skeleton plugin example command"
    #Usage message shown to the user if they type the command in incorrectly.
    usage: "/test"
    #Permission required to execute the command. This should be the name of a permission defined in the section below.
    permission: skeleton.command

    #Define permissions used in your plugin here. You can check whether permissibles have permissions in your plugin to allow or disallow actions such as command execution.
    permissions:
    #Root permission node
    skeleton:
    #Default state of this permission. `op` means that only server operators will have this permission by default.
    default: true
    #Description of what the permission does or doesn't allow.
    description: "broke"
    #Child permission nodes. If the parent permission node is true, the children will have the values set here. If false, all child permissions will be inverted.
    children:
    skeleton.command:
    default: true
    description: "Allows the use of /test"
     
  16. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Add me on discord

    minijaham#1939
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.