Skip to content

Commit 022d26a

Browse files
authored
Merge pull request #2 from HelpChat/main
2 parents cc4e0df + b3026eb commit 022d26a

File tree

6 files changed

+22
-31
lines changed

6 files changed

+22
-31
lines changed

api/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ plugins {
66
id("com.github.johnrengelman.shadow") version "7.1.2"
77
}
88

9+
repositories {
10+
// adventure snapshot repo
11+
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
12+
}
13+
914
dependencies {
1015
api(libs.adventure.bukkit)
1116
api(libs.adventure.minimessage)

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ spigot = "1.20.1-R0.1-SNAPSHOT"
44

55
# Adventure
66
minimessage = "4.14.0"
7-
adventure-platform = "4.3.0"
7+
adventure-platform = "4.3.2-SNAPSHOT"
88

99
# Other
1010
configurate = "4.1.2"
1111
cmds = "2.0.0-SNAPSHOT"
1212
papi = "2.11.1"
1313
towny = "0.98.1.3"
1414
discordsrv = "1.25.1"
15-
supervanish = "6.2.6-4"
15+
supervanish = "6.2.17"
1616
bstats = "3.0.0"
1717
essentials = "2.19.4"
1818
griefprevention = "16.18.1"

plugin/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ version = "${rootProject.version}-${System.getenv("BUILD_NUMBER")}"
1212
repositories {
1313
papi()
1414
triumphSnapshots()
15+
// adventure snapshot repo
16+
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
1517
// towny
1618
maven("https://repo.glaremasters.me/repository/towny/")
1719
// dsrv + dependencies

plugin/src/main/java/at/helpch/chatchat/data/impl/gson/GsonDatabase.java

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
import org.jetbrains.annotations.NotNull;
1212

1313
import java.io.File;
14-
import java.io.FileInputStream;
15-
import java.io.FileOutputStream;
1614
import java.io.FileReader;
1715
import java.io.FileWriter;
1816
import java.io.IOException;
17+
import java.nio.file.Files;
1918
import java.util.UUID;
2019
import java.util.logging.Level;
2120

@@ -43,6 +42,7 @@ public GsonDatabase(@NotNull final ChatChatPlugin plugin) {
4342
@Override
4443
public @NotNull ChatUser loadChatUser(@NotNull final UUID uuid) {
4544
final var userFile = new File(usersDirectory, uuid + ".json");
45+
4646
if (!userFile.exists()) {
4747
final var user = new ChatUserImpl(uuid);
4848
final var channel = ChatChannel.defaultChannel();
@@ -54,11 +54,12 @@ public GsonDatabase(@NotNull final ChatChatPlugin plugin) {
5454
try(final var reader = new FileReader(userFile)) {
5555
return gson.fromJson(reader, ChatUser.class);
5656
} catch (final JsonParseException exception) { // Handles invalid JSON
57-
plugin.getLogger().warning(
58-
"Something went wrong while trying to load user " + uuid + "!" + System.lineSeparator()
59-
+ "Creating backup at " + uuid + "-backup.json."
60-
);
61-
exception.printStackTrace();
57+
plugin.getLogger()
58+
.log(
59+
Level.WARNING,
60+
String.format("Something went wrong while trying to load user %s!. Creating backup at %1$s-backup.json", uuid),
61+
exception
62+
);
6263

6364
final var backupFile = new File(usersDirectory, uuid + "-backup.json");
6465

@@ -87,7 +88,7 @@ public GsonDatabase(@NotNull final ChatChatPlugin plugin) {
8788

8889
// copy contents of userFile to backupFile
8990
try {
90-
copyFileContents(userFile, backupFile);
91+
Files.copy(userFile.toPath(), backupFile.toPath());
9192
} catch (IOException ioException) {
9293
plugin.getLogger().log(
9394
Level.WARNING,
@@ -148,17 +149,4 @@ public void saveChatUser(@NotNull final ChatUser chatUser) {
148149
}
149150
}
150151

151-
private static void copyFileContents(
152-
@NotNull final File source,
153-
@NotNull final File destination
154-
) throws IOException {
155-
try (final var inStream = new FileInputStream(source); final var outStream = new FileOutputStream(destination)) {
156-
final byte[] buffer = new byte[1024];
157-
158-
int length;
159-
while ((length = inStream.read(buffer)) > 0){
160-
outStream.write(buffer, 0, length);
161-
}
162-
}
163-
}
164152
}

plugin/src/main/java/at/helpch/chatchat/listener/PlayerListener.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import at.helpch.chatchat.ChatChatPlugin;
44
import at.helpch.chatchat.api.user.ChatUser;
5+
import org.bukkit.Bukkit;
56
import org.bukkit.event.EventHandler;
67
import org.bukkit.event.Listener;
78
import org.bukkit.event.player.PlayerJoinEvent;
@@ -18,7 +19,7 @@ public PlayerListener(@NotNull final ChatChatPlugin plugin) {
1819

1920
@EventHandler
2021
private void onJoin(final PlayerJoinEvent event) {
21-
plugin.usersHolder().getUser(event.getPlayer());
22+
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> plugin.usersHolder().getUser(event.getPlayer()));
2223
}
2324

2425
@EventHandler
@@ -32,6 +33,6 @@ private void onLeave(final PlayerQuitEvent event) {
3233
.filter(user -> user.lastMessagedUser().get().player().equals(event.getPlayer()))
3334
.forEach(user -> user.lastMessagedUser(null));
3435

35-
plugin.usersHolder().removeUser(event.getPlayer());
36+
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> plugin.usersHolder().removeUser(event.getPlayer().getUniqueId()));
3637
}
3738
}

plugin/src/main/java/at/helpch/chatchat/user/UsersHolderImpl.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,7 @@ public UsersHolderImpl(@NotNull final ChatChatPlugin plugin) {
4040
}
4141

4242
public void removeUser(@NotNull final UUID uuid) {
43-
if (!users.containsKey(uuid)) {
44-
return;
45-
}
46-
47-
final var user = users.get(uuid);
48-
users.remove(uuid);
43+
final var user = users.remove(uuid);
4944

5045
if (!(user instanceof ChatUser)) {
5146
return;

0 commit comments

Comments
 (0)