Skip to content
This repository was archived by the owner on Feb 8, 2019. It is now read-only.

Commit ca988ec

Browse files
committed
Add PhaseTimeUpdateEvent
1 parent cd52cff commit ca988ec

File tree

2 files changed

+66
-4
lines changed

2 files changed

+66
-4
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Copyright (c) 2018 VectorNetworkProject. All rights reserved. MIT license.
4+
*
5+
* GitHub: https://github.com/VectorNetworkProject/TheMix
6+
* Website: https://www.vector-network.tk
7+
*/
8+
9+
/**
10+
* Created by PhpStorm.
11+
* User: InkoHX
12+
* Date: 2018/12/19
13+
* Time: 4:54
14+
*/
15+
16+
namespace VectorNetworkProject\TheMix\game\event\game;
17+
18+
19+
use pocketmine\event\Cancellable;
20+
use pocketmine\event\Event;
21+
22+
class PhaseTimeUpdateEvent extends Event implements Cancellable
23+
{
24+
/** @var int $time */
25+
private $time;
26+
27+
/**
28+
* PhaseTimeUpdateEvent constructor.
29+
*
30+
* @param int $time
31+
*/
32+
public function __construct(int $time)
33+
{
34+
$this->time = $time;
35+
}
36+
37+
/**
38+
* @return int
39+
*/
40+
public function getTime(): int
41+
{
42+
return $this->time;
43+
}
44+
}

src/VectorNetworkProject/TheMix/task/PhaseTask.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace VectorNetworkProject\TheMix\task;
1010

1111
use pocketmine\scheduler\Task;
12+
use VectorNetworkProject\TheMix\game\event\game\PhaseTimeUpdateEvent;
1213

1314
class PhaseTask extends Task
1415
{
@@ -25,16 +26,33 @@ public function __construct(int $time = 600)
2526
$this->time = $time;
2627
}
2728

29+
/**
30+
* @param int $currentTick
31+
*
32+
* @throws \ReflectionException
33+
*/
2834
public function onRun(int $currentTick)
2935
{
30-
// TODO: Implement onRun() method.
36+
$event = new PhaseTimeUpdateEvent($this->getTime() - 1);
37+
$event->call();
38+
if (!$event->isCancelled()) {
39+
$this->setTime($this->getTime() - 1);
40+
}
41+
}
42+
43+
/**
44+
* @return int
45+
*/
46+
public function getTime(): int
47+
{
48+
return $this->time;
3149
}
3250

3351
/**
34-
* @return string
52+
* @param int $time
3553
*/
36-
public function getTime(): string
54+
public function setTime(int $time): void
3755
{
38-
return gmdate('i:s', $this->time);
56+
$this->time = $time;
3957
}
4058
}

0 commit comments

Comments
 (0)