G2A Many GEOs
SHARE
TWEET

Untitled

a guest Mar 28th, 2020 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace FactionsPro;
  4.  
  5. use pocketmine\event\Listener;
  6. use pocketmine\event\block\{BlockPlaceEvent, BlockBreakEvent};
  7. use pocketmine\Player;
  8. use pocketmine\event\entity\{EntityDamageEvent, EntityDamageByEntityEvent};
  9. use EssentialsPE\BaseFiles\BaseAPI;
  10. use pocketmine\tile\MobSpawner;
  11. use pocketmine\utils\{Config, TextFormat};
  12. use pocketmine\scheduler\PluginTask;
  13. use pocketmine\event\player\{PlayerQuitEvent, PlayerJoinEvent, PlayerMoveEvent, PlayerDeathEvent, PlayerChatEvent, PlayerInteractEvent};
  14. use pocketmine\block\Block;
  15.  
  16. class FactionListener implements Listener {
  17.    
  18.     public $plugin;
  19.    
  20.     public function __construct(FactionMain $pg) {
  21.         $this->plugin = $pg;
  22.     }
  23.    
  24.     public function factionChat(PlayerChatEvent $PCE) {
  25.        
  26.         $playerName = $PCE->getPlayer()->getName();
  27.         //MOTD Check
  28.         if($this->plugin->motdWaiting($playerName)) {
  29.             $motdtime = $this->plugin->prefs->get("MOTDTime");
  30.             if(time() - $this->plugin->getMOTDTime($playerName) > $motdtime) {
  31.                 $PCE->getPlayer()->sendMessage($this->plugin->formatMessage("§cTimed out. §bPlease use: §3/f desc again."));
  32.                 $this->plugin->db->query("DELETE FROM motdrcv WHERE player='$playerName';");
  33.                 $PCE->setCancelled(true);
  34.                 return true;
  35.             } else {
  36.                 $motd = $PCE->getMessage();
  37.                 $faction = $this->plugin->getPlayerFaction($playerName);
  38.                 $this->plugin->setMOTD($faction, $playerName, $motd);
  39.                 $PCE->setCancelled(true);
  40.                 $PCE->getPlayer()->sendMessage($this->plugin->formatMessage("§dSuccessfully updated the faction description. Type §5/f who", true));
  41.             }
  42.         }
  43.         if(isset($this->plugin->factionChatActive[$playerName])){
  44.             if($this->plugin->factionChatActive[$playerName]){
  45.                 $msg = $PCE->getMessage();
  46.                 $faction = $this->plugin->getPlayerFaction($playerName);
  47.                 foreach($this->plugin->getServer()->getOnlinePlayers() as $fP){
  48.                     if($this->plugin->getPlayerFaction($fP->getName()) == $faction){
  49.                         if($this->plugin->getServer()->getPlayer($fP->getName())){
  50.                             $PCE->setCancelled(true);
  51.                             $this->plugin->getServer()->getPlayer($fP->getName())->sendMessage(TextFormat::DARK_GREEN."[$faction]".TextFormat::BLUE." $playerName: ".TextFormat::AQUA. $msg);
  52.                         }
  53.                     }
  54.                 }
  55.             }
  56.         }
  57.         if(isset($this->plugin->allyChatActive[$playerName])){
  58.             if($this->plugin->allyChatActive[$playerName]){
  59.                 $msg = $PCE->getMessage();
  60.                 $faction = $this->plugin->getPlayerFaction($playerName);
  61.                 foreach($this->plugin->getServer()->getOnlinePlayers() as $fP){
  62.                     if($this->plugin->areAllies($this->plugin->getPlayerFaction($fP->getName()), $faction)){
  63.                         if($this->plugin->getServer()->getPlayer($fP->getName())){
  64.                             $PCE->setCancelled(true);
  65.                             $this->plugin->getServer()->getPlayer($fP->getName())->sendMessage(TextFormat::DARK_GREEN."[$faction]".TextFormat::BLUE." $playerName: ".TextFormat::AQUA. $msg);
  66.                             $PCE->getPlayer()->sendMessage(TextFormat::DARK_GREEN."[$faction]".TextFormat::BLUE." $playerName: ".TextFormat::AQUA. $msg);
  67.                         }
  68.                     }
  69.                 }
  70.             }
  71.         }
  72.     }
  73.    
  74.     public function factionPVP(EntityDamageEvent $factionDamage) {
  75.         if($factionDamage instanceof EntityDamageByEntityEvent) {
  76.             if(!($factionDamage->getEntity() instanceof Player) or !($factionDamage->getDamager() instanceof Player)) {
  77.                 return true;
  78.             }
  79.             if(($this->plugin->isInFaction($factionDamage->getEntity()->getPlayer()->getName()) == false) or ($this->plugin->isInFaction($factionDamage->getDamager()->getPlayer()->getName()) == false)) {
  80.                 return true;
  81.             }
  82.             if(($factionDamage->getEntity() instanceof Player) and ($factionDamage->getDamager() instanceof Player)) {
  83.                 $player1 = $factionDamage->getEntity()->getPlayer()->getName();
  84.                 $player2 = $factionDamage->getDamager()->getPlayer()->getName();
  85.                         $f1 = $this->plugin->getPlayerFaction($player1);
  86.                 $f2 = $this->plugin->getPlayerFaction($player2);
  87.                 if((!$this->plugin->prefs->get("AllowFactionPvp") && $this->plugin->sameFaction($player1, $player2) == true) or (!$this->plugin->prefs->get("AllowAlliedPvp") && $this->plugin->areAllies($f1,$f2))) {
  88.                     $factionDamage->setCancelled(true);
  89.                 }
  90.             }
  91.         }
  92.     }
  93.    
  94.     public function onInteract(PlayerInteractEvent $e){
  95.         if($this->plugin->isInPlot($e->getPlayer())){
  96.             if(!$this->plugin->inOwnPlot($e->getPlayer())){
  97.                 if($e->getPlayer()->isCreative()){
  98.                     $e->getPlayer()->sendMessage($this->plugin->formatMessage("§c§lRaiding environment detected. Switching to survival mode."));
  99.                     $p->setGamemode(0);
  100.                     $e->setCancelled(true);
  101.                 }
  102.                 if($this->plugin->essentialspe->baseapi->isGod($e->getPlayer())){
  103.                     $e->getPlayer()->sendMessage($this->plugin->formatMessage("§c§lRaiding environment detected. Disabling god mode."));
  104.                     $e->setCancelled(true);
  105.                 }
  106.             }
  107.         }
  108.     }
  109.    
  110.     public function factionBlockBreakProtect(BlockBreakEvent $event) {
  111.         $x = $event->getBlock()->getX();
  112.         $y = $event->getBlock()->getY();
  113.         $z = $event->getBlock()->getZ();
  114.         if($this->plugin->pointIsInPlot($x, $z)){
  115.             if($this->plugin->factionFromPoint($x, $z) === $this->plugin->getFaction($event->getPlayer()->getName())){
  116.                 return true;
  117.             }else{
  118.                 $event->setCancelled(true);
  119.                 $event->getPlayer()->sendMessage($this->plugin->formatMessage("§6You cannot break blocks here. This is already a property of a faction. Type §2/f plotinfo §6for details."));
  120.                 return true;
  121.             }
  122.         }
  123.     }
  124.    
  125.     public function factionBlockPlaceProtect(BlockPlaceEvent $event) {
  126.             $x = $event->getBlock()->getX();
  127.         $y = $event->getBlock()->getY();
  128.             $z = $event->getBlock()->getZ();
  129.         if($this->plugin->pointIsInPlot($x, $z)) {
  130.             if($this->plugin->factionFromPoint($x, $z) === $this->plugin->getFaction($event->getPlayer()->getName())) {
  131.                 return true;
  132.             } else {
  133.                 $event->setCancelled(true);
  134.                 $event->getPlayer()->sendMessage($this->plugin->formatMessage("§6You cannot place blocks here. This is already a property of a faction. Type §2/f plotinfo for details."));
  135.                 return true;
  136.             }
  137.         }
  138.     }
  139.     public function onKill(PlayerDeathEvent $event){
  140.         $ent = $event->getEntity();
  141.         $cause = $event->getEntity()->getLastDamageCause();
  142.         if($cause instanceof EntityDamageByEntityEvent){
  143.             $killer = $cause->getDamager();
  144.             if($killer instanceof Player){
  145.                 $p = $killer->getPlayer()->getName();
  146.                 if($this->plugin->isInFaction($p)){
  147.                     $f = $this->plugin->getPlayerFaction($p);
  148.                     $e = $this->plugin->prefs->get("PowerGainedPerKillingAnEnemy");
  149.                     if($ent instanceof Player){
  150.                         if($this->plugin->isInFaction($ent->getPlayer()->getName())){
  151.                            $this->plugin->addFactionPower($f,$e);
  152.                         } else {
  153.                            $this->plugin->addFactionPower($f,$e/2);
  154.                         }
  155.                     }
  156.                 }
  157.             }
  158.         }
  159.         if($ent instanceof Player){
  160.             $e = $ent->getPlayer()->getName();
  161.             if($this->plugin->isInFaction($e)){
  162.                 $f = $this->plugin->getPlayerFaction($e);
  163.                 $e = $this->plugin->prefs->get("PowerGainedPerKillingAnEnemy");
  164.                 if($ent->getLastDamageCause() instanceof EntityDamageByEntityEvent && $ent->getLastDamageCause()->getDamager() instanceof Player){
  165.                     if($this->plugin->isInFaction($ent->getLastDamageCause()->getDamager()->getPlayer()->getName())){      
  166.                         $this->plugin->subtractFactionPower($f,$e*2);
  167.                     } else {
  168.                         $this->plugin->subtractFactionPower($f,$e);
  169.                     }
  170.                 }
  171.             }
  172.         }
  173.     }
  174.     public function onBlockBreak(BlockBreakEvent $event){
  175.           if($event->isCancelled()) return true;
  176.           $player = $event->getPlayer();
  177.           if(!$this->plugin->isInFaction($player->getName())) return true;
  178.           $block = $event->getBlock();
  179.           if($block->getId() === Block::MONSTER_SPAWNER){
  180.               $fHere = $this->plugin->factionFromPoint($block->x, $block->y);
  181.               $playerF = $this->plugin->getPlayerFaction($player->getName());
  182.               if($fHere !== $playerF and !$player->isOp()){ $event->setCancelled(true); return true; };
  183.           }
  184.     }
  185.     public function broadcastTeamJoin(PlayerJoinEvent $event){
  186.        $player = $event->getPlayer();
  187.        
  188.             if($this->plugin->isInFaction($player->getName()) == true) {
  189.                $faction = $this->plugin->getPlayerFaction($player->getName());
  190.                $db = $this->plugin->db->query("SELECT * FROM master WHERE faction='$faction'");
  191.                 foreach($this->plugin->getServer()->getOnlinePlayers() as $fP){
  192.                     if($this->plugin->getPlayerFaction($fP->getName()) == $faction){
  193.                         if($this->plugin->getServer()->getPlayer($fP->getName())){
  194.                             $this->plugin->getServer()->getPlayer($fP->getName())->sendMessage("§l§a(!)§r§e " . $player->getName() . " §ais now online");
  195.                                }
  196.                           }
  197.                     }
  198.             }
  199.     }
  200.     public function broadcastTeamQuit(PlayerQuitEvent $event){
  201.        $player = $event->getPlayer();
  202.        $name = $player->getName();
  203.        
  204.                if($this->plugin->isInFaction($player->getName()) == true) {
  205.                $faction = $this->plugin->getPlayerFaction($player->getName());
  206.                $db = $this->plugin->db->query("SELECT * FROM master WHERE faction='$faction'");
  207.                 foreach($this->plugin->getServer()->getOnlinePlayers() as $fP){
  208.                     if($this->plugin->getPlayerFaction($fP->getName()) == $faction){
  209.                         if($this->plugin->getServer()->getPlayer($fP->getName())){
  210.                                                     $this->plugin->getServer()->getPlayer($fP->getName())->sendMessage("§l§c(!)§r§4 " . $player->getName() . " §cis now offline");
  211.             }
  212.           }
  213.         }
  214.                }
  215.     }
  216.     public function onEnterEvent(PlayerMoveEvent $event){
  217.     $x = floor($event->getPlayer()->getX());
  218.     $y = floor($event->getPlayer()->getY());
  219.     $z = floor($event->getPlayer()->getZ());
  220.        
  221.     if($this->plugin->isInPlot($event->getPlayer())) {
  222.     $faction = $this->plugin->getPlayerFaction();
  223.        $event->getPlayer()->addTitle("You have just entered", "A Faction's claim named: $faction", 40, 20, 40);
  224.     }
  225.     }
  226.     public function onLeaveClaim(PlayerMoveEvent $event){
  227.     $x = floor($event->getPlayer()->getX());
  228.     $y = floor($event->getPlayer()->getY());
  229.     $z = floor($event->getPlayer()->getZ());
  230.            
  231.     if($this->plugin->drawPlot($eventt->getPlayer())) {
  232.     $event->getPlayer()->addTitle("You have just left", "A Faction's plot!", 40, 20, 40);
  233.     }
  234.     }
  235.     public function onMoveMAP(PlayerMoveEvent $event){    
  236.     $x = floor($event->getPlayer()->getX());
  237.     $y = floor($event->getPlayer()->getY());
  238.     $z = floor($event->getPlayer()->getZ());
  239.        $Faction = $this->plugin->factionFromPoint($x,$z);
  240.            $asciiCompass = self::getASCIICompass($event->getPlayer()->getYaw(), TextFormat::RED, TextFormat::GREEN);
  241.              $compass = "     " . $asciiCompass[0] . "\n     " . $asciiCompass[1] . "\n     " . $asciiCompass[2] . "\n";
  242.           if(isset($this->plugin->factionMapActive[$event->getPlayer()->getName()])){
  243.           if($this->plugin->factionMapActive[$event->getPlayer()->getName()]){
  244.        
  245.           if($this->plugin->isInPlot($event->getPlayer())) {
  246.              if($this->plugin->inOwnPlot($event->getPlayer())) {
  247.                 $tip = $compass . "§l§6Protected area§r";
  248.                 $event->getPlayer()->sendTip($tip);
  249.             } else {
  250.                 $tip = $compass . "§l§c".$Faction;
  251.                 $event->getPlayer()->sendTip($tip);
  252.                 }
  253.             }
  254.         if(!$this->plugin->ip->canGetHurt($event->getPlayer())) {
  255.                $tip = $compass . "§l§aPublic area§r";
  256.                $event->getPlayer()->sendTip($tip);
  257.             }
  258.         if(!$this->plugin->isInPlot($event->getPlayer())){
  259.                $tip = $compass . "§l§2Zona Book§r";
  260.                $event->getPlayer()->sendTip($tip);
  261.             }
  262.         }
  263.     }
  264.         }
  265.         const N = 'N';
  266.     const NE = '/';
  267.     const E = 'E';
  268.     const SE = '\\';
  269.     const S = 'S';
  270.     const SW = '/';
  271.     const W = 'W';
  272.     const NW = '\\';
  273.     public static function getASCIICompass($degrees, $colorActive, $colorDefault) : array
  274.     {
  275.         $ret = [];
  276.         $point = self::getCompassPointForDirection($degrees);
  277.         $row = "";
  278.         $row .= ($point === self::NW ? $colorActive : $colorDefault) . self::NW;
  279.         $row .= ($point === self::N ? $colorActive : $colorDefault) . self::N;
  280.         $row .= ($point === self::NE ? $colorActive : $colorDefault) . self::NE;
  281.         $ret[] = $row;
  282.         $row = "";
  283.         $row .= ($point === self::W ? $colorActive : $colorDefault) . self::W;
  284.         $row .= $colorDefault . "+";
  285.         $row .= ($point === self::E ? $colorActive : $colorDefault) . self::E;
  286.         $ret[] = $row;
  287.         $row = "";
  288.         $row .= ($point === self::SW ? $colorActive : $colorDefault) . self::SW;
  289.         $row .= ($point === self::S ? $colorActive : $colorDefault) . self::S;
  290.         $row .= ($point === self::SE ? $colorActive : $colorDefault) . self::SE;
  291.         $ret[] = $row;
  292.         return $ret;
  293.     }
  294.     public static function getCompassPointForDirection($degrees)
  295.     {
  296.         $degrees = ($degrees - 180) % 360;
  297.         if ($degrees < 0)
  298.             $degrees += 360;
  299.         if (0 <= $degrees && $degrees < 22.5)
  300.             return self::N;
  301.         elseif (22.5 <= $degrees && $degrees < 67.5)
  302.             return self::NE;
  303.         elseif (67.5 <= $degrees && $degrees < 112.5)
  304.             return self::E;
  305.         elseif (112.5 <= $degrees && $degrees < 157.5)
  306.             return self::SE;
  307.         elseif (157.5 <= $degrees && $degrees < 202.5)
  308.             return self::S;
  309.         elseif (202.5 <= $degrees && $degrees < 247.5)
  310.             return self::SW;
  311.         elseif (247.5 <= $degrees && $degrees < 292.5)
  312.             return self::W;
  313.         elseif (292.5 <= $degrees && $degrees < 337.5)
  314.             return self::NW;
  315.         elseif (337.5 <= $degrees && $degrees < 360.0)
  316.             return self::N;
  317.         else
  318.             return null;    
  319.            }
  320.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top