mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-08-06 12:33:03 +00:00
Fix vanilla command execution on discord
This commit is contained in:
parent
11836e6662
commit
3505b47d8f
1 changed files with 14 additions and 2 deletions
|
@ -7,6 +7,7 @@ import net.essentialsx.discord.JDADiscordService;
|
||||||
import net.essentialsx.discord.interactions.InteractionCommandImpl;
|
import net.essentialsx.discord.interactions.InteractionCommandImpl;
|
||||||
import net.essentialsx.discord.util.DiscordCommandSender;
|
import net.essentialsx.discord.util.DiscordCommandSender;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandException;
|
||||||
|
|
||||||
import static com.earth2me.essentials.I18n.tl;
|
import static com.earth2me.essentials.I18n.tl;
|
||||||
|
|
||||||
|
@ -20,7 +21,18 @@ public class ExecuteCommand extends InteractionCommandImpl {
|
||||||
public void onCommand(InteractionEvent event) {
|
public void onCommand(InteractionEvent event) {
|
||||||
final String command = event.getStringArgument("command");
|
final String command = event.getStringArgument("command");
|
||||||
event.reply(tl("discordCommandExecuteReply", command));
|
event.reply(tl("discordCommandExecuteReply", command));
|
||||||
Bukkit.getScheduler().runTask(jda.getPlugin(), () ->
|
Bukkit.getScheduler().runTask(jda.getPlugin(), () -> {
|
||||||
Bukkit.dispatchCommand(new DiscordCommandSender(jda, Bukkit.getConsoleSender(), event::reply).getSender(), command));
|
try {
|
||||||
|
Bukkit.dispatchCommand(new DiscordCommandSender(jda, Bukkit.getConsoleSender(), event::reply).getSender(), command);
|
||||||
|
} catch (CommandException e) {
|
||||||
|
// Check if this is a vanilla command, in which case we have to use a vanilla command sender :(
|
||||||
|
if (e.getMessage().contains("a vanilla command listener") || (e.getCause() != null && e.getCause().getMessage().contains("a vanilla command listener"))) {
|
||||||
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Something unrelated, should error out here
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue