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

help with translating user commands to console commands

Comments in 'Plugin Development' started by unerds, Jan 17, 2014.

  1. unerds
    Offline

    unerds Redditor Plugin Developer

    Joined:
    Aug 28, 2013
    Posts:
    82
    Plugins:
    1
    Minecraft User:
    unerds_
    uhhh, i'd like to apologize in advance for the extent of my ignorance :D

    now, I've recently begun working on beAreaGuard with the expressed permission of Blue Electric.

    I've been asked by a user to provide console access to two commands within that plugin.

    /areaworld and /areabuilder

    Code:
    case "areabuilder":
               if ( $user instanceof Player ){ }
               else {
                   return "This Command In-Player Only";
               }
                   
               if( !isset( $argments[0] ) ) { return "Invalid"; }
               
               if( isset( $argments[1] ) )
               {
                   foreach ($this->config["area_whiteworld"][$user->level->getName()] as $key => $builder)
                   {
                       if($builder == $user->username)
                       {
                           unset( $this->config["area_whiteworld"][$user->level->getName()][$key] );
                           $this->writeConfig();
                       }
                   }
                   return "Removed";
               }
               
               if( isset( $this->config["area_whiteworld"][$user->level->getName()] ) )
               {
                   $this->config["area_whiteworld"][$user->level->getName()][] = $argments[0];
                   $this->writeConfig();
                   return $argments[0] . " Added to Builder on This World";
               }
               else
               {
                   return "Your World Not WhiteWorld";
               }
               break;


    now, i'm at about a negative 10 skill level here, but here is my thought on how to make this work.

    line 4 of that snippet (return "This Command In-Player Only";) would need to be replaced with a translated version of next if statement, where the [$user->level->getName()] would be converted to a format that doesn't call on the $user (since it'll be run by the console, not a user)

    so i would then have to find some way to have the "areaworld" and "areabuilder" commands allow the console to provide the level name, as opposed to it getting the level name from what i assume is the users current level?

    i'm not looking for anyone to write the code for me, i just want to know if i'm on the right track in this assumption...

    the error i get when I remove the first if statement is "'Call to a member function getName() on a non-object'," - i'm assuming that $user->level->getName() isn't a proper object when it's not run by a user...?

    i may be in over my head here, but any other insights you might have would be greatly appreciated as well.

    again, please excuse my ignorance... i'll catch up eventually ;)

    cheers, -u.
  2. jython234
    Offline

    jython234 Notable Member Plugin Developer

    Joined:
    Nov 4, 2013
    Posts:
    324
    Plugins:
    1
    Minecraft User:
    jython234
    Well, the console doesn't play right? So it can't get the world the console is in.
  3. unerds
    Offline

    unerds Redditor Plugin Developer

    Joined:
    Aug 28, 2013
    Posts:
    82
    Plugins:
    1
    Minecraft User:
    unerds_
    yes, i assumed as much.

    so i should, instead, attempt to either pull the default worldname or allow the console to specify the worldname when using the /areabuilder command.

    hmm... seems simple enough...
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    So you must make sure $issuer is an instance of Player.
  5. tnpxxsheepdog
    Offline

    tnpxxsheepdog Notable Member

    Joined:
    Dec 31, 2013
    Posts:
    356
    Minecraft User:
    TNPXXSHEEPDOG
    The default world name should be set to "world" anyway as far as I can see it.. I wonder how this will impact multi-world sections. Me confused now...

Share This Page

Advertisement