fixed plugin unload method

This commit is contained in:
Steffen Schröder 2013-12-31 15:08:51 +01:00
parent fe3ca728bc
commit 07818a4ba9

View File

@ -19,13 +19,15 @@ class ChatMessagePlugin implements CommandListener, Plugin {
const PLUGIN_VERSION = 0.1;
const PLUGIN_NAME = 'ChatMessagePlugin';
const PLUGIN_AUTHOR = 'kremsy';
const SETTING_AFK_FORCE_SPEC = 'AFK command forces spec';
/**
* Private properties
*/
/** @var maniaControl $maniaControl */
/**
*
* @var maniaControl $maniaControl
*/
private $maniaControl = null;
/**
@ -34,7 +36,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
* @param \ManiaControl\ManiaControl $maniaControl
* @return bool
*/
public function load(ManiaControl $maniaControl){
public function load(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
$this->maniaControl->commandManager->registerCommandListener('me', $this, 'chat_me');
@ -65,72 +67,76 @@ class ChatMessagePlugin implements CommandListener, Plugin {
/**
* Unload the plugin and its resources
*/
public function unload(){
$this->maniaControl->callbackManager->unregisterCallbackListener($this);
public function unload() {
$this->maniaControl->commandManager->unregisterCommandListener($this);
unset($this->maniaControl);
}
/**
* Builds a chat message starting with the player's nickname, can used to express emotions
* @param array $chat
*
* @param array $chat
* @param Player $player
*/
public function chat_me(array $chat, Player $player){
$message = substr($chat[1][2],3);
public function chat_me(array $chat, Player $player) {
$message = substr($chat[1][2], 3);
$msg = '$<' . $player->nickname . '$>$s$i$fa0 ' . $message;
$msg = '$<' . $player->nickname . '$>$s$i$fa0 ' . $message;
$this->maniaControl->chat->sendChat($msg, null, false);
}
/**
* Hello Message
* @param array $chat
*
* @param array $chat
* @param Player $player
*/
public function chat_hi(array $chat, Player $player){
public function chat_hi(array $chat, Player $player) {
$command = explode(" ", $chat[1][2]);
if(isset($command[1])){
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iHello $z$<' . $this->getTarget($command[1]) . '$>$i!';
}else{
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iHello All!';
if (isset($command[1])) {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iHello $z$<' . $this->getTarget($command[1]) . '$>$i!';
}
//TODO why not italic?
else {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iHello All!';
}
// TODO why not italic?
$this->maniaControl->chat->sendChat($msg, null, false);
}
/**
* Bye Message
* @param array $chat
*
* @param array $chat
* @param Player $player
*/
public function chat_bye(array $chat, Player $player){
public function chat_bye(array $chat, Player $player) {
$command = explode(" ", $chat[1][2]);
if(isset($command[1])){
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iBye $z$<' . $this->getTarget($command[1]) . '$>$i!';
}else{
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iI have to go... Bye All!';
if (isset($command[1])) {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iBye $z$<' . $this->getTarget($command[1]) . '$>$i!';
}
else {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iI have to go... Bye All!';
}
$this->maniaControl->chat->sendChat($msg, null, false);
}
/**
* Thx Message
* @param array $chat
*
* @param array $chat
* @param Player $player
*/
public function chat_thx(array $chat, Player $player){
public function chat_thx(array $chat, Player $player) {
$command = explode(" ", $chat[1][2]);
if(isset($command[1])){
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iThanks $z$<' . $this->getTarget($command[1]) . '$>$i!';
}else{
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iThanks All!';
if (isset($command[1])) {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iThanks $z$<' . $this->getTarget($command[1]) . '$>$i!';
}
else {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iThanks All!';
}
$this->maniaControl->chat->sendChat($msg, null, false);
@ -138,16 +144,18 @@ class ChatMessagePlugin implements CommandListener, Plugin {
/**
* Good Game Message
* @param array $chat
*
* @param array $chat
* @param Player $player
*/
public function chat_gg(array $chat, Player $player){
public function chat_gg(array $chat, Player $player) {
$command = explode(" ", $chat[1][2]);
if(isset($command[1])){
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iGood Game $z$<' . $this->getTarget($command[1]) . '$>$i!';
}else{
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iGood Game All!';
if (isset($command[1])) {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iGood Game $z$<' . $this->getTarget($command[1]) . '$>$i!';
}
else {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iGood Game All!';
}
$this->maniaControl->chat->sendChat($msg, null, false);
@ -155,16 +163,18 @@ class ChatMessagePlugin implements CommandListener, Plugin {
/**
* Good Luck Message
* @param array $chat
*
* @param array $chat
* @param Player $player
*/
public function chat_gl(array $chat, Player $player){
public function chat_gl(array $chat, Player $player) {
$command = explode(" ", $chat[1][2]);
if(isset($command[1])){
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iGood Luck $z$<' . $this->getTarget($command[1]) . '$>$i!';
}else{
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iGood Luck All!';
if (isset($command[1])) {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iGood Luck $z$<' . $this->getTarget($command[1]) . '$>$i!';
}
else {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iGood Luck All!';
}
$this->maniaControl->chat->sendChat($msg, null, false);
@ -172,16 +182,18 @@ class ChatMessagePlugin implements CommandListener, Plugin {
/**
* Have Fun Message
* @param array $chat
*
* @param array $chat
* @param Player $player
*/
public function chat_hf(array $chat, Player $player){
public function chat_hf(array $chat, Player $player) {
$command = explode(" ", $chat[1][2]);
if(isset($command[1])){
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iHave Fun $z$<' . $this->getTarget($command[1]) . '$>$i!';
}else{
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iHave Fun All!';
if (isset($command[1])) {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iHave Fun $z$<' . $this->getTarget($command[1]) . '$>$i!';
}
else {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iHave Fun All!';
}
$this->maniaControl->chat->sendChat($msg, null, false);
@ -189,16 +201,18 @@ class ChatMessagePlugin implements CommandListener, Plugin {
/**
* Good Luck and Have Fun Message
* @param array $chat
*
* @param array $chat
* @param Player $player
*/
public function chat_glhf(array $chat, Player $player){
public function chat_glhf(array $chat, Player $player) {
$command = explode(" ", $chat[1][2]);
if(isset($command[1])){
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iGood Luck and Have Fun $z$<' . $this->getTarget($command[1]) . '$>$i!';
}else{
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iGood Luck and Have Fun All!';
if (isset($command[1])) {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iGood Luck and Have Fun $z$<' . $this->getTarget($command[1]) . '$>$i!';
}
else {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iGood Luck and Have Fun All!';
}
$this->maniaControl->chat->sendChat($msg, null, false);
@ -206,16 +220,18 @@ class ChatMessagePlugin implements CommandListener, Plugin {
/**
* Nice Shot Message
* @param array $chat
*
* @param array $chat
* @param Player $player
*/
public function chat_ns(array $chat, Player $player){
public function chat_ns(array $chat, Player $player) {
$command = explode(" ", $chat[1][2]);
if(isset($command[1])){
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iNice Shot $z$<' . $this->getTarget($command[1]) . '$>$i!';
}else{
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iNice Shot!';
if (isset($command[1])) {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iNice Shot $z$<' . $this->getTarget($command[1]) . '$>$i!';
}
else {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iNice Shot!';
}
$this->maniaControl->chat->sendChat($msg, null, false);
@ -223,16 +239,18 @@ class ChatMessagePlugin implements CommandListener, Plugin {
/**
* Nice one Message
* @param array $chat
*
* @param array $chat
* @param Player $player
*/
public function chat_n1(array $chat, Player $player){
public function chat_n1(array $chat, Player $player) {
$command = explode(" ", $chat[1][2]);
if(isset($command[1])){
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iNice One $z$<' . $this->getTarget($command[1]) . '$>$i!';
}else{
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iNice One!';
if (isset($command[1])) {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iNice One $z$<' . $this->getTarget($command[1]) . '$>$i!';
}
else {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iNice One!';
}
$this->maniaControl->chat->sendChat($msg, null, false);
@ -240,51 +258,56 @@ class ChatMessagePlugin implements CommandListener, Plugin {
/**
* Lol! Message
* @param array $chat
*
* @param array $chat
* @param Player $player
*/
public function chat_lol(array $chat, Player $player){
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iLoL!';
public function chat_lol(array $chat, Player $player) {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iLoL!';
$this->maniaControl->chat->sendChat($msg, null, false);
}
/**
* LooOOooL! Message
* @param array $chat
*
* @param array $chat
* @param Player $player
*/
public function chat_lool(array $chat, Player $player){
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iLooOOooL!';
public function chat_lool(array $chat, Player $player) {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iLooOOooL!';
$this->maniaControl->chat->sendChat($msg, null, false);
}
/**
* Be right back Message
* @param array $chat
*
* @param array $chat
* @param Player $player
*/
public function chat_brb(array $chat, Player $player){
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iBe Right Back!';
public function chat_brb(array $chat, Player $player) {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iBe Right Back!';
$this->maniaControl->chat->sendChat($msg, null, false);
}
/**
* Bad game for me Message
* @param array $chat
*
* @param array $chat
* @param Player $player
*/
public function chat_bgm(array $chat, Player $player){
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iBad Game for me :(';
public function chat_bgm(array $chat, Player $player) {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iBad Game for me :(';
$this->maniaControl->chat->sendChat($msg, null, false);
}
/**
* Leave the server with an Bootme Message
* @param array $chat
*
* @param array $chat
* @param Player $player
*/
public function chat_bootme(array $chat, Player $player){
$msg = '$i$ff0 $<' . $player->nickname .'$> $s$39f chooses to boot back to the real world!';
public function chat_bootme(array $chat, Player $player) {
$msg = '$i$ff0 $<' . $player->nickname . '$> $s$39f chooses to boot back to the real world!';
$this->maniaControl->chat->sendChat($msg, null, true);
$message = '$39F Thanks for Playing, please come back soon!$z';
@ -297,11 +320,12 @@ class ChatMessagePlugin implements CommandListener, Plugin {
/**
* Leave the server with an Ragequit
* @param array $chat
*
* @param array $chat
* @param Player $player
*/
public function chat_ragequit(array $chat, Player $player){
$msg = '$i$ff0 $<' . $player->nickname .'$> $s$f00 said: "@"#!" and ragequitted!';
public function chat_ragequit(array $chat, Player $player) {
$msg = '$i$ff0 $<' . $player->nickname . '$> $s$f00 said: "@"#!" and ragequitted!';
$this->maniaControl->chat->sendChat($msg, null, true);
$message = '$39F Thanks for Playing, please come back soon!$z';
@ -312,46 +336,47 @@ class ChatMessagePlugin implements CommandListener, Plugin {
}
}
/**
* Afk Message and force player to spec
* @param array $chat
*
* @param array $chat
* @param Player $player
*/
public function chat_afk(array $chat, Player $player){
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iAway From Keyboard!';
public function chat_afk(array $chat, Player $player) {
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iAway From Keyboard!';
$this->maniaControl->chat->sendChat($msg, null, false);
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_AFK_FORCE_SPEC)){
//force into spec
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_AFK_FORCE_SPEC)) {
// force into spec
$success = $this->maniaControl->client->query('ForceSpectator', $player->login, 3);
if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return;
}
//free player slot
// free player slot
$this->maniaControl->client->query('SpectatorReleasePlayerSlot', $player->login);
}
}
/**
* Checks if a Player is in the PlayerList and returns the nickname if he is, can be called per login, pid or nickname or lj for (last joined)
* Checks if a Player is in the PlayerList and returns the nickname if he is, can be called per login, pid or nickname or lj for
* (last joined)
*
* @param $login
* @return mixed
*/
private function getTarget($login){
private function getTarget($login) {
$pid = 1;
foreach($this->maniaControl->playerManager->getPlayers() as $player){
if($login == $player->login || $login == $pid || $login == $player->nickname){
foreach ($this->maniaControl->playerManager->getPlayers() as $player) {
if ($login == $player->login || $login == $pid || $login == $player->nickname) {
return $player->nickname;
}
$pid++;
}
if($login == 'lj')
return $player->nickname;
if ($login == 'lj') return $player->nickname;
return $login;
}
@ -361,7 +386,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
*
* @return int
*/
public static function getId(){
public static function getId() {
return self::PLUGIN_ID;
}
@ -370,7 +395,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
*
* @return string
*/
public static function getName(){
public static function getName() {
return self::PLUGIN_NAME;
}
@ -379,7 +404,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
*
* @return float,,
*/
public static function getVersion(){
public static function getVersion() {
return self::PLUGIN_VERSION;
}
@ -388,7 +413,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
*
* @return string
*/
public static function getAuthor(){
public static function getAuthor() {
return self::PLUGIN_AUTHOR;
}
@ -397,8 +422,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
*
* @return string
*/
public static function getDescription(){
public static function getDescription() {
return null;
}
}