Skip to content

Commit

Permalink
Update Version 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gamelist1990 committed Sep 18, 2024
2 parents 17dfd4e + 3acc746 commit 644e462
Show file tree
Hide file tree
Showing 41 changed files with 13,578 additions and 382 deletions.
15 changes: 12 additions & 3 deletions devFolder/src/Loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ world.afterEvents.worldInitialize.subscribe(async () => {

const endTime = Date.now();
const loadTime = endTime - startTime;
console.warn(`Plugin has been loaded in ${loadTime} ms`);
world.sendMessage(`[Server]§l§apluginのデータの更新が ${loadTime} msで完了しました`)
if (c().module.debugMode.enabled === true) {
console.warn(`Plugin has been loaded in ${loadTime} ms`);
}
world.sendMessage(`§f[§bServer§f]§l§aChestLockAddonのデータの更新が ${loadTime} msで完了しました`)
});

//Custom Item
Expand All @@ -51,8 +53,15 @@ world.afterEvents.itemUse.subscribe(({ itemStack: item, source: player }) => {
item.nameTag === customCommandsConfig.ui.ui_item_name &&
!c().commands.item.requireTag.some((tag) => !player.hasTag(tag))
) {
if (c().module.debugMode.enabled === true) {
console.warn(`${player.name} has Use ShowUI`);
}
showBasicUI(player);
}
});

console.warn('Full ChestLock Addon Data loaded!!');

if (c().module.debugMode.enabled === true) {
console.warn('Full ChestLock Addon Data loaded!!');

}
8 changes: 6 additions & 2 deletions devFolder/src/Modules/DataBase.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { world } from '@minecraft/server';
import { c } from './Util';

interface ChestLockAddonData {
[key: string]: any;
}

export let chestLockAddonData: ChestLockAddonData = {};

// データの保存・更新関数
export function saveData(key: string, value: any): void {
chestLockAddonData[key] = value;
const data = JSON.stringify(chestLockAddonData);
Expand All @@ -29,5 +29,9 @@ export function logData(): void {
// ResetData
export function resetData(): void {
chestLockAddonData = {};
console.warn('ChestLockAddon Data reset');
if (c().module.debugMode.enabled === true) {
console.warn('ChestLockAddon Data reset');
}

world.sendMessage("§l§eWarn §aChestLockAddon DataBase is Reset");
}
2 changes: 1 addition & 1 deletion devFolder/src/Modules/Handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ function levenshteinDistance(a: string, b: string): number {
}

// チャットイベントリスナー
//@ts-ignore
world.beforeEvents.chatSend.subscribe((event: any) => {
const { message, sender: player } = event;

Expand All @@ -146,6 +145,7 @@ world.beforeEvents.chatSend.subscribe((event: any) => {
if (!args) return;

const commandName = args.shift()?.toLowerCase().trim();
event.cancel = true;

if (commandName === 'yes' && pendingCommand && pendingCommand.player === player) {
const { command, args: pendingArgs } = pendingCommand;
Expand Down
26 changes: 24 additions & 2 deletions devFolder/src/Modules/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ interface CommandConfig {
requireTag: string[];
}

interface moduleConfig {
enabled:boolean;

}

//コマンド登録 関数C
export const c = (): { commands: { [key: string]: CommandConfig }; admin: string } => ({
export const c = (): { commands: { [key: string]: CommandConfig }; admin: string, module: {[key: string]: moduleConfig}; } => ({
commands: {
chest: {
enabled: true,
Expand Down Expand Up @@ -84,10 +89,27 @@ export const c = (): { commands: { [key: string]: CommandConfig }; admin: string
adminOnly: false,
requireTag: [],
},
report: {
enabled: true,
adminOnly: false,
requireTag: [],
},
staff: {
enabled: true,
adminOnly: false,
requireTag: ["staff","op"],
},

},

admin: 'op',

module: {
debugMode: {
enabled:true,
}
},


});

export function getGamemode(playerName: string) {
Expand Down
2 changes: 1 addition & 1 deletion devFolder/src/Modules/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const ver = '1.0';
export const ver = '1.1';
160 changes: 131 additions & 29 deletions devFolder/src/command/gui/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,70 @@ import { ActionFormData, ModalFormData } from '@minecraft/server-ui';
import { Player } from '@minecraft/server';
import { runCommand } from '../../Modules/Handler';
import { getTpaRequests } from '../utility/tpa';
import { getAllPlayerNames } from '../../Modules/Util';
import { getAvailableLanguages, translate } from '../langs/list/LanguageManager';
import { getAllPlayerNames } from '../../Modules/Util';
import { checkReports } from '../utility/report';

export function showBasicUI(player: Player): Promise<void> {
player.playSound('mob.chicken.plop');
const form = new ActionFormData()
.title('Main Menu')
.body(translate(player, 'ChooseCom'))
.button(translate(player, 'uihelp'), 'textures/items/book_writable')
.button(translate(player, 'uichest'), 'textures/blocks/chest_front')
.body(translate(player, 'ChooseCom'));

// ボタンの内容を条件分岐で変更
if (player.hasTag("staff") || player.hasTag("op")) {
form.button(translate(player, 'ui.StaffMenu'), 'textures/items/book_writable'); // アイコンはそのまま
} else {
form.button(translate(player, 'uihelp'), 'textures/items/book_writable');
}

form.button(translate(player, 'uichest'), 'textures/blocks/chest_front')
.button(translate(player, 'uilang'), 'textures/ui/language_glyph_color')
.button(translate(player, 'uijpch'), 'textures/ui/chat_send')
.button(translate(player, 'uitpa'), 'textures/items/ender_pearl')
.button(translate(player, 'ui.MainLoreButton'), 'textures/items/name_tag')
.button('Exit');
.button(translate(player, 'ui.ReportButton'), 'textures/ui/icon_bell')
.button(translate(player, 'back'));


return form
//@ts-ignore
.show(player)
.then((response) => {
if (response.canceled) {
} else {
switch (response.selection) {
case 0:
return; // キャンセルされた場合は何もしない
}

let selection: number = response.selection !== undefined ? response.selection : -1;



switch (selection) {
case 0:
if (player.hasTag("staff") || player.hasTag("op")) {
showStaffUI(player);
} else {
runCommand(player.name, 'help');
break;
case 1:
showChestMenu(player);
break;
case 2:
showLangMenu(player);
break;
case 3:
showjpchMenu(player);
break;
case 4:
showTpaMenu(player);
break;
case 5:
showloreMenu(player);
break;
}
}
break;
case 1:
showChestMenu(player);
break;
case 2:
showLangMenu(player);
break;
case 3:
showjpchMenu(player);
break;
case 4:
showTpaMenu(player);
break;
case 5:
showloreMenu(player);
break;
case 6:
showReportMenu(player);
break;
}
})
.catch((error: Error) => {
Expand All @@ -52,6 +74,33 @@ export function showBasicUI(player: Player): Promise<void> {
});
}

// スタッフ専用のUIを表示する関数
function showStaffUI(player: Player): Promise<void> {
// スタッフUIの内容を定義
const staffForm = new ActionFormData()
.title('Staff Menu')
.button(translate(player,"ui.checkReports"))
.button('Main Menu');

return staffForm
//@ts-ignore
.show(player)
.then((response) => {
if (response.canceled) {
return;
}

switch (response.selection) {
case 0:
checkReports(player);
break;
case 1:
showBasicUI(player);
break;
}
});
}

function showChestMenu(player: Player): Promise<void> {
player.playSound('mob.chicken.plop');
const form = new ActionFormData()
Expand Down Expand Up @@ -433,14 +482,14 @@ function showTpaRequestsMenu(player: Player, requests: string[]): Promise<void>
function showSendTpaMenu(player: Player): Promise<void> {
player.playSound('mob.chicken.plop');

const playerNames = getAllPlayerNames(player);
const playerNames = player.dimension.getPlayers();

const form = new ActionFormData()
.title('Send TPA Request')
.body(translate(player, 'SendTpaSelect'));

playerNames.forEach((playerName) => {
form.button(playerName);
playerNames.forEach((p) => {
form.button(p.name);
});

form.button(translate(player, 'back'));
Expand All @@ -458,7 +507,7 @@ function showSendTpaMenu(player: Player): Promise<void> {
response.selection < playerNames.length
) {
const targetPlayerName = playerNames[response.selection];
runCommand(player.name, 'tpa', ['-r', targetPlayerName]);
runCommand(player.name, 'tpa', ['-r', targetPlayerName.name]);
} else if (response.selection === playerNames.length) {
showTpaMenu(player);
} else {
Expand Down Expand Up @@ -538,3 +587,56 @@ function showChangeName(player: Player): void {
function ClearLore(player: Player): void {
runCommand(player.name, 'lore', ['-slot', '0', '-clear','a']);
}


function showReportMenu(player: Player): Promise<void> {
player.playSound('mob.chicken.plop');

const playerNames = getAllPlayerNames(player);

const form = new ActionFormData()
.title('Report Request')
.body(translate(player, 'ui.reportPSelect'));

playerNames.forEach((p) => {
form.button(p);
});

form.button(translate(player, 'back'));

return (
form
//@ts-ignore
.show(player)
.then((response) => {
if (response.canceled) {
} else {
if (
response.selection !== undefined &&
response.selection >= 0 &&
response.selection < playerNames.length
) {
const targetPlayerName = playerNames[response.selection];
const modal = new ModalFormData()
.title('Report Reason')
.textField(translate(player,"ui.EnterReport"), '');

//@ts-ignore
modal.show(player).then((modalResponse) => {
if (modalResponse.canceled || modalResponse.formValues === undefined) return;

const reason = modalResponse.formValues[0] as string;
runCommand(player.name, 'report', [targetPlayerName, '-r', reason]);
});
} else if (response.selection === playerNames.length) {
showBasicUI(player);
} else {
}
}
})
.catch((error: Error) => {
console.error(translate(player, 'FromError'), error);
player.sendMessage(translate(player, 'FromError') + error.message);
})
);
}
Loading

0 comments on commit 644e462

Please sign in to comment.