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
    what wrong ?
    PHP:
    <?php

    namespace ctf;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\event\block\BlockPlaceEvent;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\nbt\tag\Int;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\network\protocol\PlayerArmorEquipmentPacket;
    use 
    pocketmine\event\player\PlayerQuitEvent;
    use 
    pocketmine\event\player\PlayerRespawnEvent;
    use 
    pocketmine\event\entity\EntityDamageEvent;
    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;
    use 
    pocketmine\event\entity\EntityDeathEvent;
    use 
    pocketmine\Player;

    Class 
    Main extends PluginBase implements Listener{
        public 
    $editors;
        public 
    $temp;
       
        public function 
    onEnable(){
           
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->config = new Config($this->getDataFolder(). "config.yml"Config::YAML);
                    
    $this->saveDefaultConfig();
            
    $this->reloadConfig();
                    
    $this->getLogger()->info(TextFormat::DARK_BLUE "CTF has been enabled!");
                    
    $this->getConfig()->setDefaults(array("Maximum score to win (Integer)" => 15"Game Length (Mins)" => 20));
                    
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new timer($this), 1200);
                   
        }
       
        public function 
    onCommand(CommandSender $senderCommand $command$label, array $args) {
            if (
    $sender->isOp()) {       
                switch(
    $command->getName()) {
                    case 
    "ctfbs":
                        
    $this->writeConfigCoords($sender"Set spawn for Blue team.");
                        break;
                    case 
    "ctfbf":
                        
    $this->temp[$sender->getName()]["BlueFlag"] = true;
                        
    $sender->sendMessage("Place a block in the desired spot for the flag");
                        break;
                    case 
    "ctfbr":
                        
    $this->writeConfigCoords($sender"Set where to return blue flag.");
                        break;
                    case 
    "ctfrs":
                        
    $this->writeConfigCoords($sender"Set spawn for Red team.");
                        break;
                    case 
    "ctfrf":
                        
    $this->temp[$sender->getName()]["RedFlag"] = true;
                        
    $sender->sendMessage("Place a block in the desired spot for the flag");
                        break;
                    case 
    "ctfrr":
                        
    $this->writeConfigCoords($sender"Set where to return red flag.");
                        break;
                    case 
    "lobbyset":
                        
    $this->writeConfigCoords($sender"Set the lobby.");
                        break;
                    case 
    "ctfedit":
                        if (
    $sender->isOp()) {
                            if (!isset(
    $this->editors[$sender->getName()])) {
                            
    $this->editors[$sender->getName()] = true;
                            
    $sender->sendMessage("You are now allowed to edit!");
                            }
                            else {
                            unset(
    $this->editors[$sender->getName()]);
                            
    $sender->sendMessage("You are not allowed to edit!");
                            }
                        }
                        else {
                            
    $sender->sendMessage("You need to be OP to do this.");
                        }
                        break;               
                }
            }
        }
        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->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();
          }
        }
       
        public function 
    onPlayerJoin (PlayerJoinEvent $event) {
           
                
    $player $event->getPlayer();
                
    $this->assignPlayer($player);
                
    $this->giveTeamItems($player->getName()); //DEBUG getName or just player
        
    }
       
        public function 
    onPlayerQuit (PlayerQuitEvent $event) {
           
                
    $player $event->getPlayer();
                if (
    array_key_exists($player->getName(), $this->temp["BluePlayers"])) {
                    unset(
    $this->temp["BluePlayers"][$player->getName()]);
                }
                else {
                    unset(
    $this->temp["RedPlayers"][$player->getName()]);
                }
             }
       public function 
    onEntityMove(EntityMoveEvent $event) {
            
    $x round($event->getEntity()->getX());
            
    $y round($event->getEntity()->getY());
            
    $z round($event->getEntity()->getZ());
            
    $blue $this->getConfig()->get("BlueReturn");
            
    $red $this->getConfig()->get("RedReturn");
            
    $blues $this->getConfig()->get("BlueSpawn");
            
    $reds $this->getConfig()->get("RedSpawn");
           
           
            if (
    $x == $blue["x"] and $y == $blue["y"] and $z == $blue["z"]){
                
    $pos = new Position($blues["x"], $blues["y"], $blues["z"], $event->getEntity()->getLevel());
                
    $event->getEntity()->teleport($pos);  
            }
            else if (
    $x == $red["x"] and $y == $red["y"] and $z == $red["z"]) {
                
    $pos = new Position($reds["x"], $reds["y"], $reds["z"] ,$event->getEntity()->getLevel());
                
    $event->getEntity()->teleport($pos);              
            }
        }
       
       
         public function 
    onHurt(EntityDamageEvent $event) {
        if(
    $event->getEntity() instanceof Player and $event instanceof EntityDamageByEntityEvent) {
          
    $player $event->getEntity();
          
    $cause $event->getDamager();
          if ((
    $player instanceof Player) and ($cause instanceof Player)) {
              if (
    array_key_exists($player->getName(), $this->temp["BluePlayers"])) {
                    if (
    array_key_exists($cause->getName(), $this->temp["BluePlayers"])) {
                    
    $cause->sendMessage(TextFormat::RED."You cannot harm players on your team!");
                    
    $event->setCancelled();
                        }
                    }
                else if (
    array_key_exists($player->getName(), $this->temp["RedPlayers"])) {
                   if (
    array_key_exists($cause->getName(), $this->temp["RedPlayers"])) {
                   
    $cause->sendMessage(TextFormat::RED."You cannot harm players on your team!");
                   
    $event->setCancelled();
                        }
                    }
                }
             }
         }
       
        public function 
    onEntityDeath (EntityDeathEvent $event) {
            
    $event->setDrops(array());
        }
        public function 
    onPlayerRespawn (PlayerRespawnEvent $event) {
           
            
    $player $event->getPlayer();
            if (
    is_array($this->temp["BluePlayers"]) && array_key_exists($player->getName(), $this->temp["BluePlayers"])) {
                
    $config $this->getConfig()->get("BlueSpawn");
                
    $pos = new Position($config["x"], $config["y"], $config["z"], $this->getServer()->getLevelByName($config["level"]));
                
    $event->setRespawnPosition($pos);
                
    $player->sendMessage(TextFormat::GREEN."You have been teleported to your base!");
                
    $this->giveTeamItems($player->getName());
                
    $player->setNameTag(TextFormat::BLUE." . $player->getName());
            }
            else if (is_array(
    $this->temp["RedPlayers"]) && array_key_exists($player->getName(), $this->temp["RedPlayers"])) {
                
    $config = $this->getConfig()->get("RedSpawn");
                
    $pos = new Position($config["x"]$config["y"]$config["z"]$this->getServer()->getLevelByName($config["level"]));
                
    $event->setRespawnPosition($pos);
                
    $player->sendMessage(TextFormat::GREEN."You have been teleported to your base!");
                
    $this->giveTeamItems($player->getName());
                
    $player->setNameTag(TextFormat::RED." $player->getName());
            }
           
           
           
        }
       
        public function 
    writeConfigCoords($sender$coordname){
           
                
    $x = (int)$sender->x;
                
    $y = (int)$sender->y;
                
    $z = (int)$sender->z;
                
    $level $sender->getLevel()->getName();
                
    $coordarray = array("x" => $x"y" => $y"z" => $z"level" => $level);
                
    $this->getConfig()->set($coordname$coordarray);
                
    $sender->sendMessage($coordname" set!");
               
        }
       
        public function 
    assignPlayer($player){
           
            
    $name $player->getName();
            
    $red $this->temp["RedPlayers"]; //sends minor error cuz not set yet
            
    $blue $this->temp["BluePlayers"];
            if (
    count($blue) > count($red)) {
                
    $assignment "red";
            }
            else {
                
    $assignment "blue";
            }
           
            if (
    $assignment === "blue") {
                    
    $this->temp["BluePlayers"][$name] = true;
                    
    $player->setDisplayName(TextFormat::BLUE." . $name);
                    
    $player->setNameTag(TextFormat::BLUE." $name);
            }
            else {
                    
    $this->temp["RedPlayers"][$name] = true;
                    
    $player->setDisplayName(TextFormat::RED." . $name);
                    
    $player->setNameTag(TextFormat::RED." $name);
            }
           
            
    $player->sendMessage(TextFormat::YELLOW."You have been assigned to the " $assignment " team!");
           
            if (
    $assignment === "red"){
                
    $spawn "RedSpawn";
            }
            else {
                
    $spawn "BlueSpawn";
            }
           
            if (
    $this->getConfig()->get($spawn) == false) {
                
    $player->sendMessage(TextFormat::DARK_AQUA."Plugin not yet configured. Come back soon!");
            }
            else {
                
    $config $this->getConfig()->get($spawn);
                
    $pos = new Position($config["x"], $config["y"], $config["z"], $this->getServer()->getLevelByName($config["level"]));
                
    $player->teleport($pos);
                
    $player->sendMessage(TextFormat::GREEN."You have been teleported to your base!");
            }
        }
      
        public function 
    giveTeamItems($player) { //gives items to $player according to which team he is on
            
    $p $this->getServer()->getPlayer($player);
            
    $inv $p->getInventory();
            
    $inv->setContents([]);
            
    $inv->setArmorItem(0Item::get(Item::IRON_HELMET));
            
    $inv->setArmorItem(1Item::get(Item::LEATHER_TUNIC));
            
    $inv->setArmorItem(2Item::get(Item::IRON_LEGGINGS));
            
    $inv->setArmorItem(3Item::get(Item::CHAIN_BOOTS));
            
    $inv->sendArmorContents($p);
            
    $inv->addItem(Item::get(Item::STEAK05));
            
    $inv->addItem(Item::get(Item::STONE_SWORD01));
            
    $inv->addItem(Item::get(Item::BOW01));
            
    $inv->addItem(Item::get(Item::ARROW032));
            
    $inv->sendContents($p);
            
    $pk = new PlayerArmorEquipmentPacket;
            
    $pk->eid $p->getID();
            
    $armor = []; // TODO
            
    $pk->slots $armor;
            foreach(
    $this->getServer()->getOnlinePlayers() as $other){
                if(
    $p->getID() !== $other->getID()){
                    
    $other->dataPacket($pk);
                }
            }
        }
       
        public function 
    onDisable() {
            
    $this->getConfig()->save();
        }
        }
  2. PaulchenHD
    Offline

    PaulchenHD Active Member

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

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    yes
  4. PaulchenHD
    Offline

    PaulchenHD Active Member

    Joined:
    Jan 17, 2016
    Posts:
    111
    Minecraft User:
    Paulchen_HD
    show meee :3
  5. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    i give you my full plugin and you fix my plugin ok ?
  6. PaulchenHD
    Offline

    PaulchenHD Active Member

    Joined:
    Jan 17, 2016
    Posts:
    111
    Minecraft User:
    Paulchen_HD
    i like to see the errors..
  7. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    There are many mistakes and I am not able to give you all the mistakes will give you the plugin and try it for yourself and rectify the mistakes and give me it and I will be grateful to you :)
  8. PaulchenHD
    Offline

    PaulchenHD Active Member

    Joined:
    Jan 17, 2016
    Posts:
    111
    Minecraft User:
    Paulchen_HD
    PHP:
       public function onCommand(CommandSender $senderCommand $command$label, array $args) {
    if (
    $sender->isOp()) {
    switch(
    $command->getName()) {
    $sender ?





    ....

    PHP:
      public function onCommand(CommandSender $senderCommand $command$label, array $args) {
    if (
    $sender instanceof Player) {
      if (
    $sender->isOp()) {
      switch(
    $command->getName()) {
  9. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Seriously? He is not your personal developer, you have to understand the error and fix it by yourself. Understood?
  10. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Show us the error you are getting, if you know there are many, explain ALL of them.
    PaulchenHD likes this.
  11. PaulchenHD
    Offline

    PaulchenHD Active Member

    Joined:
    Jan 17, 2016
    Posts:
    111
    Minecraft User:
    Paulchen_HD
    thx :D
  12. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    I'm not a developer as you can see that you want to help me help me ! And that you do not want to help me go from here! And originally I did not ask you to help you !
  13. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Well, instead of getting mad and break the rules, why not tell us the error message and the error line?
    KubixQ and PaulchenHD like this.
  14. PaulchenHD
    Offline

    PaulchenHD Active Member

    Joined:
    Jan 17, 2016
    Posts:
    111
    Minecraft User:
    Paulchen_HD
    we need the error's to fix it ..
  15. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    Well do you want I will give you wrong? In the Plugin
  16. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    [12:57:03] [Server thread/INFO]: Loading source plugin CTF v1.0.0
    [12:57:03] [Server thread/CRITICAL]: ParseError: "syntax error, unexpected 'captured' (T_STRING), expecting ',' or ')'" (EXCEPTION) in "/CaptureTheFlag-master/src/ctf/Main" at line 108
  17. PaulchenHD
    Offline

    PaulchenHD Active Member

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

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    ok :)
  19. PaulchenHD
    Offline

    PaulchenHD Active Member

    Joined:
    Jan 17, 2016
    Posts:
    111
    Minecraft User:
    Paulchen_HD
    where is line 108 ? :D
  20. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    PHP:
    $this->getServer()->broadcastMessage(TextFormat::GREEN." . $player->getDisplayName() . " captured the BLUE teams flag!");
    It should be
    PHP:
    $this->getServer()->broadcastMessage(TextFormat::GREEN $player->getDisplayName() . " captured the BLUE teams flag!");

Share This Page

Advertisement