Skip to content

Commit

Permalink
Merge pull request #20 from 191225/alpha
Browse files Browse the repository at this point in the history
Alpha
  • Loading branch information
Nano191225 authored May 4, 2023
2 parents a9823c3 + 842792b commit 3089178
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 177 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* プレイヤーにformを表示する
* プレイヤーを追放する
* プレイヤーをkillする(クリエイティブモード含む)
* プレイヤーをノックバックする
* プレイヤーのネームタグを変更する
* プレイヤーのネームタグをリセットする
* 複数のコマンドを実行する
Expand Down Expand Up @@ -49,7 +50,6 @@
* 爆発を発生させる
* エンティティをスポーンする
* カスタムされたアイテムをスポーンする
* パーティクルをスポーンする
* ワールド全体にメッセージを送信(say)
* ディメンションを超えてプレイヤーをテレポートさせる
### Config
Expand Down
3 changes: 3 additions & 0 deletions functions/Capi_setup.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,8 @@ scoreboard objectives add Capi:deathPlayer dummy
scoreboard objectives add Capi:itemUseOnX dummy
scoreboard objectives add Capi:itemUseOnY dummy
scoreboard objectives add Capi:itemUseOnZ dummy
scoreboard objectives add Capi:vectorX dummy
scoreboard objectives add Capi:vectorY dummy
scoreboard objectives add Capi:vectorZ dummy
gamerule sendcommandfeedback false
gamerule commandblockoutput false
2 changes: 1 addition & 1 deletion functions/Capi_version.mcfunction
Original file line number Diff line number Diff line change
@@ -1 +1 @@
tellraw @s {"rawtext":[{"text":"Commander API >> Version 1.3.1 (Beta Official Release)"}]}
tellraw @s {"rawtext":[{"text":"Commander API >> Version 1.4.0 (Beta Official Release)"}]}
6 changes: 3 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "Commander API",
"description": "マインクラフト統合版のコマンドを拡張します。",
"uuid": "ebac7142-c210-4d32-87ba-5650be52f456",
"version": [ 1, 3, 1 ],
"version": [ 1, 4, 0 ],
"min_engine_version": [ 1, 19, 0 ]
},
"metadata": {
Expand All @@ -15,13 +15,13 @@
{
"type": "data",
"uuid": "36f425e9-10c9-466d-a620-0362a30c9b6f",
"version": [ 1, 3, 1 ]
"version": [ 1, 4, 0 ]
},
{
"language": "javascript",
"type": "script",
"uuid": "0d1f29e1-417f-48fb-b5fe-5a980830885a",
"version": [ 1, 3, 1 ],
"version": [ 1, 4, 0 ],
"entry": "scripts/index.js"
}
],
Expand Down
239 changes: 147 additions & 92 deletions scripts/index.js

Large diffs are not rendered by default.

199 changes: 122 additions & 77 deletions scripts/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,88 +20,133 @@ import { Database, ExtendedDatabase } from "./lib/Database";
import { setVariable } from "./util";
import Config from "./config";

export class UI {
/**
*
* @param {Minecraft.Player} player
*/
constructor(player) {
this.player = player;
}

export function Menu(player) {
player.removeTag("Capi:open_config_gui");
const Menu = new MinecraftUI.ActionFormData()
.title("§lCommander API")
.body("設定の変更後は §7/reload§r を実行して設定を反映させてください。")
.button("§lプレイヤー退出メッセージ")
.button("§lチャットUI")
.button("§l§c閉じる")
.show(player).then(response => {
if (response.selection === 0) LeaveMsg(player);
if (response.selection === 1) ChatUI(player);
});
}
Menu() { try {
this.player.removeTag("Capi:open_config_gui");
const Form = new MinecraftUI.ActionFormData()
.title("§lCommander API")
.body("設定の変更後は §7/reload§r を実行して設定を反映させてください。")
.button("§lプレイヤー退出メッセージ")
.button("§lチャットUI")
.button("§l送信キャンセル")
.button("§l§4リセット")
.button("§l§c閉じる")
.show(this.player).then(response => {
if (response.selection === 0) this.LeaveMsg();
if (response.selection === 1) this.ChatUI();
if (response.selection === 2) this.CancelSendMsg();
if (response.selection === 3) Config.clear();
});
} catch (e) {console.error(e)}}

const MenuBack = (player) => Menu(player);

function LeaveMsg(player) {
const Menu = new MinecraftUI.ActionFormData()
.title("§lCommander API")
.body(`ステータス: ${Config.get("LeaveMsgEnabled") ? "有効" : "無効"}\nメッセージ: "${Config.get("LeaveMsg")}"`)
.button("§l設定する");
if (Config.get("LeaveMsgEnabled")) Menu.button("§l§c無効にする");
else Menu.button("§l§2有効にする");

Menu.button("§l戻る")
.button("§l§c閉じる")
.show(player).then(response => {
if (response.selection === 0) LeaveMsgConfig(player);
if (response.selection === 1) {
if (Config.get("LeaveMsgEnabled")) Config.set("LeaveMsgEnabled", false);
else Config.set("LeaveMsgEnabled", true);
LeaveMsgBack(player);
}
if (response.selection === 2) MenuBack(player);
});
}

function LeaveMsgConfig(player) {
const Menu = new MinecraftUI.ModalFormData()
.title("§lCommander API")
.textField("メッセージ", "(例) {name} がサーバーから抜けた!", Config.get("LeaveMsg") || null)
.show(player).then(response => {
if (response.formValues[0].length) Config.set("LeaveMsg", String(response.formValues[0]));
else if (!response.canceled) Config.set("LeaveMsg", null);
LeaveMsgBack(player);
});
}
LeaveMsg() { try {
const Form = new MinecraftUI.ActionFormData()
.title("§lCommander API")
.body(`ステータス: ${Config.get("LeaveMsgEnabled") ? "有効" : "無効"}\nメッセージ: "${Config.get("LeaveMsg")}"`)
.button("§l設定する");
if (Config.get("LeaveMsgEnabled")) Form.button("§l§c無効にする");
else Form.button("§l§2有効にする");

Form.button("§l戻る")
.button("§l§c閉じる")
.show(this.player).then(response => {
if (response.selection === 0) this.LeaveMsgConfig();
if (response.selection === 1) {
if (Config.get("LeaveMsgEnabled")) Config.set("LeaveMsgEnabled", false);
else Config.set("LeaveMsgEnabled", true);
this.LeaveMsg();
}
if (response.selection === 2) this.Menu();
});
} catch (e) {console.error(e)}}

const LeaveMsgBack = (player) => LeaveMsg(player);
LeaveMsgConfig() {
const Form = new MinecraftUI.ModalFormData()
.title("§lCommander API")
.textField("メッセージ", "(例) {name} がサーバーから抜けた!", Config.get("LeaveMsg") || null)
.show(this.player).then(response => {
if (response.formValues[0].length) Config.set("LeaveMsg", String(response.formValues[0]));
else if (!response.canceled) Config.set("LeaveMsg", null);
this.LeaveMsg();
});
}

function ChatUI(player) {
const Menu = new MinecraftUI.ActionFormData()
.title("§lCommander API")
.body(`ステータス: ${Config.get("ChatUIEnabled") ? "有効" : "無効"}\nUI: "${Config.get("ChatUI")}"`)
.button("§l設定する");
if (Config.get("ChatUIEnabled")) Menu.button("§l§c無効にする");
else Menu.button("§l§2有効にする");
ChatUI() {
const Form = new MinecraftUI.ActionFormData()
.title("§lCommander API")
.body(`ステータス: ${Config.get("ChatUIEnabled") ? "有効" : "無効"}\nUI: "${Config.get("ChatUI")}"`)
.button("§l設定する");
if (Config.get("ChatUIEnabled")) Form.button("§l§c無効にする");
else Form.button("§l§2有効にする");

Form.button("§l戻る")
.button("§l§c閉じる")
.show(this.player).then(response => {
if (response.selection === 0) this.ChatUIConfig();
if (response.selection === 1) {
if (Config.get("ChatUIEnabled")) Config.set("ChatUIEnabled", false);
else Config.set("ChatUIEnabled", true);
this.ChatUI();
}
if (response.selection === 2) this.Menu();
});
}

Menu.button("§l戻る")
.button("§l§c閉じる")
.show(player).then(response => {
if (response.selection === 0) ChatUIConfig(player);
if (response.selection === 1) {
if (Config.get("ChatUIEnabled")) Config.set("ChatUIEnabled", false);
else Config.set("ChatUIEnabled", true);
ChatUIBack(player);
}
if (response.selection === 2) MenuBack(player);
});
}
ChatUIConfig() {

const Form = new MinecraftUI.ModalFormData()
.title("§lCommander API")
.textField("UI", "(例) {name} >> {message}", Config.get("ChatUI") || null)
.show(this.player).then(response => {
if (response.formValues[0].length) Config.set("ChatUI", String(response.formValues[0]));
else if (!response.canceled) Config.set("ChatUI", null);
this.ChatUI();
});
}

function ChatUIConfig(player) {
CancelSendMsg () {
const Form = new MinecraftUI.ActionFormData()
.title("§lCommander API")
.body(`ステータス: ${Config.get("CancelSendMsgEnabled") ? "有効" : "無効"}\nで始まっているか: "§a${Config.get("CancelSendMsg")?.start.join("§r, §a")}§r"\nで終わっているか: "§a${Config.get("CancelSendMsg")?.end.join("§r, §a")}§r"\nが含まれているか: "§a${Config.get("CancelSendMsg")?.include.join("§r, §a")}§r"`)
.button("§l設定する");
if (Config.get("CancelSendMsgEnabled")) Form.button("§l§c無効にする");
else Form.button("§l§2有効にする");

const Menu = new MinecraftUI.ModalFormData()
.title("§lCommander API")
.textField("UI", "(例) {name} >> {message}", Config.get("ChatUI") || null)
.show(player).then(response => {
if (response.formValues[0].length) Config.set("ChatUI", String(response.formValues[0]));
else if (!response.canceled) Config.set("ChatUI", null);
ChatUIBack(player);
});
}
Form.button("§l戻る")
.button("§l§c閉じる")
.show(this.player).then(response => {
if (response.selection === 0) this.CancelSendMsgConfig();
if (response.selection === 1) {
if (Config.get("CancelSendMsgEnabled")) Config.set("CancelSendMsgEnabled", false);
else Config.set("CancelSendMsgEnabled", true);
this.CancelSendMsg();
}
if (response.selection === 2) this.Menu();
});
}

const ChatUIBack = (player) => ChatUI(player);
CancelSendMsgConfig () {
const Form = new MinecraftUI.ModalFormData()
.title("§lCommander API")
.textField("で始まっているか", "(例) !, ?, #", Config.get("CancelSendMsg")?.start.join(", ") || null)
.textField("で終わっているか", "(例) ,, ., :)", Config.get("CancelSendMsg")?.end.join(", ") || null)
.textField("が含まれているか", "(例) help, !Form", Config.get("CancelSendMsg")?.include.join(", ") || null)
.show(this.player).then(response => {
const object = {
start: response.formValues[0].split(", "),
end: response.formValues[1].split(", "),
include: response.formValues[2].split(", ")
}
Config.set("CancelSendMsg", object);
this.CancelSendMsg();
});
}
}
11 changes: 8 additions & 3 deletions scripts/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ import getScore from "./lib/getScore.js";
* @param {string} text
* @returns
*/
export function setVariable(player, text) {
return new Promise(async (resolve, reject) => { try {
export async function setVariable(player, text) {
return await new Promise(async (resolve, reject) => { try {

if (!player instanceof Minecraft.Player) reject("player needs Player Class");
if (!text?.length) resolve(text);
const dataLength = text.split("").filter(t => t === "{").length;

if (!dataLength) resolve(text);

for (let i = 0; i < dataLength; i++) {
text = text.replace(/({name}|{name,})/i, player.name);
text = text.replace(/({nametag}|{nametag,})/i, player.nameTag);
Expand Down Expand Up @@ -72,8 +76,9 @@ export function setVariable(player, text) {
if (![-1, 0, 1].includes(dimension)) dimension = text.replace(new RegExp(`({dimension:${dimension}}|{dimension:${dimension},})`, "i"), "null");
}
} catch {}

if (dataLength - i === 1) resolve(text);
}
resolve(text);
} catch (e) {reject(e)}})
}

Expand Down

0 comments on commit 3089178

Please sign in to comment.