Skip to content

Commit

Permalink
a better check for nearby players
Browse files Browse the repository at this point in the history
  • Loading branch information
Hadron67 committed May 17, 2020
1 parent 3a8c3b6 commit cf38352
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/main/java/com/hadroncfy/sreplay/recording/Photographer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

Expand Down Expand Up @@ -55,7 +56,8 @@ public class Photographer extends ServerPlayerEntity implements ISizeLimitExceed
private HackyClientConnection connection;
private Recorder recorder;
private final File outputDir;
private int trackedPlayers = 0;
// private int trackedPlayers = 0;
private final List<Entity> trackedPlayers = new ArrayList<>();

private String recordingFileName, saveFileName;

Expand Down Expand Up @@ -137,7 +139,7 @@ public void run() {

setHealth(20.0F);
removed = false;
trackedPlayers = 0;
trackedPlayers.clear();
server.getPlayerManager().onPlayerConnect(connection, this);
interactionManager.setGameMode(MODE);
getServerWorld().getChunkManager().updateCameraPosition(this);
Expand Down Expand Up @@ -171,40 +173,37 @@ private boolean isRealPlayer(Entity entity){
public void onStartedTracking(Entity entity) {
super.onStartedTracking(entity);
if (isRealPlayer(entity)){
updatePause(1);
trackedPlayers.add(entity);
updatePause();
}
}

@Override
public void onStoppedTracking(Entity entity) {
super.onStoppedTracking(entity);
if (isRealPlayer(entity)){
updatePause(-1);
trackedPlayers.remove(entity);
updatePause();
}
}

public void setAutoPause(boolean b){
rparam.autoPause = b;
if (recorder != null){
if (b && trackedPlayers <= 0){
recorder.pauseRecording();
}
}
updatePause();
}

private void updatePause(int delta){
private void updatePause(){
if (recorder != null && rparam.autoPause){
final String name = getGameProfile().getName();
if (trackedPlayers > 0 && trackedPlayers + delta <= 0){
if (trackedPlayers.size() == 0 && !recorder.isRecordingPaused()){
recorder.pauseRecording();
server.getPlayerManager().broadcastChatMessage(render(SReplayMod.getFormats().autoPaused, name), true);
}
if (trackedPlayers <= 0 && trackedPlayers + delta > 0){
if (trackedPlayers.size() > 0 && recorder.isRecordingPaused()){
recorder.resumeRecording();
server.getPlayerManager().broadcastChatMessage(render(SReplayMod.getFormats().autoResumed, name), true);
}
}
trackedPlayers += delta;
}

private static String timeToString(long ms){
Expand Down

0 comments on commit cf38352

Please sign in to comment.