Discord Integration AKA Changing Factions Forever

This commit is contained in:
Driftay
2019-09-29 04:39:30 -04:00
parent 0b1add2a3e
commit 3998a346b4
20 changed files with 1139 additions and 6 deletions

View File

@@ -1,17 +1,25 @@
package com.massivecraft.factions.cmd.check;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.cmd.CommandContext;
import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.discord.FactionChatHandler;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.entities.Channel;
import net.dv8tion.jda.core.entities.MessageEmbed;
import net.dv8tion.jda.core.entities.TextChannel;
import org.bukkit.OfflinePlayer;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@@ -76,6 +84,21 @@ public class CmdCheck extends FCommand {
}
context.faction.getChecks().put(currentTime, "U" + context.fPlayer.getNameAndTag());
context.msg(TL.CHECK_WALLS_MARKED_CHECKED);
if (!Conf.useDiscordSystem) return;
String channelId = context.faction.getWallNotifyChannelId();
if (channelId == null || channelId.isEmpty()) {
return;
}
TextChannel textChannel = FactionChatHandler.jda.getTextChannelById(channelId);
if (textChannel == null) {
return;
}
if (!textChannel.getGuild().getSelfMember().hasPermission(textChannel, net.dv8tion.jda.core.Permission.MESSAGE_READ, net.dv8tion.jda.core.Permission.MESSAGE_WRITE)) {
textChannel.getGuild().getOwner().getUser().openPrivateChannel().queue(privateChannel -> privateChannel.sendMessage((":x: Missing read/write in " + textChannel.getAsMention())).queue());
return;
}
MessageEmbed embed = new EmbedBuilder().setColor(Color.MAGENTA).setTitle("Walls checked by " + context.fPlayer.getNameAndTag()).setFooter(simpleDateFormat.format(new Date(currentTime)), null).build();
textChannel.sendMessage(embed).queue();
}
} else if (subCommand.equalsIgnoreCase("buffers")) {
if (!CheckTask.bufferCheck(context.faction.getId())) {
@@ -93,6 +116,21 @@ public class CmdCheck extends FCommand {
}
context.faction.getChecks().put(System.currentTimeMillis(), "Y" + context.fPlayer.getNameAndTag());
context.msg(TL.CHECK_BUFFERS_MARKED_CHECKED);
if (!Conf.useDiscordSystem) return;
String channelId = context.faction.getBufferNotifyChannelId();
if (channelId == null || channelId.isEmpty()) {
return;
}
TextChannel textChannel = FactionChatHandler.jda.getTextChannelById(channelId);
if (textChannel == null) {
return;
}
if (!textChannel.getGuild().getSelfMember().hasPermission(textChannel, net.dv8tion.jda.core.Permission.MESSAGE_READ, net.dv8tion.jda.core.Permission.MESSAGE_WRITE)) {
textChannel.getGuild().getOwner().getUser().openPrivateChannel().queue(privateChannel -> privateChannel.sendMessage((":x: Missing read/write in " + textChannel.getAsMention())).queue());
return;
}
MessageEmbed embed = new EmbedBuilder().setColor(Color.MAGENTA).setTitle("Buffers checked by " + context.fPlayer.getNameAndTag()).setFooter(simpleDateFormat.format(new Date(currentTime)), null).build();
textChannel.sendMessage(embed).queue();
}
} else if (subCommand.equalsIgnoreCase("settings")) {
if (!context.fPlayer.getRole().isAtLeast(Role.COLEADER)) {