-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into only-two-decimal-places-in-placeholder
- Loading branch information
Showing
21 changed files
with
220 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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,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 |
This file contains 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 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 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 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 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 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 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
19 changes: 19 additions & 0 deletions
19
...my-core/src/main/java/com/eternalcode/economy/command/cooldown/CommandCooldownConfig.java
This file contains 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,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(); | ||
} |
41 changes: 41 additions & 0 deletions
41
...my-core/src/main/java/com/eternalcode/economy/command/cooldown/CommandCooldownEditor.java
This file contains 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,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; | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
...y-core/src/main/java/com/eternalcode/economy/command/cooldown/CommandCooldownMessage.java
This file contains 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,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()); | ||
} | ||
|
||
} |
This file contains 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
19 changes: 19 additions & 0 deletions
19
...nomy-core/src/main/java/com/eternalcode/economy/config/implementation/CommandsConfig.java
This file contains 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,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() | ||
); | ||
|
||
} |
This file contains 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
Oops, something went wrong.