
<?php
echo "PocketMine-MP plugin TeamAPI v1.0.1
This file has been generated using DevTools v1.14.0 at Wed, 29 Jul 2020 21:47:51 +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:1596026871;}
   plugin.ymlX   ÷o!_X   mÅÍ¶         LICENSE*  ÷o!_*  a9½º¶      	   README.mdÏ  ÷o!_Ï  ¾Ø×¶         src/matsuo/TeamAPI/TeamAPI.php§
  ÷o!_§
  ›ð"”¶      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($player);
	  if(is_null($teamname["team"]) == false){
    $teamname =  $this->getTeam($player);
    $this -> leaveTeam($teamname["team"], $player);
		}
    
  }

  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);//ãƒãƒ¼ãƒ ã«æ‰€å±žã—ã¦ãªã‹ã£ãŸã‚‰ã“ã“ã¯ã‚¹ãƒ«ãƒ¼ã•ã‚Œã¦å…¨å“¡ã«é€ä¿¡ã•ã‚Œã¡ã‚ƒã†ã‹ã‚‰ã€ä»•æ§˜ã«ã‚ã‚ã›ã¦å¤‰æ›´ã—ã¦
    }
  }
}

+6e­&`ß2“üNîHþÝ   GBMB