mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 08:17:34 +00:00
Fixes
This commit is contained in:
parent
dff26611e5
commit
ce7c7efc79
@ -26,7 +26,7 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
*/
|
||||
|
||||
class PluginAPI extends stdClass{
|
||||
private $server
|
||||
private $server;
|
||||
private $plugins = array();
|
||||
public function __construct(PocketMinecraftServer $server){
|
||||
$this->server = $server;
|
||||
|
@ -27,8 +27,8 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
class ServerAPI{
|
||||
var $restart = false;
|
||||
private $server
|
||||
private $config
|
||||
private $server;
|
||||
private $config;
|
||||
private $apiList = array();
|
||||
|
||||
public function run(){
|
||||
|
@ -26,11 +26,11 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
*/
|
||||
|
||||
class MinecraftInterface{
|
||||
var $pstruct
|
||||
var $name
|
||||
var $client
|
||||
var $pstruct;
|
||||
var $name;
|
||||
var $client;
|
||||
var $dataName;
|
||||
private $socket
|
||||
private $socket;
|
||||
private $data;
|
||||
function __construct($server, $port = 25565, $listen = false, $client = true){
|
||||
$this->socket = new UDPSocket($server, $port, (bool) $listen);
|
||||
|
111
src/classes/utils/Config.php
Normal file
111
src/classes/utils/Config.php
Normal file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
define("CONFIG_DETECT", -1); //Detect by file extension
|
||||
define("CONFIG_PROPERTIES", 0); // .properties
|
||||
define("CONFIG_CNF", CONFIG_PROPERTIES); // .cnf
|
||||
define("CONFIG_JSON", 1); // .js, .json
|
||||
define("CONFIG_YAML", 2); // .yml, .yaml
|
||||
define("CONFIG_EXPORT", 3); // .export, .xport
|
||||
define("CONFIG_SERIALIZE", 4); // .sl
|
||||
define("CONFIG_LIST", 5); // .txt, .list
|
||||
|
||||
class Config{
|
||||
private $config;
|
||||
private $file;
|
||||
private $type = CONFIG_DETECT;
|
||||
private $correct = true;
|
||||
public static $formats = array(
|
||||
"properties" => CONFIG_PROPERTIES,
|
||||
"cnf" => CONFIG_CNF,
|
||||
"conf" => CONFIG_CNF,
|
||||
"config" => CONFIG_CNF,
|
||||
"json" => CONFIG_JSON,
|
||||
"js" => CONFIG_JSON,
|
||||
"yml" => CONFIG_YAML,
|
||||
"yaml" => CONFIG_YAML,
|
||||
"export" => CONFIG_EXPORT,
|
||||
"xport" => CONFIG_EXPORT,
|
||||
"sl" => CONFIG_SERIALIZE,
|
||||
"serialize" => CONFIG_SERIALIZE,
|
||||
"txt" => CONFIG_LIST,
|
||||
"list" => CONFIG_LIST,
|
||||
);
|
||||
public function __construct($file, $type = CONFIG_DETECT, $default = array()){
|
||||
$this->type = (int) $type;
|
||||
$this->file = $file;
|
||||
if(!file_exists($file)){
|
||||
$this->config = $default;
|
||||
}else{
|
||||
if($this->type === CONFIG_DETECT){
|
||||
$extension = explode(".", basename($this->file));
|
||||
$extension = strtolower(trim(array_pop($extension)));
|
||||
if(isset(Config::$formats[$extension])){
|
||||
$this->type = Config::$formats[$extension];
|
||||
}else{
|
||||
$this->correct = false;
|
||||
}
|
||||
}
|
||||
if($this->correct === true){
|
||||
$content = @file_get_contents($this->file);
|
||||
switch($this->type){
|
||||
case CONFIG_PROPERTIES:
|
||||
case CONFIG_CNF:
|
||||
$this->parseProperties($content);
|
||||
break;
|
||||
}
|
||||
var_dump($this->config);
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function parseProperties($content){
|
||||
if(preg_match_all('/([a-zA-Z0-9\-_]*)=([^\r\n]*)/u', $content, $matches) == 0){ //false or 0 matches
|
||||
foreach($matches[1] as $k => $i){
|
||||
$v = trim($matches[2][$k]);
|
||||
switch(strtolower($v)){
|
||||
case "on":
|
||||
case "true":
|
||||
case "yes":
|
||||
$v = true;
|
||||
break;
|
||||
case "off":
|
||||
case "false":
|
||||
case "no":
|
||||
$v = false;
|
||||
break;
|
||||
}
|
||||
if(isset($this->config[$k])){
|
||||
console("[NOTICE] [Config] Repeated property ".$k." on file ".$this->file, true, true, 2);
|
||||
}
|
||||
$this->config[$k] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user