Greatly improves messaging, adds Jenkinsfile
All checks were successful
KnarCraft/PlayerPayouts/pipeline/head This commit looks good
All checks were successful
KnarCraft/PlayerPayouts/pipeline/head This commit looks good
This commit is contained in:
parent
203d843dc8
commit
f4a5811156
33
Jenkinsfile
vendored
Normal file
33
Jenkinsfile
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
pipeline {
|
||||
agent any
|
||||
tools {
|
||||
jdk 'JDK17'
|
||||
}
|
||||
stages {
|
||||
stage('Build') {
|
||||
steps {
|
||||
echo 'Building...'
|
||||
sh 'mvn clean & mvn validate & mvn compile'
|
||||
}
|
||||
}
|
||||
stage('Test') {
|
||||
steps {
|
||||
echo 'Testing...'
|
||||
sh 'mvn test'
|
||||
}
|
||||
}
|
||||
stage('Verify') {
|
||||
steps {
|
||||
echo 'Verifying...'
|
||||
sh 'mvn verify -Dmaven.test.skip=true'
|
||||
}
|
||||
}
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
echo 'Deploying...'
|
||||
sh 'mvn deploy -Dmaven.install.skip=true -Dmaven.test.skip=true'
|
||||
archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
34
pom.xml
34
pom.xml
@ -39,6 +39,20 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>net.knarcraft:knarlib</artifact>
|
||||
<includes>
|
||||
<include>net/knarcraft/knarlib/**</include>
|
||||
</includes>
|
||||
</filter>
|
||||
<filter>
|
||||
<excludes>
|
||||
<exclude>*.MF</exclude>
|
||||
<exclude>*.yml</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
@ -73,7 +87,21 @@
|
||||
<id>paper-repo</id>
|
||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>knarcraft-repo</id>
|
||||
<url>https://git.knarcraft.net/api/packages/EpicKnarvik97/maven</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>knarcraft-repo</id>
|
||||
<url>https://git.knarcraft.net/api/packages/EpicKnarvik97/maven</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>knarcraft-repo</id>
|
||||
<url>https://git.knarcraft.net/api/packages/EpicKnarvik97/maven</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@ -100,5 +128,11 @@
|
||||
<version>2.20.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.knarcraft</groupId>
|
||||
<artifactId>knarlib</artifactId>
|
||||
<version>1.2.4</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -1,12 +1,15 @@
|
||||
package net.knarcraft.playerpayouts;
|
||||
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.knarlib.formatting.Translator;
|
||||
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.config.Translatable;
|
||||
import net.knarcraft.playerpayouts.listener.PlayerJoinListener;
|
||||
import net.knarcraft.playerpayouts.manager.EconomyManager;
|
||||
import net.knarcraft.playerpayouts.manager.PermissionManager;
|
||||
@ -20,6 +23,7 @@ import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.ServicesManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -36,6 +40,7 @@ public final class PlayerPayouts extends JavaPlugin {
|
||||
|
||||
private Configuration configuration;
|
||||
private IEssentials essentials = null;
|
||||
private StringFormatter stringFormatter;
|
||||
private static PlayerPayouts playerPayouts;
|
||||
|
||||
@Override
|
||||
@ -49,6 +54,20 @@ public final class PlayerPayouts extends JavaPlugin {
|
||||
this.saveConfig();
|
||||
this.configuration = new Configuration(fileConfiguration);
|
||||
|
||||
Translator translator = new Translator();
|
||||
translator.registerMessageCategory(Translatable.GROUP_PAYOUTS_UNAVAILABLE);
|
||||
translator.loadLanguages(this.getDataFolder(), "en",
|
||||
fileConfiguration.getString("language", "en"));
|
||||
|
||||
PluginDescriptionFile description = this.getDescription();
|
||||
String prefix;
|
||||
if (description.getPrefix() == null) {
|
||||
prefix = "PlayerPayouts";
|
||||
} else {
|
||||
prefix = description.getPrefix();
|
||||
}
|
||||
stringFormatter = new StringFormatter(prefix, translator);
|
||||
|
||||
// Plugin startup logic
|
||||
if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
|
||||
if (!setupVault()) {
|
||||
@ -114,6 +133,15 @@ public final class PlayerPayouts extends JavaPlugin {
|
||||
playerPayouts.configuration.load(playerPayouts.getConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a string formatter
|
||||
*
|
||||
* @return <p>A string formatter</p>
|
||||
*/
|
||||
public static StringFormatter getStringFormatter() {
|
||||
return getInstance().stringFormatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pay all players that have been on the server long enough
|
||||
*/
|
||||
@ -144,8 +172,8 @@ public final class PlayerPayouts extends JavaPlugin {
|
||||
}
|
||||
EconomyManager.deposit(player, payment);
|
||||
if (configuration.displayPaymentMessage()) {
|
||||
player.sendMessage(this.getDescription().getPrefix() + "You got a paycheck of " +
|
||||
EconomyManager.format(payment));
|
||||
stringFormatter.displaySuccessMessage(player, stringFormatter.replacePlaceholder(
|
||||
Translatable.PAYOUT_RECEIVED, "{value}", EconomyManager.format(payment)));
|
||||
}
|
||||
PlayerTracker.trackPlayer(player);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.knarcraft.playerpayouts.command;
|
||||
|
||||
import net.knarcraft.playerpayouts.PlayerPayouts;
|
||||
import net.knarcraft.playerpayouts.config.Translatable;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
@ -19,7 +20,7 @@ public class ReloadCommand implements TabExecutor {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] args) {
|
||||
PlayerPayouts.reload();
|
||||
sender.sendMessage("Plugin reloaded!");
|
||||
PlayerPayouts.getStringFormatter().displaySuccessMessage(sender, Translatable.PLUGIN_RELOADED);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
package net.knarcraft.playerpayouts.command;
|
||||
|
||||
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.manager.PermissionManager;
|
||||
import net.knarcraft.playerpayouts.util.StringHelper;
|
||||
import org.bukkit.command.Command;
|
||||
@ -31,9 +34,10 @@ public class SetGroupPaymentCommand implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
StringFormatter stringFormatter = PlayerPayouts.getStringFormatter();
|
||||
|
||||
if (!PermissionManager.isInitialized()) {
|
||||
commandSender.sendMessage("Vault permissions aren't available, and thus per-group payouts are " +
|
||||
"unavailable.");
|
||||
stringFormatter.displayErrorMessage(commandSender, Translatable.GROUP_PAYOUTS_UNAVAILABLE);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -41,15 +45,18 @@ public class SetGroupPaymentCommand implements CommandExecutor {
|
||||
String group = arguments[0];
|
||||
if (StringHelper.isNonValue(arguments[1])) {
|
||||
configuration.setGroupPayout(group, null);
|
||||
commandSender.sendMessage(String.format("Group payout for group %s has been cleared", group));
|
||||
stringFormatter.displaySuccessMessage(commandSender, stringFormatter.replacePlaceholder(
|
||||
Translatable.GROUP_PAYOUT_CLEARED, "{group}", group));
|
||||
} else {
|
||||
Double payout = Double.parseDouble(arguments[1]);
|
||||
configuration.setGroupPayout(group, payout);
|
||||
commandSender.sendMessage(String.format("Group payout for group %s has been set to %s", group, payout));
|
||||
stringFormatter.displaySuccessMessage(commandSender, stringFormatter.replacePlaceholders(
|
||||
Translatable.GROUP_PAYOUT_SET, new String[]{"{group}", "{value}"},
|
||||
new String[]{group, String.valueOf(payout)}));
|
||||
}
|
||||
return true;
|
||||
} catch (NumberFormatException exception) {
|
||||
commandSender.sendMessage("Payout must be a number");
|
||||
stringFormatter.displayErrorMessage(commandSender, Translatable.PAYOUT_NUMBER_REQUIRED);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
package net.knarcraft.playerpayouts.command;
|
||||
|
||||
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.StringHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -35,6 +38,7 @@ public class SetPlayerPaymentCommand implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
String playerName = arguments[0];
|
||||
StringFormatter stringFormatter = PlayerPayouts.getStringFormatter();
|
||||
|
||||
// Parse the player id
|
||||
UUID playerId;
|
||||
@ -56,7 +60,7 @@ public class SetPlayerPaymentCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
if (playerId == null) {
|
||||
commandSender.sendMessage("You must supply a valid name of an online player, or a UUID");
|
||||
stringFormatter.displayErrorMessage(commandSender, Translatable.PLAYER_ID_REQUIRED);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -66,16 +70,18 @@ public class SetPlayerPaymentCommand implements CommandExecutor {
|
||||
try {
|
||||
if (StringHelper.isNonValue(arguments[1])) {
|
||||
configuration.setPlayerPayout(playerId, null);
|
||||
commandSender.sendMessage(String.format("Player payout for player %s has been cleared", playerName));
|
||||
stringFormatter.displaySuccessMessage(commandSender, stringFormatter.replacePlaceholder(
|
||||
Translatable.PLAYER_PAYOUT_CLEARED, "{player}", playerName));
|
||||
} else {
|
||||
Double payout = Double.parseDouble(arguments[1]);
|
||||
configuration.setPlayerPayout(playerId, payout);
|
||||
commandSender.sendMessage(String.format("Player payout for player %s has been set to %s", playerName,
|
||||
payout));
|
||||
stringFormatter.displaySuccessMessage(commandSender, stringFormatter.replacePlaceholders(
|
||||
Translatable.PLAYER_PAYOUT_SET, new String[]{"{player}", "{value}"},
|
||||
new String[]{playerName, String.valueOf(payout)}));
|
||||
}
|
||||
return true;
|
||||
} catch (NumberFormatException exception) {
|
||||
commandSender.sendMessage("Payout must be a number");
|
||||
stringFormatter.displayErrorMessage(commandSender, Translatable.PAYOUT_NUMBER_REQUIRED);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,63 @@
|
||||
package net.knarcraft.playerpayouts.config;
|
||||
|
||||
import net.knarcraft.knarlib.formatting.TranslatableMessage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Player Payout's translatable strings
|
||||
*/
|
||||
public enum Translatable implements TranslatableMessage {
|
||||
|
||||
/**
|
||||
* The message displayed when group payouts are unavailable because of a missing permission plugin
|
||||
*/
|
||||
GROUP_PAYOUTS_UNAVAILABLE,
|
||||
|
||||
/**
|
||||
* The message displayed when the plugin is reloaded
|
||||
*/
|
||||
PLUGIN_RELOADED,
|
||||
|
||||
/**
|
||||
* The message displayed when a group payout override has been cleared
|
||||
*/
|
||||
GROUP_PAYOUT_CLEARED,
|
||||
|
||||
/**
|
||||
* The message displayed when a group payout override has been set
|
||||
*/
|
||||
GROUP_PAYOUT_SET,
|
||||
|
||||
/**
|
||||
* The message displayed when a non-number has been given as the payout
|
||||
*/
|
||||
PAYOUT_NUMBER_REQUIRED,
|
||||
|
||||
/**
|
||||
* The message displayed when an invalid player name or UUID has been given
|
||||
*/
|
||||
PLAYER_ID_REQUIRED,
|
||||
|
||||
/**
|
||||
* The message displayed when a player payout override has been cleared
|
||||
*/
|
||||
PLAYER_PAYOUT_CLEARED,
|
||||
|
||||
/**
|
||||
* The message displayed when a player payout override has been set
|
||||
*/
|
||||
PLAYER_PAYOUT_SET,
|
||||
|
||||
/**
|
||||
* The message displayed when a payout has been received
|
||||
*/
|
||||
PAYOUT_RECEIVED,
|
||||
|
||||
;
|
||||
|
||||
@Override
|
||||
public @NotNull TranslatableMessage[] getAllMessages() {
|
||||
return Translatable.values();
|
||||
}
|
||||
|
||||
}
|
@ -3,7 +3,7 @@ package net.knarcraft.playerpayouts.config.payout;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Instantiates a new payout action
|
||||
* A payout action is the combination of two components, joined by a delimiter
|
||||
*
|
||||
* @param component1 <p>The component "to the left of" the delimiter</p>
|
||||
* @param delimiter <p>The delimiter between the two components</p>
|
||||
|
@ -41,6 +41,8 @@ public class PayoutActionParser {
|
||||
}
|
||||
|
||||
for (int i = index; i < parts.size(); i++) {
|
||||
/* If the payout component isn't null, we're in the next step of the for loop, and the entire value of
|
||||
payoutComponent is the "left" component */
|
||||
if (payoutComponent == null) {
|
||||
String part = parts.get(i);
|
||||
PayoutTarget target = PayoutTarget.match(part);
|
||||
@ -58,6 +60,7 @@ public class PayoutActionParser {
|
||||
return payoutComponent;
|
||||
}
|
||||
|
||||
// Parse the delimiter
|
||||
PayoutDelimiter delimiter = PayoutDelimiter.match(parts.get(++i).charAt(0));
|
||||
if (delimiter == null) {
|
||||
throw new ParseException("Unable to parse payout mode string delimiter " + parts.get(i) + "!", i);
|
||||
@ -93,22 +96,24 @@ public class PayoutActionParser {
|
||||
for (int index = 0; index < input.length(); index++) {
|
||||
char character = input.charAt(index);
|
||||
if (PayoutDelimiter.match(character) != null) {
|
||||
// Tokenize delimiters, and tokenize everything read before the delimiter
|
||||
if (!currentToken.isEmpty()) {
|
||||
tokens.add(currentToken.toString());
|
||||
}
|
||||
tokens.add(String.valueOf(character));
|
||||
currentToken = new StringBuilder();
|
||||
} else if (Character.isLetter(character)) {
|
||||
tokenizeNormalCharacter(currentToken, character, input.length(), index, tokens);
|
||||
// Tokenize one letter
|
||||
tokenizeLetter(currentToken, character, input.length(), index, tokens);
|
||||
}
|
||||
|
||||
// Unrecognized tokens are ignored
|
||||
// Unrecognized tokens are ignored, to allow for spaces
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a normal character to the token. Adds the current token to tokens if at the end of the input
|
||||
* Adds a letter to the token. Adds the current token to tokens if at the end of the input
|
||||
*
|
||||
* @param currentToken <p>The string builder containing the current token.</p>
|
||||
* @param character <p>The character found in the input.</p>
|
||||
@ -116,8 +121,8 @@ public class PayoutActionParser {
|
||||
* @param index <p>The index of the read character.</p>
|
||||
* @param tokens <p>The list of processed tokens.</p>
|
||||
*/
|
||||
private static void tokenizeNormalCharacter(@NotNull StringBuilder currentToken, char character, int inputLength,
|
||||
int index, @NotNull List<String> tokens) {
|
||||
private static void tokenizeLetter(@NotNull StringBuilder currentToken, char character, int inputLength,
|
||||
int index, @NotNull List<String> tokens) {
|
||||
currentToken.append(character);
|
||||
if (index == inputLength - 1) {
|
||||
tokens.add(currentToken.toString());
|
||||
|
@ -3,6 +3,9 @@ package net.knarcraft.playerpayouts.config.payout;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Delimiters usable in the payout setting string
|
||||
*/
|
||||
public enum PayoutDelimiter {
|
||||
|
||||
/**
|
||||
|
@ -1,3 +1,5 @@
|
||||
# The language to use. Currently, only "en" is available, unless you add a custom one yourself
|
||||
language: en
|
||||
# The default payout if the player has no overrides
|
||||
defaultPayout: 10
|
||||
# The amount of minutes to wait between each payout
|
||||
|
10
src/main/resources/strings.yml
Normal file
10
src/main/resources/strings.yml
Normal file
@ -0,0 +1,10 @@
|
||||
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}"
|
Loading…
Reference in New Issue
Block a user