PlayerEvents.chat(event => { const permission = "whimsy.prefix.phoenix"; // Function to check permissions using LuckPerms const checkPermission = (player, callback) => { const LuckPermsProvider = Java.loadClass('net.luckperms.api.LuckPermsProvider'); let userManager = LuckPermsProvider.get().getUserManager(); let userFuture = userManager.loadUser(player.uuid); userFuture.thenAcceptAsync((user) => { const hasPermission = user.getCachedData().getPermissionData().checkPermission(permission).asBoolean(); callback(hasPermission); }).exceptionally((error) => { console.log('Error while checking permissions:', error); callback(false); return null; }); }; // Ensure the player is defined let sourcePlayer = event.player || null; if (sourcePlayer && event.message.startsWith('!phoenix')) { checkPermission(sourcePlayer, (hasPermission) => { if (!hasPermission) { console.log(`${sourcePlayer.username} does not have the required permission: ${permission}`); 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/"}}]`) // Cancel the event to prevent unauthorized use event.setCanceled(true); return; } console.log(`${sourcePlayer.username} set their prefix to PHOENIX.`); // Run a command from the console event.server.runCommand(`lp user ${sourcePlayer.username} parent remove fairy`); event.server.runCommand(`lp user ${sourcePlayer.username} parent remove harpy`); event.server.runCommand(`lp user ${sourcePlayer.username} parent remove siren`); event.server.runCommand(`lp user ${sourcePlayer.username} parent remove mermaid`); event.server.runCommand(`lp user ${sourcePlayer.username} parent remove cerberus`); event.server.runCommand(`lp user ${sourcePlayer.username} parent add phoenix`); event.server.runCommand(`tellraw ${sourcePlayer.username} ["",{"text":"ᴡʜɪᴍꜱʏ ‣","bold":true,"color":"light_purple"},{"text":" Your prefix set to "},{"text":"Phoenix","color":"dark_red"},{"text":"."}]`) }); } });