Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifera committed Mar 25, 2021
1 parent 81d1236 commit ff5fefe
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 11 deletions.
15 changes: 13 additions & 2 deletions src/Ifera/ScoreHud/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

use Ifera\ScoreHud\event\PlayerTagsUpdateEvent;
use Ifera\ScoreHud\event\PlayerTagUpdateEvent;
use Ifera\ScoreHud\event\ServerTagsUpdateEvent;
use Ifera\ScoreHud\event\ServerTagUpdateEvent;
use Ifera\ScoreHud\scoreboard\ScoreTag;
use Ifera\ScoreHud\session\PlayerManager;
Expand Down Expand Up @@ -67,8 +68,12 @@ public function onWorldChange(EntityLevelChangeEvent $event){
}

public function onServerTagUpdate(ServerTagUpdateEvent $event){
foreach(PlayerManager::getAll() as $session){
$this->updateTag($session->getPlayer(), $event->getTag());
$this->updateServerTag($event->getTag());
}

public function onServerTagsUpdate(ServerTagsUpdateEvent $event){
foreach($event->getTags() as $tag){
$this->updateServerTag($tag);
}
}

Expand All @@ -82,6 +87,12 @@ public function onPlayerTagsUpdate(PlayerTagsUpdateEvent $event){
}
}

private function updateServerTag(ScoreTag $tag){
foreach(PlayerManager::getAll() as $session){
$this->updateTag($session->getPlayer(), $tag);
}
}

private function updateTag(Player $player, ScoreTag $newTag): void{
if(is_null($session = PlayerManager::get($player))){
return;
Expand Down
11 changes: 2 additions & 9 deletions src/Ifera/ScoreHud/event/ServerTagUpdateEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
namespace Ifera\ScoreHud\event;

use Ifera\ScoreHud\scoreboard\ScoreTag;
use Ifera\ScoreHud\ScoreHud;
use pocketmine\event\Event;

/**
* Call this event when you need to change a tag
Expand All @@ -48,20 +46,15 @@
* Call this event, pass the tag that needs updating into the
* constructor and let ScoreHud handle the rest.
*/
class ServerTagUpdateEvent extends Event{
class ServerTagUpdateEvent extends ScoreHudEvent{

/** @var ScoreHud|null */
protected $plugin = null;
/** @var ScoreTag */
protected $tag;

public function __construct(ScoreTag $tag){
$this->plugin = ScoreHud::getInstance();
$this->tag = $tag;
}

public function getPlugin(): ?ScoreHud{
return $this->plugin;
parent::__construct();
}

public function getTag(): ScoreTag{
Expand Down
75 changes: 75 additions & 0 deletions src/Ifera/ScoreHud/event/ServerTagsUpdateEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
declare(strict_types = 1);

/**
* _____ _ _ _
* / ___| | | | | | |
* \ `--. ___ ___ _ __ ___| |_| |_ _ __| |
* `--. \/ __/ _ \| '__/ _ \ _ | | | |/ _` |
* /\__/ / (_| (_) | | | __/ | | | |_| | (_| |
* \____/ \___\___/|_| \___\_| |_/\__,_|\__,_|
*
* ScoreHud, a Scoreboard plugin for PocketMine-MP
* Copyright (c) 2020 Ifera < https://github.com/Ifera >
*
* Discord: Ifera#3717
* Twitter: ifera_tr
*
* This software is distributed under "GNU General Public License v3.0".
* This license allows you to use it and/or modify it but you are not at
* all allowed to sell this plugin at any cost. If found doing so the
* necessary action required would be taken.
*
* ScoreHud is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License v3.0 for more details.
*
* You should have received a copy of the GNU General Public License v3.0
* along with this program. If not, see
* <https://opensource.org/licenses/GPL-3.0>.
* ------------------------------------------------------------------------
*/

namespace Ifera\ScoreHud\event;

use Ifera\ScoreHud\scoreboard\ScoreTag;

/**
* Same as ServerTagUpdateEvent but provides an easier way
* to send updates for multiple tags at the same time.
*
* @see ServerTagUpdateEvent
*/
class ServerTagsUpdateEvent extends ScoreHudEvent{

/** @var ScoreTag[] */
private $tags = [];

/**
* @param ScoreTag[] $tags
*/
public function __construct(array $tags){
$this->tags = $tags;

parent::__construct();
}

/**
* @param ScoreTag[] $tags
*/
public function setTags(array $tags): void{
$this->tags = $tags;
}

/**
* @return ScoreTag[]
*/
public function getTags(): array{
return $this->tags;
}

public function addTag(ScoreTag $tag): void{
$this->tags[] = $tag;
}
}

0 comments on commit ff5fefe

Please sign in to comment.