
<?php
echo "PocketMine-MP plugin PmmpToLobi v1.0.0
This file has been generated using DevTools v1.14.2 at Wed, 11 Aug 2021 21:53:17 +0900
----------------
Name: PmmpToLobi
Version: 1.0.0
Main: roi611\\pmmptolobi\\Main
Api: 3.0.0
Depend: 
Description: Lobiとの双方向通信をします
Authors: 
Website: 
CreationDate: 1628686397
";
__HALT_COMPILER(); ?>
               a:9:{s:4:"name";s:10:"PmmpToLobi";s:7:"version";s:5:"1.0.0";s:4:"main";s:22:"roi611\pmmptolobi\Main";s:3:"api";s:5:"3.0.0";s:6:"depend";s:0:"";s:11:"description";s:37:"Lobiとの双方向通信をします";s:7:"authors";s:0:"";s:7:"website";s:0:"";s:12:"creationDate";i:1628686397;}
   plugin.yml   =a   W      %   src/delion/LobiAPI/HttpAPI/Header.php  =a  =w      #   src/delion/LobiAPI/HttpAPI/Http.php
  =a
  7_ҭ         src/delion/LobiAPI/LobiAPI.phpc4  =ac4        '   src/roi611/pmmptolobi/LobiChatEvent.php  =a  d         src/roi611/pmmptolobi/Main.php9  =a9  Hn      name: PmmpToLobi
main: roi611\pmmptolobi\Main
version: 1.0.0
api: 3.0.0
load: POSTWORLD
author: roi611
description: Lobiとの双方向通信をします<?php
namespace delion\LobiAPI\HttpAPI;

class Header{
	public $Host = '';
	public $Connection = true;
	public $Accept = '';
	public $UserAgent = '';
	public $Referer = '';
	public $AcceptEncoding = '';
	public $AcceptLanguage = '';
	public $Origin = '';

	public function setHost($host){
		$this->Host = $host;
		return $this;
	}
	public function setConnection($connection){
		$this->Connection = $connection;
		return $this;
	}
	public function setAccept($accept){
		$this->Accept = $accept;
		return $this;
	}
	public function setUserAgent($useragent){
		$this->UserAgent = $useragent;
		return $this;
	}
	public function setReferer($referer){
		$this->Referer = $referer;
		return $this;
	}
	public function setAcceptEncoding($encoding){
		$this->AcceptEncoding = $encoding;
		return $this;
	}
	public function setAcceptLanguage($language){
		$this->AcceptLanguage = $language;
		return $this;
	}
	public function setOrigin($origin){
		$this->Origin = $origin;
		return $this;
	}
}<?php
namespace delion\LobiAPI\HttpAPI;

class Http{
	public $cookie_path;

	public function __construct($cookie_file_path = ''){
		$path = ($cookie_file_path == '' ? 'cookie.txt' : $cookie_file_path);
		if(file_exists($path))
			unlink($path);
		touch($path);
		$this->cookie_path = $path;
	}

	public function get($url, $header){
		$ch = curl_init($url);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
		$req_header = [];
		if($header->Host != '')
			$req_header[] = 'Host: ' . $header->Host;
		if($header->Connection)
			$req_header[] = 'Connection: keep-alive';
		if($header->Accept != '')
			$req_header[] = 'Accept: ' . $header->Accept;
		if($header->UserAgent != '')
			$req_header[] = 'User-Agent: ' . $header->UserAgent;
		if($header->Referer != '')
			$req_header[] = 'Referer: ' . $header->Referer;
		if($header->AcceptEncoding != '')
			$req_header[] = 'Accept-Encoding: ' . $header->AcceptEncoding;
		if($header->AcceptLanguage != '')
			$req_header[] = 'Accept-Language: ' . $header->AcceptLanguage;
		if(count($req_header) > 0)
			curl_setopt($ch, CURLOPT_HTTPHEADER, $req_header);
		curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_path);
		curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie_path);
		$result = curl_exec($ch);
		curl_close($ch);
		return $result;
	}

	public function post($url, $data, $header){
		$ch = curl_init($url);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
		$req_header = [];
		if($header->Host != '')
			$req_header[] = 'Host: ' . $header->Host;
		if($header->Connection)
			$req_header[] = 'Connection: keep-alive';
		if($header->Accept != '')
			$req_header[] = 'Accept: ' . $header->Accept;
		if($header->Origin != '')
			$req_header[] = 'Origin: ' . $header->Origin;
		if($header->UserAgent != '')
			$req_header[] = 'User-Agent: ' . $header->UserAgent;
		if($header->Referer != '')
			$req_header[] = 'Referer: ' . $header->Referer;
		if($header->AcceptEncoding != '')
			$req_header[] = 'Accept-Encoding: ' . $header->AcceptEncoding;
		if($header->AcceptLanguage != '')
			$req_header[] = 'Accept-Language: ' . $header->AcceptLanguage;
		curl_setopt($ch, CURLOPT_HTTPHEADER, $req_header);
		curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_path);
		curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie_path);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
		$result = curl_exec($ch);
		curl_close($ch);
		return $result;
	}
}<?php
namespace delion\LobiAPI;

use delion\LobiAPI\HttpAPI\Http;
use delion\LobiAPI\HttpAPI\Header;

class LobiAPI{
	private $NetworkAPI = null;

	public function __construct(){
		$this->NetworkAPI = new Http();
	}

	public function Login($mail, $password){
		$header1 = (new Header())
			->setAccept('text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		$source = $this->NetworkAPI->get('https://lobi.co/signin', $header1);
		$csrf_token = Pattern::get_string($source, Pattern::$csrf_token, '"');

		$post_data = sprintf('csrf_token=%s&email=%s&password=%s', $csrf_token, $mail, $password);
		$header2 = (new Header())
			->setAccept('text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		return strpos($this->NetworkAPI->post('https://lobi.co/signin', $post_data, $header2), 'ログインに失敗しました') === false;
	}

	public function TwitterLogin($mail, $password){
		$header1 = (new Header())
			->setAccept('text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		$source = $this->NetworkAPI->get('https://lobi.co/signup/twitter', $header1);
		$authenticity_token = Pattern::get_string($source, Pattern::$authenticity_token, '"');
		$redirect_after_login = Pattern::get_string($source, Pattern::$redirect_after_login, '"');
		$oauth_token = Pattern::get_string($source, Pattern::$oauth_token, '"');

		$post_data = 'authenticity_token=' . $authenticity_token . '&redirect_after_login=' . $redirect_after_login . '&oauth_token=' . $oauth_token . '&session%5Busername_or_email%5D=' . $mail . '&session%5Bpassword%5D=' . $password;
		$header2 = (new Header())
			->setAccept('text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		$source2 = $this->NetworkAPI->post('https://api.twitter.com/oauth/authorize', $post_data, $header2);
		if(strpos($source2, 'Twitterにログイン') !== false)
			return false;

		return strpos($this->NetworkAPI->get(Pattern::get_string($source2, Pattern::$twitter_redirect_to_lobi, '"'), $header1), 'ログインに失敗しました') === false;
	}

	public function GetMe(){
		$header = (new Header())
			->setAccept('application/json, text/plain, */*')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		return json_decode($this->NetworkAPI->get('https://web.lobi.co/api/me?fields=premium', $header), false);
	}

	public function GetPublicGroupList(){
		$header = (new Header())
			->setAccept('application/json, text/plain, */*')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		$result = [];

		$index = 1;
		while(true){
			$pg = json_decode($this->NetworkAPI->get("https://web.lobi.co/api/public_groups?count=1000&page=$index&with_archived=1", $header), false);
			$index++;
			if(count($pg[0]->items) == 0)
				break;
			foreach($pg as $pgbf)
				$result[] = $pg;
		}

		return $result;
	}

	public function GetPrivateGroupList(){
		$header = (new Header())
			->setAccept('application/json, text/plain, */*')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		$result = [];

		$index = 1;
		while(true){
			$pg = json_decode($this->NetworkAPI->get("https://web.lobi.co/api/groups?count=1000&page=$index", $header), false);
			$index++;
			if(count($pg[0]->items) == 0)
				break;
			foreach($pg as $pgbf)
				$result[] = $pg;
		}

		return $result;
	}

	public function GetNotifications(){
		$header = (new Header())
			->setAccept('application/json, text/plain, */*')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		return json_decode($this->NetworkAPI->get('https://web.lobi.co/api/info/notifications?platform=any', $header), false);
	}

	public function GetContacts($uid){
		$header = (new Header())
			->setAccept('application/json, text/plain, */*')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		return json_decode($this->NetworkAPI->get("https://web.lobi.co/api/user/$uid/contacts", $header), false);
	}

	public function GetFollowers($uid){
		$header = (new Header())
			->setAccept('application/json, text/plain, */*')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		return json_decode($this->NetworkAPI->get("https://web.lobi.co/api/user/$uid/followers", $header), false);
	}

	public function GetGroup($uid){
		$header = (new Header())
			->setAccept('application/json, text/plain, */*')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		return json_decode($this->NetworkAPI->get("https://web.lobi.co/api/group/$uid?error_flavor=json2&fields=group_bookmark_info%2Capp_events_info", $header), false);
	}

	public function GetGroupMembersCount($uid){
		$header = (new Header())
			->setAccept('application/json, text/plain, */*')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		$result = json_decode($this->NetworkAPI->get("https://web.lobi.co/api/group/$uid?error_flavor=json2&fields=group_bookmark_info%2Capp_events_info", $header), false);
		if(!isset($result->members_count))
			return 0;
		if($result->members_count == null)
			return 0;
		return $result->members_count;
	}

	public function GetGroupMembers($uid){
		$header = (new Header())
			->setAccept('application/json, text/plain, */*')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		$result = [];
		$next = '0';
		$limit = 10000;
		while($limit-- > 0){
			$g = json_decode($this->NetworkAPI->get("https://web.lobi.co/api/group/$uid?members_cursor=$next", $header), false);
			foreach($g->members as $m)
				$result[] = $m;
			if($g->members_next_cursor == 0)
				break;
			$next = $g->members_next_cursor;
		}

		return $result;
	}

	public function GetThreads($uid, $count = 20){
		$header = (new Header())
			->setAccept('application/json, text/plain, */*')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		return json_decode($this->NetworkAPI->get("https://web.lobi.co/api/group/$uid/chats?count=$count", $header), false);
	}
	
	public function GetReplies($uid,$chatid){
        	$header = (new Header())
           		->setAccept('application/json, text/plain, */*')
          	 	->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
          	 	->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

       		return json_decode($this->NetworkAPI->get("https://web.lobi.co/api/group/$uid/chats/replies?to=$chatid", $header),true);
   	}

	public function Goo($group_id, $chat_id){
		$header = (new Header())
			->setAccept('application/json, text/plain, */*')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		$data = ['test'=>'test_content'];

		$this->NetworkAPI->post('https://web.lobi.co/api/group/$group_id/chats/like', $data, $header);
	}

	public function UnGoo($group_id, $chat_id){
		$header = (new Header())
			->setAccept('application/json, text/plain, */*')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		$data = ['id' => $chat_id];

		$this->NetworkAPI->post("https://web.lobi.co/api/group/$group_id/chats/unlike", $data, $header);
	}

	public function Boo($group_id, $chat_id){
		$header = (new Header())
			->setAccept('application/json, text/plain, */*')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		$data = ['id' => $chat_id];

		$this->NetworkAPI->post("https://web.lobi.co/api/group/$group_id/chats/boo", $data, $header);
	}

	public function UnBoo($group_id, $chat_id){
		$header = (new Header())
			->setAccept('application/json, text/plain, */*')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		$data = ['id' => $chat_id];

		$this->NetworkAPI->post("https://web.lobi.co/api/group/$group_id/chats/unboo", $data, $header);
	}

	public function Follow($user_id){
		$header = (new Header())
			->setAccept('application/json, text/plain, */*')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		$data = ['users' => $user_id];

		$this->NetworkAPI->post("https://web.lobi.co/api/me/contacts", $data, $header);
	}

	public function UnFollow($user_id){
		$header = (new Header())
			->setAccept('application/json, text/plain, */*')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		$data = ['users' => $user_id];

		$this->NetworkAPI->post("https://web.lobi.co/api/me/contacts/remove", $data, $header);
	}

	public function MakeThread($group_id, $message, $shout = false){
		$header = (new Header())
			->setAccept('application/json, text/plain, */*')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		$data = [
			'type' => $shout ? 'shout' : 'normal',
			'lang' => 'ja',
			'message' => $message
		];

		$this->NetworkAPI->post("https://web.lobi.co/api/group/$group_id/chats", $data, $header);
	}

	public function Reply($group_id, $thread_id, $message){
		$header = (new Header())
			->setAccept('application/json, text/plain, */*')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		$data = [
			'type' => 'normal',
			'lang' => 'ja',
			'message' => $message,
			'reply_to' => $thread_id
		];

		$this->NetworkAPI->post("https://web.lobi.co/api/group/$group_id/chats", $data, $header);
	}

	public function MakePrivateGroup($user_id){
		$header = (new Header())
			->setAccept('application/json, text/plain, */*')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		$data = ['user' => $user_id];

		$this->NetworkAPI->post('https://web.lobi.co/api/groups/1on1s', $data, $header);
	}

	public function ChangeProfile($name, $description){
		$header = (new Header())
			->setAccept('application/json, text/plain, */*')
			->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36')
			->setAcceptLanguage('ja,en-US;q=0.8,en;q=0.6');

		$data = [
			'name' => $name,
			'description' => $description
		];

		$this->NetworkAPI->post("https://web.lobi.co/api/me/profile", $data, $header);
	}
}

class Pattern{
	public static $csrf_token = '<input type="hidden" name="csrf_token" value="';
	public static $authenticity_token = '<input name="authenticity_token" type="hidden" value="';
	public static $redirect_after_login = '<input name="redirect_after_login" type="hidden" value="';
	public static $oauth_token = '<input id="oauth_token" name="oauth_token" type="hidden" value="';
	public static $twitter_redirect_to_lobi = '<a class="maintain-context" href="';
	public static function get_string($source, $pattern, $end_pattern){
		$start = strpos($source, $pattern) + strlen($pattern);
		$end = strpos($source, $end_pattern, $start + 1);
		return substr($source, $start, $end - $start);
	}
}
<?php

namespace roi611\pmmptolobi;

use pocketmine\event\plugin\PluginEvent;

class LobiChatEvent extends PluginEvent{

    public function __construct($name,$message){

        $this->name = $name;
        $this->message = $message;

    }

    public function getName(): string{
        return $this->name;
    }

    public function getMessage(){
        return $this->message;
    }

}<?php

namespace roi611\pmmptolobi;

use pocketmine\plugin\PluginBase;

use pocketmine\event\Listener;
use pocketmine\event\player\PlayerChatEvent;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\event\player\PlayerQuitEvent;

use pocketmine\Server;
use pocketmine\Player;

use pocketmine\utils\Config;

use delion\LobiAPI\LobiAPI;

use pocketmine\utils\TextFormat;

use pocketmine\scheduler\Task;

class Main extends PluginBase implements Listener
{

    /** @var Config */
    public static $config;

    public $api;

    public function onEnable()
    {

        date_default_timezone_set("Asia/Tokyo");
        $this->getServer()->getPluginManager()->registerEvents($this, $this);
        self::$config = new Config($this->getDataFolder()."DATA.yml", Config::YAML, array(
            "Mail" => "テスト@テスト.gg",//ログイン用
            "Pass" => "aiueo12345",//ログイン用
            "sendGroup" => "https://web.lobi.co/group/  ->  000000000000000000000000000000000000000  <-",//メッセージを送信するグループID
            "getGroup" => "https://web.lobi.co/group/  ->  000000000000000000000000000000000000000  <-",//メッセージを取得するグループID
            "LoadTime" => 10,//メッセージを取得する周期
            "LoadThreads" => 1,//一回のループで取得するメッセージ数
            "UID" => "変更しないでください",//変更しないでください
            "JoinMessage" => "%nameがサーバーに参加しました！<br>(%now/%max)",//プレイヤー参加時のメッセージ
            "QuitMessage" => "%nameがサーバーから退出しました.....<br>(%reason)<br>また来てくださいね！<br>(%now/%max)",//プレイヤー退出時のメッセージ
            "ChatMessage" => "<%name> %message",//LOBIに送信するチャットメッセージ
            "SendMessage" => "[LOBI] <%name> %message",//Minecraftに送信するチャットメッセージ
            "ServerStart" => "サーバーが起動しました！",//サーバー起動時のメッセージ
            "ServerStop" => "サーバーが停止しました.....<br>起動までお待ちください！",//サーバー停止時のメッセージ
            "ReadMessage" => "送信しました",//送信成功時のメッセージ
            "FailureMessage" => "送信できませんでした",//送信失敗時のメッセージ
            "ServerMessageShout" => true,//サーバーの起動・停止時のシャウトのするか
            "MessageShout" => false,//プレイヤーチャットや参加メッセージのシャウトをするか
            "Time" =>"変更しないでください",//変更しないでください
            "Name" => "変更しないでください"//変更しないでください
        ));

        if(Main::$config->get("Mail") !== "テスト@テスト.gg" && Main::$config->get("sendGroup") !== "https://web.lobi.co/group/  ->  000000000000000000000000000000000000000  <-" && Main::$config->get("sendGroup") !== "https://web.lobi.co/group/  ->  000000000000000000000000000000000000000  <-"){

            $api = new LobiAPI();
            $this->api = $api;

            if($api->Login(self::$config->get("Mail"),self::$config->get("Pass"))){
            
                //ログイン成功
                $this->getLogger()->info(TextFormat::AQUA."ログイン成功\nこれ以降はアカウントを変更しないでください\n変更したい場合はconfigファイルごと消去してください");
                $text = Main::$config->get("ServerStart");
                $text = str_replace("<br>","\n",$text);
                $api->MakeThread(Main::$config->get("sendGroup"),$text,Main::$config->get("ServerMessageShout"));//LOBIにメッセージを作成

                /* ↓ UID,Name,Time の設定 ↓ */

                if(Main::$config->get("UID") === "変更しないでください"){

                    $user = $api->GetMe();
                    $uid = $user->{'uid'};
                    Main::$config->set("UID",$uid);
                    Main::$config->save();

                }

                if(Main::$config->get("Name") === "変更しないでください"){

                    $user = $api->GetMe();
                    $uid = $user->{'name'};
                    Main::$config->set("Name",$uid);
                    Main::$config->save();

                }

                Main::$config->set("Time",date("Y-m-d H:i:s",time()));
                Main::$config->save();
                $this->getScheduler()->scheduleRepeatingTask(new sendTask($api),Main::$config->get("LoadTime"));

            } else {

                //ログイン失敗
                $this->getLogger()->info(TextFormat::RED.'ログイン失敗');
                $this->getLogger()->info("§cこのプラグインを無効化致します。§r");
                $this->getServer()->getPluginManager()->disablePlugin($this);

            }

        } else {

            $this->getLogger()->info(TextFormat::RED.'Configを正しく入力してから有効にしてください');
            $this->getLogger()->info("§cこのプラグインを無効化致します。§r");
            $this->getServer()->getPluginManager()->disablePlugin($this);

        }

    }



    public function onDisable(){

        if($this->api !== null){

            $text = Main::$config->get("ServerStop");
            $text = str_replace("<br>","\n",$text);
            $this->api->MakeThread(Main::$config->get("sendGroup"),$text,Main::$config->get("ServerMessageShout"));//メッセージを作成

            $messages = $this->api->getThreads(Main::$config->get("getGroup"),3);//履歴のメッセージを作成

            foreach($messages as $data){

                $message = $data->{"message"};

                if($message === "この投稿（チャット）はグループリーダーもしくはサブリーダーによって削除されました。"){
                    continue;
                }

                if(empty($message)){
                    continue;
                }

                $user = $data->{'user'};
                $uid = $user->{'uid'};

                if($uid === Main::$config->get("UID")){//ログインしているアカウントだったら
                    continue;
                }

                $id = $data->{'id'};
                $replies = $this->api->GetReplies(Main::$config->get("getGroup"),$id);//スレッドの返信メッセージをすべて取得
                
                if(!(empty($replies['chats']))){//返信メッセージがあるか、

                    $bool = true;

                    foreach($replies['chats'] as $reply){

                        $ruser = $reply['user'];
                        $ruid = $ruser['uid'];

                        if($ruid == Main::$config->get("UID")){//返信にログインしているユーザーのメッセージがあるか、

                            $bool = false;

                        }

                    }

                    if($bool){//処理済みか、

                        $this->api->Reply(Main::$config->get("getGroup"),$id,Main::$config->get("FailureMessage"));//スレッドに返信

                    }

                } else {

                    $this->api->Reply(Main::$config->get("getGroup"),$id,Main::$config->get("FailureMessage"));//スレッドに返信

                }

            }

        }

    }



    public function onJoin(PlayerJoinEvent $event){

        /** ↓ 参加時にLOBIにスレッドを立てる ↓ */
        $text = Main::$config->get("JoinMessage");
        $text = str_replace("<br>","\n",$text);
        $text = str_replace("%now",count($this->getServer()->getOnlinePlayers()),$text);
        $text = str_replace("%max",$this->getServer()->getMaxPlayers(),$text);
        $text = str_replace("%name",$event->getPlayer()->getName(),$text);
        $this->api->MakeThread(Main::$config->get("sendGroup"),$text,Main::$config->get("MessageShout"));

    }



    public function onQuit(PlayerQuitEvent $event){

        /** ↓ 退出時にLOBIにスレッドを立てる ↓ */
        $text = Main::$config->get("QuitMessage");
        $text = str_replace("<br>","\n",$text);
        $count = count($this->getServer()->getOnlinePlayers()) - 1;
        $text = str_replace("%now",$count,$text);
        $text = str_replace("%max",$this->getServer()->getMaxPlayers(),$text);
        $text = str_replace("%name",$event->getPlayer()->getName(),$text);
        $text = str_replace("%reason",$event->getQuitReason(),$text);
        $this->api->MakeThread(Main::$config->get("sendGroup"),$text,Main::$config->get("MessageShout"));

    }



    public function onChat(PlayerChatEvent $event){
    
        $player = $event->getPlayer();
        $name = $player->getName();
        /** ↓ 色文字を無効化 ↓ */
        $message = $event->getMessage();
        $message = str_replace("§0","",$message);
        $message = str_replace("§1","",$message);
        $message = str_replace("§2","",$message);
        $message = str_replace("§3","",$message);
    
        $message = str_replace("§4","",$message);
        $message = str_replace("§5","",$message);
        $message = str_replace("§6","",$message);
        $message = str_replace("§7","",$message);
        $message = str_replace("§8","",$message);
        $message = str_replace("§9","",$message);
        $message = str_replace("§a","",$message);
        $message = str_replace("§b","",$message);
        $message = str_replace("§c","",$message);
        $message = str_replace("§d","",$message);
        $message = str_replace("§e","",$message);
        $message = str_replace("§f","",$message);
        $message = str_replace("§k","",$message);
        $message = str_replace("§l","",$message);
        $message = str_replace("§m","",$message);
        $message = str_replace("§n","",$message);
        $message = str_replace("§o","",$message);
        $message = str_replace("§r","",$message);

        /** ↓ チャット時にLOBIにスレッドを立てる ↓ */

        $text = Main::$config->get("ChatMessage");
        $text = str_replace("%name",$name,$text);
        $text = str_replace("%message",$message,$text);
        $text = str_replace("<br>","\n",$text);

        $this->api->MakeThread(Main::$config->get("sendGroup"),$text,Main::$config->get("MessageShout"));

    }



}








class sendTask extends Task{

    public function __construct($api){
        $this->api = $api;
    }
    
    public function onRun(int $currentTick){//定期的にメッセージを取得し処理を行う

        $messages = $this->api->getThreads(Main::$config->get("getGroup"),Main::$config->get("LoadThreads"));//スレッドを取得

        if(!(empty($messages))){//メッセージがあるか、

            foreach($messages as $data){

                $message = $data->{"message"};

                if(empty($message)){
                    continue;
                }

                if($message === "この投稿（チャット）はグループリーダーもしくはサブリーダーによって削除されました。"){
                    continue;
                }

                $user = $data->{'user'};
                $uid = $user->{'uid'};

                if($uid === Main::$config->get("UID")){//ログインしているユーザーか、
                    continue;
                }

                $id = $data->{'id'};
                $replies = $this->api->GetReplies(Main::$config->get("getGroup"),$id);//スレッドの返信をすべて取得
                
                if(!(empty($replies['chats']))){

                    $bool = true;

                    foreach($replies['chats'] as $reply){

                        $ruser = $reply['user'];
                        $ruid = $ruser['uid'];

                        if($ruid === Main::$config->get("UID")){//返信にログインしているユーザーのメッセージがあるか、

                            $bool = false;

                        }

                    }

                    if($bool){

                        $time = $data->{'created_date'};
                        $time = strtotime(date("Y-m-d H:i:s",$time));
                        $old = strtotime(Main::$config->get("Time"));
                        if($old > $time){//サーバー起動より前のメッセージか、

                            $this->api->Reply(Main::$config->get("getGroup"),$id,Main::$config->get("FailureMessage"));
                            continue;

                        } else {

                            /** ↓ Minecraftに送信 ↓ */
                            $name = $user->{'name'};
                            $text = Main::$config->get("SendMessage");
                            $text = str_replace("%name",$name,$text);
                            $text = str_replace("%message",$message,$text);
                            $this->api->Reply(Main::$config->get("getGroup"),$id,Main::$config->get("ReadMessage"));//返信する
                            $api = new LobiChatEvent($name,$message);
                            $api->call();//イベントを発火
                            Server::getInstance()->broadcastMessage($text);//Minecraftに送信
                            continue;

                        }

                    }

                } else {

                    $time = $data->{'created_date'};
                    $time = strtotime(date("Y-m-d H:i:s",$time));
                    $old = strtotime(Main::$config->get("Time"));
                    if($old > $time){//サーバー起動より前のメッセージか、

                        $this->api->Reply(Main::$config->get("getGroup"),$id,Main::$config->get("FailureMessage"));//返信を追加
                        continue;

                    } else {

                        /** ↓ Minecraftに送信 ↓ */
                        $name = $user->{'name'};
                        $text = Main::$config->get("SendMessage");
                        $text = str_replace("%name",$name,$text);
                        $text = str_replace("%message",$message,$text);
                        $this->api->Reply(Main::$config->get("getGroup"),$id,Main::$config->get("ReadMessage"));//返信
                        $api = new LobiChatEvent($name,$message);
                        $api->call();//イベントを発火
                        Server::getInstance()->broadcastMessage($text);//Minecraftに送信
                        continue;

                    }

                }

            }

        }

    }

}t"e:8iv+AʧXh   GBMB