Added mute support and other stuff

This commit is contained in:
Norbi Peti 2017-04-28 17:52:01 +02:00
parent d842891618
commit 1ba108fb21
6 changed files with 51 additions and 59 deletions

View file

@ -50,7 +50,7 @@ public class RoleCommand extends DiscordCommandBase {
"List of game roles:\n" + DiscordPlugin.GameRoles.stream().collect(Collectors.joining("\n")));
} else if (argsa[0].equalsIgnoreCase("addrole")) {
if (!message.getAuthor().getRolesForGuild(DiscordPlugin.mainServer).stream()
.anyMatch(r -> r.getName().equals("Moderator"))) {
.anyMatch(r -> r.getID().equals("126030201472811008"))) {
DiscordPlugin.sendMessageToChannel(message.getChannel(),
"You need to be a moderator to use this command.");
return;

View file

@ -7,7 +7,7 @@ import buttondevteam.lib.TBMCDebugMessageEvent;
public class DebugMessageListener implements Listener{
@EventHandler
public void onException(TBMCDebugMessageEvent e) {
public void onDebugMessage(TBMCDebugMessageEvent e) {
SendMessage(e.getDebugMessage());
e.setSent();
}

View file

@ -8,13 +8,19 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.server.ServerCommandEvent;
import com.earth2me.essentials.CommandSource;
import buttondevteam.discordplugin.DiscordPlayer;
import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.discordplugin.commands.ConnectCommand;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.player.*;
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.Status.StatusType;
import sx.blah.discord.util.DiscordException;
import sx.blah.discord.util.MissingPermissionsException;
public class MCListener implements Listener {
@EventHandler
@ -43,9 +49,6 @@ public class MCListener implements Listener {
if (DiscordPlugin.SafeMode)
return;
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() == "")
return;
IUser user = DiscordPlugin.dc.getUserByID(dp.getDiscordID());
@ -66,6 +69,8 @@ public class MCListener implements Listener {
@EventHandler
public void onPlayerAFK(AfkStatusChangeEvent e) {
if (e.isCancelled())
return;
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
DiscordPlugin.sanitizeString(e.getAffected().getBase().getDisplayName()) + " is "
+ (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
}
/*
* @EventHandler public void onPlayerMute(MuteStatusChangeEvent e) { e.getAffected() }
*/
@EventHandler
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);
}
}
}

View file

@ -1,22 +1,18 @@
package buttondevteam.discordplugin.mccommands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import buttondevteam.discordplugin.DiscordPlayer;
import buttondevteam.discordplugin.commands.ConnectCommand;
import buttondevteam.discordplugin.listeners.MCChatListener;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.player.ChromaGamerBase;
import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.TBMCPlayerBase;
@CommandClass(modOnly = false, path = "accept")
public class AcceptMCCommand extends DiscordMCCommandBase {
@Override
public String GetDiscordCommandPath() {
return "accept";
}
@Override
public String[] GetHelpText(String alias) {
return new String[] { //
@ -28,30 +24,20 @@ public class AcceptMCCommand extends DiscordMCCommandBase {
}
@Override
public boolean GetModOnly() {
return false;
}
@Override
public boolean GetPlayerOnly() {
return true;
}
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
String did = ConnectCommand.WaitingToConnect.get(sender.getName());
public boolean OnCommand(Player player, String alias, String[] args) {
String did = ConnectCommand.WaitingToConnect.get(player.getName());
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;
}
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.save();
mcp.save();
ConnectCommand.WaitingToConnect.remove(sender.getName());
ConnectCommand.WaitingToConnect.remove(player.getName());
MCChatListener.UnconnectedSenders.remove(did);
sender.sendMessage("§bAccounts connected.");
player.sendMessage("§bAccounts connected.");
return true;
}

View file

@ -1,15 +1,13 @@
package buttondevteam.discordplugin.mccommands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import buttondevteam.discordplugin.commands.ConnectCommand;
import buttondevteam.lib.chat.CommandClass;
@CommandClass(modOnly = false, path = "decline")
public class DeclineMCCommand extends DiscordMCCommandBase {
@Override
public String GetDiscordCommandPath() {
return "decline";
}
@Override
public String[] GetHelpText(String alias) {
return new String[] { //
@ -21,23 +19,13 @@ public class DeclineMCCommand extends DiscordMCCommandBase {
}
@Override
public boolean GetModOnly() {
return false;
}
@Override
public boolean GetPlayerOnly() {
return true;
}
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
String did = ConnectCommand.WaitingToConnect.remove(sender.getName());
public boolean OnCommand(Player player, String alias, String[] args) {
String did = ConnectCommand.WaitingToConnect.remove(player.getName());
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;
}
sender.sendMessage("§bPending connection declined.");
player.sendMessage("§bPending connection declined.");
return true;
}

View file

@ -1,14 +1,9 @@
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 {
@Override
public String GetCommandPath() {
return "discord " + GetDiscordCommandPath();
}
public abstract String GetDiscordCommandPath();
@CommandClass(modOnly = false, path = "discord")
public abstract class DiscordMCCommandBase extends PlayerCommandBase {
}