Skip to content

Commit 674dbcf

Browse files
committed
📝 Add action for auto messages module
1 parent 738b0ca commit 674dbcf

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/main/java/fr/maxlego08/essentials/module/modules/AutoMessageModule.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import fr.maxlego08.essentials.ZEssentialsPlugin;
55
import fr.maxlego08.essentials.api.configuration.NonLoadable;
66
import fr.maxlego08.essentials.module.ZModule;
7+
import fr.maxlego08.menu.api.requirement.Action;
8+
import fr.maxlego08.menu.api.utils.Placeholders;
79
import org.bukkit.configuration.file.YamlConfiguration;
810

911
import java.util.ArrayList;
@@ -40,11 +42,17 @@ public void loadConfiguration() {
4042

4143
YamlConfiguration configuration = getConfiguration();
4244
List<Map<?, ?>> messagesList = configuration.getMapList("messages");
45+
int index = 0;
4346
for (Map<?, ?> map : messagesList) {
4447
List<String> lines = (List<String>) map.get("lines");
4548
if (lines != null) {
46-
this.autoMessages.add(new AutoMessage(lines));
49+
List<Map<String, Object>> actionElements = (List<Map<String, Object>>) map.get("actions");
50+
List<Action> actions = actionElements != null
51+
? this.plugin.getButtonManager().loadActions(actionElements, "messages[" + index + "].actions", getConfigurationFile())
52+
: new ArrayList<>();
53+
this.autoMessages.add(new AutoMessage(lines, actions));
4754
}
55+
index++;
4856
}
4957

5058
if (this.isEnable && !this.autoMessages.isEmpty() && this.interval > 0) {
@@ -63,13 +71,17 @@ private void broadcastNextMessage() {
6371
this.currentIndex = (this.currentIndex + 1) % this.autoMessages.size();
6472
}
6573

74+
var fakeInventory = this.plugin.getInventoryManager().getFakeInventory();
6675
for (var player : this.plugin.getServer().getOnlinePlayers()) {
6776
for (String line : message.lines()) {
6877
this.componentMessage.sendMessage(player, line);
6978
}
79+
for (Action action : message.actions()) {
80+
action.preExecute(player, null, fakeInventory, new Placeholders());
81+
}
7082
}
7183
}
7284

73-
private record AutoMessage(List<String> lines) {
85+
private record AutoMessage(List<String> lines, List<Action> actions) {
7486
}
7587
}

src/main/resources/modules/automessage/config.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,31 @@ interval: 300
2020
random-order: false
2121

2222
# List of messages to broadcast
23+
# Each message can have optional 'actions' that will be executed for each player when the message is sent.
24+
# Actions use the zMenu action system. Available action types:
25+
# - type: message # Send additional messages
26+
# - type: console command # Execute console commands (%player% placeholder available)
27+
# - type: player command # Execute commands as player
28+
# - type: sound # Play a sound
29+
# - type: actionbar # Send an action bar message
30+
# - type: title # Send a title
31+
# See zMenu documentation for more action types: https://docs.zmenu.dev/
2332
messages:
2433
- lines:
2534
- ""
2635
- "#ffd353ℹ ᴀɴɴᴏᴜɴᴄᴇᴍᴇɴᴛ"
2736
- "&7Welcome to our server! Type &f/rules &7for server rules."
2837
- ""
38+
# actions:
39+
# - type: sound
40+
# sound: BLOCK_NOTE_BLOCK_PLING
41+
# pitch: 1.0
42+
# volume: 1.0
2943
- lines:
3044
- ""
3145
- "#ffd353ℹ ᴀɴɴᴏᴜɴᴄᴇᴍᴇɴᴛ"
3246
- "&7Join our Discord: &f/discord"
3347
- ""
48+
# actions:
49+
# - type: actionbar
50+
# message: "&eClick here to join our Discord!"

0 commit comments

Comments
 (0)