feat: wrapped init and dispose player ctx by try-catch blocks

This commit is contained in:
Andrey Terentev 2025-03-09 22:58:36 +07:00
parent c6b6217588
commit dc0f628a0d
2 changed files with 7 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import net.minestom.server.entity.Player;
import net.minestom.server.network.player.GameProfile; import net.minestom.server.network.player.GameProfile;
import net.minestom.server.network.player.PlayerConnection; import net.minestom.server.network.player.PlayerConnection;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import ru.dragonestia.msb3.api.util.UncheckedRunnable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -30,7 +31,7 @@ public class MsbPlayer extends Player {
var ctxKey = entry.getKey(); var ctxKey = entry.getKey();
var ctx = entry.getValue(); var ctx = entry.getValue();
ctx.init(); UncheckedRunnable.runIgnoreException(ctx::init);
} }
} }
@ -39,7 +40,7 @@ public class MsbPlayer extends Player {
var ctxKey = entry.getKey(); var ctxKey = entry.getKey();
var ctx = entry.getValue(); var ctx = entry.getValue();
ctx.dispose(); UncheckedRunnable.runIgnoreException(ctx::dispose);
} }
} }
} }

View File

@ -14,4 +14,8 @@ public interface UncheckedRunnable extends Runnable {
} }
void runUnchecked() throws Exception; void runUnchecked() throws Exception;
static void runIgnoreException(UncheckedRunnable runnable) {
runnable.run();
}
} }