Callbacks Structure Refactor

This commit is contained in:
kremsy 2017-04-13 19:14:23 +02:00
parent 7a7826b4b6
commit fce74ed928
15 changed files with 102 additions and 237 deletions

View File

@ -88,7 +88,21 @@ interface Callbacks {
const SM_ONSHOTDENY = "Shootmania.Event.OnShotDeny";
const SM_ONFALLDAMAGE = "Shootmania.Event.OnFallDamage";
const SM_ONCOMMAND = "Shootmania.Event.OnCommand";
//Shootmania.Event.OnPlayerRemoved Shootmania.Event.OnPlayerAdded not needed yet
/**
* Use the PlayerManager Callback in favour of this
*
* @see \ManiaControl\Players\PlayerManager::CB_PLAYERCONNECT
*/
const SM_ONPLAYERADDED = "Shootmania.Event.OnPlayerAdded";
/**
* Use the PlayerManager Callback in favour of this
*
* @see \ManiaControl\Players\PlayerManager::CB_PLAYERDISCONNECT
*/
const SM_ONPLAYERREMOVED = "Shootmania.Event.OnPlayerRemoved";
const SM_ONPLAYERREQUESTRESPAWN = "Shootmania.Event.OnPlayerRequestRespawn";
const SM_ONACTIONCUSTOMEVENT = "Shootmania.Event.OnActionCustomEvent";
const SM_ONACTIONEVENT = "Shootmania.Event.OnActionEvent";
@ -111,8 +125,21 @@ interface Callbacks {
const TM_ONEVENTDEFAULT = "Trackmania.Event.Default";
const TM_ONEVENTSTARTLINE = "Trackmania.Event.StartLine";
const TM_ONCOMMAND = "Trackmania.Event.OnCommand";
const TM_ONPLAYERADDED = "Trackmania.Event.OnPlayerAdded";
const TM_ONPLAYERREMOVED = "Trackmania.Event.OnPlayerRemoved";
/**
* Use the PlayerManager Callback in favour of this
*
* @see \ManiaControl\Players\PlayerManager::CB_PLAYERCONNECT
*/
const TM_ONPLAYERADDED = "Trackmania.Event.OnPlayerAdded";
/**
* Use the PlayerManager Callback in favour of this
*
* @see \ManiaControl\Players\PlayerManager::CB_PLAYERDISCONNECT
*/
const TM_ONPLAYERREMOVED = "Trackmania.Event.OnPlayerRemoved";
const TM_ONWAYPOINT = "Trackmania.Event.WayPoint";
const TM_ONGIVEUP = "Trackmania.Event.GiveUp";
const TM_ONRESPAWN = "Trackmania.Event.Respawn";

View File

@ -3,7 +3,7 @@
namespace ManiaControl\Callbacks;
use ManiaControl\Callbacks\Models\RecordCallback;
use ManiaControl\Callbacks\Structures\Common\StatusCallbackStructure;
use ManiaControl\Callbacks\Structures\Common\BasePlayerTimeStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnActionCustomEventStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnActionEvent;
use ManiaControl\Callbacks\Structures\ShootMania\OnArmorEmptyStructure;
@ -17,7 +17,7 @@ use ManiaControl\Callbacks\Structures\ShootMania\OnJoustReloadStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnJoustRoundResultsStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnJoustSelectedPlayersStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnNearMissStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnPlayerObjectStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnBasePlayerObjectTimeStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnPlayerRequestActionChange;
use ManiaControl\Callbacks\Structures\ShootMania\OnPlayerRequestRespawnStructure;
use ManiaControl\Callbacks\Structures\ShootMania\OnPlayerTriggersSectorStructure;
@ -87,6 +87,10 @@ class ShootManiaCallbacks implements CallbackListener {
case Callbacks::SM_ONEVENTDEFAULT:
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnDefaultEventStructure($this->maniaControl, $data));
break;
case Callbacks::SM_ONPLAYERADDED:
case Callbacks::SM_ONPLAYERREMOVED:
$this->maniaControl->getCallbackManager()->triggerCallback($name, new BasePlayerTimeStructure($this->maniaControl, $data));
break;
case Callbacks::SM_ONSHOOT:
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnShootStructure($this->maniaControl, $data));
break;
@ -118,13 +122,13 @@ class ShootManiaCallbacks implements CallbackListener {
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnActionEvent($this->maniaControl, $data));
break;
case Callbacks::SM_ONPLAYERTOUCHESOBJECT:
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnPlayerObjectStructure($this->maniaControl, $data));
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnBasePlayerObjectTimeStructure($this->maniaControl, $data));
break;
case Callbacks::SM_ONPLAYERTRIGGERSSECTOR:
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnPlayerTriggersSectorStructure($this->maniaControl, $data));
break;
case Callbacks::SM_ONPLAYERTHROWSOBJECT:
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnPlayerObjectStructure($this->maniaControl, $data));
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnBasePlayerObjectTimeStructure($this->maniaControl, $data));
break;
case Callbacks::SM_ONPLAYERREQUESTACTIONCHANGE:
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnPlayerRequestActionChange($this->maniaControl, $data));

View File

@ -0,0 +1,39 @@
<?php
namespace ManiaControl\Callbacks\Structures\Common;
use ManiaControl\ManiaControl;
/**
* Structure Class for the Player Added and Removed Structure Callback
*
* @api
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class BasePlayerTimeStructure extends BaseTimeStructure {
/**
* Construct a new On Hit Structure
*
* @param ManiaControl $maniaControl
* @param array $data
*/
public function __construct(ManiaControl $maniaControl, $data) {
parent::__construct($maniaControl, $data);
}
/**
* Gets the Player Object
*
* @api
* @return \ManiaControl\Players\Player
*/
public function getPlayer() {
return $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->login);
}
}

View File

@ -3,7 +3,7 @@
namespace ManiaControl\Callbacks\Structures\ShootMania;
use ManiaControl\Callbacks\Structures\Common\BaseStructure;
use ManiaControl\Callbacks\Structures\Common\BasePlayerTimeStructure;
use ManiaControl\ManiaControl;
/**
@ -14,9 +14,7 @@ use ManiaControl\ManiaControl;
* @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class OnPlayerObjectStructure extends BaseStructure {
private $time;
private $player;
class OnBasePlayerObjectTimeStructure extends BasePlayerTimeStructure {
private $objectId;
private $modelId;
private $modelName;
@ -30,32 +28,10 @@ class OnPlayerObjectStructure extends BaseStructure {
public function __construct(ManiaControl $maniaControl, $data) {
parent::__construct($maniaControl, $data);
$this->time = $this->getPlainJsonObject()->time;
$this->objectId = $this->getPlainJsonObject()->objectid;
$this->modelId = $this->getPlainJsonObject()->modelid;
$this->modelName = $this->getPlainJsonObject()->modelname;
$this->player = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->login);
}
/**
* Returns Server time when the event occured
*
* @api
* @return int
*/
public function getTime() {
return $this->time;
}
/**
* < Login of the player who touched the object
*
* @api
* @return \ManiaControl\Players\Player
*/
public function getPlayer() {
return $this->player;
}
/**

View File

@ -3,7 +3,7 @@
namespace ManiaControl\Callbacks\Structures\ShootMania;
use ManiaControl\Callbacks\Structures\Common\BaseStructure;
use ManiaControl\Callbacks\Structures\Common\BasePlayerTimeStructure;
use ManiaControl\ManiaControl;
/**
@ -14,9 +14,7 @@ use ManiaControl\ManiaControl;
* @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class OnPlayerRequestActionChange extends BaseStructure {
private $time;
private $player;
class OnPlayerRequestActionChange extends BasePlayerTimeStructure {
private $actionChange;
/**
@ -28,30 +26,7 @@ class OnPlayerRequestActionChange extends BaseStructure {
public function __construct(ManiaControl $maniaControl, $data) {
parent::__construct($maniaControl, $data);
$this->time = $this->getPlainJsonObject()->time;
$this->actionChange = $this->getPlainJsonObject()->actionchange;
$this->player = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->login);
}
/**
* Returns Server time when the event occured
*
* @api
* @return int
*/
public function getTime() {
return $this->time;
}
/**
* < player who requested a new action
*
* @api
* @return \ManiaControl\Players\Player
*/
public function getPlayer() {
return $this->player;
}
/**

View File

@ -3,6 +3,7 @@
namespace ManiaControl\Callbacks\Structures\ShootMania;
use ManiaControl\Callbacks\Structures\Common\BasePlayerTimeStructure;
use ManiaControl\Callbacks\Structures\Common\BaseStructure;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
@ -15,44 +16,5 @@ use ManiaControl\Players\Player;
* @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class OnPlayerRequestRespawnStructure extends BaseStructure {
private $time;
/**
* @var Player $player
*/
private $player;
/**
* OnPlayerRequestRespawnStructure constructor.
*
* @param \ManiaControl\ManiaControl $maniaControl
* @param $data
*/
public function __construct(ManiaControl $maniaControl, $data) {
parent::__construct($maniaControl, $data);
$this->time = $this->getPlainJsonObject()->time;
$this->player = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->login);
}
/**
* Returns the Time the Event Happened
*
* @api
* @return int
*/
public function getTime() {
return $this->time;
}
/**
* Gets the Player
*
* @api
* @return \ManiaControl\Players\Player
*/
public function getPlayer() {
return $this->player;
}
class OnPlayerRequestRespawnStructure extends BasePlayerTimeStructure {
}

View File

@ -3,7 +3,7 @@
namespace ManiaControl\Callbacks\Structures\ShootMania;
use ManiaControl\Callbacks\Structures\Common\BaseStructure;
use ManiaControl\Callbacks\Structures\Common\BasePlayerTimeStructure;
use ManiaControl\ManiaControl;
/**
@ -14,9 +14,7 @@ use ManiaControl\ManiaControl;
* @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class OnPlayerTriggersSectorStructure extends BaseStructure {
private $time;
private $player;
class OnPlayerTriggersSectorStructure extends BasePlayerTimeStructure {
private $sectorId;
/**
@ -28,30 +26,8 @@ class OnPlayerTriggersSectorStructure extends BaseStructure {
public function __construct(ManiaControl $maniaControl, $data) {
parent::__construct($maniaControl, $data);
$this->time = $this->getPlainJsonObject()->time;
$this->sectorId = $this->getPlainJsonObject()->sectorid;
$this->player = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->login);
}
/**
* Returns Server time when the event occured
*
* @api
* @return int
*/
public function getTime() {
return $this->time;
}
/**
* < player who touched the object
*
* @api
* @return \ManiaControl\Players\Player
*/
public function getPlayer() {
return $this->player;
}
/**

View File

@ -4,6 +4,7 @@ namespace ManiaControl\Callbacks\Structures\ShootMania;
use ManiaControl\Callbacks\Structures\Common\BaseStructure;
use ManiaControl\Callbacks\Structures\Common\BaseTimeStructure;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
@ -15,8 +16,7 @@ use ManiaControl\Players\Player;
* @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class OnShootStructure extends BaseStructure {
public $time;
class OnShootStructure extends BaseTimeStructure {
public $weapon;
/**
* @var Player $shooter
@ -26,21 +26,10 @@ class OnShootStructure extends BaseStructure {
public function __construct(ManiaControl $maniaControl, $data) {
parent::__construct($maniaControl, $data);
$this->time = $this->getPlainJsonObject()->time;
$this->weapon = $this->getPlainJsonObject()->weapon;
$this->shooterLogin = $this->getPlainJsonObject()->shooter;
}
/**
* Gets the Time the event Happened
*
* @api
* @return int
*/
public function getTime() {
return $this->time;
}
/**
* Gets the Weapon
*

View File

@ -4,6 +4,7 @@ namespace ManiaControl\Callbacks\Structures\ShootMania;
use ManiaControl\Callbacks\Structures\Common\BaseStructure;
use ManiaControl\Callbacks\Structures\Common\BaseTimeStructure;
use ManiaControl\ManiaControl;
@ -15,8 +16,7 @@ use ManiaControl\ManiaControl;
* @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class OnShotDenyStructure extends BaseStructure {
private $time;
class OnShotDenyStructure extends BaseTimeStructure {
private $shooterWeapon;
private $victimWeapon;
@ -33,7 +33,6 @@ class OnShotDenyStructure extends BaseStructure {
parent::__construct($maniaControl, $data);
$jsonObj = $this->getPlainJsonObject();
$this->time = $jsonObj->time;
$this->shooterWeapon = $jsonObj->victim;
$this->victimWeapon = $jsonObj->damage;
@ -41,17 +40,6 @@ class OnShotDenyStructure extends BaseStructure {
$this->victim = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->victim);
}
/**
* ServerTime The Event Happened //TODO add Trait for the Time Property
*
* @api
* @return int
*/
public function getTime() {
return $this->time;
}
/**
* Gets the Shooter Player
*

View File

@ -4,6 +4,7 @@ namespace ManiaControl\Callbacks\Structures\TrackMania;
use ManiaControl\Callbacks\Structures\Common\BaseStructure;
use ManiaControl\Callbacks\Structures\Common\BaseTimeStructure;
use ManiaControl\ManiaControl;
//TODO make a common structure between shootmania and this and extend it
/**
@ -14,8 +15,7 @@ use ManiaControl\ManiaControl;
* @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class OnCommandStructure extends BaseStructure {
private $time;
class OnCommandStructure extends BaseTimeStructure {
private $name;
private $value;
@ -28,20 +28,10 @@ class OnCommandStructure extends BaseStructure {
public function __construct(ManiaControl $maniaControl, $data) {
parent::__construct($maniaControl, $data);
$this->time = $this->getPlainJsonObject()->time;
$this->name = $this->getPlainJsonObject()->name;
$this->value = $this->getPlainJsonObject()->value;
}
/**
* < Server time when the event occured
*
* @api
* @return int
*/
public function getTime() {
return $this->time;
}
/**
* < Name of the command

View File

@ -4,6 +4,7 @@ namespace ManiaControl\Callbacks\Structures\TrackMania;
use ManiaControl\Callbacks\Structures\Common\BaseStructure;
use ManiaControl\Callbacks\Structures\Common\BaseTimeStructure;
use ManiaControl\ManiaControl;
/**
@ -13,8 +14,7 @@ use ManiaControl\ManiaControl;
* @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class OnDefaultEventStructure extends BaseStructure {
private $time;
class OnDefaultEventStructure extends BaseTimeStructure {
private $type;
/**
@ -26,22 +26,14 @@ class OnDefaultEventStructure extends BaseStructure {
public function __construct(ManiaControl $maniaControl, $data) {
parent::__construct($maniaControl, $data);
$this->time = $this->getPlainJsonObject()->time;
$this->type = $this->getPlainJsonObject()->type;
}
/**
* Returns Server time when the event occured
*
* @return int
*/
public function getTime() {
return $this->time;
}
/**
* Returns the type of event
*
* @api
* @return string
*/
public function getType() {

View File

@ -3,8 +3,7 @@
namespace ManiaControl\Callbacks\Structures\TrackMania;
use ManiaControl\Callbacks\Structures\Common\BaseStructure;
use ManiaControl\ManiaControl;
use ManiaControl\Callbacks\Structures\Common\BasePlayerTimeStructure;
/**
* Structure Class for the EventStartLine Structure Callback
@ -14,34 +13,5 @@ use ManiaControl\ManiaControl;
* @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class OnEventStartLineStructure extends BaseStructure {
private $time;
private $player;
public function __construct(ManiaControl $maniaControl, $data) {
parent::__construct($maniaControl, $data);
$this->time = $this->getPlainJsonObject()->time;
$this->player = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->login);
}
/**
* Returns Server time when the event occured
*
* @api
* @return int
*/
public function getTime() {
return $this->time;
}
/**
* < player who triggered the action
*
* @api
* @return \ManiaControl\Players\Player
*/
public function getPlayer() {
return $this->player;
}
class OnEventStartLineStructure extends BasePlayerTimeStructure {
}

View File

@ -4,7 +4,7 @@ namespace ManiaControl\Callbacks\Structures\TrackMania;
use ManiaControl\Callbacks\Models\RecordCallback;
use ManiaControl\Callbacks\Structures\Common\BaseStructure;
use ManiaControl\Callbacks\Structures\Common\BasePlayerTimeStructure;
use ManiaControl\ManiaControl;
use ManiaControl\Utils\Formatter;
@ -16,9 +16,7 @@ use ManiaControl\Utils\Formatter;
* @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class OnEventWayPointStructure extends BaseStructure {
private $time;
private $player;
class OnEventWayPointStructure extends BasePlayerTimeStructure {
private $racetime;
private $laptime;
private $stuntsscore;
@ -39,8 +37,6 @@ class OnEventWayPointStructure extends BaseStructure {
public function __construct(ManiaControl $maniaControl, $data) {
parent::__construct($maniaControl, $data);
$this->time = $this->getPlainJsonObject()->time;
$this->player = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->login);
$this->racetime = (int) $this->getPlainJsonObject()->racetime;
$this->laptime = (int) $this->getPlainJsonObject()->laptime;
$this->stuntsscore = $this->getPlainJsonObject()->stuntsscore;
@ -55,7 +51,7 @@ class OnEventWayPointStructure extends BaseStructure {
// Build callback
$wayPointCallback = new RecordCallback();
$wayPointCallback->rawCallback = $data;
$wayPointCallback->setPlayer($this->player);
$wayPointCallback->setPlayer($this->getPlayer());
$wayPointCallback->blockId = $this->blockid;
$wayPointCallback->time = $this->racetime;
$wayPointCallback->checkpoint = $this->checkpointinrace;
@ -77,25 +73,4 @@ class OnEventWayPointStructure extends BaseStructure {
}
$this->maniaControl->getCallbackManager()->triggerCallback($wayPointCallback);
}
/**
* Returns Server time when the event occured
*
* @api
* @return int
*/
public function getTime() {
return $this->time;
}
/**
* < player who triggered the action
*
* @api
* @return \ManiaControl\Players\Player
*/
public function getPlayer() {
return $this->player;
}
}

View File

@ -10,6 +10,7 @@ use ManiaControl\ManiaControl;
/**
* Structure Class for the Trackmania OnScores Structure Callback
*
* @api
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3

View File

@ -3,6 +3,7 @@
namespace ManiaControl\Callbacks;
use ManiaControl\Callbacks\Models\RecordCallback;
use ManiaControl\Callbacks\Structures\Common\BasePlayerTimeStructure;
use ManiaControl\Callbacks\Structures\TrackMania\OnCommandStructure;
use ManiaControl\Callbacks\Structures\TrackMania\OnDefaultEventStructure;
use ManiaControl\Callbacks\Structures\TrackMania\OnEventStartLineStructure;
@ -64,8 +65,8 @@ class TrackManiaCallbacks implements CallbackListener {
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnCommandStructure($this->maniaControl, $data));
break;
case Callbacks::TM_ONPLAYERADDED:
break;
case Callbacks::TM_ONPLAYERREMOVED:
$this->maniaControl->getCallbackManager()->triggerCallback($name, new BasePlayerTimeStructure($this->maniaControl, $data));
break;
case Callbacks::TM_ONWAYPOINT:
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnEventWayPointStructure($this->maniaControl, $data));