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

Effect Remove Help

Comments in 'Plugin Development' started by SM11, Aug 18, 2015.

  1. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    What do u mean Outside?
  2. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Figured it out, But it when I use the Command it, It brings up the Usage and It Doesn't function
  3. Rspuds
    Offline

    Rspuds New Member

    Joined:
    Aug 4, 2015
    Posts:
    53
    You need to return true to fix it sending the usage. As for it not functioning I need to see new code again
  4. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    PHP:
    <?php

    namespace SM11\EffectRemove;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\effect\Effect;

    class 
    Main extends PluginBase{

        public function 
    onEnable(){
            
    $this->getLogger()->info("EffectRemove have been Enabled!");
        }

        public function 
    onDisable(){
            
    $this->getLogger()->info("EffectRemove Have been Enabled!");
        }

       public function 
    onCommand(CommandSender $sender,Command $cmd,$label, array $args) {
         if (
    $cmd->getName() != "er") return false;
         if (
    count($args) != 0) return false;
             
    $this->removeEffectFromWorld($args[0], $args[1]);

    }
       public function 
    removeEffectFromWorld(Level $world$effectId){
             
    $effectName Effect::getEffect($effectId)->getName();
             foreach(
    $world->getPlayers() as $p){
             if(
    $p->hasEffect($effectId)){
             
    $p->removeEffect($effectId);
             
    $p->sendMessage('[EffectRemover] '.$effectName.' effect has been taken away');
             }
             }
             
    $this->getServer()->broadcastMessage('[EffectRemover] '.ucfirst($effectName).' effect have been taken away from '.$world->getName().' world');
             return 
    true;
    }

       }
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    SM11 remember. We cant help you if we dont see code!
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    if (count($args) != 0) return false;
    It stops right there
    do this
    if(count($args) != 2) return false;
    $this->removeEffectFromWorld($this->getServer()->getLevelByName($args[0], $args[1]))
  7. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Sorry I Posted the Code Above you post
  8. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    wow syntax error :D
    do this: $this->getServer()->getLevelByName($args[0])
  9. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    [CRITICAL] Unhandled exception executing command 'er world speed' in er: Argument 1 passed to SM11\EffectRemove\Main::removeEffectFromWorld() must be an instance of SM11\EffectRemove\Level, instance of pocketmine\level\Level given, called in C:\Users\shawn_000\Desktop\MCPE Test Pocketmine\PocketMine-MPTest\plugins\EffectRemove\src\SM11\EffectRemove\Main.php on line 23 and defined

    10:34:41[NOTICE] InvalidArgumentException: "Argument 1 passed to SM11\EffectRemove\Main::removeEffectFromWorld() must be an instance of SM11\EffectRemove\Level, instance of pocketmine\level\Level given, called in C:\Users\shawn_000\Desktop\MCPE Test Pocketmine\PocketMine-MPTest\plugins\EffectRemove\src\SM11\EffectRemove\Main.php on line 23 and defined" (E_RECOVERABLE_ERROR) in "/EffectRemove/src/SM11/EffectRemove/Main" at line 26
  10. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Now it Says something different
    Unhandled exception executing command 'er world speed' in er: Argument 1 passed to SM11\EffectRemove\Main::removeEffectFromWorld() must be an instance of SM11\EffectRemove\Level, instance of pocketmine\level\Level given, called in C:\Users\shawn_000\Desktop\MCPE Test Pocketmine\PocketMine-MPTest\plugins\EffectRemove\src\SM11\EffectRemove\Main.php on line 24 and defined

    10:36:03[NOTICE] InvalidArgumentException: "Argument 1 passed to SM11\EffectRemove\Main::removeEffectFromWorld() must be an instance of SM11\EffectRemove\Level, instance of pocketmine\level\Level given, called in C:\Users\shawn_000\Desktop\MCPE Test Pocketmine\PocketMine-MPTest\plugins\EffectRemove\src\SM11\EffectRemove\Main.php on line 24 and defined" (E_RECOVERABLE_ERROR) in "/EffectRemove/src/SM11/EffectRemove/Main" at line 27
  11. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    lol, add
    PHP:
    use pocketmine\level\Level;
  12. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    [CRITICAL] Unhandled exception executing command 'er world speed' in er: Missing argument 2 for SM11\EffectRemove\Main::removeEffectFromWorld(), called in C:\Users\shawn_000\Desktop\MCPE Test Pocketmine\PocketMine-MPTest\plugins\EffectRemove\src\SM11\EffectRemove\Main.php on line 25 and defined

    10:39:24[WARNING] RuntimeException: "Missing argument 2 for SM11\EffectRemove\Main::removeEffectFromWorld(), called in C:\Users\shawn_000\Desktop\MCPE Test Pocketmine\PocketMine-MPTest\plugins\EffectRemove\src\SM11\EffectRemove\Main.php on line 25 and defined" (E_WARNING) in "/EffectRemove/src/SM11/EffectRemove/Main" at line 28
  13. Rspuds
    Offline

    Rspuds New Member

    Joined:
    Aug 4, 2015
    Posts:
    53
    Can you post code again
  14. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    PHP:
    <?php

    namespace SM11\EffectRemove;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\effect\Effect;
    use 
    pocketmine\level\Level;

    class 
    Main extends PluginBase{

        public function 
    onEnable(){
            
    $this->getLogger()->info("EffectRemove have been Enabled!");
        }

        public function 
    onDisable(){
            
    $this->getLogger()->info("EffectRemove Have been Enabled!");
        }

       public function 
    onCommand(CommandSender $sender,Command $cmd,$label, array $args) {
         if (
    $cmd->getName() != "Er") return false;
         if(
    count($args) != 2) return false;
             
    $this->getServer()->getLevelByName($args[0]);
             
    $this->removeEffectFromWorld($this->getServer()->getLevelByName($args[0], $args[1]));
           
    }
       public function 
    removeEffectFromWorld(Level $world$effectId){
             
    $effectName Effect::getEffect($effectId)->getName();
             foreach(
    $world->getPlayers() as $p){
             if(
    $p->hasEffect($effectId)){
             
    $p->removeEffect($effectId);
             
    $p->sendPopup('[SSM] '.$effectName.'May The Match Begin');
             }
             }
             
    $this->getServer()->SendPopup('[SSM] '.ucfirst($effectName).' Match Has started'.$world->getName().' world');
             return 
    true;
    }

       }
  15. Rspuds
    Offline

    Rspuds New Member

    Joined:
    Aug 4, 2015
    Posts:
    53
    when does it give the error. On loading the plugin or when you use the command?
  16. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    When I use the Command
  17. Rspuds
    Offline

    Rspuds New Member

    Joined:
    Aug 4, 2015
    Posts:
    53
    I think you are putting in to many arguments when using the command then. You should only have 2 arguments ($args[0] and $args[1]) but this says argument 2. show me what you are putting in chat for the command
  18. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    /er <world> <effect>
  19. Rspuds
    Offline

    Rspuds New Member

    Joined:
    Aug 4, 2015
    Posts:
    53
    Ok i think i figured it out

    PHP:
    $this->removeEffectFromWorld($this->getServer()->getLevelByName($args[0], $args[1]));
    I don't think you need "$this->getServer()->getLevelByName" and if you do need that info you are getting it in the wrong place.

    Try this and I think it should work...

    PHP:
    $this->removeEffectFromWorld($args[0], $args[1]);
  20. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    it didn't work

Share This Page

Advertisement