56 lines
1.8 KiB
Java
56 lines
1.8 KiB
Java
|
package xyz.etztech.qol.commands;
|
||
|
|
||
|
import github.scarsz.discordsrv.DiscordSRV;
|
||
|
import org.bukkit.command.Command;
|
||
|
import org.bukkit.command.CommandExecutor;
|
||
|
import org.bukkit.command.CommandSender;
|
||
|
import org.bukkit.entity.Player;
|
||
|
import org.bukkit.metadata.FixedMetadataValue;
|
||
|
import xyz.etztech.qol.EtzTechUtil;
|
||
|
import xyz.etztech.qol.Lang;
|
||
|
import xyz.etztech.qol.QoL;
|
||
|
|
||
|
public class DiscordIgnoreCommand implements CommandExecutor {
|
||
|
public static final String DISCORD_IGNORE_METADATA = "qol.discord_ignore";
|
||
|
QoL plugin;
|
||
|
|
||
|
public DiscordIgnoreCommand(QoL plugin) {
|
||
|
this.plugin = plugin;
|
||
|
plugin.getCommand("discordignore").setExecutor(this);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
|
||
|
if (!( commandSender instanceof Player)) {
|
||
|
EtzTechUtil.sms(commandSender, Lang.NO_CONSOLE.getDef());
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
if (!commandSender.hasPermission("qol.discordignore")) {
|
||
|
EtzTechUtil.sms(commandSender, Lang.NO_PERMISSION.getDef());
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
if (!DiscordSRV.api.isAnyHooked()) {
|
||
|
EtzTechUtil.sms(commandSender, "Command not enabled!");
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
Player player = (Player) commandSender;
|
||
|
|
||
|
boolean ignoreState = player.hasMetadata(DISCORD_IGNORE_METADATA);
|
||
|
String msg;
|
||
|
if (ignoreState) {
|
||
|
player.removeMetadata(DISCORD_IGNORE_METADATA, plugin);
|
||
|
msg = "Discord messages will now appear.";
|
||
|
}
|
||
|
else {
|
||
|
player.setMetadata(DISCORD_IGNORE_METADATA, new FixedMetadataValue(plugin, DISCORD_IGNORE_METADATA));
|
||
|
msg = "Ignoring Discord messages.";
|
||
|
}
|
||
|
|
||
|
EtzTechUtil.sms(commandSender, org.bukkit.ChatColor.GREEN + msg);
|
||
|
return true;
|
||
|
}
|
||
|
}
|