Skip to content

Commit

Permalink
ScoreHud v7.0.0 - a lot has changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifera committed Feb 18, 2022
1 parent 270ea71 commit 408b7c8
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 113 deletions.
12 changes: 6 additions & 6 deletions .poggit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ projects:
icon: meta/ScoreHud.PNG
libs:
- src: Ifera/ScoreFactory/ScoreFactory
version: ^3.0.2
branch: pm4
version: ^3.1.0
branch: master
- src: ifera-mc/UpdateNotifier/UpdateNotifier
version: ^2.0.0
branch: API-4.0.0
version: ^3.0.0
branch: master
- src: ifera-mc/ConfigUpdater/ConfigUpdater
version: ^1.2.1
branch: PM4
version: ^2.0.0
branch: master
lint:
phpstan: false
...
5 changes: 1 addition & 4 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
name: ScoreHud
main: Ifera\ScoreHud\ScoreHud
api: 4.0.0
version: 6.3.1
version: 7.0.0
author: Ifera
description: Add fully customizable scoreboards to your server.

extensions:
Core: '>=8.0'

virions:
- ScoreFactory
- UpdateNotifier
Expand Down
41 changes: 12 additions & 29 deletions resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
---
# _____ _ _ _
# / ___| | | | | | |
# \ `--. ___ ___ _ __ ___| |_| |_ _ __| |
# `--. \/ __/ _ \| '__/ _ \ _ | | | |/ _` |
# /\__/ / (_| (_) | | | __/ | | | |_| | (_| |
# \____/ \___\___/|_| \___\_| |_/\__,_|\__,_|
#
# 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>.
# -----------------------------------------------------------------------

# DO NOT EDIT THIS VALUE.
# ONLY FOR INTERNAL USE.
config-version: 10
config-version: 11

# Set how you want to update the lines shown on the scoreboard.
# Available modes: single, complete
#
# - single: Only the tags on scoreboard which have an update are updated
# and not the entire board. (preferred)
# - complete: On a single tag update the entire scoreboard is updated i.e.
# the tags which don't have an update are updated as well.
#
# Apart from that difference both modes work the same. You will not notice much difference.
line-update-mode: single

# If you want to have different scoreboards for different worlds
# then edit the nested values to suit your needs.
Expand Down
20 changes: 2 additions & 18 deletions resources/scorehud.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
---
# DO NOT EDIT THIS VALUE.
# ONLY FOR INTERNAL USE.
scorehud-version: 2

# =============================
# SCOREHUD VERSION 6.0+ NOTE:
# =============================
#
# Plugin developers are responsible for adding support for ScoreHud
# in their plugins. Starting from ScoreHud version 6.0 onwards addon
# support has been removed.
#
# ScoreHud is now event driven and all previous addons will no longer
# work unless the author of that plugin adds support for ScoreHud in
# their own plugin.
#
# If you want support for a plugin please ask the plugin author of
# that plugin to add support for ScoreHud in their plugin.
# =============================
scorehud-version: 3

# Set the title for the scoreboard shown.
titles:
Expand Down Expand Up @@ -50,7 +34,7 @@ titles:
# ==================
# You can only set a maximum of 15 lines and no more. #blameMOJANG
#
# Also note that you need 'ScoreHudX' plugin for some tags to work.
# You can find some pre-made tags from the ScoreHudX repo:
# https://github.com/Ifera/ScoreHudX
# ==================

Expand Down
44 changes: 20 additions & 24 deletions src/Ifera/ScoreHud/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,82 +42,78 @@
use pocketmine\event\entity\EntityTeleportEvent;
use pocketmine\event\Listener;
use pocketmine\player\Player;
use pocketmine\world\Position;
use function is_null;

class EventListener implements Listener{
class EventListener implements Listener {

/** @var ScoreHud */
private $plugin;

public function __construct(ScoreHud $plugin){
public function __construct(ScoreHud $plugin) {
$this->plugin = $plugin;
}

public function onWorldChange(EntityTeleportEvent $event){
if(!ScoreHudSettings::isMultiWorld()){
public function onWorldChange(EntityTeleportEvent $event): void {
if (!ScoreHudSettings::isMultiWorld()) {
return;
}

$from = $event->getFrom();
$to = $event->getTo();

if(!($from instanceof Position and $to instanceof Position)){
return;
}

if($from->getWorld()->getFolderName() === $to->getWorld()->getFolderName()){
if ($from->getWorld()->getFolderName() === $to->getWorld()->getFolderName()) {
return;
}

$player = $event->getEntity();

if(!$player instanceof Player or !$player->spawned){
if (!$player instanceof Player or !$player->spawned) {
return;
}

PlayerManager::getNonNull($player)->handle($to->getWorld()->getFolderName());
}

public function onServerTagUpdate(ServerTagUpdateEvent $event){
public function onServerTagUpdate(ServerTagUpdateEvent $event): void {
$this->updateServerTag($event->getTag());
}

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

public function onPlayerTagUpdate(PlayerTagUpdateEvent $event){
public function onPlayerTagUpdate(PlayerTagUpdateEvent $event): void {
$this->updateTag($event->getPlayer(), $event->getTag());
}

public function onPlayerTagsUpdate(PlayerTagsUpdateEvent $event){
foreach($event->getTags() as $tag){
public function onPlayerTagsUpdate(PlayerTagsUpdateEvent $event): void {
foreach ($event->getTags() as $tag) {
$this->updateTag($event->getPlayer(), $tag);
}
}

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

private function updateTag(Player $player, ScoreTag $newTag): void{
if(
private function updateTag(Player $player, ScoreTag $newTag): void {
if (
!$player->isOnline() ||
ScoreHudSettings::isInDisabledWorld($player->getWorld()->getFolderName()) ||
is_null($session = PlayerManager::get($player)) ||
is_null($scoreboard = $session->getScoreboard()) ||
is_null($scoreTag = $scoreboard->getTag($newTag->getName()))
){
) {
return;
}

$this->plugin->setScore($player, false);
$scoreTag->setValue($newTag->getValue());
$scoreboard->update()->display();

if (ScoreHudSettings::isSingleLineUpdateMode()) $scoreboard->handleSingleTagUpdate($scoreTag);
else $scoreboard->update()->display();
}
}
9 changes: 5 additions & 4 deletions src/Ifera/ScoreHud/ScoreHud.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
class ScoreHud extends PluginBase{
use SingletonTrait;

private const CONFIG_VERSION = 10;
private const SCOREHUD_VERSION = 2;
private const CONFIG_VERSION = 11;
private const SCOREHUD_VERSION = 3;

private ?Config $scoreConfig;

Expand Down Expand Up @@ -182,11 +182,12 @@ public function setScore(Player $player, bool $calledFromTask): void{
}

if(HelperUtils::isDisabled($player) || ScoreHudSettings::isInDisabledWorld($player->getWorld()->getFolderName())){
ScoreFactory::removeScore($player);
ScoreFactory::removeObjective($player);

return;
}

ScoreFactory::setScore($player, TitleUtils::getTitle($calledFromTask));
ScoreFactory::setObjective($player, TitleUtils::getTitle($calledFromTask));
ScoreFactory::sendObjective($player);
}
}
8 changes: 8 additions & 0 deletions src/Ifera/ScoreHud/ScoreHudSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ public static function destroy(): void{
* Settings from config.yml
*/

public static function getLineUpdateMode(): string{
return (string) strtolower(self::$config->getNested("line-update-mode", "single"));
}

public static function isSingleLineUpdateMode(): bool{
return self::getLineUpdateMode() === "single";
}

public static function isMultiWorld(): bool{
return (bool) self::$config->getNested("multi-world.active", false);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Ifera/ScoreHud/commands/ScoreHudCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function execute(CommandSender $sender, string $commandLabel, array $args

case "off":
if(!HelperUtils::isDisabled($sender)){
ScoreFactory::removeScore($sender);
ScoreFactory::removeObjective($sender);
HelperUtils::disable($sender);

$sender->sendMessage(ScoreHudSettings::PREFIX . "§aSuccessfully disabled ScoreHud.");
Expand Down
25 changes: 10 additions & 15 deletions src/Ifera/ScoreHud/scoreboard/ScoreTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,30 @@

namespace Ifera\ScoreHud\scoreboard;

class ScoreTag{
class ScoreTag {

/** @var string */
private $name;
/** @var string */
private $value = "";
public function __construct(
private string $name,
private string $value = ""
) {}

public function __construct(string $name, string $value){
$this->name = $name;
$this->value = $value;
}

public function getId(): string{
public function getId(): string {
return "{" . $this->name . "}";
}

public function getName(): string{
public function getName(): string {
return $this->name;
}

public function getValue(): string{
public function getValue(): string {
return $this->value;
}

public function setValue(string $value): void{
public function setValue(string $value): void {
$this->value = $value;
}

public function __toArray(): array{
public function __toArray(): array {
return [
"name" => $this->name,
"value" => $this->value
Expand Down
Loading

0 comments on commit 408b7c8

Please sign in to comment.