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

Help please :(

Comments in 'Plugin Development' started by iDirtPlayzMC, May 26, 2015.

  1. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    I got this error when i first try to edit / make plugin

    17:05:02 [INFO] Starting Minecraft: PE server version v0.10.5 alpha
    17:05:02 [INFO] Loading pocketmine.yml...
    17:05:02 [INFO] Loading server properties...
    17:05:02 [INFO] Starting Minecraft PE server on 0.0.0.0:19132
    17:05:02 [INFO] This server is running PocketMine-MP version 1.4.1-980 "絶好(Zekkou)ケーキ(Cake)" (API 1.11.0)
    17:05:02 [INFO] PocketMine-MP is distributed under the LGPL License
    17:05:03 [INFO] Loading DevTools v1.10.0
    17:05:03 [INFO] Enabling DevTools v1.10.0
    17:05:03 [INFO] Loading source plugin SimpleBoost v0.1

    Parse error: syntax error, unexpected '}' in C:\Users\Chakkarin\Desktop\Bukkit\Pocketmine Sutff\PocketMine-MP\plugins\SimpleBoost\src\iDirtniverse\Main.php on line 38

    Call Stack:
    0.0121 342904 1. {main}() C:\Users\Chakkarin\Desktop\Bukkit\Pocketmine Sutff\PocketMine-MP\PocketMine-MP.phar:0
    0.0156 337880 2. require('phar://C:/Users/Chakkarin/Desktop/Bukkit/Pocketmine Sutff/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/PocketMine.php') C:\Users\Chakkarin\Desktop\Bukkit\Pocketmine Sutff\PocketMine-MP\PocketMine-MP.phar:1
    0.2679 457224 3. pocketmine\Server->__construct() phar://C:/Users/Chakkarin/Desktop/Bukkit/Pocketmine Sutff/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/PocketMine.php:442
    1.0853 10696232 4. pocketmine\Server->enablePlugins() phar://C:/Users/Chakkarin/Desktop/Bukkit/Pocketmine Sutff/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:1628
    1.0853 10696304 5. pocketmine\Server->enablePlugin() phar://C:/Users/Chakkarin/Desktop/Bukkit/Pocketmine Sutff/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:1771
    1.0853 10696400 6. pocketmine\plugin\PluginManager->enablePlugin() phar://C:/Users/Chakkarin/Desktop/Bukkit/Pocketmine Sutff/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:1785
    1.0859 10698088 7. pocketmine\plugin\PharPluginLoader->enablePlugin() phar://C:/Users/Chakkarin/Desktop/Bukkit/Pocketmine Sutff/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/plugin/PluginManager.php:559
    1.0861 10698152 8. pocketmine\plugin\PluginBase->setEnabled() phar://C:/Users/Chakkarin/Desktop/Bukkit/Pocketmine Sutff/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/plugin/PharPluginLoader.php:123
    1.0862 10698232 9. DevTools\DevTools->onEnable() phar://C:/Users/Chakkarin/Desktop/Bukkit/Pocketmine Sutff/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/plugin/PluginBase.php:86
    1.0878 10701712 10. pocketmine\plugin\PluginManager->loadPlugins() phar://C:/Users/Chakkarin/Desktop/Bukkit/Pocketmine Sutff/PocketMine-MP/plugins/DevTools_v1.10.0.phar/src/DevTools/DevTools.php:45
    1.0900 10704616 11. pocketmine\plugin\PluginManager->loadPlugin() phar://C:/Users/Chakkarin/Desktop/Bukkit/Pocketmine Sutff/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/plugin/PluginManager.php:296
    1.0908 10706224 12. FolderPluginLoader\FolderPluginLoader->loadPlugin() phar://C:/Users/Chakkarin/Desktop/Bukkit/Pocketmine Sutff/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/plugin/PluginManager.php:152
    1.0930 10707656 13. class_exists() phar://C:/Users/Chakkarin/Desktop/Bukkit/Pocketmine Sutff/PocketMine-MP/plugins/DevTools_v1.10.0.phar/src/FolderPluginLoader/FolderPluginLoader.php:64
    1.0930 10707832 14. spl_autoload_call() phar://C:/Users/Chakkarin/Desktop/Bukkit/Pocketmine Sutff/PocketMine-MP/plugins/DevTools_v1.10.0.phar/src/FolderPluginLoader/FolderPluginLoader.php:64
    1.0930 10707864 15. BaseClassLoader->loadClass() phar://C:/Users/Chakkarin/Desktop/Bukkit/Pocketmine Sutff/PocketMine-MP/plugins/DevTools_v1.10.0.phar/src/FolderPluginLoader/FolderPluginLoader.php:64

    17:05:03 [EMERGENCY] An unrecoverable error has occurred and the server has crashed. Creating a crash dump
    17:05:03 [EMERGENCY] Please submit the "C:\Users\Chakkarin\Desktop\Bukkit\Pocketmine Sutff\PocketMine-MP\CrashDump_Tue_May_26-17.05.03-UTC_2015.log" file to the Bug Reporting page. Give as much info as you can.
    17:05:03 [INFO] Disabling DevTools v1.10.0
    bin\php\php.exe: Exit 1


    Plugin file : MAIN.PHP

    PHP:
    <?php
    namespace iDirtniverse;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\utils\Config;

    use 
    pocketmine\event\player\PlayerQuitEvent;

    class 
    Main extends PluginBase implements Listener {
        protected 
    $state;
        protected 
    $modules;

        public function 
    onEnable(){
            if (!
    is_dir($this->getDataFolder())) mkdir($this->getDataFolder());
            
    $defaults = [
                
    "modules" => [
                    
    "simpleboost" => true,

                ],
                
    "simpleboost" => [
                    
    "blocks" => [ "EMERALD_BLOCK" ],
                ],
            ];
            
    $cnt 0;
            
    $cfg=(new Config($this->getDataFolder()."config.yml",
                
    Config::YAML,$defaults))->getAll();
            if (
    $cfg["modules"]["simpleboost"]);
            
    $this->modules[] = new SimpleBoost($this,$cfg["simpleboost"]);
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }

    }

    public function 
    onPlayerQuit(PlayerQuitEvent $ev) {
        
    $n strtolower($ev->getPlayer()->getName());
        if (isset(
    $this->state[$n])) unset($this->state[$n]);
    }
    public function 
    getState($label,$player,$default) {
        if (
    $player instanceof CommandSender$player $player->getName();
        
    $player strtolower($player);
        if (!isset(
    $this->state[$player])) return $default;
        if (!isset(
    $this->state[$player][$label])) return $default;
        return 
    $this->state[$player][$label];
    }
    public function 
    setState($label,$player,$val) {
        if (
    $player instanceof CommandSender$player $player->getName();
        
    $player strtolower($player);
        if (!isset(
    $this->state[$player])) $this->state[$player] = [];
        
    $this->state[$player][$label] = $val;
    }
    public function 
    unsetState($label,$player) {
        if (
    $player instanceof CommandSender$player $player->getName();
        
    $player strtolower($player);
        if (!isset(
    $this->state[$player])) return;
        if (!isset(
    $this->state[$player][$label])) return;
        unset(
    $this->state[$player][$label]);
    }
    public function 
    getItem($txt,$default=0,$msg="") {
        
    $r explode(":",$txt);
        if (
    count($r)) {
            if (!isset(
    $r[1])) $r[1] = 0;
            
    $item Item::fromString($r[0].":".$r[1]);
            if (isset(
    $r[2])) $item->setCount(intval($r[2]));
            if (
    $item->getId() != Item::AIR) {
                return 
    $item;
            }
        }
        if (
    $default) {
            if (
    $msg != "")
                
    $this->getLogger()->info("$msg: Invalid item $txt, using default");
            
    $item Item::fromString($default.":0");
            
    $item->setCount(1);
            return 
    $item;
        }
        if (
    $msg != "")
            
    $this->getLogger()->info("$msg: Invalid item $txt, ignoring");
        return 
    null;
    }
    }

    SIMPLEBOOST.PHP

    PHP:
    <?php
    namespace iDirtniverse;

    use 
    pocketmine\event\Listener;

    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\event\entity\EntityDamageEvent;
    use 
    pocketmine\event\player\PlayerMoveEvent;
    use 
    pocketmine\math\Vector3;


    class 
    SimpleBoost implements Listener {
        protected 
    $blocks;

        public function 
    __construct($plugin,$cfg) {
            
    $this->owner $plugin;
            
    $this->blocks = [];
            if (isset(
    $cfg["blocks"]) && is_array($cfg["blocks"])) {
                foreach (
    $cfg["blocks"] as $i) {
                    
    $item $this->owner->getItem($i,false,"SimpleBoost");
                    if (
    $item === null) continue;
                    
    $this->blocks[$item->getId()] = $item->getId();
                }
            }
            if (
    count($this->blocks)) {
                
    $this->owner->getServer()->getPluginManager()->registerEvents($this$this->owner);
                
    $this->owner->getLogger()->info(TextFormat::GREEN."SimpleBoost blocks:".
                    
    count($this->blocks));
            } else {
                
    $this->getLogger()->info(TextFormat::RED."No blocks configured");
            }
        }

        public function 
    onFall(EntityDamageEvent $ev) {
            if (
    $ev->isCancelled()) return;
            
    $cause $ev->getCause();
            if (
    $cause !== EntityDamageEvent::CAUSE_FALL) return;
            
    $et $ev->getEntity();
            
    $id $et->getLevel()->getBlockIdAt($et->getX(),$et->getY()-1,$et->getZ());
            if (isset(
    $this->blocks[$id])) {
                
    // Soft landing!
                
    $ev->setCancelled();
            }
        }

        public function 
    onMove(PlayerMoveEvent $ev) {
            if (
    $ev->isCancelled()) return;
            
    $from $ev->getFrom();
            
    $to $ev->getTo();
            
    $dir = ["dx"=>$to->getX()-$from->getX(),
                
    "dy"=>$to->getY()-$from->getY(),
                
    "dz"=>$to->getZ()-$from->getZ()];
            if (!
    $dir["dy"]) return;
            
    $id $to->getLevel()->getBlockIdAt($to->getX(),$to->getY()-1,$to->getZ());
            if (isset(
    $this->blocks[$id])) {
                
    $ev->getPlayer()->setMotion(new Vector3($dir["dx"],-$dir["dy"],$dir["dz"]*1.1));

            }
        }
    }
    Error at line 37 please help ;-;

    Credits : aliuly
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    <?php
    namespace iDirtniverse;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\utils\Config;

    use 
    pocketmine\event\player\PlayerQuitEvent;

    class 
    Main extends PluginBase implements Listener {
        protected 
    $state;
        protected 
    $modules;

        public function 
    onEnable(){
            if (!
    is_dir($this->getDataFolder())) mkdir($this->getDataFolder());
            
    $defaults = [
                
    "modules" => [
                    
    "simpleboost" => true,

                ],
                
    "simpleboost" => [
                    
    "blocks" => [ "EMERALD_BLOCK" ],
                ],
            ];
            
    $cnt 0;
            
    $cfg=(new Config($this->getDataFolder()."config.yml",
                
    Config::YAML,$defaults))->getAll();
            if (
    $cfg["modules"]["simpleboost"]);
            
    $this->modules[] = new SimpleBoost($this,$cfg["simpleboost"]);
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }

    // Remove the } here

    public function onPlayerQuit(PlayerQuitEvent $ev) {
        
    $n strtolower($ev->getPlayer()->getName());
        if (isset(
    $this->state[$n])) unset($this->state[$n]);
    }
    public function 
    getState($label,$player,$default) {
        if (
    $player instanceof CommandSender$player $player->getName();
        
    $player strtolower($player);
        if (!isset(
    $this->state[$player])) return $default;
        if (!isset(
    $this->state[$player][$label])) return $default;
        return 
    $this->state[$player][$label];
    }
    public function 
    setState($label,$player,$val) {
        if (
    $player instanceof CommandSender$player $player->getName();
        
    $player strtolower($player);
        if (!isset(
    $this->state[$player])) $this->state[$player] = [];
        
    $this->state[$player][$label] = $val;
    }
    public function 
    unsetState($label,$player) {
        if (
    $player instanceof CommandSender$player $player->getName();
        
    $player strtolower($player);
        if (!isset(
    $this->state[$player])) return;
        if (!isset(
    $this->state[$player][$label])) return;
        unset(
    $this->state[$player][$label]);
    }
    public function 
    getItem($txt,$default=0,$msg="") {
        
    $r explode(":",$txt);
        if (
    count($r)) {
            if (!isset(
    $r[1])) $r[1] = 0;
            
    $item Item::fromString($r[0].":".$r[1]);
            if (isset(
    $r[2])) $item->setCount(intval($r[2]));
            if (
    $item->getId() != Item::AIR) {
                return 
    $item;
            }
        }
        if (
    $default) {
            if (
    $msg != "")
                
    $this->getLogger()->info("$msg: Invalid item $txt, using default");
            
    $item Item::fromString($default.":0");
            
    $item->setCount(1);
            return 
    $item;
        }
        if (
    $msg != "")
            
    $this->getLogger()->info("$msg: Invalid item $txt, ignoring");
        return 
    null;
    }
    }
    Jon likes this.
  3. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    Thanks!
  4. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    I got this error
    Fatal error: Call to undefined method iDirtniverse\Main::getItem() in C:\Users\Chakkarin\Desktop\Bukkit\Pocketmine Sutff\PocketMine-MP\plugins\SimpleBoost\src\iDirtniverse\SimpleBoost.php on line 21
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    $this->owner->getItem($i,false,"SimpleBoost") is wrong, I don't know how to fix it, never working with more than 1 class, sorry.
  6. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    is ok :)

Share This Page

Advertisement