probably broke something

This commit is contained in:
ZeroEpoch1969 2019-11-28 02:08:36 -07:00
parent 60c46b7c8e
commit 4ca89c6bf2
No known key found for this signature in database
GPG Key ID: A7BAB4E14F089CF3
8 changed files with 103 additions and 33 deletions

1
.idea/compiler.xml generated
View File

@ -7,6 +7,7 @@
<sourceOutputDir name="target/generated-sources/annotations" /> <sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" /> <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" /> <outputRelativeToContentRoot value="true" />
<module name="totalfreedom" />
</profile> </profile>
</annotationProcessing> </annotationProcessing>
<bytecodeTargetLevel> <bytecodeTargetLevel>

2
.idea/modules.xml generated
View File

@ -2,7 +2,7 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/TotalFreedomMod.iml" filepath="$PROJECT_DIR$/TotalFreedomMod.iml" /> <module fileurl="file://$PROJECT_DIR$/totalfreedom.iml" filepath="$PROJECT_DIR$/totalfreedom.iml" />
</modules> </modules>
</component> </component>
</project> </project>

View File

@ -170,7 +170,7 @@
<dependency> <dependency>
<groupId>net.dv8tion</groupId> <groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId> <artifactId>JDA</artifactId>
<version>3.8.0_423</version> <version>4.0.0_39</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

View File

@ -130,6 +130,9 @@ public class ChatManager extends FreedomService
// Set format // Set format
event.setFormat(format); event.setFormat(format);
// Send to discord
plugin.dc.messageChatChannel(player.getName() + " \u00BB " + ChatColor.stripColor(message));
} }
public ChatColor getColor(Admin admin, Displayable display) public ChatColor getColor(Admin admin, Displayable display)

View File

@ -56,6 +56,7 @@ public enum ConfigEntry
// //
DISCORD_TOKEN(String.class, "discord.token"), DISCORD_TOKEN(String.class, "discord.token"),
DISCORD_REPORT_CHANNEL_ID(String.class, "discord.report_channel_id"), DISCORD_REPORT_CHANNEL_ID(String.class, "discord.report_channel_id"),
DISCORD_CHAT_CHANNEL_ID(String.class, "discord.chat_channel_id"),
DISCORD_ROLE_SYNC(Boolean.class, "discord.role_sync"), DISCORD_ROLE_SYNC(Boolean.class, "discord.role_sync"),
DISCORD_SERVER_ID(String.class, "discord.server_id"), DISCORD_SERVER_ID(String.class, "discord.server_id"),
DISCORD_MASTER_BUILDER_ROLE_ID(String.class, "discord.master_builder_role_id"), DISCORD_MASTER_BUILDER_ROLE_ID(String.class, "discord.master_builder_role_id"),
@ -63,6 +64,7 @@ public enum ConfigEntry
DISCORD_TELNET_ROLE_ID(String.class, "discord.telnet_role_id"), DISCORD_TELNET_ROLE_ID(String.class, "discord.telnet_role_id"),
DISCORD_SENIOR_ROLE_ID(String.class, "discord.senior_role_id"), DISCORD_SENIOR_ROLE_ID(String.class, "discord.senior_role_id"),
DISCORD_DEVELOPER_ROLE_ID(String.class, "discord.developer_role_id"), DISCORD_DEVELOPER_ROLE_ID(String.class, "discord.developer_role_id"),
DISCORD_ASSISTANT_EXECUTIVE_ROLE_ID(String.class, "discord.assistant_executive_role_id"),
DISCORD_EXECUTIVE_ROLE_ID(String.class, "discord.executive_role_id"), DISCORD_EXECUTIVE_ROLE_ID(String.class, "discord.executive_role_id"),
DISCORD_SERVER_OWNER_ROLE_ID(String.class, "discord.server_owner_role_id"), DISCORD_SERVER_OWNER_ROLE_ID(String.class, "discord.server_owner_role_id"),
// //

View File

@ -15,18 +15,24 @@ import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.playerverification.VPlayer; import me.totalfreedom.totalfreedommod.playerverification.VPlayer;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
import net.dv8tion.jda.core.AccountType; import net.dv8tion.jda.api.AccountType;
import net.dv8tion.jda.core.EmbedBuilder; import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.core.JDA; import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.core.JDABuilder; import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.core.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.core.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.core.entities.MessageEmbed; import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.core.entities.Role; import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.core.entities.TextChannel; import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.core.managers.GuildController; import net.dv8tion.jda.api.events.ReadyEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.apache.commons.lang.WordUtils; import org.apache.commons.lang.WordUtils;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class Discord extends FreedomService public class Discord extends FreedomService
{ {
@ -57,22 +63,68 @@ public class Discord extends FreedomService
} }
try try
{ {
bot = new JDABuilder(AccountType.BOT).setToken(ConfigEntry.DISCORD_TOKEN.getString()).addEventListener(new PrivateMessageListener()).setAudioEnabled(false).setAutoReconnect(true).buildBlocking();
bot = new JDABuilder(AccountType.BOT)
.setToken(ConfigEntry.DISCORD_TOKEN.getString())
.addEventListeners(new PrivateMessageListener())
.addEventListeners(new DiscordToMinecraftListener())
.setAutoReconnect(true)
.addEventListeners(new ListenerAdapter()
{
@Override
public void onReady(ReadyEvent event)
{
new StartEvent(event.getJDA()).start();
}
}).build();
FLog.info("Discord verification bot has successfully enabled!"); FLog.info("Discord verification bot has successfully enabled!");
} }
catch (LoginException e) catch (LoginException e)
{ {
FLog.warning("An invalid token for the discord verification bot, the bot will not enable."); FLog.warning("An invalid token for the discord verification bot, the bot will not enable.");
} }
catch (IllegalArgumentException | InterruptedException e) catch (IllegalArgumentException e)
{ {
FLog.warning("Discord verification bot failed to start."); FLog.warning("Discord verification bot failed to start.");
} }
catch (NoClassDefFoundError e) catch (NoClassDefFoundError e)
{ {
FLog.warning("The JDA plugin is not installed, therefore the bot cannot start."); FLog.warning("The JDA plugin is not installed, therefore the bot cannot start.");
FLog.warning("To resolve this error, please download JDA from: https://github.com/TFPatches/Minecraft-JDA/releases"); FLog.warning("To resolve this error, please download the latest JDA from: https://github.com/TFPatches/Minecraft-JDA/releases");
} }
}
// Do no ask why this is here. I spent two hours trying to make a simple thing work
public class StartEvent {
private final JDA api;
public StartEvent(JDA api) {
this.api = api;
}
public void start()
{
messageChatChannel("**Server has started**");
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event)
{
messageChatChannel("**" + event.getPlayer().getName() + " joined the server" + "**");
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerLeave(PlayerQuitEvent event)
{
messageChatChannel("**" + event.getPlayer().getName() + " left the server" + "**");
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerDeath(PlayerDeathEvent event)
{
messageChatChannel("**" + event.getDeathMessage() + "**");
} }
@Override @Override
@ -81,6 +133,15 @@ public class Discord extends FreedomService
startBot(); startBot();
} }
public void messageChatChannel(String message)
{
String chat_channel_id = ConfigEntry.DISCORD_CHAT_CHANNEL_ID.getString();
if (enabled && !chat_channel_id.isEmpty())
{
bot.getTextChannelById(chat_channel_id).sendMessage(message).queue();
}
}
public static String getCodeForAdmin(Admin admin) public static String getCodeForAdmin(Admin admin)
{ {
for (String code : LINK_CODES.keySet()) for (String code : LINK_CODES.keySet())
@ -110,6 +171,7 @@ public class Discord extends FreedomService
{ {
if (bot != null) if (bot != null)
{ {
messageChatChannel("**Server has stopped**");
bot.shutdown(); bot.shutdown();
} }
FLog.info("Discord verification bot has successfully shutdown."); FLog.info("Discord verification bot has successfully shutdown.");
@ -171,8 +233,6 @@ public class Discord extends FreedomService
return false; return false;
} }
GuildController controller = new GuildController(server);
Member member = server.getMemberById(admin.getDiscordID()); Member member = server.getMemberById(admin.getDiscordID());
if (member == null) if (member == null)
{ {
@ -202,15 +262,15 @@ public class Discord extends FreedomService
{ {
if (member.getRoles().contains(superAdminRole)) if (member.getRoles().contains(superAdminRole))
{ {
controller.removeRolesFromMember(member, superAdminRole).complete(); server.removeRoleFromMember(member, superAdminRole).complete();
} }
if (member.getRoles().contains(telnetAdminRole)) if (member.getRoles().contains(telnetAdminRole))
{ {
controller.removeRolesFromMember(member, telnetAdminRole).complete(); server.removeRoleFromMember(member, telnetAdminRole).complete();
} }
if (member.getRoles().contains(seniorAdminRole)) if (member.getRoles().contains(seniorAdminRole))
{ {
controller.removeRolesFromMember(member, seniorAdminRole).complete(); server.removeRoleFromMember(member, seniorAdminRole).complete();
} }
return true; return true;
} }
@ -219,15 +279,15 @@ public class Discord extends FreedomService
{ {
if (!member.getRoles().contains(superAdminRole)) if (!member.getRoles().contains(superAdminRole))
{ {
controller.addRolesToMember(member, superAdminRole).complete(); server.addRoleToMember(member, superAdminRole).complete();
} }
if (member.getRoles().contains(telnetAdminRole)) if (member.getRoles().contains(telnetAdminRole))
{ {
controller.removeRolesFromMember(member, telnetAdminRole).complete(); server.removeRoleFromMember(member, telnetAdminRole).complete();
} }
if (member.getRoles().contains(seniorAdminRole)) if (member.getRoles().contains(seniorAdminRole))
{ {
controller.removeRolesFromMember(member, seniorAdminRole).complete(); server.removeRoleFromMember(member, seniorAdminRole).complete();
} }
return true; return true;
} }
@ -235,15 +295,15 @@ public class Discord extends FreedomService
{ {
if (!member.getRoles().contains(telnetAdminRole)) if (!member.getRoles().contains(telnetAdminRole))
{ {
controller.addRolesToMember(member, telnetAdminRole).complete(); server.addRoleToMember(member, telnetAdminRole).complete();
} }
if (member.getRoles().contains(superAdminRole)) if (member.getRoles().contains(superAdminRole))
{ {
controller.removeRolesFromMember(member, superAdminRole).complete(); server.removeRoleFromMember(member, superAdminRole).complete();
} }
if (member.getRoles().contains(seniorAdminRole)) if (member.getRoles().contains(seniorAdminRole))
{ {
controller.removeRolesFromMember(member, seniorAdminRole).complete(); server.removeRoleFromMember(member, seniorAdminRole).complete();
} }
return true; return true;
} }
@ -251,15 +311,15 @@ public class Discord extends FreedomService
{ {
if (!member.getRoles().contains(seniorAdminRole)) if (!member.getRoles().contains(seniorAdminRole))
{ {
controller.addRolesToMember(member, seniorAdminRole).complete(); server.addRoleToMember(member, seniorAdminRole).complete();
} }
if (member.getRoles().contains(superAdminRole)) if (member.getRoles().contains(superAdminRole))
{ {
controller.removeRolesFromMember(member, superAdminRole).complete(); server.removeRoleFromMember(member, superAdminRole).complete();
} }
if (member.getRoles().contains(telnetAdminRole)) if (member.getRoles().contains(telnetAdminRole))
{ {
controller.removeRolesFromMember(member, telnetAdminRole).complete(); server.removeRoleFromMember(member, telnetAdminRole).complete();
} }
return true; return true;
} }

View File

@ -3,8 +3,8 @@ package me.totalfreedom.totalfreedommod.discord;
import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.playerverification.VPlayer; import me.totalfreedom.totalfreedommod.playerverification.VPlayer;
import net.dv8tion.jda.core.events.message.priv.PrivateMessageReceivedEvent; import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent;
import net.dv8tion.jda.core.hooks.ListenerAdapter; import net.dv8tion.jda.api.hooks.ListenerAdapter;
public class PrivateMessageListener extends ListenerAdapter public class PrivateMessageListener extends ListenerAdapter
{ {
@ -21,7 +21,7 @@ public class PrivateMessageListener extends ListenerAdapter
Admin admin = Discord.LINK_CODES.get(code); Admin admin = Discord.LINK_CODES.get(code);
admin.setDiscordID(event.getMessage().getAuthor().getId()); admin.setDiscordID(event.getMessage().getAuthor().getId());
Discord.LINK_CODES.remove(code); Discord.LINK_CODES.remove(code);
event.getChannel().sendMessage("Link successful. Now this Discord account is linked with the Minecraft account `" + admin.getName() + "`.\n" event.getChannel().sendMessage("Link successful. Now this Discord account is linked with your Minecraft account `" + admin.getName() + "`.\n"
+ "Now when you are an impostor on the server, you may use `/verify` to verify.").complete(); + "Now when you are an impostor on the server, you may use `/verify` to verify.").complete();
Discord.syncRoles(admin); Discord.syncRoles(admin);
} }
@ -33,7 +33,7 @@ public class PrivateMessageListener extends ListenerAdapter
TotalFreedomMod.plugin().pv.saveVerificationData(player); TotalFreedomMod.plugin().pv.saveVerificationData(player);
Discord.PLAYER_LINK_CODES.remove(code); Discord.PLAYER_LINK_CODES.remove(code);
event.getChannel().sendMessage("Link successful. Now this Discord account is linked with the Minecraft account `" + player.getName() + "`.\n" event.getChannel().sendMessage("Link successful. Now this Discord account is linked with your Minecraft account `" + player.getName() + "`.\n"
+ "Now when you are an impostor on the server, you may use `/verify` to verify.").complete(); + "Now when you are an impostor on the server, you may use `/verify` to verify.").complete();
} }
} }

View File

@ -50,6 +50,8 @@ discord:
server_id: '' server_id: ''
# Channel to send /report messages to # Channel to send /report messages to
report_channel_id: '' report_channel_id: ''
# Channel for discord to minecraft and vice-versa
chat_channel_id: ''
# Do you want roles to sync with the server? # Do you want roles to sync with the server?
role_sync: false role_sync: false
# Master Admin role ID # Master Admin role ID
@ -62,6 +64,8 @@ discord:
senior_role_id: '' senior_role_id: ''
# Developer role ID # Developer role ID
developer_role_id: '' developer_role_id: ''
# Assistant Executive Admin role ID
assistant_executive_role_id: ''
# Executive Admin role ID # Executive Admin role ID
executive_role_id: '' executive_role_id: ''
# Owner role ID # Owner role ID