Skip to content

Commit

Permalink
Added leaves decay #69
Browse files Browse the repository at this point in the history
  • Loading branch information
jarne committed Aug 8, 2021
1 parent f461e61 commit 0ee9560
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 7 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -83,15 +84,15 @@ Worlds is really easy to use. Here is the command syntax:
/worlds set legacy
/worlds set permission <permissionstring>
/worlds set gamemode <survival|creative|adventure|spectator>
/worlds set <build|pvp|damage|interact|explode|drop|hunger|fly|daylightcycle> <true|false>
/worlds set <build|pvp|damage|interact|explode|drop|hunger|fly|daylightcycle|leavesdecay> <true|false>
/worlds unset
/worlds unset <permission|gamemode|build|pvp|damage|interact|explode|drop|hunger|fly|daylightcycle>
/worlds unset <permission|gamemode|build|pvp|damage|interact|explode|drop|hunger|fly|daylightcycle|leavesdecay>
/worlds defaults
/worlds defaults legacy
/worlds defaults set permission <permissionstring>
/worlds defaults set gamemode <survival|creative|adventure|spectator>
/worlds defaults set <build|pvp|damage|interact|explode|drop|hunger|fly|daylightcycle> <true|false>
/worlds defaults unset <permission|gamemode|build|pvp|damage|interact|explode|drop|hunger|fly|daylightcycle>
/worlds defaults set <build|pvp|damage|interact|explode|drop|hunger|fly|daylightcycle|leavesdecay> <true|false>
/worlds defaults unset <permission|gamemode|build|pvp|damage|interact|explode|drop|hunger|fly|daylightcycle|leavesdecay>
```

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).
Expand Down
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ website: https://plugins.surva.net/#worlds
commands:
worlds:
description: "Worlds plugin main command"
usage: "/worlds list\n/worlds create <worldname> [type]\n/worlds <remove|load|unload|tp> <worldname>\n/worlds <copy|rename> <from> <to>\n/worlds set\n/worlds set legacy\n/worlds set permission <permissionstring>\n/worlds set gamemode <survival|creative|adventure|spectator>\n/worlds set <build|pvp|damage|interact|explode|drop|hunger|fly|daylightcycle> <true|false>\n/worlds unset\n/worlds unset <permission|gamemode|build|pvp|damage|interact|explode|drop|hunger|fly|daylightcycle>\n/worlds defaults\n/worlds defaults legacy\n/worlds defaults set permission <permissionstring>\n/worlds defaults set gamemode <survival|creative|adventure|spectator>\n/worlds defaults set <build|pvp|damage|interact|explode|drop|hunger|fly|daylightcycle> <true|false>\n/worlds defaults unset <permission|gamemode|build|pvp|damage|interact|explode|drop|hunger|fly|daylightcycle>"
usage: "/worlds list\n/worlds create <worldname> [type]\n/worlds <remove|load|unload|tp> <worldname>\n/worlds <copy|rename> <from> <to>\n/worlds set\n/worlds set legacy\n/worlds set permission <permissionstring>\n/worlds set gamemode <survival|creative|adventure|spectator>\n/worlds set <build|pvp|damage|interact|explode|drop|hunger|fly|daylightcycle|leavesdecay> <true|false>\n/worlds unset\n/worlds unset <permission|gamemode|build|pvp|damage|interact|explode|drop|hunger|fly|daylightcycle|leavesdecay>\n/worlds defaults\n/worlds defaults legacy\n/worlds defaults set permission <permissionstring>\n/worlds defaults set gamemode <survival|creative|adventure|spectator>\n/worlds defaults set <build|pvp|damage|interact|explode|drop|hunger|fly|daylightcycle|leavesdecay> <true|false>\n/worlds defaults unset <permission|gamemode|build|pvp|damage|interact|explode|drop|hunger|fly|daylightcycle|leavesdecay>"
aliases: ["ws"]
permissions:
worlds.list:
Expand Down
1 change: 1 addition & 0 deletions resources/languages/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions resources/languages/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ forms:
hunger: "Hunger"
fly: "Flying"
daylightcycle: "Daylight cycling"
leavesdecay: "Leaves decay"
options:
notset: "§7not set (null)"
true: "§aenabled"
Expand Down
15 changes: 15 additions & 0 deletions src/surva/worlds/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down
1 change: 1 addition & 0 deletions src/surva/worlds/commands/DefaultsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
]
)
);
Expand Down
1 change: 1 addition & 0 deletions src/surva/worlds/commands/SetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
]
)
);
Expand Down
13 changes: 12 additions & 1 deletion src/surva/worlds/form/DefaultSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
],
];
}

Expand All @@ -136,7 +146,7 @@ public function handleResponse(Player $player, $data): void
return;
}

if (count($data) !== 10) {
if (count($data) !== 11) {
return;
}

Expand All @@ -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"));
}
Expand Down
13 changes: 12 additions & 1 deletion src/surva/worlds/form/WorldSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
],
];
}

Expand All @@ -141,7 +151,7 @@ public function handleResponse(Player $player, $data): void
return;
}

if (count($data) !== 11) {
if (count($data) !== 12) {
return;
}

Expand All @@ -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"));
}
Expand Down
1 change: 1 addition & 0 deletions src/surva/worlds/logic/WorldActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public static function isValidFlag(string $flagName): bool
"hunger",
"fly",
"daylightcycle",
"leavesdecay",
]
);
}
Expand Down
12 changes: 12 additions & 0 deletions src/surva/worlds/types/World.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -74,6 +77,7 @@ public function loadItems(): void
$this->loadValue("hunger");
$this->loadValue("fly");
$this->loadValue("daylightcycle");
$this->loadValue("leavesdecay");
}

/**
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 0ee9560

Please sign in to comment.