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

what wrong this code ?

Comments in 'Plugin Development' started by PmServer, Mar 28, 2016.

  1. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    PHP:
    public function onBlockBreak(BlockBreakEvent $event) {
              
            
    $player $event->getPlayer();
            
    $x = (Int)$event->getBlock()->getX();
            
    $y = (Int)$event->getBlock()->getY();
            
    $z = (Int)$event->getBlock()->getZ();
            
    $level $event->getBlock()->getLevel()->getName();
            
    $blue $this->getConfig()->get("BlueFlag");
            
    $red $this->getConfig()->get("RedFlag");
          
            if (isset(
    $this->editors[$player->getName()])) {
                
    $event->setCancelled(false);
            }
          
            else if (
    $x == $blue["x"] and $y == $blue["y"] and $z == $blue["z"] and $level $blue["level"]) {
                if (
    array_key_exists($player->getName(), $this->temp["RedPlayers"])) { // player is on red team
                    
    $event->setCancelled();
                    
    $item = new Item(35111);
                    
    $player->getInventory()->addItem($item);
                    if (isset(
    $this->temp[$player->getName()])) {
                    
    $player->sendMessage("You can only place the flag once.");
                    }
                    else {
                    
    $this->getServer()->broadcastMessage(TextFormat::GREEN." . $player->getDisplayName() . " captured the BLUE teams flag!");
                    
    $this->temp[$player->getName()] = true;
                    
    $player->setNameTag(TextFormat::RED." $player->getName());
                    }
                }
                else {
                
    $event->setCancelled();
                }
            }
            else if (
    $x == $red["x"] and $y == $red["y"] and $z == $red["z"] and $level == $red["level"]) {
                if (
    array_key_exists($player->getName(), $this->temp["BluePlayers"])) { // player is on blue team
                    
    $event->setCancelled();
                    
    $item = new Item(35,141);
                    
    $player->getInventory()->addItem($item);
                    if (isset(
    $this->temp[$player->getName()])) {
                    
    $player->sendMessage("You can only place the flag once.");
                    }
                    else {
                    
    $this->getServer()->broadcastMessage(TextFormat::GREEN." . $player->getDisplayName() . "captured the RED teams flag!"); // this line 108
                    
    $this->temp[$player->getName()] = true;
                    
    $player->setNameTag(TextFormat::BLUE." $player->getName());
                    }
                }
                else {
                    
    $event->setCancelled();
                }
            }
            else {
                
    $event->setCancelled();
            }
        }
      
        public function 
    onBlockPlace (BlockPlaceEvent $event) {
          
            
    $player $event->getPlayer();
            
    $x = (Int)$event->getBlock()->getX();
            
    $y = (Int)$event->getBlock()->getY();
            
    $z = (Int)$event->getBlock()->getZ();
            
    $level $event->getBlock()->getLevel()->getName();
          
            if (isset(
    $this->editors[$player->getName()])) {
                
    $event->setCancelled(false);
                }
          
            else if (isset(
    $this->temp[$player->getName()]["RedFlag"])) {
              
                
    $coordarray = array("x" => $x"y" => $y"z" => $z"level" => $level);
                
    $this->getConfig()->set("RedFlag"$coordarray);
                
    $player->sendMessage("Red flag set!");
                unset(
    $this->temp[$player->getName()]);
            }
            else if (isset(
    $this->temp[$player->getName()]["BlueFlag"])) {
              
                
    $coordarray = array("x" => $x"y" => $y"z" => $z"level" => $level);
                
    $this->getConfig()->set("BlueFlag"$coordarray);
                
    $player->sendMessage("Blue flag set!");
                unset(
    $this->temp[$player->getName()]);
            }
          
            else {
                if (isset(
    $this->temp["RedPlayers"]) or isset($this->temp["BluePlayers"])) { // IDK why I made this function
                
    if(is_array($this->temp["RedPlayers"]) && array_key_exists($player->getName(), $this->temp["RedPlayers"])) { //Player is on the red team
                    
    $config $this->getConfig()->get("RedReturn");
                    if(
    $x == $config["x"] and $y == $config["y"] and $z == $config["z"] and $level == $config["level"]) {
                        if (isset(
    $this->temp["RedPoints"])) {
                            
    $points $this->temp["RedPoints"] +1;
                            
    $this->temp["RedPoints"] = $points;
                            
    $event->setCancelled();
                        }
                        else {
                            
    $this->temp["RedPoints"] = 1;
                        }
                        
    $event->setCancelled();
                        
    $this->giveTeamItems($player->getName());
                    
    $this->broadcastScore($player);
                        if (isset(
    $this->temp[$player->getName()])) {
                        unset(
    $this->temp[$player->getName()]);
                        
    $player->setNameTag(TextFormat::RED." . $player->getName());                  
                        }
                    }
                  }
                    if(is_array(
    $this->temp["BluePlayers"]) && array_key_exists($player->getName(), $this->temp["BluePlayers"])) { //Player is on the blue team
                    
    $config = $this->getConfig()->get("BlueReturn");
                    if(
    $x == $config["x"] and $y == $config["y"] and $z == $config["z"] and $level == $config["level"]) {
                        if (isset(
    $this->temp["BluePoints"])) {
                            
    $points = $this->temp["BluePoints"] +1;
                            
    $this->temp["BluePoints"] = $points;
                            
    $event->setCancelled();
                        }
                        else {
                            
    $this->temp["BluePoints"] = 1;
                        }
                        
    $event->setCancelled();
                        
    $this->giveTeamItems($player->getName());
                        
    $this->broadcastScore($player);
                        if (isset(
    $this->temp[$player->getName()])) {
                        unset(
    $this->temp[$player->getName()]);
                        
    $player->setNameTag(TextFormat::BLUE." $player->getName());
                        }
                    }
                }
            }
                  
    $event->setCancelled();
          }
        }
  2. PaulchenHD
    Offline

    PaulchenHD Active Member

    Joined:
    Jan 17, 2016
    Posts:
    111
    Minecraft User:
    Paulchen_HD
    yeah thats right . . :)
  3. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    There is another mistake
    [13:03:55] [Server thread/INFO]: Loading source plugin CTF v1.0.0
    [13:03:55] [Server thread/CRITICAL]: ParseError: "syntax error, unexpected '"', expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)" (EXCEPTION) in "/CaptureTheFlag-master/src/ctf/Main" at line 117
  4. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    PHP:
    $player->setNameTag(TextFormat::RED." . $player->getName());
    Change it to
    PHP:
    $player->setNameTag(TextFormat::RED $player->getName());
  5. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Wait a second, your code was so messed. You will got a lot of syntax errors on there...
    KubixQ, applqpak and PaulchenHD like this.
  6. PaulchenHD
    Offline

    PaulchenHD Active Member

    Joined:
    Jan 17, 2016
    Posts:
    111
    Minecraft User:
    Paulchen_HD
    PHP:
    $this->getServer()->broadcastMessage(TextFormat::GREEN." . $player->getDisplayName() . "captured the RED teams flag!");
    to...
    PHP:
    $this->getServer()->broadcastMessage(TextFormat::GREEN $player->getDisplayName() . "captured the RED teams flag!");
  7. PaulchenHD
    Offline

    PaulchenHD Active Member

    Joined:
    Jan 17, 2016
    Posts:
    111
    Minecraft User:
    Paulchen_HD
    yeah..
  8. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    PHP:
    if(is_array($this->temp["BluePlayers"]) && array_key_exists($player->getName(), $this->temp["BluePlayers"])) { //Player is on the blue team
    error ^ this
  9. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    hello ??
  10. PaulchenHD
    Offline

    PaulchenHD Active Member

    Joined:
    Jan 17, 2016
    Posts:
    111
    Minecraft User:
    Paulchen_HD
    ....
    applqpak likes this.
  11. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    what wrong this ?
    PHP:
    if(is_array($this->temp["BluePlayers"]) && array_key_exists($player->getName(), $this->temp["BluePlayers"])) { //Player is on the blue team
  12. PaulchenHD
    Offline

    PaulchenHD Active Member

    Joined:
    Jan 17, 2016
    Posts:
    111
    Minecraft User:
    Paulchen_HD


    i don't know why do you code this and you say your not Plugin-Developer...
    applqpak likes this.
  13. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    I want you to replace me this and I will only interested in the rest okay?
  14. PaulchenHD
    Offline

    PaulchenHD Active Member

    Joined:
    Jan 17, 2016
    Posts:
    111
    Minecraft User:
    Paulchen_HD
    okay :) have fun ! :3
  15. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    Where are you going ? This solution to me first and then go ! :)
  16. PaulchenHD
    Offline

    PaulchenHD Active Member

    Joined:
    Jan 17, 2016
    Posts:
    111
    Minecraft User:
    Paulchen_HD
    no i have to go ask @Vaivez66 thx
  17. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    @PmServer, please just use an IDE(NetBeans, PHPStorm,...) - It will point out your errors so you at least can try to fix it yourself.
    applqpak and PaulchenHD like this.
  18. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    also, here is another tip....
    if you dont want a ide, when you have the errors, fix them one at a time.
    read the error, then fix the problem. The crashlog or console error ONLY shows the first wring thing, and not all of thwm. use that to your advantage, and that will help you fix the plugin.

    If you cant be bothered reading all of the crash, them they is a handy feature on pmt.mcpe.me that changes the "boring" text into sections, so its easier to read.

    also, if you do not want a propper IDE, then have a good text editor, like Notepad++ or Brackets, then search google for "PHP Formatter". those things tell you your errors too.
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Then how much different is this from asking people to redo the plugin for you...
    Nawaf_Craft1b and PaulchenHD like this.
  20. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    For some reason I find Vim a good mobile friendly editor. Not bad on PC too.
    PaulchenHD likes this.

Share This Page

Advertisement