Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions generated/lang/KnownTranslationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,40 @@ public static function commands_unbanip_usage() : Translatable{
return new Translatable(KnownTranslationKeys::COMMANDS_UNBANIP_USAGE, []);
}

public static function commands_weather_clear() : Translatable{
return new Translatable(KnownTranslationKeys::COMMANDS_WEATHER_CLEAR, []);
}

public static function commands_weather_disabled() : Translatable{
return new Translatable(KnownTranslationKeys::COMMANDS_WEATHER_DISABLED, []);
}

public static function commands_weather_query(Translatable|string $param0) : Translatable{
return new Translatable(KnownTranslationKeys::COMMANDS_WEATHER_QUERY, [
0 => $param0,
]);
}

public static function commands_weather_query_clear() : Translatable{
return new Translatable(KnownTranslationKeys::COMMANDS_WEATHER_QUERY_CLEAR, []);
}

public static function commands_weather_query_rain() : Translatable{
return new Translatable(KnownTranslationKeys::COMMANDS_WEATHER_QUERY_RAIN, []);
}

public static function commands_weather_query_thunder() : Translatable{
return new Translatable(KnownTranslationKeys::COMMANDS_WEATHER_QUERY_THUNDER, []);
}

public static function commands_weather_rain() : Translatable{
return new Translatable(KnownTranslationKeys::COMMANDS_WEATHER_RAIN, []);
}

public static function commands_weather_thunder() : Translatable{
return new Translatable(KnownTranslationKeys::COMMANDS_WEATHER_THUNDER, []);
}

public static function commands_whitelist_add_success(Translatable|string $param0) : Translatable{
return new Translatable(KnownTranslationKeys::COMMANDS_WHITELIST_ADD_SUCCESS, [
0 => $param0,
Expand Down Expand Up @@ -2027,6 +2061,18 @@ public static function pocketmine_command_version_usage() : Translatable{
return new Translatable(KnownTranslationKeys::POCKETMINE_COMMAND_VERSION_USAGE, []);
}

public static function pocketmine_command_weather_description() : Translatable{
return new Translatable(KnownTranslationKeys::POCKETMINE_COMMAND_WEATHER_DESCRIPTION, []);
}

public static function pocketmine_command_weather_disable() : Translatable{
return new Translatable(KnownTranslationKeys::POCKETMINE_COMMAND_WEATHER_DISABLE, []);
}

public static function pocketmine_command_weather_usage() : Translatable{
return new Translatable(KnownTranslationKeys::POCKETMINE_COMMAND_WEATHER_USAGE, []);
}

public static function pocketmine_command_whitelist_description() : Translatable{
return new Translatable(KnownTranslationKeys::POCKETMINE_COMMAND_WHITELIST_DESCRIPTION, []);
}
Expand Down Expand Up @@ -2513,6 +2559,10 @@ public static function pocketmine_permission_command_version() : Translatable{
return new Translatable(KnownTranslationKeys::POCKETMINE_PERMISSION_COMMAND_VERSION, []);
}

public static function pocketmine_permission_command_weather() : Translatable{
return new Translatable(KnownTranslationKeys::POCKETMINE_PERMISSION_COMMAND_WEATHER, []);
}

public static function pocketmine_permission_command_whitelist_add() : Translatable{
return new Translatable(KnownTranslationKeys::POCKETMINE_PERMISSION_COMMAND_WHITELIST_ADD, []);
}
Expand Down
12 changes: 12 additions & 0 deletions generated/lang/KnownTranslationKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ final class KnownTranslationKeys{
public const COMMANDS_UNBANIP_INVALID = "commands.unbanip.invalid";
public const COMMANDS_UNBANIP_SUCCESS = "commands.unbanip.success";
public const COMMANDS_UNBANIP_USAGE = "commands.unbanip.usage";
public const COMMANDS_WEATHER_CLEAR = "commands.weather.clear";
public const COMMANDS_WEATHER_DISABLED = "commands.weather.disabled";
public const COMMANDS_WEATHER_QUERY = "commands.weather.query";
public const COMMANDS_WEATHER_QUERY_CLEAR = "commands.weather.query.clear";
public const COMMANDS_WEATHER_QUERY_RAIN = "commands.weather.query.rain";
public const COMMANDS_WEATHER_QUERY_THUNDER = "commands.weather.query.thunder";
public const COMMANDS_WEATHER_RAIN = "commands.weather.rain";
public const COMMANDS_WEATHER_THUNDER = "commands.weather.thunder";
public const COMMANDS_WHITELIST_ADD_SUCCESS = "commands.whitelist.add.success";
public const COMMANDS_WHITELIST_ADD_USAGE = "commands.whitelist.add.usage";
public const COMMANDS_WHITELIST_DISABLED = "commands.whitelist.disabled";
Expand Down Expand Up @@ -443,6 +451,9 @@ final class KnownTranslationKeys{
public const POCKETMINE_COMMAND_VERSION_SERVERSOFTWARENAME = "pocketmine.command.version.serverSoftwareName";
public const POCKETMINE_COMMAND_VERSION_SERVERSOFTWAREVERSION = "pocketmine.command.version.serverSoftwareVersion";
public const POCKETMINE_COMMAND_VERSION_USAGE = "pocketmine.command.version.usage";
public const POCKETMINE_COMMAND_WEATHER_DESCRIPTION = "pocketmine.command.weather.description";
public const POCKETMINE_COMMAND_WEATHER_DISABLE = "pocketmine.command.weather.disable";
public const POCKETMINE_COMMAND_WEATHER_USAGE = "pocketmine.command.weather.usage";
public const POCKETMINE_COMMAND_WHITELIST_DESCRIPTION = "pocketmine.command.whitelist.description";
public const POCKETMINE_COMMAND_XP_DESCRIPTION = "pocketmine.command.xp.description";
public const POCKETMINE_COMMAND_XP_USAGE = "pocketmine.command.xp.usage";
Expand Down Expand Up @@ -549,6 +560,7 @@ final class KnownTranslationKeys{
public const POCKETMINE_PERMISSION_COMMAND_UNBAN_IP = "pocketmine.permission.command.unban.ip";
public const POCKETMINE_PERMISSION_COMMAND_UNBAN_PLAYER = "pocketmine.permission.command.unban.player";
public const POCKETMINE_PERMISSION_COMMAND_VERSION = "pocketmine.permission.command.version";
public const POCKETMINE_PERMISSION_COMMAND_WEATHER = "pocketmine.permission.command.weather";
public const POCKETMINE_PERMISSION_COMMAND_WHITELIST_ADD = "pocketmine.permission.command.whitelist.add";
public const POCKETMINE_PERMISSION_COMMAND_WHITELIST_DISABLE = "pocketmine.permission.command.whitelist.disable";
public const POCKETMINE_PERMISSION_COMMAND_WHITELIST_ENABLE = "pocketmine.permission.command.whitelist.enable";
Expand Down
12 changes: 12 additions & 0 deletions generated/lang/KnownTranslationParameterInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ final class KnownTranslationParameterInfo{
Keys::COMMANDS_UNBANIP_INVALID => [],
Keys::COMMANDS_UNBANIP_SUCCESS => ["0"],
Keys::COMMANDS_UNBANIP_USAGE => [],
Keys::COMMANDS_WEATHER_CLEAR => [],
Keys::COMMANDS_WEATHER_DISABLED => [],
Keys::COMMANDS_WEATHER_QUERY => ["0"],
Keys::COMMANDS_WEATHER_QUERY_CLEAR => [],
Keys::COMMANDS_WEATHER_QUERY_RAIN => [],
Keys::COMMANDS_WEATHER_QUERY_THUNDER => [],
Keys::COMMANDS_WEATHER_RAIN => [],
Keys::COMMANDS_WEATHER_THUNDER => [],
Keys::COMMANDS_WHITELIST_ADD_SUCCESS => ["0"],
Keys::COMMANDS_WHITELIST_ADD_USAGE => [],
Keys::COMMANDS_WHITELIST_DISABLED => [],
Expand Down Expand Up @@ -446,6 +454,9 @@ final class KnownTranslationParameterInfo{
Keys::POCKETMINE_COMMAND_VERSION_SERVERSOFTWARENAME => ["serverSoftwareName"],
Keys::POCKETMINE_COMMAND_VERSION_SERVERSOFTWAREVERSION => ["serverSoftwareVersion", "serverGitHash"],
Keys::POCKETMINE_COMMAND_VERSION_USAGE => [],
Keys::POCKETMINE_COMMAND_WEATHER_DESCRIPTION => [],
Keys::POCKETMINE_COMMAND_WEATHER_DISABLE => [],
Keys::POCKETMINE_COMMAND_WEATHER_USAGE => [],
Keys::POCKETMINE_COMMAND_WHITELIST_DESCRIPTION => [],
Keys::POCKETMINE_COMMAND_XP_DESCRIPTION => [],
Keys::POCKETMINE_COMMAND_XP_USAGE => [],
Expand Down Expand Up @@ -552,6 +563,7 @@ final class KnownTranslationParameterInfo{
Keys::POCKETMINE_PERMISSION_COMMAND_UNBAN_IP => [],
Keys::POCKETMINE_PERMISSION_COMMAND_UNBAN_PLAYER => [],
Keys::POCKETMINE_PERMISSION_COMMAND_VERSION => [],
Keys::POCKETMINE_PERMISSION_COMMAND_WEATHER => [],
Keys::POCKETMINE_PERMISSION_COMMAND_WHITELIST_ADD => [],
Keys::POCKETMINE_PERMISSION_COMMAND_WHITELIST_DISABLE => [],
Keys::POCKETMINE_PERMISSION_COMMAND_WHITELIST_ENABLE => [],
Expand Down
12 changes: 12 additions & 0 deletions resources/translations/eng.ini
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ commands.unban.usage=/pardon <name>
commands.unbanip.invalid=You have entered an invalid IP address
commands.unbanip.success=Unbanned IP address {%0}
commands.unbanip.usage=/pardon-ip <address>
commands.weather.clear=Changing to clear weather
commands.weather.disabled=Weather Cycle isn't enabled in this world.
commands.weather.query=Weather state is: {%0}
commands.weather.query.clear=clear
commands.weather.query.rain=rain
commands.weather.query.thunder=thunder
commands.weather.rain=Changing to rainy weather
commands.weather.thunder=Changing to rain and thunder
commands.whitelist.add.success=Added {%0} to the whitelist
commands.whitelist.add.usage=/whitelist add <player>
commands.whitelist.disabled=Turned off the whitelist
Expand Down Expand Up @@ -437,6 +445,9 @@ pocketmine.command.version.plugin.website=Website: {%website}
pocketmine.command.version.serverSoftwareName=This server is running {%serverSoftwareName}
pocketmine.command.version.serverSoftwareVersion=Server version: {%serverSoftwareVersion} (git hash: {%serverGitHash})
pocketmine.command.version.usage=/version [plugin name]
pocketmine.command.weather.description=Sets the weather
pocketmine.command.weather.disable=Weather is disable in this world
pocketmine.command.weather.usage=/weather <clear|rain|thunder> [duration]
pocketmine.command.whitelist.description=Manages the list of players allowed to use this server
pocketmine.command.xp.description=Adds or removes player experience
pocketmine.command.xp.usage=/xp <experience[L]> [player]
Expand Down Expand Up @@ -543,6 +554,7 @@ pocketmine.permission.command.transferserver=Allows the user to transfer self to
pocketmine.permission.command.unban.ip=Allows the user to unban IP addresses
pocketmine.permission.command.unban.player=Allows the user to unban players
pocketmine.permission.command.version=Allows the user to view the version of the server
pocketmine.permission.command.weather=Allows the player to change the weather
pocketmine.permission.command.whitelist.add=Allows the user to add a player to the server whitelist
pocketmine.permission.command.whitelist.disable=Allows the user to disable the server whitelist
pocketmine.permission.command.whitelist.enable=Allows the user to enable the server whitelist
Expand Down
3 changes: 2 additions & 1 deletion src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,8 @@ public function __construct(
ServerProperties::AUTO_SAVE => true,
ServerProperties::VIEW_DISTANCE => self::DEFAULT_MAX_VIEW_DISTANCE,
ServerProperties::XBOX_AUTH => true,
ServerProperties::LANGUAGE => "eng"
ServerProperties::LANGUAGE => "eng",
ServerProperties::WEATHER_ENABLED => true
])
);

Expand Down
1 change: 1 addition & 0 deletions src/ServerProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ private function __construct(){
public const SERVER_PORT_IPV4 = "server-port";
public const SERVER_PORT_IPV6 = "server-portv6";
public const VIEW_DISTANCE = "view-distance";
public const WEATHER_ENABLED = "weather-enabled";
public const WHITELIST = "white-list";
public const XBOX_AUTH = "xbox-auth";
}
5 changes: 5 additions & 0 deletions src/block/Farmland.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ public function onEntityLand(Entity $entity) : ?float{
protected function canHydrate() : bool{
$world = $this->position->getWorld();

if($world->isRaining($this->position)){
$this->waterPositionIndex = self::WATER_POSITION_INDEX_UNKNOWN;
return true;
}

$startX = $this->position->getFloorX() - (int) (self::WATER_SEARCH_HORIZONTAL_LENGTH / 2);
$startY = $this->position->getFloorY();
$startZ = $this->position->getFloorZ() - (int) (self::WATER_SEARCH_HORIZONTAL_LENGTH / 2);
Expand Down
11 changes: 8 additions & 3 deletions src/block/Fire.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ public function onRandomTick() : void{
$canSpread = true;

if(!$down->burnsForever()){
//TODO: check rain
$world = $this->position->getWorld();
if($world->isRaining($this->position)){
return;
}

if($this->age === self::MAX_AGE){
if(!$down->isFlammable() && mt_rand(0, 3) === 3){ //1/4 chance to extinguish
$canSpread = false;
Expand Down Expand Up @@ -187,8 +191,9 @@ private function spreadFire() : void{
if($block->getTypeId() !== BlockTypeIds::AIR){
continue;
}

//TODO: fire can't spread if it's raining in any horizontally adjacent block, or the current one
if($world->isRaining($block->position)){
continue;
}

$encouragement = 0;
foreach($block->position->sides() as $vector3){
Expand Down
2 changes: 2 additions & 0 deletions src/block/LightningRod.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ final class LightningRod extends Transparent implements AnyFacing, CopperMateria
use CopperTrait;
use AnyFacingTrait;

// TODO: Add lightning attraction behavior when thunderstorms occur

protected function recalculateCollisionBoxes() : array{
$myAxis = Facing::axis($this->facing);

Expand Down
2 changes: 2 additions & 0 deletions src/command/SimpleCommandMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
use pocketmine\command\defaults\TransferServerCommand;
use pocketmine\command\defaults\VanillaCommand;
use pocketmine\command\defaults\VersionCommand;
use pocketmine\command\defaults\WeatherCommand;
use pocketmine\command\defaults\WhitelistCommand;
use pocketmine\command\defaults\XpCommand;
use pocketmine\command\utils\CommandStringHelper;
Expand Down Expand Up @@ -134,6 +135,7 @@ private function setDefaultCommands() : void{
new TitleCommand(),
new TransferServerCommand(),
new VersionCommand(),
new WeatherCommand(),
new WhitelistCommand(),
new XpCommand(),
]);
Expand Down
118 changes: 118 additions & 0 deletions src/command/defaults/WeatherCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/

declare(strict_types=1);

namespace pocketmine\command\defaults;

use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\KnownTranslationFactory;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\Player;
use pocketmine\utils\AssumptionFailedError;
use function count;
use function max;
use function strtolower;

class WeatherCommand extends VanillaCommand{

public function __construct(){
parent::__construct(
"weather",
KnownTranslationFactory::pocketmine_command_weather_description(),
KnownTranslationFactory::pocketmine_command_weather_usage(),
);
$this->setPermission(DefaultPermissionNames::COMMAND_WEATHER);
}

public function execute(CommandSender $sender, string $label, array $args) : void{
if($sender instanceof Player){
$world = $sender->getWorld();
}else{
$world = $sender->getServer()->getWorldManager()->getDefaultWorld();
}

if($world === null){
throw new AssumptionFailedError("Failed to retrieve world instance. Default world is not loaded.");
}

if(!$world->isWeatherEnabled()){
$sender->sendMessage(KnownTranslationFactory::pocketmine_command_weather_disable());
return;
}

if(count($args) < 1){
$rainLevel = $world->getRainLevel();
$thunderLevel = $world->getThunderLevel();

if($rainLevel > 0.0 && $thunderLevel > 0.0){
$current = "thunder";
}elseif($rainLevel > 0.0){
$current = "rain";
}else{
$current = "clear";
}

$stateName = match($current){
"clear" => KnownTranslationFactory::commands_weather_query_clear(),
"rain" => KnownTranslationFactory::commands_weather_query_rain(),
"thunder" => KnownTranslationFactory::commands_weather_query_thunder(),
};

$sender->sendMessage(KnownTranslationFactory::commands_weather_query($stateName));
return;
}

$type = match(strtolower($args[0])){
"clear" => "clear",
"rain" => "rain",
"thunder" => "thunder",
default => throw new InvalidCommandSyntaxException(),
};

$rainLevel = 0.0;
$thunderLevel = 0.0;
$duration = max(100, (int) ($args[1] ?? 6000));

switch($type){
case "rain":
$rainLevel = 1.0;
$thunderLevel = 0.0;
break;

case "thunder":
$rainLevel = 1.0;
$thunderLevel = 1.0;
break;
}
$world->setWeather($rainLevel, $thunderLevel, $duration);

Command::broadcastCommandMessage($sender,
match($type){
"clear" => KnownTranslationFactory::commands_weather_clear(),
"rain" => KnownTranslationFactory::commands_weather_rain(),
"thunder" => KnownTranslationFactory::commands_weather_thunder(),
}
);
}
}
5 changes: 5 additions & 0 deletions src/entity/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,11 @@ protected function doOnFireTick(int $tickDiff = 1) : bool{
return false;
}

$world = $this->getWorld();
if($world->isRaining($this->location)){
$this->extinguish(EntityExtinguishEvent::CAUSE_RAIN);
}

$this->fireTicks -= $tickDiff;

if(($this->fireTicks % 20 === 0) || $tickDiff > 20){
Expand Down
4 changes: 4 additions & 0 deletions src/entity/EntityFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ public function __construct(){
'ThrownTrident' //as above
]);

$this->register(LightningBolt::class, function(World $world, CompoundTag $nbt) : LightningBolt{
return new LightningBolt(Helper::parseLocation($nbt, $world), $nbt);
}, ['lightning_bolt', 'minecraft:lightning_bolt']);

$this->register(Squid::class, function(World $world, CompoundTag $nbt) : Squid{
return new Squid(Helper::parseLocation($nbt, $world), $nbt);
}, ['Squid', 'minecraft:squid']);
Expand Down
Loading