Skip to content

Commit 11fc9b4

Browse files
Add relay command
* Added relay and relaysilent commands * Updated Javacord from v3.3.2 to v3.4.0 * Added translation for command can't be run from console * Listing of commands now only shows commands the player has permission to * Slight efficiency improvement for chat listening by checking if there's a communication method with Discord before attempting
1 parent 70b187f commit 11fc9b4

11 files changed

Lines changed: 133 additions & 15 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
<dependency>
210210
<groupId>org.javacord</groupId>
211211
<artifactId>javacord</artifactId>
212-
<version>3.3.2</version>
212+
<version>3.4.0</version>
213213
<scope>compile</scope>
214214
<type>pom</type>
215215
</dependency>

src/main/java/com/firecontroller1847/truediscordlink/DiscordManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,11 @@ public ArrayList<String[]> sendDiscordMessage(String content) {
315315
return this.sendDiscordMessage(content, false);
316316
}
317317

318+
// Checks to see if there is a method of communication to the Discord server
319+
public boolean canCommunicateWithDiscord() {
320+
return discordlink.getConfig().getBoolean("webhooks.enabled") || (isBotConnected() && discordlink.getConfig().getLongList("bot.from_mc_channels").size() > 0);
321+
}
322+
318323
// Sends a message to the Discord server via the bot
319324
private void sendDiscordBotMessage(String content, boolean blocking, Player player) {
320325
if (!isBotConnected()) {

src/main/java/com/firecontroller1847/truediscordlink/TrueDiscordLink.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public boolean onAfterConfiguration() {
5252
// Register Commands
5353
PluginCommand cmdtdl = Objects.requireNonNull(this.getCommand("truediscordlink"));
5454
cmdtdl.setExecutor(new CommandTrueDiscordLink());
55-
5655
cmdtdl.setTabCompleter(new TabCompleterTrueDiscordLink());
5756

5857
// Register Events
@@ -97,7 +96,7 @@ private void migrateConfigurations() throws IOException {
9796
migrated = true;
9897
}
9998

100-
// Migration for Channel Tags
99+
// v1.1.0 -> v1.2.0
101100
if (!this.getConfig().contains("tagging.enable_channel_tagging", true)) {
102101
this.getConfig().set("tagging.enable_channel_tagging", true);
103102
this.getLogger().info("[config.yml] Added tagging.enable_channel_tagging");
@@ -108,26 +107,43 @@ private void migrateConfigurations() throws IOException {
108107
this.getLogger().info("[en.yml] Added tagging.minecraft_channel_tag_color");
109108
migrated = true;
110109
}
111-
112-
// Migration for Channel Notification Upon Linkage.
113110
if (!this.getConfig().contains("bot.linking.notify", true)) {
114111
this.getConfig().set("bot.linking.notify.link.enabled", false);
115112
this.getConfig().set("bot.linking.notify.link.channel", "000000000000000000");
116-
117113
this.getConfig().set("bot.linking.notify.unlink.enabled", false);
118114
this.getConfig().set("bot.linking.notify.unlink.channel", "000000000000000000");
119-
120115
this.getLogger().info("[config.yml] Added bot.linking.notify.*");
121116
migrated = true;
122117
}
123118
if (!translations.contains("linking.discord.notify", true)) {
124119
translations.set("linking.discord.notify.link", "%username% has linked with %mention%!");
125120
translations.set("linking.discord.notify.unlink", "%username% has unlinked with %mention%!");
126-
127121
this.getLogger().info("[en.yml] Added linking.discord.notify.*");
128122
migrated = true;
129123
}
130124

125+
// v1.2.0 -> v1.3.0
126+
if (!translations.contains("no_console_usage", true)) {
127+
translations.set("no_console_usage", "%prefix% §cYou cannot use this command from console!");
128+
this.getLogger().info("[en.yml] Added no_console_usage");
129+
migrated = true;
130+
}
131+
if (!translations.contains("commands.relay.no_message", true)) {
132+
translations.set("commands.relay.no_message", "%prefix% §cYou must include a message for me to relay.");
133+
this.getLogger().info("[en.yml] Added commands.relay.no_message");
134+
migrated = true;
135+
}
136+
if (!translations.contains("commands.relay.no_discord_communication", true)) {
137+
translations.set("commands.relay.no_discord_communication", "%prefix% §cThere is no way for me to communicate with Discord! Ensure you have either webhooks enabled or a bot enabled with 'from_mc_channels' configured!");
138+
this.getLogger().info("[en.yml] Added commands.relay.no_discord_communication");
139+
migrated = true;
140+
}
141+
if (!translations.contains("commands.relay.success", true)) {
142+
translations.set("commands.relay.success", "%prefix% Message successfully relayed to the Discord server.");
143+
this.getLogger().info("[en.yml] Added commands.relay.success");
144+
migrated = true;
145+
}
146+
131147
// Save
132148
if (migrated) {
133149
this.saveConfig();

src/main/java/com/firecontroller1847/truediscordlink/commands/CommandLink.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
3030

3131
// Check against console
3232
if (sender instanceof ConsoleCommandSender) {
33-
sender.sendMessage("You cannot use this command from console!");
33+
sender.sendMessage(plugin.getTranslation("no_console_usage"));
3434
return true;
3535
}
3636

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.firecontroller1847.truediscordlink.commands;
2+
3+
import com.firecontroller1847.truediscordlink.DiscordManager;
4+
import com.firecontroller1847.truediscordlink.FireCommand;
5+
import com.firecontroller1847.truediscordlink.FirePlugin;
6+
import com.firecontroller1847.truediscordlink.TrueDiscordLink;
7+
import org.bukkit.command.Command;
8+
import org.bukkit.command.CommandSender;
9+
import org.jetbrains.annotations.NotNull;
10+
11+
import java.util.Arrays;
12+
13+
public class CommandRelay extends FireCommand {
14+
15+
private boolean silent;
16+
17+
public CommandRelay(FirePlugin plugin, boolean silent) {
18+
super(plugin);
19+
this.silent = silent;
20+
}
21+
22+
@Override
23+
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
24+
// Get Discord manager
25+
DiscordManager discordManager = ((TrueDiscordLink) this.getPlugin()).getDiscordManager();
26+
27+
// Check if you can communicate with Discord
28+
if (!discordManager.canCommunicateWithDiscord()) {
29+
sender.sendMessage(plugin.getTranslation("commands.relay.no_discord_communication"));
30+
return true;
31+
}
32+
33+
// Message
34+
String message = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
35+
36+
// Handle empty message
37+
if (message.isEmpty()) {
38+
sender.sendMessage(plugin.getTranslation("commands.relay.no_message"));
39+
return true;
40+
}
41+
42+
// Send the message to Discord
43+
discordManager.sendDiscordMessage(String.join(" ", message));
44+
45+
// Respond to sender
46+
if (!silent) {
47+
sender.sendMessage(plugin.getTranslation("commands.relay.success"));
48+
}
49+
50+
// The command always works
51+
return true;
52+
}
53+
54+
}

src/main/java/com/firecontroller1847/truediscordlink/commands/CommandTrueDiscordLink.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.firecontroller1847.truediscordlink.commands;
22

3+
import com.firecontroller1847.truediscordlink.FirePlugin;
34
import com.firecontroller1847.truediscordlink.TrueDiscordLink;
45
import org.bukkit.command.Command;
56
import org.bukkit.command.CommandExecutor;
@@ -27,12 +28,32 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
2728
if (args[0].equalsIgnoreCase("unlink")) {
2829
return TrueDiscordLink.runCommand(new CommandUnlink(plugin), "truediscordlink.command.unlink", sender, command, label, args);
2930
}
31+
32+
// Relay
33+
if (args[0].equalsIgnoreCase("relay")) {
34+
return TrueDiscordLink.runCommand(new CommandRelay(plugin, false), "truediscordlink.command.relay", sender, command, label, args);
35+
}
36+
if (args[0].equalsIgnoreCase("relaysilent")) {
37+
return TrueDiscordLink.runCommand(new CommandRelay(plugin, true), "truediscordlink.command.relaysilent", sender, command, label, args);
38+
}
3039
}
3140

3241
// If it's not the command or any sub command, list all commands
33-
sender.sendMessage("/" + label + " reload");
34-
sender.sendMessage("/" + label + " link");
35-
sender.sendMessage("/" + label + " unlink");
42+
if (FirePlugin.hasPermission(sender, "truediscordlink.command.reload")) {
43+
sender.sendMessage("/" + label + " reload");
44+
}
45+
if (FirePlugin.hasPermission(sender, "truediscordlink.command.link")) {
46+
sender.sendMessage("/" + label + " link");
47+
}
48+
if (FirePlugin.hasPermission(sender, "truediscordlink.command.unlink")) {
49+
sender.sendMessage("/" + label + " unlink");
50+
}
51+
if (FirePlugin.hasPermission(sender, "truediscordlink.command.relay")) {
52+
sender.sendMessage("/" + label + " relay");
53+
}
54+
if (FirePlugin.hasPermission(sender, "truediscordlink.command.relaysilent")) {
55+
sender.sendMessage("/" + label + " relaysilent");
56+
}
3657
return true;
3758
}
3859

src/main/java/com/firecontroller1847/truediscordlink/commands/CommandUnlink.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
3131

3232
// Check against console
3333
if (sender instanceof ConsoleCommandSender) {
34-
sender.sendMessage("You cannot use this command from console!");
34+
sender.sendMessage(plugin.getTranslation("no_console_usage"));
3535
return true;
3636
}
3737

src/main/java/com/firecontroller1847/truediscordlink/listeners/minecraft/PlayerChatListener.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ public PlayerChatListener(TrueDiscordLink discordlink) {
2020

2121
@EventHandler
2222
public void onPlayerChat(AsyncPlayerChatEvent event) {
23+
// Check if you can communicate with Discord
24+
if (!discordlink.getDiscordManager().canCommunicateWithDiscord()) {
25+
return;
26+
}
27+
28+
// Check for essentials muting
2329
if (discordlink.getEssentialsApi() != null) {
2430
User user = discordlink.getEssentialsApi().getUser(event.getPlayer().getUniqueId());
2531
if (user != null && user.isMuted()) {

src/main/java/com/firecontroller1847/truediscordlink/tabcompleters/TabCompleterTrueDiscordLink.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ public class TabCompleterTrueDiscordLink implements TabCompleter {
1616
public static final String[][] FIRST_ARGS = {
1717
{ "reload", "truediscordlink.command.reload" },
1818
{ "link", "truediscordlink.command.link" },
19-
{ "unlink", "truediscordlink.command.unlink" }
19+
{ "unlink", "truediscordlink.command.unlink" },
20+
{ "relay", "truediscordlink.command.relay" },
21+
{ "relaysilent", "truediscordlink.command.relaysilent" }
2022
};
2123

2224
// Define Secondary Arguments

src/main/resources/lang/en.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@
1818
# Colors are accepted! Use the following character as the prefix: §
1919
# Hex codes are supported! Use them in the following format: §#000000
2020
prefix: "[§bDiscordLink§r]"
21-
no_permission: "§cYou do not have permission to run this command!"
21+
no_permission: "%prefix% §cYou do not have permission to run this command!"
22+
no_console_usage: "%prefix% §cYou cannot use this command from console!"
23+
commands:
24+
relay:
25+
no_message: "%prefix% §cYou must include a message for me to relay."
26+
no_discord_communication: "%prefix% §cThere is no way for me to communicate with Discord! Ensure you have either webhooks enabled or a bot enabled with 'from_mc_channels' configured!"
27+
success: "%prefix% Message successfully relayed to the Discord server."
2228
config:
2329
error: "%prefix% §cThere was an error loading the configuration!"
2430
reloaded: "%prefix% Configuration reloaded!"

0 commit comments

Comments
 (0)