Skip to content

Commit

Permalink
Merge branch 'dev/4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
fuyutsuki committed May 23, 2022
2 parents 9ec815a + eaa65f2 commit 3473c4f
Show file tree
Hide file tree
Showing 40 changed files with 381 additions and 577 deletions.
11 changes: 11 additions & 0 deletions .github/changelogs/4.x/en_us.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# 4.x changelog

## 4.1.x

### 4.1.0

#### :arrow_heading_up: following PMMP changes

- Following up on PMMP 4.x changes
- Just in.

***

## 4.0.x

### 4.0.7
Expand Down
11 changes: 11 additions & 0 deletions .github/changelogs/4.x/ja_jp.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# 4.x 変更履歴

## 4.1.x

### 4.1.0

#### :arrow_heading_up: PMMPの変更に追従

- PMMP 4.xの変更に追従しました
- ただいま。

***

## 4.0.x

### 4.0.7
Expand Down
20 changes: 6 additions & 14 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: Texter
prefix: Texter
main: jp\mcbe\fuyutsuki\Texter\Main
version: 4.0.7
api: 3.19.0 # pmmp/PocketMine-MP
version: 4.1.0
api: 4.3.0
mcpe-protocol:
- 431 # 1.16.220
- 503 # 1.18.31
softdepend:
# aieuo/Mineflow
- Mineflow # >= 2.0
virions:
# jojoe77777/libFormAPI
- libFormAPI # >= 1.3

author: yuko_fuyutsuki
author: yuko fuyutsuki
authors:
# SpecialThanks
- mfmfnek0
Expand Down Expand Up @@ -40,14 +40,6 @@ authors:
website: https://github.com/fuyutsuki/Texter

permissions:
texter.*:
texter.command.txt:
default: op
description: permission that allows player to use texter
children:
texter.command.*:
default: op
description: permission that allows player to use texter commands
children:
texter.command.txt:
default: op
description: permission that allows player to use /txt
description: permission that allows player to use /txt
51 changes: 23 additions & 28 deletions src/jp/mcbe/fuyutsuki/Texter/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,66 +32,61 @@
use jp\mcbe\fuyutsuki\Texter\i18n\TexterLang;
use jp\mcbe\fuyutsuki\Texter\task\SendTextsTask;
use jp\mcbe\fuyutsuki\Texter\text\SendType;
use pocketmine\event\entity\EntityLevelChangeEvent;
use pocketmine\event\level\LevelLoadEvent;
use pocketmine\event\entity\EntityTeleportEvent;
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\event\server\DataPacketSendEvent;
use pocketmine\event\world\WorldLoadEvent;
use pocketmine\network\mcpe\protocol\AvailableCommandsPacket;
use pocketmine\network\mcpe\protocol\ProtocolInfo;
use pocketmine\Player;
use pocketmine\player\Player;
use pocketmine\plugin\Plugin;

/**
* Class EventListener
* @package jp\mcbe\fuyutsuki\Texter
*/
class EventListener implements Listener {

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

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

public function onJoinPlayer(PlayerJoinEvent $ev) {
$player = $ev->getPlayer();
$level = $player->getLevel();
$sendTask = new SendTextsTask($this->plugin, $player, $level, new SendType(SendType::ADD));
$world = $player->getWorld();
$sendTask = new SendTextsTask($player, $world, SendType::ADD());
$this->plugin->getScheduler()->scheduleDelayedRepeatingTask($sendTask, SendTextsTask::DELAY_TICKS, SendTextsTask::TICKING_PERIOD);
}

public function onLoadLevel(LevelLoadEvent $ev) {
$folderName = $ev->getLevel()->getFolderName();
public function onLoadLevel(WorldLoadEvent $ev) {
$folderName = $ev->getWorld()->getFolderName();
if (FloatingTextData::getInstance($folderName) === null) {
$floatingTextData = new FloatingTextData($this->plugin, $folderName);
$floatingTextData->generateFloatingTexts($this->plugin);
$this->plugin->getLogger()->debug("Loaded FloatingTextCluster file: {$folderName}.json");
}
}

public function onEntityLevelChange(EntityLevelChangeEvent $ev) {
public function onEntityLevelChange(EntityTeleportEvent $ev) {
$entity = $ev->getEntity();
if ($entity instanceof Player) {
$from = $ev->getOrigin();
$to = $ev->getTarget();
$removeTask = new SendTextsTask($this->plugin, $entity, $from, new SendType(SendType::REMOVE));
$addTask = new SendTextsTask($this->plugin, $entity, $to, new SendType(SendType::ADD));
$from = $ev->getFrom()->getWorld();
$to = $ev->getTo()->getWorld();
$removeTask = new SendTextsTask($entity, $from, SendType::REMOVE());
$addTask = new SendTextsTask($entity, $to, SendType::ADD());
$scheduler = $this->plugin->getScheduler();
$scheduler->scheduleDelayedRepeatingTask($removeTask, SendTextsTask::DELAY_TICKS, SendTextsTask::TICKING_PERIOD);
$scheduler->scheduleDelayedRepeatingTask($addTask, SendTextsTask::DELAY_TICKS, SendTextsTask::TICKING_PERIOD);
}
}

public function onSendPacket(DataPacketSendEvent $ev) {
$pk = $ev->getPacket();
if ($pk->pid() === ProtocolInfo::AVAILABLE_COMMANDS_PACKET) {
/** @var AvailableCommandsPacket $pk */
if (isset($pk->commandData[TexterCommand::NAME])) {
$locale = $ev->getPlayer()->getLocale();
$texterCommand = $pk->commandData[TexterCommand::NAME];
$texterCommand->commandDescription = TexterLang::fromLocale($locale)->translateString(TexterCommand::DESCRIPTION);
foreach ($ev->getPackets() as $pk) {
if ($pk->pid() === ProtocolInfo::AVAILABLE_COMMANDS_PACKET) {
/** @var AvailableCommandsPacket $pk */
if (isset($pk->commandData[TexterCommand::NAME])) {
$locale = $ev->getTargets()[0]->getPlayerInfo()->getLocale();
$texterCommand = $pk->commandData[TexterCommand::NAME];
$texterCommand->commandDescription = TexterLang::fromLocale($locale)->translateString(TexterCommand::DESCRIPTION);
}
}
}
}
Expand Down
23 changes: 9 additions & 14 deletions src/jp/mcbe/fuyutsuki/Texter/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

use aieuo\mineflow\Main as MineflowMain;
use aieuo\mineflow\variable\DefaultVariables;
use http\Exception;
use Exception;
use jp\mcbe\fuyutsuki\Texter\command\TexterCommand;
use jp\mcbe\fuyutsuki\Texter\data\ConfigData;
use jp\mcbe\fuyutsuki\Texter\data\FloatingTextData;
Expand All @@ -49,29 +49,24 @@
use function glob;
use function mkdir;

/**
* Class Main
* @package jp\mcbe\fuyutsuki\Texter
*/
class Main extends PluginBase {

/** @var string */
private static $prefix;
private const PHAR_HEADER = "phar://";

private static string $prefix;

/** @var ConfigData */
private $config;
/** @var TexterLang */
private $lang;
private ConfigData $config;
private TexterLang $lang;

public function onLoad() {
public function onLoad(): void {
self::setPrefix();
$this->loadResources();
$this->registerCommands();
$this->loadFloatingTexts();
$this->checkUpdate();
}

public function onEnable() {
public function onEnable(): void {
$pluginManager = $this->getServer()->getPluginManager();
if ($this->isPackaged()) {
$pluginManager->registerEvents(new EventListener($this), $this);
Expand Down Expand Up @@ -224,7 +219,7 @@ private function mineflowLinkage() {
}

private function isPackaged(): bool {
if ($this->isPhar()) {
if (str_starts_with($this->getFile(), self::PHAR_HEADER)) {
if (class_exists(Dependencies::PACKAGED_LIBRARY_NAMESPACE . Dependencies::LIB_FORM_API)) {
return true;// PoggitCI
}else {
Expand Down
21 changes: 10 additions & 11 deletions src/jp/mcbe/fuyutsuki/Texter/TexterApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,23 @@
use jp\mcbe\fuyutsuki\Texter\data\FloatingTextData;
use jp\mcbe\fuyutsuki\Texter\text\FloatingTextCluster;
use jp\mcbe\fuyutsuki\Texter\util\Imconstructable;
use pocketmine\level\Level;
use JsonException;
use pocketmine\world\World;

/**
* Class TexterApi
* @package jp\mcbe\fuyutsuki\Texter
*/
final class TexterApi {

use Imconstructable;

/**
* Register FloatingTextCluster to the TexterAPI to show/hide floating text when
* moving between worlds on a server with multiple worlds.
* @param Level $level
* @param World $world
* @param FloatingTextCluster $floatingText
* @return bool registrable?
* @throws JsonException
*/
public static function register(Level $level, FloatingTextCluster $floatingText): bool {
$floatingTextData = FloatingTextData::getInstance($level->getFolderName());
public static function register(World $world, FloatingTextCluster $floatingText): bool {
$floatingTextData = FloatingTextData::getInstance($world->getFolderName());
if ($floatingTextData->notExistsFloatingText($floatingText->name())) {
$floatingTextData->store($floatingText);
$floatingTextData->save();
Expand All @@ -59,12 +57,13 @@ public static function register(Level $level, FloatingTextCluster $floatingText)

/**
* Unregister FloatingTextCluster.
* @param Level $level
* @param World $world
* @param FloatingTextCluster $floatingText
* @return bool unregistered?
* @throws JsonException
*/
public static function unregister(Level $level, FloatingTextCluster $floatingText): bool {
$floatingTextData = FloatingTextData::getInstance($level->getFolderName());
public static function unregister(World $world, FloatingTextCluster $floatingText): bool {
$floatingTextData = FloatingTextData::getInstance($world->getFolderName());
if ($floatingTextData->existsFloatingText($floatingText->name())) {
$floatingTextData->removeFloatingText($floatingText->name());
$floatingTextData->save();
Expand Down
31 changes: 18 additions & 13 deletions src/jp/mcbe/fuyutsuki/Texter/command/TexterCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@
use jp\mcbe\fuyutsuki\Texter\command\sub\RemoveSubCommand;
use jp\mcbe\fuyutsuki\Texter\i18n\TexterLang;
use jp\mcbe\fuyutsuki\Texter\Main;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\PluginCommand;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\Player;
use pocketmine\player\Player;
use pocketmine\plugin\Plugin;
use pocketmine\plugin\PluginOwned;
use pocketmine\utils\TextFormat;

/**
* Class TexterCommand
* @package jp\mcbe\fuyutsuki\Texter\command
*/
class TexterCommand extends PluginCommand {
class TexterCommand extends Command implements PluginOwned {

public const NAME = "txt";
public const DESCRIPTION = "command.txt.description";
public const USAGE = "command.txt.usage";
public const PERMISSION = "texter.command.txt";

public function __construct(Main $plugin) {
parent::__construct(self::NAME, $plugin);
public function __construct(
private Main $plugin
) {
parent::__construct(self::NAME);
$consoleLang = TexterLang::fromConsole();
$description = $consoleLang->translateString(self::DESCRIPTION);
$usage = $consoleLang->translateString(self::USAGE);
Expand All @@ -63,10 +63,11 @@ public function __construct(Main $plugin) {
}

public function execute(CommandSender $sender, string $commandLabel, array $args): bool {
$plugin = $this->getPlugin();
$plugin = $this->getOwningPlugin();
if ($plugin->isDisabled() || !$this->testPermission($sender)) return false;

if ($sender instanceof Player) {
/** @var Player $sender */
$serverLang = $sender->getServer()->getLanguage();
$playerLang = TexterLang::fromLocale($sender->getLocale());
if (isset($args[0])) {
Expand All @@ -83,7 +84,7 @@ public function execute(CommandSender $sender, string $commandLabel, array $args
$message = $serverLang->translateString("commands.generic.usage", [
$playerLang->translateString("command.txt.add.usage")
]);
$sender->sendMessage(Main::prefix() . " {$message}");
$sender->sendMessage(Main::prefix() . " $message");
}
}else {
AddFloatingTextForm::send($sender);
Expand Down Expand Up @@ -122,7 +123,7 @@ public function execute(CommandSender $sender, string $commandLabel, array $args
$message = $serverLang->translateString("commands.generic.usage", [
$playerLang->translateString("command.txt.move.usage")
]);
$sender->sendMessage(Main::prefix() . " {$message}");
$sender->sendMessage(Main::prefix() . " $message");
}else {
ListFloatingTextForm::send($sender, $subCommandLabel);
}
Expand All @@ -138,7 +139,7 @@ public function execute(CommandSender $sender, string $commandLabel, array $args
$message = $serverLang->translateString("commands.generic.usage", [
$playerLang->translateString("command.txt.remove.usage")
]);
$sender->sendMessage(Main::prefix() . " {$message}");
$sender->sendMessage(Main::prefix() . " $message");
}
break;

Expand All @@ -155,4 +156,8 @@ public function execute(CommandSender $sender, string $commandLabel, array $args
return true;
}

public function getOwningPlugin(): Plugin {
return $this->plugin;
}

}
Loading

0 comments on commit 3473c4f

Please sign in to comment.