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

Tutorial Common PocketMine API / OO mistakes

Comments in 'Resources' started by Legoboy0215, Jan 7, 2016.

  1. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Ok. Let me get this straight. This tutorial just lists some common mistakes I have seen in this forums Plugin Development section or Plugin repo. Remember to comment if you have suggestions. Don't blame me for creating the mistake. (What am I talking about :confused:)

    1. 323, my love. Well, if you have been on this forums for a few months, you should have seen this even if you did not notice it. Usual code:

    PHP:
    public function onTap(PlayerInteractEvent $event){
       
    $player $event->getPlayer();
       
    $sign $event->getBlock();
       
    $id $sign->getId();
       if(
    $id === Block::SIGN_POST || $id === Block::WALL_SIGN || $id === 323){
           
    //Imagine something...
       
    }
    }
    What's the problem? WAIT. ISN'T 323 an item id? Yep. This is not really an error, but just plain old bad practice.

    2. Can't find my class. Do I have english now? Classes are basic stuff in OOP. But when PocketMine can't find them, you're in big trouble. Simple. No code examples here. Just check your namespace in the file. the main in plugin.yml and the folder structure. For example:

    Code:
    Example:
    --- src
         --- Legoboy
             --- Example
                 --- Main.php
                 --- AnotherClass.php
    --- plugin.yml
    
    In the structure above, main inside the plugin.yml should be:

    Code:
    main: Legoboy\Example\Main
    
    And the namespace code should be:

    PHP:
    <?php

    namespace Legoboy\Example;

    //Code here.
    3. Code error. WTF is this? Come on. Every programming language will out put an HUMAN READABLE error so that we can fix it, obviously. Here is one error for you to think of:

    Code:
    UndefinedVariableException: "Undefined variable: hi" (E_NOTICE) in "/plugins/Example/src/Legoboy/Example/Main" at line 18
    
    What is this error about? Oh. Obviously PM has a massive bug! Go on GitHub and report the issue, then open a thread named "PM MASSIVE ISSUE". Now, lets be serious. Read the first word in the message:
    UndefinedVariableException. Un-defined variable. A variable has not been defined. It even mentions which file and which line the error occurs in!!! *facepalm*

    4. Two PHP files. Simple. They are classes, not files. http://forums.pocketmine.net/threads/create-two-php-files-in-a-plugin.12728/

    5. Any things? Comment below!!!

    Simple advice:
    Additional resources: http://forums.pocketmine.net/threads/debugging-cheat-sheet.4532/

    Like and DON'T follow if you think this helped you!
    Last edited: Jan 7, 2016
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
  3. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    I can't edit the post ?!
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You should be able to. Reload the page.
    Also, reload to check my edited post.
  5. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    I did. LOL I am going to die. No I am just serious.
  6. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Also, is common see people using globals x)
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Actually, there are very few.
    I actually tried using them in my first old API plugins, but at that time I only knew $GLOBALS and PocketMine disabled it :p
  8. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Why does everyone on PocketMine hate IDs? IDs are shorter and better to mind (because everybody has different calls to an item/block).
  9. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    When did I say I hate ids?
    PEMapModder likes this.
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    We are saying that people are checking a block ID to be an item ID, because they copied code.

    It is definitely most efficient to check by ID, (and damage if you need).
  11. Thunder33345
    Offline

    Thunder33345 Notable Member

    Joined:
    Apr 3, 2014
    Posts:
    755
    Minecraft User:
    Thunder33345
    can anyone explain why 1 is bad and what is a hotfix then if you say 1 is bad?(if there no hot fix i guess that is the only way we will roll)
  12. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    What?
  13. Thunder33345
    Offline

    Thunder33345 Notable Member

    Joined:
    Apr 3, 2014
    Posts:
    755
    Minecraft User:
    Thunder33345
    if you say 1 is a bad practice what is a good practice that can replace 1?
  14. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Remove 323 checking. Just check the WallSign or SignPost.
  15. Thunder33345
    Offline

    Thunder33345 Notable Member

    Joined:
    Apr 3, 2014
    Posts:
    755
    Minecraft User:
    Thunder33345
    you mean
    if $block instanceof Sign
    ?
  16. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Yah or use id to check WallSign or SignPost.
  17. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
  18. saedsohili
    Offline

    saedsohili New Member

    Joined:
    Aug 10, 2016
    Posts:
    2
    Minecraft User:
    saedsohili
    My name is saed.i downloaded netbeans and I like make plugin but I don't know to use which codes to make plugin.
    Please help me.(sorry for my bad English).

Share This Page

Advertisement