Skip to content

Commit db72229

Browse files
committed
Code cleanup
1 parent e1ef860 commit db72229

File tree

105 files changed

+932
-896
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+932
-896
lines changed

src/pocketmine/CrashDump.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private function pluginsData(){
9797
"load" => $d->getOrder() === PluginLoadOrder::POSTWORLD ? "POSTWORLD" : "STARTUP",
9898
"website" => $d->getWebsite()
9999
];
100-
$this->addLine($d->getName() . " " . $d->getVersion() . " by " . implode(", ", $d->getAuthors())." for API(s) ". implode(", ", $d->getCompatibleApis()));
100+
$this->addLine($d->getName() . " " . $d->getVersion() . " by " . implode(", ", $d->getAuthors()) . " for API(s) " . implode(", ", $d->getCompatibleApis()));
101101
}
102102
}
103103
}
@@ -169,10 +169,10 @@ private function baseCrash(){
169169
$this->data["error"] = $error;
170170
unset($this->data["error"]["fullFile"]);
171171
unset($this->data["error"]["trace"]);
172-
$this->addLine("Error: ". $error["message"]);
173-
$this->addLine("File: ". $error["file"]);
174-
$this->addLine("Line: ". $error["line"]);
175-
$this->addLine("Type: ". $error["type"]);
172+
$this->addLine("Error: " . $error["message"]);
173+
$this->addLine("File: " . $error["file"]);
174+
$this->addLine("Line: " . $error["line"]);
175+
$this->addLine("Type: " . $error["type"]);
176176

177177
if(strpos($error["file"], "src/pocketmine/") === false and strpos($error["file"], "src/raklib/") === false and file_exists($error["fullFile"])){
178178
$this->addLine();
@@ -186,7 +186,7 @@ private function baseCrash(){
186186
$filePath = \pocketmine\cleanPath($file->getValue($plugin));
187187
if(strpos($error["file"], $filePath) === 0){
188188
$this->data["plugin"] = $plugin->getName();
189-
$this->addLine("BAD PLUGIN: ".$plugin->getDescription()->getFullName());
189+
$this->addLine("BAD PLUGIN: " . $plugin->getDescription()->getFullName());
190190
break;
191191
}
192192
}
@@ -228,7 +228,7 @@ private function generalData(){
228228
$this->data["general"]["zend"] = zend_version();
229229
$this->data["general"]["php_os"] = PHP_OS;
230230
$this->data["general"]["os"] = Utils::getOS();
231-
$this->addLine("PocketMine-MP version: " . $version->get(false). " #" . $version->getNumber() . " [Protocol " . Info::CURRENT_PROTOCOL . "; API " . API_VERSION . "]");
231+
$this->addLine("PocketMine-MP version: " . $version->get(false) . " #" . $version->getNumber() . " [Protocol " . Info::CURRENT_PROTOCOL . "; API " . API_VERSION . "]");
232232
$this->addLine("Git commit: " . GIT_COMMIT);
233233
$this->addLine("uname -a: " . php_uname("a"));
234234
$this->addLine("PHP Version: " . phpversion());

src/pocketmine/Player.php

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
164164
private $inAction = false;
165165

166166

167-
168167
private $needACK = [];
169168

170169
/**
@@ -287,8 +286,8 @@ public function showPlayer(Player $player){
287286
}
288287
unset($this->hiddenPlayers[$player->getName()]);
289288
if($player->isOnline()){
290-
$player->spawnTo($this);
291-
}
289+
$player->spawnTo($this);
290+
}
292291
}
293292

294293
/**
@@ -520,6 +519,7 @@ public function getSpawn(){
520519
return $this->spawnPosition;
521520
}else{
522521
$level = $this->server->getDefaultLevel();
522+
523523
return $level->getSafeSpawn();
524524
}
525525
}
@@ -1368,7 +1368,7 @@ public function handleDataPacket(DataPacket $packet){
13681368
$item = $this->inventory->getItem($packet->slot);
13691369
$slot = $packet->slot;
13701370
}
1371-
1371+
13721372
if($packet->slot === -1){ //Air
13731373
if(($this->gamemode & 0x01) === Player::CREATIVE){
13741374
$found = false;
@@ -1379,7 +1379,7 @@ public function handleDataPacket(DataPacket $packet){
13791379
break;
13801380
}
13811381
}
1382-
1382+
13831383
if(!$found){ //couldn't find a empty slot (error)
13841384
$this->inventory->sendContents($this);
13851385
break;
@@ -1498,27 +1498,27 @@ public function handleDataPacket(DataPacket $packet){
14981498
switch($packet->action){
14991499
case 5: //Shot arrow
15001500
//if($this->entity->inAction === true){
1501-
if($this->inventory->getItemInHand()->getID() === Item::BOW){
1502-
$f = 1 * 2 * 1.5;
1503-
$nbt = new Compound("", [
1504-
"Pos" => new Enum("Pos", [
1505-
new Double("", $this->x),
1506-
new Double("", $this->y + 1.62),
1507-
new Double("", $this->z)
1508-
]),
1509-
"Motion" => new Enum("Motion", [
1510-
new Double("", -sin($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI) * $f),
1511-
new Double("", -sin($this->pitch / 180 * M_PI) * $f),
1512-
new Double("", cos($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI) * $f)
1513-
]),
1514-
"Rotation" => new Enum("Rotation", [
1515-
new Float("", $this->yaw),
1516-
new Float("", $this->pitch)
1517-
]),
1518-
]);
1519-
$arrow = new Arrow($this->chunk, $nbt);
1520-
$arrow->spawnToAll();
1521-
}
1501+
if($this->inventory->getItemInHand()->getID() === Item::BOW){
1502+
$f = 1 * 2 * 1.5;
1503+
$nbt = new Compound("", [
1504+
"Pos" => new Enum("Pos", [
1505+
new Double("", $this->x),
1506+
new Double("", $this->y + 1.62),
1507+
new Double("", $this->z)
1508+
]),
1509+
"Motion" => new Enum("Motion", [
1510+
new Double("", -sin($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI) * $f),
1511+
new Double("", -sin($this->pitch / 180 * M_PI) * $f),
1512+
new Double("", cos($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI) * $f)
1513+
]),
1514+
"Rotation" => new Enum("Rotation", [
1515+
new Float("", $this->yaw),
1516+
new Float("", $this->pitch)
1517+
]),
1518+
]);
1519+
$arrow = new Arrow($this->chunk, $nbt);
1520+
$arrow->spawnToAll();
1521+
}
15221522
//}
15231523
$this->startAction = false;
15241524
//$this->entity->inAction = false;
@@ -1711,7 +1711,7 @@ public function handleDataPacket(DataPacket $packet){
17111711

17121712
if($item->isTool() and ($this->gamemode & 0x01) === 0){
17131713
if($item->useOn($target) and $item->getDamage() >= $item->getMaxDurability()){
1714-
$this->inventory->setItemInHand(Item::get(Item::AIR, 0 ,1));
1714+
$this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1));
17151715
}
17161716
}
17171717
}
@@ -1893,12 +1893,11 @@ public function handleDataPacket(DataPacket $packet){
18931893
}
18941894
if(($this->gamemode & 0x01) === Player::CREATIVE){
18951895
if($this->getCreativeBlock($packet->item) !== -1){
1896-
$this->inventory->setItem($packet->slot,$packet->item);
1897-
$this->inventory->setHotbarSlotIndex($packet->slot,$packet->slot); //links $hotbar[$packet->slot] to $slots[$packet->slot]
1896+
$this->inventory->setItem($packet->slot, $packet->item);
1897+
$this->inventory->setHotbarSlotIndex($packet->slot, $packet->slot); //links $hotbar[$packet->slot] to $slots[$packet->slot]
18981898
}
1899-
}
1900-
else{
1901-
$this->inventory->setHeldItemSlot($packet->slot);
1899+
}else{
1900+
$this->inventory->setHeldItemSlot($packet->slot);
19021901
}
19031902
$transaction = new BaseTransaction($this->inventory, $packet->slot, $this->inventory->getItem($packet->slot), $packet->item);
19041903
}elseif(isset($this->windowIndex[$packet->windowid])){
@@ -2054,7 +2053,7 @@ public function handleDataPacket(DataPacket $packet){
20542053
public function kick($reason = ""){
20552054
$this->server->getPluginManager()->callEvent($ev = new PlayerKickEvent($this, $reason, TextFormat::YELLOW . $this->username . " has left the game"));
20562055
if(!$ev->isCancelled()){
2057-
$message = "Kicked by admin.". ($reason !== "" ? " Reason: ". $reason : "");
2056+
$message = "Kicked by admin." . ($reason !== "" ? " Reason: " . $reason : "");
20582057
$this->sendMessage($message);
20592058
$this->close($ev->getQuitMessage(), $message);
20602059

@@ -2183,7 +2182,7 @@ public function kill(){
21832182
$this->inventory->clearAll();
21842183
}
21852184

2186-
$message = $this->getName() ." died";
2185+
$message = $this->getName() . " died";
21872186
$cause = $this->getLastDamageCause();
21882187
$ev = null;
21892188
if($cause instanceof EntityDamageEvent){
@@ -2196,29 +2195,29 @@ public function kill(){
21962195
if($ev instanceof EntityDamageByEntityEvent){
21972196
$e = $ev->getDamager();
21982197
if($e instanceof Player){
2199-
$message = $this->getName() ." was killed by ".$e->getName();
2198+
$message = $this->getName() . " was killed by " . $e->getName();
22002199
break;
22012200
}elseif($e instanceof Living){
2202-
$message = $this->getName() ." was slain by ".$e->getName();
2201+
$message = $this->getName() . " was slain by " . $e->getName();
22032202
break;
22042203
}
22052204
}
2206-
$message = $this->getName() ." was killed";
2205+
$message = $this->getName() . " was killed";
22072206
break;
22082207
case EntityDamageEvent::CAUSE_SUICIDE:
22092208

22102209
break;
22112210
case EntityDamageEvent::CAUSE_VOID:
2212-
$message = $this->getName() ." fell out of the world";
2211+
$message = $this->getName() . " fell out of the world";
22132212
break;
22142213
case EntityDamageEvent::CAUSE_FALL:
22152214
if($ev instanceof EntityDamageEvent){
22162215
if($ev->getFinalDamage() > 2){
2217-
$message = $this->getName() ." fell from a high place";
2216+
$message = $this->getName() . " fell from a high place";
22182217
break;
22192218
}
22202219
}
2221-
$message = $this->getName() ." hit the ground too hard";
2220+
$message = $this->getName() . " hit the ground too hard";
22222221
break;
22232222

22242223
case EntityDamageEvent::CAUSE_CONTACT:

src/pocketmine/PocketMine.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ function dummy(){
6868
use LogLevel;
6969
use pocketmine\utils\Binary;
7070
use pocketmine\utils\MainLogger;
71-
use pocketmine\utils\TextFormat;
7271
use pocketmine\utils\Utils;
7372
use pocketmine\wizard\Installer;
7473
use raklib\RakLib;
@@ -86,7 +85,7 @@ function dummy(){
8685

8786
if(!extension_loaded("pthreads")){
8887
echo "[CRITICAL] Unable to find the pthreads extension." . PHP_EOL;
89-
echo "[CRITICAL] Please use the installer provided on the homepage.". PHP_EOL;
88+
echo "[CRITICAL] Please use the installer provided on the homepage." . PHP_EOL;
9089
exit(1);
9190
}
9291

@@ -351,7 +350,7 @@ function error_handler($errno, $errstr, $errfile, $errline, $trace = null){
351350

352351
foreach(ThreadManager::getInstance()->getAll() as $id => $thread){
353352
if($thread->isRunning()){
354-
$logger->debug("Stopping ".(new \ReflectionClass($thread))->getShortName()." thread");
353+
$logger->debug("Stopping " . (new \ReflectionClass($thread))->getShortName() . " thread");
355354
if($thread instanceof Thread){
356355
$thread->kill();
357356

@@ -366,7 +365,7 @@ function error_handler($errno, $errstr, $errfile, $errline, $trace = null){
366365
}
367366
}
368367
}elseif(!$thread->isJoined()){
369-
$logger->debug("Joining ".(new \ReflectionClass($thread))->getShortName()." thread");
368+
$logger->debug("Joining " . (new \ReflectionClass($thread))->getShortName() . " thread");
370369
$thread->join();
371370
}
372371
}

src/pocketmine/Server.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
use pocketmine\nbt\tag\Short;
6161
use pocketmine\nbt\tag\String;
6262
use pocketmine\network\protocol\DataPacket;
63-
use pocketmine\network\protocol\Info;
6463
use pocketmine\network\query\QueryHandler;
6564
use pocketmine\network\query\QueryPacket;
6665
use pocketmine\network\RakLibInterface;
@@ -879,6 +878,7 @@ public function getLevelByName($name){
879878
public function unloadLevel(Level $level, $forceUnload = false){
880879
if($level->unload($forceUnload) === true and $this->isLevelLoaded($level->getFolderName())){
881880
unset($this->levels[$level->getID()]);
881+
882882
return true;
883883
}
884884

@@ -923,7 +923,8 @@ public function loadLevel($name){
923923
try{
924924
$level = new Level($this, $name, $path, $provider);
925925
}catch(\Exception $e){
926-
$this->logger->error("Could not load level \"" . $name . "\": ". $e->getMessage());
926+
$this->logger->error("Could not load level \"" . $name . "\": " . $e->getMessage());
927+
927928
return false;
928929
}
929930

@@ -1575,6 +1576,7 @@ public function __construct(\SplClassLoader $autoloader, \ThreadedLogger $logger
15751576
if(!($this->getDefaultLevel() instanceof Level)){
15761577
$this->getLogger()->emergency("No default level has been loaded");
15771578
$this->forceShutdown();
1579+
15781580
return;
15791581
}
15801582

@@ -1621,8 +1623,9 @@ public function broadcast($message, $permissions){
16211623
foreach($recipients as $recipient){
16221624
$recipient->sendMessage($message);
16231625
}
1626+
16241627
return count($recipients);
1625-
}
1628+
}
16261629

16271630
/**
16281631
* Broadcasts a Minecraft packet to a list of players
@@ -1693,6 +1696,7 @@ public function dispatchCommand(CommandSender $sender, $commandLine){
16931696
}else{
16941697
$sender->sendMessage("Unknown command. Type \"help\" for help.");
16951698
}
1699+
16961700
return false;
16971701
}
16981702

@@ -1862,7 +1866,7 @@ public function crashDump(){
18621866
$this->logger->emergency("An unrecoverable error has occurred and the server has crashed. Creating a crash dump");
18631867
$dump = new CrashDump($this);
18641868

1865-
$this->logger->emergency("Please submit the \"".$dump->getPath()."\" file to the Bug Reporting page. Give as much info as you can.");
1869+
$this->logger->emergency("Please submit the \"" . $dump->getPath() . "\" file to the Bug Reporting page. Give as much info as you can.");
18661870

18671871

18681872
if($this->getProperty("auto-report.enabled", true) !== false){
@@ -1878,9 +1882,9 @@ public function crashDump(){
18781882
return;
18791883
}
18801884

1881-
$reply = Utils::postURL("http://".$this->getProperty("auto-report.host", "crash.pocketmine.net")."/submit/api", [
1885+
$reply = Utils::postURL("http://" . $this->getProperty("auto-report.host", "crash.pocketmine.net") . "/submit/api", [
18821886
"report" => "yes",
1883-
"name" => "PocketMine-MP ".$this->getPocketMineVersion(),
1887+
"name" => "PocketMine-MP " . $this->getPocketMineVersion(),
18841888
"email" => "[email protected]",
18851889
"reportPaste" => base64_encode($dump->getEncodedData())
18861890
]);
@@ -2016,7 +2020,7 @@ public function sendUsage(){
20162020

20172021
private function titleTick(){
20182022
if(defined("pocketmine\\DEBUG") and \pocketmine\DEBUG >= 0 and \pocketmine\ANSI === true){
2019-
echo "\x1b]0;PocketMine-MP " . $this->getPocketMineVersion() . " | Online " . count($this->players) . "/" . $this->getMaxPlayers() . " | RAM " . round((memory_get_usage() / 1024) / 1024, 2) . "/" . round((memory_get_usage(true) / 1024) / 1024, 2) . " MB | U ". round($this->mainInterface->getUploadUsage() / 1024, 2) ." D ". round($this->mainInterface->getDownloadUsage() / 1024, 2) ." kB/s | TPS " . $this->getTicksPerSecond() . "\x07";
2023+
echo "\x1b]0;PocketMine-MP " . $this->getPocketMineVersion() . " | Online " . count($this->players) . "/" . $this->getMaxPlayers() . " | RAM " . round((memory_get_usage() / 1024) / 1024, 2) . "/" . round((memory_get_usage(true) / 1024) / 1024, 2) . " MB | U " . round($this->mainInterface->getUploadUsage() / 1024, 2) . " D " . round($this->mainInterface->getDownloadUsage() / 1024, 2) . " kB/s | TPS " . $this->getTicksPerSecond() . "\x07";
20202024
}
20212025
}
20222026

src/pocketmine/Thread.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ abstract class Thread extends \Thread{
2828

2929
public final function start($options = PTHREADS_INHERIT_ALL){
3030
ThreadManager::getInstance()->add($this);
31+
3132
return parent::start($options & ~PTHREADS_INHERIT_CLASSES);
3233
}
3334
}

src/pocketmine/ThreadManager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function getAll(){
6363
foreach($this as $key => $thread){
6464
$array[$key] = $thread;
6565
}
66+
6667
return $array;
6768
}
6869
}

src/pocketmine/Worker.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ abstract class Worker extends \Worker{
2828

2929
public final function start($options = PTHREADS_INHERIT_ALL){
3030
ThreadManager::getInstance()->add($this);
31+
3132
return parent::start($options & ~PTHREADS_INHERIT_CLASSES);
3233
}
3334
}

src/pocketmine/block/Cactus.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
use pocketmine\level\Level;
2626
use pocketmine\math\Vector3 as Vector3;
2727
use pocketmine\Player;
28-
use pocketmine\Server;
2928

3029
class Cactus extends Transparent{
3130
public function __construct($meta = 0){

src/pocketmine/block/Generic.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
use pocketmine\item\Item;
2525
use pocketmine\level\Level;
2626
use pocketmine\Player;
27-
use pocketmine\Server;
2827

2928
class Generic extends Block{
3029

src/pocketmine/block/TallGrass.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function getDrops(Item $item){
5353
if(mt_rand(0, 15) === 0){
5454
return [Item::WHEAT_SEEDS, 0, 1];
5555
}
56+
5657
return [];
5758
}
5859

0 commit comments

Comments
 (0)