Buggy code:
int selected = fileHud . getSelected ( ) ; if ( selected == 0 ) { System . out . println ( "LOAD" ) ; JFileChooser chooser = new JFileChooser ( ) ; FileNameExtensionFilter filter = new FileNameExtensionFilter ( "Level" , "xml" ) ; chooser . setCurrentDirectory ( levelFile . getParentFile ( ) ) ; chooser . setFileFilter ( filter ) ; int returnVal = chooser . showOpenDialog ( getStageManager ( ) . gameCanvas ) ; if ( returnVal == ( JFileChooser . APPROVE_OPTION ) ) { Map < String , String > data = new HashMap < > ( ) ; data . put ( "file" , chooser . getSelectedFile ( ) . getPath ( ) ) ; getStageManager ( ) . setStage ( STAGE_LEVEL_EDITOR , data ) ; } } else if ( selected == 1 ) { System . out . println ( "Save" ) ; map . save ( levelFile ) ; } return ; } isSelecting = false ; if ( ( editMode ) == ( StageEditor . EDITMODE_MAP ) ) { if ( ( ( selectedX ) == ( lastSelectionX ) ) && ( ( selectedY ) == ( lastSelectionY ) ) ) { if ( ( e . getButton ( ) ) == ( MouseEvent . BUTTON1 ) ) { map . setTile ( selectedX , selectedY ) ; } else if ( ( e . getButton ( ) ) == ( MouseEvent . BUTTON3 ) ) { map . removeTile ( selectedX , selectedY ) ; } } else { if ( ( e . getButton ( ) ) == ( MouseEvent . BUTTON1 ) ) { map . fillRect ( selectedX , selectedY , lastSelectionX , lastSelectionY ) ; } else if ( ( e . getButton ( ) ) == ( MouseEvent . BUTTON3 ) ) { map . clearRect ( selectedX , selectedY , lastSelectionX , lastSelectionY ) ; } } } else { MapObject mouseObject = null ; MapObject [ ] objects = map . getMapObjects ( ) ; for ( int i = 0 ; i < ( objects . length ) ; i ++ ) { if ( ( ( selectedX ) >= ( objects [ i ] . getX ( ) ) ) && ( ( selectedX ) < ( ( ( objects [ i ] . getX ( ) ) + ( objects [ i ] . getWidth ( ) ) ) + ( ( objects [ i ] . getWidth ( ) ) == 0 ? 1 : 0 ) ) ) ) { if ( ( ( selectedY ) >= ( objects [ i ] . getY ( ) ) ) && ( ( selectedY ) < ( ( ( objects [ i ] . getY ( ) ) + ( objects [ i ] . getHeight ( ) ) ) + ( ( objects [ i ] . getHeight ( ) ) == 0 ? 1 : 0 ) ) ) ) { mouseObject = objects [ i ] ; } } } if ( ( editMode ) == ( StageEditor . EDITMODE_OBJECT ) ) { selectedMapObject = null ; if ( ! ( isLogicMapObject ( mouseObject ) ) ) { selectedMapObject = mouseObject ; if ( ( selectedMapObject ) == null ) { placeObject ( objectHud . getObject ( ) ) ; } } } else if ( ( editMode ) == ( StageEditor . EDITMODE_LOGIC ) ) { if ( ( e . getButton ( ) ) == ( MouseEvent . BUTTON1 ) ) { selectedMapObject = null ; <START_BUG> if ( isLogicMapObject ( mouseObject ) ) { <END_BUG> selectedMapObject = mouseObject ; if ( ( selectedMapObject ) == null ) { placeObject ( logicHud . getObject ( ) ) ; } } } else if ( ( e . getButton ( ) ) == ( MouseEvent . BUTTON3 ) ) { if ( mouseObject != null ) { int spriteSize = ( TileSet . SPRITE_SIZE ) * ( scale ) ; if ( ( ( connectingLogicLine ) && ( mouseObject != ( startLogicLine ) ) ) && ( ( ( mouseObject . inputCount ( ) ) > 0 ) || ( mouseObject . moreInputs ( ) ) ) ) { startLogicLine . setOutput ( mouseObject . getId ( ) ) ; if ( ( ( mouseObject . inputCount ( ) ) != 1 ) || ( mouseObject . moreInputs ( ) ) ) { int inputcount = ( mouseObject . inputCount ( ) ) + ( mouseObject . moreInputs ( ) ? 1 : 0 ) ; int input = ( ( int ) ( ( ( ( mouse_X ) + ( xOffset ) ) - ( ( mouseObject . getX ( ) ) * spriteSize ) ) // ( ( ( mouseObject . getWidth ( ) ) == 0 ? spriteSize : ( mouseObject . getWidth ( ) ) * spriteSize ) // inputcount ) ) ) ; mouseObject . setInput ( input , startLogicLine . getId ( ) ) ; } connectingLogicLine = false ; } else { connectingLogicLine = false ; if ( ( ( ( mouse_Y ) + ( yOffset ) ) % spriteSize ) < ( ( spriteSize // 16 ) * 3 ) ) { } else if ( ( ( ( ( mouse_Y ) + ( yOffset ) ) % spriteSize ) > ( spriteSize - ( ( spriteSize // 16 ) * 3 ) ) ) && ( ( ( selectedY ) - ( mouseObject . getY ( ) ) ) == ( ( mouseObject . getHeight ( ) ) == 0 ? 0 : ( mouseObject . getHeight ( ) ) - 1 ) ) ) { mouseObject . invertOutput ( ) ; } else { mouseObject . onEditorRightClick ( ) ; } } } else { connectingLogicLine = false ;

Fix:
if ( ( isLogicMapObject ( mouseObject ) ) || ( mouseObject == null ) ) {