@@ -77,19 +77,25 @@ public class FenceBuildingManager {
7777 /** Flag to disable direct mouse input when targeting system is handling input */
7878 private boolean disableDirectMouseInput = false ;
7979
80+ /** Player reference for ownership tracking */
81+ private final wagemaker .uk .player .Player player ;
82+
8083 /**
8184 * Creates a new FenceBuildingManager with the specified dependencies.
8285 *
8386 * @param structureManager Manager for fence structure data
8487 * @param validator Validator for placement operations
8588 * @param camera Camera for input coordinate conversion
89+ * @param player The player instance for ownership tracking
8690 */
8791 public FenceBuildingManager (FenceStructureManager structureManager ,
8892 FencePlacementValidator validator ,
89- OrthographicCamera camera ) {
93+ OrthographicCamera camera ,
94+ wagemaker .uk .player .Player player ) {
9095 this .structureManager = structureManager ;
9196 this .validator = validator ;
9297 this .camera = camera ;
98+ this .player = player ;
9399 this .buildingModeActive = false ;
94100 this .selectedMaterialType = FenceMaterialType .WOOD ; // Default material
95101 this .lastProcessedGridPos = null ;
@@ -109,6 +115,15 @@ public FenceBuildingManager(FenceStructureManager structureManager,
109115 // Visual effects manager will be set externally since it requires ShapeRenderer
110116 }
111117
118+ /**
119+ * Gets the player instance associated with this manager.
120+ *
121+ * @return The player instance
122+ */
123+ public wagemaker .uk .player .Player getPlayer () {
124+ return player ;
125+ }
126+
112127 /**
113128 * Updates the fence building manager, processing input and managing state.
114129 * Should be called every frame when the game is active.
@@ -373,9 +388,15 @@ private void processBuildingInput() {
373388 public boolean placeFenceSegment (int gridX , int gridY ) {
374389 Point gridPos = new Point (gridX , gridY );
375390
391+ String playerId = player .getPlayerId ();
392+ // Fallback for single player or during initialization
393+ if (playerId == null ) {
394+ playerId = "local_player" ;
395+ }
396+
376397 // Validate placement with comprehensive error handling
377398 FencePlacementValidator .ValidationResult result =
378- validator .validatePlacement (gridPos , selectedMaterialType , "local_player" );
399+ validator .validatePlacement (gridPos , selectedMaterialType , playerId );
379400
380401 if (!result .isValid ()) {
381402 // Provide detailed error feedback to the user
@@ -392,9 +413,9 @@ public boolean placeFenceSegment(int gridX, int gridY) {
392413 }
393414
394415 try {
395- System .out .println ("[FenceBuildingManager] Attempting to place fence at grid (" + gridPos .x + ", " + gridPos .y + ") with material " + selectedMaterialType );
416+ System .out .println ("[FenceBuildingManager] Attempting to place fence at grid (" + gridPos .x + ", " + gridPos .y + ") with material " + selectedMaterialType + " for owner " + playerId );
396417 // Attempt to place the fence piece with automatic piece type selection
397- FencePiece placedPiece = structureManager .addFencePiece (gridPos , selectedMaterialType );
418+ FencePiece placedPiece = structureManager .addFencePiece (gridPos , selectedMaterialType , playerId );
398419
399420 if (placedPiece != null ) {
400421 System .out .println ("[FenceBuildingManager] Fence piece created: " + placedPiece .getType () + " at world (" + placedPiece .getX () + ", " + placedPiece .getY () + ")" );
@@ -492,9 +513,15 @@ private void displayPlacementSuccess(FencePiece placedPiece, Point gridPos) {
492513 public boolean removeFenceSegment (int gridX , int gridY ) {
493514 Point gridPos = new Point (gridX , gridY );
494515
516+ String playerId = player .getPlayerId ();
517+ // Fallback for single player or during initialization
518+ if (playerId == null ) {
519+ playerId = "local_player" ;
520+ }
521+
495522 // Validate removal with comprehensive error handling
496523 FencePlacementValidator .ValidationResult result =
497- validator .validateRemoval (gridPos , "local_player" );
524+ validator .validateRemoval (gridPos , playerId );
498525
499526 if (!result .isValid ()) {
500527 displayRemovalError (result .getErrorMessage (), gridPos );
0 commit comments