Compare commits
11 Commits
2.0.0-BETA
...
2.0.2-BETA
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10f06baadc | ||
|
|
07fa138d58 | ||
|
|
abf5c45053 | ||
|
|
a1f527346a | ||
|
|
8a4478764f | ||
|
|
8b70947d03 | ||
|
|
58b25c726f | ||
|
|
22ed86b4d8 | ||
|
|
ed9b2419a6 | ||
|
|
90d9486165 | ||
|
|
c2ac4a6517 |
5
pom.xml
5
pom.xml
@@ -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.2-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>
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ public class Conf {
|
||||
public static boolean worldGuardChecking = false;
|
||||
public static boolean worldGuardBuildPriority = false;
|
||||
//DISCORD
|
||||
public static boolean useDiscordSystem = true;
|
||||
public static boolean useDiscordSystem = false;
|
||||
public static String discordBotToken = "<token here>";
|
||||
public static String fromDiscordFactionChatPrefix = "&f[&dDiscord&f] ";
|
||||
public static String avatarUrl = "http://cravatar.eu/helmavatar/%uuid%.png";
|
||||
|
||||
@@ -261,6 +261,8 @@ public class FactionsPlugin extends MPlugin {
|
||||
}
|
||||
if(Conf.useDiscordSystem) {
|
||||
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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -38,9 +40,6 @@ public class FactionChatHandler extends ListenerAdapter {
|
||||
private void startBot() {
|
||||
try {
|
||||
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) {
|
||||
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) {
|
||||
String factionsChatChannelId = faction.getFactionChatChannelId();
|
||||
String messageWithMentions = null;
|
||||
if (factionsChatChannelId == null || factionsChatChannelId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@@ -69,6 +69,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();
|
||||
|
||||
Reference in New Issue
Block a user