11package com .vltno .timeloop ;
22
3+ import net .minecraft .world .phys .Vec3 ;
4+
35import java .util .ArrayList ;
46import java .util .HashMap ;
57import java .util .List ;
@@ -10,8 +12,6 @@ public class LoopSceneManager {
1012 private TimeLoopConfig config ;
1113 private String scenePrefix ;
1214 private Map <String , PlayerData > recordingPlayers ;
13-
14-
1515
1616 // Constructor to initialize recordingPlayers map
1717 public LoopSceneManager (TimeLoopConfig config ) {
@@ -23,18 +23,46 @@ public LoopSceneManager(TimeLoopConfig config) {
2323 // Method to add a player to the recordingPlayers map
2424 public void addPlayer (List <String > args ) {
2525 String playerName = args .get (0 );
26- List <String > nickname = args .size () > 1 ? args .subList (1 , args .size ()) : null ;
27- List <String > skin = args .size () > 2 ? args .subList (2 , args .size ()) : null ;
2826
29- if (playerName != null && !playerName .isEmpty ()) {
30- String tempNickname = (nickname == null || nickname .isEmpty ()) ? playerName : nickname .getFirst ();
31- String tempSkin = (skin == null || skin .isEmpty ()) ? playerName : skin .getFirst ();
32-
33- // Use player name as the key and store a PlayerData object
34- recordingPlayers .put (playerName , new PlayerData (playerName , tempNickname , tempSkin ));
35- } else {
36- System .out .println ("Invalid player data. Player not added." );
27+ String nickname = args .size () > 1 ? args .get (1 ) : null ;
28+ String skin = args .size () > 2 ? args .get (2 ) : null ;
29+ String rewindPosition = args .size () > 3 ? args .get (3 ) : null ;
30+
31+ if (playerName == null || playerName .isEmpty ()) {
32+ TimeLoop .LOOP_LOGGER .error ("Player name is null or empty. Skipping player addition." );
33+ return ;
3734 }
35+
36+ String tempNickname = (nickname == null || nickname .isEmpty ()) ? playerName : nickname ;
37+ String tempSkin = (skin == null || skin .isEmpty ()) ? playerName : skin ;
38+
39+ Vec3 tempRewindPosition = Vec3 .ZERO ;
40+
41+ if (rewindPosition != null && !rewindPosition .isEmpty ()) {
42+ try {
43+ String processedString = rewindPosition .trim ();
44+
45+ if ((processedString .startsWith ("(" ) && processedString .endsWith (")" )) ||
46+ (processedString .startsWith ("[" ) && processedString .endsWith ("]" ))) {
47+ processedString = processedString .substring (1 , processedString .length () - 1 ).trim ();
48+ }
49+
50+ String [] positionParts = processedString .split ("\\ s*,\\ s*" );
51+
52+ if (positionParts .length == 3 ) {
53+ double x = Double .parseDouble (positionParts [0 ]);
54+ double y = Double .parseDouble (positionParts [1 ]);
55+ double z = Double .parseDouble (positionParts [2 ]);
56+ tempRewindPosition = new Vec3 (x , y , z );
57+ }
58+ } catch (NumberFormatException e ) {
59+ TimeLoop .LOOP_LOGGER .error ("Invalid rewind position format. Skipping rewind position." );
60+ }
61+ }
62+
63+ PlayerData playerData = new PlayerData (playerName , tempNickname , tempSkin , tempRewindPosition );
64+
65+ recordingPlayers .put (playerName , playerData );
3866 }
3967
4068
@@ -43,12 +71,12 @@ public void removePlayer(String playerName) {
4371 if (playerName != null && !playerName .isEmpty ()) {
4472 PlayerData removed = recordingPlayers .remove (playerName );
4573 if (removed != null ) {
46- System . out . println ("Player '" + playerName + "' removed successfully." );
74+ TimeLoop . LOOP_LOGGER . info ("Player '" + playerName + "' removed successfully." );
4775 } else {
48- System . out . println ("Player '" + playerName + "' not found in the list." );
76+ TimeLoop . LOOP_LOGGER . info ("Player '" + playerName + "' not found in the list." );
4977 }
5078 } else {
51- System . out . println ("Invalid player name. Player not removed." );
79+ TimeLoop . LOOP_LOGGER . info ("Invalid player name. Player not removed." );
5280 }
5381 }
5482
0 commit comments