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

@@ -20,6 +20,8 @@ import com.massivecraft.factions.cmd.roles.CmdDemote;
import com.massivecraft.factions.cmd.roles.CmdPromote;
import com.massivecraft.factions.cmd.tnt.CmdTnt;
import com.massivecraft.factions.cmd.tnt.CmdTntFill;
import com.massivecraft.factions.discord.CmdInviteBot;
import com.massivecraft.factions.discord.CmdSetGuild;
import com.massivecraft.factions.missions.CmdMissions;
import com.massivecraft.factions.shop.CmdShop;
import com.massivecraft.factions.zcore.util.TL;
@@ -149,6 +151,8 @@ public class FCmdRoot extends FCommand implements CommandExecutor {
public CmdSpawnerLock cmdSpawnerLock = new CmdSpawnerLock();
public CmdSetDiscord cmdSetDiscord = new CmdSetDiscord();
public CmdSeeDiscord cmdSeeDiscord = new CmdSeeDiscord();
public CmdInviteBot cmdInviteBot = new CmdInviteBot();
public CmdSetGuild cmdSetGuild = new CmdSetGuild();
public FCmdRoot() {
super();
@@ -260,6 +264,11 @@ public class FCmdRoot extends FCommand implements CommandExecutor {
this.addSubCommand(this.cmdConvertConfig);
this.addSubCommand(this.cmdSpawnerLock);
if(Conf.useDiscordSystem){
this.addSubCommand(this.cmdInviteBot);
this.addSubCommand(this.cmdSetGuild);
}
if (Conf.useCheckSystem) {
this.addSubCommand(this.cmdCheck);
this.addSubCommand(this.cmdWeeWoo);

View File

@@ -5,10 +5,18 @@ import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.discord.FactionChatHandler;
import com.massivecraft.factions.zcore.util.TL;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.MessageBuilder;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.MessageEmbed;
import net.dv8tion.jda.core.entities.TextChannel;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -68,6 +76,29 @@ public class CheckTask implements Runnable {
CheckTask.wallChecks.add(faction.getId());
}
faction.msg(TL.CHECK_WALLS_CHECK);
String channelId = faction.getWallNotifyChannelId();
if (channelId == null) {
continue;
}
if (channelId.isEmpty()) {
continue;
}
TextChannel textChannel = FactionChatHandler.jda.getTextChannelById(channelId);
if (textChannel == null) {
continue;
}
if (!textChannel.getGuild().getSelfMember().hasPermission(textChannel, Permission.MESSAGE_READ, Permission.MESSAGE_WRITE)) {
textChannel.getGuild().getOwner().getUser().openPrivateChannel().queue(privateChannel -> privateChannel.sendMessage((":x: Missing read/write in " + textChannel.getAsMention())).queue());
} else {
String format = faction.getNotifyFormat();
if (format == null || format.isEmpty()) {
format = "@everyone, check %type%";
}
format = format.replace("%type%", "walls");
MessageEmbed embed = new EmbedBuilder().setColor(Color.WHITE).setFooter(this.simpleDateFormat.format(new Date(currentTime)), null).build();
textChannel.sendMessage(new MessageBuilder(embed).setContent(format).build()).queue();
}
}
@@ -91,8 +122,29 @@ public class CheckTask implements Runnable {
CheckTask.bufferChecks.add(faction.getId());
}
faction.msg(TL.CHECK_BUFFERS_CHECK);
String channelId = faction.getBufferNotifyChannelId();
if (channelId == null) {
continue;
}
if (channelId.isEmpty()) {
continue;
}
TextChannel textChannel = FactionChatHandler.jda.getTextChannelById(channelId);
if (textChannel == null) {
continue;
}
if (!textChannel.getGuild().getSelfMember().hasPermission(textChannel, Permission.MESSAGE_READ, Permission.MESSAGE_WRITE)) {
textChannel.getGuild().getOwner().getUser().openPrivateChannel().queue(privateChannel -> privateChannel.sendMessage((":x: Missing read/write in " + textChannel.getAsMention())).queue());
} else {
String format = faction.getNotifyFormat();
if (format == null || format.isEmpty()) {
format = "@everyone, check %type%";
}
format = format.replace("%type%", "buffers");
MessageEmbed embed = new EmbedBuilder().setColor(Color.WHITE).setFooter(this.simpleDateFormat.format(new Date(currentTime)), null).build();
textChannel.sendMessage(new MessageBuilder(embed).setContent(format).build()).queue();
}
}
}
}

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)) {

View File

@@ -1,10 +1,14 @@
package com.massivecraft.factions.cmd.check;
import com.massivecraft.factions.Conf;
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.zcore.util.TL;
import net.dv8tion.jda.core.entities.Channel;
import net.dv8tion.jda.core.entities.TextChannel;
public class CmdWeeWoo extends FCommand {
public CmdWeeWoo() {
@@ -30,7 +34,19 @@ public class CmdWeeWoo extends FCommand {
}
context.faction.setWeeWoo(true);
context.msg(TL.COMMAND_WEEWOO_STARTED, context.fPlayer.getNameAndTag());
if (!Conf.useDiscordSystem) return;
String discordChannelId = context.faction.getWeeWooChannelId();
if (discordChannelId != null && !discordChannelId.isEmpty()) {
TextChannel textChannel = FactionChatHandler.jda.getTextChannelById(discordChannelId);
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;
}
textChannel.sendMessage(TL.WEEWOO_STARTED_DISCORD.format(context.fPlayer.getNameAndTag())).queue();
}
} else if (argument.equalsIgnoreCase("stop")) {
if (!weewoo) {
context.msg(TL.COMMAND_WEEWOO_ALREADY_STOPPED);
@@ -38,6 +54,19 @@ public class CmdWeeWoo extends FCommand {
}
context.faction.setWeeWoo(false);
context.msg(TL.COMMAND_WEEWOO_STOPPED, context.fPlayer.getNameAndTag());
if(!Conf.useDiscordSystem) return;
String discordChannelId = context.faction.getWeeWooChannelId();
if (discordChannelId != null && !discordChannelId.isEmpty()) {
TextChannel textChannel = FactionChatHandler.jda.getTextChannelById(discordChannelId);
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;
}
textChannel.sendMessage(TL.WEEWOO_STOPPED_DISCORD.format(context.fPlayer.getNameAndTag())).queue();
}
} else {
context.msg("/f weewoo <start/stop>");
}

View File

@@ -3,7 +3,11 @@ package com.massivecraft.factions.cmd.check;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.discord.FactionChatHandler;
import com.massivecraft.factions.zcore.util.TL;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.TextChannel;
public class WeeWooTask implements Runnable {
@@ -20,6 +24,26 @@ public class WeeWooTask implements Runnable {
continue;
}
faction.msg(TL.WEE_WOO_MESSAGE);
if (!FactionChatHandler.jda.getStatus().equals(JDA.Status.CONNECTED)) {
continue;
}
String discordChannelId = faction.getWeeWooChannelId();
if (discordChannelId == null || discordChannelId.isEmpty()) {
continue;
}
TextChannel textChannel = FactionChatHandler.jda.getTextChannelById(discordChannelId);
if (textChannel == null) {
continue;
}
if (!textChannel.getGuild().getSelfMember().hasPermission(textChannel, Permission.MESSAGE_READ, Permission.MESSAGE_WRITE)) {
textChannel.getGuild().getOwner().getUser().openPrivateChannel().queue(privateChannel -> privateChannel.sendMessage((":x: Missing read/write in " + textChannel.getAsMention())).queue());
} else {
String format = faction.getWeeWooFormat();
if (format == null || format.isEmpty()) {
format = "@everyone, we're being raided! Get online!";
}
textChannel.sendMessage(format).queue();
}
}
}
}