Skip to content
This repository was archived by the owner on Dec 12, 2022. It is now read-only.

Commit c0311e0

Browse files
committed
feat: code cleanup
1 parent 60ac993 commit c0311e0

7 files changed

Lines changed: 118 additions & 92 deletions

File tree

README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
# WoolVolcano
22

3-
## Installation:
4-
- Download the latest version [here](https://github.com/Josscoder/WoolVolcano/releases/latest).
5-
- Put the WoolVolcano_v1.phar inside plugins/.
6-
- Start the server.
3+
Victory effect for your Minecraft BE server, inspired by Cubecraft, for Pocketmine 4.0.0
4+
5+
If you encounter any bugs, have suggestions or questions, [create an issue](https://github.com/Josscoder/WoolVolcano/issues/new).
6+
7+
## Setup
8+
9+
1) Download the latest version [here](https://github.com/Josscoder/WoolVolcano/releases/latest)
10+
2) Put the .phar in your plugins folder
11+
3) And finally, start your server!
712

813
## How can I preview?
9-
Only op users can type "volcano" without quotes in chat.
14+
15+
Only operator players can write "volcano" without quotes in the server chat.
1016
[Here](https://twitter.com/Josscoder/status/1397231329180364801) is an example video
1117

1218
## For developers
13-
To give the player the win effect, do:
14-
````
15-
WoolVolcano::getInstance()->giveTo($player);
19+
20+
With the following code you can give the win effect to the player:
21+
````php
22+
\jossc\volcano\Main::getInstance()->giveTo($player);
1623
````

plugin.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
name: WoolVolcano
2-
main: jossc\volcano\WoolVolcano
1+
name: Main
2+
main: jossc\volcano\Main
33
api: 4.0.0
4-
version: 1.0
4+
version: 1.1
55
author: Josscoder
Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace jossc\volcano;
44

5-
use jossc\volcano\entity\FallingWool;
5+
use jossc\volcano\entity\CustomFallingWoolBlock;
66
use jossc\volcano\listener\EventListener;
77
use jossc\volcano\task\VolcanoTak;
88
use pocketmine\block\BlockFactory;
@@ -15,40 +15,44 @@
1515
use pocketmine\utils\TextFormat;
1616
use pocketmine\world\World;
1717

18-
class WoolVolcano extends PluginBase {
18+
class Main extends PluginBase {
1919

20-
/*** @var WoolVolcano */
21-
private static $instance;
22-
23-
/*** @return WoolVolcano */
24-
public static function getInstance(): WoolVolcano {
25-
return self::$instance;
26-
}
20+
/*** @var Main */
21+
private static $main;
2722

2823
protected function onEnable(): void{
29-
self::$instance = $this;
24+
self::$main = $this;
3025

3126
$this->registerEntity();
32-
$this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this);
27+
28+
$this->getServer()->getPluginManager()->registerEvents(
29+
new EventListener($this),
30+
$this
31+
);
3332

3433
$this->getLogger()->info(TextFormat::GREEN . 'This plugin has been enabled!.');
3534
}
3635

3736
private function registerEntity(): void {
38-
EntityFactory::getInstance()->register(FallingWool::class,
39-
function(World $world, CompoundTag $nbt) : FallingWool {
40-
return new FallingWool(
37+
EntityFactory::getInstance()->register(CustomFallingWoolBlock::class,
38+
function(World $world, CompoundTag $nbt) : CustomFallingWoolBlock {
39+
return new CustomFallingWoolBlock(
4140
EntityDataHelper::parseLocation($nbt, $world),
4241
BlockFactory::getInstance()->get(BlockLegacyIds::WOOL, 0),
4342
$nbt
4443
);
45-
}, ['FallingWool', 'minecraft:falling_wool_entity']);
44+
}, ['CustomFallingWoolBlock', 'minecraft:falling_wool_block_entity']);
45+
}
46+
47+
/*** @return Main */
48+
public static function getInstance(): Main {
49+
return self::$main;
4650
}
4751

4852
/*** @param Player $player */
4953
public function giveTo(Player $player): void {
5054
$this->getScheduler()->scheduleDelayedRepeatingTask(
51-
new VolcanoTak($player, $player->getWorld()), 0, 2
55+
new VolcanoTak($player, $player->getWorld()), 1, 3
5256
);
5357
}
5458

src/jossc/volcano/entity/FallingWool.php renamed to src/jossc/volcano/entity/CustomFallingWoolBlock.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,19 @@
33
namespace jossc\volcano\entity;
44

55
use pocketmine\entity\object\FallingBlock;
6+
use pocketmine\nbt\tag\CompoundTag;
67

7-
class FallingWool extends FallingBlock {
8+
class CustomFallingWoolBlock extends FallingBlock {
9+
10+
/*** @param CompoundTag $nbt */
11+
protected function initEntity(CompoundTag $nbt): void
12+
{
13+
parent::initEntity($nbt);
14+
15+
$this->setForceMovementUpdate(true);
16+
$this->setSilent(true);
17+
$this->setCanSaveWithChunk(false);
18+
}
819

920
/**
1021
* @param int $tickDiff

src/jossc/volcano/listener/EventListener.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
namespace jossc\volcano\listener;
44

5-
use jossc\volcano\WoolVolcano;
5+
use jossc\volcano\Main;
66
use pocketmine\event\Listener;
77
use pocketmine\event\player\PlayerChatEvent;
88

99
class EventListener implements Listener {
1010

11-
/*** @var WoolVolcano */
12-
private $instance;
11+
/*** @var Main */
12+
private $main;
1313

1414
/**
1515
* EventListener constructor.
16-
* @param WoolVolcano $instance
16+
* @param Main $main
1717
*/
18-
public function __construct(WoolVolcano $instance) {
19-
$this->instance = $instance;
18+
public function __construct(Main $main) {
19+
$this->main = $main;
2020
}
2121

2222
/*** @param PlayerChatEvent $event */
@@ -33,6 +33,6 @@ public function PlayerChatEvent(PlayerChatEvent $event): void {
3333

3434
$event->cancel();
3535

36-
$this->instance->giveTo($player);
36+
$this->main->giveTo($player);
3737
}
3838
}

src/jossc/volcano/task/VolcanoTak.php

Lines changed: 27 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@
22

33
namespace jossc\volcano\task;
44

5-
use jossc\volcano\entity\FallingWool;
5+
use jossc\volcano\entity\CustomFallingWoolBlock;
66
use jossc\volcano\utils\Utils;
7-
use pocketmine\block\BlockFactory;
8-
use pocketmine\block\BlockLegacyIds;
9-
use pocketmine\entity\EntityDataHelper;
10-
use pocketmine\entity\Location;
11-
use pocketmine\math\Vector3;
127
use pocketmine\player\Player;
138
use pocketmine\scheduler\Task;
149
use pocketmine\world\World;
@@ -17,10 +12,13 @@ class VolcanoTak extends Task {
1712

1813
/*** @var Player */
1914
private $player;
15+
2016
/*** @var World */
2117
private $world;
18+
2219
/*** @var array */
2320
private $fallingBlocks = [];
21+
2422
/*** @var int */
2523
private $amount = 100;
2624

@@ -34,69 +32,41 @@ public function __construct(Player $player, World $world) {
3432
$this->world = $world;
3533
}
3634

37-
/*** @return bool */
38-
private function isExecutable(): bool {
39-
$player = $this->player;
40-
$amount = $this->amount;
35+
public function onRun(): void {
36+
if ($this->isExecutable()) {
4137

42-
return ($amount >= 1) &&
43-
($player->isOnline()) &&
44-
($player->getWorld() === $this->world);
45-
}
38+
$location = $this->player->getLocation();
4639

47-
public function onRun(): void {
48-
if (!$this->isExecutable()) {
49-
$this->getHandler()->cancel();
40+
$fallingWool = Utils::generateFallingWoolBlock($location);
41+
array_push($this->fallingBlocks, $fallingWool);
5042

51-
foreach ($this->fallingBlocks as $fallingBlock) {
52-
if (!$fallingBlock instanceof FallingWool) {
53-
continue;
54-
}
43+
Utils::playSound("liquid.lavapop", $this->player);
5544

56-
if (!$fallingBlock->isFlaggedForDespawn()) {
57-
$fallingBlock->flagForDespawn();
58-
}
59-
}
45+
$this->amount--;
6046

6147
return;
6248
}
6349

64-
$player = $this->player;
65-
$location = $player->getLocation();
66-
$fallingWool = $this->generateFallingWool($location);
67-
array_push($this->fallingBlocks, $fallingWool);
50+
$this->getHandler()->cancel();
6851

69-
Utils::playSound("liquid.lavapop", $player);
52+
foreach ($this->fallingBlocks as $fallingBlock) {
53+
if (!$fallingBlock instanceof CustomFallingWoolBlock) {
54+
continue;
55+
}
7056

71-
$this->amount--;
57+
if (!$fallingBlock->isFlaggedForDespawn()) {
58+
$fallingBlock->flagForDespawn();
59+
}
60+
}
7261
}
7362

74-
/**
75-
* @param Location $location
76-
* @return FallingWool
77-
*/
78-
private function generateFallingWool(Location $location): FallingWool {
79-
$nbt = EntityDataHelper::createBaseNBT($location->asVector3());
80-
81-
$meta = rand(0, 15);
82-
$fallingBlock = new FallingWool(
83-
$location,
84-
BlockFactory::getInstance()->get(BlockLegacyIds::WOOL, $meta),
85-
$nbt
86-
);
87-
88-
$fallingBlock->setMotion(new Vector3(
89-
-sin(mt_rand(1, 360) /60 * M_PI),
90-
0.95,
91-
cos(mt_rand(1, 360) / 60 * M_PI))
92-
);
93-
94-
$fallingBlock->setForceMovementUpdate(true);
95-
$fallingBlock->setSilent(true);
96-
$fallingBlock->setCanSaveWithChunk(false);
97-
98-
$fallingBlock->spawnToAll();
63+
/*** @return bool */
64+
private function isExecutable(): bool {
65+
$player = $this->player;
66+
$amount = $this->amount;
9967

100-
return $fallingBlock;
68+
return ($amount >= 1) &&
69+
($player->isOnline()) &&
70+
($player->getWorld() === $this->world);
10171
}
10272
}

src/jossc/volcano/utils/Utils.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,45 @@
22

33
namespace jossc\volcano\utils;
44

5+
use jossc\volcano\entity\CustomFallingWoolBlock;
6+
use pocketmine\block\BlockFactory;
7+
use pocketmine\block\BlockLegacyIds;
8+
use pocketmine\entity\EntityDataHelper;
9+
use pocketmine\entity\Location;
10+
use pocketmine\math\Vector3;
511
use pocketmine\network\mcpe\protocol\PlaySoundPacket;
612
use pocketmine\player\Player;
713

814
class Utils {
915

16+
/**
17+
* @param Location $location
18+
* @return CustomFallingWoolBlock
19+
*/
20+
public static function generateFallingWoolBlock(Location $location): CustomFallingWoolBlock {
21+
$nbt = EntityDataHelper::createBaseNBT($location->asVector3());
22+
23+
$fallingBlock = new CustomFallingWoolBlock(
24+
$location,
25+
BlockFactory::getInstance()->get(BlockLegacyIds::WOOL, rand(0, 15)),
26+
$nbt
27+
);
28+
29+
$fallingBlock->setMotion(new Vector3(
30+
-sin(mt_rand(1, 360) / 60 * M_PI),
31+
0.95,
32+
cos(mt_rand(1, 360) / 60 * M_PI))
33+
);
34+
35+
$fallingBlock->spawnToAll();
36+
37+
return $fallingBlock;
38+
}
39+
40+
/**
41+
* @param string $soundName
42+
* @param Player $player
43+
*/
1044
public static function playSound(string $soundName, Player $player): void {
1145
$location = $player->getLocation();
1246

0 commit comments

Comments
 (0)