Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-25 07:40:10 +01:00
Use instance of ThreadLocalRandom for particle offsets
Random instances are synchronized meaning this was a potential deadlock situation.
Dieser Commit ist enthalten in:
Ursprung
26a778fd77
Commit
3c18eb44aa
@ -43,7 +43,6 @@ import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class QueryPacketHandler {
|
||||
@ -265,7 +264,7 @@ public class QueryPacketHandler {
|
||||
public void regenerateToken() {
|
||||
byte[] token = new byte[16];
|
||||
for (int i = 0; i < 16; i++) {
|
||||
token[i] = (byte) new Random().nextInt(255);
|
||||
token[i] = (byte) ThreadLocalRandom.current().nextInt(255);
|
||||
}
|
||||
|
||||
this.token = token;
|
||||
|
@ -43,11 +43,11 @@ import org.geysermc.connector.registry.type.ParticleMapping;
|
||||
import org.geysermc.connector.utils.DimensionUtils;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Translator(packet = ServerSpawnParticlePacket.class)
|
||||
public class JavaSpawnParticleTranslator extends PacketTranslator<ServerSpawnParticlePacket> {
|
||||
private final Random random = new Random();
|
||||
|
||||
@Override
|
||||
public void translate(ServerSpawnParticlePacket packet, GeyserSession session) {
|
||||
@ -58,10 +58,11 @@ public class JavaSpawnParticleTranslator extends PacketTranslator<ServerSpawnPar
|
||||
Vector3f position = Vector3f.from(packet.getX(), packet.getY(), packet.getZ());
|
||||
session.sendUpstreamPacket(particleCreateFunction.apply(position));
|
||||
} else {
|
||||
Random random = ThreadLocalRandom.current();
|
||||
for (int i = 0; i < packet.getAmount(); i++) {
|
||||
double offsetX = this.random.nextGaussian() * (double) packet.getOffsetX();
|
||||
double offsetY = this.random.nextGaussian() * (double) packet.getOffsetY();
|
||||
double offsetZ = this.random.nextGaussian() * (double) packet.getOffsetZ();
|
||||
double offsetX = random.nextGaussian() * (double) packet.getOffsetX();
|
||||
double offsetY = random.nextGaussian() * (double) packet.getOffsetY();
|
||||
double offsetZ = random.nextGaussian() * (double) packet.getOffsetZ();
|
||||
Vector3f position = Vector3f.from(packet.getX() + offsetX, packet.getY() + offsetY, packet.getZ() + offsetZ);
|
||||
|
||||
session.sendUpstreamPacket(particleCreateFunction.apply(position));
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren