Skip to content

Commit

Permalink
Merge pull request #301 from genboy/development
Browse files Browse the repository at this point in the history
Development Fix losing the compass
  • Loading branch information
genboy authored Mar 30, 2021
2 parents 8337c3a + abcd452 commit 0520f93
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 135 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Festival
author: Genboy
version: 2.1.2.1
version: 2.1.2.3
main: genboy\Festival\Festival
load: POSTWORLD
api: [3.0.0]
Expand Down
75 changes: 34 additions & 41 deletions src/genboy/Festival/Area.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@ class Area{
/** @var int */
public $priority;
/** @var Vector3 */
private $pos1;
public $pos1;
/** @var Vector3 */
private $pos2;
public $pos2;
/** @var int */
private $radius;
public $radius;
/** @var int */
public $top;
/** @var int */
public $bottom;
/** @var string */
private $levelName;
public $levelName;
/** @var string[] */
private $whitelist;
public $whitelist;
/** @var string[] */
public $commands;
/** @var string[] */
public $events;
/** @var Main */
private $plugin;
/** @var Festival */
public $plugin;

public function __construct(string $name, string $desc, int $priority, array $flags, Vector3 $pos1, Vector3 $pos2, int $radius, int $top, int $bottom, string $levelName, array $whitelist, array $commands, array $events, Festival $plugin){
$this->name = $name;
Expand All @@ -61,22 +61,22 @@ public function __construct(string $name, string $desc, int $priority, array $fl
}

/**
* @return string
* @return str
*/
public function getName() : string {
return $this->name;
}

/**
* @param string
* @param str
*/
public function setName( $str) : string {
public function setName( $str ) : string {
$this->name = $str;
return $this->name;
}

/**
* @return string
* @return str
*/
public function getDesc() : string {
return $this->desc;
Expand Down Expand Up @@ -104,7 +104,7 @@ public function setPriority( $int ) : int{
public function getPriority() : int{
return $this->priority;
}

/**
* @return Vector3
*/
Expand Down Expand Up @@ -136,9 +136,9 @@ public function getRadius() : int{
/**
* @param int
*/
public function setTop( $int ) : int{
public function setTop( int $int ) : int{
$this->top = $int;
return $int;
return $int;
}
/**
* @return int
Expand Down Expand Up @@ -234,7 +234,7 @@ public function getCommand(string $id) : bool{
*/
public function getEvents() : array{

$arr = [];
$arr = [];
if(is_array($this->events)){
foreach($this->events as $nm => $ids){
if( $ids != '' && $ids != ' ' && $ids != 'null' ){
Expand Down Expand Up @@ -266,7 +266,6 @@ public function contains(Vector3 $pos, string $levelName) : bool{

// in sphere area
$r = $this->radius;

if( $this->getTop() > 0 || $this->getBottom() > 0){

$cy1 = $this->pos1->getY() + $r;
Expand All @@ -281,32 +280,23 @@ public function contains(Vector3 $pos, string $levelName) : bool{
}else if( $this->getBottom() > 0 ){
$cy2 = $cy2 - $this->getBottom();
}

$distance2d = $this->plugin->get_flat_distance($this->pos1, $pos);
if( $distance2d <= $r && $cy1 >= $pos->getY() && $cy2 <= $pos->getY() ){
return true; // point outside radius + y height
}else{
return false; // point outside radius + -y height
}

}else{

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

}
return false; // point outside radius

}else if( isset( $this->pos1 ) && isset( $this->pos2 ) ){
// in cube area

// if scale limit $cy1,$cy2 > 0

$cy1 = max($this->pos1->getY(), $this->pos2->getY());
if( $this->getTop() == 9999 ){
$cy1 = 999999;
Expand All @@ -320,15 +310,17 @@ public function contains(Vector3 $pos, string $levelName) : bool{
$cy2 = min( $this->pos2->getY(), $this->pos1->getY()) - $this->getBottom();
}

// else
return ((min($this->pos1->getX(), $this->pos2->getX()) <= $pos->getX())
if((min($this->pos1->getX(), $this->pos2->getX()) <= $pos->getX())
&& (max($this->pos1->getX(), $this->pos2->getX()) >= $pos->getX())
&& ($cy2 <= $pos->getY()) //&& (min($this->pos1->getY(), $this->pos2->getY()) <= $pos->getY())
&& ($cy1 >= $pos->getY())//&& (max($this->pos1->getY(), $this->pos2->getY()) >= $pos->getY())
&& (min($this->pos1->getZ(), $this->pos2->getZ()) <= $pos->getZ())
&& (max($this->pos1->getZ(), $this->pos2->getZ()) >= $pos->getZ())
&& strtolower( $this->levelName ) === strtolower( $levelName ) );
&& strtolower( $this->levelName ) === strtolower( $levelName ) ){
return true;
}
}
return false;

}

Expand Down Expand Up @@ -362,22 +354,19 @@ public function centerContains(Vector3 $pos, string $levelName) : bool{
$distance2d = $this->plugin->get_flat_distance($this->pos1, $pos);
if( $distance2d <= $r && $cy1 >= $pos->getY() && $cy2 <= $pos->getY() ){
return true; // point outside radius + y height
}else{
return false; // point outside radius + -y height
}
return false;

}else{

$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
if( $dis <= $r ){
return true; // point in radius
}
return false;

}
return false; // point outside radius + -y height

}else if( isset( $this->pos1 ) && isset( $this->pos2 ) ){

Expand All @@ -402,9 +391,13 @@ public function centerContains(Vector3 $pos, string $levelName) : bool{
$px = $pos->getX();
$py = $pos->getY();
$pz = $pos->getZ();
return( $px >= ($cx - 1) && $px <= ($cx + 1) && $pz >= ($cz - 1) && $pz <= ($cz + 1) && $py >= $cy2 && $py <= $cy1
&& strtolower( $this->levelName ) === strtolower( $levelName ) );
}
if( $px >= ($cx - 1) && $px <= ($cx + 1) && $pz >= ($cz - 1) && $pz <= ($cz + 1) && $py >= $cy2 && $py <= $cy1 && strtolower( $this->levelName ) === strtolower( $levelName ) ){
return true;
}
return false;

}
return false;

}

Expand Down
Loading

0 comments on commit 0520f93

Please sign in to comment.