#ByPander - World creation error
1 messages · Page 1 of 1 (latest)
Async cant interact with non thread safe objects/methods
Is there an easy fix to my code? Or should i read in async?
Code?
WorldCreator wc = new WorldCreator("BingoWorld" + worldNumber); wc.environment(World.Environment.NORMAL); wc.type(WorldType.NORMAL); world = wc.createWorld(); assert world != null; WorldBorder wb = world.getWorldBorder(); wb.setCenter(0,0); wb.setSize(2000);
Do u need more code?
Clazz
Here is the Class:
`package de.bypander.bingo.BingoGame;
import org.bukkit.*;
import org.bukkit.entity.Player;
import java.util.Objects;
import java.util.UUID;
public class BingoGame {
World world;
UUID[] gamePlayer;
QueueManager queueManager;
public BingoGame(UUID[] player, int worldNumber, QueueManager manager) {
queueManager = manager;
WorldCreator wc = new WorldCreator("BingoWorld" + worldNumber);
wc.environment(World.Environment.NORMAL);
wc.type(WorldType.NORMAL);
world = wc.createWorld();
assert world != null;
WorldBorder wb = world.getWorldBorder();
wb.setCenter(0,0);
wb.setSize(2000);
int i = 0;
for (UUID value : player) {
if (value != null) {
i++;
}
}
gamePlayer = new UUID[i];
int k = 0;
for (int j = 0; j < gamePlayer.length; j++) {
if (player[j] != null) {
gamePlayer[k] = player[j];
k++;
}
}
for (int l = 320; l > -64; l--) {
if (!world.getBlockAt(0, l, 0).isEmpty()) {
break;
}
}
for (UUID uuid : player) {
Objects.requireNonNull(Bukkit.getPlayerExact(Objects.requireNonNull(Bukkit.getPlayer(uuid)).getName())).teleport(new Location(world, 0, 0, 0, 0, 0));
}
}
}`
Did you created class using async task or promises?
the fact that it's done synchronously with the main thread means the worldcreator will block the server from processing anything
as it takes a very long time to create a world
Is there an easy fix or work around?
cant tell you, ive never dealt with world creation (atleast not on spigot)
Do you mean when i call the constructor?
Here is the method where i am calling the constructor:
public void startRound() { for (UUID value : loggedPlayer) { if (value != null) { Objects.requireNonNull(Bukkit.getPlayer(value)).sendMessage(ChatColor.GRAY.toString() + "The Bingo round is starting. This could take a few moments."); } } new BingoGame(loggedPlayer, worldNumber, this); worldNumber++; }