mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
probably broke something
This commit is contained in:
parent
60c46b7c8e
commit
4ca89c6bf2
1
.idea/compiler.xml
generated
1
.idea/compiler.xml
generated
@ -7,6 +7,7 @@
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="totalfreedom" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
<bytecodeTargetLevel>
|
||||
|
2
.idea/modules.xml
generated
2
.idea/modules.xml
generated
@ -2,7 +2,7 @@
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<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>
|
||||
</component>
|
||||
</project>
|
2
pom.xml
2
pom.xml
@ -170,7 +170,7 @@
|
||||
<dependency>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
<version>3.8.0_423</version>
|
||||
<version>4.0.0_39</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -130,6 +130,9 @@ public class ChatManager extends FreedomService
|
||||
|
||||
// Set format
|
||||
event.setFormat(format);
|
||||
|
||||
// Send to discord
|
||||
plugin.dc.messageChatChannel(player.getName() + " \u00BB " + ChatColor.stripColor(message));
|
||||
}
|
||||
|
||||
public ChatColor getColor(Admin admin, Displayable display)
|
||||
|
@ -56,6 +56,7 @@ public enum ConfigEntry
|
||||
//
|
||||
DISCORD_TOKEN(String.class, "discord.token"),
|
||||
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_SERVER_ID(String.class, "discord.server_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_SENIOR_ROLE_ID(String.class, "discord.senior_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_SERVER_OWNER_ROLE_ID(String.class, "discord.server_owner_role_id"),
|
||||
//
|
||||
|
@ -15,18 +15,24 @@ import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.playerverification.VPlayer;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import net.dv8tion.jda.core.AccountType;
|
||||
import net.dv8tion.jda.core.EmbedBuilder;
|
||||
import net.dv8tion.jda.core.JDA;
|
||||
import net.dv8tion.jda.core.JDABuilder;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.Member;
|
||||
import net.dv8tion.jda.core.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.core.entities.Role;
|
||||
import net.dv8tion.jda.core.entities.TextChannel;
|
||||
import net.dv8tion.jda.core.managers.GuildController;
|
||||
import net.dv8tion.jda.api.AccountType;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.events.ReadyEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
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
|
||||
{
|
||||
@ -57,22 +63,68 @@ public class Discord extends FreedomService
|
||||
}
|
||||
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!");
|
||||
}
|
||||
catch (LoginException e)
|
||||
{
|
||||
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.");
|
||||
}
|
||||
catch (NoClassDefFoundError e)
|
||||
{
|
||||
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
|
||||
@ -81,6 +133,15 @@ public class Discord extends FreedomService
|
||||
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)
|
||||
{
|
||||
for (String code : LINK_CODES.keySet())
|
||||
@ -110,6 +171,7 @@ public class Discord extends FreedomService
|
||||
{
|
||||
if (bot != null)
|
||||
{
|
||||
messageChatChannel("**Server has stopped**");
|
||||
bot.shutdown();
|
||||
}
|
||||
FLog.info("Discord verification bot has successfully shutdown.");
|
||||
@ -171,8 +233,6 @@ public class Discord extends FreedomService
|
||||
return false;
|
||||
}
|
||||
|
||||
GuildController controller = new GuildController(server);
|
||||
|
||||
Member member = server.getMemberById(admin.getDiscordID());
|
||||
if (member == null)
|
||||
{
|
||||
@ -202,15 +262,15 @@ public class Discord extends FreedomService
|
||||
{
|
||||
if (member.getRoles().contains(superAdminRole))
|
||||
{
|
||||
controller.removeRolesFromMember(member, superAdminRole).complete();
|
||||
server.removeRoleFromMember(member, superAdminRole).complete();
|
||||
}
|
||||
if (member.getRoles().contains(telnetAdminRole))
|
||||
{
|
||||
controller.removeRolesFromMember(member, telnetAdminRole).complete();
|
||||
server.removeRoleFromMember(member, telnetAdminRole).complete();
|
||||
}
|
||||
if (member.getRoles().contains(seniorAdminRole))
|
||||
{
|
||||
controller.removeRolesFromMember(member, seniorAdminRole).complete();
|
||||
server.removeRoleFromMember(member, seniorAdminRole).complete();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -219,15 +279,15 @@ public class Discord extends FreedomService
|
||||
{
|
||||
if (!member.getRoles().contains(superAdminRole))
|
||||
{
|
||||
controller.addRolesToMember(member, superAdminRole).complete();
|
||||
server.addRoleToMember(member, superAdminRole).complete();
|
||||
}
|
||||
if (member.getRoles().contains(telnetAdminRole))
|
||||
{
|
||||
controller.removeRolesFromMember(member, telnetAdminRole).complete();
|
||||
server.removeRoleFromMember(member, telnetAdminRole).complete();
|
||||
}
|
||||
if (member.getRoles().contains(seniorAdminRole))
|
||||
{
|
||||
controller.removeRolesFromMember(member, seniorAdminRole).complete();
|
||||
server.removeRoleFromMember(member, seniorAdminRole).complete();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -235,15 +295,15 @@ public class Discord extends FreedomService
|
||||
{
|
||||
if (!member.getRoles().contains(telnetAdminRole))
|
||||
{
|
||||
controller.addRolesToMember(member, telnetAdminRole).complete();
|
||||
server.addRoleToMember(member, telnetAdminRole).complete();
|
||||
}
|
||||
if (member.getRoles().contains(superAdminRole))
|
||||
{
|
||||
controller.removeRolesFromMember(member, superAdminRole).complete();
|
||||
server.removeRoleFromMember(member, superAdminRole).complete();
|
||||
}
|
||||
if (member.getRoles().contains(seniorAdminRole))
|
||||
{
|
||||
controller.removeRolesFromMember(member, seniorAdminRole).complete();
|
||||
server.removeRoleFromMember(member, seniorAdminRole).complete();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -251,15 +311,15 @@ public class Discord extends FreedomService
|
||||
{
|
||||
if (!member.getRoles().contains(seniorAdminRole))
|
||||
{
|
||||
controller.addRolesToMember(member, seniorAdminRole).complete();
|
||||
server.addRoleToMember(member, seniorAdminRole).complete();
|
||||
}
|
||||
if (member.getRoles().contains(superAdminRole))
|
||||
{
|
||||
controller.removeRolesFromMember(member, superAdminRole).complete();
|
||||
server.removeRoleFromMember(member, superAdminRole).complete();
|
||||
}
|
||||
if (member.getRoles().contains(telnetAdminRole))
|
||||
{
|
||||
controller.removeRolesFromMember(member, telnetAdminRole).complete();
|
||||
server.removeRoleFromMember(member, telnetAdminRole).complete();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ package me.totalfreedom.totalfreedommod.discord;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.playerverification.VPlayer;
|
||||
import net.dv8tion.jda.core.events.message.priv.PrivateMessageReceivedEvent;
|
||||
import net.dv8tion.jda.core.hooks.ListenerAdapter;
|
||||
import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
|
||||
public class PrivateMessageListener extends ListenerAdapter
|
||||
{
|
||||
@ -21,7 +21,7 @@ public class PrivateMessageListener extends ListenerAdapter
|
||||
Admin admin = Discord.LINK_CODES.get(code);
|
||||
admin.setDiscordID(event.getMessage().getAuthor().getId());
|
||||
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();
|
||||
Discord.syncRoles(admin);
|
||||
}
|
||||
@ -33,7 +33,7 @@ public class PrivateMessageListener extends ListenerAdapter
|
||||
|
||||
TotalFreedomMod.plugin().pv.saveVerificationData(player);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +50,8 @@ discord:
|
||||
server_id: ''
|
||||
# Channel to send /report messages to
|
||||
report_channel_id: ''
|
||||
# Channel for discord to minecraft and vice-versa
|
||||
chat_channel_id: ''
|
||||
# Do you want roles to sync with the server?
|
||||
role_sync: false
|
||||
# Master Admin role ID
|
||||
@ -62,6 +64,8 @@ discord:
|
||||
senior_role_id: ''
|
||||
# Developer role ID
|
||||
developer_role_id: ''
|
||||
# Assistant Executive Admin role ID
|
||||
assistant_executive_role_id: ''
|
||||
# Executive Admin role ID
|
||||
executive_role_id: ''
|
||||
# Owner role ID
|
||||
|
Loading…
Reference in New Issue
Block a user