Compare commits

...

11 Commits

Author SHA1 Message Date
Driftay
10f06baadc Version Change 2019-09-30 16:04:41 -04:00
Driftay
07fa138d58 Disabled Discord Features By Default 2019-09-30 16:03:44 -04:00
Driftay
abf5c45053 Version Change 2019-09-29 18:51:24 -04:00
Driftay
a1f527346a Fixed NPE on Guild loading 2019-09-29 18:45:48 -04:00
Driftay
8a4478764f Merge pull request #19 from DroppingAnvil/1.6.x
You can now mention discord users in game!
2019-09-29 18:45:15 -04:00
DroppingAnvil
8b70947d03 Uncommented something that shouldnt have been 2019-09-29 13:36:37 -05:00
DroppingAnvil
58b25c726f First step to mentions! You can now mention discord users ingame if they have a one word name and there is not someone named the same thing! I plan to make this system much much better soon! 2019-09-29 13:29:23 -05:00
Driftay
22ed86b4d8 Added f points to stats discord command 2019-09-29 08:13:48 -04:00
Driftay
ed9b2419a6 Jar reduced by 200kbs 2019-09-29 07:24:37 -04:00
DroppingAnvil
90d9486165 Merge pull request #7 from Driftay/1.6.x
Merge
2019-09-29 04:16:37 -05:00
DroppingAnvil
c2ac4a6517 Merge from Driftay/1.6.x 2019-09-24 12:07:58 -05:00
5 changed files with 42 additions and 17 deletions

View File

@@ -4,7 +4,7 @@
<groupId>com.massivecraft</groupId> <groupId>com.massivecraft</groupId>
<artifactId>Factions</artifactId> <artifactId>Factions</artifactId>
<version>1.6.9.5-U0.2.1-2.0.0-BETA</version> <version>1.6.9.5-U0.2.1-2.0.2-BETA</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>SaberFactions</name> <name>SaberFactions</name>
@@ -383,10 +383,9 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.jagrosh</groupId> <groupId>com.jagrosh</groupId>
<artifactId>jda-utilities</artifactId> <artifactId>jda-utilities-commons</artifactId>
<version>2.1</version> <version>2.1</version>
<scope>compile</scope> <scope>compile</scope>
<type>pom</type>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -98,7 +98,7 @@ public class Conf {
public static boolean worldGuardChecking = false; public static boolean worldGuardChecking = false;
public static boolean worldGuardBuildPriority = false; public static boolean worldGuardBuildPriority = false;
//DISCORD //DISCORD
public static boolean useDiscordSystem = true; public static boolean useDiscordSystem = false;
public static String discordBotToken = "<token here>"; public static String discordBotToken = "<token here>";
public static String fromDiscordFactionChatPrefix = "&f[&dDiscord&f] "; public static String fromDiscordFactionChatPrefix = "&f[&dDiscord&f] ";
public static String avatarUrl = "http://cravatar.eu/helmavatar/%uuid%.png"; public static String avatarUrl = "http://cravatar.eu/helmavatar/%uuid%.png";

View File

@@ -261,6 +261,8 @@ public class FactionsPlugin extends MPlugin {
} }
if(Conf.useDiscordSystem) { if(Conf.useDiscordSystem) {
new FactionChatHandler(this); new FactionChatHandler(this);
} else {
System.out.println("\n\n\n SABER-FACTIONS-DISCORD-INTEGRATION - You are not using Discord integration features, set conf.json option useDiscordSystem to true and put a valid token in before using!\n\n\n");
} }
ShopConfig.setup(); ShopConfig.setup();

View File

@@ -16,7 +16,6 @@ import java.awt.*;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.attribute.FileAttribute;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.List; import java.util.List;
import java.util.*; import java.util.*;
@@ -37,27 +36,30 @@ public class DiscordListener extends ListenerAdapter {
private static JSONGuilds loadGuilds() { private static JSONGuilds loadGuilds() {
try { try {
if (!DiscordListener.file.exists()) { if (file.exists())
Files.createFile(DiscordListener.file.toPath(), (FileAttribute<?>[]) new FileAttribute[0]); return FactionsPlugin.getInstance().gson.fromJson(String.join("\n", Files.readAllLines(file.toPath())), JSONGuilds.class);
Files.write(DiscordListener.file.toPath(), "{}".getBytes()); Files.createFile(file.toPath());
} Files.write(file.toPath(), "{}".getBytes());
return FactionsPlugin.getInstance().gson.fromJson(String.join("\n", Files.readAllLines(DiscordListener.file.toPath())), JSONGuilds.class); return FactionsPlugin.getInstance().gson.fromJson(String.join("\n", Files.readAllLines(file.toPath())), JSONGuilds.class);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
throw new NullPointerException(); throw new NullPointerException();
} }
} }
public static void saveGuilds() { public static void saveGuilds() {
try { try {
String content = FactionsPlugin.getInstance().gson.toJson(DiscordListener.guilds); String content = FactionsPlugin.getInstance().gson.toJson(guilds);
Files.write(DiscordListener.file.toPath(), content.getBytes()); Files.write(file.toPath(), content.getBytes());
} catch (IOException e) { }
catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
throw new NullPointerException(); throw new NullPointerException();
} }
} }
public void onGuildMessageReceived(GuildMessageReceivedEvent event) { public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
try { try {
if (event.getMessage().isWebhookMessage() || event.getAuthor().isBot()) { if (event.getMessage().isWebhookMessage() || event.getAuthor().isBot()) {
@@ -208,7 +210,7 @@ public class DiscordListener extends ListenerAdapter {
EmbedBuilder embedBuilder = new EmbedBuilder().setColor(Color.MAGENTA).setTitle("Faction Stats").setAuthor(ChatColor.stripColor(faction.getTag())).addField("Description", faction.getDescription(), false).addField("Players Online", String.valueOf(faction.getOnlinePlayers().size()), true).addField("Total players", String.valueOf(faction.getFPlayers().size()), true).addField("Alts", String.valueOf(faction.getAltPlayers().size()), true).addField("Land", String.valueOf(faction.getLandRounded()), true).addField("Power", faction.getPowerRounded() + "/" + faction.getPowerMaxRounded(), true); EmbedBuilder embedBuilder = new EmbedBuilder().setColor(Color.MAGENTA).setTitle("Faction Stats").setAuthor(ChatColor.stripColor(faction.getTag())).addField("Description", faction.getDescription(), false).addField("Players Online", String.valueOf(faction.getOnlinePlayers().size()), true).addField("Total players", String.valueOf(faction.getFPlayers().size()), true).addField("Alts", String.valueOf(faction.getAltPlayers().size()), true).addField("Land", String.valueOf(faction.getLandRounded()), true).addField("Power", faction.getPowerRounded() + "/" + faction.getPowerMaxRounded(), true);
Faction guildFaction = this.getFaction(event.getGuild()); Faction guildFaction = this.getFaction(event.getGuild());
if (guildFaction != null && guildFaction.getId().equals(faction.getId()) && this.canAccessRole(guildFaction, event.getMember())) { if (guildFaction != null && guildFaction.getId().equals(faction.getId()) && this.canAccessRole(guildFaction, event.getMember())) {
embedBuilder.addField("Kills", String.valueOf(faction.getKills()), true).addField("Deaths", String.valueOf(faction.getDeaths()), true); embedBuilder.addField("Kills", String.valueOf(faction.getKills()), true).addField("Points", String.valueOf(faction.getPoints()), true).addField("Deaths", String.valueOf(faction.getDeaths()), true);
} }
event.getChannel().sendMessage(embedBuilder.build()).queue(); event.getChannel().sendMessage(embedBuilder.build()).queue();
} }

View File

@@ -11,6 +11,7 @@ import net.dv8tion.jda.core.JDABuilder;
import net.dv8tion.jda.core.Permission; import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Message; import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.TextChannel; import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.entities.Webhook; import net.dv8tion.jda.core.entities.Webhook;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.core.hooks.ListenerAdapter; import net.dv8tion.jda.core.hooks.ListenerAdapter;
@@ -21,6 +22,7 @@ import org.bukkit.ChatColor;
import javax.security.auth.login.LoginException; import javax.security.auth.login.LoginException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@@ -38,9 +40,6 @@ public class FactionChatHandler extends ListenerAdapter {
private void startBot() { private void startBot() {
try { try {
jda = new JDABuilder(AccountType.BOT).setToken(Conf.discordBotToken).buildBlocking(); jda = new JDABuilder(AccountType.BOT).setToken(Conf.discordBotToken).buildBlocking();
if(jda == null) {
System.out.println("\n\n\n SABER-FACTIONS-DISCORD-INTEGRATION - Please Make a Valid Token To Use Discord Features! Location Conf.json discordBotToken.\n\n\n");
}
} catch (LoginException | InterruptedException e) { } catch (LoginException | InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -48,6 +47,7 @@ public class FactionChatHandler extends ListenerAdapter {
public static void sendMessage(FactionsPlugin plugin, Faction faction, UUID uuid, String username, String message) { public static void sendMessage(FactionsPlugin plugin, Faction faction, UUID uuid, String username, String message) {
String factionsChatChannelId = faction.getFactionChatChannelId(); String factionsChatChannelId = faction.getFactionChatChannelId();
String messageWithMentions = null;
if (factionsChatChannelId == null || factionsChatChannelId.isEmpty()) { if (factionsChatChannelId == null || factionsChatChannelId.isEmpty()) {
return; return;
} }
@@ -69,6 +69,28 @@ public class FactionChatHandler extends ListenerAdapter {
} else { } else {
webhookClient = textChannel.createWebhook(Conf.webhookName).complete().newClient().build(); webhookClient = textChannel.createWebhook(Conf.webhookName).complete().newClient().build();
} }
if (message.contains("@")) {
List<String> x = new ArrayList<>(Arrays.asList(message.split(" ")));
for (String y : x) {
if (y.contains("@")) {
if (!jda.getUsersByName(y.replace("@", ""), false).isEmpty() && jda.getUsersByName(y.replace("@", ""), false).size() < 2) {
x.set(x.indexOf(y), jda.getUsersByName(y.replace("@", ""), false).get(0).getAsMention());
}
}
}
StringBuilder sB = new StringBuilder();
for (String s : x) {
sB.append(s);
sB.append(" ");
}
messageWithMentions = sB.toString();
}
if (messageWithMentions != null) {
WebhookMessage webhookMessage = new WebhookMessageBuilder().setUsername(ChatColor.stripColor(username)).setAvatarUrl(Conf.avatarUrl.replace("%uuid%", uuid.toString())).setContent(ChatColor.stripColor(messageWithMentions)).build();
webhookClient.send(webhookMessage).join();
webhookClient.close();
return;
}
WebhookMessage webhookMessage = new WebhookMessageBuilder().setUsername(ChatColor.stripColor(username)).setAvatarUrl(Conf.avatarUrl.replace("%uuid%", uuid.toString())).setContent(ChatColor.stripColor(message)).build(); WebhookMessage webhookMessage = new WebhookMessageBuilder().setUsername(ChatColor.stripColor(username)).setAvatarUrl(Conf.avatarUrl.replace("%uuid%", uuid.toString())).setContent(ChatColor.stripColor(message)).build();
webhookClient.send(webhookMessage).join(); webhookClient.send(webhookMessage).join();
webhookClient.close(); webhookClient.close();