code improvements & cleanup

This commit is contained in:
Steffen Schröder 2014-06-23 16:32:40 +02:00
parent d4f685a607
commit 0b5162db32

View File

@ -38,6 +38,8 @@ class DynamicPointLimitPlugin implements CallbackListener, CommandListener, Plug
const CACHE_SPEC_STATUS = 'SpecStatus'; const CACHE_SPEC_STATUS = 'SpecStatus';
const SCRIPT_SETTING_MAP_POINTS_LIMIT = 'S_MapPointsLimit';
/* /*
* Private Properties * Private Properties
*/ */
@ -142,7 +144,7 @@ class DynamicPointLimitPlugin implements CallbackListener, CommandListener, Plug
if ($this->lastPointLimit !== $pointLimit) { if ($this->lastPointLimit !== $pointLimit) {
try { try {
$this->maniaControl->client->setModeScriptSettings(array('S_MapPointsLimit' => $pointLimit)); $this->maniaControl->client->setModeScriptSettings(array(self::SCRIPT_SETTING_MAP_POINTS_LIMIT => $pointLimit));
$message = "Dynamic PointLimit changed to: {$pointLimit}!"; $message = "Dynamic PointLimit changed to: {$pointLimit}!";
if ($this->lastPointLimit !== null) { if ($this->lastPointLimit !== null) {
$message .= " (From {$this->lastPointLimit})"; $message .= " (From {$this->lastPointLimit})";
@ -180,7 +182,7 @@ class DynamicPointLimitPlugin implements CallbackListener, CommandListener, Plug
return; return;
} }
try { try {
$this->maniaControl->client->setModeScriptSettings(array('S_MapPointsLimit' => $value)); $this->maniaControl->client->setModeScriptSettings(array(self::SCRIPT_SETTING_MAP_POINTS_LIMIT => $value));
$this->staticMode = true; $this->staticMode = true;
$this->lastPointLimit = $value; $this->lastPointLimit = $value;
$this->maniaControl->chat->sendInformation("PointLimit changed to: {$value} (Fixed)"); $this->maniaControl->chat->sendInformation("PointLimit changed to: {$value} (Fixed)");
@ -213,17 +215,16 @@ class DynamicPointLimitPlugin implements CallbackListener, CommandListener, Plug
/** /**
* Handle BeginMap Callback * Handle BeginMap Callback
*
* @param Setting $setting
*/ */
public function handleBeginMap() { public function handleBeginMap() {
if ($this->staticMode) if ($this->staticMode && !is_null($this->lastPointLimit)) {
{ // Refresh static point limit in case it has been reset
$this->maniaControl->chat->sendChat('$fffPointlimit fixed at '.$this->lastPointLimit.'.');
try { try {
$this->maniaControl->client->setModeScriptSettings(array('S_MapPointsLimit' => (int)($this->lastPointLimit))); $this->maniaControl->client->setModeScriptSettings(array(self::SCRIPT_SETTING_MAP_POINTS_LIMIT => $this->lastPointLimit));
}catch(FaultException $e){ $message = "PointLimit fixed at {$this->lastPointLimit}.";
$this->maniaControl->chat->sendInformation($message);
} catch (GameModeException $e) {
$this->lastPointLimit = null;
} }
} }
} }
@ -244,4 +245,3 @@ class DynamicPointLimitPlugin implements CallbackListener, CommandListener, Plug
$this->updatePointLimit(); $this->updatePointLimit();
} }
} }
?>