Renames plugin, and adds README

This commit is contained in:
Kristian Knarvik 2024-01-09 02:05:56 +01:00
parent 36f1454cfa
commit b91858ad2d
18 changed files with 173 additions and 66 deletions

64
README.md Normal file
View File

@ -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) | <group> <payout> | Sets the payout for a specific group |
| [/setplayerpayout](#setplayerpayout) | <player> <payout> | 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 <group> <payout>`
| 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 <player> <payout>`
| 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 |

View File

@ -5,11 +5,11 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.knarcraft</groupId>
<artifactId>TimeIsMoney</artifactId>
<artifactId>PlayerPayouts</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>TimeIsMoney</name>
<name>PlayerPayouts</name>
<properties>
<java.version>16</java.version>

View File

@ -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 <p>An instance of this plugin</p>
*/
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<Permission> permissionProvider = servicesManager.getRegistration(Permission.class);
RegisteredServiceProvider<Economy> 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;
}
}

View File

@ -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;
}

View File

@ -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])) {

View File

@ -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<String> 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()),

View File

@ -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;

View File

@ -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;

View File

@ -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,21 +92,36 @@ 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;
}
}
if (maxPay == -1) {
return defaultPayout;
} else {
return maxPay;
/**
* Gets the max payout of the given player's permission groups
*
* @param player <p>The player to get the group payout for</p>
* @return <p>The group payout, or -1 if no groups has a set payout</p>
*/
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);
}
}
}
return maxPay;
}
/**
* The delay between each time a player is paid in minutes
@ -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<String, Double> entry : groupPayouts.entrySet()) {
if (entry.getValue() == null) {
groupPayouts.remove(entry.getKey());
}
}
for (Map.Entry<UUID, Double> entry : playerPayouts.entrySet()) {
if (entry.getValue() == null) {
playerPayouts.remove(entry.getKey());
}
}
}
}

View File

@ -1,4 +1,4 @@
package net.knarcraft.timeismoney.config;
package net.knarcraft.playerpayouts.config;
import org.jetbrains.annotations.NotNull;

View File

@ -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;

View File

@ -1,4 +1,4 @@
package net.knarcraft.timeismoney.manager;
package net.knarcraft.playerpayouts.manager;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.OfflinePlayer;

View File

@ -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;

View File

@ -1,4 +1,4 @@
package net.knarcraft.timeismoney.manager;
package net.knarcraft.playerpayouts.manager;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

View File

@ -1,4 +1,4 @@
package net.knarcraft.timeismoney.util;
package net.knarcraft.playerpayouts.util;
import org.jetbrains.annotations.NotNull;

View File

@ -1,4 +1,4 @@
package net.knarcraft.timeismoney.util;
package net.knarcraft.playerpayouts.util;
import org.jetbrains.annotations.NotNull;

View File

@ -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: [ ]

View File

@ -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