
<?php
echo "PocketMine-MP plugin TeamAPI v1.0.0
This file has been generated using DevTools v1.14.0 at Sun, 26 Jul 2020 20:33:21 +0900
----------------
";

if(extension_loaded("phar")){
	$phar = new \Phar(__FILE__);
	foreach($phar->getMetadata() as $key => $value){
		echo ucfirst($key) . ": " . (is_array($value) ? implode(", ", $value) : $value) . "\n";
	}
}

__HALT_COMPILER(); ?>
¬             ò   a:9:{s:4:"name";s:7:"TeamAPI";s:7:"version";s:5:"1.0.1";s:4:"main";s:22:"matsuo\TeamAPI\TeamAPI";s:3:"api";s:6:"3.11.0";s:6:"depend";s:0:"";s:11:"description";s:0:"";s:7:"authors";s:0:"";s:7:"website";s:0:"";s:12:"creationDate";i:1595763201;}
   plugin.ymlX   j_X   mÅͶ         LICENSE*  j_*  a9½º¶      	   README.mdÏ  j_Ï  ¾Ø׶         src/matsuo/TeamAPI/TeamAPI.phpP
  j_P
  k{žӶ      name: TeamAPI
main: matsuo\TeamAPI\TeamAPI
version: 1.0.1
api: 3.11.0
author: matsuo877
MIT License

Copyright (c) 2020 matsuo877

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# TeamAPI
チーム関連のAPI  
チャット非表示、フレンドリーファイア禁止機能標準搭載

サーバーのpluginsフォルダに入れれば使えるようになります

use文  
```use matsuo\TeamAPI\TeamAPI```

インスタンスの取得例
```TeamAPI::getInstance()->jointeam($teamname, $player);```

使える関数  
$playerはプレイヤーオブジェクトとします  
チームに参加する  
```jointeam($teamname, $player)```  
チームを抜ける  
```leaveteam($teamname, $player)```  
チーム情報を取得する（戻り値は[チーム名、メンバー]のような形の配列で帰ってきます）  
```getteam（$player）```  
2人のプレイヤーが同じチームか確認する（返り値はbool型です）  
```sameteam($playera, $playerb)```  
SPECIAL THANKS  
WhiteGrouseさん  
rain1208さん  
らっしゅさん  


**問題点等あればお気軽にプルリクして頂けると助かります。**
<?php
namespace matsuo\TeamAPI;

use pocketmine\plugin\PluginBase;
use pocketmine\event\Listener;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\player\PlayerChatEvent;
use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\Player;

class TeamAPI extends PluginBase implements Listener {
  
  private static $instance = null;
  
  public static function getInstance(){
   return self::$instance;
}

  public function onLoad(){
   self::$instance = $this;
}

  private $teams = [];

  public function joinTeam(string $teamName, Player $player) {
    $playerName = $player->getName();
    $members = [];
    $members[] = $playerName;
    $this->teams[$teamName] = $members;
  }

  public function leaveTeam(string $teamName, Player $player) {
    $playerName = $player->getName();
    if(($key = array_search($playerName, $this->teams[$teamName])) !== false) {
      unset($this->teams[$teamName][$key]);
    }
  }

  public function getTeam(Player $player) {
    $name = $player->getName();
    foreach($this->teams as $teamName => $members) {
      if(in_array($name, $members)) {
        return ["team" => $teamName, "members" => $members];
      }
    }
    return false;
  }

  public function sameTeam($playerA, $playerB): bool {
    $nameA = $playerA->getName();
    $nameB = $playerB->getName();
    foreach($this->teams as $teamName => $members) {
      if(in_array($nameA, $members) && in_array($nameB, $members)) {
        return true;
      }
    }
    return false;
  }

  public function onEnable() {
    $this->getServer()->getPluginManager()->registerEvents($this, $this);
  }

  public function onDamage(EntityDamageByEntityEvent $event) {
    $atker = $event->getDamager();
    $hiter = $event->getEntity();
    if($atker instanceof Player && $hiter instanceof Player && $this->sameTeam($atker, $hiter)) {
      $event->setCancelled();
    }
  }

  public function onQuit(PlayerQuitEvent $event) {
    $player = $event -> getPlayer();
    $teamname = $this->getTeam($event->getName());
    $this -> leaveTeam($teamname, $player->getname());
  }

  public function onChat(PlayerChatEvent $event) {
    $sender = $event->getPlayer();
    $recipients = [];
    $teamInfo = $this->getTeam($sender);
    if($teamInfo !== false) {
      foreach($event->getRecipients() as $player) {
        if(in_array($player->getName(), $teamInfo["members"])) {
          $recipients[] = $player;
        }
      }
      $event->setRecipients($recipients);//チームに所属してなかったらここはスルーされて全員に送信されちゃうから、仕様にあわせて変更して
    }
  }
}

�s,衞oéz.“e71w   GBMB