Fixed NPE on Guild loading
This commit is contained in:
parent
8a4478764f
commit
a1f527346a
@ -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()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user