Added mute support and other stuff
This commit is contained in:
parent
d842891618
commit
1ba108fb21
6 changed files with 51 additions and 59 deletions
|
@ -50,7 +50,7 @@ public class RoleCommand extends DiscordCommandBase {
|
||||||
"List of game roles:\n" + DiscordPlugin.GameRoles.stream().collect(Collectors.joining("\n")));
|
"List of game roles:\n" + DiscordPlugin.GameRoles.stream().collect(Collectors.joining("\n")));
|
||||||
} else if (argsa[0].equalsIgnoreCase("addrole")) {
|
} else if (argsa[0].equalsIgnoreCase("addrole")) {
|
||||||
if (!message.getAuthor().getRolesForGuild(DiscordPlugin.mainServer).stream()
|
if (!message.getAuthor().getRolesForGuild(DiscordPlugin.mainServer).stream()
|
||||||
.anyMatch(r -> r.getName().equals("Moderator"))) {
|
.anyMatch(r -> r.getID().equals("126030201472811008"))) {
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||||
"You need to be a moderator to use this command.");
|
"You need to be a moderator to use this command.");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -7,7 +7,7 @@ import buttondevteam.lib.TBMCDebugMessageEvent;
|
||||||
|
|
||||||
public class DebugMessageListener implements Listener{
|
public class DebugMessageListener implements Listener{
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onException(TBMCDebugMessageEvent e) {
|
public void onDebugMessage(TBMCDebugMessageEvent e) {
|
||||||
SendMessage(e.getDebugMessage());
|
SendMessage(e.getDebugMessage());
|
||||||
e.setSent();
|
e.setSent();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,13 +8,19 @@ import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.event.server.ServerCommandEvent;
|
import org.bukkit.event.server.ServerCommandEvent;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.CommandSource;
|
||||||
|
|
||||||
import buttondevteam.discordplugin.DiscordPlayer;
|
import buttondevteam.discordplugin.DiscordPlayer;
|
||||||
import buttondevteam.discordplugin.DiscordPlugin;
|
import buttondevteam.discordplugin.DiscordPlugin;
|
||||||
import buttondevteam.discordplugin.commands.ConnectCommand;
|
import buttondevteam.discordplugin.commands.ConnectCommand;
|
||||||
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import buttondevteam.lib.player.*;
|
import buttondevteam.lib.player.*;
|
||||||
import net.ess3.api.events.*;
|
import net.ess3.api.events.*;
|
||||||
|
import sx.blah.discord.handle.obj.IRole;
|
||||||
import sx.blah.discord.handle.obj.IUser;
|
import sx.blah.discord.handle.obj.IUser;
|
||||||
import sx.blah.discord.handle.obj.Status.StatusType;
|
import sx.blah.discord.handle.obj.Status.StatusType;
|
||||||
|
import sx.blah.discord.util.DiscordException;
|
||||||
|
import sx.blah.discord.util.MissingPermissionsException;
|
||||||
|
|
||||||
public class MCListener implements Listener {
|
public class MCListener implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -43,9 +49,6 @@ public class MCListener implements Listener {
|
||||||
if (DiscordPlugin.SafeMode)
|
if (DiscordPlugin.SafeMode)
|
||||||
return;
|
return;
|
||||||
DiscordPlayer dp = e.getPlayer().getAs(DiscordPlayer.class);
|
DiscordPlayer dp = e.getPlayer().getAs(DiscordPlayer.class);
|
||||||
/*System.out.println("dp: " + dp);
|
|
||||||
if (dp != null)
|
|
||||||
System.out.println("dp.did: " + dp.getDiscordID());*/
|
|
||||||
if (dp == null || dp.getDiscordID() == null || dp.getDiscordID() == "")
|
if (dp == null || dp.getDiscordID() == null || dp.getDiscordID() == "")
|
||||||
return;
|
return;
|
||||||
IUser user = DiscordPlugin.dc.getUserByID(dp.getDiscordID());
|
IUser user = DiscordPlugin.dc.getUserByID(dp.getDiscordID());
|
||||||
|
@ -66,6 +69,8 @@ public class MCListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerAFK(AfkStatusChangeEvent e) {
|
public void onPlayerAFK(AfkStatusChangeEvent e) {
|
||||||
|
if (e.isCancelled())
|
||||||
|
return;
|
||||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
|
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
|
||||||
DiscordPlugin.sanitizeString(e.getAffected().getBase().getDisplayName()) + " is "
|
DiscordPlugin.sanitizeString(e.getAffected().getBase().getDisplayName()) + " is "
|
||||||
+ (e.getValue() ? "now" : "no longer") + " AFK.");
|
+ (e.getValue() ? "now" : "no longer") + " AFK.");
|
||||||
|
@ -76,7 +81,25 @@ public class MCListener implements Listener {
|
||||||
DiscordPlugin.Restart = !e.getCommand().equalsIgnoreCase("stop"); // The variable is always true except if stopped
|
DiscordPlugin.Restart = !e.getCommand().equalsIgnoreCase("stop"); // The variable is always true except if stopped
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
@EventHandler
|
||||||
* @EventHandler public void onPlayerMute(MuteStatusChangeEvent e) { e.getAffected() }
|
public void onPlayerMute(MuteStatusChangeEvent e) {
|
||||||
*/
|
try {
|
||||||
|
DiscordPlugin.perform(() -> {
|
||||||
|
final IRole role = DiscordPlugin.dc.getRoleByID("164090010461667328");
|
||||||
|
final CommandSource source = e.getAffected().getSource();
|
||||||
|
if (!source.isPlayer())
|
||||||
|
return;
|
||||||
|
final IUser user = DiscordPlugin.dc
|
||||||
|
.getUserByID(TBMCPlayerBase.getPlayer(source.getPlayer().getUniqueId(), TBMCPlayer.class)
|
||||||
|
.getAs(DiscordPlayer.class).getDiscordID());
|
||||||
|
if (e.getValue())
|
||||||
|
user.addRole(role);
|
||||||
|
else
|
||||||
|
user.removeRole(role);
|
||||||
|
});
|
||||||
|
} catch (DiscordException | MissingPermissionsException ex) {
|
||||||
|
TBMCCoreAPI.SendException("Failed to give/take Muted role to player " + e.getAffected().getName() + "!",
|
||||||
|
ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,18 @@
|
||||||
package buttondevteam.discordplugin.mccommands;
|
package buttondevteam.discordplugin.mccommands;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import buttondevteam.discordplugin.DiscordPlayer;
|
import buttondevteam.discordplugin.DiscordPlayer;
|
||||||
import buttondevteam.discordplugin.commands.ConnectCommand;
|
import buttondevteam.discordplugin.commands.ConnectCommand;
|
||||||
import buttondevteam.discordplugin.listeners.MCChatListener;
|
import buttondevteam.discordplugin.listeners.MCChatListener;
|
||||||
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import buttondevteam.lib.player.ChromaGamerBase;
|
import buttondevteam.lib.player.ChromaGamerBase;
|
||||||
import buttondevteam.lib.player.TBMCPlayer;
|
import buttondevteam.lib.player.TBMCPlayer;
|
||||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||||
|
|
||||||
|
@CommandClass(modOnly = false, path = "accept")
|
||||||
public class AcceptMCCommand extends DiscordMCCommandBase {
|
public class AcceptMCCommand extends DiscordMCCommandBase {
|
||||||
|
|
||||||
@Override
|
|
||||||
public String GetDiscordCommandPath() {
|
|
||||||
return "accept";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] GetHelpText(String alias) {
|
public String[] GetHelpText(String alias) {
|
||||||
return new String[] { //
|
return new String[] { //
|
||||||
|
@ -28,30 +24,20 @@ public class AcceptMCCommand extends DiscordMCCommandBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean GetModOnly() {
|
public boolean OnCommand(Player player, String alias, String[] args) {
|
||||||
return false;
|
String did = ConnectCommand.WaitingToConnect.get(player.getName());
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean GetPlayerOnly() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
|
||||||
String did = ConnectCommand.WaitingToConnect.get(sender.getName());
|
|
||||||
if (did == null) {
|
if (did == null) {
|
||||||
sender.sendMessage("§cYou don't have a pending connection to Discord.");
|
player.sendMessage("§cYou don't have a pending connection to Discord.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
DiscordPlayer dp = ChromaGamerBase.getUser(did, DiscordPlayer.class);
|
DiscordPlayer dp = ChromaGamerBase.getUser(did, DiscordPlayer.class);
|
||||||
TBMCPlayer mcp = TBMCPlayerBase.getPlayer(((Player) sender).getUniqueId(), TBMCPlayer.class);
|
TBMCPlayer mcp = TBMCPlayerBase.getPlayer(player.getUniqueId(), TBMCPlayer.class);
|
||||||
dp.connectWith(mcp);
|
dp.connectWith(mcp);
|
||||||
dp.save();
|
dp.save();
|
||||||
mcp.save();
|
mcp.save();
|
||||||
ConnectCommand.WaitingToConnect.remove(sender.getName());
|
ConnectCommand.WaitingToConnect.remove(player.getName());
|
||||||
MCChatListener.UnconnectedSenders.remove(did);
|
MCChatListener.UnconnectedSenders.remove(did);
|
||||||
sender.sendMessage("§bAccounts connected.");
|
player.sendMessage("§bAccounts connected.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
package buttondevteam.discordplugin.mccommands;
|
package buttondevteam.discordplugin.mccommands;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import buttondevteam.discordplugin.commands.ConnectCommand;
|
import buttondevteam.discordplugin.commands.ConnectCommand;
|
||||||
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
|
|
||||||
|
@CommandClass(modOnly = false, path = "decline")
|
||||||
public class DeclineMCCommand extends DiscordMCCommandBase {
|
public class DeclineMCCommand extends DiscordMCCommandBase {
|
||||||
|
|
||||||
@Override
|
|
||||||
public String GetDiscordCommandPath() {
|
|
||||||
return "decline";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] GetHelpText(String alias) {
|
public String[] GetHelpText(String alias) {
|
||||||
return new String[] { //
|
return new String[] { //
|
||||||
|
@ -21,23 +19,13 @@ public class DeclineMCCommand extends DiscordMCCommandBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean GetModOnly() {
|
public boolean OnCommand(Player player, String alias, String[] args) {
|
||||||
return false;
|
String did = ConnectCommand.WaitingToConnect.remove(player.getName());
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean GetPlayerOnly() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
|
||||||
String did = ConnectCommand.WaitingToConnect.remove(sender.getName());
|
|
||||||
if (did == null) {
|
if (did == null) {
|
||||||
sender.sendMessage("§cYou don't have a pending connection to Discord.");
|
player.sendMessage("§cYou don't have a pending connection to Discord.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
sender.sendMessage("§bPending connection declined.");
|
player.sendMessage("§bPending connection declined.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,9 @@
|
||||||
package buttondevteam.discordplugin.mccommands;
|
package buttondevteam.discordplugin.mccommands;
|
||||||
|
|
||||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
|
import buttondevteam.lib.chat.PlayerCommandBase;
|
||||||
|
|
||||||
public abstract class DiscordMCCommandBase extends TBMCCommandBase {
|
@CommandClass(modOnly = false, path = "discord")
|
||||||
|
public abstract class DiscordMCCommandBase extends PlayerCommandBase {
|
||||||
@Override
|
|
||||||
public String GetCommandPath() {
|
|
||||||
return "discord " + GetDiscordCommandPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract String GetDiscordCommandPath();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue