Added `discordignore` command
+ Toggles Discord messages on/off for the user + Resolves #16pull/17/head
parent
df292f88c5
commit
ca36515fc2
4
pom.xml
4
pom.xml
|
@ -3,7 +3,7 @@
|
||||||
<groupId>xyz.etztech</groupId>
|
<groupId>xyz.etztech</groupId>
|
||||||
<artifactId>QoL</artifactId>
|
<artifactId>QoL</artifactId>
|
||||||
<!-- Version is used in plugin.yml -->
|
<!-- Version is used in plugin.yml -->
|
||||||
<version>1.14</version>
|
<version>1.15</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<!-- Plugin Information -->
|
<!-- Plugin Information -->
|
||||||
|
@ -53,7 +53,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.discordsrv</groupId>
|
<groupId>com.discordsrv</groupId>
|
||||||
<artifactId>discordsrv</artifactId>
|
<artifactId>discordsrv</artifactId>
|
||||||
<version>1.19.1</version>
|
<version>1.23.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package xyz.etztech.qol;
|
package xyz.etztech.qol;
|
||||||
|
|
||||||
|
import github.scarsz.discordsrv.DiscordSRV;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
@ -124,6 +125,10 @@ public class QoL extends JavaPlugin {
|
||||||
new WikiCommand(this);
|
new WikiCommand(this);
|
||||||
new MoonCommand(this);
|
new MoonCommand(this);
|
||||||
|
|
||||||
|
if (DiscordSRV.api.isAnyHooked()) {
|
||||||
|
new DiscordIgnoreCommand(this);
|
||||||
|
}
|
||||||
|
|
||||||
if (dynmap != null) {
|
if (dynmap != null) {
|
||||||
new MarkerCommand(this);
|
new MarkerCommand(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
package xyz.etztech.qol.commands;
|
||||||
|
|
||||||
|
import github.scarsz.discordsrv.DiscordSRV;
|
||||||
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
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.discord_ignore")) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,15 @@
|
||||||
package xyz.etztech.qol.listeners;
|
package xyz.etztech.qol.listeners;
|
||||||
|
|
||||||
import github.scarsz.discordsrv.DiscordSRV;
|
import github.scarsz.discordsrv.DiscordSRV;
|
||||||
|
import github.scarsz.discordsrv.api.events.DiscordGuildMessagePreBroadcastEvent;
|
||||||
import github.scarsz.discordsrv.api.events.GameChatMessagePreProcessEvent;
|
import github.scarsz.discordsrv.api.events.GameChatMessagePreProcessEvent;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import xyz.etztech.qol.EtzTechUtil;
|
||||||
|
import xyz.etztech.qol.Lang;
|
||||||
import xyz.etztech.qol.QoL;
|
import xyz.etztech.qol.QoL;
|
||||||
import github.scarsz.discordsrv.api.Subscribe;
|
import github.scarsz.discordsrv.api.Subscribe;
|
||||||
|
import xyz.etztech.qol.commands.DiscordIgnoreCommand;
|
||||||
|
|
||||||
public class DiscordSRVListener {
|
public class DiscordSRVListener {
|
||||||
private final QoL plugin;
|
private final QoL plugin;
|
||||||
|
@ -20,4 +26,18 @@ public class DiscordSRVListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void discordGuildMessagePreBroadcastEvent(DiscordGuildMessagePreBroadcastEvent event) {
|
||||||
|
event.getRecipients().removeIf(recipient -> {
|
||||||
|
if (recipient instanceof Player) {
|
||||||
|
Player player = (Player) recipient;
|
||||||
|
|
||||||
|
return player.hasMetadata(DiscordIgnoreCommand.DISCORD_IGNORE_METADATA);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,9 @@ commands:
|
||||||
description: Search the Minecraft wiki
|
description: Search the Minecraft wiki
|
||||||
moon:
|
moon:
|
||||||
description: Get information about the current moon phase
|
description: Get information about the current moon phase
|
||||||
|
discordignore:
|
||||||
|
description: Mute chat messages coming from Discord
|
||||||
|
aliases: [dignore]
|
||||||
permissions:
|
permissions:
|
||||||
qol.admin:
|
qol.admin:
|
||||||
description: Ability to reload the plugin
|
description: Ability to reload the plugin
|
||||||
|
@ -126,3 +129,6 @@ permissions:
|
||||||
qol.moon:
|
qol.moon:
|
||||||
description: Ability to use the moon command
|
description: Ability to use the moon command
|
||||||
default: op
|
default: op
|
||||||
|
qol.discordignore:
|
||||||
|
description: Ability to use the use the discordignore command
|
||||||
|
default: op
|
||||||
|
|
Loading…
Reference in New Issue