Skip to content

Commit 19ff9ab

Browse files
committed
Merge branch 'master' of https://github.com/Sandertv/BlockSniper
2 parents a0a2d08 + cefbbd3 commit 19ff9ab

22 files changed

Lines changed: 284 additions & 183 deletions

plugin.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: "BlockSniper"
3-
version: 1.0.1
3+
version: 1.2.0
44
api: [2.0.0, 2.1.0, 3.0.0-ALPHA1, 3.0.0-ALPHA2, 3.0.0-ALPHA3]
55
author: "Sandertv"
66
main: Sandertv\BlockSniper\Loader
@@ -69,6 +69,9 @@ permissions:
6969
blocksniper.type.biome:
7070
default: op
7171
description: "Allows access to the biome type"
72+
blocksniper.type.raise:
73+
default: op
74+
description: "Allows access to the raise type"
7275
blocksniper.shape:
7376
default: false
7477
description: "Allows access to all BlockSniper shapes."

resources/settings.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Brush-Item: 396
1212
Maximum-Radius: 15
1313

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

1717
# Whether to reset the size, or make it remain the current size when smallest size with decrement brush is reached.
1818
Reset-Decrement-Brush: true

src/Sandertv/BlockSniper/Loader.php

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

1818
class Loader extends PluginBase {
1919

20-
const VERSION = "1.1.0";
20+
const VERSION = "1.2.0";
2121
const API_TARGET = "2.0.0 - 3.0.0-ALPHA3";
2222

2323
public $undoStore;
@@ -37,7 +37,13 @@ class Loader extends PluginBase {
3737
public $language;
3838

3939
public function onEnable() {
40-
$this->getLogger()->info(TF::GREEN . "BlockSniper has been enabled.");
40+
$this->reloadAll();
41+
42+
$this->registerCommands();
43+
$this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this);
44+
}
45+
46+
public function reloadAll() {
4147
$this->brush = new Brush($this);
4248
$this->undoStore = new UndoStorer($this);
4349
$this->cloneStore = new CloneStorer($this);
@@ -47,21 +53,18 @@ public function onEnable() {
4753
if(!is_dir($this->getDataFolder() . "templates/")) {
4854
mkdir($this->getDataFolder() . "templates/");
4955
}
50-
$this->saveResource("settings.yml");
51-
$this->settings = new Config($this->getDataFolder() . "settings.yml", Config::YAML);
52-
53-
// Language file setup
5456
if(!is_dir($this->getDataFolder() . "languages/")) {
5557
mkdir($this->getDataFolder() . "languages/");
5658
}
59+
60+
$this->saveResource("settings.yml");
61+
$this->settings = new Config($this->getDataFolder() . "settings.yml", Config::YAML);
62+
5763
if(!$this->setupLanguageFile()) {
5864
$this->getLogger()->info(TF::AQUA . "[BlockSniper] No valid language selected, English has been auto-selected.\n" . TF::AQUA . "Please setup a language by using /blocksniper language <lang>.");
5965
} else {
6066
$this->getLogger()->info(TF::AQUA . "[BlockSniper] Language selected: " . TF::GREEN . $this->getSettings()->get("Message-Language"));
6167
}
62-
63-
$this->registerCommands();
64-
$this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this);
6568
}
6669

6770
/**

src/Sandertv/BlockSniper/UndoStorer.php

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

99
class UndoStorer {
1010

11-
public $totalStores = 0;
11+
public $totalStores;
1212
public $undoStore = [];
1313
public $lastUndo;
1414

@@ -33,8 +33,8 @@ public function saveUndo(array $blocks) {
3333
}
3434
unset($i);
3535

36-
if(count($this->undoStore) === $this->getOwner()->settings->get("Maximum-Undo-Stores")) {
37-
$this->unsetFirstUndo(); // Unset the first undo to make sure the array won't get too big.
36+
if($this->getTotalUndoStores() === $this->getOwner()->settings->get("Maximum-Undo-Stores")) {
37+
$this->unsetFirstUndo();
3838
}
3939
$this->getOwner()->getServer()->getScheduler()->scheduleDelayedTask(new UndoDiminishTask($this->getOwner()), 2400);
4040

@@ -52,20 +52,22 @@ public function unsetFirstUndo() {
5252
unset($this->undoStore[min(array_keys($this->undoStore))]);
5353
}
5454

55-
public function restoreLastUndo() {
56-
foreach($this->undoStore[max(array_keys($this->undoStore))] as $key => $block) {
57-
$Id = explode("(", $key);
58-
$blockId = $Id[0];
59-
$meta = explode(":", $blockId);
60-
$meta = $meta[1];
61-
$x = $block["x"];
62-
$y = $block["y"];
63-
$z = $block["z"];
64-
$finalBlock = Item::get($blockId, $meta)->getBlock();
65-
$finalBlock->setDamage((int)$meta !== null ? $meta : 0);
66-
$this->getOwner()->getServer()->getLevelByName($block["level"])->setBlock(new Vector3($x, $y, $z), $finalBlock, false, false);
55+
public function restoreLastUndo(int $amount = 1) {
56+
for($currentAmount = 0; $currentAmount < $amount; $currentAmount++) {
57+
foreach($this->undoStore[max(array_keys($this->undoStore))] as $key => $block) {
58+
$Id = explode("(", $key);
59+
$blockId = $Id[0];
60+
$meta = explode(":", $blockId);
61+
$meta = $meta[1];
62+
$x = $block["x"];
63+
$y = $block["y"];
64+
$z = $block["z"];
65+
$finalBlock = Item::get($blockId, $meta)->getBlock();
66+
$finalBlock->setDamage((int)$meta !== null ? $meta : 0);
67+
$this->getOwner()->getServer()->getLevelByName($block["level"])->setBlock(new Vector3($x, $y, $z), $finalBlock, false, false);
68+
}
69+
$this->unsetLastUndo();
6770
}
68-
$this->unsetLastUndo();
6971
}
7072

7173
public function unsetLastUndo() {
@@ -81,7 +83,7 @@ public function resetUndoStorage() {
8183
* @return bool
8284
*/
8385
public function undoStorageExists() {
84-
if($this->totalStores === 0 || !is_array($this->undoStore) || empty($this->undoStore)) {
86+
if(!is_array($this->undoStore) || empty($this->undoStore)) {
8587
return false;
8688
}
8789
return true;
@@ -100,4 +102,11 @@ public function getLastUndoBlockAmount() {
100102
public function getLastUndoActivity(): int {
101103
return (time() - $this->lastUndo);
102104
}
105+
106+
/**
107+
* @return int
108+
*/
109+
public function getTotalUndoStores(): int {
110+
return count($this->undoStore);
111+
}
103112
}

src/Sandertv/BlockSniper/brush/BaseShape.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,49 @@ abstract class BaseShape {
99
const MAX_WORLD_HEIGHT = 256;
1010
const MIN_WORLD_HEIGHT = 0;
1111

12-
const SHAPE_CUBE = 0;
13-
const SHAPE_SPHERE = 1;
12+
const SHAPE_SPHERE = 0;
13+
const SHAPE_CUBE = 1;
1414
const SHAPE_CYLINDER = 2;
1515
const SHAPE_CUBOID = 3;
1616

1717
public function __construct(Loader $main) {
1818
$this->main = $main;
1919
}
2020

21+
/**
22+
* @param string $shape
23+
*
24+
* @return bool
25+
*/
26+
public static function isShape(string $shape): bool {
27+
$shapeConst = strtoupper("shape_" . $shape);
28+
if(defined("self::$shapeConst")) {
29+
return true;
30+
}
31+
return false;
32+
}
33+
34+
/**
35+
* Registers a new Shape. Example:
36+
* Triangle, 4
37+
*
38+
* Defines the shape as a constant making it able to be used.
39+
*
40+
*
41+
* @param string $shape
42+
* @param int $number
43+
*
44+
* @return bool
45+
*/
46+
public static function registerShape(string $shape, int $number): bool {
47+
$shapeConst = strtoupper("shape_" . str_replace("_", "", $shape));
48+
if(defined("self::$shapeConst")) {
49+
return false;
50+
}
51+
define(('Sandertv\BlockSniper\brush\BaseShape\\' . $shapeConst), $number);
52+
return true;
53+
}
54+
2155
public abstract function getName(): string;
2256

2357
public abstract function getPermission(): string;

src/Sandertv/BlockSniper/brush/BaseType.php

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,54 @@ abstract class BaseType {
1515
const TYPE_REPLACE = 3;
1616
const TYPE_FLATTEN = 4;
1717
const TYPE_DRAIN = 5;
18-
const TYPE_LEAF_BLOWER = 6;
18+
const TYPE_LEAFBLOWER = 6;
1919
const TYPE_CLEAN = 7;
2020
const TYPE_BIOME = 8;
21-
const TYPE_CLEAN_ENTITIES = 9;
21+
const TYPE_CLEANENTITIES = 9;
2222
const TYPE_MELT = 10;
2323
const TYPE_EXPAND = 11;
24+
const TYPE_RAISE = 12;
2425

2526
public $main;
2627

2728
public function __construct(Loader $main) {
2829
$this->main = $main;
2930
}
3031

32+
/**
33+
* @param string $type
34+
*
35+
* @return bool
36+
*/
37+
public static function isType(string $type): bool {
38+
$typeConst = strtoupper("type_" . $type);
39+
if(defined("self::$typeConst")) {
40+
return true;
41+
}
42+
return false;
43+
}
44+
45+
/**
46+
* Registers a new Type. Example:
47+
* Raise, 12
48+
*
49+
* Defines the type as a constant making it able to be used.
50+
*
51+
*
52+
* @param string $type
53+
* @param int $number
54+
*
55+
* @return bool
56+
*/
57+
public static function registerType(string $type, int $number): bool {
58+
$typeConst = strtoupper("type_" . str_replace("_", "", $type));
59+
if(defined("self::$typeConst")) {
60+
return false;
61+
}
62+
define(('Sandertv\BlockSniper\brush\BaseType\\' . $typeConst), $number);
63+
return true;
64+
}
65+
3166
public abstract function getName(): string;
3267

3368
public abstract function getPermission(): string;

src/Sandertv/BlockSniper/brush/Brush.php

Lines changed: 7 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,6 @@
66
use pocketmine\item\Item;
77
use pocketmine\Player;
88
use ReflectionClass;
9-
use Sandertv\BlockSniper\brush\shapes\CubeShape;
10-
use Sandertv\BlockSniper\brush\shapes\CuboidShape;
11-
use Sandertv\BlockSniper\brush\shapes\CylinderStandingShape;
12-
use Sandertv\BlockSniper\brush\shapes\SphereShape;
13-
use Sandertv\BlockSniper\brush\types\BiomeType;
14-
use Sandertv\BlockSniper\brush\types\CleanEntitiesType;
15-
use Sandertv\BlockSniper\brush\types\CleanType;
16-
use Sandertv\BlockSniper\brush\types\DrainType;
17-
use Sandertv\BlockSniper\brush\types\ExpandType;
18-
use Sandertv\BlockSniper\brush\types\FillType;
19-
use Sandertv\BlockSniper\brush\types\FlattenType;
20-
use Sandertv\BlockSniper\brush\types\LayerType;
21-
use Sandertv\BlockSniper\brush\types\LeafBlowerType;
22-
use Sandertv\BlockSniper\brush\types\MeltType;
23-
use Sandertv\BlockSniper\brush\types\OverlayType;
24-
use Sandertv\BlockSniper\brush\types\ReplaceType;
259
use Sandertv\BlockSniper\Loader;
2610

2711
class Brush {
@@ -188,25 +172,9 @@ public static function setShape(Player $player, string $shape) {
188172
* @return BaseShape
189173
*/
190174
public static function getShape(Player $player): BaseShape {
191-
$shapeName = self::$brush[$player->getId()]["shape"];
192-
switch($shapeName) {
193-
case "cube":
194-
$shape = new CubeShape(self::$owner, $player, $player->getLevel(), self::getSize($player), $player->getTargetBlock(100));
195-
break;
196-
case "sphere":
197-
$shape = new SphereShape(self::$owner, $player, $player->getLevel(), self::getSize($player), $player->getTargetBlock(100));
198-
break;
199-
case "cuboid":
200-
$shape = new CuboidShape(self::$owner, $player, $player->getLevel(), self::getSize($player), self::getHeight($player), $player->getTargetBlock(100));
201-
break;
202-
case "cylinder":
203-
$shape = new CylinderStandingShape(self::$owner, $player, $player->getLevel(), self::getSize($player), self::getHeight($player), $player->getTargetBlock(100));
204-
break;
205-
206-
default:
207-
$shape = new SphereShape(self::$owner, $player, $player->getLevel(), self::getSize($player), $player->getTargetBlock(100));
208-
break;
209-
}
175+
$shapeName = 'Sandertv\BlockSniper\brush\shapes\\' . (ucfirst(self::$brush[$player->getId()]["shape"]) . "Shape");
176+
$shape = new $shapeName(self::$owner, $player, $player->getLevel(), self::getSize($player), $player->getTargetBlock(100));
177+
210178
return $shape;
211179
}
212180

@@ -235,49 +203,9 @@ public static function getHeight(Player $player): int {
235203
* @return BaseType
236204
*/
237205
public static function getType(Player $player, array $blocks = []): BaseType {
238-
$typeName = self::$brush[$player->getId()]["type"];
239-
switch($typeName) {
240-
case "fill":
241-
$type = new FillType(self::$owner, $player, $player->getLevel(), $blocks);
242-
break;
243-
case "clean":
244-
$type = new CleanType(self::$owner, $player, $player->getLevel(), $blocks);
245-
break;
246-
case "drain":
247-
$type = new DrainType(self::$owner, $player, $player->getLevel(), $blocks);
248-
break;
249-
case "flatten":
250-
$type = new FlattenType(self::$owner, $player, $player->getLevel(), $blocks, $player->getTargetBlock(100));
251-
break;
252-
case "layer":
253-
$type = new LayerType(self::$owner, $player, $player->getLevel(), $blocks, $player->getTargetBlock(100));
254-
break;
255-
case "leafblower":
256-
$type = new LeafBlowerType(self::$owner, $player, $player->getLevel(), $blocks);
257-
break;
258-
case "overlay":
259-
$type = new OverlayType(self::$owner, $player, $player->getLevel(), $blocks);
260-
break;
261-
case "replace":
262-
$type = new ReplaceType(self::$owner, $player, $player->getLevel(), $blocks);
263-
break;
264-
case "expand":
265-
$type = new ExpandType(self::$owner, $player, $player->getLevel(), $blocks);
266-
break;
267-
case "melt":
268-
$type = new MeltType(self::$owner, $player, $player->getLevel(), $blocks);
269-
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;
280-
}
206+
$typeName = 'Sandertv\BlockSniper\brush\types\\' . (ucfirst(self::$brush[$player->getId()]["type"]) . "Type");
207+
$type = new $typeName(self::$owner, $player, $player->getLevel(), $blocks);
208+
281209
return $type;
282210
}
283211

@@ -289,7 +217,7 @@ public static function setBiome(Player $player, string $biome) {
289217
self::$brush[$player->getId()]["biome"] = $biome;
290218
}
291219

292-
public static function getBiomeIdFromString(Player $player): int {
220+
public static function getBiomeId(Player $player): int {
293221
$biomes = new ReflectionClass('pocketmine\level\generator\biome\Biome');
294222
$const = strtoupper(str_replace(" ", "_", self::$brush[$player->getId()]["biome"]));
295223
if($biomes->hasConstant($const)) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class CuboidShape extends BaseShape {
1818
public $center;
1919
public $player;
2020

21-
public function __construct(Loader $main, Player $player, Level $level, float $width = null, float $height = null, Position $center = null) {
21+
public function __construct(Loader $main, Player $player, Level $level, float $width = null, Position $center = null) {
2222
parent::__construct($main);
2323
$this->level = $level;
2424
$this->width = $width;
25-
$this->height = $height;
25+
$this->height = Brush::getHeight($player);
2626
$this->center = $center;
2727
$this->player = $player;
2828
}

0 commit comments

Comments
 (0)