diff --git a/pom.xml b/pom.xml
index b49bd25..0173fa7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -131,7 +131,7 @@
net.knarcraft
knarlib
- 1.2.4
+ 1.2.5
compile
diff --git a/src/main/java/net/knarcraft/playerpayouts/PlayerPayouts.java b/src/main/java/net/knarcraft/playerpayouts/PlayerPayouts.java
index 1ba2c95..c14b1fa 100644
--- a/src/main/java/net/knarcraft/playerpayouts/PlayerPayouts.java
+++ b/src/main/java/net/knarcraft/playerpayouts/PlayerPayouts.java
@@ -40,6 +40,7 @@ public final class PlayerPayouts extends JavaPlugin {
private Configuration configuration;
private IEssentials essentials = null;
+ private Translator translator;
private StringFormatter stringFormatter;
private static PlayerPayouts playerPayouts;
@@ -54,7 +55,7 @@ public final class PlayerPayouts extends JavaPlugin {
this.saveConfig();
this.configuration = new Configuration(fileConfiguration);
- Translator translator = new Translator();
+ translator = new Translator();
translator.registerMessageCategory(Translatable.GROUP_PAYOUTS_UNAVAILABLE);
translator.loadLanguages(this.getDataFolder(), "en",
fileConfiguration.getString("language", "en"));
@@ -134,7 +135,7 @@ public final class PlayerPayouts extends JavaPlugin {
}
/**
- * Gets a string formatter
+ * Gets the string formatter
*
* @return
A string formatter
*/
@@ -142,6 +143,15 @@ public final class PlayerPayouts extends JavaPlugin {
return getInstance().stringFormatter;
}
+ /**
+ * Gets the translator
+ *
+ * @return A translator
+ */
+ public static Translator getTranslator() {
+ return getInstance().translator;
+ }
+
/**
* Pay all players that have been on the server long enough
*/
diff --git a/src/main/java/net/knarcraft/playerpayouts/command/SetGroupPaymentCommand.java b/src/main/java/net/knarcraft/playerpayouts/command/SetGroupPaymentCommand.java
index fbb3ea4..f7e6906 100644
--- a/src/main/java/net/knarcraft/playerpayouts/command/SetGroupPaymentCommand.java
+++ b/src/main/java/net/knarcraft/playerpayouts/command/SetGroupPaymentCommand.java
@@ -12,6 +12,8 @@ import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
/**
* A command for overriding payments for specific groups
@@ -32,10 +34,6 @@ public class SetGroupPaymentCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
@NotNull String[] arguments) {
- if (arguments.length < 2) {
- return false;
- }
-
StringFormatter stringFormatter = PlayerPayouts.getStringFormatter();
if (!PermissionManager.isInitialized()) {
@@ -43,11 +41,38 @@ public class SetGroupPaymentCommand implements CommandExecutor {
return false;
}
+ // Display all current group payment overrides
+ if (arguments.length == 0) {
+ StringBuilder builder = new StringBuilder(stringFormatter.getUnformattedColoredMessage(
+ Translatable.CURRENT_PAYOUT_OVERRIDE));
+ for (Map.Entry entry : configuration.getGroupPayouts().entrySet()) {
+ if (entry.getValue() == null) {
+ continue;
+ }
+ builder.append(stringFormatter.replacePlaceholders(Translatable.PAYOUT_OVERRIDE_LIST_FORMAT,
+ List.of("{subject}", "{value}"), List.of(entry.getKey(), String.valueOf(entry.getValue()))));
+ }
+ stringFormatter.displaySuccessMessage(commandSender, builder.toString());
+ return true;
+ }
+
if (Arrays.stream(PermissionManager.getPermissionGroups()).noneMatch(item -> item.equals(arguments[0]))) {
stringFormatter.displayErrorMessage(commandSender, Translatable.GROUP_INVALID);
return false;
}
+ // Display the specified group's payment override
+ if (arguments.length == 1) {
+ String output = stringFormatter.getUnformattedMessage(Translatable.CURRENT_PAYOUT_OVERRIDE);
+ Double value = configuration.getGroupPayout(arguments[0]);
+ if (value != null) {
+ output += stringFormatter.replacePlaceholders(Translatable.PAYOUT_OVERRIDE_LIST_FORMAT,
+ List.of("{subject}", "{value}"), List.of(arguments[0], String.valueOf(value)));
+ }
+ stringFormatter.displaySuccessMessage(commandSender, output);
+ return true;
+ }
+
try {
String group = arguments[0];
if (StringHelper.isNonValue(arguments[1])) {
diff --git a/src/main/java/net/knarcraft/playerpayouts/command/SetPlayerPaymentCommand.java b/src/main/java/net/knarcraft/playerpayouts/command/SetPlayerPaymentCommand.java
index 47df25f..aca0d9a 100644
--- a/src/main/java/net/knarcraft/playerpayouts/command/SetPlayerPaymentCommand.java
+++ b/src/main/java/net/knarcraft/playerpayouts/command/SetPlayerPaymentCommand.java
@@ -4,15 +4,16 @@ import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.playerpayouts.PlayerPayouts;
import net.knarcraft.playerpayouts.config.Configuration;
import net.knarcraft.playerpayouts.config.Translatable;
+import net.knarcraft.playerpayouts.util.PlayerIdHelper;
import net.knarcraft.playerpayouts.util.StringHelper;
import org.bukkit.Bukkit;
-import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
+import java.util.List;
+import java.util.Map;
import java.util.UUID;
/**
@@ -34,36 +35,48 @@ public class SetPlayerPaymentCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
@NotNull String[] arguments) {
- if (arguments.length < 2) {
- return false;
- }
- String playerName = arguments[0];
StringFormatter stringFormatter = PlayerPayouts.getStringFormatter();
- // Parse the player id
- UUID playerId;
- try {
- // Find player from UUID
- playerId = UUID.fromString(playerName);
- } catch (IllegalArgumentException exception) {
- // Get player from player name
- Player player = Bukkit.getPlayer(playerName);
- if (player != null) {
- playerId = player.getUniqueId();
- } else {
- // Try to match the player name against the offline player list
- playerId = null;
- for (OfflinePlayer offlinePlayer : Bukkit.getOfflinePlayers()) {
- if (offlinePlayer.getName() != null && offlinePlayer.getName().equals(playerName)) {
- playerId = offlinePlayer.getUniqueId();
- }
+ // Display all current group payment overrides
+ if (arguments.length == 0) {
+ StringBuilder builder = new StringBuilder(stringFormatter.getUnformattedColoredMessage(
+ Translatable.CURRENT_PAYOUT_OVERRIDE));
+ for (Map.Entry entry : configuration.getPlayerPayouts().entrySet()) {
+ if (entry.getValue() == null) {
+ continue;
}
- if (playerId == null) {
- stringFormatter.displayErrorMessage(commandSender, Translatable.PLAYER_ID_REQUIRED);
- return false;
+ String playerName = entry.getKey().toString();
+ String possibleName = Bukkit.getOfflinePlayer(entry.getKey()).getName();
+ if (possibleName != null) {
+ playerName = possibleName;
}
+ builder.append(stringFormatter.replacePlaceholders(Translatable.PAYOUT_OVERRIDE_LIST_FORMAT,
+ List.of("{subject}", "{value}"), List.of(playerName, String.valueOf(entry.getValue()))));
}
+ stringFormatter.displaySuccessMessage(commandSender, builder.toString());
+ return true;
+ }
+
+ String playerName = arguments[0];
+
+ // Parse the player id
+ UUID playerId = PlayerIdHelper.getId(playerName);
+ if (playerId == null) {
+ stringFormatter.displayErrorMessage(commandSender, Translatable.PLAYER_ID_REQUIRED);
+ return false;
+ }
+
+ // Display the specified group's payment override
+ if (arguments.length == 1) {
+ String output = stringFormatter.getUnformattedMessage(Translatable.CURRENT_PAYOUT_OVERRIDE);
+ Double value = configuration.getPlayerPayout(playerId);
+ if (value != null) {
+ output += stringFormatter.replacePlaceholders(Translatable.PAYOUT_OVERRIDE_LIST_FORMAT,
+ List.of("{subject}", "{value}"), List.of(playerName, String.valueOf(value)));
+ }
+ stringFormatter.displaySuccessMessage(commandSender, output);
+ return true;
}
// Parse the payout value
diff --git a/src/main/java/net/knarcraft/playerpayouts/config/Configuration.java b/src/main/java/net/knarcraft/playerpayouts/config/Configuration.java
index 73046b1..ac36498 100644
--- a/src/main/java/net/knarcraft/playerpayouts/config/Configuration.java
+++ b/src/main/java/net/knarcraft/playerpayouts/config/Configuration.java
@@ -55,6 +55,8 @@ public class Configuration {
groupPayouts = new HashMap<>();
playerPayouts = new HashMap<>();
this.fileConfiguration = fileConfiguration;
+
+ // Load per-group payouts
ConfigurationSection groupPayoutsSection = fileConfiguration.getConfigurationSection(
ConfigurationKey.GROUP_PAYOUTS.getPath());
if (groupPayoutsSection != null) {
@@ -62,6 +64,8 @@ public class Configuration {
groupPayouts.put(key, groupPayoutsSection.getDouble(key));
}
}
+
+ // Load per-player payouts
ConfigurationSection playerPayoutsSection = fileConfiguration.getConfigurationSection(
ConfigurationKey.PLAYER_PAYOUTS.getPath());
if (playerPayoutsSection != null) {
@@ -69,12 +73,17 @@ public class Configuration {
playerPayouts.put(UUID.fromString(key), playerPayoutsSection.getDouble(key));
}
}
+
+ // Load simple configuration values
this.defaultPayout = fileConfiguration.getDouble(ConfigurationKey.DEFAULT_PAYOUT.getPath(), 10);
this.hoursUntilBonus = fileConfiguration.getInt(ConfigurationKey.HOURS_UNTIL_BONUS.getPath(), 100);
this.bonusMultiplier = fileConfiguration.getDouble(ConfigurationKey.BONUS_MULTIPLIER.getPath(), 1);
this.payoutDelay = fileConfiguration.getInt(ConfigurationKey.PAYOUT_DELAY.getPath(), 60);
this.afkPercentage = fileConfiguration.getDouble(ConfigurationKey.AFK_PERCENTAGE.getPath(), 0);
- this.displayPaymentMessage = fileConfiguration.getBoolean(ConfigurationKey.DISPLAY_PAYMENT_MESSAGE.getPath(), true);
+ this.displayPaymentMessage = fileConfiguration.getBoolean(ConfigurationKey.DISPLAY_PAYMENT_MESSAGE.getPath(),
+ true);
+
+ // Parse the payout rules
try {
this.payoutComponent = PayoutActionParser.matchPayoutComponent(fileConfiguration.getString(
ConfigurationKey.PAYOUT_RULES.getPath(), "p,hg,b"));
@@ -260,6 +269,44 @@ public class Configuration {
this.save();
}
+ /**
+ * Gets all group payout overrides
+ *
+ * @return All group payout overrides
+ */
+ public @NotNull Map getGroupPayouts() {
+ return groupPayouts;
+ }
+
+ /**
+ * Gets a group payout override
+ *
+ * @param groupName The group to get the override of
+ * @return The overridden payout, or null if missing or cleared
+ */
+ public @Nullable Double getGroupPayout(@NotNull String groupName) {
+ return groupPayouts.get(groupName);
+ }
+
+ /**
+ * Gets all player payout overrides
+ *
+ * @return All player payout overrides
+ */
+ public @NotNull Map getPlayerPayouts() {
+ return playerPayouts;
+ }
+
+ /**
+ * Gets a player payout override
+ *
+ * @param playerId The id of the player to get the override of
+ * @return The overridden payout, or null if missing or cleared
+ */
+ public @Nullable Double getPlayerPayout(@NotNull UUID playerId) {
+ return playerPayouts.get(playerId);
+ }
+
/**
* Saves this configuration to disk
*/
diff --git a/src/main/java/net/knarcraft/playerpayouts/config/Translatable.java b/src/main/java/net/knarcraft/playerpayouts/config/Translatable.java
index c2868d8..201eb57 100644
--- a/src/main/java/net/knarcraft/playerpayouts/config/Translatable.java
+++ b/src/main/java/net/knarcraft/playerpayouts/config/Translatable.java
@@ -58,6 +58,16 @@ public enum Translatable implements TranslatableMessage {
*/
GROUP_INVALID,
+ /**
+ * The text displayed when listing current payout overrides
+ */
+ CURRENT_PAYOUT_OVERRIDE,
+
+ /**
+ * The format to use when listing current payout overrides
+ */
+ PAYOUT_OVERRIDE_LIST_FORMAT,
+
;
@Override
diff --git a/src/main/java/net/knarcraft/playerpayouts/util/PlayerIdHelper.java b/src/main/java/net/knarcraft/playerpayouts/util/PlayerIdHelper.java
new file mode 100644
index 0000000..ac8319a
--- /dev/null
+++ b/src/main/java/net/knarcraft/playerpayouts/util/PlayerIdHelper.java
@@ -0,0 +1,54 @@
+package net.knarcraft.playerpayouts.util;
+
+import org.bukkit.Bukkit;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.UUID;
+
+/**
+ * A helper class for dealing with player ids
+ */
+public final class PlayerIdHelper {
+
+ private PlayerIdHelper() {
+
+ }
+
+ /**
+ * Gets a player's UUID from the player's identifier
+ *
+ * @param playerIdentifier The identifier of the player
+ * @return The id of the player, or null if an invalid UUID or name has been given
+ */
+ public static @Nullable UUID getId(@NotNull String playerIdentifier) {
+ UUID playerId;
+ try {
+ // Find player from UUID
+ playerId = UUID.fromString(playerIdentifier);
+ } catch (IllegalArgumentException exception) {
+ // Get player from player name
+ Player player = Bukkit.getPlayer(playerIdentifier);
+ if (player != null) {
+ playerId = player.getUniqueId();
+ } else {
+ // Try to match the player name against the offline player list
+ playerId = null;
+ for (OfflinePlayer offlinePlayer : Bukkit.getOfflinePlayers()) {
+ if (offlinePlayer.getName() != null && offlinePlayer.getName().equals(playerIdentifier)) {
+ playerId = offlinePlayer.getUniqueId();
+ }
+ }
+
+ if (playerId == null) {
+ return null;
+ }
+ }
+ }
+
+ return playerId;
+ }
+
+}
diff --git a/src/main/resources/strings.yml b/src/main/resources/strings.yml
index abf7f73..af56296 100644
--- a/src/main/resources/strings.yml
+++ b/src/main/resources/strings.yml
@@ -1,11 +1,13 @@
en:
- GROUP_PAYOUTS_UNAVAILABLE: "Vault permissions aren't available, and thus per-group payouts are unavailable."
- PLUGIN_RELOADED: "Plugin reloaded!"
- GROUP_PAYOUT_CLEARED: "Group payout for group {group} has been cleared"
- GROUP_PAYOUT_SET: "Group payout for group {group} has been set to {value}"
- PLAYER_PAYOUT_CLEARED: "Player payout for player {player} has been cleared"
- PLAYER_PAYOUT_SET: "Player payout for player {player} has been set to {value}"
- PAYOUT_NUMBER_REQUIRED: "Payout must be a number"
- PLAYER_ID_REQUIRED: "You must supply a valid name of an online player, or a UUID"
- PAYOUT_RECEIVED: "You got a paycheck of {value}"
- GROUP_INVALID: "You have specified an invalid permission group"
\ No newline at end of file
+ GROUP_PAYOUTS_UNAVAILABLE: "ECECECVault permissions aren't available, and thus per-group payouts are unavailable."
+ PLUGIN_RELOADED: "ECECECPlugin reloaded!"
+ GROUP_PAYOUT_CLEARED: "ECECECGroup payout for group {group} has been cleared"
+ GROUP_PAYOUT_SET: "ECECECGroup payout for group {group} has been set to {value}"
+ PLAYER_PAYOUT_CLEARED: "ECECECPlayer payout for player {player} has been cleared"
+ PLAYER_PAYOUT_SET: "ECECECPlayer payout for player {player} has been set to {value}"
+ PAYOUT_NUMBER_REQUIRED: "ECECECPayout must be a number"
+ PLAYER_ID_REQUIRED: "ECECECYou must supply a valid name of an online player, or a UUID"
+ PAYOUT_RECEIVED: "ECECECYou got a paycheck of {value}"
+ GROUP_INVALID: "ECECECYou have specified an invalid permission group"
+ CURRENT_PAYOUT_OVERRIDE: "ECECECCurrent payout override(s):&r"
+ PAYOUT_OVERRIDE_LIST_FORMAT: "\ne9e0d0{subject}&r -> ůc2b{value}&r"
\ No newline at end of file