Skip to content

Commit

Permalink
chore: 1.17 and adventure chat for professions
Browse files Browse the repository at this point in the history
  • Loading branch information
bensku committed Jul 7, 2021
1 parent 8c2c2bf commit c193a00
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 26 deletions.
12 changes: 0 additions & 12 deletions package-lock.json

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

30 changes: 17 additions & 13 deletions src/chat/prompt.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { clickEvent, color, text } from 'craftjs-plugin/chat';
import { UUID } from 'java.util';
import { CommandSender, ConsoleCommandSender } from 'org.bukkit.command';
import { Player } from 'org.bukkit.entity';
import { Action } from 'net.md_5.bungee.api.chat.ClickEvent';
import { ConsoleCommandSender } from 'org.bukkit.command';
import { sendMessages } from './system';
import { Audience } from 'net.kyori.adventure.audience';
import { Action } from 'net.kyori.adventure.text.event.ClickEvent';

/**
* Pending prompts.
*/
const pendingPrompts: Map<
CommandSender | Player,
Audience,
Map<string, (action: string) => void>
> = new Map();

Expand All @@ -25,7 +26,7 @@ export class Prompt {
/**
* Target command sender.
*/
private target: CommandSender | Player;
private target: Audience;

/**
* If we should try to automatically 'support' console that can't click
Expand All @@ -47,15 +48,17 @@ export class Prompt {
* is not perfect, so commands that are commonly used from console might want
* to do their own thing and disable this.
*/
constructor(target: CommandSender | Player, consoleSupport = true) {
constructor(target: Audience, consoleSupport = true) {
this.target = target;
this.consoleSupport = consoleSupport;
this.randomId = UUID.randomUUID().toString(); // No need for secure randomness

// If console and console support is toggled on, send initial message
if (consoleSupport && this.target instanceof ConsoleCommandSender) {
target.sendMessage(
`[Prompt] Chat prompt for console created; randomId=${this.randomId}`,
text(
`[Prompt] Chat prompt for console created; randomId=${this.randomId}`,
),
);
}
}
Expand Down Expand Up @@ -161,24 +164,25 @@ registerCommand(
* if they typed the right commands in chat by hand.
*/
export async function promptYesNo(
target: CommandSender | Player,
target: Audience,
timeout: number,
promptText: string,
): Promise<string> {
const prompt = new Prompt(target);
target.sendMessage(
sendMessages(
target,
text(promptText + ' '),
color('#00AA00', text('✔')),
color('#00AA00', '✔'),
clickEvent(
Action.RUN_COMMAND,
prompt.command('yes'),
color('#55FF55', text('Kyllä ')),
color('#55FF55', 'Kyllä '),
),
color('#AA0000', text('✘')),
color('#AA0000', '✘'),
clickEvent(
Action.RUN_COMMAND,
prompt.command('no'),
color('#FF5555', text('Ei ')),
color('#FF5555', 'Ei '),
),
);
return prompt.waitAnswer(timeout);
Expand Down
2 changes: 1 addition & 1 deletion src/chat/style/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export function getChatTheme(player: Player): Theme<TextColor> {
];
}

export function defaultChatTheme(): Theme<ChatColor> {
export function defaultChatTheme(): Theme<TextColor> {
return COMPILED_THEMES.default;
}

Expand Down

0 comments on commit c193a00

Please sign in to comment.