Skip to content

Commit

Permalink
/stop offline menu now menulist, pagemenu empty arr support
Browse files Browse the repository at this point in the history
  • Loading branch information
Jurorno9 authored and BalaM314 committed Jan 26, 2025
1 parent c4a5a15 commit 8a92a86
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 15 deletions.
14 changes: 9 additions & 5 deletions build/scripts/menus.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 17 additions & 3 deletions build/scripts/staffCommands.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions src/menus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,12 @@ export function pageMenu(title: string, description: string, elements: GUI_Eleme
let pages = elements.length
function drawpage(index: number) {
let e: GUI_Element[] = [];
e.push(...elements[index])
e.push(new GUI_Page(index + 1, pages))
if(!pages){
e.push(new GUI_Cancel());
}else{
e.push(...elements[index])
e.push(new GUI_Page(index + 1, pages))
}
menu(title, description, e, target, (res) => {
// handle control element of the ui
if (typeof res.data === 'string') {
Expand All @@ -143,17 +147,16 @@ export function pageMenu(title: string, description: string, elements: GUI_Eleme
break;
default:
callback(res);
break;
}
} else {
callback(res);
}
})
return;
}
drawpage(0);

}
//TODO make list a GUI_Element[] instead of a single Container
//TODO use GUI_Element for formatting instead of defaulting to single column
export function listMenu(title: string, description: string, list: GUI_Container, target: FishPlayer, callback: (opts: { data: any, text: string, sender: FishPlayer, outputSuccess: (message: string) => void, outputFail: (message: string) => void; }) => void, pageSize: number = 10) {
let pooledData: any[] = [];
list.data().flat().forEach((data) => { pooledData.push(data) });
Expand Down
18 changes: 16 additions & 2 deletions src/staffCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { maxTime } from "./globals";
import { updateMaps } from "./files";
import * as fjsContext from "./fjsContext";
import { fishState, ipPattern, uuidPattern } from "./globals";
import { GUI_Cancel, GUI_Confirm, GUI_Container, menu } from './menus';
import { GUI_Cancel, GUI_Confirm, GUI_Container, listMenu, menu } from './menus';
import { FishPlayer } from "./players";
import { Rank } from "./ranks";
import { addToTileHistory, colorBadBoolean, formatTime, formatTimeRelative, getAntiBotInfo, logAction, match, serverRestartLoop, untilForever, updateBans } from "./utils";
Expand Down Expand Up @@ -223,7 +223,7 @@ export const commands = commandList({
}


menu("Stop", "Choose a player to mark", [new GUI_Container(possiblePlayers, "auto", p => p.lastName), new GUI_Cancel()], sender, ({data: optionPlayer, sender}) => {
listMenu("Stop", "Choose a player to mark", new GUI_Container(possiblePlayers, "auto", (p:PlayerInfo) => {return p.lastName}), sender, ({data: optionPlayer}) => {
if(args.time == null){
menu("Stop", "Select stop time", [new GUI_Container(["2 days", "7 days", "30 days", "forever"])], sender, ({text: optionTime}) => {
const time =
Expand Down Expand Up @@ -406,6 +406,7 @@ export const commands = commandList({
return;
}
//Overload 3: ban by menu
/*
menu(`[scarlet]BAN[]`, "Choose a player to ban.", [new GUI_Container(setToArray(Groups.player), "auto", opt => opt.name), new GUI_Cancel()], sender, ({data:target}) => {
if(target.admin) fail(`Cannot ban an admin.`);
menu("Confirm", `Are you sure you want to ban ${target.name}?`, [new GUI_Confirm()], sender, ({data:confirm}) => {
Expand All @@ -418,6 +419,19 @@ export const commands = commandList({
updateBans(player => `[scarlet]Player [yellow]${player.name}[scarlet] has been whacked by ${sender.prefixedName}.`);
});
});
*/
listMenu(`[scarlet]BAN[]`, "Choose a player to ban.", new GUI_Container(setToArray(Groups.player), "auto", opt => opt.name), sender, ({data:target}) => {
if(target.admin) fail(`Cannot ban an admin.`);
menu("Confirm", `Are you sure you want to ban ${target.name}?`, [new GUI_Confirm()], sender, ({data:confirm}) => {
if(!confirm) fail("Cancelled.");
admins.banPlayerIP(target.ip()); //this also bans the UUID
api.ban({ip: target.ip(), uuid: target.uuid()});
Log.info(`${target.ip()}/${target.uuid()} was banned.`);
logAction("banned", sender, target.getInfo());
outputSuccess(f`Banned player ${target}.`);
updateBans(player => `[scarlet]Player [yellow]${player.name}[scarlet] has been whacked by ${sender.prefixedName}.`);
});
});
}
},

Expand Down

0 comments on commit 8a92a86

Please sign in to comment.