Наследование: implements pocketmine\plugin\Plugin
Пример #1
0
 public function __construct(PluginBase $owner, $target)
 {
     $this->owner = $owner;
     switch (strtolower($target)) {
         case "emergency":
             $this->level = LogLevel::EMERGENCY;
             break;
         case "alert":
             $this->level = LogLevel::ALERT;
             break;
         case "critical":
             $this->level = LogLevel::CRITICAL;
             break;
         case "error":
             $this->level = LogLevel::ERROR;
             break;
         case "warning":
             $this->level = LogLevel::WARNING;
             break;
         case "notice":
             $this->level = LogLevel::NOTICE;
             break;
         case "info":
             $this->level = LogLevel::INFO;
             break;
         case "debug":
             $this->level = LogLevel::DEBUG;
             break;
         default:
             $owner->getServer()->getLogger()->error(mc::_("Invalid log target %1%", $target));
             $owner->getServer()->getLogger()->error(mc::_("Using \"debug\""));
             $this->level = LogLevel::DEBUG;
     }
 }
Пример #2
0
 public function __construct(PluginBase $owner)
 {
     $path = $owner->getDataFolder() . "stats.sqlite3";
     $this->database = new \SQLite3($path);
     $sql = "CREATE TABLE IF NOT EXISTS Scores (\n\t\t\tplayer TEXT NOT NULL,\n\t\t\ttype TEXT NOT NULL,\n\t\t\tcount INTEGER NOT NULL,\n\t\t\tPRIMARY KEY (player,type)\n\t\t)";
     $this->database->exec($sql);
 }
Пример #3
0
 /**
  * Show a notice when the money API is found
  *
  * @param PluginBase $plugin - current plugin
  * @param PluginBase $api - found plugin
  * @param LogLevel $level - optional log level
  */
 public static function foundMoney(PluginBase $plugin, $api, $level = LogLevel::INFO)
 {
     if (class_exists(__NAMESPACE__ . "\\mc", false)) {
         $plugin->getLogger()->log($level, TextFormat::BLUE . mc::_("Using money API from %1%", $api->getFullName()));
     } else {
         $plugin->getLogger()->log($level, TextFormat::BLUE . "Using money API from " . $api->getFullName());
     }
 }
Пример #4
0
 /**
  * @param PluginBase $owner - plugin that owns this session
  * @param bool $hard - hard freeze option
  */
 public function __construct(PluginBase $owner, $hard = true)
 {
     $bag = $owner->getServer()->getPluginManager()->getPlugin("GrabBag");
     if ($bag && $bag->isEnabled() && MPMU::apiCheck($bag->getDescription()->getVersion(), "2.3") && $bag->api->getFeature("shield")) {
         $this->api = $bag->api;
         return;
     }
     parent::__construct($owner);
     $this->api = null;
 }
 /**
  * @param PluginBase $owner - plugin that owns this session
  * @param bool $hard - hard freeze option
  */
 public function __construct(PluginBase $owner, $hard = true)
 {
     $bag = $owner->getServer()->getPluginManager()->getPlugin("GrabBag");
     if ($bag && $bag->isEnabled() && MPMU::apiCheck($bag->getDescription()->getVersion(), "2.3") && $bag->api->getFeature("freeze-thaw")) {
         $this->api = $bag->api;
         return;
     }
     parent::__construct($owner);
     // We do it here so to prevent the registration of listeners
     $this->api = null;
     $this->hard = $hard;
 }
Пример #6
0
 public function __construct(PluginBase $owner, $target)
 {
     $this->owner = $owner;
     $fp = @fopen($target, "a");
     if ($fp === false) {
         $owner->getServer()->getLogger()->error(mc::_("Error writing to %1%", $target));
         throw new \RuntimeException("{$target}: unable to open");
         return;
     }
     fclose($fp);
     $this->file = $target;
 }
Пример #7
0
 public function __construct(PluginBase $owner)
 {
     $cf = $owner->getCfg("MySql");
     $this->database = new \mysqli($cf["host"], $cf["user"], $cf["password"], $cf["database"], $cf["port"]);
     if ($this->database->connect_error) {
         throw new \RuntimeException("Invalid MySql settings");
         return;
     }
     $sql = "CREATE TABLE IF NOT EXISTS Scores (\n\t\t\tplayer VARCHAR(16) NOT NULL,\n\t\t\ttype VARCHAR(128) NOT NULL,\n\t\t\tcount INT NOT NULL,\n\t\t\tPRIMARY KEY (player,type)\n\t\t)";
     $this->database->query($sql);
     $owner->getServer()->getScheduler()->scheduleRepeatingTask(new PluginCallbackTask($owner, [$this, "pingMySql"]), 600);
     $owner->getLogger()->info("Connected to MySQL server");
 }
Пример #8
0
 public function __construct(PluginBase $owner, $cf)
 {
     $this->owner = $owner;
     $this->isGlobal = $cf["settings"]["global"];
     $this->database = new \mysqli($cf["MySql"]["host"], $cf["MySql"]["user"], $cf["MySql"]["password"], $cf["MySql"]["database"], $cf["MySql"]["port"]);
     if ($this->database->connect_error) {
         throw new \RuntimeException("Invalid MySql settings");
         return;
     }
     $sql = "CREATE TABLE IF NOT EXISTS NetherChests (\n      player VARCHAR(16) NOT NULL,\n      world VARCHAR(128) NOT NULL,\n      slot INT NOT NULL,\n      id INT NOT NULL,\n      damage INT NOT NULL,\n      count INT NOT NULL,\n      PRIMARY KEY (player,world,slot)\n    )";
     $this->database->query($sql);
     $owner->getServer()->getScheduler()->scheduleRepeatingTask(new PluginCallbackTask($owner, [$this, "pingMySql"]), 600);
     $owner->getLogger()->info("Connected to MySQL server");
 }
Пример #9
0
 public function __construct(Plugin $plugin, $goods, $dfts)
 {
     $this->owner = $plugin;
     $this->owner->getServer()->getPluginManager()->registerEvents($this, $this->owner);
     $this->goods = [];
     foreach ($goods as $cf) {
         $item = Item::fromString($cf);
         if (($item = $item->getId()) == Item::AIR) {
             $plugin->getLogger()->error(mc::_("Invalid trade-good: %1%", $cf));
             continue;
         }
         $this->goods[$item] = $item;
     }
     $this->defaults = $dfts;
     $this->state = [];
 }
Пример #10
0
 /**
  * @param PluginBase $owner - plugin that owns this session
  */
 public function __construct(PluginBase $owner)
 {
     $bag = $owner->getServer()->getPluginManager()->getPlugin("GrabBag");
     $this->apis = [null, null];
     if ($bag && $bag->isEnabled() && MPMU::apiCheck($bag->getDescription()->getVersion(), "2.3")) {
         if ($bag->api->getFeature("chat-utils")) {
             $this->apis[0] = $bag->api;
         }
         if ($bag->api->getFeature("mute-unmute")) {
             $this->apis[1] = $bag->api;
         }
         return;
     }
     parent::__construct($owner);
     $this->chat = true;
 }
Пример #11
0
 /**
  * @param PluginBase        $plugin
  * @param PluginDescription $description
  * @param string            $dataFolder
  * @param string            $file
  */
 private function initPlugin(PluginBase $plugin, PluginDescription $description, $dataFolder, $file)
 {
     $plugin->init($this, $this->server, $description, $dataFolder, $file);
     $plugin->onLoad();
 }
Пример #12
0
 public function __construct(Plugin $plugin, $xfg)
 {
     $this->owner = $plugin;
     $this->keepers = [];
     $cfg = (new Config($plugin->getDataFolder() . "shops.yml", Config::YAML))->getAll();
     $this->state = [];
     foreach ($cfg as $i => $j) {
         $this->keepers[$i] = [];
         if (isset($j["messages"])) {
             $this->keepers[$i]["messages"] = $j["messages"];
         } else {
             $this->keepers[$i]["messages"] = [];
         }
         $this->keepers[$i]["attack"] = isset($j["attack"]) ? $j["attack"] : 5;
         $this->keepers[$i]["slim"] = isset($j["slim"]) ? $j["slim"] : false;
         $this->keepers[$i]["displayName"] = isset($j["display"]) ? $j["display"] : "default";
         // Load the skin in memory
         if (is_file($plugin->getDataFolder() . $j["skin"])) {
             $this->keepers[$i]["skin"] = zlib_decode(file_get_contents($plugin->getDataFolder() . $j["skin"]));
         } else {
             $this->keepers[$i]["skin"] = null;
         }
         if (isset($cfg[$i]["msgs"])) {
             $this->keepers[$i]["msgs"] = $cfg[$i]["msgs"];
         }
         $items = isset($cfg[$i]["items"]) && $cfg[$i]["items"] ? $cfg[$i]["items"] : ["IRON_SWORD,2", "APPLE,10,1"];
         $this->keepers[$i]["items"] = [];
         foreach ($items as $n) {
             $t = explode(",", $n);
             if (count($t) < 2 || count($t) > 3) {
                 $plugin->getLogger()->error(mc::_("Item error: %1%", $n));
                 continue;
             }
             $item = Item::fromString(array_shift($t));
             if ($item->getId() == Item::AIR) {
                 $plugin->getLogger()->error(mc::_("Unknown Item error: %1%", $n));
                 continue;
             }
             $price = intval(array_pop($t));
             if ($price <= 0) {
                 $plugin->getLogger()->error(mc::_("Invalid price: %1%", $n));
                 continue;
             }
             if (count($t)) {
                 $qty = intval($t[0]);
                 if ($qty <= 0 || $qty >= $item->getMaxStackSize()) {
                     $plugin->getLogger()->error(mc::_("Bad quantity: %1%", $n));
                     continue;
                 }
                 $item->setCount($qty);
             }
             echo "Item: " . $item->getId() . "," . $item->getCount() . "\n";
             //##DEBUG
             $this->keepers[$i]["items"][implode(":", [$item->getId(), $item->getDamage()])] = [$item, $price];
         }
         if (count($this->keepers[$i]["items"])) {
             continue;
         }
         $plugin->getLogger()->error(mc::_("ShopKeep %1% disabled!", $i));
         unset($this->keepers[$i]);
         continue;
     }
     if (count($this->keepers) == 0) {
         $plugin->getLogger()->error(mc::_("No shopkeepers found!"));
         $this->keepers = null;
         return;
     }
     Entity::registerEntity(TraderNpc::class, true);
     $this->owner->getServer()->getPluginManager()->registerEvents($this, $this->owner);
     $this->owner->getServer()->getScheduler()->scheduleRepeatingTask(new PluginCallbackTask($this->owner, [$this, "spamPlayers"], [$xfg["range"], $xfg["freq"]]), $xfg["ticks"]);
 }
Пример #13
0
 public function __construct(Main $plugin)
 {
     parent::__construct($plugin);
 }
Пример #14
0
 /**
  * This will hopefully save someone typing.
  * @param PluginBase $base
  * @return SimpleWarpAPI
  */
 public static function getInstance(PluginBase $base)
 {
     return $base->getServer()->getPluginManager()->getPlugin("SimpleWarp")->getApi();
 }
Пример #15
0
 public function __construct($meta = 0, $count = 1)
 {
     parent::__construct(self::SPLASH_POTION, $meta, $count, $this->getNameByMeta($meta));
 }