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