Skip to content

Commit

Permalink
Merge branch 'master' into only-two-decimal-places-in-placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
vLuckyyy committed Dec 29, 2024
2 parents a21057e + 3f814dc commit dce0302
Show file tree
Hide file tree
Showing 21 changed files with 220 additions and 25 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
cache: 'gradle'

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build
run: ./gradlew eternaleconomy-core:shadowJar
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repositories {
}

dependencies {
implementation("com.gradleup.shadow:shadow-gradle-plugin:8.3.0")
implementation("com.gradleup.shadow:shadow-gradle-plugin:8.3.3")
implementation("net.minecrell:plugin-yml:0.6.0")
implementation("xyz.jpenilla:run-task:2.3.1")
implementation("me.champeau.jmh:jmh-gradle-plugin:0.7.2")
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ object Versions {
const val OKAERI_CONFIGS = "5.0.3"
const val LITE_COMMANDS = "3.6.0-SNAPSHOT"

const val ETERNALCODE_COMMONS = "1.1.4-SNAPSHOT"
const val ETERNALCODE_COMMONS = "1.1.5"
const val MULTIFICATION = "1.1.3"

const val JETBRAINS_ANNOTATIONS = "24.1.0"
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/economy-checkstyle.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

checkstyle {
toolVersion = "10.17.0"
toolVersion = "10.18.2"

configFile = file("${rootDir}/config/checkstyle/checkstyle.xml")
configProperties["checkstyle.suppressions.file"] = "${rootDir}/config/checkstyle/suppressions.xml"
Expand All @@ -17,7 +17,7 @@ configurations.named("checkstyle") {
resolutionStrategy {
capabilitiesResolution {
withCapability("com.google.collections:google-collections") {
select("com.google.guava:guava:33.2.1-jre")
select("com.google.guava:guava:33.3.1-jre")
}
}
}
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/economy-repositories.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ repositories {
maven("https://storehouse.okaeri.eu/repository/maven-public/")
maven("https://jitpack.io")
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
8 changes: 7 additions & 1 deletion eternaleconomy-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import net.minecrell.pluginyml.bukkit.BukkitPluginDescription

plugins {
`economy-java`
`economy-repositories`
Expand Down Expand Up @@ -50,7 +52,7 @@ dependencies {

compileOnly("me.clip:placeholderapi:${Versions.PLACEHOLDER_API}")

testImplementation(platform("org.junit:junit-bom:5.10.2"))
testImplementation(platform("org.junit:junit-bom:5.11.2"))
testImplementation("org.junit.jupiter:junit-jupiter")
jmh("org.openjdk.jmh:jmh-core:1.37")
jmh("org.openjdk.jmh:jmh-generator-annprocess:1.37")
Expand All @@ -68,6 +70,10 @@ bukkit {
author = "EternalCodeTeam"
name = "EternalEconomy"
website = "www.eternalcode.pl"
// Enabling this option previously caused issues where the plugin was loaded before Vault,
// preventing the Vault Economy Provider from registering and causing dependent plugins to malfunction.
// Setting the load order to startup ensures the economy plugin is one of the first to load, avoiding these issues.
load = BukkitPluginDescription.PluginLoadOrder.STARTUP
version = "${project.version}"

depend = listOf("Vault")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import com.eternalcode.economy.command.admin.AdminSetCommand;
import com.eternalcode.economy.command.argument.AccountArgument;
import com.eternalcode.economy.command.context.AccountContext;
import com.eternalcode.economy.command.cooldown.CommandCooldownEditor;
import com.eternalcode.economy.command.cooldown.CommandCooldownMessage;
import com.eternalcode.economy.command.handler.InvalidUsageHandlerImpl;
import com.eternalcode.economy.command.handler.MissingPermissionHandlerImpl;
import com.eternalcode.economy.command.message.InvalidBigDecimalMessage;
Expand All @@ -26,6 +28,7 @@
import com.eternalcode.economy.command.validator.notsender.NotSender;
import com.eternalcode.economy.command.validator.notsender.NotSenderValidator;
import com.eternalcode.economy.config.ConfigService;
import com.eternalcode.economy.config.implementation.CommandsConfig;
import com.eternalcode.economy.config.implementation.PluginConfig;
import com.eternalcode.economy.config.implementation.messages.MessageConfig;
import com.eternalcode.economy.database.DatabaseManager;
Expand All @@ -41,6 +44,7 @@
import dev.rollczi.litecommands.LiteCommands;
import dev.rollczi.litecommands.bukkit.LiteBukkitFactory;
import dev.rollczi.litecommands.jakarta.LiteJakartaExtension;
import dev.rollczi.litecommands.message.LiteMessages;
import jakarta.validation.constraints.Positive;
import java.io.File;
import java.math.BigDecimal;
Expand Down Expand Up @@ -81,6 +85,7 @@ public void onEnable() {
ConfigService configService = new ConfigService();
MessageConfig messageConfig = configService.create(MessageConfig.class, new File(dataFolder, "messages.yml"));
PluginConfig pluginConfig = configService.create(PluginConfig.class, new File(dataFolder, "config.yml"));
CommandsConfig commandsConfig = configService.create(CommandsConfig.class, new File(dataFolder, "commands.yml"));

NoticeService noticeService = new NoticeService(messageConfig, this.audienceProvider, miniMessage);

Expand Down Expand Up @@ -112,14 +117,17 @@ public void onEnable() {
.missingPermission(new MissingPermissionHandlerImpl(noticeService))
.invalidUsage(new InvalidUsageHandlerImpl(noticeService))

.message(LiteMessages.COMMAND_COOLDOWN, new CommandCooldownMessage(noticeService, commandsConfig))
.editorGlobal(new CommandCooldownEditor(commandsConfig))

.commands(
new AdminAddCommand(accountPaymentService, decimalFormatter, noticeService),
new AdminRemoveCommand(accountPaymentService, decimalFormatter, noticeService),
new AdminSetCommand(accountPaymentService, decimalFormatter, noticeService),
new AdminResetCommand(accountPaymentService, noticeService),
new AdminBalanceCommand(noticeService, decimalFormatter),
new MoneyBalanceCommand(noticeService, decimalFormatter),
new MoneyTransferCommand(accountPaymentService, decimalFormatter, noticeService),
new MoneyTransferCommand(accountPaymentService, decimalFormatter, noticeService, pluginConfig),
new EconomyReloadCommand(configService, noticeService)
)

Expand All @@ -138,6 +146,7 @@ public void onEnable() {
accountManager,
decimalFormatter,
server,
this,
this.getLogger()
);
bridgeManager.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import com.eternalcode.economy.bridge.placeholderapi.PlaceholderEconomyExpansion;
import com.eternalcode.economy.format.DecimalFormatter;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;

Expand All @@ -16,30 +18,44 @@ public class BridgeManager {
private final DecimalFormatter decimalFormatter;

private final Server server;
private final Plugin plugin;
private final Logger logger;

public BridgeManager(
PluginDescriptionFile pluginDescriptionFile,
AccountManager accountManager,
DecimalFormatter decimalFormatter,
Server server,
Plugin plugin,
Logger logger
) {
this.pluginDescriptionFile = pluginDescriptionFile;
this.accountManager = accountManager;
this.decimalFormatter = decimalFormatter;
this.server = server;
this.plugin = plugin;
this.logger = logger;
}

public void init() {
this.setupBridge("PlaceholderAPI", () -> {
new PlaceholderEconomyExpansion(
this.pluginDescriptionFile,
this.accountManager,
this.decimalFormatter
).initialize();
// Using "load: STARTUP" in plugin.yml causes the plugin to load before PlaceholderAPI.
// Therefore, we need to delay the bridge initialization until the server is fully started.
// The scheduler runs the code after the "Done" message, ensuring the server is fully operational.
Bukkit.getScheduler().runTask(this.plugin, () -> {
this.setupBridge("PlaceholderAPI", () -> {
PlaceholderEconomyExpansion placeholderEconomyExpansion = new PlaceholderEconomyExpansion(
this.pluginDescriptionFile,
this.accountManager,
this.decimalFormatter
);

placeholderEconomyExpansion.register();

System.out.println("PlaceholderAPI bridge initialized!");
});
});

// other bridges (do not put bridges in the scheduler if not needed)
}

private void setupBridge(String pluginName, BridgeInitializer bridge) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.eternalcode.economy.command.cooldown;

import com.eternalcode.multification.notice.Notice;
import eu.okaeri.configs.OkaeriConfig;
import eu.okaeri.configs.annotation.Comment;

import java.time.Duration;

public class CommandCooldownConfig extends OkaeriConfig {
@Comment("Duration of the cooldown (e.g. 5s, 10m, 1h)")
public Duration duration = Duration.ofSeconds(5);
@Comment("Permission for admins to bypass the cooldown")
public String bypassPermission = "eternaleconomy.player.pay.bypass";
public Notice message = Notice.builder()
.chat("<b><gradient:#00FFA2:#34AE00>ECONOMY</gradient></b> <dark_gray>➤</dark_gray> "
+ "<white>You must wait <gradient:#00FFA2:#34AE00>{TIME}</gradient> before using /pay again.")
.actionBar("<gradient:#00FFA2:#34AE00>Wait {TIME}!</gradient>")
.build();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.eternalcode.economy.command.cooldown;

import com.eternalcode.economy.config.implementation.CommandsConfig;
import dev.rollczi.litecommands.command.builder.CommandBuilder;
import dev.rollczi.litecommands.cooldown.CooldownContext;
import dev.rollczi.litecommands.editor.Editor;
import dev.rollczi.litecommands.meta.Meta;
import org.bukkit.command.CommandSender;

import java.util.Map;

public class CommandCooldownEditor implements Editor<CommandSender> {

private final CommandsConfig commandsConfig;

public CommandCooldownEditor(CommandsConfig commandsConfig) {
this.commandsConfig = commandsConfig;
}

@Override
public CommandBuilder<CommandSender> edit(CommandBuilder<CommandSender> commandBuilder) {
Meta meta = commandBuilder.meta();

for (Map.Entry<String, CommandCooldownConfig> entry : commandsConfig.cooldowns.entrySet()) {
String commandName = entry.getKey();
boolean isCurrent = commandBuilder.isNameOrAlias(commandName);

if (!isCurrent) {
continue;
}

CommandCooldownConfig cooldown = entry.getValue();

meta.put(Meta.COOLDOWN, new CooldownContext(commandName, cooldown.duration, cooldown.bypassPermission));
break;
}

return commandBuilder;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.eternalcode.economy.command.cooldown;

import com.eternalcode.economy.config.implementation.CommandsConfig;
import com.eternalcode.economy.multification.NoticeService;
import dev.rollczi.litecommands.cooldown.CooldownState;
import dev.rollczi.litecommands.invocation.Invocation;
import dev.rollczi.litecommands.message.InvokedMessage;
import dev.rollczi.litecommands.message.LiteMessages;
import dev.rollczi.litecommands.time.DurationParser;
import org.bukkit.command.CommandSender;

import java.time.Duration;

public class CommandCooldownMessage implements InvokedMessage<CommandSender, Object, CooldownState> {

private final NoticeService noticeService;
private final CommandsConfig commandsConfig;

public CommandCooldownMessage(NoticeService noticeService, CommandsConfig commandsConfig) {
this.noticeService = noticeService;
this.commandsConfig = commandsConfig;
}

@Override
public Object get(Invocation<CommandSender> invocation, CooldownState cooldownState) {
CommandCooldownConfig cooldown = commandsConfig.cooldowns.get(cooldownState.getCooldownContext().getKey());

if (cooldown == null) {
return LiteMessages.COMMAND_COOLDOWN.getDefaultMessage(cooldownState);
}

String formatted = DurationParser.TIME_UNITS.format(Duration.ofSeconds(cooldownState.getRemainingDuration().getSeconds()));

return noticeService.create()
.notice(notice -> cooldown.message)
.placeholder("{TIME}", formatted)
.viewer(invocation.sender());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.eternalcode.economy.account.Account;
import com.eternalcode.economy.account.AccountPaymentService;
import com.eternalcode.economy.command.validator.notsender.NotSender;
import com.eternalcode.economy.config.implementation.PluginConfig;
import com.eternalcode.economy.format.DecimalFormatter;
import com.eternalcode.economy.multification.NoticeService;
import dev.rollczi.litecommands.annotations.argument.Arg;
Expand All @@ -21,15 +22,18 @@ public class MoneyTransferCommand {
private final AccountPaymentService accountPaymentService;
private final DecimalFormatter decimalFormatter;
private final NoticeService noticeService;
private PluginConfig pluginConfig;

public MoneyTransferCommand(
AccountPaymentService accountPaymentService,
DecimalFormatter decimalFormatter,
NoticeService noticeService
NoticeService noticeService,
PluginConfig pluginConfig
) {
this.accountPaymentService = accountPaymentService;
this.decimalFormatter = decimalFormatter;
this.noticeService = noticeService;
this.pluginConfig = pluginConfig;
}

@Execute
Expand All @@ -45,6 +49,16 @@ void execute(@Context Account payer, @Arg @NotSender Account receiver, @Arg @Pos
return;
}

if (amount.compareTo(this.pluginConfig.transactionLimit) > 0) {
this.noticeService.create()
.notice(notice -> notice.player.transferLimit)
.placeholder("{LIMIT}", this.decimalFormatter.format(this.pluginConfig.transactionLimit))
.player(payer.uuid())
.send();

return;
}

this.accountPaymentService.payment(payer, receiver, amount);

this.noticeService.create()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.eternalcode.economy.config.implementation;

import com.eternalcode.economy.command.cooldown.CommandCooldownConfig;
import eu.okaeri.configs.OkaeriConfig;
import eu.okaeri.configs.annotation.Comment;

import java.util.Map;

public class CommandsConfig extends OkaeriConfig {

@Comment({
"Cooldowns for commands",
"You can set a cooldown for each command, e.g. 'pay' command:",
})
public Map<String, CommandCooldownConfig> cooldowns = Map.of(
"pay", new CommandCooldownConfig()
);

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class PluginConfig extends OkaeriConfig {
@Comment("Default balance for new accounts")
public BigDecimal defaultBalance = BigDecimal.valueOf(0.0);

@Comment("Limit on the amount of money sent in one transaction")
public BigDecimal transactionLimit = BigDecimal.valueOf(1_000_000_000.0);

public static class Units extends OkaeriConfig {

public List<DecimalUnit> format = Arrays.asList(
Expand Down
Loading

0 comments on commit dce0302

Please sign in to comment.