Skip to content

Commit 6d2f4ea

Browse files
committed
config
1 parent 605f603 commit 6d2f4ea

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package pro.cloudnode.smp.cloudnodemsg;
2+
3+
import net.kyori.adventure.text.Component;
4+
import net.kyori.adventure.text.minimessage.MiniMessage;
5+
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
6+
import org.bukkit.configuration.file.FileConfiguration;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
import java.util.Objects;
10+
11+
public final class PluginConfig {
12+
public @NotNull FileConfiguration config;
13+
14+
public PluginConfig(final @NotNull FileConfiguration config) {
15+
this.config = config;
16+
}
17+
18+
/**
19+
* Incoming message format (recipient's point of view)
20+
* <p>Placeholders:</p>
21+
* <ul>
22+
* <li>{@code <sender>} - the username of the message sender</li>
23+
* <li>{@code <recipient>} - the username of the message recipient</li>
24+
* <li>{@code <message>} - the message text</li>
25+
* </ul>
26+
*
27+
* @param sender The username of the message sender
28+
* @param recipient The username of the message recipient
29+
* @param message The message text
30+
*/
31+
public @NotNull Component incoming(final @NotNull String sender, final @NotNull String recipient, final @NotNull String message) {
32+
return MiniMessage.miniMessage().deserialize(Objects.requireNonNull(config.getString("incoming"))
33+
.replace("<sender>", sender)
34+
.replace("<recipient>", recipient),
35+
Placeholder.unparsed("message", message)
36+
);
37+
}
38+
39+
/**
40+
* Outgoing message format (sender's point of view)
41+
* <p>Placeholders:</p>
42+
* <ul>
43+
* <li>{@code <sender>} - the username of the message sender</li>
44+
* <li>{@code <recipient>} - the username of the message recipient</li>
45+
* <li>{@code <message>} - the message text</li>
46+
* </ul>
47+
*
48+
* @param sender The username of the message sender
49+
* @param recipient The username of the message recipient
50+
* @param message The message text
51+
*/
52+
public @NotNull Component outgoing(final @NotNull String sender, final @NotNull String recipient, final @NotNull String message) {
53+
return MiniMessage.miniMessage().deserialize(Objects.requireNonNull(config.getString("outgoing"))
54+
.replace("<sender>", sender)
55+
.replace("<recipient>", recipient),
56+
Placeholder.unparsed("message", message)
57+
);
58+
}
59+
60+
/**
61+
* Command usage format
62+
* <p>Placeholders:</p>
63+
* <ul>
64+
* <li>{@code <command>} - the command name</li>
65+
* <li>{@code <usage>} - the command usage parameters</li>
66+
* </ul>
67+
*
68+
* @param label Command label
69+
* @param usage Command usage parameters
70+
*/
71+
public @NotNull Component usage(final @NotNull String label, final @NotNull String usage) {
72+
return MiniMessage.miniMessage().deserialize(Objects.requireNonNull(config.getString("usage")),
73+
Placeholder.unparsed("command", label),
74+
Placeholder.unparsed("usage", usage)
75+
);
76+
}
77+
78+
/**
79+
* Name for console/server that should appear as {@code <sender>} or {@code <recipient>} in messages
80+
*/
81+
public @NotNull String consoleName() {
82+
return Objects.requireNonNull(config.getString("console-name"));
83+
}
84+
85+
/**
86+
* No permission
87+
*/
88+
public @NotNull Component noPermission() {
89+
return MiniMessage.miniMessage().deserialize(Objects.requireNonNull(config.getString("errors.no-permission")));
90+
}
91+
92+
/**
93+
* Player has no username (somehow)
94+
*/
95+
public @NotNull Component invalidPlayer() {
96+
return MiniMessage.miniMessage().deserialize(Objects.requireNonNull(config.getString("errors.invalid-player")));
97+
}
98+
99+
/**
100+
* Player not found
101+
* <p>Placeholders:</p>
102+
* <ul><li>{@code <player>} - the player's username</li></ul>
103+
*
104+
* @param player The player's username
105+
*/
106+
public @NotNull Component playerNotFound(final @NotNull String player) {
107+
return MiniMessage.miniMessage().deserialize(Objects.requireNonNull(config.getString("errors.player-not-found")),
108+
Placeholder.unparsed("player", player)
109+
);
110+
}
111+
112+
public @NotNull Component messageYourself() {
113+
return MiniMessage.miniMessage().deserialize(Objects.requireNonNull(config.getString("errors.message-yourself")));
114+
}
115+
}
116+

src/main/resources/config.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Incoming message format (recipient's point of view)
2+
# Placeholders:
3+
# <sender> - the username of the message sender
4+
# <recipient> - the username of the message recipient
5+
# <message> - the message text
6+
incoming: '<click:suggest_command:/msg <sender> ><dark_gray>[<#60a5fa><sender></#60a5fa> <white>-></white> <#bfdbfe>me</#bfdbfe>]</dark_gray></click> <reset><#dbeafe><message></#dbeafe>'
7+
8+
# Outgoing message format (sender's point of view)
9+
# Same placeholders as incoming
10+
outgoing: '<click:suggest_command:/msg <recipient> ><dark_gray>[<#93c5fd>me</#93c5fd> <white>-></white> <#60a5fa><recipient></#60a5fa>]</dark_gray></click> <reset><#dbeafe><message></#dbeafe>'
11+
12+
# Name for console/server that should appear as <sender> or <recipient> in messages
13+
console-name: "Server"
14+
15+
# Command usage format
16+
# Placeholders:
17+
# <command> - the command name
18+
# <usage> - the command usage parameters
19+
usage: "<yellow>(!) Usage:</yellow> <white>/<command> <usage></white>"
20+
21+
# Error messages
22+
errors:
23+
# No permission
24+
no-permission: "<red>(!) You don't have permission to use this command.</red>"
25+
26+
# Player has no username (somehow)
27+
invalid-player: "<red>(!) Invalid player.</red>"
28+
29+
# Player not found
30+
# Placeholders:
31+
# <player> - the player's username
32+
player-not-found: "<red>(!) Player <gray><player></gray> not found.</red>"
33+
34+
message-yourself: "<red>(!) You can't send a message to yourself.</red>"

0 commit comments

Comments
 (0)