2 issues about a future plugin

Discussion in 'Development' started by WEATHERCRAFTYT1, Jul 23, 2020.

  1. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Spider Jockey

    Messages:
    26
    Hello im making a build battle plugin and I started doing testing! But i get this error.
    Error: Undefined offset: 2
    PHP:
                                                                        }
                                                                        if(
    $time==10)
                                                                        {
                                                                            
    $points = new Config($this->plugin->getDataFolder() . "/puntos".$arena.".yml"Config::YAML);
                                                                            
    $limit = new Config($this->plugin->getDataFolder() . "/limit.yml"Config::YAML);
                                                                            
    $paints $points->getAll();
                                                                            
    $values = array();
                                                                            foreach(
    $paints as $key => $w){
                                                                                
    array_push($values$w);
                                                                            }
                                                                            
    natsort($values);
                                                                            
    $val array_reverse($values);
                                                                            
    $max max($values);
                                                                            
    $quien array_search($max$paints);
                                                                            
    $thesp $limit->get($quien);
                                                                            
    $this->plugin->getServer()->broadcastMessage($this->prefix .TE::YELLOW">> ".TE::AQUA."BUILD BATTLE WINNERS!!! $arena ".TE::GREEN."($tema)");
                                                                            
    $this->plugin->getServer()->broadcastMessage($this->prefix .TE::YELLOW"1ST°: ".TE::AQUA.$quien." ".TE::GREEN.$max);
                                                                            unset(
    $paints[$quien]);
                                                                            
    $quien2 array_search($val[1], $paints);
                                                                            
    $this->plugin->getServer()->broadcastMessage($this->prefix .TE::GRAY"2ND°: ".TE::AQUA.$quien2." ".TE::GREEN.$val[1]);
                                                                            unset(
    $paints[$quien2]);
                                                                            
    $quien3 array_search($val[2], $paints);
                                                                            
    $this->plugin->getServer()->broadcastMessage($this->prefix .TE::GOLD"3RD°: ".TE::AQUA.$quien3." ".TE::GREEN.$val[2]);
                                                                            foreach(
    $playersArena as $pl) {
                                                                                
    $puntaje $points->get($pl->getName());
                                                                                
    $tupos array_search($puntaje$val);
                                                                                
    $rand mt_rand(12);
                                                                                
    $ra mt_rand(16);
                                                                                if(
    $rand==1)
                                                                                {
                                                                                
    $spawn = new Position($thesp[0]+$ra,$thesp[1]+21,$thesp[2]+0.5,$levelArena);
                                                                                }
                                                                                elseif(
    $rand==2)
                                                                                {
                                                                                
    $spawn = new Position($thesp[0]-$ra,$thesp[1]+21,$thesp[2]+0.5,$levelArena);
                                                                                }
                                                                                
    $pl->sendMessage($this->prefix .TE::GREEN"Percentage of how players rated you: ".TE::YELLOW.$tupos."°: ".TE::GREEN.$puntaje);
                                                                                
    $pl->teleport($spawn,0,0);
                                                                            }
                                                                        }
    Later when i start my server again i get this new issue.

    Error: syntax error, unexpected 'else' (T_ELSE), expecting function (T_FUNCTION) or const (T_CONST) on
    PHP:
     public function Puntuar(PlayerItemHeldEvent $event) {
                
    $player $event->getPlayer();
                
    $level $player->getLevel()->getFolderName();
                if(
    in_array($level,$this->arenas))
                {
                    
    $config = new Config($this->getDataFolder() . "/config.yml"Config::YAML);
                    
    $time $config->get($level "PlayTime");
                    if(
    $time<=170)
                    {
                        if(
    $config->get("actual".$level)!=$player->getName())
                        {
                            if(
    $event->getItem()->getDamage()==14)
                            {
                                
    $player->sendTip(TE::BOLD.TE::DARK_RED."SHAME TO MY EYES");
                            }
                            elseif(
    $event->getItem()->getDamage()==6)
                            {
                                
    $player->sendTip(TE::BOLD.TE::RED."JUST POOP");
                            }
                            elseif(
    $event->getItem()->getDamage()==5)
                            {
                                
    $player->sendTip(TE::BOLD.TE::GREEN."OK THATS FINE");
                            }
                            elseif(
    $event->getItem()->getDamage()==13)
                            {
                                
    $player->sendTip(TE::BOLD.TE::DARK_GREEN."GOOD I DO LIKE IT");
                            }
                            elseif(
    $event->getItem()->getDamage()==11)
                            {
                                
    $player->sendTip(TE::BOLD.TE::DARK_PURPLE."THIS IS VERY GOOD RECOMMENED");
                            }
                            elseif(
    $event->getItem()->getDamage()==4)
                            {
                                
    $player->sendTip(TE::BOLD.TE::GOLD."NOW THIS SHOULD BE ON THE SERVER");
                            }
                        }
        
                            else
                        {
                            
    $player->sendTip(TE::BOLD.TE::RED."You cant vote your own Plot Silly.");
                        }
                    }
                }
            }
    anyone can help how to change this to success
     
  2. minijaham

    minijaham Baby Zombie

    Messages:
    100
    GitHub:
    minijaham
    It's a syntax error. I can see that you forgot to add one bracket at the end
     
  3. Primus

    Primus Zombie Pigman

    Messages:
    434
    If you've written so much code, but still don't know how to fix a simple syntax error. Then I have suspicions that you are just copying and pasting stuff.
     
    Taco and minijaham like this.
  4. Kygekraqmak

    Kygekraqmak Spider Jockey

    Messages:
    41
    GitHub:
    Kygekraqmak
    Try to use this

    PHP:
    public function Puntuar(PlayerItemHeldEvent $event) {
        
    $player $event->getPlayer();
        
    $level $player->getLevel()->getFolderName();
        if(
    in_array($level,$this->arenas)) {
            
    $config = new Config($this->getDataFolder() . "/config.yml"Config::YAML);
            
    $time $config->get($level "PlayTime");
            if(
    $time<=170) {
                if(
    $config->get("actual".$level)!=$player->getName()) {
                    switch(
    $event->getItem()->getDamage()) {
                        case 
    14:
                            
    $player->sendTip(TE::BOLD.TE::DARK_RED."SHAME TO MY EYES");
                        break;
                        case 
    6:
                            
    $player->sendTip(TE::BOLD.TE::RED."JUST POOP");
                        break;
                        case 
    5:
                            
    $player->sendTip(TE::BOLD.TE::GREEN."OK THATS FINE");
                        break;
                        case 
    13:
                            
    $player->sendTip(TE::BOLD.TE::DARK_GREEN."GOOD I DO LIKE IT");
                        break;
                        case 
    11:
                            
    $player->sendTip(TE::BOLD.TE::DARK_PURPLE."THIS IS VERY GOOD RECOMMENED");
                        break;
                        case 
    4:
                            
    $player->sendTip(TE::BOLD.TE::GOLD."NOW THIS SHOULD BE ON THE SERVER");
                        break;
                    }
                } else {
                    
    $player->sendTip(TE::BOLD.TE::RED."You cant vote your own Plot Silly.");
                }
            }
        }
    }
    Consider using switch if you have to use many elseif-es.
     
    Last edited: Sep 13, 2020

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.