Skip to content

Commit

Permalink
Bug fixes, related issues #148 #140.
Browse files Browse the repository at this point in the history
Use own Async pool to reduce stress on PMMP's AsyncPool.
  • Loading branch information
larryTheCoder committed Jan 3, 2021
1 parent 28b8e01 commit 9ab8ef7
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 46 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
Powered by Open Sourced code, Our code comrade.
Its time to burn those old fancy paid plugins and beat them in face!

### Notice
Support for PM3 will no longer be available in any time soon.

## Introduction
SkyWarsForPE is a production-standard plugin built for all Minecraft PE Community, the code was acquired by Alair069 for
SkyWars project/development. However, due to some inactivity in this project in the self-isolated environment, it was brought
Expand Down
4 changes: 2 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: SkyWarsForPE
main: larryTheCoder\SkyWarsPE
version: "3.1.34-BETA"
api: 3.0.0+ALPHA9
version: "3.1.35-BETA"
api: 3.16.0
author: larryTheCoder
website: https://github.com/larryTheCoder/SkyWarsForPE
softdepend:
Expand Down
4 changes: 2 additions & 2 deletions resources/language/ko_KR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ team-setup-3: '최소 팀'
team-setup-4: '최대 팀'
team-setup-5: '팀 색깔'

team-error-1: '&c팀 설정 중 오류가 발생했습니다. 0-15 사이의 정수여야 하며, ';'으로 분리되어야 합니다.'
team-error-1: "&c팀 설정 중 오류가 발생했습니다. 0-15 사이의 정수여야 하며, ';'으로 분리되어야 합니다."
team-error-2: '&c설정한 팀 색깔이 최대 팀 수보다 적습니다'

solo-setup-1: "솔로 팀 설정"
Expand Down Expand Up @@ -217,7 +217,7 @@ economy-internal: "&c결제를 진행할 수 없습니다. 잠시 후 다시 시

# Panel messages
panel-cancelled: "&c요청이 취소되었습니다."
panel-choose-cage: "&a케이지 &d{CAGE}&a를 선택했습니다.
panel-choose-cage: "&a케이지 &d{CAGE}&a를 선택했습니다."
panel-join-spect: "&a관전자 스폰 위치가 기록되었습니다."
panel-join-sign: "&a참가 표지판 위치가 기록되었습니다."
panel-spawn-pos: "&a스폰 위치 &e#{COUNT}&a를 설정했습니다."
Expand Down
4 changes: 2 additions & 2 deletions src/larryTheCoder/ArenaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
use larryTheCoder\arena\ArenaImpl;
use larryTheCoder\utils\ConfigManager;
use larryTheCoder\utils\Utils;
use larryTheCoder\worker\LevelAsyncPool;
use pocketmine\Player;
use pocketmine\Server;
use pocketmine\utils\Config;

final class ArenaManager {
Expand Down Expand Up @@ -135,7 +135,7 @@ public function deleteArena(ArenaImpl $arena): void{
unset($this->config[$arena->getMapName()]);
});

Server::getInstance()->getAsyncPool()->submitTask($task);
LevelAsyncPool::getAsyncPool()->submitTask($task);
}

/**
Expand Down
18 changes: 16 additions & 2 deletions src/larryTheCoder/SkyWarsPE.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
Utils
};
use larryTheCoder\utils\cage\CageManager;
use larryTheCoder\worker\LevelAsyncPool;
use onebone\economyapi\EconomyAPI;
use pocketmine\command\{Command, CommandSender};
use pocketmine\entity\Entity;
Expand All @@ -59,7 +60,7 @@
class SkyWarsPE extends PluginBase {

private const CONFIG_VERSION = 4;
private const LOCALE_VERSION = 10;
private const LOCALE_VERSION = 11;
private const CAGES_VERSION = 2;

/** @var SkyWarsPE|null */
Expand Down Expand Up @@ -99,6 +100,9 @@ public function initConfig(): void{
$this->saveResource("arenas/default.yml");
$this->saveResource("looting-tables.json");
$this->saveResource("language/en_US.yml");
$this->saveResource("language/es_ES.yml");
$this->saveResource("language/ko_KR.yml");
$this->saveResource("language/ru_RU.yml");

// Load config file first.
$cfg = new Config($this->getDataFolder() . "config.yml", Config::YAML);
Expand Down Expand Up @@ -129,19 +133,27 @@ public function initConfig(): void{
$localeCode = basename($file, ".yml");

if($locale->get("config-version") < self::LOCALE_VERSION && file_exists($this->getFile() . "resources/language/" . $localeCode . ".yml")){
$newLocale = new Config($this->getFile() . "resources/language/" . $localeCode . ".yml");
if($newLocale->get("config-version") < self::LOCALE_VERSION){
goto register;
}

$this->getServer()->getLogger()->info(Settings::$prefix . TextFormat::YELLOW . "§cLanguage '" . $localeCode . "' is outdated, saving a newer locale config.");

Utils::oldRenameRecursive("language/" . $localeCode . ".yml");
$this->saveResource("language/" . $localeCode . ".yml", true);

$locale->reload();
$locale = $newLocale;
}

register:
TranslationContainer::getInstance()->addTranslation($localeCode, $locale);
}
}

public function onEnable(): void{
new LevelAsyncPool($this, 4);

$server = $this->getServer();
if(\Phar::running(true) === ""){
if(!class_exists("poggit\libasynql\libasynql")){
Expand Down Expand Up @@ -260,6 +272,8 @@ public function onDisable(): void{
Utils::unLoadGame();
SkyWarsDatabase::shutdown();

LevelAsyncPool::getAsyncPool()->shutdown();

if($this->pedestalManager !== null){
$this->pedestalManager->closeAll();
}
Expand Down
26 changes: 14 additions & 12 deletions src/larryTheCoder/arena/ArenaImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
use larryTheCoder\arena\api\CageManager;
use larryTheCoder\arena\api\impl\ArenaListener;
use larryTheCoder\arena\api\PlayerManager;
use larryTheCoder\arena\api\scoreboard\Internal;
use larryTheCoder\arena\api\scoreboard\ScoreFilter;
use larryTheCoder\arena\api\SignManager;
use larryTheCoder\arena\api\task\ArenaTickTask;
use larryTheCoder\arena\task\SkyWarsTask;
Expand Down Expand Up @@ -106,7 +106,7 @@ public function setConfig(ConfigManager $arenaData, bool $duringRuntime = false)

$this->signManager = new SignManager($this, $this->getSignPosition(), Settings::$prefix);
$this->cageManager = new CageManager($this->spawnPedestals);
$this->scoreboard = new Internal($this, Utils::getScoreboardConfig($this));
$this->scoreboard = new ScoreFilter($this, Utils::getScoreboardConfig($this));

$this->signManager->setTemplate([$this->statusLine1, $this->statusLine2, $this->statusLine3, $this->statusLine4]);

Expand Down Expand Up @@ -230,8 +230,6 @@ public function setSpectator(Player $player): void{
}

public function unsetPlayer(Player $player, bool $isSpectator = false): void{
$player->setGamemode(0);

if($isSpectator){
$player->setAllowFlight(false);

Expand All @@ -244,16 +242,20 @@ public function unsetPlayer(Player $player, bool $isSpectator = false): void{
SkyWarsDatabase::addPlayedSince($player->getName(), time() - $this->startedTime);
}

$player->getInventory()->clearAll();
$player->getArmorInventory()->clearAll();
if(!$player->isClosed()){
$player->setGamemode(0);

if($this->getPlayerManager()->teamMode && isset($this->originalNametag[$player->getName()])){
$player->setNameTag($this->originalNametag[$player->getName()]);
unset($this->originalNametag[$player->getName()]);
}
$player->getInventory()->clearAll();
$player->getArmorInventory()->clearAll();

$player->setHealth(20);
$player->setFood(20);
if($this->getPlayerManager()->teamMode && isset($this->originalNametag[$player->getName()])){
$player->setNameTag($this->originalNametag[$player->getName()]);
unset($this->originalNametag[$player->getName()]);
}

$player->setHealth(20);
$player->setFood(20);
}
}

public function leaveArena(Player $player, bool $onQuit = false): void{
Expand Down
5 changes: 3 additions & 2 deletions src/larryTheCoder/arena/api/Arena.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use larryTheCoder\arena\api\task\CompressionAsyncTask;
use larryTheCoder\arena\api\utils\QueueManager;
use larryTheCoder\database\SkyWarsDatabase;
use larryTheCoder\worker\LevelAsyncPool;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\ItemIds;
Expand Down Expand Up @@ -281,7 +282,7 @@ final public function resetWorld(): void{
$this->lobbyLevel = null;
$this->deleteTimeout = 0;
});
Server::getInstance()->getAsyncPool()->submitTask($task);
LevelAsyncPool::getAsyncPool()->submitTask($task);

$this->deleteTimeout = 30;
}
Expand Down Expand Up @@ -335,7 +336,7 @@ final public function loadWorld(bool $onStart = true): void{
$this->processQueue();
});

Server::getInstance()->getAsyncPool()->submitTask($task);
LevelAsyncPool::getAsyncPool()->submitTask($task);

$this->setFlags(self::WORLD_ATTEMPT_LOAD, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,45 @@

namespace larryTheCoder\arena\api\scoreboard;

use larryTheCoder\arena\api\impl\Scoreboard;
use JackMD\ScoreHud\libs\JackMD\ScoreFactory\ScoreFactory;
use JackMD\ScoreHud\ScoreHud;
use larryTheCoder\arena\api\Arena;
use pocketmine\Player;
use pocketmine\Server;
use pocketmine\utils\Config;

/**
* ScoreHUD compatibility layer class, allows communication with this plugin
* and perhaps improve gameplay experience as v6.0 allows event-driven scoreboards.
*/
class ScoreHUD implements Scoreboard {
class ScoreFilter extends Internal {

public function __construct(){
// TODO: Figure out how to gain dominance in this haha.
}
/** @var ScoreHud */
public $scoreboard = null;

public function __construct(Arena $arena, Config $defaultConf){
parent::__construct($arena, $defaultConf);

public function setStatus(string $status): void{
// TODO: Implement tickScoreboard() method.
// TODO: Check for v6.0, event driven scoreboards, wooo. For now lets stick to v5.2.0
// which is literally discarding or ignoring this plugin functionality.
$this->scoreboard = Server::getInstance()->getPluginManager()->getPlugin("ScoreHud");
}

public function removePlayer(Player $player): void{
if($this->scoreboard !== null){
unset($this->scoreboard->disabledScoreHudPlayers[strtolower($player->getName())]);
}

public function tickScoreboard(): void{
// TODO: Implement tickScoreboard() method.
parent::removePlayer($player);
}

public function resetScoreboard(): void{
// TODO: Implement resetScoreboard() method.
}
public function addPlayer(Player $player): void{
if($this->scoreboard !== null){
ScoreFactory::removeScore($player);

public function removePlayer(Player $pl): void{
// TODO: Implement removePlayer() method.
}
$this->scoreboard->disabledScoreHudPlayers[strtolower($player->getName())] = 1;
}

public function addPlayer(Player $pl): void{
// TODO: Implement addPlayer() method.
parent::addPlayer($player);
}
}
1 change: 1 addition & 0 deletions src/larryTheCoder/commands/SkyWarsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public function onCommand(CommandSender $sender, Command $cmd, array $args): boo
}elseif($arena->hasFlags(Arena::ARENA_OFFLINE_MODE)){
$sender->sendMessage(Settings::$prefix . TranslationContainer::getTranslation($sender, 'arena-hibernation'));
}elseif($arena->getStatus() < ArenaState::STATE_ARENA_RUNNING){
$arena->startArena();
$arena->setStatus(ArenaState::STATE_ARENA_RUNNING);

$sender->sendMessage(Settings::$prefix . TranslationContainer::getTranslation($sender, 'arena-started', ["{ARENA}" => $arena->getMapName()]));
Expand Down
15 changes: 8 additions & 7 deletions src/larryTheCoder/panel/FormManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
use larryTheCoder\utils\cage\CageManager;
use larryTheCoder\utils\PlayerData;
use larryTheCoder\utils\Settings;
use larryTheCoder\worker\LevelAsyncPool;
use pocketmine\block\Slab;
use pocketmine\event\block\BlockBreakEvent;
use pocketmine\event\Listener;
Expand Down Expand Up @@ -231,7 +232,7 @@ function(Player $player, bool $response) use ($arena): void{
FormQueue::sendForm($player, $form);
});

Server::getInstance()->getAsyncPool()->submitTask($task);
LevelAsyncPool::getAsyncPool()->submitTask($task);
}, function(Player $pl): void{
$pl->sendMessage(TC::getTranslation($pl, 'panel-cancelled'));
});
Expand Down Expand Up @@ -665,7 +666,7 @@ private function performWorldCopy(ArenaImpl $arena, callable $onComplete): void{
$onComplete($level);
});

Server::getInstance()->getAsyncPool()->submitTask($task);
LevelAsyncPool::getAsyncPool()->submitTask($task);
}

/**
Expand All @@ -685,9 +686,9 @@ public function showChooseCage(Player $player): void{
$form->append(TC::getTranslation($player, 'cage-selected', ["{CAGE_NAME}" => $cage->getCageName()]));
}elseif($cage->getPrice() > 0){
if(!$player->hasPermission($cage->getCagePermission())){
$form->append(TC::getTranslation($player, 'cage-buy', ["{CAGE_NAME}" => $cage->getCageName()]));
$form->append(TC::getTranslation($player, 'cage-buy', ["{CAGE_NAME}" => $cage->getCageName(), "{CAGE_PRICE}" => $cage->getPrice()]));
}else{
$form->append(TC::getTranslation($player, 'cage-bought', ["{CAGE_NAME}" => $cage->getCageName(), "{CAGE_PRICE}" => $cage->getPrice()]));
$form->append(TC::getTranslation($player, 'cage-bought', ["{CAGE_NAME}" => $cage->getCageName()]));
}
}else{
$form->append(TC::getTranslation($player, 'cage-select', ["{CAGE_NAME}" => $cage->getCageName()]));
Expand Down Expand Up @@ -815,7 +816,7 @@ public function onBlockBreakEvent(BlockBreakEvent $event): void{
$this->cleanupEvent($player, true);
});

Server::getInstance()->getAsyncPool()->submitTask($task);
LevelAsyncPool::getAsyncPool()->submitTask($task);
}

$event->setCancelled();
Expand All @@ -829,15 +830,15 @@ private function cleanupEvent(Player $player, bool $cleanWorld = false): void{
$arena->setFlags(ArenaImpl::ARENA_IN_SETUP_MODE, false);

if($cleanWorld && ($level = Server::getInstance()->getLevelByName($arena->getLevelName())) !== null){
Server::getInstance()->getAsyncPool()->submitTask(new AsyncDirectoryDelete([$level]));
LevelAsyncPool::getAsyncPool()->submitTask(new AsyncDirectoryDelete([$level]));
}
}

if(isset($this->lastHoldIndex[$player->getName()])){
$holdIndex = $this->lastHoldIndex[$player->getName()][0];
$lastItem = $this->lastHoldIndex[$player->getName()][1];

$player->getInventory()->setItem(0, $lastItem);
$player->getInventory()->setItem(0, $lastItem ?? ItemFactory::get(ItemIds::AIR));
$player->getInventory()->setHeldItemIndex($holdIndex);

unset($this->lastHoldIndex[$player->getName()]);
Expand Down
Loading

0 comments on commit 9ab8ef7

Please sign in to comment.