Skip to content
Permalink
Browse files

Reformat code

  • Loading branch information
timmyRS committed Nov 16, 2019
1 parent 95e2a4e commit a624b12390dd814dd12dceb88688616a27f1cf4f
Showing with 112 additions and 99 deletions.
  1. +8 −1 composer.json
  2. +1 −1 plugins/Chunks.php
  3. +1 −1 plugins/GroupManagement.php
  4. +7 −1 selfcheck.php
  5. +16 −16 src/ClientConnection.php
  6. +79 −79 src/IntegratedServer.php
@@ -2,7 +2,14 @@
"name": "timmyrs/phpcraft",
"description": "A PHP library for all things Minecraft: Java Edition.",
"keywords": [
"minecraft-api", "minecraft-library", "nbt-library", "minecraft-protocol", "minecraft-java-edition", "minecraft-java", "minecraft", "mcje"
"minecraft-api",
"minecraft-library",
"nbt-library",
"minecraft-protocol",
"minecraft-java-edition",
"minecraft-java",
"minecraft",
"mcje"
],
"homepage": "https://github.com/Phpcraft/core",
"type": "library",
@@ -5,7 +5,7 @@
* @var Plugin $this
*/
use Phpcraft\
{BlockState, ClientConnection, Connection, Event\ServerChunkBorderEvent, Event\ServerJoinEvent, Event\ServerTickEvent, NBT\CompoundTag, NBT\LongArrayTag, Plugin, PluginManager};
{BlockState, ClientConnection, Connection, Event\ServerChunkBorderEvent, Event\ServerJoinEvent, Event\ServerTickEvent, NBT\CompoundTag, NBT\LongArrayTag, Plugin};
$this->on(function(ServerJoinEvent $event)
{
if($event->cancelled)
@@ -5,7 +5,7 @@
* @var Plugin $this
*/
use Phpcraft\
{ClientConfiguration, Command\ServerCommandSender, Plugin, PluginManager};
{ClientConfiguration, Command\ServerCommandSender, Plugin};
$this->registerCommand("group", function(ServerCommandSender &$sender, ClientConfiguration $player, string $group = "")
{
if($group == "")
@@ -47,7 +47,13 @@
$str .= $nl;
if(defined("PHP_WINDOWS_VERSION_MAJOR"))
{
if(in_array($ext, ["curl", "gd", "gmp", "mbstring", "sockets"]))
if(in_array($ext, [
"curl",
"gd",
"gmp",
"mbstring",
"sockets"
]))
{
$str .= "├ cone get php-$ext".$nl."└ If you don't have Cone, check the extensions section of your php.ini.\n";
}
@@ -627,22 +627,6 @@ function setGamemode(int $gamemode): ClientConnection
return $this;
}

/**
* Sets the client's abilities according to the given gamemode.
*
* @param int $gamemode
* @return ClientConnection $this
* @see ClientConnection::sendAbilities
* @see ClientConnection::setGamemode
*/
function setAbilitiesFromGamemode(int $gamemode): ClientConnection
{
$this->instant_breaking = ($gamemode == Gamemode::CREATIVE);
$this->flying = ($gamemode == Gamemode::SPECTATOR);
$this->invulnerable = $this->can_fly = ($gamemode == Gamemode::CREATIVE || $gamemode == Gamemode::SPECTATOR);
return $this;
}

/**
* Sends the client their abilities.
*
@@ -668,6 +652,22 @@ function sendAbilities(): ClientConnection
return $this;
}

/**
* Sets the client's abilities according to the given gamemode.
*
* @param int $gamemode
* @return ClientConnection $this
* @see ClientConnection::sendAbilities
* @see ClientConnection::setGamemode
*/
function setAbilitiesFromGamemode(int $gamemode): ClientConnection
{
$this->instant_breaking = ($gamemode == Gamemode::CREATIVE);
$this->flying = ($gamemode == Gamemode::SPECTATOR);
$this->invulnerable = $this->can_fly = ($gamemode == Gamemode::CREATIVE || $gamemode == Gamemode::SPECTATOR);
return $this;
}

function getName(): string
{
return $this->username;
@@ -1,9 +1,9 @@
<?php
namespace Phpcraft;
use Exception;
use hellsh\UUID;
use Phpcraft\
{Command\Command, Enum\Gamemode, Event\ServerChatEvent, Event\ServerChunkBorderEvent, Event\ServerClientMetadataEvent, Event\ServerClientSettingsEvent, Event\ServerFlyingChangeEvent, Event\ServerJoinEvent, Event\ServerLeaveEvent, Event\ServerMovementEvent, Event\ServerOnGroundChangeEvent, Event\ServerPacketEvent, Event\ServerRotationEvent, Exception\IOException, Packet\ClientSettingsPacket, Packet\JoinGamePacket, Packet\PluginMessage\ClientboundBrandPluginMessagePacket, Packet\ServerboundPacketId};
use hellsh\UUID;
use RuntimeException;
class IntegratedServer extends Server
{
@@ -388,84 +388,6 @@ function __construct(string $name = "Phpcraft Integrated Server", array $custom_
};
}

/**
* Starts the integrated server using $argv.
*
* @param string $name
* @param array $custom_config_defaults
* @return IntegratedServer
*/
static function cliStart(string $name = "Phpcraft Integrated Server", array $custom_config_defaults = []): IntegratedServer
{
global $argv;
$options = [
"offline" => false,
"plain" => false
];
for($i = 1; $i < count($argv); $i++)
{
$arg = ltrim($argv[$i], "-/");
switch($arg)
{
case "offline":
case "plain":
$options[$arg] = true;
break;
case "?":
case "help":
echo "offline disables online mode and allows cracked players\n";
echo "plain uses the plain user interface e.g. for writing logs to a file\n";
exit;
default:
die("Unknown flag '$arg' -- use 'help' to get a list of supported flags.\n");
}
}
return self::start($name, $options["offline"], $options["plain"], $custom_config_defaults);
}

/**
* Starts the integrated server using the given settings.
*
* @param string $name
* @param bool $offline
* @param bool $plain
* @param array $custom_config_defaults
* @return IntegratedServer
*/
static function start(string $name = "Phpcraft Integrated Server", bool $offline = false, bool $plain = false, array $custom_config_defaults = []): IntegratedServer
{
try
{
$ui = ($plain ? new PlainUserInterface() : new FancyUserInterface($name));
}
catch(RuntimeException $e)
{
echo "Since you're on PHP <7.2.0 and Windows <10.0.10586, the plain user interface is forcefully enabled.\n";
$ui = new PlainUserInterface();
}
if($offline)
{
$private_key = null;
}
else
{
$ui->add("Generating 1024-bit RSA keypair... ")
->render();
$args = [
"private_key_bits" => 1024,
"private_key_type" => OPENSSL_KEYTYPE_RSA
];
if(Phpcraft::isWindows())
{
$args["config"] = __DIR__."/openssl.cnf";
}
$private_key = openssl_pkey_new($args) or die("Failed to generate private key.\n");
$ui->append("Done.")
->render();
}
return new static($name, $custom_config_defaults, $ui, $private_key);
}

/**
* @return void
*/
@@ -600,4 +522,82 @@ function saveConfig(): void
{
file_put_contents("config/".$this->name.".json", json_encode($this->config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
}

/**
* Starts the integrated server using $argv.
*
* @param string $name
* @param array $custom_config_defaults
* @return IntegratedServer
*/
static function cliStart(string $name = "Phpcraft Integrated Server", array $custom_config_defaults = []): IntegratedServer
{
global $argv;
$options = [
"offline" => false,
"plain" => false
];
for($i = 1; $i < count($argv); $i++)
{
$arg = ltrim($argv[$i], "-/");
switch($arg)
{
case "offline":
case "plain":
$options[$arg] = true;
break;
case "?":
case "help":
echo "offline disables online mode and allows cracked players\n";
echo "plain uses the plain user interface e.g. for writing logs to a file\n";
exit;
default:
die("Unknown flag '$arg' -- use 'help' to get a list of supported flags.\n");
}
}
return self::start($name, $options["offline"], $options["plain"], $custom_config_defaults);
}

/**
* Starts the integrated server using the given settings.
*
* @param string $name
* @param bool $offline
* @param bool $plain
* @param array $custom_config_defaults
* @return IntegratedServer
*/
static function start(string $name = "Phpcraft Integrated Server", bool $offline = false, bool $plain = false, array $custom_config_defaults = []): IntegratedServer
{
try
{
$ui = ($plain ? new PlainUserInterface() : new FancyUserInterface($name));
}
catch(RuntimeException $e)
{
echo "Since you're on PHP <7.2.0 and Windows <10.0.10586, the plain user interface is forcefully enabled.\n";
$ui = new PlainUserInterface();
}
if($offline)
{
$private_key = null;
}
else
{
$ui->add("Generating 1024-bit RSA keypair... ")
->render();
$args = [
"private_key_bits" => 1024,
"private_key_type" => OPENSSL_KEYTYPE_RSA
];
if(Phpcraft::isWindows())
{
$args["config"] = __DIR__."/openssl.cnf";
}
$private_key = openssl_pkey_new($args) or die("Failed to generate private key.\n");
$ui->append("Done.")
->render();
}
return new static($name, $custom_config_defaults, $ui, $private_key);
}
}

0 comments on commit a624b12

Please sign in to comment.
You can’t perform that action at this time.