Compare commits

...

9 Commits

Author SHA1 Message Date
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
3 changed files with 39 additions and 13 deletions

View File

@@ -4,7 +4,7 @@
<groupId>com.massivecraft</groupId>
<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.1-BETA</version>
<packaging>jar</packaging>
<name>SaberFactions</name>
@@ -383,10 +383,9 @@
</dependency>
<dependency>
<groupId>com.jagrosh</groupId>
<artifactId>jda-utilities</artifactId>
<artifactId>jda-utilities-commons</artifactId>
<version>2.1</version>
<scope>compile</scope>
<type>pom</type>
</dependency>
</dependencies>

View File

@@ -16,7 +16,6 @@ import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.attribute.FileAttribute;
import java.text.DecimalFormat;
import java.util.List;
import java.util.*;
@@ -37,27 +36,30 @@ public class DiscordListener extends ListenerAdapter {
private static JSONGuilds loadGuilds() {
try {
if (!DiscordListener.file.exists()) {
Files.createFile(DiscordListener.file.toPath(), (FileAttribute<?>[]) new FileAttribute[0]);
Files.write(DiscordListener.file.toPath(), "{}".getBytes());
}
return FactionsPlugin.getInstance().gson.fromJson(String.join("\n", Files.readAllLines(DiscordListener.file.toPath())), JSONGuilds.class);
if (file.exists())
return FactionsPlugin.getInstance().gson.fromJson(String.join("\n", Files.readAllLines(file.toPath())), JSONGuilds.class);
Files.createFile(file.toPath());
Files.write(file.toPath(), "{}".getBytes());
return FactionsPlugin.getInstance().gson.fromJson(String.join("\n", Files.readAllLines(file.toPath())), JSONGuilds.class);
} catch (IOException e) {
e.printStackTrace();
throw new NullPointerException();
}
}
public static void saveGuilds() {
try {
String content = FactionsPlugin.getInstance().gson.toJson(DiscordListener.guilds);
Files.write(DiscordListener.file.toPath(), content.getBytes());
} catch (IOException e) {
String content = FactionsPlugin.getInstance().gson.toJson(guilds);
Files.write(file.toPath(), content.getBytes());
}
catch (IOException e) {
e.printStackTrace();
throw new NullPointerException();
}
}
public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
try {
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);
Faction guildFaction = this.getFaction(event.getGuild());
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();
}

View File

@@ -11,6 +11,7 @@ import net.dv8tion.jda.core.JDABuilder;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Message;
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.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
@@ -21,6 +22,7 @@ import org.bukkit.ChatColor;
import javax.security.auth.login.LoginException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
@@ -48,6 +50,7 @@ public class FactionChatHandler extends ListenerAdapter {
public static void sendMessage(FactionsPlugin plugin, Faction faction, UUID uuid, String username, String message) {
String factionsChatChannelId = faction.getFactionChatChannelId();
String messageWithMentions = null;
if (factionsChatChannelId == null || factionsChatChannelId.isEmpty()) {
return;
}
@@ -69,6 +72,28 @@ public class FactionChatHandler extends ListenerAdapter {
} else {
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();
webhookClient.send(webhookMessage).join();
webhookClient.close();