fixed chatmessageplugin
This commit is contained in:
parent
62398b719a
commit
90124a4c9a
@ -5,6 +5,7 @@ namespace ManiaControl\Plugins;
|
||||
use ManiaControl\Commands\CommandListener;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Players\Player;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||
|
||||
/**
|
||||
* ManiaControl Chat-Message Plugin
|
||||
@ -15,12 +16,12 @@ class ChatMessagePlugin implements CommandListener, Plugin {
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
const PLUGIN_ID = 9;
|
||||
const PLUGIN_VERSION = 0.1;
|
||||
const PLUGIN_NAME = 'ChatMessagePlugin';
|
||||
const PLUGIN_AUTHOR = 'kremsy';
|
||||
const PLUGIN_ID = 9;
|
||||
const PLUGIN_VERSION = 0.1;
|
||||
const PLUGIN_NAME = 'ChatMessagePlugin';
|
||||
const PLUGIN_AUTHOR = 'kremsy';
|
||||
const SETTING_AFK_FORCE_SPEC = 'AFK command forces spec';
|
||||
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
@ -38,7 +39,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
|
||||
*/
|
||||
public function load(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
|
||||
$this->maniaControl->commandManager->registerCommandListener('me', $this, 'chat_me');
|
||||
$this->maniaControl->commandManager->registerCommandListener('hi', $this, 'chat_hi');
|
||||
$this->maniaControl->commandManager->registerCommandListener('bye', $this, 'chat_bye');
|
||||
@ -58,9 +59,9 @@ class ChatMessagePlugin implements CommandListener, Plugin {
|
||||
$this->maniaControl->commandManager->registerCommandListener('bootme', $this, 'chat_bootme');
|
||||
$this->maniaControl->commandManager->registerCommandListener('ragequit', $this, 'chat_ragequit');
|
||||
$this->maniaControl->commandManager->registerCommandListener('rq', $this, 'chat_ragequit');
|
||||
|
||||
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_AFK_FORCE_SPEC, true);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -75,12 +76,12 @@ class ChatMessagePlugin implements CommandListener, Plugin {
|
||||
/**
|
||||
* 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], 4);
|
||||
|
||||
|
||||
$msg = '$<' . $player->nickname . '$>$s$i$fa0 ' . $message;
|
||||
$this->maniaControl->chat->sendChat($msg, null, false);
|
||||
}
|
||||
@ -88,16 +89,15 @@ class ChatMessagePlugin implements CommandListener, Plugin {
|
||||
/**
|
||||
* Hello Message
|
||||
*
|
||||
* @param array $chat
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function chat_hi(array $chat, Player $player) {
|
||||
$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!';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iHello All!';
|
||||
}
|
||||
$this->maniaControl->chat->sendChat($msg, null, false);
|
||||
@ -106,159 +106,151 @@ class ChatMessagePlugin implements CommandListener, Plugin {
|
||||
/**
|
||||
* Bye Message
|
||||
*
|
||||
* @param array $chat
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function chat_bye(array $chat, Player $player) {
|
||||
$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!';
|
||||
}
|
||||
else {
|
||||
} 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) {
|
||||
$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!';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iThanks All!';
|
||||
}
|
||||
|
||||
|
||||
$this->maniaControl->chat->sendChat($msg, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Good Game Message
|
||||
*
|
||||
* @param array $chat
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function chat_gg(array $chat, Player $player) {
|
||||
$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!';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iGood Game All!';
|
||||
}
|
||||
|
||||
|
||||
$this->maniaControl->chat->sendChat($msg, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Good Luck Message
|
||||
*
|
||||
* @param array $chat
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function chat_gl(array $chat, Player $player) {
|
||||
$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!';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iGood Luck All!';
|
||||
}
|
||||
|
||||
|
||||
$this->maniaControl->chat->sendChat($msg, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Have Fun Message
|
||||
*
|
||||
* @param array $chat
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function chat_hf(array $chat, Player $player) {
|
||||
$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!';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iHave Fun All!';
|
||||
}
|
||||
|
||||
|
||||
$this->maniaControl->chat->sendChat($msg, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Good Luck and Have Fun Message
|
||||
*
|
||||
* @param array $chat
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function chat_glhf(array $chat, Player $player) {
|
||||
$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!';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iGood Luck and Have Fun All!';
|
||||
}
|
||||
|
||||
|
||||
$this->maniaControl->chat->sendChat($msg, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Nice Shot Message
|
||||
*
|
||||
* @param array $chat
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function chat_ns(array $chat, Player $player) {
|
||||
$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!';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iNice Shot!';
|
||||
}
|
||||
|
||||
|
||||
$this->maniaControl->chat->sendChat($msg, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Nice one Message
|
||||
*
|
||||
* @param array $chat
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function chat_n1(array $chat, Player $player) {
|
||||
$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!';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$msg = '$g[$<' . $player->nickname . '$>$s] $ff0$iNice One!';
|
||||
}
|
||||
|
||||
|
||||
$this->maniaControl->chat->sendChat($msg, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lol! Message
|
||||
*
|
||||
* @param array $chat
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function chat_lol(array $chat, Player $player) {
|
||||
@ -269,7 +261,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
|
||||
/**
|
||||
* LooOOooL! Message
|
||||
*
|
||||
* @param array $chat
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function chat_lool(array $chat, Player $player) {
|
||||
@ -280,7 +272,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
|
||||
/**
|
||||
* Be right back Message
|
||||
*
|
||||
* @param array $chat
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function chat_brb(array $chat, Player $player) {
|
||||
@ -291,7 +283,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
|
||||
/**
|
||||
* Bad game for me Message
|
||||
*
|
||||
* @param array $chat
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function chat_bgm(array $chat, Player $player) {
|
||||
@ -302,16 +294,16 @@ class ChatMessagePlugin implements CommandListener, Plugin {
|
||||
/**
|
||||
* 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!';
|
||||
$this->maniaControl->chat->sendChat($msg, null, true);
|
||||
|
||||
|
||||
$message = '$39F Thanks for Playing, please come back soon!$z';
|
||||
$success = $this->maniaControl->client->query('Kick', $player->login, $message);
|
||||
if (!$success) {
|
||||
$success = $this->maniaControl->client->kick($player->login, $message);
|
||||
if(!$success) {
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
|
||||
return;
|
||||
}
|
||||
@ -320,16 +312,16 @@ 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!';
|
||||
$this->maniaControl->chat->sendChat($msg, null, true);
|
||||
|
||||
|
||||
$message = '$39F Thanks for Playing, please come back soon!$z';
|
||||
$success = $this->maniaControl->client->query('Kick', $player->login, $message);
|
||||
if (!$success) {
|
||||
$success = $this->maniaControl->client->kick($player->login, $message);
|
||||
if(!$success) {
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
|
||||
return;
|
||||
}
|
||||
@ -338,23 +330,26 @@ 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!';
|
||||
$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
|
||||
$success = $this->maniaControl->client->query('ForceSpectator', $player->login, 3);
|
||||
if (!$success) {
|
||||
$success = $this->maniaControl->client->forceSpectator($player->login, 3);
|
||||
if(!$success) {
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// free player slot
|
||||
$this->maniaControl->client->query('SpectatorReleasePlayerSlot', $player->login);
|
||||
try {
|
||||
$this->maniaControl->client->spectatorReleasePlayerSlot($player->login);
|
||||
} catch(Exception $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -367,16 +362,18 @@ class ChatMessagePlugin implements CommandListener, Plugin {
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user