diff --git a/README.md b/README.md index 444d6fb..b5ab5d5 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ Please report bugs on the issues page on GitHub. - Hunger - Fly - Daylight cycle + - Leaves decay - You have an idea what to add? Feel free to open an issue. - **DEFAULT VALUES** Set default values for worlds without settings - **SOPHISTICATED** Easy to use, fast and mostly bug-free. @@ -83,15 +84,15 @@ Worlds is really easy to use. Here is the command syntax: /worlds set legacy /worlds set permission /worlds set gamemode -/worlds set +/worlds set /worlds unset -/worlds unset +/worlds unset /worlds defaults /worlds defaults legacy /worlds defaults set permission /worlds defaults set gamemode -/worlds defaults set -/worlds defaults unset +/worlds defaults set +/worlds defaults unset ``` For a full list of commands, their usage and a description what they are for, take a look at the [wiki](https://plugins.surva.net/docs/Worlds#commands). diff --git a/plugin.yml b/plugin.yml index a6b3fa2..ff8c2f1 100644 --- a/plugin.yml +++ b/plugin.yml @@ -10,7 +10,7 @@ website: https://plugins.surva.net/#worlds commands: worlds: description: "Worlds plugin main command" - usage: "/worlds list\n/worlds create [type]\n/worlds \n/worlds \n/worlds set\n/worlds set legacy\n/worlds set permission \n/worlds set gamemode \n/worlds set \n/worlds unset\n/worlds unset \n/worlds defaults\n/worlds defaults legacy\n/worlds defaults set permission \n/worlds defaults set gamemode \n/worlds defaults set \n/worlds defaults unset " + usage: "/worlds list\n/worlds create [type]\n/worlds \n/worlds \n/worlds set\n/worlds set legacy\n/worlds set permission \n/worlds set gamemode \n/worlds set \n/worlds unset\n/worlds unset \n/worlds defaults\n/worlds defaults legacy\n/worlds defaults set permission \n/worlds defaults set gamemode \n/worlds defaults set \n/worlds defaults unset " aliases: ["ws"] permissions: worlds.list: diff --git a/resources/languages/de.yml b/resources/languages/de.yml index 2496dd0..60d50d6 100644 --- a/resources/languages/de.yml +++ b/resources/languages/de.yml @@ -110,6 +110,7 @@ forms: hunger: "Hunger" fly: "Fliegen" daylightcycle: "Tag-Nacht-Zyklus" + leavesdecay: "Blätter verwesen" options: notset: "§7nicht eingestellt (kein Wert)" true: "§aaktiviert" diff --git a/resources/languages/en.yml b/resources/languages/en.yml index bbf34c8..79dae28 100644 --- a/resources/languages/en.yml +++ b/resources/languages/en.yml @@ -110,6 +110,7 @@ forms: hunger: "Hunger" fly: "Flying" daylightcycle: "Daylight cycling" + leavesdecay: "Leaves decay" options: notset: "§7not set (null)" true: "§aenabled" diff --git a/src/surva/worlds/EventListener.php b/src/surva/worlds/EventListener.php index 7bae484..295dec9 100644 --- a/src/surva/worlds/EventListener.php +++ b/src/surva/worlds/EventListener.php @@ -10,6 +10,7 @@ use pocketmine\entity\object\Painting; use pocketmine\event\block\BlockBreakEvent; use pocketmine\event\block\BlockPlaceEvent; +use pocketmine\event\block\LeavesDecayEvent; use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityLevelChangeEvent; @@ -305,6 +306,20 @@ public function onPlayerInteract(PlayerInteractEvent $event): void } } + /** + * @param \pocketmine\event\block\LeavesDecayEvent $event + */ + public function onLeavesDecay(LeavesDecayEvent $event): void + { + $foldername = $event->getBlock()->getLevel()->getFolderName(); + + if ($world = $this->getWorlds()->getWorldByName($foldername)) { + if ($world->getLeavesDecay() === false) { + $event->setCancelled(); + } + } + } + /** * @return Worlds */ diff --git a/src/surva/worlds/commands/DefaultsCommand.php b/src/surva/worlds/commands/DefaultsCommand.php index 7372053..b6b7ad6 100644 --- a/src/surva/worlds/commands/DefaultsCommand.php +++ b/src/surva/worlds/commands/DefaultsCommand.php @@ -52,6 +52,7 @@ public function do(CommandSender $sender, array $args): bool "hunger" => $this->formatBool($defaults->getHunger()), "fly" => $this->formatBool($defaults->getFly()), "daylightcycle" => $this->formatBool($defaults->getDaylightCycle()), + "leavesdecay" => $this->formatBool($defaults->getLeavesDecay()), ] ) ); diff --git a/src/surva/worlds/commands/SetCommand.php b/src/surva/worlds/commands/SetCommand.php index e37ad4c..cbf2ec7 100644 --- a/src/surva/worlds/commands/SetCommand.php +++ b/src/surva/worlds/commands/SetCommand.php @@ -58,6 +58,7 @@ public function do(CommandSender $sender, array $args): bool "hunger" => $this->formatBool($world->getHunger()), "fly" => $this->formatBool($world->getFly()), "daylightcycle" => $this->formatBool($world->getDaylightCycle()), + "leavesdecay" => $this->formatBool($world->getLeavesDecay()), ] ) ); diff --git a/src/surva/worlds/form/DefaultSettingsForm.php b/src/surva/worlds/form/DefaultSettingsForm.php index c59e349..6a5740a 100644 --- a/src/surva/worlds/form/DefaultSettingsForm.php +++ b/src/surva/worlds/form/DefaultSettingsForm.php @@ -121,6 +121,16 @@ public function __construct(Worlds $wsInstance, Defaults $defaults) ], "default" => $this->convBool($defaults->getDaylightCycle()), ], + [ + "type" => "dropdown", + "text" => $this->getWorlds()->getMessage("forms.world.params.leavesdecay"), + "options" => [ + $this->getWorlds()->getMessage("forms.world.options.notset"), + $this->getWorlds()->getMessage("forms.world.options.false"), + $this->getWorlds()->getMessage("forms.world.options.true"), + ], + "default" => $this->convBool($defaults->getLeavesDecay()), + ], ]; } @@ -136,7 +146,7 @@ public function handleResponse(Player $player, $data): void return; } - if (count($data) !== 10) { + if (count($data) !== 11) { return; } @@ -150,6 +160,7 @@ public function handleResponse(Player $player, $data): void $this->procBool("hunger", $data[7]); $this->procBool("fly", $data[8]); $this->procBool("daylightcycle", $data[9]); + $this->procBool("leavesdecay", $data[10]); $player->sendMessage($this->getWorlds()->getMessage("forms.saved")); } diff --git a/src/surva/worlds/form/WorldSettingsForm.php b/src/surva/worlds/form/WorldSettingsForm.php index 6ea8a95..7b55ff2 100644 --- a/src/surva/worlds/form/WorldSettingsForm.php +++ b/src/surva/worlds/form/WorldSettingsForm.php @@ -126,6 +126,16 @@ public function __construct(Worlds $wsInstance, string $worldName, World $world) ], "default" => $this->convBool($world->getDaylightCycle()), ], + [ + "type" => "dropdown", + "text" => $this->getWorlds()->getMessage("forms.world.params.leavesdecay"), + "options" => [ + $this->getWorlds()->getMessage("forms.world.options.notset"), + $this->getWorlds()->getMessage("forms.world.options.false"), + $this->getWorlds()->getMessage("forms.world.options.true"), + ], + "default" => $this->convBool($world->getLeavesDecay()), + ], ]; } @@ -141,7 +151,7 @@ public function handleResponse(Player $player, $data): void return; } - if (count($data) !== 11) { + if (count($data) !== 12) { return; } @@ -161,6 +171,7 @@ public function handleResponse(Player $player, $data): void $this->procBool("hunger", $data[8]); $this->procBool("fly", $data[9]); $this->procBool("daylightcycle", $data[10]); + $this->procBool("leavesdecay", $data[11]); $player->sendMessage($this->getWorlds()->getMessage("forms.saved")); } diff --git a/src/surva/worlds/logic/WorldActions.php b/src/surva/worlds/logic/WorldActions.php index f30e300..85a74c7 100644 --- a/src/surva/worlds/logic/WorldActions.php +++ b/src/surva/worlds/logic/WorldActions.php @@ -52,6 +52,7 @@ public static function isValidFlag(string $flagName): bool "hunger", "fly", "daylightcycle", + "leavesdecay", ] ); } diff --git a/src/surva/worlds/types/World.php b/src/surva/worlds/types/World.php index 33e6616..83e1bff 100644 --- a/src/surva/worlds/types/World.php +++ b/src/surva/worlds/types/World.php @@ -50,6 +50,9 @@ class World /* @var bool|null */ protected $daylightcycle; + /* @var bool|null */ + protected $leavesdecay; + public function __construct(Worlds $worlds, Config $config) { $this->worlds = $worlds; @@ -74,6 +77,7 @@ public function loadItems(): void $this->loadValue("hunger"); $this->loadValue("fly"); $this->loadValue("daylightcycle"); + $this->loadValue("leavesdecay"); } /** @@ -135,6 +139,14 @@ public function removeValue(string $name): void $this->loadItems(); } + /** + * @return bool|null + */ + public function getLeavesDecay(): ?bool + { + return $this->leavesdecay; + } + /** * @return bool|null */