Skip to content

Commit

Permalink
Merge pull request #169 from genboy/master
Browse files Browse the repository at this point in the history
Sphere extend adn moved to folder
  • Loading branch information
genboy committed May 28, 2019
2 parents f00d2ec + 1145974 commit c61defc
Show file tree
Hide file tree
Showing 13 changed files with 485 additions and 74 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
@@ -1,7 +1,7 @@
name: Festival
author: Genboy
version: 1.1.3
main: genboy\Festival\Main
main: genboy\Festival\Festival
load: POSTWORLD
api: [3.0.0]
website: "https://github.com/genboy/Festival"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 31 additions & 4 deletions src/genboy/Festival/Area.php
Expand Up @@ -37,7 +37,7 @@ class Area{
/** @var Main */
private $plugin;

public function __construct(string $name, string $desc, array $flags, Vector3 $pos1, Vector3 $pos2, int $radius, string $levelName, array $whitelist, array $commands, array $events, Main $plugin){
public function __construct(string $name, string $desc, array $flags, Vector3 $pos1, Vector3 $pos2, int $radius, string $levelName, array $whitelist, array $commands, array $events, Festival $plugin){
$this->name = strtolower($name);
$this->desc = $desc;
$this->flags = $flags;
Expand Down Expand Up @@ -194,13 +194,25 @@ public function contains(Vector3 $pos, string $levelName) : bool{
// check if area is sphere or cube (given radius)
if( isset( $this->radius ) && $this->radius > 0 && isset( $this->pos1 ) ){
// in sphere area
return ( $pos->getX() >= ( $this->pos1->getX() - $this->radius )
/* return ( $pos->getX() >= ( $this->pos1->getX() - $this->radius )
&& $pos->getX() <= ( $this->pos1->getX() + $this->radius )
&& $pos->getY() >= ( $this->pos1->getY() - $this->radius )
&& $pos->getY() <= ( $this->pos1->getY() + $this->radius )
&& $pos->getZ() >= ( $this->pos1->getZ() - $this->radius )
&& $pos->getZ() <= ( $this->pos1->getZ() + $this->radius )
&& strtolower( $this->levelName ) === strtolower( $levelName ) );
*/
$r = $this->radius;
$dis = $this->plugin->get_3d_distance($this->pos1, $pos);
if( $dis < $r ){
return true; //point in radius
}else if($dis == $r){
return true; // point is equal to radius
}else{
return false; // point outside radius
}


}else if( isset( $this->pos1 ) && isset( $this->pos2 ) ){
// in cube area
return ((min($this->pos1->getX(), $this->pos2->getX()) <= $pos->getX())
Expand All @@ -226,15 +238,29 @@ public function contains(Vector3 $pos, string $levelName) : bool{
*/
public function centerContains(Vector3 $pos, string $levelName) : bool{

if( isset( $this->radius ) && $this->radius > 1 && isset( $this->pos1 ) ){
// in sphere area center
if( isset( $this->radius ) && $this->radius > 0 && isset( $this->pos1 ) ){

/* in cube (not sphere) area center
return ( $pos->getX() >= ( $this->pos1->getX() - 2 )
&& $pos->getX() <= ( $this->pos1->getX() + 2 )
&& $pos->getY() >= ( $this->pos1->getY() - 2 )
&& $pos->getY() <= ( $this->pos1->getY() + 2 )
&& $pos->getZ() >= ( $this->pos1->getZ() - 2 )
&& $pos->getZ() <= ( $this->pos1->getZ() + 2 )
&& strtolower( $this->levelName ) === strtolower( $levelName ) );
*/
// Real sphere..

$r = 2; //$this->radius;
$dis = $this->plugin->get_3d_distance($this->pos1, $pos);
if( $dis < $r ){
return true; //point in radius
}else if($dis == $r){
return true; // point is equal to radius
}else{
return false; // point outside radius
}

}else if( isset( $this->pos1 ) && isset( $this->pos2 ) ){
// in cube area center
$cx = $this->pos2->getX() + ( ( $this->pos1->getX() - $this->pos2->getX() ) / 2 );
Expand Down Expand Up @@ -263,6 +289,7 @@ public function centerContains(Vector3 $pos, string $levelName) : bool{
*/
}


/**
* @param string $flag
* @return bool
Expand Down

0 comments on commit c61defc

Please sign in to comment.