3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-07-10 23:38:06 +02:00

Use instance of ThreadLocalRandom for particle offsets

Random instances are synchronized meaning this was a potential deadlock situation.
Dieser Commit ist enthalten in:
Camotoy 2021-08-26 21:43:53 -04:00
Ursprung 26a778fd77
Commit 3c18eb44aa
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
2 geänderte Dateien mit 6 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -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;

Datei anzeigen

@ -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));