mirror of
https://github.com/ViaVersion/ViaLegacy.git
synced 2025-01-10 19:48:09 +01:00
Prevented concurrency issues
This commit is contained in:
parent
24bb06af6a
commit
b27cddc14f
@ -21,6 +21,7 @@ import com.viaversion.viaversion.api.Via;
|
|||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import net.raphimc.vialegacy.ViaLegacy;
|
||||||
import net.raphimc.vialegacy.protocols.alpha.protocola1_0_17_1_0_17_4toa1_0_16_2.Protocola1_0_17_1_0_17_4toa1_0_16_2;
|
import net.raphimc.vialegacy.protocols.alpha.protocola1_0_17_1_0_17_4toa1_0_16_2.Protocola1_0_17_1_0_17_4toa1_0_16_2;
|
||||||
import net.raphimc.vialegacy.protocols.alpha.protocola1_0_17_1_0_17_4toa1_0_16_2.storage.TimeLockStorage;
|
import net.raphimc.vialegacy.protocols.alpha.protocola1_0_17_1_0_17_4toa1_0_16_2.storage.TimeLockStorage;
|
||||||
import net.raphimc.vialegacy.protocols.alpha.protocola1_1_0_1_1_2_1toa1_0_17_1_0_17_4.ClientboundPacketsa1_0_17;
|
import net.raphimc.vialegacy.protocols.alpha.protocola1_1_0_1_1_2_1toa1_0_17_1_0_17_4.ClientboundPacketsa1_0_17;
|
||||||
@ -28,6 +29,8 @@ import net.raphimc.vialegacy.protocols.release.protocol1_6_1to1_5_2.Protocol1_6_
|
|||||||
import net.raphimc.vialegacy.protocols.release.protocol1_6_2to1_6_1.ClientboundPackets1_6_1;
|
import net.raphimc.vialegacy.protocols.release.protocol1_6_2to1_6_1.ClientboundPackets1_6_1;
|
||||||
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.PlayerInfoStorage;
|
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.PlayerInfoStorage;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class TimeLockTask implements Runnable {
|
public class TimeLockTask implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -36,6 +39,7 @@ public class TimeLockTask implements Runnable {
|
|||||||
final TimeLockStorage timeLockStorage = info.get(TimeLockStorage.class);
|
final TimeLockStorage timeLockStorage = info.get(TimeLockStorage.class);
|
||||||
final PlayerInfoStorage playerInfoStorage = info.get(PlayerInfoStorage.class);
|
final PlayerInfoStorage playerInfoStorage = info.get(PlayerInfoStorage.class);
|
||||||
if (timeLockStorage != null && playerInfoStorage != null && playerInfoStorage.entityId != -1) {
|
if (timeLockStorage != null && playerInfoStorage != null && playerInfoStorage.entityId != -1) {
|
||||||
|
info.getChannel().eventLoop().submit(() -> {
|
||||||
try {
|
try {
|
||||||
if (info.getProtocolInfo().getPipeline().contains(Protocol1_6_1to1_5_2.class)) {
|
if (info.getProtocolInfo().getPipeline().contains(Protocol1_6_1to1_5_2.class)) {
|
||||||
if (timeLockStorage.getTime() == 0) { // 0 always does the daylight cycle
|
if (timeLockStorage.getTime() == 0) { // 0 always does the daylight cycle
|
||||||
@ -50,8 +54,10 @@ public class TimeLockTask implements Runnable {
|
|||||||
updateTime.write(Type.LONG, timeLockStorage.getTime()); // time
|
updateTime.write(Type.LONG, timeLockStorage.getTime()); // time
|
||||||
updateTime.send(Protocola1_0_17_1_0_17_4toa1_0_16_2.class);
|
updateTime.send(Protocola1_0_17_1_0_17_4toa1_0_16_2.class);
|
||||||
}
|
}
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable e) {
|
||||||
|
ViaLegacy.getPlatform().getLogger().log(Level.WARNING, "Error sending time update", e);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@ public class AlphaInventoryUpdateTask implements Runnable {
|
|||||||
final InventoryStorage inventoryStorage = info.get(InventoryStorage.class);
|
final InventoryStorage inventoryStorage = info.get(InventoryStorage.class);
|
||||||
if (inventoryStorage == null) continue;
|
if (inventoryStorage == null) continue;
|
||||||
|
|
||||||
|
info.getChannel().eventLoop().submit(() -> {
|
||||||
try {
|
try {
|
||||||
final Item[] mainInventory = fixItems(Via.getManager().getProviders().get(AlphaInventoryProvider.class).getMainInventoryItems(info));
|
final Item[] mainInventory = fixItems(Via.getManager().getProviders().get(AlphaInventoryProvider.class).getMainInventoryItems(info));
|
||||||
final Item[] craftingInventory = fixItems(Via.getManager().getProviders().get(AlphaInventoryProvider.class).getCraftingInventoryItems(info));
|
final Item[] craftingInventory = fixItems(Via.getManager().getProviders().get(AlphaInventoryProvider.class).getCraftingInventoryItems(info));
|
||||||
@ -64,7 +65,7 @@ public class AlphaInventoryUpdateTask implements Runnable {
|
|||||||
System.arraycopy(armorInventory, 0, mergedArmorInventory, 0, armorInventory.length);
|
System.arraycopy(armorInventory, 0, mergedArmorInventory, 0, armorInventory.length);
|
||||||
|
|
||||||
boolean hasChanged = !Arrays.equals(mergedMainInventory, inventoryStorage.mainInventory) || !Arrays.equals(mergedCraftingInventory, inventoryStorage.craftingInventory) || !Arrays.equals(mergedArmorInventory, inventoryStorage.armorInventory);
|
boolean hasChanged = !Arrays.equals(mergedMainInventory, inventoryStorage.mainInventory) || !Arrays.equals(mergedCraftingInventory, inventoryStorage.craftingInventory) || !Arrays.equals(mergedArmorInventory, inventoryStorage.armorInventory);
|
||||||
if (!hasChanged) continue;
|
if (!hasChanged) return;
|
||||||
|
|
||||||
inventoryStorage.mainInventory = copyItems(mergedMainInventory);
|
inventoryStorage.mainInventory = copyItems(mergedMainInventory);
|
||||||
inventoryStorage.craftingInventory = copyItems(mergedCraftingInventory);
|
inventoryStorage.craftingInventory = copyItems(mergedCraftingInventory);
|
||||||
@ -88,6 +89,7 @@ public class AlphaInventoryUpdateTask implements Runnable {
|
|||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
ViaLegacy.getPlatform().getLogger().log(Level.WARNING, "Error sending inventory update packets", e);
|
ViaLegacy.getPlatform().getLogger().log(Level.WARNING, "Error sending inventory update packets", e);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
|||||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import net.raphimc.vialegacy.ViaLegacy;
|
||||||
import net.raphimc.vialegacy.api.data.BlockList1_6;
|
import net.raphimc.vialegacy.api.data.BlockList1_6;
|
||||||
import net.raphimc.vialegacy.api.model.IdAndData;
|
import net.raphimc.vialegacy.api.model.IdAndData;
|
||||||
import net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1.Protocol1_0_0_1tob1_8_0_1;
|
import net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1.Protocol1_0_0_1tob1_8_0_1;
|
||||||
@ -33,6 +34,8 @@ import net.raphimc.vialegacy.protocols.release.protocol1_4_2to1_3_1_2.types.Type
|
|||||||
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ChunkTracker;
|
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ChunkTracker;
|
||||||
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.PlayerInfoStorage;
|
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.PlayerInfoStorage;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class PlayerAirTimeUpdateTask implements Runnable {
|
public class PlayerAirTimeUpdateTask implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -42,6 +45,8 @@ public class PlayerAirTimeUpdateTask implements Runnable {
|
|||||||
if (playerAirTimeStorage != null) {
|
if (playerAirTimeStorage != null) {
|
||||||
final PlayerInfoStorage playerInfoStorage = info.get(PlayerInfoStorage.class);
|
final PlayerInfoStorage playerInfoStorage = info.get(PlayerInfoStorage.class);
|
||||||
if (playerInfoStorage == null) continue;
|
if (playerInfoStorage == null) continue;
|
||||||
|
info.getChannel().eventLoop().submit(() -> {
|
||||||
|
try {
|
||||||
final IdAndData headBlock = info.get(ChunkTracker.class).getBlockNotNull(floor(playerInfoStorage.posX), floor(playerInfoStorage.posY + 1.62F), floor(playerInfoStorage.posZ));
|
final IdAndData headBlock = info.get(ChunkTracker.class).getBlockNotNull(floor(playerInfoStorage.posX), floor(playerInfoStorage.posY + 1.62F), floor(playerInfoStorage.posZ));
|
||||||
if (headBlock.id == BlockList1_6.waterMoving.blockID || headBlock.id == BlockList1_6.waterStill.blockID) {
|
if (headBlock.id == BlockList1_6.waterMoving.blockID || headBlock.id == BlockList1_6.waterStill.blockID) {
|
||||||
playerAirTimeStorage.sentPacket = false;
|
playerAirTimeStorage.sentPacket = false;
|
||||||
@ -53,19 +58,19 @@ public class PlayerAirTimeUpdateTask implements Runnable {
|
|||||||
playerAirTimeStorage.air = playerAirTimeStorage.MAX_AIR;
|
playerAirTimeStorage.air = playerAirTimeStorage.MAX_AIR;
|
||||||
this.sendAirTime(playerInfoStorage, playerAirTimeStorage, info);
|
this.sendAirTime(playerInfoStorage, playerAirTimeStorage, info);
|
||||||
}
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
ViaLegacy.getPlatform().getLogger().log(Level.WARNING, "Error updating air time", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendAirTime(final PlayerInfoStorage playerInfoStorage, final PlayerAirTimeStorage playerAirTimeStorage, final UserConnection userConnection) {
|
private void sendAirTime(final PlayerInfoStorage playerInfoStorage, final PlayerAirTimeStorage playerAirTimeStorage, final UserConnection userConnection) throws Exception {
|
||||||
try {
|
|
||||||
final PacketWrapper updateAirTime = PacketWrapper.create(ClientboundPackets1_0.ENTITY_METADATA, userConnection);
|
final PacketWrapper updateAirTime = PacketWrapper.create(ClientboundPackets1_0.ENTITY_METADATA, userConnection);
|
||||||
updateAirTime.write(Type.INT, playerInfoStorage.entityId); // entity id
|
updateAirTime.write(Type.INT, playerInfoStorage.entityId); // entity id
|
||||||
updateAirTime.write(Types1_3_1.METADATA_LIST, Lists.newArrayList(new Metadata(1, MetaType1_3_1.Short, Integer.valueOf(playerAirTimeStorage.air).shortValue()))); // metadata
|
updateAirTime.write(Types1_3_1.METADATA_LIST, Lists.newArrayList(new Metadata(1, MetaType1_3_1.Short, Integer.valueOf(playerAirTimeStorage.air).shortValue()))); // metadata
|
||||||
updateAirTime.send(Protocol1_0_0_1tob1_8_0_1.class);
|
updateAirTime.send(Protocol1_0_0_1tob1_8_0_1.class);
|
||||||
} catch (Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int floor(double f) {
|
private static int floor(double f) {
|
||||||
|
@ -20,8 +20,11 @@ package net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.storage;
|
|||||||
import com.viaversion.viaversion.api.connection.StoredObject;
|
import com.viaversion.viaversion.api.connection.StoredObject;
|
||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
import com.viaversion.viaversion.api.minecraft.Position;
|
import com.viaversion.viaversion.api.minecraft.Position;
|
||||||
|
import net.raphimc.vialegacy.ViaLegacy;
|
||||||
import net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.Protocolb1_3_0_1tob1_2_0_2;
|
import net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.Protocolb1_3_0_1tob1_2_0_2;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class BlockDigStorage extends StoredObject {
|
public class BlockDigStorage extends StoredObject {
|
||||||
|
|
||||||
public int tick = 1;
|
public int tick = 1;
|
||||||
@ -44,7 +47,7 @@ public class BlockDigStorage extends StoredObject {
|
|||||||
}
|
}
|
||||||
Protocolb1_3_0_1tob1_2_0_2.sendBlockDigPacket(this.getUser(), (byte) 1, position, facing);
|
Protocolb1_3_0_1tob1_2_0_2.sendBlockDigPacket(this.getUser(), (byte) 1, position, facing);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
ViaLegacy.getPlatform().getLogger().log(Level.WARNING, "Error while ticking BlockDigStorage", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,9 @@ public class BlockDigTickTask implements Runnable {
|
|||||||
public void run() {
|
public void run() {
|
||||||
for (UserConnection info : Via.getManager().getConnectionManager().getConnections()) {
|
for (UserConnection info : Via.getManager().getConnectionManager().getConnections()) {
|
||||||
final BlockDigStorage blockDigStorage = info.get(BlockDigStorage.class);
|
final BlockDigStorage blockDigStorage = info.get(BlockDigStorage.class);
|
||||||
if (blockDigStorage != null) blockDigStorage.tick();
|
if (blockDigStorage != null) {
|
||||||
|
info.getChannel().eventLoop().submit(blockDigStorage::tick);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ public class ClassicPingTask implements Runnable {
|
|||||||
final ExtensionProtocolMetadataStorage protocolMetadata = info.get(ExtensionProtocolMetadataStorage.class);
|
final ExtensionProtocolMetadataStorage protocolMetadata = info.get(ExtensionProtocolMetadataStorage.class);
|
||||||
if (protocolMetadata == null) continue;
|
if (protocolMetadata == null) continue;
|
||||||
if (!protocolMetadata.hasServerExtension(ClassicProtocolExtension.TWO_WAY_PING, 1)) continue;
|
if (!protocolMetadata.hasServerExtension(ClassicProtocolExtension.TWO_WAY_PING, 1)) continue;
|
||||||
|
info.getChannel().eventLoop().submit(() -> {
|
||||||
try {
|
try {
|
||||||
final PacketWrapper pingRequest = PacketWrapper.create(ServerboundPacketsc0_30cpe.EXT_TWO_WAY_PING, info);
|
final PacketWrapper pingRequest = PacketWrapper.create(ServerboundPacketsc0_30cpe.EXT_TWO_WAY_PING, info);
|
||||||
pingRequest.write(Type.BYTE, (byte) 0); // direction
|
pingRequest.write(Type.BYTE, (byte) 0); // direction
|
||||||
@ -46,6 +47,7 @@ public class ClassicPingTask implements Runnable {
|
|||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
ViaLegacy.getPlatform().getLogger().log(Level.WARNING, "Error sending TwoWayPing extension ping packet", e);
|
ViaLegacy.getPlatform().getLogger().log(Level.WARNING, "Error sending TwoWayPing extension ping packet", e);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,9 @@ public class EntityTrackerTickTask implements Runnable {
|
|||||||
public void run() {
|
public void run() {
|
||||||
for (UserConnection info : Via.getManager().getConnectionManager().getConnections()) {
|
for (UserConnection info : Via.getManager().getConnectionManager().getConnections()) {
|
||||||
final EntityTracker entityTracker = info.get(EntityTracker.class);
|
final EntityTracker entityTracker = info.get(EntityTracker.class);
|
||||||
if (entityTracker != null) entityTracker.tick();
|
if (entityTracker != null) {
|
||||||
|
info.getChannel().eventLoop().submit(entityTracker::tick);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user