-
-
Notifications
You must be signed in to change notification settings - Fork 2
GH-37 Implement /withdraw command for physical banknote withdrawal #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Qbiterv
wants to merge
17
commits into
EternalCodeTeam:master
Choose a base branch
from
Qbiterv:physical-withdraw
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+810
−142
Open
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b5d1c21
Implement basic of paycheck management system with admin commands and…
Qbiterv 2ec3945
Enhance paycheck system: add price argument resolver, improve paychec…
Qbiterv 57297af
Refactor paycheck system to withdraw system: rename classes and updat…
Qbiterv a6c2134
Refactor withdraw system: rename classes, update dependencies, and im…
Qbiterv 632c26b
Refactor withdraw system: update message handling, improve price argu…
Qbiterv dc22d8b
Refactor withdraw system: update plugin metadata handling, adjust ite…
Qbiterv de005b7
Fix price validation logic in PriceArgumentResolver: update threshold…
Qbiterv e84550c
Refactor command argument handling: update amount argument to use Pri…
Qbiterv e558053
Refactor AdminSetCommand: improve method parameter formatting for bet…
Qbiterv 292a847
Refactor WithdrawItemService: ensure default item type is set to PAPE…
Qbiterv 2aba885
Implement WithdrawItemService interface and create WithdrawItemServic…
Qbiterv 40bf52c
Refactor PluginConfig and command classes: replace ItemStack with Con…
Qbiterv 94d83d2
Refactor WithdrawService: update texture assignment to handle absence…
Qbiterv 55aa9b6
Refactor command argument handling: replace PriceArgumentResolver wit…
Qbiterv df22aa5
Refactor message formatting: streamline chat notices for improved rea…
Qbiterv 4b312cd
Review. Use proper paper-api loader, fix multiple bug's.
vLuckyyy 43aed79
Fix tabulation. Remove useless changes.
vLuckyyy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...my-core/src/main/java/com/eternalcode/economy/command/argument/PriceArgumentResolver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package com.eternalcode.economy.command.argument; | ||
|
|
||
| import com.eternalcode.economy.config.implementation.PluginConfig; | ||
| import com.eternalcode.economy.config.implementation.messages.MessageConfig; | ||
| import dev.rollczi.litecommands.argument.Argument; | ||
| import dev.rollczi.litecommands.argument.parser.ParseResult; | ||
| import dev.rollczi.litecommands.argument.resolver.ArgumentResolver; | ||
| import dev.rollczi.litecommands.invocation.Invocation; | ||
| import org.bukkit.command.CommandSender; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.math.RoundingMode; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| public class PriceArgumentResolver extends ArgumentResolver<CommandSender, BigDecimal> { | ||
| public static final String KEY = "price"; | ||
| private static final Pattern PRICE_PATTERN = | ||
| Pattern.compile("^(\\d+(?:[.,]\\d+)?)([kmb])?$", Pattern.CASE_INSENSITIVE); | ||
Qbiterv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private final PluginConfig config; | ||
| private final MessageConfig messages; | ||
|
|
||
| private final Map<Character, BigDecimal> multipliers; | ||
|
|
||
| public PriceArgumentResolver(PluginConfig config, MessageConfig messages) { | ||
Qbiterv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.config = config; | ||
| this.messages = messages; | ||
| this.multipliers = new HashMap<>(); | ||
|
|
||
| config.units.format.forEach(unit -> { | ||
| this.multipliers.put(unit.getSuffix(), BigDecimal.valueOf(unit.getFactor())); | ||
Qbiterv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| protected ParseResult<BigDecimal> parse( | ||
| Invocation<CommandSender> invocation, Argument<BigDecimal> argument, String raw) { | ||
| Matcher matcher = PRICE_PATTERN.matcher(raw.toLowerCase()); | ||
Qbiterv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (!matcher.matches()) { | ||
| return ParseResult.failure(this.messages.invalidPrice); | ||
| } | ||
|
|
||
| String numberPart = matcher.group(1).replace(',', '.'); | ||
| String suffix = matcher.group(2); | ||
|
|
||
| try { | ||
| BigDecimal value = new BigDecimal(numberPart); | ||
|
|
||
| if (suffix != null) { | ||
| BigDecimal multiplier = multipliers.get(Character.toLowerCase(suffix.charAt(0))); | ||
|
|
||
| if (multiplier == null) { | ||
| return ParseResult.failure(this.messages.invalidPrice); | ||
| } | ||
|
|
||
| value = value.multiply(multiplier); | ||
| } | ||
|
|
||
| if (value.compareTo(BigDecimal.ZERO) <= 0) { | ||
| return ParseResult.failure(this.messages.priceNeedToBeGreaterThanZero); | ||
Qbiterv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return ParseResult.success(value.setScale(2, RoundingMode.DOWN)); | ||
|
|
||
| } catch (NumberFormatException e) { | ||
Qbiterv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return ParseResult.failure(this.messages.invalidPrice); | ||
| } | ||
| } | ||
| } | ||
24 changes: 24 additions & 0 deletions
24
...onomy-core/src/main/java/com/eternalcode/economy/command/impl/admin/AdminItemCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.eternalcode.economy.command.impl.admin; | ||
Qbiterv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| import com.eternalcode.economy.EconomyPermissionConstant; | ||
| import com.eternalcode.economy.withdraw.WithdrawManager; | ||
| import dev.rollczi.litecommands.annotations.command.Command; | ||
| import dev.rollczi.litecommands.annotations.context.Context; | ||
| import dev.rollczi.litecommands.annotations.execute.Execute; | ||
| import dev.rollczi.litecommands.annotations.permission.Permission; | ||
| import org.bukkit.entity.Player; | ||
|
|
||
| @Command(name = "economy item") | ||
Qbiterv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @Permission(EconomyPermissionConstant.ADMIN_ITEM_PERMISSION) | ||
| public class AdminItemCommand { | ||
Qbiterv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private final WithdrawManager withdrawManager; | ||
|
|
||
| public AdminItemCommand(WithdrawManager withdrawManager) { | ||
| this.withdrawManager = withdrawManager; | ||
| } | ||
|
|
||
| @Execute | ||
| void execute(@Context Player player) { | ||
| withdrawManager.setItem(player); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...ava/com/eternalcode/economy/config/implementation/messages/MessagePaycheckSubSection.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.eternalcode.economy.config.implementation.messages; | ||
|
|
||
| import com.eternalcode.multification.notice.Notice; | ||
| import eu.okaeri.configs.OkaeriConfig; | ||
|
|
||
| public class MessagePaycheckSubSection extends OkaeriConfig { | ||
| public Notice noItem = Notice.chat( | ||
| "<b><gradient:#00FFA2:#34AE00>ECONOMY</gradient></b> <dark_gray>➤</dark_gray> <red>You must hold item to create paycheck!" | ||
| ); | ||
|
|
||
| public Notice noCheck = Notice.chat( | ||
| "<b><gradient:#00FFA2:#34AE00>ECONOMY</gradient></b> <dark_gray>➤</dark_gray> <red>You must hold an paycheck to redeem it!" | ||
| ); | ||
|
|
||
| public Notice setItem = Notice.chat( | ||
Qbiterv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "<b><gradient:#00FFA2:#34AE00>ECONOMY</gradient></b> <dark_gray>➤</dark_gray> <green>You have set paycheck item to <white>{ITEM}<green>!" | ||
| ); | ||
|
|
||
| public Notice withdraw = Notice.chat( | ||
Qbiterv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "<b><gradient:#00FFA2:#34AE00>ECONOMY</gradient></b> <dark_gray>➤</dark_gray> <green>You have withdrawn a paycheck of <white>{VALUE}<green>!" | ||
| ); | ||
|
|
||
| public Notice redeem = Notice.chat( | ||
Qbiterv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "<b><gradient:#00FFA2:#34AE00>ECONOMY</gradient></b> <dark_gray>➤</dark_gray> <green>You have redeemed your paycheck of <white>{VALUE}<green>!" | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
eternaleconomy-core/src/main/java/com/eternalcode/economy/withdraw/WithdrawCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.eternalcode.economy.withdraw; | ||
|
|
||
| import com.eternalcode.economy.EconomyPermissionConstant; | ||
| import com.eternalcode.economy.account.Account; | ||
| import com.eternalcode.economy.command.argument.PriceArgumentResolver; | ||
| import com.eternalcode.economy.format.DecimalFormatter; | ||
| import com.eternalcode.economy.multification.NoticeService; | ||
| import dev.rollczi.litecommands.annotations.argument.Arg; | ||
| import dev.rollczi.litecommands.annotations.argument.Key; | ||
| import dev.rollczi.litecommands.annotations.command.Command; | ||
| import dev.rollczi.litecommands.annotations.context.Context; | ||
| import dev.rollczi.litecommands.annotations.execute.Execute; | ||
| import dev.rollczi.litecommands.annotations.permission.Permission; | ||
| import jakarta.validation.constraints.Positive; | ||
|
|
||
Qbiterv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| import java.math.BigDecimal; | ||
|
|
||
| @Command(name = "withdraw", aliases = {"paycheck", "check"}) | ||
| @Permission(EconomyPermissionConstant.ADMIN_ITEM_PERMISSION) | ||
Qbiterv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public class WithdrawCommand { | ||
| private final WithdrawManager withdrawManager; | ||
| private final NoticeService noticeService; | ||
| private final DecimalFormatter decimalFormatter; | ||
|
|
||
| public WithdrawCommand( | ||
| WithdrawManager withdrawManager, | ||
| NoticeService noticeService, | ||
| DecimalFormatter decimalFormatter | ||
| ) { | ||
| this.withdrawManager = withdrawManager; | ||
| this.noticeService = noticeService; | ||
| this.decimalFormatter = decimalFormatter; | ||
| } | ||
|
|
||
| @Execute | ||
| void execute(@Context Account account, @Arg @Positive @Key(PriceArgumentResolver.KEY) BigDecimal value) { | ||
Qbiterv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| BigDecimal balance = account.balance(); | ||
| BigDecimal subtract = balance.subtract(value); | ||
|
|
||
| if (subtract.compareTo(BigDecimal.ZERO) < 0) { | ||
Qbiterv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| noticeService.create() | ||
| .notice(messageConfig -> messageConfig.player.insufficientBalance) | ||
| .placeholder("{MISSING_BALANCE}", decimalFormatter.format(subtract.abs())) | ||
| .player(account.uuid()) | ||
| .send(); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| withdrawManager.givePaycheck(account.uuid(), value); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.