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 Jun 1, 2022
2 parents 3473c4f + a1f80a8 commit cb1ade7
Show file tree
Hide file tree
Showing 23 changed files with 198 additions and 126 deletions.
6 changes: 6 additions & 0 deletions .github/changelogs/4.x/en_us.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## 4.1.x

### 4.1.1

#### :bug: Bug fix

- Fixed a crash when using forms

### 4.1.0

#### :arrow_heading_up: following PMMP changes
Expand Down
6 changes: 6 additions & 0 deletions .github/changelogs/4.x/ja_jp.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## 4.1.x

### 4.1.1

#### :bug: バグ修正

- フォームを使用するとサーバーがクラッシュする問題を修正しました

### 4.1.0

#### :arrow_heading_up: PMMPの変更に追従
Expand Down
4 changes: 2 additions & 2 deletions .github/readme/ja_jp.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Texterは複数ワールドに対応した、FloatingText(浮き文字)の追加
- [ ] id_id(インドネシア語)
- [x] ja_jp(日本語)
- [ ] ko_kr(韓国語)
- [x] ru_ru(ロシア語)
- [ ] ru_ru(ロシア語)
- [ ] tr_tr(トルコ語)
- [ ] zh_cn(中国語/簡体)
- [x] vi_vn(ベトナム語)
- [ ] vi_vn(ベトナム語)
4 changes: 2 additions & 2 deletions .github/readme/ru_ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Texter - это плагин для [PocketMine-MP](https://github.com/pmmp/Pock
- [ ] id_id(Indonesian)
- [x] ja_jp(Japanese)
- [ ] ko_kr(Korean)
- [x] ru_ru(Russian)
- [ ] ru_ru(Russian)
- [ ] tr_tr(Turkish)
- [ ] zh_cn(Chinese/Simplified)
- [x] vi_vn(Vietnamese)
- [ ] vi_vn(Vietnamese)
4 changes: 2 additions & 2 deletions .github/readme/vi_vn.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ PR luôn được mở!
- [ ] id_id(Tiếng In-đô-nê-xi-a)
- [x] ja_jp(Tiếng Nhật)
- [ ] ko_kr(Tiếng Hàng)
- [x] ru_ru(Tiếng Nga)
- [ ] ru_ru(Tiếng Nga)
- [ ] tr_tr(Tiếng Thủ Nhĩ Kỳ)
- [ ] zh_cn(Tiếng Trung Quốc)
- [x] vi_vn(Tiếng Việt)
- [ ] vi_vn(Tiếng Việt)
4 changes: 2 additions & 2 deletions .poggit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ projects:
path: ""
icon: "/assets/Logo.png"
libs:
- src: jojoe77777/FormAPI/libFormAPI
version: 1.3.0
- src: dktapps-pm-pl/pmforms/pmforms
version: ^2.0.0
...
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ The supported languages will be automatically translated according to the langua

#### Support status

PR in other languages is welcome!
issue or PR in other languages is welcome!

- [x] en_us(English)
- [ ] id_id(Indonesian)
Expand All @@ -83,4 +83,4 @@ PR in other languages is welcome!
- [ ] ru_ru(Russian)
- [ ] tr_tr(Turkish)
- [ ] zh_cn(Chinese/Simplified)
- [x] vi_vn(Vietnamese)
- [ ] vi_vn(Vietnamese)
6 changes: 3 additions & 3 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: Texter
prefix: Texter
main: jp\mcbe\fuyutsuki\Texter\Main
version: 4.1.0
version: 4.1.1
api: 4.3.0
mcpe-protocol:
- 503 # 1.18.31
softdepend:
# aieuo/Mineflow
- Mineflow # >= 2.0
virions:
# jojoe77777/libFormAPI
- libFormAPI # >= 1.3
# dktapps-pm-pl/pmforms
- pmforms # ^2.0.0

author: yuko fuyutsuki
authors:
Expand Down
2 changes: 1 addition & 1 deletion resources/language/en_us.ini
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ form.list.description.1=Lists editable FloatingTexts within 10 blocks of straigh
form.list.description.2=Specified FloatingText name: {%0}\nPlease select the operation to do for this.
error.on.enable.not.packaged=Please use the phar file downloaded from PoggitCI (https://poggit.pmmp.io/p/Texter).
error.on.enable.not.found.libformapi=Can't find the libFormAPI in the virions folder. Please download libFormAPI and install it correctly.
error.on.enable.not.found.virions=Can't find the {%0} in the virions folder. Please download {%0} and install it correctly.
error.ft.name.not.specified=A FloatingText name is not specified
error.ft.name.exists=A FloatingText with the specified name: {%0} already exists.
error.ft.name.not.exists=No FloatingText with the specified name: {%0} does not exist.
Expand Down
2 changes: 1 addition & 1 deletion resources/language/ja_jp.ini
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ form.list.description.1=自分から直線距離10ブロック以内の編集可
form.list.description.2=指定された浮き文字: "{%0}"\nこの浮き文字に行う操作を選択して下さい。

error.on.enable.not.packaged=PoggitCI(https://poggit.pmmp.io/p/Texter)からダウンロードしたpharファイルを使ってください。
error.on.enable.not.found.libformapi=virionsフォルダにlibFormAPIが見つかりません。libFormAPIをダウンロードし、正しく導入してください。
error.on.enable.not.found.virions=virionsフォルダに{%0}が見つかりません。{%0}をダウンロードし、正しく導入してください。
error.ft.name.not.specified=浮き文字の名前が指定されていません
error.ft.name.exists=このワールドには"{%0}"の名前を持つ浮き文字が既に存在します。
error.ft.name.not.exists=このワールドには"{%0}"の名前を持つ浮き文字は存在しません。
Expand Down
2 changes: 1 addition & 1 deletion src/jp/mcbe/fuyutsuki/Texter/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function onLoadLevel(WorldLoadEvent $ev) {
if (FloatingTextData::getInstance($folderName) === null) {
$floatingTextData = new FloatingTextData($this->plugin, $folderName);
$floatingTextData->generateFloatingTexts($this->plugin);
$this->plugin->getLogger()->debug("Loaded FloatingTextCluster file: {$folderName}.json");
$this->plugin->getLogger()->debug("Loaded FloatingTextCluster file: $folderName.json");
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/jp/mcbe/fuyutsuki/Texter/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
use function explode;
use function file_exists;
use function glob;
use function implode;
use function mkdir;
use function str_starts_with;

class Main extends PluginBase {

Expand Down Expand Up @@ -220,7 +222,7 @@ private function mineflowLinkage() {

private function isPackaged(): bool {
if (str_starts_with($this->getFile(), self::PHAR_HEADER)) {
if (class_exists(Dependencies::PACKAGED_LIBRARY_NAMESPACE . Dependencies::LIB_FORM_API)) {
if (class_exists(Dependencies::PACKAGED_LIBRARY_NAMESPACE . Dependencies::PMFORMS)) {
return true;// PoggitCI
}else {
$message = $this->lang->translateString("error.on.enable.not.packaged");
Expand All @@ -230,10 +232,10 @@ private function isPackaged(): bool {
}else {
$plugins = $this->getServer()->getPluginManager()->getPlugins();
if (isset($plugins["DEVirion"])) {
if (class_exists(Dependencies::LIB_FORM_API)) {
if (class_exists(Dependencies::PMFORMS)) {
return true;// developer
}else {
$message = $this->lang->translateString("error.on.enable.not.found.libformapi");
$message = $this->lang->translateString("error.on.enable.not.found.virions", [implode(", ", ["pmforms"])]);
$this->getLogger()->critical($message);
return false;
}
Expand Down
1 change: 0 additions & 1 deletion src/jp/mcbe/fuyutsuki/Texter/command/TexterCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public function execute(CommandSender $sender, string $commandLabel, array $args
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 Down
70 changes: 41 additions & 29 deletions src/jp/mcbe/fuyutsuki/Texter/command/form/AddFloatingTextForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

namespace jp\mcbe\fuyutsuki\Texter\command\form;

use jojoe77777\FormAPI\CustomForm;
use dktapps\pmforms\CustomForm;
use dktapps\pmforms\CustomFormResponse;
use dktapps\pmforms\element\Input;
use dktapps\pmforms\element\Label;
use dktapps\pmforms\element\StepSlider;
use dktapps\pmforms\element\Toggle;
use jp\mcbe\fuyutsuki\Texter\data\FloatingTextData;
use jp\mcbe\fuyutsuki\Texter\i18n\TexterLang;
use jp\mcbe\fuyutsuki\Texter\Main;
Expand All @@ -13,80 +18,87 @@
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\utils\TextFormat;
use Ramsey\Uuid\Uuid;
use function count;
use function range;
use function strtolower;

class AddFloatingTextForm extends CustomForm {

private ?FloatingTextSession $session;

public function __construct(Player $player) {
parent::__construct(null);
$playerName = strtolower($player->getName());
$lang = TexterLang::fromLocale($player->getLocale());
$this->session = FloatingTextSession::get($playerName);
if ($this->session === null) {
$this->session = new FloatingTextSession($playerName, $lang);
}

$elements = [];
$inputName = $lang->translateString("form.ft.name.unique");

$this->setTitle(Main::prefix() . " txt > " . ($this->session->isEdit() ? "edit" : "add"));

if ($this->session->hasNoTexts()) {
$this->session->setNoTexts(false);
$this->addLabel(TextFormat::RED . "[!]" . $lang->translateString("form.add.error.no.texts"));
$elements[] = new Label(Uuid::uuid4()->getBytes(), TextFormat::RED . "[!]" . $lang->translateString("form.add.error.no.texts"));
}
if ($this->session->isDuplicateName()) {
$this->session->setDuplicateName(false);
$this->addLabel(TextFormat::RED . "[!]" . $lang->translateString("error.ft.name.exists", [
$elements[] = new Label(Uuid::uuid4()->getBytes(), TextFormat::RED . "[!]" . $lang->translateString("error.ft.name.exists", [
$this->session->name(),
]));
}

$this->addLabel($lang->translateString("form.add.description"));
$this->addInput($inputName, $inputName, $this->session->name(), FormLabels::NAME);
$elements[] = new Label(Uuid::uuid4()->getBytes(), $lang->translateString("form.add.description"));
$elements[] = new Input(FormLabels::NAME, $inputName, $inputName, $this->session->name());

if (count($this->session->texts()) >= 2) {
$spacing = $this->session->spacing()->multiply(10)->add(30, 30, 30);
$range = range(-30, 30);
foreach ($range as $k => $v) {
$range[$k] = (string)($v/10);
}
$this->addLabel($lang->translateString("form.add.spacing.description"));
$this->addStepSlider($lang->translateString("form.add.spacing.x"), $range, $spacing->getFloorX(), FormLabels::X);
$this->addStepSlider($lang->translateString("form.add.spacing.y"), $range, $spacing->getFloorY(), FormLabels::Y);
$this->addStepSlider($lang->translateString("form.add.spacing.z"), $range, $spacing->getFloorZ(), FormLabels::Z);
$this->addLabel($lang->translateString("command.txt.usage.cluster.remove"));
$elements[] = new Label(Uuid::uuid4()->getBytes(), $lang->translateString("form.add.spacing.description"));
$elements[] = new StepSlider(FormLabels::X, $lang->translateString("form.add.spacing.x"), $range, $spacing->getFloorX());
$elements[] = new StepSlider(FormLabels::Y, $lang->translateString("form.add.spacing.y"), $range, $spacing->getFloorY());
$elements[] = new StepSlider(FormLabels::Z, $lang->translateString("form.add.spacing.z"), $range, $spacing->getFloorZ());
$elements[] = new Label(Uuid::uuid4()->getBytes(), $lang->translateString("command.txt.usage.cluster.remove"));
}

$this->addLabel($lang->translateString("command.txt.usage.new.line"));
$elements[] = new Label(Uuid::uuid4()->getBytes(), $lang->translateString("command.txt.usage.new.line"));
if (empty($this->session->texts())) {
$this->session->addText("");
}
foreach ($this->session->texts() as $key => $text) {
$inputText = $lang->translateString("form.add.text", [
$key + 1,
]);
$this->addInput($inputText, $inputText, $text, FormLabels::TEXT . "_$key");
}
$this->addToggle($lang->translateString("form.add.more.ft"), null, FormLabels::ADD_MORE);
}

public function handleResponse(Player $player, $data): void {
if ($data === null) {
FloatingTextSession::remove(strtolower($player->getName()));
return;
$elements[] = new Input(FormLabels::TEXT . "_$key", $inputText, $inputText, $text);
}
$elements[] = new Toggle(FormLabels::ADD_MORE, $lang->translateString("form.add.more.ft"));

parent::__construct(
Main::prefix() . " txt > " . ($this->session->isEdit() ? "edit" : "add"),
$elements,
function(Player $player, CustomFormResponse $response): void {
$this->handleSubmit($player, $response);
},
function(Player $player): void {
FloatingTextSession::remove(strtolower($player->getName()));
}
);

$this->processData($data);
}

$this->session->setName($data[FormLabels::NAME]);
private function handleSubmit(Player $player, CustomFormResponse $response): void {
$this->session->setName($response->getString(FormLabels::NAME));
$texts = $this->session->texts();
$this->session->setTexts([]);

$empty = 0;
foreach ($texts as $key => $text) {
if (!empty($data[FormLabels::TEXT . "_$key"])) {
$this->session->addText($data[FormLabels::TEXT . "_$key"]);
if (!empty($response->getString(FormLabels::TEXT . "_$key"))) {
$this->session->addText($response->getString(FormLabels::TEXT . "_$key"));
}else {
++$empty;
}
Expand All @@ -104,11 +116,11 @@ public function handleResponse(Player $player, $data): void {

$spacing = null;
if (count($texts) >= 2) {
$spacing = new Vector3($data[FormLabels::X], $data[FormLabels::Y], $data[FormLabels::Z]);
$spacing = new Vector3($response->getFloat(FormLabels::X), $response->getFloat(FormLabels::Y), $response->getFloat(FormLabels::Z));
$spacing = $spacing->subtract(30, 30, 30)->divide(10);
}

if ($data[FormLabels::ADD_MORE]) {
if ($response->getBool(FormLabels::ADD_MORE)) {
$this->session->addText("");
self::send($player);
}else {
Expand Down
Loading

0 comments on commit cb1ade7

Please sign in to comment.