From c123f2d10b468ae69da3877b9c4fe7d565d3f76f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 25 Aug 2018 15:43:23 +0100 Subject: [PATCH 1/4] SimpleCommandMap: clean up error reporting in registerServerAliases() --- src/pocketmine/command/SimpleCommandMap.php | 22 ++++++++------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/pocketmine/command/SimpleCommandMap.php b/src/pocketmine/command/SimpleCommandMap.php index 78308da68..76e859cd0 100644 --- a/src/pocketmine/command/SimpleCommandMap.php +++ b/src/pocketmine/command/SimpleCommandMap.php @@ -302,9 +302,9 @@ class SimpleCommandMap implements CommandMap{ } $targets = []; + $bad = []; + $recursive = []; - $bad = ""; - $recursive = ""; foreach($commandStrings as $commandString){ $args = explode(" ", $commandString); $commandName = ""; @@ -312,27 +312,21 @@ class SimpleCommandMap implements CommandMap{ if($command === null){ - if(strlen($bad) > 0){ - $bad .= ", "; - } - $bad .= $commandString; + $bad[] = $commandString; }elseif($commandName === $alias){ - if($recursive !== ""){ - $recursive .= ", "; - } - $recursive .= $commandString; + $recursive[] = $commandString; }else{ $targets[] = $commandString; } } - if($recursive !== ""){ - $this->server->getLogger()->warning($this->server->getLanguage()->translateString("pocketmine.command.alias.recursive", [$alias, $recursive])); + if(!empty($recursive)){ + $this->server->getLogger()->warning($this->server->getLanguage()->translateString("pocketmine.command.alias.recursive", [$alias, implode(", ", $recursive)])); continue; } - if(strlen($bad) > 0){ - $this->server->getLogger()->warning($this->server->getLanguage()->translateString("pocketmine.command.alias.notFound", [$alias, $bad])); + if(!empty($bad)){ + $this->server->getLogger()->warning($this->server->getLanguage()->translateString("pocketmine.command.alias.notFound", [$alias, implode(", ", $bad)])); continue; } From 298259b4730769330e283c79c8cc1652c53ab64c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 25 Aug 2018 16:05:25 +0100 Subject: [PATCH 2/4] PluginsCommand: clean up garbage code --- src/pocketmine/command/defaults/PluginsCommand.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/pocketmine/command/defaults/PluginsCommand.php b/src/pocketmine/command/defaults/PluginsCommand.php index c86a59286..f80325725 100644 --- a/src/pocketmine/command/defaults/PluginsCommand.php +++ b/src/pocketmine/command/defaults/PluginsCommand.php @@ -25,6 +25,7 @@ namespace pocketmine\command\defaults; use pocketmine\command\CommandSender; use pocketmine\lang\TranslationContainer; +use pocketmine\plugin\Plugin; use pocketmine\utils\TextFormat; class PluginsCommand extends VanillaCommand{ @@ -48,15 +49,10 @@ class PluginsCommand extends VanillaCommand{ } private function sendPluginList(CommandSender $sender){ - $list = ""; - foreach(($plugins = $sender->getServer()->getPluginManager()->getPlugins()) as $plugin){ - if(strlen($list) > 0){ - $list .= TextFormat::WHITE . ", "; - } - $list .= $plugin->isEnabled() ? TextFormat::GREEN : TextFormat::RED; - $list .= $plugin->getDescription()->getFullName(); - } + $list = array_map(function(Plugin $plugin) : string{ + return ($plugin->isEnabled() ? TextFormat::GREEN : TextFormat::RED) . $plugin->getDescription()->getFullName(); + }, $sender->getServer()->getPluginManager()->getPlugins()); - $sender->sendMessage(new TranslationContainer("pocketmine.command.plugins.success", [count($plugins), $list])); + $sender->sendMessage(new TranslationContainer("pocketmine.command.plugins.success", [count($list), implode(TextFormat::WHITE . ", ", $list)])); } } From 7dd53f23978e1ff9503b901f23c69af2185870fe Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 25 Aug 2018 16:07:49 +0100 Subject: [PATCH 3/4] Replace unnecessary strlen > 0 calls with !== "" checks --- src/pocketmine/command/defaults/TeleportCommand.php | 2 +- src/pocketmine/level/format/io/leveldb/LevelDB.php | 6 +++--- src/pocketmine/network/rcon/RCONInstance.php | 2 +- src/pocketmine/permission/BanEntry.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pocketmine/command/defaults/TeleportCommand.php b/src/pocketmine/command/defaults/TeleportCommand.php index b83b21677..899086540 100644 --- a/src/pocketmine/command/defaults/TeleportCommand.php +++ b/src/pocketmine/command/defaults/TeleportCommand.php @@ -49,7 +49,7 @@ class TeleportCommand extends VanillaCommand{ } $args = array_values(array_filter($args, function($arg){ - return strlen($arg) > 0; + return $arg !== ""; })); if(count($args) < 1 or count($args) > 6){ throw new InvalidCommandSyntaxException(); diff --git a/src/pocketmine/level/format/io/leveldb/LevelDB.php b/src/pocketmine/level/format/io/leveldb/LevelDB.php index 5b94d0f4c..725c572ff 100644 --- a/src/pocketmine/level/format/io/leveldb/LevelDB.php +++ b/src/pocketmine/level/format/io/leveldb/LevelDB.php @@ -377,7 +377,7 @@ class LevelDB extends BaseLevelProvider{ /** @var CompoundTag[] $entities */ $entities = []; - if(($entityData = $this->db->get($index . self::TAG_ENTITY)) !== false and strlen($entityData) > 0){ + if(($entityData = $this->db->get($index . self::TAG_ENTITY)) !== false and $entityData !== ""){ $entities = $nbt->read($entityData, true); if(!is_array($entities)){ $entities = [$entities]; @@ -392,7 +392,7 @@ class LevelDB extends BaseLevelProvider{ } $tiles = []; - if(($tileData = $this->db->get($index . self::TAG_BLOCK_ENTITY)) !== false and strlen($tileData) > 0){ + if(($tileData = $this->db->get($index . self::TAG_BLOCK_ENTITY)) !== false and $tileData !== ""){ $tiles = $nbt->read($tileData, true); if(!is_array($tiles)){ $tiles = [$tiles]; @@ -402,7 +402,7 @@ class LevelDB extends BaseLevelProvider{ //TODO: extra data should be converted into blockstorage layers (first they need to be implemented!) /* $extraData = []; - if(($extraRawData = $this->db->get($index . self::TAG_BLOCK_EXTRA_DATA)) !== false and strlen($extraRawData) > 0){ + if(($extraRawData = $this->db->get($index . self::TAG_BLOCK_EXTRA_DATA)) !== false and $extraRawData !== ""){ $binaryStream->setBuffer($extraRawData, 0); $count = $binaryStream->getLInt(); for($i = 0; $i < $count; ++$i){ diff --git a/src/pocketmine/network/rcon/RCONInstance.php b/src/pocketmine/network/rcon/RCONInstance.php index d1e98da2e..0ea1d771b 100644 --- a/src/pocketmine/network/rcon/RCONInstance.php +++ b/src/pocketmine/network/rcon/RCONInstance.php @@ -177,7 +177,7 @@ class RCONInstance extends Thread{ $disconnect[$id] = $sock; break; } - if(strlen($payload) > 0){ + if($payload !== ""){ $this->cmd = ltrim($payload); $this->synchronized(function(){ $this->notifier->wakeupSleeper(); diff --git a/src/pocketmine/permission/BanEntry.php b/src/pocketmine/permission/BanEntry.php index 790fb8ada..3c91d5839 100644 --- a/src/pocketmine/permission/BanEntry.php +++ b/src/pocketmine/permission/BanEntry.php @@ -168,7 +168,7 @@ class BanEntry{ } $expire = trim(array_shift($str)); - if(strtolower($expire) !== "forever" and strlen($expire) > 0){ + if($expire !== "" and strtolower($expire) !== "forever"){ $entry->setExpires(self::parseDate($expire)); } if(empty($str)){ From 22fcfffa53b032aa65a0e7bf1517153dbdfaf757 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 25 Aug 2018 16:09:51 +0100 Subject: [PATCH 4/4] PluginsCommand: remove useless private function --- src/pocketmine/command/defaults/PluginsCommand.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/pocketmine/command/defaults/PluginsCommand.php b/src/pocketmine/command/defaults/PluginsCommand.php index f80325725..e4332b81d 100644 --- a/src/pocketmine/command/defaults/PluginsCommand.php +++ b/src/pocketmine/command/defaults/PluginsCommand.php @@ -44,15 +44,12 @@ class PluginsCommand extends VanillaCommand{ if(!$this->testPermission($sender)){ return true; } - $this->sendPluginList($sender); - return true; - } - private function sendPluginList(CommandSender $sender){ $list = array_map(function(Plugin $plugin) : string{ return ($plugin->isEnabled() ? TextFormat::GREEN : TextFormat::RED) . $plugin->getDescription()->getFullName(); }, $sender->getServer()->getPluginManager()->getPlugins()); $sender->sendMessage(new TranslationContainer("pocketmine.command.plugins.success", [count($list), implode(TextFormat::WHITE . ", ", $list)])); + return true; } }