-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstantFurnace.php
98 lines (89 loc) · 2.84 KB
/
InstantFurnace.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* ____ _ _ ___
* | _ \ _ __ ___ ___ ___ _ __ | |_| |/ (_)_ __ ___
* | |_) | '__/ _ \/ __|/ _ \ '_ \| __| ' /| | '_ ` _ \
* | __/| | | __/\__ \ __/ | | | |_| . \| | | | | | |
* |_| |_| \___||___/\___|_| |_|\__|_|\_\_|_| |_| |_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the MIT License. see <https://opensource.org/licenses/MIT>.
*
*
* @author PresentKim ([email protected])
* @link https://github.com/PresentKim
* @license https://opensource.org/licenses/MIT MIT License
*
* @name InstantFurnace
* @main kim\present\singleton\InstantFurnace
* @version 1.0.0
* @api 4.0.0
* @description Instant furnace
*
* (\ /)
* ( . .) ♥
* c(")(")
*/
declare(strict_types=1);
namespace kim\present\singleton {
use pocketmine\event\inventory\FurnaceBurnEvent;
use pocketmine\event\inventory\FurnaceSmeltEvent;
use pocketmine\event\Listener;
use pocketmine\plugin\PluginBase;
use pocketmine\tile\Furnace;
class InstantFurnace extends PluginBase implements Listener{
/** @var \ReflectionProperty */
private $burnTimeProperty, $cookTimeProperty;
/**
* Called when the plugin is loaded, before calling onEnable()
*
* @throws \ReflectionException
*/
public function onLoad() : void{
$reflectionClass = new \ReflectionClass(Furnace::class);
$this->cookTimeProperty = $reflectionClass->getProperty("cookTime");
$this->cookTimeProperty->setAccessible(true);
$this->burnTimeProperty = $reflectionClass->getProperty("burnTime");
$this->burnTimeProperty->setAccessible(true);
}
/**
* Called when the plugin is enabled
*/
public function onEnable() : void{
$this->getServer()->getPluginManager()->registerEvents($this, $this);
}
/**
* @priority HIGHEST
*
* @param FurnaceBurnEvent $event
*/
public function onFurnaceBurnEvent(FurnaceBurnEvent $event) : void{
if(!$event->isCancelled()){
$burnTime = $event->getBurnTime();
if($burnTime > 200){
$furnace = $event->getFurnace();
$event->setBurnTime($burnTime - 199);
$this->cookTimeProperty->setValue($furnace, 399);
}
}
}
/**
* @priority HIGHEST
*
* @param FurnaceSmeltEvent $event
*/
public function onFurnaceSmeltEvent(FurnaceSmeltEvent $event) : void{
if(!$event->isCancelled()){
$furnace = $event->getFurnace();
$burnTime = $this->burnTimeProperty->getValue($furnace);
if($burnTime > 199){
$this->burnTimeProperty->setValue($furnace, $burnTime - 199);
$this->cookTimeProperty->setValue($furnace, 399);
}elseif($furnace->getInventory()->getFuel()->getFuelTime() > 200){
$this->burnTimeProperty->setValue($furnace, 1);
$this->cookTimeProperty->setValue($furnace, $this->cookTimeProperty->getValue($furnace) + $burnTime);
}
}
}
}
}