diff --git a/docs/files/parkourCommands.json b/docs/files/parkourCommands.json index c0ed47d2..52e4d22f 100644 --- a/docs/files/parkourCommands.json +++ b/docs/files/parkourCommands.json @@ -141,7 +141,7 @@ "permission": "parkour.admin.*", "commandGroup": "5", "consoleSyntax": "pac economy (info / setprize / setfee / add / deduct / amount)", - "autoTabSyntax": "[info,setprize,setfee,add,deduct,amount] {1:setprize=(course),1:setfee=(course),1:info=(nothing),*=(player)} {1:info=(nothing),1:amount=(nothing),*=(amount)}" + "autoTabSyntax": "[info,setprize,setfee,add,deduct,amount] {1:setprize=(course),1:setfee=(course),1:info=(nothing),*=(player)} {1:info=(nothing),1:amount=(nothing),*=(amount)} {1:setfee=(truefalse),*=(nothing)}" }, { "command": "editkit", diff --git a/src/main/java/io/github/a5h73y/parkour/Parkour.java b/src/main/java/io/github/a5h73y/parkour/Parkour.java index 9d23c9b9..55a8ecd9 100644 --- a/src/main/java/io/github/a5h73y/parkour/Parkour.java +++ b/src/main/java/io/github/a5h73y/parkour/Parkour.java @@ -20,6 +20,7 @@ import io.github.a5h73y.parkour.other.PluginBackupUtil; import io.github.a5h73y.parkour.plugin.BountifulApi; import io.github.a5h73y.parkour.plugin.EconomyApi; +import io.github.a5h73y.parkour.plugin.PermissionVault; import io.github.a5h73y.parkour.plugin.PlaceholderApi; import io.github.a5h73y.parkour.type.Initializable; import io.github.a5h73y.parkour.type.Teardownable; @@ -88,6 +89,7 @@ public class Parkour extends JavaPlugin { private BountifulApi bountifulApi; private EconomyApi economyApi; + private PermissionVault permissionVault; private PlaceholderApi placeholderApi; /** @@ -219,6 +221,7 @@ private AbstractPluginReceiver registerManager(AbstractPluginReceiver manager) { private void setupPlugins() { bountifulApi = new BountifulApi(this); economyApi = new EconomyApi(this); + permissionVault = new PermissionVault(this); placeholderApi = new PlaceholderApi(this); } @@ -388,6 +391,10 @@ public EconomyApi getEconomyApi() { return economyApi; } + public PermissionVault getPermissionVault() { + return permissionVault; + } + public PlaceholderApi getPlaceholderApi() { return placeholderApi; } diff --git a/src/main/java/io/github/a5h73y/parkour/commands/ParkourCommands.java b/src/main/java/io/github/a5h73y/parkour/commands/ParkourCommands.java index 4d1fa8d1..9b4c0801 100644 --- a/src/main/java/io/github/a5h73y/parkour/commands/ParkourCommands.java +++ b/src/main/java/io/github/a5h73y/parkour/commands/ParkourCommands.java @@ -199,7 +199,7 @@ public boolean onCommand(@NotNull CommandSender sender, if (!PermissionUtils.hasPermission(player, Permission.ADMIN_ALL)) { return false; - } else if (!ValidationUtils.validateArgs(player, args, 2, 4)) { + } else if (!ValidationUtils.validateArgs(player, args, 2, 5)) { return false; } diff --git a/src/main/java/io/github/a5h73y/parkour/conversation/CoursePrizeConversation.java b/src/main/java/io/github/a5h73y/parkour/conversation/CoursePrizeConversation.java index b41c7cf2..7bec9bbc 100644 --- a/src/main/java/io/github/a5h73y/parkour/conversation/CoursePrizeConversation.java +++ b/src/main/java/io/github/a5h73y/parkour/conversation/CoursePrizeConversation.java @@ -7,7 +7,6 @@ import io.github.a5h73y.parkour.type.course.ParkourEventType; import io.github.a5h73y.parkour.utility.MaterialUtils; import io.github.a5h73y.parkour.utility.TranslationUtils; - import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.conversations.BooleanPrompt; diff --git a/src/main/java/io/github/a5h73y/parkour/plugin/EconomyApi.java b/src/main/java/io/github/a5h73y/parkour/plugin/EconomyApi.java index 276a2de1..0c076c1c 100644 --- a/src/main/java/io/github/a5h73y/parkour/plugin/EconomyApi.java +++ b/src/main/java/io/github/a5h73y/parkour/plugin/EconomyApi.java @@ -147,7 +147,7 @@ public void displayEconomyInformation(CommandSender commandSender) { /** * Validate and Charge the Player for joining Course. * Check if there is a Join Fee for the Course, and that the player has sufficient funds. - * If there is a Fee, charge the Player and continue. + * If there is a Fee, check if it's a one-time Fee, charge the Player and continue. * * @param player requesting player * @param courseName course name @@ -159,17 +159,23 @@ public boolean validateAndChargeCourseJoin(Player player, String courseName) { double joinFee = parkour.getConfigManager().getCourseConfig(courseName).getEconomyJoiningFee(); if (joinFee > 0) { - if (!hasAmount(player, joinFee)) { - player.sendMessage(TranslationUtils.getTranslation("Economy.Insufficient") - .replace(AMOUNT_PLACEHOLDER, joinFee + getCurrencyName()) - .replace(COURSE_PLACEHOLDER, courseName)); - allowed = false; - - } else { - chargePlayer(player, joinFee); - player.sendMessage(TranslationUtils.getTranslation("Economy.Fee") - .replace(AMOUNT_PLACEHOLDER, joinFee + getCurrencyName()) - .replace(COURSE_PLACEHOLDER, courseName)); + boolean oneTimeFee = parkour.getConfigManager().getCourseConfig(courseName).isOneTimeFee(); + if (!oneTimeFee || (oneTimeFee && !parkour.getPermissionVault().hasPaidOneTimeFee(player, courseName))) { + if (!hasAmount(player, joinFee)) { + player.sendMessage(TranslationUtils.getTranslation("Economy.Insufficient") + .replace(AMOUNT_PLACEHOLDER, joinFee + getCurrencyName()) + .replace(COURSE_PLACEHOLDER, courseName)); + allowed = false; + + } else { + chargePlayer(player, joinFee); + player.sendMessage(TranslationUtils.getTranslation("Economy.Fee") + .replace(AMOUNT_PLACEHOLDER, joinFee + getCurrencyName()) + .replace(COURSE_PLACEHOLDER, courseName)); + if (oneTimeFee) { + parkour.getPermissionVault().setPaidOneTimeFee(player, courseName); + } + } } } } @@ -241,8 +247,8 @@ private void processSetPrizeCommand(CommandSender commandSender, String... args) } private void processSetFeeCommand(CommandSender commandSender, String... args) { - if (args.length != 4) { - TranslationUtils.sendInvalidSyntax(commandSender, "econ", "setfee (course) (amount)"); + if (args.length < 4) { + TranslationUtils.sendInvalidSyntax(commandSender, "econ", "setfee (course) (amount) [one-time-fee]"); return; } @@ -256,7 +262,9 @@ private void processSetFeeCommand(CommandSender commandSender, String... args) { return; } + boolean value = args.length == 5 && args[4].equalsIgnoreCase("true") ? true : false; parkour.getConfigManager().getCourseConfig(args[2]).setEconomyJoiningFee(Double.parseDouble(args[3])); + parkour.getConfigManager().getCourseConfig(args[2]).setEconomyOneTimeFee(value); TranslationUtils.sendPropertySet(commandSender, "Join Fee", args[2], args[3]); } diff --git a/src/main/java/io/github/a5h73y/parkour/plugin/PermissionVault.java b/src/main/java/io/github/a5h73y/parkour/plugin/PermissionVault.java new file mode 100644 index 00000000..91cca5dc --- /dev/null +++ b/src/main/java/io/github/a5h73y/parkour/plugin/PermissionVault.java @@ -0,0 +1,58 @@ +package io.github.a5h73y.parkour.plugin; + +import static org.bukkit.Bukkit.getServer; + +import org.bukkit.entity.Player; +import org.bukkit.plugin.RegisteredServiceProvider; +import io.github.a5h73y.parkour.Parkour; +import io.github.a5h73y.parkour.utility.PluginUtils; +import net.milkbowl.vault.permission.Permission; + +public class PermissionVault extends PluginWrapper { + + public PermissionVault(Parkour parkour) { + super(parkour); + } + + private Permission permission; + private static final String COURSE_PERMISSION = "parkour.course."; + + @Override + protected void initialise() { + super.initialise(); + + if (isEnabled()) { + RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Permission.class); + + if (rsp == null) { + PluginUtils.log("[Permission] Failed to connect to Vault's Permission service.", 2); + setEnabled(false); + return; + } + + permission = rsp.getProvider(); + } + } + + public Permission getPermissions() { + return permission; + } + + public boolean isPermissions() { + return permission != null; + } + + public boolean hasPaidOneTimeFee(Player player, String courseName) { + return player.hasPermission(COURSE_PERMISSION + courseName); + } + + public void setPaidOneTimeFee(Player player, String courseName) { + permission.playerAdd(null, player, COURSE_PERMISSION + courseName); + } + + @Override + public String getPluginName() { + return "Vault"; + } + +} diff --git a/src/main/java/io/github/a5h73y/parkour/type/course/CourseConfig.java b/src/main/java/io/github/a5h73y/parkour/type/course/CourseConfig.java index 638e31d4..3e814156 100644 --- a/src/main/java/io/github/a5h73y/parkour/type/course/CourseConfig.java +++ b/src/main/java/io/github/a5h73y/parkour/type/course/CourseConfig.java @@ -41,6 +41,7 @@ public class CourseConfig extends Json { public static final String DISPLAY_NAME = "DisplayName"; public static final String ECONOMY_FINISH_REWARD = "EconomyFinishReward"; public static final String ECONOMY_JOINING_FEE = "EconomyJoiningFee"; + public static final String ECONOMY_ONETIME_FEE = "EconomyOneTimeFee"; public static final String HAS_FALL_DAMAGE = "HasFallDamage"; public static final String JOIN_ITEMS = "JoinItems"; public static final String LINKED_COURSE = "LinkedCourse"; @@ -436,6 +437,7 @@ public String getMaterialPrizeLabel() { * The Material and Amount to be rewarded for finishing the Course. * @param materialName prize material * @param amount prize amount + * @param label display name */ public void setMaterialPrize(@NotNull String materialName, int amount, String label) { this.set(PRIZE_MATERIAL, materialName); @@ -812,7 +814,7 @@ public void setEconomyFinishReward(@Nullable Double finishReward) { } /** - * Get Economic Fee for joining Course. + * Get Economy Fee for joining Course. * @return joining fee */ public double getEconomyJoiningFee() { @@ -827,6 +829,22 @@ public boolean hasEconomyJoiningFee() { return this.contains(ECONOMY_JOINING_FEE); } + /** + * Check if the Economy Joining fee is a one-time fee. + * @return is one-time joining fee + */ + public boolean isOneTimeFee() { + return this.getBoolean(ECONOMY_ONETIME_FEE); + } + + /** + * Set Economy one-time fee. + * @param is one-time joining fee + */ + public void setEconomyOneTimeFee(Boolean OneTimeFee) { + this.set(ECONOMY_ONETIME_FEE, OneTimeFee); + } + /** * Set Economy Joining fee. * @param joinFee join fee @@ -1090,6 +1108,8 @@ public static void displayCourseInfo(@NotNull CommandSender commandSender, if (parkour.getEconomyApi().isEnabled()) { sendConditionalValue(commandSender, "Join Fee", config.getEconomyJoiningFee()); + sendConditionalValue(commandSender, "One-Time Fee", + config.hasEconomyJoiningFee() && config.isOneTimeFee(), "true"); sendConditionalValue(commandSender, "Economy Reward", config.getEconomyFinishReward()); } diff --git a/src/main/java/io/github/a5h73y/parkour/type/course/CourseSettingsManager.java b/src/main/java/io/github/a5h73y/parkour/type/course/CourseSettingsManager.java index a545cc89..d737e680 100644 --- a/src/main/java/io/github/a5h73y/parkour/type/course/CourseSettingsManager.java +++ b/src/main/java/io/github/a5h73y/parkour/type/course/CourseSettingsManager.java @@ -48,7 +48,6 @@ import java.util.Map; import java.util.Set; import de.leonhard.storage.sections.FlatFileSection; -import org.bukkit.Material; import org.bukkit.command.CommandSender; import org.bukkit.conversations.Conversable; import org.bukkit.entity.Player; diff --git a/src/main/resources/parkourCommands.json b/src/main/resources/parkourCommands.json index c0ed47d2..52e4d22f 100644 --- a/src/main/resources/parkourCommands.json +++ b/src/main/resources/parkourCommands.json @@ -141,7 +141,7 @@ "permission": "parkour.admin.*", "commandGroup": "5", "consoleSyntax": "pac economy (info / setprize / setfee / add / deduct / amount)", - "autoTabSyntax": "[info,setprize,setfee,add,deduct,amount] {1:setprize=(course),1:setfee=(course),1:info=(nothing),*=(player)} {1:info=(nothing),1:amount=(nothing),*=(amount)}" + "autoTabSyntax": "[info,setprize,setfee,add,deduct,amount] {1:setprize=(course),1:setfee=(course),1:info=(nothing),*=(player)} {1:info=(nothing),1:amount=(nothing),*=(amount)} {1:setfee=(truefalse),*=(nothing)}" }, { "command": "editkit",