diff --git a/README.md b/README.md new file mode 100644 index 0000000..9923f34 --- /dev/null +++ b/README.md @@ -0,0 +1,64 @@ +# Player Payouts + +This Spigot plugin gives players customizable payouts based on their played in-game time. A unique feature of this +plugin is a configurable bonus once players reach a specified total play-time on the server. The plugin is highly +configurable. You can alter the base payout per-group or per-player, you can adjust how often players are paid, how big +a percentage is paid to AFK players and whether players are alerted upon receiving a payout. + +The logic for which payout is used is as follows: + +- If a payout is set for a player, that payout will be used. +- If a payout is set for one or more of a player's group, the highest value will be used. +- If none of the above apply, the base pay is used. + +## Dependencies + +### Required + +- Vault (A vault-compatible economy plugin is required. A vault-compatible permission is necessary for per-group + payments) + +### Optional + +- EssentialsX (Necessary for checking if a player is AFK) + +## Commands + +| Command | Arguments | Description | +|--------------------------------------|-------------------|------------------------------------------| +| /timeismoney:reload | | Reloads the configuration file from disk | +| [/setgrouppayout](#setgrouppayout) | | Sets the payout for a specific group | +| [/setplayerpayout](#setplayerpayout) | | Sets the payout for a specific player | + +Note that for the set payout commands, you can use "null", "clear" or "none" to remove a payout you previously set. + +### /setgrouppayout + +This command is used to override the payout for a specific group. + +`/setgrouppayout ` + +| Argument | Usage | +|----------|---------------------------------------------------------------------------------------------------------------------------------| +| group | The name of the group to specify the payout for | +| payout | The decimal number denoting how much of the currency players in the group should be paid, or "clear" to unset a previous value. | + +### /setplayerpayout + +`/setplayerpayout ` + +| Argument | Usage | +|----------|-----------------------------------------------------------------------------------------------------------------------| +| player | The name or UUID of the player to specify the payout for | +| payout | The decimal number denoting how much of the currency the player should be paid, or "clear" to unset a previous value. | + +## Configuration options + +| Option | Type | Description | +|-----------------------|--------------------|--------------------------------------------------------------------------------------------------------------------------| +| defaultPayout | decimal number | The amount of currency to pay by default | +| paymentDelay | number | The amount of minutes to wait between each payout | +| displayPaymentMessage | true / false | Whether to display a message to the player each time a player receives a payout | +| hoursUntilBonus | number / -1 | The amount of hours a player must play until they start receiving a payout bonus, or -1 to disable the feature | +| bonusMultiplier | decimal number | A multiplier used to increase or decrease the time bonus ((hours played / hours until bonus) * bonusMultiplier) + payout | +| afkPercentage | percentage (0-100) | The percentage of their normal payout to pay AFK players | diff --git a/pom.xml b/pom.xml index b78e032..9ed881d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,11 +5,11 @@ 4.0.0 net.knarcraft - TimeIsMoney + PlayerPayouts 1.0-SNAPSHOT jar - TimeIsMoney + PlayerPayouts 16 diff --git a/src/main/java/net/knarcraft/timeismoney/TimeIsMoney.java b/src/main/java/net/knarcraft/playerpayouts/PlayerPayouts.java similarity index 82% rename from src/main/java/net/knarcraft/timeismoney/TimeIsMoney.java rename to src/main/java/net/knarcraft/playerpayouts/PlayerPayouts.java index 50ad52f..562a624 100644 --- a/src/main/java/net/knarcraft/timeismoney/TimeIsMoney.java +++ b/src/main/java/net/knarcraft/playerpayouts/PlayerPayouts.java @@ -1,16 +1,16 @@ -package net.knarcraft.timeismoney; +package net.knarcraft.playerpayouts; import com.earth2me.essentials.IEssentials; -import net.knarcraft.timeismoney.command.ReloadCommand; -import net.knarcraft.timeismoney.command.SetGroupPaymentCommand; -import net.knarcraft.timeismoney.command.SetGroupPaymentTabCompleter; -import net.knarcraft.timeismoney.command.SetPlayerPaymentCommand; -import net.knarcraft.timeismoney.command.SetPlayerPaymentTabCompleter; -import net.knarcraft.timeismoney.config.Configuration; -import net.knarcraft.timeismoney.listener.PlayerJoinListener; -import net.knarcraft.timeismoney.manager.EconomyManager; -import net.knarcraft.timeismoney.manager.PermissionManager; -import net.knarcraft.timeismoney.manager.PlayerTracker; +import net.knarcraft.playerpayouts.command.ReloadCommand; +import net.knarcraft.playerpayouts.command.SetGroupPaymentCommand; +import net.knarcraft.playerpayouts.command.SetGroupPaymentTabCompleter; +import net.knarcraft.playerpayouts.command.SetPlayerPaymentCommand; +import net.knarcraft.playerpayouts.command.SetPlayerPaymentTabCompleter; +import net.knarcraft.playerpayouts.config.Configuration; +import net.knarcraft.playerpayouts.listener.PlayerJoinListener; +import net.knarcraft.playerpayouts.manager.EconomyManager; +import net.knarcraft.playerpayouts.manager.PermissionManager; +import net.knarcraft.playerpayouts.manager.PlayerTracker; import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.permission.Permission; import org.bukkit.Bukkit; @@ -32,15 +32,15 @@ import java.util.logging.Level; * Time is money's main class */ @SuppressWarnings("unused") -public final class TimeIsMoney extends JavaPlugin { +public final class PlayerPayouts extends JavaPlugin { private Configuration configuration; private IEssentials essentials = null; - private static TimeIsMoney timeIsMoney; + private static PlayerPayouts playerPayouts; @Override public void onEnable() { - timeIsMoney = this; + playerPayouts = this; this.saveDefaultConfig(); this.reloadConfig(); this.saveConfig(); @@ -51,7 +51,9 @@ public final class TimeIsMoney extends JavaPlugin { // Plugin startup logic if (Bukkit.getPluginManager().getPlugin("Vault") != null) { - setupVault(); + if (!setupVault()) { + return; + } } else { this.getLogger().log(Level.SEVERE, "Could not find Vault. Plugin disabled."); this.setEnabled(false); @@ -99,17 +101,17 @@ public final class TimeIsMoney extends JavaPlugin { * * @return

An instance of this plugin

*/ - public static TimeIsMoney getInstance() { - return timeIsMoney; + public static PlayerPayouts getInstance() { + return playerPayouts; } /** * Reloads the configuration from disk */ public static void reload() { - timeIsMoney.reloadConfig(); - timeIsMoney.saveConfig(); - timeIsMoney.configuration = new Configuration(timeIsMoney.getConfig()); + playerPayouts.reloadConfig(); + playerPayouts.saveConfig(); + playerPayouts.configuration = new Configuration(playerPayouts.getConfig()); } /** @@ -180,7 +182,7 @@ public final class TimeIsMoney extends JavaPlugin { /** * Sets up Vault by getting plugins from their providers */ - private void setupVault() { + private boolean setupVault() { ServicesManager servicesManager = this.getServer().getServicesManager(); RegisteredServiceProvider permissionProvider = servicesManager.getRegistration(Permission.class); RegisteredServiceProvider economyProvider = servicesManager.getRegistration(Economy.class); @@ -188,14 +190,17 @@ public final class TimeIsMoney extends JavaPlugin { if (permissionProvider != null) { PermissionManager.initialize(permissionProvider.getProvider()); } else { - getLogger().log(Level.WARNING, "No Vault permission provider found. Permission rewards are unavailable."); + getLogger().log(Level.WARNING, "No Vault permission provider found. Per-group payouts cannot be used!"); } if (economyProvider != null) { EconomyManager.initialize(economyProvider.getProvider()); } else { - getLogger().log(Level.WARNING, "No Vault economy provider found. Economy rewards are unavailable."); + getLogger().log(Level.SEVERE, "No Vault economy provider found. PlayerPayouts disabled!"); + this.onDisable(); + return false; } + return true; } } diff --git a/src/main/java/net/knarcraft/timeismoney/command/ReloadCommand.java b/src/main/java/net/knarcraft/playerpayouts/command/ReloadCommand.java similarity index 87% rename from src/main/java/net/knarcraft/timeismoney/command/ReloadCommand.java rename to src/main/java/net/knarcraft/playerpayouts/command/ReloadCommand.java index 6c49288..46d6963 100644 --- a/src/main/java/net/knarcraft/timeismoney/command/ReloadCommand.java +++ b/src/main/java/net/knarcraft/playerpayouts/command/ReloadCommand.java @@ -1,6 +1,6 @@ -package net.knarcraft.timeismoney.command; +package net.knarcraft.playerpayouts.command; -import net.knarcraft.timeismoney.TimeIsMoney; +import net.knarcraft.playerpayouts.PlayerPayouts; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; @@ -18,7 +18,7 @@ public class ReloadCommand implements TabExecutor { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - TimeIsMoney.reload(); + PlayerPayouts.reload(); sender.sendMessage("Plugin reloaded!"); return true; } diff --git a/src/main/java/net/knarcraft/timeismoney/command/SetGroupPaymentCommand.java b/src/main/java/net/knarcraft/playerpayouts/command/SetGroupPaymentCommand.java similarity index 81% rename from src/main/java/net/knarcraft/timeismoney/command/SetGroupPaymentCommand.java rename to src/main/java/net/knarcraft/playerpayouts/command/SetGroupPaymentCommand.java index be95e89..2199c42 100644 --- a/src/main/java/net/knarcraft/timeismoney/command/SetGroupPaymentCommand.java +++ b/src/main/java/net/knarcraft/playerpayouts/command/SetGroupPaymentCommand.java @@ -1,7 +1,8 @@ -package net.knarcraft.timeismoney.command; +package net.knarcraft.playerpayouts.command; -import net.knarcraft.timeismoney.config.Configuration; -import net.knarcraft.timeismoney.util.StringHelper; +import net.knarcraft.playerpayouts.config.Configuration; +import net.knarcraft.playerpayouts.manager.PermissionManager; +import net.knarcraft.playerpayouts.util.StringHelper; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -31,6 +32,12 @@ public class SetGroupPaymentCommand implements CommandExecutor { return false; } + if (!PermissionManager.isInitialized()) { + commandSender.sendMessage("Vault permissions aren't available, and thus per-group payouts are " + + "unavailable."); + return false; + } + try { String group = arguments[0]; if (StringHelper.isNonValue(arguments[1])) { diff --git a/src/main/java/net/knarcraft/timeismoney/command/SetGroupPaymentTabCompleter.java b/src/main/java/net/knarcraft/playerpayouts/command/SetGroupPaymentTabCompleter.java similarity index 81% rename from src/main/java/net/knarcraft/timeismoney/command/SetGroupPaymentTabCompleter.java rename to src/main/java/net/knarcraft/playerpayouts/command/SetGroupPaymentTabCompleter.java index 610c32c..c70a2e1 100644 --- a/src/main/java/net/knarcraft/timeismoney/command/SetGroupPaymentTabCompleter.java +++ b/src/main/java/net/knarcraft/playerpayouts/command/SetGroupPaymentTabCompleter.java @@ -1,7 +1,7 @@ -package net.knarcraft.timeismoney.command; +package net.knarcraft.playerpayouts.command; -import net.knarcraft.timeismoney.manager.PermissionManager; -import net.knarcraft.timeismoney.util.TabCompletionHelper; +import net.knarcraft.playerpayouts.manager.PermissionManager; +import net.knarcraft.playerpayouts.util.TabCompletionHelper; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -20,6 +20,10 @@ public class SetGroupPaymentTabCompleter implements TabCompleter { @Override public List onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] arguments) { + if (!PermissionManager.isInitialized()) { + return null; + } + if (arguments.length == 1) { // List permission groups return TabCompletionHelper.filterMatchingContains(List.of(PermissionManager.getPermissionGroups()), diff --git a/src/main/java/net/knarcraft/timeismoney/command/SetPlayerPaymentCommand.java b/src/main/java/net/knarcraft/playerpayouts/command/SetPlayerPaymentCommand.java similarity index 95% rename from src/main/java/net/knarcraft/timeismoney/command/SetPlayerPaymentCommand.java rename to src/main/java/net/knarcraft/playerpayouts/command/SetPlayerPaymentCommand.java index c1d468c..c1b47a4 100644 --- a/src/main/java/net/knarcraft/timeismoney/command/SetPlayerPaymentCommand.java +++ b/src/main/java/net/knarcraft/playerpayouts/command/SetPlayerPaymentCommand.java @@ -1,7 +1,7 @@ -package net.knarcraft.timeismoney.command; +package net.knarcraft.playerpayouts.command; -import net.knarcraft.timeismoney.config.Configuration; -import net.knarcraft.timeismoney.util.StringHelper; +import net.knarcraft.playerpayouts.config.Configuration; +import net.knarcraft.playerpayouts.util.StringHelper; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; diff --git a/src/main/java/net/knarcraft/timeismoney/command/SetPlayerPaymentTabCompleter.java b/src/main/java/net/knarcraft/playerpayouts/command/SetPlayerPaymentTabCompleter.java similarity index 95% rename from src/main/java/net/knarcraft/timeismoney/command/SetPlayerPaymentTabCompleter.java rename to src/main/java/net/knarcraft/playerpayouts/command/SetPlayerPaymentTabCompleter.java index e6719fe..8bc55d4 100644 --- a/src/main/java/net/knarcraft/timeismoney/command/SetPlayerPaymentTabCompleter.java +++ b/src/main/java/net/knarcraft/playerpayouts/command/SetPlayerPaymentTabCompleter.java @@ -1,6 +1,6 @@ -package net.knarcraft.timeismoney.command; +package net.knarcraft.playerpayouts.command; -import net.knarcraft.timeismoney.util.TabCompletionHelper; +import net.knarcraft.playerpayouts.util.TabCompletionHelper; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; diff --git a/src/main/java/net/knarcraft/timeismoney/config/Configuration.java b/src/main/java/net/knarcraft/playerpayouts/config/Configuration.java similarity index 84% rename from src/main/java/net/knarcraft/timeismoney/config/Configuration.java rename to src/main/java/net/knarcraft/playerpayouts/config/Configuration.java index 70f8ad6..e4b621b 100644 --- a/src/main/java/net/knarcraft/timeismoney/config/Configuration.java +++ b/src/main/java/net/knarcraft/playerpayouts/config/Configuration.java @@ -1,7 +1,7 @@ -package net.knarcraft.timeismoney.config; +package net.knarcraft.playerpayouts.config; -import net.knarcraft.timeismoney.TimeIsMoney; -import net.knarcraft.timeismoney.manager.PermissionManager; +import net.knarcraft.playerpayouts.PlayerPayouts; +import net.knarcraft.playerpayouts.manager.PermissionManager; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; @@ -92,20 +92,35 @@ public class Configuration { return playerPayouts.get(player.getUniqueId()); } - double maxPay = -1; + double groupPayout = -1; if (PermissionManager.isInitialized()) { - for (String group : PermissionManager.getPlayerGroups(player)) { - if (groupPayouts.containsKey(group)) { - maxPay = Math.max(maxPay, groupPayouts.get(group)); + groupPayout = getGroupPayout(player); + } + + if (groupPayout == -1) { + return defaultPayout; + } else { + return groupPayout; + } + } + + /** + * Gets the max payout of the given player's permission groups + * + * @param player

The player to get the group payout for

+ * @return

The group payout, or -1 if no groups has a set payout

+ */ + private double getGroupPayout(@NotNull Player player) { + double maxPay = -1; + for (String group : PermissionManager.getPlayerGroups(player)) { + if (groupPayouts.containsKey(group)) { + Double groupPayout = groupPayouts.get(group); + if (groupPayout != null) { + maxPay = Math.max(maxPay, groupPayout); } } } - - if (maxPay == -1) { - return defaultPayout; - } else { - return maxPay; - } + return maxPay; } /** @@ -209,7 +224,19 @@ public class Configuration { fileConfiguration.setComments(ConfigurationKey.GROUP_PAYOUTS.getPath(), List.of("Overrides for specific groups")); - TimeIsMoney.getInstance().saveConfig(); + PlayerPayouts.getInstance().saveConfig(); + + // Null values are necessary for updating removed keys, but should not appear otherwise + for (Map.Entry entry : groupPayouts.entrySet()) { + if (entry.getValue() == null) { + groupPayouts.remove(entry.getKey()); + } + } + for (Map.Entry entry : playerPayouts.entrySet()) { + if (entry.getValue() == null) { + playerPayouts.remove(entry.getKey()); + } + } } } diff --git a/src/main/java/net/knarcraft/timeismoney/config/ConfigurationKey.java b/src/main/java/net/knarcraft/playerpayouts/config/ConfigurationKey.java similarity index 97% rename from src/main/java/net/knarcraft/timeismoney/config/ConfigurationKey.java rename to src/main/java/net/knarcraft/playerpayouts/config/ConfigurationKey.java index 212dbf4..f225975 100644 --- a/src/main/java/net/knarcraft/timeismoney/config/ConfigurationKey.java +++ b/src/main/java/net/knarcraft/playerpayouts/config/ConfigurationKey.java @@ -1,4 +1,4 @@ -package net.knarcraft.timeismoney.config; +package net.knarcraft.playerpayouts.config; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/knarcraft/timeismoney/listener/PlayerJoinListener.java b/src/main/java/net/knarcraft/playerpayouts/listener/PlayerJoinListener.java similarity index 78% rename from src/main/java/net/knarcraft/timeismoney/listener/PlayerJoinListener.java rename to src/main/java/net/knarcraft/playerpayouts/listener/PlayerJoinListener.java index 11e5227..c747d04 100644 --- a/src/main/java/net/knarcraft/timeismoney/listener/PlayerJoinListener.java +++ b/src/main/java/net/knarcraft/playerpayouts/listener/PlayerJoinListener.java @@ -1,6 +1,6 @@ -package net.knarcraft.timeismoney.listener; +package net.knarcraft.playerpayouts.listener; -import net.knarcraft.timeismoney.manager.PlayerTracker; +import net.knarcraft.playerpayouts.manager.PlayerTracker; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; diff --git a/src/main/java/net/knarcraft/timeismoney/manager/EconomyManager.java b/src/main/java/net/knarcraft/playerpayouts/manager/EconomyManager.java similarity index 96% rename from src/main/java/net/knarcraft/timeismoney/manager/EconomyManager.java rename to src/main/java/net/knarcraft/playerpayouts/manager/EconomyManager.java index a3415c8..87eded7 100644 --- a/src/main/java/net/knarcraft/timeismoney/manager/EconomyManager.java +++ b/src/main/java/net/knarcraft/playerpayouts/manager/EconomyManager.java @@ -1,4 +1,4 @@ -package net.knarcraft.timeismoney.manager; +package net.knarcraft.playerpayouts.manager; import net.milkbowl.vault.economy.Economy; import org.bukkit.OfflinePlayer; diff --git a/src/main/java/net/knarcraft/timeismoney/manager/PermissionManager.java b/src/main/java/net/knarcraft/playerpayouts/manager/PermissionManager.java similarity index 96% rename from src/main/java/net/knarcraft/timeismoney/manager/PermissionManager.java rename to src/main/java/net/knarcraft/playerpayouts/manager/PermissionManager.java index 8743671..2d5706f 100644 --- a/src/main/java/net/knarcraft/timeismoney/manager/PermissionManager.java +++ b/src/main/java/net/knarcraft/playerpayouts/manager/PermissionManager.java @@ -1,4 +1,4 @@ -package net.knarcraft.timeismoney.manager; +package net.knarcraft.playerpayouts.manager; import net.milkbowl.vault.permission.Permission; import org.bukkit.entity.Player; diff --git a/src/main/java/net/knarcraft/timeismoney/manager/PlayerTracker.java b/src/main/java/net/knarcraft/playerpayouts/manager/PlayerTracker.java similarity index 96% rename from src/main/java/net/knarcraft/timeismoney/manager/PlayerTracker.java rename to src/main/java/net/knarcraft/playerpayouts/manager/PlayerTracker.java index 1e3b476..3e8ed07 100644 --- a/src/main/java/net/knarcraft/timeismoney/manager/PlayerTracker.java +++ b/src/main/java/net/knarcraft/playerpayouts/manager/PlayerTracker.java @@ -1,4 +1,4 @@ -package net.knarcraft.timeismoney.manager; +package net.knarcraft.playerpayouts.manager; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/knarcraft/timeismoney/util/StringHelper.java b/src/main/java/net/knarcraft/playerpayouts/util/StringHelper.java similarity index 93% rename from src/main/java/net/knarcraft/timeismoney/util/StringHelper.java rename to src/main/java/net/knarcraft/playerpayouts/util/StringHelper.java index ce40830..bc81a6f 100644 --- a/src/main/java/net/knarcraft/timeismoney/util/StringHelper.java +++ b/src/main/java/net/knarcraft/playerpayouts/util/StringHelper.java @@ -1,4 +1,4 @@ -package net.knarcraft.timeismoney.util; +package net.knarcraft.playerpayouts.util; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/knarcraft/timeismoney/util/TabCompletionHelper.java b/src/main/java/net/knarcraft/playerpayouts/util/TabCompletionHelper.java similarity index 97% rename from src/main/java/net/knarcraft/timeismoney/util/TabCompletionHelper.java rename to src/main/java/net/knarcraft/playerpayouts/util/TabCompletionHelper.java index f3ff301..a55c583 100644 --- a/src/main/java/net/knarcraft/timeismoney/util/TabCompletionHelper.java +++ b/src/main/java/net/knarcraft/playerpayouts/util/TabCompletionHelper.java @@ -1,4 +1,4 @@ -package net.knarcraft.timeismoney.util; +package net.knarcraft.playerpayouts.util; import org.jetbrains.annotations.NotNull; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index d6ab5ec..89fb219 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -10,7 +10,7 @@ hoursUntilBonus: 100 bonusMultiplier: 1 # The percentage of their normal payout to pay AFK players afkPercentage: 0 -# Overrides for specific groups +# Overrides for specific groups. Use /setgrouppayout groupPayouts: [ ] -# Overrides for specific players +# Overrides for specific players. Use /setplayerpayout playerPayouts: [ ] \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index c2f1e92..e9cbb4c 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,8 +1,8 @@ -name: "TimeIsMoney" +name: "PlayerPayouts" version: '${project.version}' -main: net.knarcraft.timeismoney.TimeIsMoney +main: net.knarcraft.playerpayouts.PlayerPayouts api-version: '1.20' -prefix: 'TimeIsMoney' +prefix: 'PlayerPayouts' author: EpicKnarvik97 depend: - Vault