mirror of
https://github.com/TheDeus-Group/TFM-4.3-Reloaded.git
synced 2024-12-22 22:54:57 +00:00
Fix senior admins not being senior while executing commands via Discord
This commit is contained in:
parent
4c2719b9e9
commit
e1e7bf784e
10 changed files with 39 additions and 13 deletions
|
@ -1,6 +1,5 @@
|
|||
package me.StevenLawson.TotalFreedomMod.discord.command;
|
||||
|
||||
import org.javacord.api.entity.message.Message;
|
||||
import org.javacord.api.entity.message.MessageBuilder;
|
||||
import org.javacord.api.entity.server.Server;
|
||||
import org.javacord.api.entity.user.User;
|
||||
|
@ -20,7 +19,8 @@ public interface DiscordCommand {
|
|||
* Execute the command, and return the results
|
||||
* @param user The user who executed the command
|
||||
* @param args The arguments they executed it with
|
||||
* @param guild
|
||||
* @return The results as a MessageBuilder
|
||||
*/
|
||||
MessageBuilder execute(User user, List<String> args);
|
||||
MessageBuilder execute(User user, List<String> args, Server guild);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public class DiscordCommandManager {
|
|||
for (ExecutableDiscordCommand command : commands) {
|
||||
if(command.command.equalsIgnoreCase(commandOrAlias) || command.aliases.contains(commandOrAlias.toLowerCase())) {
|
||||
if(command.canExecute(user, server)) {
|
||||
MessageBuilder messageBuilder = command.execute(user, args);
|
||||
MessageBuilder messageBuilder = command.execute(user, args, server);
|
||||
messageBuilder.send(channel);
|
||||
} else {
|
||||
EmbedBuilder errorEmbed = new EmbedBuilder();
|
||||
|
|
|
@ -63,7 +63,7 @@ public class ExecutableDiscordCommand implements DiscordCommand {
|
|||
return true;
|
||||
}
|
||||
|
||||
public MessageBuilder execute(User user, List<String> args) {
|
||||
public MessageBuilder execute(User user, List<String> args, Server guild) {
|
||||
return new MessageBuilder().setContent("");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,11 @@ package me.StevenLawson.TotalFreedomMod.discord.commands;
|
|||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||
import me.StevenLawson.TotalFreedomMod.discord.command.ExecutableDiscordCommand;
|
||||
import me.StevenLawson.TotalFreedomMod.discord.sender.DiscordCommandSender;
|
||||
import me.StevenLawson.TotalFreedomMod.util.SynchronousUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.javacord.api.entity.message.MessageBuilder;
|
||||
import org.javacord.api.entity.message.embed.Embed;
|
||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||
import org.javacord.api.entity.server.Server;
|
||||
import org.javacord.api.entity.user.User;
|
||||
|
||||
import java.awt.*;
|
||||
|
@ -23,13 +22,13 @@ public class AdminConsoleCommand extends ExecutableDiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public MessageBuilder execute(User user, List<String> args) {
|
||||
public MessageBuilder execute(User user, List<String> args, Server guild) {
|
||||
try {
|
||||
new BukkitRunnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
DiscordCommandSender discordCommandSender = new DiscordCommandSender(user);
|
||||
DiscordCommandSender discordCommandSender = new DiscordCommandSender(user, guild);
|
||||
String command = String.join(" ", args);
|
||||
Bukkit.dispatchCommand(discordCommandSender, command);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import me.StevenLawson.TotalFreedomMod.discord.bridge.DiscordBridge;
|
|||
import me.StevenLawson.TotalFreedomMod.discord.command.ExecutableDiscordCommand;
|
||||
import org.javacord.api.entity.message.MessageBuilder;
|
||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||
import org.javacord.api.entity.server.Server;
|
||||
import org.javacord.api.entity.user.User;
|
||||
|
||||
import java.awt.*;
|
||||
|
@ -18,7 +19,7 @@ public class HelpCommand extends ExecutableDiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public MessageBuilder execute(User user, List<String> args) {
|
||||
public MessageBuilder execute(User user, List<String> args, Server guild) {
|
||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
embedBuilder.setColor(Color.GREEN);
|
||||
embedBuilder.setTitle("Help Command");
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.javacord.api.entity.message.MessageBuilder;
|
||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||
import org.javacord.api.entity.server.Server;
|
||||
import org.javacord.api.entity.user.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -21,7 +22,7 @@ public class ListCommand extends ExecutableDiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public MessageBuilder execute(User user, List<String> args) {
|
||||
public MessageBuilder execute(User user, List<String> args, Server guild) {
|
||||
EmbedBuilder builder = new EmbedBuilder()
|
||||
.setTitle(String.format("Player List - %s", MainConfig.getString(ConfigurationEntry.SERVER_NAME)))
|
||||
.setDescription(String.format("There are %s / %s online players", Bukkit.getOnlinePlayers().size(), Bukkit.getMaxPlayers()));
|
||||
|
|
|
@ -14,7 +14,7 @@ public class TPSCommand extends ExecutableDiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public MessageBuilder execute(User user, List<String> args) {
|
||||
public MessageBuilder execute(User user, List<String> args, org.javacord.api.entity.server.Server guild) {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.setTitle("Server lag information");
|
||||
builder.addField("TPS", String.valueOf(Math.round(Server.getTPS())));
|
||||
|
|
|
@ -4,6 +4,7 @@ import me.StevenLawson.TotalFreedomMod.discord.command.ExecutableDiscordCommand;
|
|||
import me.StevenLawson.TotalFreedomMod.exception.PenisException;
|
||||
import org.javacord.api.entity.message.MessageBuilder;
|
||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||
import org.javacord.api.entity.server.Server;
|
||||
import org.javacord.api.entity.user.User;
|
||||
|
||||
import java.awt.*;
|
||||
|
@ -17,7 +18,7 @@ public class UptimeCommand extends ExecutableDiscordCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public MessageBuilder execute(User user, List<String> args) {
|
||||
public MessageBuilder execute(User user, List<String> args, Server guild) {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
try {
|
||||
builder.setTitle("VPS Uptime Information")
|
||||
|
|
|
@ -15,10 +15,12 @@ import java.util.Set;
|
|||
|
||||
public class DiscordCommandSender implements CommandSender {
|
||||
private final User user;
|
||||
private final org.javacord.api.entity.server.Server server;
|
||||
protected final PermissibleBase perm;
|
||||
|
||||
public DiscordCommandSender(User user) {
|
||||
public DiscordCommandSender(User user, org.javacord.api.entity.server.Server server) {
|
||||
this.user = user;
|
||||
this.server = server;
|
||||
this.perm = new PermissibleBase(this);
|
||||
}
|
||||
|
||||
|
@ -105,4 +107,12 @@ public class DiscordCommandSender implements CommandSender {
|
|||
@Override
|
||||
public void setOp(boolean b) {
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public org.javacord.api.entity.server.Server getDiscordServer() {
|
||||
return server;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,11 +4,13 @@ import com.google.common.collect.ImmutableList;
|
|||
import me.StevenLawson.TotalFreedomMod.admin.Admin;
|
||||
import me.StevenLawson.TotalFreedomMod.admin.AdminList;
|
||||
import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
|
||||
import me.StevenLawson.TotalFreedomMod.discord.sender.DiscordCommandSender;
|
||||
import me.StevenLawson.TotalFreedomMod.util.Utilities;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.javacord.api.entity.permission.Role;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
|
@ -79,6 +81,18 @@ public enum PlayerRank implements Comparator<PlayerRank>, Comparable<PlayerRank>
|
|||
|
||||
public static PlayerRank fromSender(CommandSender sender)
|
||||
{
|
||||
if (sender instanceof DiscordCommandSender) {
|
||||
DiscordCommandSender discordSender = (DiscordCommandSender) sender;
|
||||
List<Role> roles = discordSender.getUser().getRoles(discordSender.getDiscordServer());
|
||||
|
||||
for (Role role : roles) {
|
||||
if(role.getName().toLowerCase().contains("senior")) {
|
||||
return SENIOR;
|
||||
}
|
||||
}
|
||||
|
||||
return SUPER;
|
||||
}
|
||||
if (!(sender instanceof Player))
|
||||
{
|
||||
return CONSOLE;
|
||||
|
|
Loading…
Reference in a new issue