Skip to content

Commit ce80778

Browse files
authored
BlockSniper Version 1.1.0 (#26)
**New Types** - [x] Added CleanEntities brush type. - [x] Added Biome brush type. **New Brush Parameters** - [x] Added Decrementing brush. - [x] Added Biome brush. **Configuration** - [x] Made Brush item configurable. - [x] Made either resetting, or remaining at the same size with decrementing brush configurable. **Copy -> Paste** - [x] Implemented undo for pasting templates and copies. **API** - [x] Added BrushPropertiesChangeEvent. **Bug Fixes** - [x] Fixed Undo destroying management. - [x] Fixed multiworld Copying.
1 parent a567ff9 commit ce80778

28 files changed

Lines changed: 464 additions & 97 deletions

.github/ISSUE_TEMPLATE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
-->
66

77
#### Description
8-
<!--- Write a detailed description about the issue -->
8+
<!--- Write a detailed description about the issue. -->
99

1010
#### Versions
1111
* PocketMine version:
1212
* BlockSniper version:
1313
* Game version: PE/W10
1414

1515
#### Crashdump and/or console errors
16-
<!--- Insert in the code block below -->
16+
<!--- Insert in the code block below. -->
1717
```
1818
```
19-
<!--- Issues that do not follow this template will get closed immediatly, so make sure to follow it. -->
19+
<!--- Issues that do not follow this template will get closed immediatly, so make sure to follow it. If your issue is a suggestion or question, feel free to remove it however. -->

plugin.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ permissions:
6363
blocksniper.type.melt:
6464
default: op
6565
description: "Allows access to the melt type"
66+
blocksniper.type.cleanentities:
67+
default: op
68+
description: "Allows access to the clean entities type"
69+
blocksniper.type.biome:
70+
default: op
71+
description: "Allows access to the biome type"
6672
blocksniper.shape:
6773
default: false
6874
description: "Allows access to all BlockSniper shapes."

resources/settings.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
---
2-
# Configuration for BlockSniper: An innovative worldedit plugin by Sandertv.
2+
# Configuration for BlockSniper: A WorldEdit plugin for PocketMine.
3+
4+
# Language in which messages are displayed. Available languages:
5+
# en (English), nl (Dutch), de (German), fr (French), fa (Persian), ru (Russian), zh_tw (Chinese)
6+
Message-Language: ""
7+
8+
# Item ID of the item that is used to brush. (Golden carrot by default)
9+
Brush-Item: 396
310

411
# Maximum radius for shapes/types, it is recommended to keep this number below 20 to prevent server freezes and lag.
512
Maximum-Radius: 15
613

714
# Maximum undo stores to save, old ones will get destroyed automatically. Setting this number too high could result in lag or data loss.
815
Maximum-Undo-Stores: 7
916

10-
# Language in which messages are displayed. Available languages:
11-
# en (English), nl (Dutch), de (German), fr (French), fa (Persian), ru (Russian), zh_tw (Chinese)
12-
Message-Language: ""
17+
# Whether to reset the size, or make it remain the current size when smallest size with decrement brush is reached.
18+
Reset-Decrement-Brush: true
1319
...

src/Sandertv/BlockSniper/Loader.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
class Loader extends PluginBase {
1919

20-
const VERSION = "1.0.1";
21-
const API_TARGET = "2.1.0 - 3.0.0-ALPHA3";
20+
const VERSION = "1.1.0";
21+
const API_TARGET = "2.0.0 - 3.0.0-ALPHA3";
2222

2323
public $undoStore;
2424
public $cloneStore;
@@ -90,11 +90,16 @@ public function getSettings(): Config {
9090
}
9191

9292
public function registerCommands() {
93-
$this->getServer()->getCommandMap()->register("blocksniper", new BlockSniperCommand($this));
94-
$this->getServer()->getCommandMap()->register("brush", new BrushCommand($this));
95-
$this->getServer()->getCommandMap()->register("undo", new UndoCommand($this));
96-
$this->getServer()->getCommandMap()->register("clone", new CloneCommand($this));
97-
$this->getServer()->getCommandMap()->register("paste", new PasteCommand($this));
93+
$blockSniperCommands = [
94+
"blocksniper" => new BlockSniperCommand($this),
95+
"brush" => new BrushCommand($this),
96+
"undo" => new UndoCommand($this),
97+
"clone" => new CloneCommand($this),
98+
"paste" => new PasteCommand($this)
99+
];
100+
foreach($blockSniperCommands as $name => $class) {
101+
$this->getServer()->getCommandMap()->register($name, $class);
102+
}
98103
}
99104

100105
public function onDisable() {

src/Sandertv/BlockSniper/UndoStorer.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class UndoStorer {
1010

1111
public $totalStores = 0;
1212
public $undoStore = [];
13+
public $lastUndo;
1314

1415
public function __construct(Loader $owner) {
1516
$this->owner = $owner;
@@ -36,6 +37,8 @@ public function saveUndo(array $blocks) {
3637
$this->unsetFirstUndo(); // Unset the first undo to make sure the array won't get too big.
3738
}
3839
$this->getOwner()->getServer()->getScheduler()->scheduleDelayedTask(new UndoDiminishTask($this->getOwner()), 2400);
40+
41+
$this->lastUndo = time();
3942
}
4043

4144
/**
@@ -90,4 +93,11 @@ public function undoStorageExists() {
9093
public function getLastUndoBlockAmount() {
9194
return count($this->undoStore[max(array_keys($this->undoStore))]);
9295
}
96+
97+
/**
98+
* @return int
99+
*/
100+
public function getLastUndoActivity(): int {
101+
return (time() - $this->lastUndo);
102+
}
93103
}

src/Sandertv/BlockSniper/brush/BaseShape.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ abstract class BaseShape {
88

99
const MAX_WORLD_HEIGHT = 256;
1010
const MIN_WORLD_HEIGHT = 0;
11+
1112
const SHAPE_CUBE = 0;
12-
const SHAPE_SPHERE = 1, SHAPE_BALL = 1;
13-
const SHAPE_CYLINDER = 2, SHAPE_STANDING_CYLINDER = 2;
13+
const SHAPE_SPHERE = 1;
14+
const SHAPE_CYLINDER = 2;
1415
const SHAPE_CUBOID = 3;
15-
16+
1617
public function __construct(Loader $main) {
1718
$this->main = $main;
1819
}

src/Sandertv/BlockSniper/brush/BaseType.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@ abstract class BaseType {
88

99
const MAX_WORLD_HEIGHT = 256;
1010
const MIN_WORLD_HEIGHT = 0;
11+
12+
const TYPE_FILL = 0;
1113
const TYPE_OVERLAY = 1;
12-
const TYPE_LAYER = 2, TYPE_FLAT_LAYER = 2;
14+
const TYPE_LAYER = 2;
1315
const TYPE_REPLACE = 3;
14-
const TYPE_FLATTEN = 4, TYPE_EQUALIZE = 4;
16+
const TYPE_FLATTEN = 4;
1517
const TYPE_DRAIN = 5;
1618
const TYPE_LEAF_BLOWER = 6;
17-
const TYPE_CLEAN = 7, TYPE_CLEAR = 7;
19+
const TYPE_CLEAN = 7;
20+
const TYPE_BIOME = 8;
21+
const TYPE_CLEAN_ENTITIES = 9;
22+
const TYPE_MELT = 10;
23+
const TYPE_EXPAND = 11;
24+
1825
public $main;
19-
26+
2027
public function __construct(Loader $main) {
2128
$this->main = $main;
2229
}

src/Sandertv/BlockSniper/brush/Brush.php

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,30 @@
55
use pocketmine\block\Block;
66
use pocketmine\item\Item;
77
use pocketmine\Player;
8+
use ReflectionClass;
89
use Sandertv\BlockSniper\brush\shapes\CubeShape;
910
use Sandertv\BlockSniper\brush\shapes\CuboidShape;
1011
use Sandertv\BlockSniper\brush\shapes\CylinderStandingShape;
1112
use Sandertv\BlockSniper\brush\shapes\SphereShape;
13+
use Sandertv\BlockSniper\brush\types\BiomeType;
14+
use Sandertv\BlockSniper\brush\types\CleanEntitiesType;
1215
use Sandertv\BlockSniper\brush\types\CleanType;
1316
use Sandertv\BlockSniper\brush\types\DrainType;
17+
use Sandertv\BlockSniper\brush\types\ExpandType;
1418
use Sandertv\BlockSniper\brush\types\FillType;
1519
use Sandertv\BlockSniper\brush\types\FlattenType;
1620
use Sandertv\BlockSniper\brush\types\LayerType;
1721
use Sandertv\BlockSniper\brush\types\LeafBlowerType;
22+
use Sandertv\BlockSniper\brush\types\MeltType;
1823
use Sandertv\BlockSniper\brush\types\OverlayType;
1924
use Sandertv\BlockSniper\brush\types\ReplaceType;
20-
use Sandertv\BlockSniper\brush\types\ExpandType;
21-
use Sandertv\BlockSniper\brush\types\MeltType;
2225
use Sandertv\BlockSniper\Loader;
2326

2427
class Brush {
2528

2629
public static $brush = [];
2730
public static $owner;
31+
public static $resetSize = [];
2832

2933
public function __construct(Loader $owner) {
3034
self::$owner = $owner;
@@ -46,7 +50,10 @@ public static function setupDefaultValues(Player $player): bool {
4650
"size" => 1,
4751
"height" => 1,
4852
"blocks" => [Block::get(Block::STONE)],
49-
"obsolete" => Block::get(Block::AIR)
53+
"obsolete" => Block::get(Block::AIR),
54+
"gravity" => false,
55+
"decrement" => false,
56+
"biome" => "plains"
5057
];
5158
return true;
5259
}
@@ -66,6 +73,40 @@ public static function setBlocks(Player $player, array $blocks) {
6673
}
6774
}
6875

76+
/**
77+
* @param Player $player
78+
* @param $value
79+
*/
80+
public static function setDecrementing(Player $player, $value) {
81+
self::$brush[$player->getId()]["decrement"] = (bool)$value;
82+
}
83+
84+
/**
85+
* @param Player $player
86+
*
87+
* @return bool
88+
*/
89+
public static function isDecrementing(Player $player): bool {
90+
return self::$brush[$player->getId()]["decrement"];
91+
}
92+
93+
/**
94+
* @param Player $player
95+
* @param $value
96+
*/
97+
public static function setGravity(Player $player, $value) {
98+
self::$brush[$player->getId()]["gravity"] = (bool)$value;
99+
}
100+
101+
/**
102+
* @param Player $player
103+
*
104+
* @return bool
105+
*/
106+
public static function getGravity(Player $player): bool {
107+
return self::$brush[$player->getId()]["gravity"];
108+
}
109+
69110
/**
70111
* @param Player $player
71112
* @param $value
@@ -150,16 +191,16 @@ public static function getShape(Player $player): BaseShape {
150191
$shapeName = self::$brush[$player->getId()]["shape"];
151192
switch($shapeName) {
152193
case "cube":
153-
$shape = new CubeShape(self::$owner, $player->getLevel(), self::getSize($player), $player->getTargetBlock(100));
194+
$shape = new CubeShape(self::$owner, $player, $player->getLevel(), self::getSize($player), $player->getTargetBlock(100));
154195
break;
155196
case "sphere":
156197
$shape = new SphereShape(self::$owner, $player, $player->getLevel(), self::getSize($player), $player->getTargetBlock(100));
157198
break;
158199
case "cuboid":
159-
$shape = new CuboidShape(self::$owner, $player->getLevel(), self::getSize($player), self::getHeight($player), $player->getTargetBlock(100));
200+
$shape = new CuboidShape(self::$owner, $player, $player->getLevel(), self::getSize($player), self::getHeight($player), $player->getTargetBlock(100));
160201
break;
161202
case "cylinder":
162-
$shape = new CylinderStandingShape(self::$owner, $player->getLevel(), self::getSize($player), self::getHeight($player), $player->getTargetBlock(100));
203+
$shape = new CylinderStandingShape(self::$owner, $player, $player->getLevel(), self::getSize($player), self::getHeight($player), $player->getTargetBlock(100));
163204
break;
164205

165206
default:
@@ -193,7 +234,7 @@ public static function getHeight(Player $player): int {
193234
*
194235
* @return BaseType
195236
*/
196-
public static function getType(Player $player, array $blocks): BaseType {
237+
public static function getType(Player $player, array $blocks = []): BaseType {
197238
$typeName = self::$brush[$player->getId()]["type"];
198239
switch($typeName) {
199240
case "fill":
@@ -226,7 +267,35 @@ public static function getType(Player $player, array $blocks): BaseType {
226267
case "melt":
227268
$type = new MeltType(self::$owner, $player, $player->getLevel(), $blocks);
228269
break;
270+
case "cleanentities":
271+
$type = new CleanEntitiesType(self::$owner, $player, $player->getLevel(), $blocks);
272+
break;
273+
case "biome":
274+
$type = new BiomeType(self::$owner, $player, $player->getLevel(), $blocks);
275+
break;
276+
277+
default:
278+
$type = new FillType(self::$owner, $player, $player->getLevel(), $blocks);
279+
break;
229280
}
230281
return $type;
231282
}
283+
284+
/**
285+
* @param Player $player
286+
* @param string $biome
287+
*/
288+
public static function setBiome(Player $player, string $biome) {
289+
self::$brush[$player->getId()]["biome"] = $biome;
290+
}
291+
292+
public static function getBiomeIdFromString(Player $player): int {
293+
$biomes = new ReflectionClass('pocketmine\level\generator\biome\Biome');
294+
$const = strtoupper(str_replace(" ", "_", self::$brush[$player->getId()]["biome"]));
295+
if($biomes->hasConstant($const)) {
296+
$biome = $biomes->getConstant($const);
297+
return $biome;
298+
}
299+
return 0;
300+
}
232301
}

src/Sandertv/BlockSniper/brush/shapes/CubeShape.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,26 @@
33
namespace Sandertv\BlockSniper\brush\shapes;
44

55
use pocketmine\level\Level;
6-
use pocketmine\math\Vector3;
76
use pocketmine\level\Position;
7+
use pocketmine\math\Vector3;
8+
use pocketmine\Player;
89
use Sandertv\BlockSniper\brush\BaseShape;
10+
use Sandertv\BlockSniper\brush\Brush;
911
use Sandertv\BlockSniper\Loader;
1012

1113
class CubeShape extends BaseShape {
1214

1315
public $level;
1416
public $radius;
1517
public $center;
18+
public $player;
1619

17-
public function __construct(Loader $main, Level $level, float $radius = null, Position $center = null) {
20+
public function __construct(Loader $main, Player $player, Level $level, float $radius = null, Position $center = null) {
1821
parent::__construct($main);
1922
$this->level = $level;
2023
$this->radius = $radius;
2124
$this->center = $center;
25+
$this->player = $player;
2226
}
2327

2428
/**
@@ -30,18 +34,21 @@ public function getBlocksInside(): array {
3034
$targetZ = $this->center->z;
3135

3236
$minX = $targetX - $this->radius;
33-
$minY = $targetY - $this->radius;
3437
$minZ = $targetZ - $this->radius;
38+
$minY = $targetY - $this->radius;
3539
$maxX = $targetX + $this->radius;
36-
$maxY = $targetY + $this->radius;
3740
$maxZ = $targetZ + $this->radius;
38-
41+
$maxY = $targetY + $this->radius;
3942
$blocksInside = [];
4043

4144
for($x = $minX; $x <= $maxX; $x++) {
42-
for($y = $minY; $y <= $maxY; $y++) {
43-
for($z = $minZ; $z <= $maxZ; $z++) {
44-
$blocksInside[] = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
45+
for($z = $minZ; $z <= $maxZ; $z++) {
46+
for($y = $minY; $y <= $maxY; $y++) {
47+
if(Brush::getGravity($this->player) === true || Brush::getGravity($this->player) === 1) {
48+
$gravityY = ($this->level->getHighestBlockAt($x, $z) + 1) <= $maxY ? $this->level->getHighestBlockAt($x, $z) + 1 : $y;
49+
}
50+
$blocksInside[] = $this->getLevel()->getBlock(new Vector3($x, (isset($gravityY) ? $gravityY : $y), $z));
51+
unset($temporalY);
4552
}
4653
}
4754
}

0 commit comments

Comments
 (0)