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

Code behaving unexpectedly

Comments in 'Plugin Development' started by minebuilder0110, Jan 16, 2016.

  1. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    PHP:
    case "sethome":
                if(!isset(
    $homes)){
                
    $homes = array();
                
    $homeCount 0;
                } else {
                
    $homes $this->homes->getNested("$name.homes.$level");
                
    $homeCount count($homes);
                }
                
    $sender->sendMessage("$maxHomes   $homeCount");
                if(!
    $sender instanceof Player){
                    
    $sender->sendMessage(TextFormat::RED "This command is valid in-game only.");
                    return 
    true;
                }
                if(!isset(
    $args[0]) || isset($args[1])){
                    
    $sender->sendMessage(TextFormat::RED "One argument is required.");
                    return 
    false;
                }
                if(
    $homeCount >= $maxHomes){
                    
    $sender->sendMessage("You have reached your maximum home limit.");
                    return 
    true;
                }
                
    $x $sender->getX();
                
    $y $sender->getY();
                
    $z $sender->getZ();
                
    $data = array($x$y$z);
                
    $this->homes->setNested("$name.homes.$level." $args[0] . ""$data);
                
    $this->homes->save();
                
    $homesLeft $maxHomes $homeCount;
                
    $sender->sendMessage("You have successfully created a new home: " $args[0] . ". Now you have $homesLeft home left.");
                break;
    case 
    "home":
                if(!isset(
    $homes)){
                    
    $sender->sendMessage("You do not have a home.");
                    return 
    true;
                }
                foreach(
    $homes as $homeName){
                    if(!isset(
    $args[0])){
                        
    $sender->sendMessage("Available homes:");
                        
    $sender->sendMessage($homeName);
                        
    $sender->sendMessage("You currently have $homeCount/$maxHomes homes");
                        return 
    true;
                    }
                    if(!
    $homeName === $args[0]){
                        
    $sender->sendMessage("That home does not exist.");
                        return 
    true;
                    }
                    
    $coordinate $this->homes->getNested("$name.homes.$level." $args[0] . "");
                    
    $sender->teleport(new Position($coordinate[0], $coordinate[1], $coordinate[2]));
                    
    $sender->sendMessage("You have been teleported to your home: " $args[0] . ".");
                    return 
    true;
                    break;
    (I would like to tell you that there are much more in this code, but this is the part I am having trouble with. This means that the bracket might be missing. Also, sorry for the amount of codes, I am absolutely desperate.)
    I have written this code myself, and I have noticed millions of problems that have been annoying me since couple of days ago.
    1. In the sethome section, $homeCount does not update unless I stop the server. I was pretty sure it would update, but it get stuck at that instance of number of homes.
    2. In the home section, I am getting RuntimeException: "Illegal offset type in isset or empty" errors. I have no idea what this means, and what is even worse is that when it used to work, $homeName only returned the first home name only.
    3. In the home section again, there is a part where I check if that home exists. It just doesn't work. I thought it would behave like what happened in the problem 2 and block anything but the first home, but it just lets all the homes.

    It would be superb if you answered at least one of them, and even better if you find other mistakes. I am not that good with coding still, so it would help me a lot. Thank you in advance.
  2. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Can you please upload all of the code? It's really hard to help when we don't know which kind of objects the properties are.

    Also, if you don't want to share the code to the public, feel free to PM me it.
    Last edited: Jan 16, 2016
  3. KubixQ
    Offline

    KubixQ Active Member

    Joined:
    Sep 13, 2015
    Posts:
    85
    Minecraft User:
    KubixQ
    Why you don't use SetHome plugin, or copy code from this plugin to your plugin? :D
  4. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    That's not really the point if he wants to learn.
    KubixQ likes this.

Share This Page

Advertisement