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

Config!?

Comments in 'Plugin Development' started by KHAV, Sep 6, 2016.

  1. KHAV
    Offline

    KHAV New Member

    Joined:
    Aug 7, 2016
    Posts:
    35
    Minecraft User:
    KHAV
    Hi

    How i can make config for teleport position?
  2. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    You don't use config to teleport; It's usually for storing settings as you can tell from its name.
    EDIT: Nevermind, I missed that last word 'position'.
    Last edited: Sep 9, 2016
    applqpak likes this.
  3. Praxthisnovcht
    Offline

    Praxthisnovcht Notable Member Plugin Developer

    Joined:
    Mar 10, 2014
    Posts:
    699
    Plugins:
    4
    Minecraft User:
    PraxHellTag
    NO Config
    PHP:
    $player->teleport(new Position(-69736, -854$this->getServer()->getLevelByName($world)));
    $this->getServer()->getLevelByName($world)->loadChunk(#Pos;
    CONFIG
    Code:
    SpawnWorld: world
    SpawnX: -697.000000
    SpawnY: 36.000000
    SpawnZ: -854.000000

    PHP:
                    $conf $this->getConfig()->get("SpawnWorld");
                    
    $world $this->getServer()->getLevelByName($conf);
                    
    $x $this->getConfig()->get("SpawnX");
                    
    $y $this->getConfig()->get("SpawnY");
                    
    $z $this->getConfig()->get("SpawnZ");
                    
    $world->loadChunk($x$z);
                    
    $world->loadChunk($world->getSpawnLocation()->getX(), $world->getSpawnLocation()->getZ());
                    
    $p->teleport($world->getSpawnLocation(), 00);
                    
    //$p->getInventory()->clearAll();
                    
    $pos = new Vector3($x$y$z);
                    
    //$p->setGamemode(2);
                    
    $p->teleport($pos);  
    Last edited: Sep 6, 2016
  4. KHAV
    Offline

    KHAV New Member

    Joined:
    Aug 7, 2016
    Posts:
    35
    Minecraft User:
    KHAV

    I have plugin warp and i want to make for the plugin config for x y z position
  5. Praxthisnovcht
    Offline

    Praxthisnovcht Notable Member Plugin Developer

    Joined:
    Mar 10, 2014
    Posts:
    699
    Plugins:
    4
    Minecraft User:
    PraxHellTag
    I understand little English, that's what you look for?
  6. KHAV
    Offline

    KHAV New Member

    Joined:
    Aug 7, 2016
    Posts:
    35
    Minecraft User:
    KHAV
    Can you tell me what i type in enable?
  7. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    If you are talking about onEnable(), that's for you to write unless you want it to create config.
  8. Praxthisnovcht
    Offline

    Praxthisnovcht Notable Member Plugin Developer

    Joined:
    Mar 10, 2014
    Posts:
    699
    Plugins:
    4
    Minecraft User:
    PraxHellTag
    PHP:
    <?php
    namespace ;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\event\entity\EntityLevelChangeEvent;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\level\Level;


    class 
    Main extends PluginBase  implements Listener {

        public function 
    onEnable() {
            
    $this->saveDefaultConfig();
    //        $this->reloadConfig();
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
    }

    ## CODE HERE 
    Last edited: Sep 6, 2016
  9. KHAV
    Offline

    KHAV New Member

    Joined:
    Aug 7, 2016
    Posts:
    35
    Minecraft User:
    KHAV
    It is. Crashed me in $this->reloadConfig();
  10. KHAV
    Offline

    KHAV New Member

    Joined:
    Aug 7, 2016
    Posts:
    35
    Minecraft User:
    KHAV
    And crashed me in $conf = $this->getConfig()->get("inSpawnWorld");
  11. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    @KHAV can you show us the crashdump as well as what you have tried to fix it?
    And why register event?
  12. KHAV
    Offline

    KHAV New Member

    Joined:
    Aug 7, 2016
    Posts:
    35
    Minecraft User:
    KHAV
    This Crash $conf:

    Genisys Crash Dump Tue Sep 6 15:21:10 CST 2016

    Error: syntax error, unexpected '$conf ' (T_VARIABLE)
    File: /TeamVSTeamDP/src/TeamVSTeamDP/Main
    Line: 88
    Type: notice

    THIS CRASH WAS CAUSED BY A PLUGIN

    Code:
    [79] $i= Item::get(261);
    [80] $player->getInventory()->addItem($i);
    [81] $i= Item::get(262, 0, 64);
    [82] $player->getInventory()->addItem($i);
    [83] $i= Item::get(364, 0, 64);
    [84] $player->getInventory()->addItem($i);
    [85] $i= Item::get(272);
    [86] $player->getInventory()->addItem($i);
    [87] $team = "§f[§l§cRed§f]";
    [88] $conf = $this->getConfig()->get("SpawnWorld");
    [89] $world = $this->getServer()->getLevelByName($conf);
    [90] $x = $this->getConfig()->get("SpawnX");
    [91] $y = $this->getConfig()->get("SpawnY");
    [92] $z = $this->getConfig()->get("SpawnZ");
    [93] $world->loadChunk($x, $z);
    [94] $world->loadChunk($world->getSpawnLocation()->getX(), $world->getSpawnLocation()->getZ());
    [95] $p->teleport($world->getSpawnLocation(), 0, 0);
    [96] $pos = new Vector3($x, $y, $z);
    [97] $p->teleport($pos);
    [98]

    Backtrace:
    #0 (): spl_autoload_call(string TeamVSTeamDP\Main)
    #1 /src/pocketmine/plugin/FolderPluginLoader(48): class_exists(string TeamVSTeamDP\Main, boolean 1)
    #2 /src/pocketmine/plugin/PluginManager(155): pocketmine\plugin\FolderPluginLoader->loadPlugin(string /storage/emulated/0/PocketMine/plugins/TeamVSTeamDP)
    #3 /src/pocketmine/plugin/PluginManager(333): pocketmine\plugin\PluginManager->loadPlugin(string /storage/emulated/0/PocketMine/plugins/TeamVSTeamDP, array Array())
    #4 /src/pocketmine/Server(2022): pocketmine\plugin\PluginManager->loadPlugins(string /storage/emulated/0/PocketMine/plugins/)
    #5 /src/pocketmine/PocketMine(467): pocketmine\Server->__construct(pocketmine\CompatibleClassLoader object, pocketmine\utils\MainLogger object, string phar:///storage/emulated/0/PocketMine/PocketMine-MP.phar/, string /storage/emulated/0/PocketMine/, string /storage/emulated/0/PocketMine/plugins/, string unknown)
    #6 (1): require_once(string phar:///storage/emulated/0/PocketMine/PocketMine-MP.phar/src/pocketmine/PocketMine.php)

    Genisys version: e28d63b9b9d3965bd225349679f645d1fd250896 [Protocol 82; API 2.0.0]
    uname -a: Linux localhost 3.10.61-gcd3fde7-dirty #2 SMP PREEMPT Sun May 15 20:20:55 CST 2016 armv7l
    PHP version: 7.0.3
    Zend version: 3.0.0
    OS : Linux, android

    Server uptime: 2 seconds
    Number of loaded worlds: 0
    Players online: 0/20
  13. KHAV
    Offline

    KHAV New Member

    Joined:
    Aug 7, 2016
    Posts:
    35
    Minecraft User:
    KHAV
    And this for reloadConfig:

    Genisys Crash Dump Tue Sep 6 15:17:31 CST 2016

    Error: syntax error, unexpected '$this' (T_VARIABLE)
    File: /TeamVSTeamDP/src/TeamVSTeamDP/Main
    Line: 25
    Type: notice

    THIS CRASH WAS CAUSED BY A PLUGIN

    Code:
    [16] use pocketmine\nbt\tag\IntTag;
    [17] use pocketmine\nbt\tag\CompoundTag;
    [18] use pocketmine\utils\Config;
    [19]
    [20] class Main extends PluginBase implements Listener {
    [21]
    [22] public function onEnable()
    [23] {
    [24] $this->saveDefaultConfig();
    [25] $this->reloadConfig();
    [26] $this->getLogger()->info(TextFormat::AQUA . "TeamVSTeamDP Enabled");
    [27]
    [28] $this->getServer()->getPluginManager()->registerEvents($this ,$this);
    [29] }
    [30]
    [31] public function onCommand(CommandSender $player, Command $cmd, $label, array $args) {
    [32] if($cmd->getName() == 'tvt'){
    [33] switch(mt_rand(1,2)){
    [34] case 1:
    [35] {

    Backtrace:
    #0 (): spl_autoload_call(string TeamVSTeamDP\Main)
    #1 /src/pocketmine/plugin/FolderPluginLoader(48): class_exists(string TeamVSTeamDP\Main, boolean 1)
    #2 /src/pocketmine/plugin/PluginManager(155): pocketmine\plugin\FolderPluginLoader->loadPlugin(string /storage/emulated/0/PocketMine/plugins/TeamVSTeamDP)
    #3 /src/pocketmine/plugin/PluginManager(333): pocketmine\plugin\PluginManager->loadPlugin(string /storage/emulated/0/PocketMine/plugins/TeamVSTeamDP, array Array())
    #4 /src/pocketmine/Server(2022): pocketmine\plugin\PluginManager->loadPlugins(string /storage/emulated/0/PocketMine/plugins/)
    #5 /src/pocketmine/PocketMine(467): pocketmine\Server->__construct(pocketmine\CompatibleClassLoader object, pocketmine\utils\MainLogger object, string phar:///storage/emulated/0/PocketMine/PocketMine-MP.phar/, string /storage/emulated/0/PocketMine/, string /storage/emulated/0/PocketMine/plugins/, string unknown)
    #6 (1): require_once(string phar:///storage/emulated/0/PocketMine/PocketMine-MP.phar/src/pocketmine/PocketMine.php)

    Genisys version: e28d63b9b9d3965bd225349679f645d1fd250896 [Protocol 82; API 2.0.0]
    uname -a: Linux localhost 3.10.61-gcd3fde7-dirty #2 SMP PREEMPT Sun May 15 20:20:55 CST 2016 armv7l
    PHP version: 7.0.3
    Zend version: 3.0.0
    OS : Linux, android

    Server uptime: 2 seconds
    Number of loaded worlds: 0
    Players online: 0/20

    Loaded plugins:
    Slapper 1.2.9.7 by jojoe77777 for API(s) 2.0.0
    WorldEdit 3.2 by ByZikenPE for API(s) 1.13.0
    EconomyAPI 2.0.9 by onebone for API(s) 1.0.0, 1.1.0, 1.2.0, 1.2.1, 1.3.0, 1.3.1, 1.4.0, 1.4.1
    MiniBosses 1.0.0 by ace for API(s) 1.0.0
    KitCastle 1 by khavmc for API(s) 2.0.0
  14. Praxthisnovcht
    Offline

    Praxthisnovcht Notable Member Plugin Developer

    Joined:
    Mar 10, 2014
    Posts:
    699
    Plugins:
    4
    Minecraft User:
    PraxHellTag
    use the tag to insert your code please
  15. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Is PluginBase::reloadConfig() really necessary there?
    Praxthisnovcht likes this.
  16. KHAV
    Offline

    KHAV New Member

    Joined:
    Aug 7, 2016
    Posts:
    35
    Minecraft User:
    KHAV
    Okay can you help please?
  17. Praxthisnovcht
    Offline

    Praxthisnovcht Notable Member Plugin Developer

    Joined:
    Mar 10, 2014
    Posts:
    699
    Plugins:
    4
    Minecraft User:
    PraxHellTag
    No. forget to remove the
    it is not important here
  18. Yeelze
    Offline

    Yeelze New Member

    Joined:
    Apr 2, 2016
    Posts:
    31
    Minecraft User:
    Yeelze
    config.yml:
    PHP:
    # YourPlugin\resources

    ---
    # Put your world here
    defaultLevelexample
    # Here the coords
    x50
    y
    100
    z
    150
    ...
    Base.php:
    PHP:
    <?php

    namespace Manager;

    use 
    pocketmine\plugin\PluginBase;

    class 
    Base extends PluginBase {

        
    /** @var Events */
        
    private $listener;

        
    /**
         * Initialize the plugin
         */
        
    public function initialize() {
            if(!
    is_dir($this->getDataFolder())) {
                @
    mkdir($this->getDataFolder());
               
            }
            
    $this->saveDefaultConfig();
        }

        
    /**
         * Enable the plugin
         */
        
    public function onEnable() {
            
    $this->initialize();
            
    $this->setListener();
            
    $this->loadDefaultLevel();
        }

        
    /**
         * Set the listener
         */
        
    public function setListener() {
            
    $this->listener = new Events($this);
        }

        
    /**
         * Load the default level (on the config)
         */
        
    public function loadDefaultLevel() {
            
    $level $this->getConfig()->get("defaultLevel");
            if(!
    $this->getServer()->isLevelLoaded($level)) {
                
    $this->getServer()->loadLevel($level);
            }
        }

    }
    Events.php:
    PHP:
    <?php

    namespace Manager;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\Player;

    class 
    Events implements Listener {

        
    /** @var Base */
        
    private $plugin;

        
    /**
         * Events constructor.
         * @param Base $plugin
         */
        
    public function __construct(Base $plugin) {
            
    $this->plugin $plugin;
            
    $plugin->getServer()->getPluginManager()->registerEvents($this$plugin);
        }

        
    /**
         * @param Player $player
         */
        
    public function customTeleport(Player $player) {
            
    $plugin $this->plugin;
            
    $config $plugin->getConfig();
            
    $defaultLevel $config->get("defaultLevel");
            if(!
    $player->getLevel() == $defaultLevel) {
                
    $player->teleport($plugin->getServer()->getLevelByName($defaultLevel)->getSafeSpawn());
            }
            
    $player->teleport(new Vector3($config->get("x"), $config->get("y"), $config->get("z")));
        }

    }
    To teleport a player put in the function you want $this->customTeleport(Player);
  19. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    This little YAML thing can ruin everything.
  20. JUZEXMOD
    Offline

    JUZEXMOD New Member

    Joined:
    May 28, 2016
    Posts:
    19
    Minecraft User:
    JUZEXMOD
    PHP:
    <?php

    namespace Config;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\utils\TextFormat as Color;
    use 
    pocketmine\utils\Config;

    class 
    Main extends PluginBase implements Listener{
     
     
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            @
    mkdir($this->getDataFolder());
            
    $xyz = [
                    
    "x" => 0,
                    
    "y" => 0,
                    
    "z" => 0,
            ];
            
    $cfg = new Config($this->getDataFolder(), "Config.yml"Config::YAML$xyz);
            
    $cfg->save();
        }
     
        public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args){
            switch(
    $cmd->getName()){
                case 
    'teleport':
                        
    $x $this->getConfig()->get("x");
                        
    $y $this->getConfig()->get("y");
                        
    $z $this->getConfig()->get("z");
                        
    $sender->teleport(new position($x$y$z));
                        
    $this->getConfig()->save();
                 
        }
     
        public function 
    onDisable(){
            
    $this->getConfig()->save();
        }
    }
    Last edited: Sep 9, 2016

Share This Page

Advertisement