This commit is contained in:
ZeroEpoch1969 2019-11-28 02:12:47 -07:00
parent d99e6629c4
commit 0abfb70a42
No known key found for this signature in database
GPG Key ID: A7BAB4E14F089CF3
2 changed files with 86 additions and 1 deletions

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$/totalfreedom.iml" filepath="$PROJECT_DIR$/totalfreedom.iml" /> <module fileurl="file://$PROJECT_DIR$/TotalFreedomMod.iml" filepath="$PROJECT_DIR$/TotalFreedomMod.iml" />
</modules> </modules>
</component> </component>
</project> </project>

View File

@ -0,0 +1,85 @@
package me.totalfreedom.totalfreedommod.discord;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.rank.Title;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.bukkit.ChatColor;
public class DiscordToMinecraftListener extends ListenerAdapter
{
public void onMessageReceived(MessageReceivedEvent event)
{
String chat_channel_id = ConfigEntry.DISCORD_CHAT_CHANNEL_ID.getString();
if (!chat_channel_id.isEmpty() && event.getChannel().getId().equals(chat_channel_id))
{
if (!event.getAuthor().getId().equals(Discord.bot.getSelfUser().getId()))
{
Member member = event.getMember();
String tag = getDisplay(member);
String message = ChatColor.DARK_GRAY + "[" + ChatColor.DARK_AQUA + "Discord" + ChatColor.DARK_GRAY + "]";
if (tag != null)
{
message += " " + tag;
}
message += " " + ChatColor.RED + member.getEffectiveName() + ChatColor.DARK_GRAY + " : " + ChatColor.RESET + event.getMessage().getContentRaw();
FUtil.bcastMsg(message);
}
}
}
public String getDisplay(Member member)
{
Guild server = Discord.bot.getGuildById(ConfigEntry.DISCORD_SERVER_ID.getString());
// Server Owner
if (member.getRoles().contains(server.getRoleById(ConfigEntry.DISCORD_SERVER_OWNER_ROLE_ID.getString())))
{
return Title.OWNER.getColoredTag();
}
// Developers
else if (member.getRoles().contains(server.getRoleById(ConfigEntry.DISCORD_EXECUTIVE_ROLE_ID.getString())))
{
return Title.DEVELOPER.getColoredTag();
}
// Executives
else if (member.getRoles().contains(server.getRoleById(ConfigEntry.DISCORD_EXECUTIVE_ROLE_ID.getString())))
{
return Title.EXECUTIVE.getColoredTag();
}
// Assistant Executives
else if (member.getRoles().contains(server.getRoleById(ConfigEntry.DISCORD_ASSISTANT_EXECUTIVE_ROLE_ID.getString())))
{
return Title.ASSISTANT_EXECUTIVE.getColoredTag();
}
// Senior Admins
else if (member.getRoles().contains(server.getRoleById(ConfigEntry.DISCORD_SENIOR_ROLE_ID.getString())))
{
return Rank.SENIOR_ADMIN.getColoredTag();
}
// Telnet Admins
else if (member.getRoles().contains(server.getRoleById(ConfigEntry.DISCORD_TELNET_ROLE_ID.getString())))
{
return Rank.TELNET_ADMIN.getColoredTag();
}
// Super Admins
else if (member.getRoles().contains(server.getRoleById(ConfigEntry.DISCORD_SUPER_ROLE_ID.getString())))
{
return Rank.SUPER_ADMIN.getColoredTag();
}
// Master Builders
else if (member.getRoles().contains(server.getRoleById(ConfigEntry.DISCORD_MASTER_BUILDER_ROLE_ID.getString())))
{
return Title.MASTER_BUILDER.getColoredTag();
}
// None
else
{
return null;
}
}
}