Skip to content

Commit 6cd1c7e

Browse files
committed
Fix #7, #9
1 parent 8430274 commit 6cd1c7e

File tree

7 files changed

+163
-82
lines changed

7 files changed

+163
-82
lines changed

.idea/workspace.xml

+110-65
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: CubeBox
3-
version: 1.0.1
3+
version: 1.1.0
44
api: 3.0.0
55
author: TheAz928
66
main: TheAz928\CubeBox\Loader

src/TheAz928/CubeBox/Loader.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ public function getCrate(string $id): ?Crate {
126126

127127
/**
128128
* @param PlayerInteractEvent $event
129+
* @priority MONITOR
130+
* @ignoreCancelled false
129131
*/
130132
public function onInteract(PlayerInteractEvent $event): void {
131133
$player = $event->getPlayer();
@@ -154,7 +156,8 @@ public function onInteract(PlayerInteractEvent $event): void {
154156
$crateTile->spawnToAll();
155157

156158
unset($this->creationSession[$player->getName()]);
157-
}elseif($tile instanceof CrateTile){
159+
}
160+
if($tile instanceof CrateTile){
158161
$event->setCancelled();
159162

160163
if($item->equals($tile->getCrate()->getKey())){

src/TheAz928/CubeBox/entity/FloatingText.php

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
namespace TheAz928\CubeBox\entity;
33

4-
use pocketmine\entity\Zombie;
4+
use pocketmine\entity\Living;
55

66
use pocketmine\event\entity\EntityDamageEvent;
77

@@ -26,7 +26,15 @@
2626
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2727
*/
2828

29-
class FloatingText extends Zombie {
29+
class FloatingText extends Living {
30+
31+
public const NETWORK_ID = self::VEX;
32+
33+
/** @var float */
34+
public $height = 1.00;
35+
36+
/** @var float */
37+
public $width = 1.00;
3038

3139
/** @var float */
3240
protected $gravity = 0.00;
@@ -44,6 +52,13 @@ public static function spawn(Position $pos, string $text): self {
4452
return $entity;
4553
}
4654

55+
/**
56+
* @return string
57+
*/
58+
public function getName(): string {
59+
return "Floating Text";
60+
}
61+
4762
protected function initEntity(): void {
4863
parent::initEntity();
4964

src/TheAz928/CubeBox/entity/GiftBoxEntity.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ protected function initEntity(): void {
8181
parent::initEntity();
8282

8383
$this->setScale(0.5);
84+
$this->setCanSaveWithChunk(false);
8485
}
8586

8687
/**
@@ -118,8 +119,8 @@ public function entityBaseTick(int $tickDiff = 1): bool {
118119
$this->getTile()->setIsInUse(false);
119120
$this->getTile()->setChestState(false);
120121

121-
if($this->rewardItem !== null){
122-
$this->rewardItem->flagForDespawn();
122+
if($this->rewardItem !== null and $this->rewardItem->isClosed() == false){
123+
$this->rewardItem->close();
123124
}
124125

125126
return true;
@@ -198,6 +199,7 @@ public function entityBaseTick(int $tickDiff = 1): bool {
198199

199200
if($reward->getItem()->isNull() == false){
200201
$this->rewardItem = $this->getLevel()->dropItem($this, $reward->getItem(), new Vector3(0, 0, 0), 12000);
202+
201203
$this->rewardItem->setNameTag($rarity . $reward->getItem()->getName());
202204
$this->rewardItem->setNameTagAlwaysVisible(true);
203205
}
@@ -210,8 +212,8 @@ public function entityBaseTick(int $tickDiff = 1): bool {
210212
if($this->timeCounter > (20 * 11)){
211213
$this->flagForDespawn();
212214

213-
if($this->rewardItem !== null){
214-
$this->rewardItem->flagForDespawn();
215+
if($this->rewardItem !== null and $this->rewardItem->isClosed() == false){
216+
$this->rewardItem->close();
215217
}
216218

217219
$this->getTile()->setIsInUse(false);

src/TheAz928/CubeBox/form/ConfirmOpenForm.php

+13-8
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,17 @@
1414
/**
1515
* CubeBox: The next level crate plugin for PocketMine-MP
1616
* CopyRight (C) 2020 CubePM (TheAz928)
17-
*
1817
* This program is free software: you can redistribute it and/or modify
1918
* it under the terms of the GNU General Public License as published by
2019
* the Free Software Foundation, either version 3 of the License, or
2120
* any later version.
22-
*
2321
* This program is distributed in the hope that it will be useful,
2422
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2523
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2624
* GNU General Public License for more details.
27-
*
2825
* You should have received a copy of the GNU General Public License
2926
* along with this program. If not, see <http://www.gnu.org/licenses/>.
3027
*/
31-
3228
class ConfirmOpenForm implements Form {
3329

3430
/** @var CrateTile */
@@ -46,13 +42,22 @@ public function __construct(CrateTile $tile) {
4642
* @return array
4743
*/
4844
public function jsonSerialize(): array {
45+
$content = TextFormat::GRAY . "Open this crate for ";
46+
if(($m = $this->tile->getCrate()->getMoneyCost()) > -1){
47+
$content .= "$" . number_format($m);
48+
}
49+
if(($e = $this->tile->getCrate()->getXpCost()) > -1){
50+
$content .= " and " . number_format($e) . "XP Level(s)";
51+
}
52+
$content .= "?";
53+
4954
return [
5055
"type" => "form",
51-
"title" => "CubeBox",
52-
"content" => "Are you sure you want to open this crate for\n" . TextFormat::GREEN . "XP: " . TextFormat::WHITE . $this->tile->getCrate()->getXpCost() . "\n" . TextFormat::GREEN . "Money: " . TextFormat::WHITE . "$" . $this->tile->getCrate()->getMoneyCost() . "\n\n\n\n\n\n\n\n",
56+
"title" => $this->tile->getCrate()->getName(),
57+
"content" => $content,
5358
"buttons" => [
54-
["text" => "Yes"],
55-
["text" => "No"]
59+
["text" => TextFormat::DARK_GREEN . "Yes"],
60+
["text" => TextFormat::RED . "No"]
5661
]
5762
];
5863
}

src/TheAz928/CubeBox/tile/CrateTile.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function close(): void {
126126
parent::close();
127127

128128
if($this->displayEntity !== null){
129-
$this->displayEntity->flagForDespawn();
129+
$this->displayEntity->close();
130130
}
131131
}
132132

@@ -174,6 +174,8 @@ public function onUpdate(): bool {
174174

175175
$dust1 = new DustParticle($pos->asVector3(), ...$this->getCrate()->getRGBA());
176176

177+
$pos = $this->asVector3();
178+
177179
$pos->x = ($pos->x + 0.5) + -sin($i);
178180
$pos->z = ($pos->z + 0.5) + cos($i);
179181

@@ -209,6 +211,15 @@ public function onUpdate(): bool {
209211
}
210212
}
211213
if($this->getDisplayEntity()->isClosed() == false){
214+
if($this->getDisplayEntity()->isClosed()){
215+
$pos = $this->asPosition();
216+
$pos->x += 0.5;
217+
$pos->y += 2.4;
218+
$pos->z += 0.5;
219+
220+
$this->displayEntity = FloatingText::spawn($pos, "");
221+
}
222+
212223
$this->getDisplayEntity()->setNameTag($this->getCrate()->getName() . "\n\n" . TextFormat::RESET . $display);
213224
}
214225
}

0 commit comments

Comments
 (0)