mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-13 19:50:31 +00:00
Fix pocket speakers incorrectly detaching computers
- Fix UpgradeSpeakerPeripheral not calling super.detach (so old computers were never cleaned up) - Correctly lock computer accesses inside SpeakerPeripheral Fixes #1003. Fingers crossed this is the last bug. Then I can bump the year and push a new release tomorrow.
This commit is contained in:
parent
a9519f68a1
commit
16df86224b
@ -39,14 +39,13 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
||||
private final String type;
|
||||
private final Set<String> additionalTypes;
|
||||
private final Map<String, PeripheralMethod> methodMap;
|
||||
private boolean attached;
|
||||
private boolean attached = false;
|
||||
|
||||
PeripheralWrapper( IPeripheral peripheral, String side )
|
||||
{
|
||||
super( environment );
|
||||
this.side = side;
|
||||
this.peripheral = peripheral;
|
||||
attached = false;
|
||||
|
||||
type = Objects.requireNonNull( peripheral.getType(), "Peripheral type cannot be null" );
|
||||
additionalTypes = peripheral.getAdditionalTypes();
|
||||
|
@ -53,7 +53,7 @@ public abstract class SpeakerPeripheral implements IPeripheral
|
||||
public static final int SAMPLE_RATE = 48000;
|
||||
|
||||
private final UUID source = UUID.randomUUID();
|
||||
private final Set<IComputerAccess> computers = Collections.newSetFromMap( new HashMap<>() );
|
||||
private final Set<IComputerAccess> computers = new HashSet<>();
|
||||
|
||||
private long clock = 0;
|
||||
private long lastPositionTime;
|
||||
@ -141,9 +141,12 @@ public abstract class SpeakerPeripheral implements IPeripheral
|
||||
syncedPosition( pos );
|
||||
|
||||
// And notify computers that we have space for more audio.
|
||||
for( IComputerAccess computer : computers )
|
||||
synchronized( computers )
|
||||
{
|
||||
computer.queueEvent( "speaker_audio_empty", computer.getAttachmentName() );
|
||||
for( IComputerAccess computer : computers )
|
||||
{
|
||||
computer.queueEvent( "speaker_audio_empty", computer.getAttachmentName() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -379,13 +382,19 @@ public abstract class SpeakerPeripheral implements IPeripheral
|
||||
@Override
|
||||
public void attach( @Nonnull IComputerAccess computer )
|
||||
{
|
||||
computers.add( computer );
|
||||
synchronized( computers )
|
||||
{
|
||||
computers.add( computer );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detach( @Nonnull IComputerAccess computer )
|
||||
{
|
||||
computers.remove( computer );
|
||||
synchronized( computers )
|
||||
{
|
||||
computers.remove( computer );
|
||||
}
|
||||
}
|
||||
|
||||
private static final class PendingSound
|
||||
|
@ -21,6 +21,8 @@ public abstract class UpgradeSpeakerPeripheral extends SpeakerPeripheral
|
||||
@Override
|
||||
public void detach( @Nonnull IComputerAccess computer )
|
||||
{
|
||||
super.detach( computer );
|
||||
|
||||
// We could be in the process of shutting down the server, so we can't send packets in this case.
|
||||
MinecraftServer server = ServerLifecycleHooks.getCurrentServer();
|
||||
if( server == null || server.isStopped() ) return;
|
||||
|
Loading…
Reference in New Issue
Block a user