diff --git a/README.md b/README.md index b774632..88037f8 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,24 @@ + ## Festival -If you like Festival please share your experience to help Festival plugin improve, thank you! +If you like Festival please [vote](https://poggit.pmmp.io/p/Festival/1.0.9) and [share your experience](https://github.com/genboy/Festival/issues) to help Festival plugin improve, thank you! ![Festival plugin logo large](https://genboy.net/wp-content/uploads/2018/02/festival_plugin_logo.png) - - Create a festival with this custom area events plugin for Pocketmine Server: ### Manage area's and run commmands attachted to area events. -![Festival creation & usage](https://genboy.net/wp-content/uploads/2018/11/festival_usage_1.0.8.png) +![Festival creation & usage](https://genboy.net/wp-content/uploads/2018/11/festival_usage_1.0.8.png) -###### Copyright [Genboy](https://genboy.net) 2018 +###### Copyright [Genboy](https://genboy.net) 2018 --- ## Info +Festival 1.0.9 functionalities will not extend further more. Important bug fixes will still be done untill Festival 2 is ready. +Festival 2 is in [development](https://github.com/genboy/Festival/projects/2) including FormUI for easy control, a new code structure and some of the flags will be completely rewritten. I probably dump the translations untill there is request for it. Just to let you know .. # Festival @@ -421,6 +422,11 @@ Thank you - Area messages display in chat with config option Msgtype 'msg' - cmd flag: area event commands for ops or whitelisted players only + **Since v1.0.9** + - gmc flying allowed by default + - fix inArea Player availabillity + - fix player damage cause check + ------ @@ -428,5 +434,4 @@ Thank you The area code derives from the [iProctector plugin](https://github.com/LDX-MCPE/iProtector). All credits for the area creation and protection code go to the iProtector creator [LDX-MCPE](https://github.com/LDX-MCPE) and [other iProtector devs](https://github.com/LDX-MCPE/iProtector/network). -The Festival code is written and tested by Genboy and first released on 12 Feb 2018, first extendomg the area object with area events (enter and leave messages) and soon added functions and ingame commands to attach a commandstring to a area-event. Since v1.0.7 the area's and players can be protected with 12 flags, and trigger commands on areaEnter, areaCenter and areaLeave. - +The Festival code is written and tested by Genboy and first released on 12 Feb 2018, first extending the area object with area events (enter and leave messages) and soon added functions and ingame commands to attach a commandstring to a area-event. Since v1.0.7 the area's and players can be protected with 12 flags, and trigger commands on areaEnter, areaCenter and areaLeave. \ No newline at end of file diff --git a/plugin.yml b/plugin.yml index 3f3daf9..f3c2a31 100644 --- a/plugin.yml +++ b/plugin.yml @@ -3,7 +3,7 @@ author: Genboy version: 1.0.8-dev2 main: genboy\Festival\Main load: POSTWORLD -api: [3.0.0-ALPHA10,3.0.0-ALPHA11,3.0.0-ALPHA12,3.0.0] +api: [3.0.0] website: "https://github.com/genboy/Festival" commands: fe: diff --git a/resources/en.json b/resources/en.json index f4a470d..23e1825 100644 --- a/resources/en.json +++ b/resources/en.json @@ -39,7 +39,7 @@ "area-list" : "Area list", "players-in-area": "players in area", "area-whitelist": "whitelist", - "area-no-commands": "no commands attachted", + "area-no-commands": "no commands attached", "player-has-been-whitelisted": "has been whitelisted in area", "player-allready-whitelisted": "is allready whitelisted in area", "player-has-been-unwhitelisted": "has been unwhitelisted from area", diff --git a/resources/nl.json b/resources/nl.json index af8e580..8b47c75 100644 --- a/resources/nl.json +++ b/resources/nl.json @@ -92,7 +92,7 @@ "set-to": "aangepast naar", "for-area": "voor gebied", - "all-players-are-god": "Alle spelers zajin in god-mode in dit gebied!", + "all-players-are-god": "Alle spelers hebben god-mode in dit gebied!", "no-pvp-area": "Dit is geen PVP area!", "no-flight-area": "Vliegen is hier niet toegstaan!", "flight-area": "Vliegen is hier toegestaand!", diff --git a/src/genboy/Festival/Main.php b/src/genboy/Festival/Main.php index c54ff85..7a89eb6 100644 --- a/src/genboy/Festival/Main.php +++ b/src/genboy/Festival/Main.php @@ -1186,10 +1186,10 @@ public function onCommand(CommandSender $sender, Command $cmd, string $label, ar $this->saveAreas(); $o = TextFormat::GREEN . Language::translate("cmd-id"). ' '.$cid.' edited'; }else{ - $o = TextFormat::RED .Language::translate("cmd-id"). ' '.$cid.' '. Language::tranlate("cannot-be-found") .' ( /fe command list)'; + $o = TextFormat::RED .Language::translate("cmd-id"). ' '.$cid.' '. Language::translate("cannot-be-found") .' ( /fe command list)'; } }else{ - $o = TextFormat::RED .Language::tranlate("cmd-specify-id-and-command-usage"); + $o = TextFormat::RED .Language::translate("cmd-specify-id-and-command-usage"); } break; @@ -1265,11 +1265,33 @@ public function onCommand(CommandSender $sender, Command $cmd, string $label, ar */ public function onJoin(PlayerJoinEvent $event){ $player = $event->getPlayer(); + $playername = strtolower($player->getName()); $level = $player->getLevel(); // $this->getServer()->getDefaultLevel(); - $this->areaTitles[strtolower($player->getName())] = []; + + $this->areaTitles[$playername] = []; + $this->inArea[$playername] = []; $this->checkAreaTitles( $player, $level ); } + + + /** onQuit + * @param Event $event + * @return bool + */ + public function onQuit(PlayerQuitEvent $event){ + + $playerName = strtolower($event->getPlayer()->getName()); + $lvl = $event->getPlayer()->getLevel()->getName(); + unset($this->inArea[$playerName]); + + foreach($this->areas as $area){ + $this->hideAreaTitle( $event->getPlayer(), $event->getPlayer()->getPosition()->getLevel(), $area ); + } + unset( $this->areaTitles[$playerName] ); + + } + /** levelChange * change Area Titles for Player ( FloatingTextParticle ) * @param EntityLevelChangeEvent $event @@ -1442,16 +1464,40 @@ public function onBlockUpdate( BlockUpdateEvent $event ): void{ // BlockUpdateEv // kill fire - or lava - flowing_lava 10, lava 11 , Bucket item id 325 $f = true; - $aid = $this->getServer()->getLevelByName( $levelname )->getBlockIdAt($block->x, $block->y + 1, $block->z); + $aid = $block->getLevel()->getBlockIdAt($block->x, $block->y + 1, $block->z); + if( $aid == 51 || $aid == 10 || $aid == 11 ){ // is fire/lava above if( !$this->canBurn( $position ) ){ // is fire not allowed? // Block::FIRE - $this->getServer()->getLevelByName( $levelname )->setBlockIdAt( $block->x, $block->y + 1, $block->z, 0); + $block->getLevel()->setBlock(new Vector3($block->x, $block->y + 1, $block->z), Block::get(0,0) ); // $block->getLevel()->setBlockIdAt( $block->x, $block->y + 1, $block->z, 0 ); //Block::AIR //$msg = TextFormat::RED . "Fire removed from " . $block->getName() . "(". $block->getID() . ") at [x=" . round($block->x) . " y=" . round($block->y) . " z=" . round($block->z) . "]"; //$this->getLogger()->info( $msg ); } } } + + /** onBlockBurn + * BlockBurnEvent + * @param BlockUpdateEvent $event + * @return void + + // Should check BlockBurnEvent .. + // https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/event/block/BlockBurnEvent.php + + public function onBlockBurn( BlockBurnEvent $event ): void { // BlockBurnEvent + + $block = $event->getBlock(); + $position = new Position($block->getFloorX(), $block->getFloorY(), $block->getFloorZ(), $block->getLevel()); + $levelname = $block->getLevel()->getName(); + + if( !$this->canBurn( $position ) ){ // is fire not allowed? // Block::FIRE + $event->setCancelled(); + } + + } + */ + + /* public function onPlayerBucketEvent( PlayerBucketEvent $event): void{ $block = $event->getBlockClicked(); @@ -1559,22 +1605,6 @@ public function Hunger(PlayerExhaustEvent $event){ } - /** onQuit - * @param Event $event - * @return bool - */ - public function onQuit(PlayerQuitEvent $event){ - - $playerName = strtolower($event->getPlayer()->getName()); - $lvl = $event->getPlayer()->getLevel()->getName(); - unset($this->inArea[$playerName]); - - foreach($this->areas as $area){ - $this->hideAreaTitle( $event->getPlayer(), $event->getPlayer()->getPosition()->getLevel(), $area ); - } - unset( $this->areaTitles[$playerName] ); - - } /** OUTBOUND ACTION */ @@ -1625,19 +1655,23 @@ public function canTouch(Player $player, Position $position) : bool{ if($t){ $o = false; } - foreach($this->inArea[$playername] as $areaname){ - if( isset($this->areaList[ $areaname ]) ){ - $area = $this->areaList[$areaname]; - if($area->getFlag("touch")){ - $o = false; - } - if(!$area->getFlag("touch") && $t){ - $o = true; - } - if($area->isWhitelisted($playername)){ - $o = true; + if( isset( $this->inArea[$playername] ) && is_array( $this->inArea[$playername] ) ){ + foreach($this->inArea[$playername] as $areaname){ + if( isset($this->areaList[ $areaname ]) ){ + $area = $this->areaList[$areaname]; + if($area->getFlag("touch")){ + $o = false; + } + if(!$area->getFlag("touch") && $t){ + $o = true; + } + if($area->isWhitelisted($playername)){ + $o = true; + } } } + }else{ + $o = false; } return $o; } @@ -1693,19 +1727,23 @@ public function canGetHurt(Entity $entity) : bool{ $o = false; } $playername = strtolower($entity->getName()); - foreach($this->inArea[$playername] as $areaname){ - if( isset($this->areaList[ $areaname ]) ){ - $area = $this->areaList[ $areaname ]; - if($area->getFlag("god")){ - $o = false; - } - if(!$area->getFlag("god") && $g ){ - $o = true; - } - if($area->isWhitelisted($playername)){ - $o = false; + if( isset( $this->inArea[$playername] ) && is_array( $this->inArea[$playername] ) ){ + foreach($this->inArea[$playername] as $areaname){ + if( isset($this->areaList[ $areaname ]) ){ + $area = $this->areaList[ $areaname ]; + if($area->getFlag("god")){ + $o = false; + } + if(!$area->getFlag("god") && $g ){ + $o = true; + } + if($area->isWhitelisted($playername)){ + $o = false; + } } } + }else{ + $o = false; } } return $o; @@ -1724,19 +1762,23 @@ public function hasFallDamage(Entity $entity) : bool{ $o = false; } $playername = strtolower($entity->getName()); - foreach($this->inArea[$playername] as $areaname){ - if( isset($this->areaList[ $areaname ]) ){ - $area = $this->areaList[$areaname]; - if($area->getFlag("falldamage")){ - $o = false; - } - if(!$area->getFlag("falldamage") && $f){ - $o = true; - } - if($area->isWhitelisted($playername)){ - $o = false; + if( isset( $this->inArea[$playername] ) && is_array( $this->inArea[$playername] ) ){ + foreach($this->inArea[$playername] as $areaname){ + if( isset($this->areaList[ $areaname ]) ){ + $area = $this->areaList[$areaname]; + if($area->getFlag("falldamage")){ + $o = false; + } + if(!$area->getFlag("falldamage") && $f){ + $o = true; + } + if($area->isWhitelisted($playername)){ + $o = false; + } } } + }else{ + $o = false; } } return $o; @@ -1778,9 +1820,9 @@ public function canPVP(EntityDamageEvent $ev) : bool{ $player = $ev->getDamager(); if( $this->skippTime( 2, strtolower($player->getName()) ) ){ if( $god ){ - $this->areaMessage( Language::tranlate("all-players-are-god"), $player ); + $this->areaMessage( Language::translate("all-players-are-god"), $player ); }else{ - $this->areaMessage( Language::tranlate("no-pvp-area"), $player ); + $this->areaMessage( Language::translate("no-pvp-area"), $player ); } } } @@ -1796,13 +1838,20 @@ public function canDamage(EntityDamageEvent $ev) : bool{ if($ev->getEntity() instanceof Player){ $player = $ev->getEntity(); $playerName = strtolower($player->getName()); - if( !$this->canGetHurt( $player ) || !$this->canBurn( $player->getPosition() )){ + if( !$this->canGetHurt( $player ) ){ if( $player->isOnFire() ){ $player->extinguish(); // 1.0.7-dev } $ev->setCancelled(); return false; } + if( !$this->canBurn( $player->getPosition() )){ + if( $player->isOnFire() ){ + $player->extinguish(); // 1.0.7-dev + $ev->setCancelled(); + return false; + } + } if(!$this->canPVP($ev)){ // v 1.0.6-13 $ev->setCancelled(); return false; @@ -1832,26 +1881,30 @@ public function checkPlayerFlying(Player $player){ if( $f ){ $fly = false; // flag default } - - foreach($this->inArea[$playername] as $areaname){ - if( isset($this->areaList[ $areaname ]) ){ - $area = $this->areaList[$areaname]; - if( $area->getFlag("flight") && !$area->isWhitelisted( $playername ) ){ - $fly = false; // flag area - } - if(!$area->getFlag("flight") && $f){ - $fly = true; - } - if( !$area->getFlag("msg") ){ - $sendmsg = true; - } - if( $area->getFlag("falldamage") ){ - $falldamage = true; + if( isset( $this->inArea[$playername] ) && is_array( $this->inArea[$playername] ) ){ + foreach($this->inArea[$playername] as $areaname){ + if( isset($this->areaList[ $areaname ]) ){ + $area = $this->areaList[$areaname]; + if( $area->getFlag("flight") && !$area->isWhitelisted( $playername ) ){ + $fly = false; // flag area + } + if(!$area->getFlag("flight") && $f){ + $fly = true; + } + if( !$area->getFlag("msg") ){ + $sendmsg = true; + } + if( $area->getFlag("falldamage") ){ + $falldamage = true; + } } } + }else{ + $fly = false; // flag default } // ! if( $player->isOp() ){ - if( $player->hasPermission("festival") || $player->hasPermission("festival.access") ){ + // Survival Mode = 0, Creative Mode = 1, Adventure Mode = 2, Spectator Mode = 4 + if( $player->hasPermission("festival") || $player->hasPermission("festival.access") || $player->getGamemode() === 1 ){ $fly = true; $player->setAllowFlight(true); return $fly; @@ -1894,16 +1947,18 @@ public function canEntitySpawn( Entity $e ): bool{ || $e instanceof ItemEntity || $e instanceof Projectile || $e instanceof FloatingTextParticle + + //|| $e instanceof mysterybox\entity\MysterySkull // https://github.com/CubePM/MysteryBox/blob/master/src/mysterybox/entity/MysterySkull.php ){ return $o; // might be allowed to spawn under different flag } $nm = ''; // - if( null !== $e->getName() ){ + if( method_exists($e,'getName') && null !== $e->getName() ){ $nm = $e instanceof Item ? $e->getItem()->getName() : $e->getName(); } $pos = false; - if( null !== $e->getPosition() ){ + if( method_exists($e,'getPosition') && null !== $e->getPosition() ){ $pos = $e->getPosition(); } @@ -1972,21 +2027,24 @@ public function canUseEffects( Player $player ) : bool{ $o = false; } - foreach($this->inArea[$playername] as $areaname){ - if( isset($this->areaList[ $areaname ]) ){ - $area = $this->areaList[$areaname]; - if($area->getFlag("effects")){ - $o = false; - } - if(!$area->getFlag("effects") && $e){ - $o = true; - } - if( $area->isWhitelisted( $playername ) ){ - $o = true; + if( isset( $this->inArea[$playername] ) && is_array( $this->inArea[$playername] ) ){ + foreach($this->inArea[$playername] as $areaname){ + if( isset($this->areaList[ $areaname ]) ){ + $area = $this->areaList[$areaname]; + if($area->getFlag("effects")){ + $o = false; + } + if(!$area->getFlag("effects") && $e){ + $o = true; + } + if( $area->isWhitelisted( $playername ) ){ + $o = true; + } } } + }else{ + $o = false; } - return $o; } @@ -2005,19 +2063,24 @@ public function canDrop(Player $player, Position $position) : bool{ $o = false; } $playername = strtolower($player->getName()); - foreach($this->inArea[$playername] as $areaname){ - if( isset($this->areaList[ $areaname ]) ){ - $area = $this->areaList[$areaname]; - if($area->getFlag("drop")){ - $o = false; - } - if(!$area->getFlag("drop") && $d){ - $o = true; - } - if($area->isWhitelisted($playername)){ - $o = true; + + if( isset( $this->inArea[$playername] ) && is_array( $this->inArea[$playername] ) ){ + foreach($this->inArea[$playername] as $areaname){ + if( isset($this->areaList[ $areaname ]) ){ + $area = $this->areaList[$areaname]; + if($area->getFlag("drop")){ + $o = false; + } + if(!$area->getFlag("drop") && $d){ + $o = true; + } + if($area->isWhitelisted($playername)){ + $o = true; + } } } + }else{ + $o = false; } return $o; } @@ -2096,22 +2159,27 @@ public function canUseTNT(Player $player, Position $position) : bool{ $o = false; } $playername = strtolower($player->getName()); - foreach($this->inArea[$playername] as $areaname){ - if( isset($this->areaList[ $areaname ]) ){ - $area = $this->areaList[$areaname]; - //if( $area->contains( $position, $position->getLevel()->getName() ) ){} + if( isset( $this->inArea[$playername] ) && is_array( $this->inArea[$playername] ) ){ + foreach($this->inArea[$playername] as $areaname){ + if( isset($this->areaList[ $areaname ]) ){ + $area = $this->areaList[$areaname]; - if($area->getFlag("tnt")){ - $o = false; - } - if(!$area->getFlag("tnt") && $d){ - $o = true; - } - if($area->isWhitelisted($playername)){ - $o = true; + //if( $area->contains( $position, $position->getLevel()->getName() ) ){} + + if($area->getFlag("tnt")){ + $o = false; + } + if(!$area->getFlag("tnt") && $d){ + $o = true; + } + if($area->isWhitelisted($playername)){ + $o = true; + } } } + }else{ + $o = false; } return $o; } @@ -2164,24 +2232,28 @@ public function canShoot( Player $player ) : bool{ $o = false; } - foreach($this->inArea[$playername] as $areaname){ - if( isset($this->areaList[ $areaname ]) ){ - $area = $this->areaList[$areaname]; - if($area->getFlag("shoot")){ - $o = false; - } - if(!$area->getFlag("shoot") && $s){ - $o = true; - } - if($area->isWhitelisted($playername)){ - $o = true; - } - if( $area->getFlag("msg") ){ - $m = false; + if( isset( $this->inArea[$playername] ) && is_array( $this->inArea[$playername] ) ){ + foreach($this->inArea[$playername] as $areaname){ + if( isset($this->areaList[ $areaname ]) ){ + $area = $this->areaList[$areaname]; + if($area->getFlag("shoot")){ + $o = false; + } + if(!$area->getFlag("shoot") && $s){ + $o = true; + } + if($area->isWhitelisted($playername)){ + $o = true; + } + if( $area->getFlag("msg") ){ + $m = false; + } } } + }else{ + $o = false; + $m = true; } - if( $m && !$o ){ // 'ínline' message method $msg = TextFormat::RED . "NO Shooting here!"; $player->areaMessage( $msg ); @@ -2235,19 +2307,23 @@ public function canHunger( PlayerExhaustEvent $event ): bool{ if ($h) { $o = false; } - foreach($this->inArea[$playername] as $areaname){ - if( isset($this->areaList[ $areaname ]) ){ - $area = $this->areaList[$areaname]; - if ($area->getFlag("hunger")) { - $o = false; - } - if(!$area->getFlag("hunger") && $h){ - $o = true; - } - if($area->isWhitelisted($playername)){ - $o = false; + if( isset( $this->inArea[$playername] ) && is_array( $this->inArea[$playername] ) ){ + foreach($this->inArea[$playername] as $areaname){ + if( isset($this->areaList[ $areaname ]) ){ + $area = $this->areaList[$areaname]; + if ($area->getFlag("hunger")) { + $o = false; + } + if(!$area->getFlag("hunger") && $h){ + $o = true; + } + if($area->isWhitelisted($playername)){ + $o = false; + } } } + }else{ + $o = false; } return $o; } @@ -2340,6 +2416,7 @@ public function enterArea(Area $area, PlayerMoveEvent $ev): void{ } } $playerName = strtolower( $player->getName() ); + $this->inArea[$playerName][] = strtolower( $area->getName() ); // player area's // effects check @@ -2720,18 +2797,15 @@ public function saveAreas() : void{ * makes it easy to find Festival console output fast */ public function codeSigned(){ - $this->getLogger()->info( " " ); - $this->getLogger()->info( " |~ " ); - $this->getLogger()->info( " .___---^^^ ^^^---___. " ); - $this->getLogger()->info( " ___|~__/_____________________\___|~__ " ); - $this->getLogger()->info( " /_______\ ._____. /_______\ " ); - $this->getLogger()->info( " / |\ / | F | \ |\ \ " ); - $this->getLogger()->info( "------------------'-----'-------------------" ); - $this->getLogger()->info( " ____ ___ _ |_| _ " ); - $this->getLogger()->info( " | __|| -_| ___ | |_ | | _ _ ___ | | " ); - $this->getLogger()->info( " | _| |___||_ -|| _ | | | | || .'|| | " ); - $this->getLogger()->info( " |_| |___||_| |_| \__/ |__,||_| " ); - $this->getLogger()->info( " GENBOY 2018 " ); + + + $this->getLogger()->info( "~~__.__~~" ); + $this->getLogger()->info( "..-/-\-.." ); + $this->getLogger()->info( "by-Genboy" ); + $this->getLogger()->info( "--__|~_--" ); + $this->getLogger()->info( "-/_____\-" ); + $this->getLogger()->info( "./..|\.\." ); + } }