Skip to content
This repository has been archived by the owner on Jun 22, 2024. It is now read-only.

Commit

Permalink
Fixes exhaustion when loading large profiles (Slimefun#4127)
Browse files Browse the repository at this point in the history
  • Loading branch information
WalshyDev committed Feb 19, 2024
1 parent 2aa1f0c commit c013fad
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main/java/io/github/thebusybiscuit/slimefun4/Threads.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.thebusybiscuit.slimefun4;

import javax.annotation.ParametersAreNonnullByDefault;

import org.bukkit.plugin.java.JavaPlugin;

public class Threads {

@ParametersAreNonnullByDefault
public static void newThread(JavaPlugin plugin, String name, Runnable runnable) {
// TODO: Change to thread pool
new Thread(runnable, plugin.getName() + " - " + name).start();
}

public static String getCaller() {
// First item will be getting the call stack
// Second item will be this call
// Third item will be the func we care about being called
// And finally will be the caller
StackTraceElement element = Thread.currentThread().getStackTrace()[3];
return element.getClassName() + "." + element.getMethodName() + ":" + element.getLineNumber();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.github.bakedlibs.dough.common.ChatColors;
import io.github.bakedlibs.dough.common.CommonPatterns;
import io.github.bakedlibs.dough.config.Config;
import io.github.thebusybiscuit.slimefun4.Threads;
import io.github.thebusybiscuit.slimefun4.api.events.AsyncProfileLoadEvent;
import io.github.thebusybiscuit.slimefun4.api.gps.Waypoint;
import io.github.thebusybiscuit.slimefun4.api.items.HashedArmorpiece;
Expand Down Expand Up @@ -394,6 +395,7 @@ public static boolean get(@Nonnull OfflinePlayer p, @Nonnull Consumer<PlayerProf
loading.put(uuid, true);
Slimefun.getThreadService().newThread(Slimefun.instance(), "PlayerProfile#get(" + uuid + ")", () -> {
PlayerData data = Slimefun.getPlayerStorage().loadPlayerData(p.getUniqueId());
loading.remove(uuid);

AsyncProfileLoadEvent event = new AsyncProfileLoadEvent(new PlayerProfile(p, data));
Bukkit.getPluginManager().callEvent(event);
Expand Down

0 comments on commit c013fad

Please sign in to comment.