Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ALL OF THIS IS RUNNING IN A COMMAND
- */
- // Get Bukkit and PlotSquared player instances
- Player player = (Player) sender;
- PlotPlayer plotPlayer = PlotPlayer.wrap(player);
- int maxPlots = plotPlayer.getAllowedPlots();
- int plotsToBuy = 0;
- try {
- plotsToBuy = Integer.parseInt(args[0]);
- } catch(NumberFormatException e) {
- player.sendMessage(ChatUtils.prefix() + "Please only enter a whole number!");
- return true;
- }
- if(plotsToBuy == 0) {
- player.sendMessage(ChatUtils.prefix() + "You must buy at least 1 plot!");
- return true;
- }
- int costOfPlot = CreativeCore.plugin.getConfig().getInt("plot-cost");
- // Server currency
- int playerCredits = Credits.getAPI().getCredits(player);
- if(playerCredits >= plotsToBuy * costOfPlot) {
- if(player.hasPermission("plots.plot." + maxPlots) && maxPlots != 1) {
- // Create permission nodes.
- PermissionNode node = PermissionNode.builder("plots.plot." + plotsToBuy).build();
- PermissionNode oldNode = PermissionNode.builder("plots.plot." + maxPlots).build();
- // Get LP API.
- LuckPerms api = LuckPermsProvider.get();
- final int finalToBuy = plotsToBuy;
- // Add the new permission to the user
- api.getUserManager().loadUser(player.getUniqueId()).thenApply(user ->
- user.data().add(node));
- // Remove the old permission from the user.
- api.getUserManager().loadUser(player.getUniqueId()).thenApply(user ->
- user.data().remove(oldNode)).thenRun(() -> {
- /*
- / Is this code in .thenRun() going to run once the future is complete without blocking?
- */
- Credits.getAPI().setCredits(player, playerCredits - finalToBuy * costOfPlot);
- // Some database stuff on bungee using plugin channels
- int newPlayerCredits = Credits.getAPI().getCredits(player);
- if(finalToBuy == 1) Credits.getAPI().sendCreditsPurchaseHistory(player, "1 Plot", playerCredits, newPlayerCredits);
- else Credits.getAPI().sendCreditsPurchaseHistory(player, finalToBuy + " Plots", playerCredits, newPlayerCredits);
- player.sendMessage(ChatUtils.prefix() + "Successfully bought ยงa" + finalToBuy + " plots");
- });
- /*/ How would I check if the future failed to complete (such as user not loading, permissions not applying)
- and then send the user a message saying so?
- */
- }
- } else {
- player.sendMessage(ChatUtils.prefix() + "You do not have enough credits to buy " + plotsToBuy + " plots.");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement