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

Can someone please check my coding

Comments in 'Plugin Development' started by Deathcrow, Sep 17, 2015.

Thread Status:
Not open for further replies.
  1. Deathcrow
    Offline

    Deathcrow Active Member

    Joined:
    Aug 20, 2015
    Posts:
    61
    Minecraft User:
    Deathcrow
    hello i would like to someone to check and see if everything is correct
    PHP:
    <?php
    namespace LiveWireTech\ItemEnchantment;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\item\enchantment\EnchantmentEntry;
    use 
    pocketmine\item\enchantment\EnchantmentList;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\item\enchantment\Enchantment;
    class 
    ItemEnchantment extends PluginBase{
    public function 
    onEnable(){
    $this->saveDefaultConfig();
    $this->getConfig()->set("itemid""261");
    $this->getConfig()->set("enchantment","2");
    $this->getLogger()->info("ItemEnchantment has been loaded");
    }
    public function 
    onDisable(){
    $this->getLogger()->info("ItemEnchantment was disabled");
    }
    public function 
    ItemHeld(PlayerItemHeldEvent $event) {
    $item $event->getItem();
    $id $item->getId();
    $damage $item->getDamage();
    }
    public function 
    onCommand(CommandSender $sender,Command $command,$commandLabel, array $args){
    $conItem $this->getConfig()->get("itemid");
    $enchantment $this->getConfig()->get("enchantment");
    if(
    strtolower ($command->getName()) === "EnchantItem"){

       if(
    $id === $conItem){
       
    $item->addEnchantment($enchantment);

       }
    return 
    true;
    }
    return 
    false
    }
    }
    ?>

    EDIT
    this code doesnt work and idk why

    EDIT #2
    The command when its run says
    "Unknown error has occured"
    Last edited: Sep 17, 2015
  2. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    All I can tell you is that if you try to submit it in that state right now, it'll definitely get rejected.
  3. Deathcrow
    Offline

    Deathcrow Active Member

    Joined:
    Aug 20, 2015
    Posts:
    61
    Minecraft User:
    Deathcrow
    Not trying to submit it its mainly for personal use
  4. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Yeah it looks good I guess.
  5. Deathcrow
    Offline

    Deathcrow Active Member

    Joined:
    Aug 20, 2015
    Posts:
    61
    Minecraft User:
    Deathcrow
    :(My code doesnt work and idk why
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    He's coding style definataly sucks
    iDirtPlayzMC likes this.
  7. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    you did strtolower($command->getName()) === 'EnchantItem' :D do === 'enchantitem'
    MCPEPIG and iDirtPlayzMC like this.
  8. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Add how the heck you think we can help with that information???
    iDirtPlayzMC likes this.
  9. Deathcrow
    Offline

    Deathcrow Active Member

    Joined:
    Aug 20, 2015
    Posts:
    61
    Minecraft User:
    Deathcrow
    "Unknown error has occured" when running command
  10. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Did you know: You can get more detailed information in your console -_-
    Legoboy0215 likes this.
  11. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
    There's no need to be rude about it... Programming is difficult, the last thing he wants is a remark like that.
    Legoboy0215 and HotFireyDeath like this.
  12. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
  13. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    In the onCommand method, "$id" is undefined.
    Taha_The_Hacker likes this.
  14. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    and $item and other shit... @Deathcrow why did you set all the variables in a completely different event? get the item in hand onCommand also i beleive addEnchantment takes a enchantment object not a integer
  15. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Can you show the console error message when you run the command?
  16. Deathcrow
    Offline

    Deathcrow Active Member

    Joined:
    Aug 20, 2015
    Posts:
    61
    Minecraft User:
    Deathcrow
    It says unidentified variable id
  17. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    You didnt define $id in onCommand().
  18. Deathcrow
    Offline

    Deathcrow Active Member

    Joined:
    Aug 20, 2015
    Posts:
    61
    Minecraft User:
    Deathcrow
    Honestly i have never seen such rude people in my life i took a HTML5 class last semester to brush up on web development and there were plenty of people who did not quite grasp the concepts but i sought to help them out and not ridicule them
  19. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    You will meet alot of people like that on these forums sadly.
    CrazedMiner likes this.
  20. Deathcrow
    Offline

    Deathcrow Active Member

    Joined:
    Aug 20, 2015
    Posts:
    61
    Minecraft User:
    Deathcrow
    I changed it to this but still get same error in log
    PHP:
    public function onCommand(CommandSender $sender,Command $command,$commandLabel, array $args){
    $item $event->getItem();
    $id $item->getId();
    $damage $item->getDamage();
    $conItem $this->getConfig()->get("itemid");
    $enchantment $this->getConfig()->get("enchantment");

    if(
    strtolower ($command->getName()) === "enchantitem"){
     
       if(
    $id === $conItem){
       
    $item->addEnchantment($enchantment);
      

       }

    }


    }
Thread Status:
Not open for further replies.

Share This Page

Advertisement