1 | PlayerEvents.chat(event => {
|
2 | const permission = "whimsy.prefix.phoenix";
|
3 |
|
4 | // Function to check permissions using LuckPerms
|
5 | const checkPermission = (player, callback) => {
|
6 | const LuckPermsProvider = Java.loadClass('net.luckperms.api.LuckPermsProvider');
|
7 | let userManager = LuckPermsProvider.get().getUserManager();
|
8 |
|
9 | let userFuture = userManager.loadUser(player.uuid);
|
10 |
|
11 | userFuture.thenAcceptAsync((user) => {
|
12 | const hasPermission = user.getCachedData().getPermissionData().checkPermission(permission).asBoolean();
|
13 | callback(hasPermission);
|
14 | }).exceptionally((error) => {
|
15 | console.log('Error while checking permissions:', error);
|
16 | callback(false);
|
17 | return null;
|
18 | });
|
19 | };
|
20 |
|
21 | // Ensure the player is defined
|
22 | let sourcePlayer = event.player || null;
|
23 |
|
24 | if (sourcePlayer && event.message.startsWith('!phoenix')) {
|
25 | checkPermission(sourcePlayer, (hasPermission) => {
|
26 | if (!hasPermission) {
|
27 | console.log(`${sourcePlayer.username} does not have the required permission: ${permission}`);
|
28 | event.server.runCommand(`tellraw ${sourcePlayer.username} ["",{"text":"ᴡʜɪᴍꜱʏ ‣","bold":true,"color":"light_purple"},{"text":" You don't have this prefix unlocked!","color":"red"},{"text":" Consider donating to get this prefix:","color":"yellow"},{"text":" "},{"text":"WhimsyStore.com","clickEvent":{"action":"open_url","value":"https://whimsy.buycraft.net/"}}]`)
|
29 | // Cancel the event to prevent unauthorized use
|
30 | event.setCanceled(true);
|
31 | return;
|
32 | }
|
33 |
|
34 | console.log(`${sourcePlayer.username} set their prefix to PHOENIX.`);
|
35 | // Run a command from the console
|
36 | event.server.runCommand(`lp user ${sourcePlayer.username} parent remove fairy`);
|
37 | event.server.runCommand(`lp user ${sourcePlayer.username} parent remove harpy`);
|
38 | event.server.runCommand(`lp user ${sourcePlayer.username} parent remove siren`);
|
39 | event.server.runCommand(`lp user ${sourcePlayer.username} parent remove mermaid`);
|
40 | event.server.runCommand(`lp user ${sourcePlayer.username} parent remove cerberus`);
|
41 | event.server.runCommand(`lp user ${sourcePlayer.username} parent add phoenix`);
|
42 | event.server.runCommand(`tellraw ${sourcePlayer.username} ["",{"text":"ᴡʜɪᴍꜱʏ ‣","bold":true,"color":"light_purple"},{"text":" Your prefix set to "},{"text":"Phoenix","color":"dark_red"},{"text":"."}]`)
|
43 | });
|
44 | }
|
45 | });
|