Skip to content

Commit

Permalink
Fix exception on Folia and specify Accept header
Browse files Browse the repository at this point in the history
Fixes #49
  • Loading branch information
MrMicky-FR committed Sep 15, 2024
1 parent 5414bdf commit 2c93016
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
allprojects {
group 'com.azuriom'
version '1.3.6'
version '1.3.7'
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ public Optional<WorldData> getWorldData() {
.mapToInt(w -> w.getLoadedChunks().length)
.sum();

int entities = getServer().getWorlds().stream()
// Prevent 'Accessing entity state off owning region's thread' exception on Folia
int entities = isFolia() ? 0 : getServer().getWorlds().stream()
.mapToInt(w -> w.getEntities().size())
.sum();

Expand Down Expand Up @@ -195,9 +196,8 @@ private boolean isPlayerVisible(Player player) {
return true;
}

@SuppressWarnings("deprecation") // Folia support
private void scheduleTpsTask() {
if (this.scheduler instanceof FoliaSchedulerAdapter) {
if (isFolia()) {
FoliaSchedulerAdapter.scheduleSyncTask(this, this.tpsTask, 1, 1);

return;
Expand All @@ -206,7 +206,6 @@ private void scheduleTpsTask() {
getServer().getScheduler().runTaskTimer(this, this.tpsTask, 1, 1);
}

@SuppressWarnings("deprecation") // Folia support
private SchedulerAdapter createSchedulerAdapter() {
try {
Class.forName("io.papermc.paper.threadedregions.scheduler.ScheduledTask");
Expand All @@ -219,4 +218,8 @@ private SchedulerAdapter createSchedulerAdapter() {
);
}
}

private boolean isFolia() {
return this.scheduler instanceof FoliaSchedulerAdapter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ private HttpURLConnection prepareConnection(RequestMethod method, String endpoin
conn.setConnectTimeout(CONNECT_TIMEOUT);
conn.setReadTimeout(READ_TIMEOUT);
conn.setRequestMethod(method.name());
conn.addRequestProperty("Accept", "application/json");
conn.addRequestProperty("Azuriom-Link-Token", token);
conn.addRequestProperty("Content-Type", "application/json; charset=utf-8");
conn.addRequestProperty("User-Agent", "AzLink java v" + version);
Expand Down

0 comments on commit 2c93016

Please sign in to comment.