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

One Class ore More?

Comments in 'Plugin Development' started by Marcelo234, Dec 24, 2015.

  1. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Hey Guys I want to make a PM-MinigamePlugin...But there is something wrong...Pls help me

    Thanks Marcelo234
  2. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Code:
    <?php
    
    namespace FallingBlocks;
    
    use pocketmine\Server;
    use pocketmine\command\Command;
    use pocketmine\command\CommandExecutor;
    use pocketmine\command\CommandSender;
    use pocketmine\command\PluginCommand;
    use pocketmine\event\player\PlayerKickEvent;
    use pocketmine\Player;
    use pocketmine\item\Item;
    use pocketmine\event\player\PlayerRespawnEvent;
    use pocketmine\event\player\PlayerJoinEvent;
    use pocketmine\event\player\PlayerChatEvent;
    use pocketmine\event\player\PlayerInteractEvent;
    use pocketmine\event\player\PlayerDeathEvent;
    use pocketmine\event\entity\EntityDamageEvent;
    use pocketmine\event\entity\EntityDamageByEntityEvent;
    use pocketmine\event\entity\EntityLevelChangeEvent;
    use pocketmine\event\block\BlockPlaceEvent;
    use pocketmine\event\block\BlockBreakEvent;
    use pocketmine\event\EventExecutor;
    use pocketmine\event\EventPriority;
    use pocketmine\event\Listener;
    use pocketmine\plugin\Plugin;
    use pocketmine\utils\TextFormat;
    use pocketmine\sheduler\PluginTask;
    use pocketmine\utils\Config;
    use pocketmine\math\Vector3;
    use pocketmine\math\Vector2;
    use pocketmine\inventory\BaseInventory;
    use pocketmine\tile\Sign;
    use pocketmine\event\block\SignChangeEvent;
    use pocketmine\entity\Effect;
    use pocketmine\entity\InstantEffect;
    use pocketmine\level\particle\BubbleParticle;
    use pocketmine\level\particle\CriticalParticle;
    use pocketmine\level\particle\EnchantParticle;
    use pocketmine\level\particle\FlameParticle;
    use pocketmine\level\particle\HeartParticle;
    use pocketmine\level\particle\InkParticle;
    use pocketmine\level\particle\LavaDripParticle;
    use pocketmine\level\particle\PortalParticle;
    use pocketmine\level\particle\SmokeParticle;
    use pocketmine\level\particle\WaterDripParticle;
    use pocketmine\plugin\PluginBase;
    use statuscheck;
    use SignUpdate;
    
    //////////////////////////////////////////////////////
    //////////////////////////////////////////////////////
    //////////////////////////////////////////////////////
    ///////M C K A F F  F A L L I N G  B L O C K S////////
    //////////////////////////////////////////////////////
    //////////////////////////////////////////////////////
    //////////////////////////////////////////////////////
    
    class FallingBlocks extends PluginBase implements Listener {
       
        public function onEnable() {
           
            $this->getLogger()->info(TextFormat::GREEN."[McKaff_FallingBlocks] succesfully loaded!");
           
            $this->getServer()->getPluginManager()->registerEvents($this, $this);
       
            $this->getServer()->loadLevel("FB-1");
            $this->getServer()->loadLevel("FB-2");
           
            $this->getServer()->loadLevel("FB-1-game");
            $this->getServer()->loadLevel("FB-2-game");
           
            $this->getServer()->getScheduler()->scheduleRepeatingTask(new statuscheck($this), 40);
            $this->getServer()->getScheduler()->scheduleRepeatingTask(new SignUpdate($this), 40);
           
        }
        public function onDisable() {
           
            $this->getLogger()->info(TextFormat::RED."[McKaff_FallingBlocks] disabled!");
    
        }
       
        public function onSignCreate(SignChangeEvent $event) {
            $player = $event->getPlayer();
           
            $onlineFB1 = count($this->getOwner()->getServer()->getLevelbyname("FB-1")->Players());
            $onlineFB2 = count($this->getOwner()->getServer()->getLevelbyname("FB-2")->Players());
          
                 if($event->getLine(0) == "FB-1") {
                     $event->setLine(0,"§l§bFallingBlocks");
                     $event->setLine(1,"§aLevel-1");
                     $event->setLine(2,'§f'.$onlineFB1.'§7/§f20');
                     $event->setLine(3,"§6[Tap to join]");
                     $player->sendMessage(TextFormat::GOLD."Succesfully created ".TextFormat::GRAY."FallingBlocks-Level-1");
                 }
                 else {
                    
                 }
                
                 if($event->getLine(0) == "FB-2") {
                    $event->setLine(0,"§l§bFallingBlocks");
                    $event->setLine(1,"§aLevel-2");
                    $event->setLine(2,'§f'.$onlineFB2.'§7/§f20');
                    $event->setLine(3,"§6[Tap to join]");
                    $player->sendMessage(TextFormat::GOLD."Succesfully created ".TextFormat::GRAY."FallingBlocks-Level-2");
                 }
                 else {
                    
                 }
                
      }
     
      public function onPlayerInteract(PlayerInteractEvent $event) {
          $sign = $event->getPlayer()->getlevel()->getTile($event->getBlock());
          $player =$event->getPlayer();
         
          if($event->getBlock()->getId() == 323 || $event->getBlock()->getId() == 63 ||$event->getBlock()->getId() == 68 ) {
              if($sign instanceof Sign) {
                  $signtext = $sign->getText();
                  if($signtext[0] === "§l§bFallingBlocks") {
                      if($signtext[1] === "§aLevel-1") {      
                          if($signtext[3] === "§6[Tap to join") {
                            $event->getPlayer()->teleport(Server::getInstance()->getLevelByName("FB-1")->getSafeSpawn());
                            $event->getPlayer()->sendMessage(TextFormat::GOLD."You joined ".TextFormat::GRAY."FallingBlocks Level-1".TextFormat::GOLD."!");
                            $event->getPlayer()->setGamemode(0);
                            $player->removeAllEffects();
                           }
                          elseif($signtext[3] === "§c[Full]") {
                            $event->getPlayer()->sendMessage("§cThe Game is full!");
                           }
                          elseif($signtext[3] === "§7[in-game]") {
                            $event->getPlayer()->sendMessage("§cThe Game is running!");
                          }
                      }
                  }
              }
          }
         
          if($event->getBlock()->getId() == 323 || $event->getBlock()->getId() == 63 ||$event->getBlock()->getId() == 68 ) {
              if($sign instanceof Sign) {
                  $signtext = $sign->getText();
                  if($signtext[0] === "§l§bFallingBlocks") {
                      if($signtext[1] === "§aLevel-2") {
                          if($signtext[3] === "§6[Tap to join") {
                            $event->getPlayer()->teleport(Server::getInstance()->getLevelByName("FB-2")->getSafeSpawn());
                            $event->getPlayer()->sendMessage(TextFormat::GOLD."You joined ".TextFormat::GRAY."FallingBlocks Level-2".TextFormat::GOLD."!");
                            $event->getPlayer()->setGamemode(0);
                            $player->removeAllEffects();
                           }
                          elseif($signtext[3] === "§c[Full]") {
                            $event->getPlayer()->sendMessage("§cThe Game is full!");
                           }
                          elseif($signtext[3] === "§7[in-game]") {
                            $event->getPlayer()->sendMessage("§cThe Game is running!");
                          }
                      }
                  }
              }
          }
      }
    
    }
    
    class statuscheck extends Task {
       
        public function __construct(Plugin $owner) {
          
            parent::__construct($owner);
           
        }
       
    public function onRun($currentTick) {
        
            $joinedplayersFB1 = count($this->getOwner()->getServer()->getLevelByName("FB-1")->getOnlinePlayers());
            $joinedplayersFB2 = count($this->getOwner()->getServer()->getLevelByName("FB-2")->getOnlinePlayers());
           
            $time = time();
            $playerlevel = $event->getPlayer()->getLevel()->getName();
           
        if($playerlevel == "FB-1") {
           
            foreach($this->getOwner()->getServer()->getOnlinePlayers() as $player) {
                $name = $player->getName();
            }
          
            if($joinedplayersFB1 < 2) {
                foreach($this->getOwner()->getServer()->getOnlinePlayers as $player) {
                    $player->sendPopup(TextFormat::AQUA.'Waiting for other players');
                }
            }
            else{
                if(!(isset($this->getOwner()->countdownende))) {
                if(!(isset($this->getOwner()->countdown))) {
                     $this->getOwner()->countdown = $time+30;
                     unset ($this->getOwner()->countdown);
                }
               
                else{
                $seconds = $this->getOwner()->countdown - $time;
                foreach($this->getOwner()->getServer()->getOnlinePlayers() as $player) {
                    $player->sendMessage('§l§b[FallingBlocks]'.TextFormat::GOLD.'Game will start in '.Color::GRAY.$seconds.Color::GOLD.' seconds');
                }
                if($countdown == 0) {
                    foreach($this->getOwner()->getServer()->getOnlinePlayers() as $player) {
                        $player->teleport($this->getOwner()->getServer()->getLevelbyName("FB-1-game")->getSafeSpwn());
                    }
                    $this->getOwner()->countdown = 1;
                }
                }
            }
        
        }
    }
    if($playerlevel == "FB-2") {
           
            foreach($this->getOwner()->getServer()->getOnlinePlayers() as $player) {
                $name = $player->getName();
            }
          
            if($joinedplayersFB2 < 2) {
                foreach($this->getOwner()->getServer()->getOnlinePlayers as $player) {
                    $player->sendPopup(TextFormat::AQUA.'Waiting for other players');
                }
            }
           
            if($joinedplayersFB2 < 3) {
                foreach($this->getOwner()->getServer()->getOnlinePlayers as $player) {
                    $player->sendTip(TextFormat::AQUA."BuildTeam");
                    $player->sendPopup(TextFormat::AQUA."/BuildTeam");
                }
            }
           
            else{
                if(!(isset($this->getOwner()->countdownende))) {
                if(!(isset($this->getOwner()->countdown))) {
                     $this->getOwner()->countdown = $time+30;
                     unset ($this->getOwner()->countdown);
                }
               
                else{
                $seconds = $this->getOwner()->countdown - $time;
                foreach($this->getOwner()->getServer()->getOnlinePlayers() as $player) {
                    $player->sendMessage('§l§b[FallingBlocks]'.TextFormat::GOLD.'Game will start in '.Color::GRAY.$seconds.Color::GOLD.' seconds');
                }
                if($countdown == 0) {
                    foreach($this->getOwner()->getServer()->getOnlinePlayers() as $player) {
                        $player->teleport($this->getOwner()->getServer()->getLevelbyName("FB-2-game")->getSafeSpwn());
                    }
                    $this->getOwner()->countdown = 1;
                }
                }
            }
        
        }
    }
    }
    
    class SignUpdate extends Task {
       
         public function __construct(Plugin $owner) {
          
            parent::__construct($owner);
        }
       
          public function onRunFB1($currentTick) {
             
            $onlineFB1 = count($this->getOwner()->getServer()->getLevelbyname("FB-1")->Players());
           
            foreach($this->getOwner()->getServer()->getLevels() as $ln => $l) {
                $tl = $l->getTitels();
                foreach($tl as $tl1 => $title) {
                    if($tile instanceof Sign){
                       
                        $t = $title->getText();
                       
                        if($t[0] == "§l§bFallingBlocks") {
                          if($t[1] == "§aLevel-1") {
                            if($onlineFB1 <= 1) {
                                $title->setText("§l§bFallingBlocks ", "§aLevel-1", '§f'.$onlineFB1.'§7/§f20', "§6[Tap to join]");
                            }
                            elseif($online >= 20) {
                                $title->setText("§l§bFallingBlocks", "§aLevel-1", '§f'.$onlineFB1.'§7/§f20', "§c[Full]");
                            }
                            elseif(isset($this->getOwner()->countdownende)) {
                                $title->setText("§l§bFallingBlocks", "§aLevel-1", '§f'.$onlineFB1.'§7/§f20', "§7[in-game]");
                            }
                          }
                        }
                    }
                }
            }
        }
           
            public function onRunFB2($currentTick) {
           
            $onlineFB2 = count($this->getOwner()->getServer()->getLevelbyname("FB-2")->Players());
           
            foreach($this->getOwner()->getServer()->getLevels() as $ln => $l) {
                $tl = $l->getTitels();
                foreach($tl as $tl1 => $title) {
                    if($tile instanceof Sign){
                       
                        $t = $title->getText();
                       
                        if($t[0] == "§l§bFallingBlocks") {
                          if($t[1] == "§aLevel-2") {
                            if($onlineFB1 <= 1) {
                                $title->setText("§l§bFallingBlocks ", "§aLevel-2", '§f'.$onlineFB2.'§7/§f20', "§6[Tap to join]");
                            }
                            elseif($online >= 20) {
                                $title->setText("§l§bFallingBlocks", "§aLevel-2", '§f'.$onlineFB2.'§7/§f20', "§c[Full]");
                            }
                            elseif(isset($this->getOwner()->countdownende)) {
                                $title->setText("§l§bFallingBlocks", "§aLevel-2", '§f'.$onlineFB2.'§7/§f20', "§7[in-game]");
                            }
                          }
                        }
                    }
                }
            }
        }
    }
  3. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Code:
    ## YAML Template.
    ---
    name: McKaff_FallingBlocks
    main: McKaff_FallingBlocks\FallingBlocks
    version: 0.1.0
    api: [1.13.0]
    author: McKaff
    description: A Minigame Plugin[FallingBlocks]!
  4. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Code:
    [23:08:15] [Server thread/INFO]: Loading pocketmine.yml...
    [23:08:15] [Server thread/INFO]: Loading server properties...
    [23:08:15] [Server thread/INFO]: Selected English (eng) as the base language
    [23:08:15] [Server thread/INFO]: Starting Minecraft: PE server version v0.13.1 alpha
    [23:08:15] [Server thread/INFO]: Opening server on 0.0.0.0:19132
    [23:08:16] [Server thread/INFO]: This server is running PocketMine-MP version 1.6dev-52 "[REDACTED]" (API 1.13.1)
    [23:08:16] [Server thread/INFO]: PocketMine-MP is distributed under the LGPL License
    [23:08:18] [Server thread/INFO]: Loading DevTools v1.10.0
    [23:08:18] [Server thread/INFO]: Loading SignPortal v1.1.2
    [23:08:18] [Server thread/INFO]: Enabling DevTools v1.10.0
    [23:08:18] [Server thread/INFO]: Loading source plugin McKaff_FallingBlocks v0.1.0
    
    Fatal error: Cannot declare class FallingBlocks\statuscheck because the name is already in use in C:\Users\Marcelo\Desktop\McKaff_FallingBlocks\plugins\McKaff_FallingBlocks\src\McKaff_FallingBlocks\FallingBlocks.php on line 273
    
    Call Stack:
        0.0587     447640   1. {main}() C:\Users\Marcelo\Desktop\McKaff_FallingBlocks\PocketMine-MP.phar:0
        0.0654     442608   2. require('phar://C:/Users/Marcelo/Desktop/McKaff_FallingBlocks/PocketMine-MP.phar/src/pocketmine/PocketMine.php') C:\Users\Marcelo\Desktop\McKaff_FallingBlocks\PocketMine-MP.phar:1
        1.1904     583448   3. pocketmine\Server->__construct() phar://C:/Users/Marcelo/Desktop/McKaff_FallingBlocks/PocketMine-MP.phar/src/pocketmine/PocketMine.php:464
        4.4492   16148328   4. pocketmine\Server->enablePlugins() phar://C:/Users/Marcelo/Desktop/McKaff_FallingBlocks/PocketMine-MP.phar/src/pocketmine/Server__32bit.php:1637
        4.4492   16148384   5. pocketmine\Server->enablePlugin() phar://C:/Users/Marcelo/Desktop/McKaff_FallingBlocks/PocketMine-MP.phar/src/pocketmine/Server__32bit.php:1881
        4.4492   16148480   6. pocketmine\plugin\PluginManager->enablePlugin() phar://C:/Users/Marcelo/Desktop/McKaff_FallingBlocks/PocketMine-MP.phar/src/pocketmine/Server__32bit.php:1895
        4.4505   16150160   7. pocketmine\plugin\PharPluginLoader->enablePlugin() phar://C:/Users/Marcelo/Desktop/McKaff_FallingBlocks/PocketMine-MP.phar/src/pocketmine/plugin/PluginManager.php:562
        4.4515   16150224   8. pocketmine\plugin\PluginBase->setEnabled() phar://C:/Users/Marcelo/Desktop/McKaff_FallingBlocks/PocketMine-MP.phar/src/pocketmine/plugin/PharPluginLoader.php:123
        4.4520   16150304   9. DevTools\DevTools->onEnable() phar://C:/Users/Marcelo/Desktop/McKaff_FallingBlocks/PocketMine-MP.phar/src/pocketmine/plugin/PluginBase.php:86
        4.4555   16153744  10. pocketmine\plugin\PluginManager->loadPlugins() phar://C:/Users/Marcelo/Desktop/McKaff_FallingBlocks/plugins/DevTools_v1.10.0.phar/src/DevTools/DevTools.php:45
        4.4682   16155560  11. pocketmine\plugin\PluginManager->loadPlugin() phar://C:/Users/Marcelo/Desktop/McKaff_FallingBlocks/PocketMine-MP.phar/src/pocketmine/plugin/PluginManager.php:296
        4.4694   16157248  12. FolderPluginLoader\FolderPluginLoader->loadPlugin() phar://C:/Users/Marcelo/Desktop/McKaff_FallingBlocks/PocketMine-MP.phar/src/pocketmine/plugin/PluginManager.php:152
        4.4718   16158792  13. class_exists() phar://C:/Users/Marcelo/Desktop/McKaff_FallingBlocks/plugins/DevTools_v1.10.0.phar/src/FolderPluginLoader/FolderPluginLoader.php:64
        4.4718   16159000  14. spl_autoload_call() phar://C:/Users/Marcelo/Desktop/McKaff_FallingBlocks/plugins/DevTools_v1.10.0.phar/src/FolderPluginLoader/FolderPluginLoader.php:64
        4.4719   16159048  15. BaseClassLoader->loadClass() phar://C:/Users/Marcelo/Desktop/McKaff_FallingBlocks/plugins/DevTools_v1.10.0.phar/src/FolderPluginLoader/FolderPluginLoader.php:64
    
    [23:08:18] [Server thread/EMERGENCY]: An unrecoverable error has occurred and the server has crashed. Creating a crash dump
    [23:08:18] [Server thread/EMERGENCY]: Please upload the "C:\Users\Marcelo\Desktop\McKaff_FallingBlocks\CrashDump_Thu_Dec_24-23.08.18-GMT_2015.log" file to the Crash Archive and submit the link to the Bug Reporting page. Give as much info as you can.
    [23:08:18] [Server thread/INFO]: Disabling DevTools v1.10.0
    bin\php\php.exe: Exit 1
    
  5. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Try removing
    PHP:
    use statuscheck;
    use 
    SignUpdate;
    from the class FallingBlocks, you dont need those
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    There isn't a function Level::players(), first of all.
    Last edited: Dec 28, 2015
    Marcelo234 and Gamecrafter like this.
  7. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    323 is not a block ID. It's an item id.
    Typo. Correction: "getSafeSpawn()"
    Typo. Correction: "getTiles()"
    What even...

    Plus a lot more.
    applqpak, Marcelo234 and Gamecrafter like this.
  8. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    What makes you think you can? Please learn OOP.
    applqpak likes this.
  9. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Have you an Link were I can learn?
  10. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    And....I removed "use statuscheck" and "use SignUpdate"....And I corrected all parts,but it won't work....
  11. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Sorry I don't understand...sorry
  12. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    You were using code like
    PHP:
    $this->getOwner()->getServer()->getLevelbyname("FB-2")->Players();
    But there is no function "players()". You have to use "getPlayers()", like this
    PHP:
    $this->getOwner()->getServer()->getLevelbyname("FB-2")->getPlayers();
  13. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Do you know search engine called "Google"?
    Marcelo234 likes this.
  14. Bluplayz
    Offline

    Bluplayz Active Member

    Joined:
    Aug 20, 2015
    Posts:
    74
    Minecraft User:
    Bluplayz
    Why did u use so many getOwner() ? So u use it where you dient need it , example u use it in signChangeEvent
  15. TutoGamerWalid
    Offline

    TutoGamerWalid Active Member

    Joined:
    Jun 11, 2015
    Posts:
    69
    Minecraft User:
    TutoGamerWalid
    getLevelByName*
  16. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    I was going to correct that but it didn't matter.

Share This Page

Advertisement