proper scoping to callback structures + usage Information Method

This commit is contained in:
kremsy 2017-03-26 12:42:20 +02:00
parent 4effad8f6d
commit de3bae9029
16 changed files with 172 additions and 132 deletions

View File

@ -3,8 +3,8 @@
namespace ManiaControl\Callbacks\Structures;
use ManiaControl\General\Dumpable;
use ManiaControl\ManiaControl;
use ReflectionClass;
/**
* Base Structure of all Callback Structures
@ -13,7 +13,7 @@ use ManiaControl\ManiaControl;
* @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
abstract class BaseStructure implements Dumpable {
abstract class BaseStructure {
/** @var ManiaControl $maniaControl */
protected $maniaControl;
private $plainJsonObject;
@ -31,10 +31,34 @@ abstract class BaseStructure implements Dumpable {
}
/**
* Var_Dump the Structure
* Gets Information about the Class, and a List of the Public Method
*/
public function dump() {
var_dump(json_decode(json_encode($this)));
var_dump("Class Name including Namespace: " . get_class($this));
public function getUsage() {
$reflection = new ReflectionClass(get_class($this));
echo $reflection->getDocComment();
echo "\nStructure Name of Class = " . get_class($this);
echo "\nMethods:\n";
$metody = $reflection->getMethods();
$methods = array_reverse($metody);
foreach ($methods as $key => $value) {
/** @var \ReflectionMethod $value */
//Don't print the Constructor
if ($value->isPublic() && $value->getName() != "__construct" && $value->getName() != "getUsage") {
echo "\n\n";
$txt = preg_replace('/\t/', '', $value->getDocComment());
echo $txt;
echo "\n \$result = " . $value->getName() . "();";
$parameters = $value->getParameters();
foreach ($parameters as $parameter) {
echo "\n" . $parameter;
}
echo "\n";
}
}
}
}

View File

@ -14,7 +14,7 @@ use ManiaControl\ManiaControl;
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class StartEndStructure extends BaseStructure {
public $count;
private $count;
public function __construct(ManiaControl $maniaControl, $data) {
parent::__construct($maniaControl, $data);
@ -23,7 +23,9 @@ class StartEndStructure extends BaseStructure {
}
/**
* @return mixed
* Get the Count of this Section
*
* @return int
*/
public function getCount() {
return $this->count;

View File

@ -14,7 +14,7 @@ use ManiaControl\ManiaControl;
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class StartServerStructure extends BaseStructure {
public $restarted;
private $restarted;
public function __construct(ManiaControl $maniaControl, $data) {
parent::__construct($maniaControl, $data);
@ -23,6 +23,8 @@ class StartServerStructure extends BaseStructure {
}
/**
* Flag if the Server got Restarted
*
* @return mixed
*/
public function getRestarted() {

View File

@ -10,14 +10,14 @@ class Landmark {
private $position = null;
/**
* @return mixed
* @return string
*/
public function getTag() {
return $this->tag;
}
/**
* @param mixed $tag
* @param string $tag
*/
public function setTag($tag) {
$this->tag = $tag;
@ -52,14 +52,14 @@ class Landmark {
}
/**
* @return mixed
* @return \ManiaControl\Callbacks\Structures\ShootMania\Models\Position
*/
public function getPosition() {
return $this->position;
}
/**
* @param mixed $position
* @param \ManiaControl\Callbacks\Structures\ShootMania\Models\Position $position
*/
public function setPosition(Position $position) {
$this->position = $position;

View File

@ -18,7 +18,7 @@ use ManiaControl\Players\Player;
*/
class OnCaptureStructure extends BaseStructure {
public $time;
private $time;
private $landMark;
private $playerArray = array();
@ -44,23 +44,17 @@ class OnCaptureStructure extends BaseStructure {
$this->landMark->setPosition($position);
}
/** Dumps the Object with some Information */
public function dump() {
var_dump($this->landMark);
parent::dump();
}
/**
* Get the logins
* Get the logins as Array
*
* @return array
* @return string[]
*/
public function getLoginArray() {
return $this->playerArray;
}
/**
* Get the players
* Get the Players as Player Array
*
* @return Player[]
*/
@ -76,16 +70,11 @@ class OnCaptureStructure extends BaseStructure {
}
/**
* @return LandMark
* Returns Information about the Captured Landmark
*
* @return \ManiaControl\Callbacks\Structures\ShootMania\Models\LandMark
*/
public function getLandMark() {
return $this->landMark;
}
/**
* @param mixed $landMark
*/
public function setLandMark(Landmark $landMark) {
$this->landMark = $landMark;
}
}

View File

@ -14,9 +14,9 @@ use ManiaControl\ManiaControl;
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class OnCommandStructure extends BaseStructure {
public $time;
public $name;
public $value;
private $time;
private $name;
private $value;
public function __construct(ManiaControl $maniaControl, $data) {
parent::__construct($maniaControl, $data);
@ -26,13 +26,9 @@ class OnCommandStructure extends BaseStructure {
$this->value = $this->getPlainJsonObject()->value;
}
/** Dumps the Object with some Information */
public function dump() {
parent::dump();
var_dump("With getShooter() you get a Player Object");
}
/**
* < Server time when the event occured
*
* @return int
*/
public function getTime() {
@ -40,14 +36,22 @@ class OnCommandStructure extends BaseStructure {
}
/**
* @return mixed
* < Name of the command
*
* @return string
*/
public function getName() {
return $this->name;
}
/**
* @return \ManiaControl\Players\Player
* < The value passed by the command
* "boolean": true,
* "integer": 123,
* "real": 123.456,
* "text": "an example value"
*
* @return mixed
*/
public function getValue() {
return $this->value;

View File

@ -14,8 +14,8 @@ use ManiaControl\ManiaControl;
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class OnDefaultEventStructure extends BaseStructure {
public $time;
public $type;
private $time;
private $type;
public function __construct(ManiaControl $maniaControl, $data) {
parent::__construct($maniaControl, $data);
@ -25,6 +25,8 @@ class OnDefaultEventStructure extends BaseStructure {
}
/**
* Returns Server time when the event occured
*
* @return int
*/
public function getTime() {
@ -32,6 +34,8 @@ class OnDefaultEventStructure extends BaseStructure {
}
/**
* Returns the type of event
*
* @return string
*/
public function getType() {

View File

@ -15,7 +15,7 @@ use ManiaControl\Players\Player;
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class OnFallDamageStructure extends BaseStructure {
public $time;
private $time;
/**
* @var Player $shooter
*/
@ -29,6 +29,8 @@ class OnFallDamageStructure extends BaseStructure {
}
/**
* < Server time when the event occured
*
* @return int
*/
public function getTime() {
@ -36,15 +38,12 @@ class OnFallDamageStructure extends BaseStructure {
}
/**
* < Player who fell
*
* @return Player
*/
public function getVictim() {
return $this->victim;
}
/** Dumps the Object with some Information */
public function dump() {
parent::dump();
var_dump("With getVictim() you get a Player Object");
}
}

View File

@ -17,15 +17,15 @@ use ManiaControl\Players\Player;
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class OnHitNearMissArmorEmptyStructure extends BaseStructure {
public $time;
public $weapon;
public $damage;
public $distance = 0; //Note no distance on the OnHit and ArmorEmpty yet
private $time;
private $weapon;
private $damage;
private $distance = 0; //Note no distance on the OnHit and ArmorEmpty yet
private $shooterPosition;
private $victimPosition;
protected $shooter;
protected $victim;
private $shooter;
private $victim;
//private $shooterPoints; (was in mp3)
//private $hitDistance; (was in mp3)
@ -43,7 +43,7 @@ class OnHitNearMissArmorEmptyStructure extends BaseStructure {
$jsonObj = $this->getPlainJsonObject();
$this->time = $jsonObj->time;
$this->weapon = $jsonObj->weapon;
$this->damage = $jsonObj->damage;
$this->damage = $jsonObj->damage; //TODO does only exist on onhit -> make baseclass
$this->shooterPosition = new Position();
$this->shooterPosition->setX($jsonObj->shooterposition->x);
@ -63,18 +63,9 @@ class OnHitNearMissArmorEmptyStructure extends BaseStructure {
$this->victim = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->victim);
}
/** Dumps the Object with some Information */
public function dump() {
var_dump("Dump of property Shooter Position");
var_dump($this->shooterPosition);
var_dump("Dump of property Victim Position");
var_dump($this->victimPosition);
parent::dump();
var_dump("With getShooter() you get a Player Object");
var_dump("With getVictim() you get a Player Object");
}
/**
* < Server time when the event occured
*
* @return int
*/
public function getTime() {
@ -82,6 +73,9 @@ class OnHitNearMissArmorEmptyStructure extends BaseStructure {
}
/**
* < Id of the weapon [1-Laser, 2-Rocket, 3-Nucleus, 5-Arrow]
*
* @see \ManiaControl\Callbacks\Structures\ShootMania\Models\Weapons
* @return int
*/
public function getWeapon() {
@ -89,6 +83,9 @@ class OnHitNearMissArmorEmptyStructure extends BaseStructure {
}
/**
* < Amount of Damage done by the hit (only on onHit)
* TODO base class and extend properties)
*
* @return int
*/
public function getDamage() {
@ -96,7 +93,7 @@ class OnHitNearMissArmorEmptyStructure extends BaseStructure {
}
/**
* TODO Position Object
* < Position of the Shooter at the time
*
* @return Position
*/
@ -105,15 +102,17 @@ class OnHitNearMissArmorEmptyStructure extends BaseStructure {
}
/**
* TODO Position Object
* < Position of the Victim at the time
*
* @return Position
* @return \ManiaControl\Callbacks\Structures\ShootMania\Models\Position
*/
public function getVictimPosition() {
return $this->victimPosition;
}
/**
* < Shooter Player
*
* @return Player
*/
public function getShooter() {
@ -121,6 +120,8 @@ class OnHitNearMissArmorEmptyStructure extends BaseStructure {
}
/**
* < Victim Player
*
* @return Player
*/
public function getVictim() {

View File

@ -15,9 +15,9 @@ use ManiaControl\Players\Player;
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class OnPlayerRequestRespawnStructure extends BaseStructure {
public $time;
private $time;
/**
* @var Player $shooter
* @var Player $player
*/
private $player;
@ -26,9 +26,13 @@ class OnPlayerRequestRespawnStructure extends BaseStructure {
$this->time = $this->getPlainJsonObject()->time;
$this->player = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->login);
$this->getUsage();
}
/**
* Returns the Time the Event Happened
*
* @return int
*/
public function getTime() {
@ -36,15 +40,11 @@ class OnPlayerRequestRespawnStructure extends BaseStructure {
}
/**
* @return Player
* Gets the Player
*
* @return \ManiaControl\Players\Player
*/
public function getPlayer() {
return $this->player;
}
/** Dumps the Object with some Information */
public function dump() {
parent::dump();
var_dump("With getPlayer() you get a Player Object");
}
}

View File

@ -6,7 +6,6 @@ namespace ManiaControl\Callbacks\Structures\ShootMania;
use ManiaControl\Callbacks\Structures\BaseStructure;
use ManiaControl\Callbacks\Structures\ShootMania\Models\TeamScore;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
/**
* Structure Class for the OnScores Structure Callback
@ -16,13 +15,13 @@ use ManiaControl\Players\Player;
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class OnScoresStructure extends BaseStructure {
public $responseId;
public $section;
public $useTeams;
public $winnerTeam;
public $winnerPlayer;
private $responseId;
private $section;
private $useTeams;
private $winnerTeam;
private $winnerPlayer;
private $teamScores = array();
public $players; //TODO implement
private $players; //TODO implement
//TODO test
public function __construct(ManiaControl $maniaControl, $data) {
@ -51,36 +50,36 @@ class OnScoresStructure extends BaseStructure {
//TODO implement player
}
/** Dumps the Object with some Information */
public function dump() {
parent::dump();
var_dump("With getWinnerPlayer() you get a Player Object");
var_dump($this->teamScores);
}
/**
* @return Player
* Get the Winner Player Object
*
* @return \ManiaControl\Players\Player
*/
public function getWinnerPlayer() {
return $this->winnerPlayer;
}
/**
* @return mixed
* Get the Response Id
*
* @return string
*/
public function getResponseId() {
return $this->responseId;
}
/**
* @return mixed
* < Current progress of the match. Can be "" | "EndRound" | "EndMap" | "EndMatch"
*
* @return string
*/
public function getSection() {
return $this->section;
}
/**
* Returns if the GameMode uses Teams or not
*
* @return boolean
*/
public function getUseTeams() {
@ -88,13 +87,17 @@ class OnScoresStructure extends BaseStructure {
}
/**
* Get the Winner Team Id
*
* @return int
*/
public function getWinnerTeam() {
public function getWinnerTeamId() {
return $this->winnerTeam;
}
/**
* Returns the TeamScores
*
* @return TeamScore[]
*/
public function getTeamScores() {
@ -102,6 +105,8 @@ class OnScoresStructure extends BaseStructure {
}
/**
* Get The Player Scores
*
* @return mixed
*/
public function getPlayers() {

View File

@ -29,6 +29,7 @@ class OnShootStructure extends BaseStructure {
$this->weapon = $this->getPlainJsonObject()->weapon;
$this->shooter = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->shooter);
}
/**

View File

@ -5,7 +5,6 @@ namespace ManiaControl\Callbacks\Structures\ShootMania;
use ManiaControl\Callbacks\Structures\BaseStructure;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
/**
@ -16,12 +15,12 @@ use ManiaControl\Players\Player;
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class OnShotDenyStructure extends BaseStructure {
public $time;
public $shooterWeapon;
public $victimWeapon;
private $time;
private $shooterWeapon;
private $victimWeapon;
protected $shooter;
protected $victim;
private $shooter;
private $victim;
/**
* Construct a new On Hit Structure
@ -41,14 +40,9 @@ class OnShotDenyStructure extends BaseStructure {
$this->victim = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->victim);
}
/** Dumps the Object with some Information */
public function dump() {
parent::dump();
var_dump("With getShooter() you get a Player Object");
var_dump("With getVictim() you get a Player Object");
}
/**
* ServerTime The Event Happened //TODO add Trait for the Time Property
*
* @return int
*/
public function getTime() {
@ -57,14 +51,18 @@ class OnShotDenyStructure extends BaseStructure {
/**
* @return Player
* Gets the Shooter Player
*
* @return \ManiaControl\Players\Player
*/
public function getShooter() {
return $this->shooter;
}
/**
* @return Player
* Gets the Victim Player
*
* @return \ManiaControl\Players\Player
*/
public function getVictim() {
return $this->victim;
@ -78,7 +76,10 @@ class OnShotDenyStructure extends BaseStructure {
}
/**
* @return mixed
* Get the Victim Weapon
*
* @see \ManiaControl\Callbacks\Structures\ShootMania\Models\Weapons
* @return int
*/
public function getVictimWeapon() {
return $this->victimWeapon;

View File

@ -14,9 +14,9 @@ use ManiaControl\ManiaControl;
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class OnCommandStructure extends BaseStructure {
public $time;
public $name;
public $value;
private $time;
private $name;
private $value;
public function __construct(ManiaControl $maniaControl, $data) {
parent::__construct($maniaControl, $data);
@ -26,13 +26,9 @@ class OnCommandStructure extends BaseStructure {
$this->value = $this->getPlainJsonObject()->value;
}
/** Dumps the Object with some Information */
public function dump() {
parent::dump();
var_dump("With getShooter() you get a Player Object");
}
/**
* < Server time when the event occured
*
* @return int
*/
public function getTime() {
@ -40,18 +36,24 @@ class OnCommandStructure extends BaseStructure {
}
/**
* @return mixed
* < Name of the command
*
* @return string
*/
public function getName() {
return $this->name;
}
/**
* @return \ManiaControl\Players\Player
* < The value passed by the command
* "boolean": true,
* "integer": 123,
* "real": 123.456,
* "text": "an example value"
*
* @return mixed
*/
public function getValue() {
return $this->value;
}
}

View File

@ -14,8 +14,8 @@ use ManiaControl\ManiaControl;
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class OnDefaultEventStructure extends BaseStructure {
public $time;
public $type;
private $time;
private $type;
public function __construct(ManiaControl $maniaControl, $data) {
parent::__construct($maniaControl, $data);
@ -25,6 +25,8 @@ class OnDefaultEventStructure extends BaseStructure {
}
/**
* Returns Server time when the event occured
*
* @return int
*/
public function getTime() {
@ -32,6 +34,8 @@ class OnDefaultEventStructure extends BaseStructure {
}
/**
* Returns the type of event
*
* @return string
*/
public function getType() {

View File

@ -29,6 +29,8 @@ class CallbacksListStructure extends BaseStructure {
$this->responseId = $this->getPlainJsonObject()->responseid;
$this->callbacks = $this->getPlainJsonObject()->callbacks;
$this->getUsage();
}
/**